protected List<Integer> getSigEncrActions(List<WSSecurityEngineResult> results) { List<Integer> sigEncrActions = new ArrayList<Integer>(); for (WSSecurityEngineResult result : results) { Integer action = (Integer) (result) .get(WSSecurityEngineResult.TAG_ACTION); if (WSConstants.SIGN == action || WSConstants.ENCR == action) { sigEncrActions.add(action); } } return sigEncrActions; }
protected List<WSSecurityEngineResult> getResults(List<WSSecurityEngineResult> results, int action) { List<WSSecurityEngineResult> list = new ArrayList<WSSecurityEngineResult>(); for (WSSecurityEngineResult result : results) { // Check the result of every action whether it matches the given // action Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION); if (actInt == action) { list.add(result); } } return list; }
/** * Fetch the result of a given action from a given result list * * @param resultList The result list to fetch an action from * @param action The action to fetch * @return The last result fetched from the result list, null if the result * could not be found */ public static WSSecurityEngineResult fetchActionResult( List<WSSecurityEngineResult> resultList, int action ) { WSSecurityEngineResult returnResult = null; for (WSSecurityEngineResult result : resultList) { // // Check the result of every action whether it matches the given action // int resultAction = ((java.lang.Integer)result.get(WSSecurityEngineResult.TAG_ACTION)).intValue(); if (resultAction == action) { returnResult = result; } } return returnResult; }
public static WSSecurityEngineResult[] fetchActionResults(List<WSSecurityEngineResult> wsSecurityEngineResults, int action) { List<WSSecurityEngineResult> wsResult = new ArrayList<WSSecurityEngineResult>(); // Find the part of the security result that matches the given action for (WSSecurityEngineResult wsSecurityEngineResult : wsSecurityEngineResults) { // Check the result of every action whether it matches the given action WSSecurityEngineResult result = (WSSecurityEngineResult) wsSecurityEngineResult; int resultAction = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION); if (resultAction == action) { wsResult.add(wsSecurityEngineResult); } } return wsResult.toArray(new WSSecurityEngineResult[wsResult .size()]); }
public static byte[] getRequestEncryptedKeyValue(List<WSHandlerResult> results) { for (WSHandlerResult result : results) { List<WSSecurityEngineResult> wsSecEngineResults = result.getResults(); /* * Scan the results for the first Signature action. Use the * certificate of this Signature to set the certificate for the * encryption action :-). */ for (WSSecurityEngineResult wsSecEngineResult : wsSecEngineResults) { Integer actInt = (Integer) wsSecEngineResult.get(WSSecurityEngineResult.TAG_ACTION); byte[] decryptedKey = (byte[]) wsSecEngineResult.get(WSSecurityEngineResult.TAG_SECRET); if (actInt == WSConstants.ENCR && decryptedKey != null) { return decryptedKey; } } } return null; }
private static X509Certificate getReqSigCert(List<WSHandlerResult> results) { /* * Scan the results for a matching actor. Use results only if the * receiving Actor and the sending Actor match. */ for (WSHandlerResult result : results) { List<WSSecurityEngineResult> wsSecEngineResults = result.getResults(); /* * Scan the results for the first Signature action. Use the * certificate of this Signature to set the certificate for the * encryption action :-). */ for (WSSecurityEngineResult wsSecEngineResult : wsSecEngineResults) { Integer actInt = (Integer) wsSecEngineResult.get(WSSecurityEngineResult.TAG_ACTION); if (actInt == WSConstants.SIGN) { return (X509Certificate) wsSecEngineResult.get(WSSecurityEngineResult.TAG_X509_CERTIFICATE); } } } return null; }
/** * Get a list of WSSecurityEngineResults of the given Integer tag */ public List<WSSecurityEngineResult> getResultsByTag(Integer tag) { List<WSSecurityEngineResult> foundResults = new ArrayList<WSSecurityEngineResult>(); if (resultsList != null) { for (WSSecurityEngineResult result : resultsList) { if (result != null) { Integer resultTag = (Integer)result.get(WSSecurityEngineResult.TAG_ACTION); if (tag.intValue() == resultTag.intValue()) { foundResults.add(result); } } } } return foundResults; }
/** * Get a list of WSSecurityEngineResults of the given Integer tag */ public List<WSSecurityEngineResult> getResultsByTag(Integer tag) { List<WSSecurityEngineResult> foundResults = new ArrayList<WSSecurityEngineResult>(); if (resultsList != null) { for (WSSecurityEngineResult result : resultsList) { if (result != null) { Integer resultTag = (Integer)result.get(WSSecurityEngineResult.TAG_ACTION); if (tag.intValue() == resultTag.intValue()) { foundResults.add(result); } } } } return foundResults; }
/** * Get a WSSecurityEngineResult of the given Integer tag for the given Id */ public WSSecurityEngineResult getResultByTag(Integer tag, String uri) { String id = uri; if (id == null || "".equals(uri)) { return null; } else if (id.charAt(0) == '#') { id = id.substring(1); } if (resultsList != null) { for (WSSecurityEngineResult result : resultsList) { if (result != null) { Integer resultTag = (Integer)result.get(WSSecurityEngineResult.TAG_ACTION); String cId = (String)result.get(WSSecurityEngineResult.TAG_ID); if ((tag.intValue() == resultTag.intValue()) && id.equals(cId)) { return result; } } } } return null; }
/** * Get a WSSecurityEngineResult for the given Id. * @param uri is the (relative) uri of the id * @return the WSSecurityEngineResult or null if nothing found */ public WSSecurityEngineResult getResult(String uri) { String id = uri; if (id == null) { return null; } else if (id.charAt(0) == '#') { id = id.substring(1); } if (resultsList != null) { for (WSSecurityEngineResult result : resultsList) { if (result != null) { String cId = (String)result.get(WSSecurityEngineResult.TAG_ID); if (id.equals(cId)) { return result; } } } } return null; }
protected boolean checkReceiverResults( List<WSSecurityEngineResult> wsResult, List<Integer> actions ) { int size = actions.size(); int ai = 0; for (WSSecurityEngineResult result : wsResult) { final Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION); int act = actInt.intValue(); if (act == WSConstants.SC || act == WSConstants.BST) { continue; } if (ai >= size || actions.get(ai++).intValue() != act) { return false; } } if (ai != size) { return false; } return true; }
protected boolean checkReceiverResults( List<WSSecurityEngineResult> wsResult, List<Integer> actions ) { int size = actions.size(); int ai = 0; for (WSSecurityEngineResult result : wsResult) { final Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION); int act = actInt.intValue(); if (act == WSConstants.SC || act == WSConstants.BST) { continue; } if (ai >= size || actions.get(ai++).intValue() != act) { return false; } } if (ai != size) { return false; } return true; }
/** * Get a WSSecurityEngineResult of the given Integer tag for the given Id */ public WSSecurityEngineResult getResultByTag(Integer tag, String uri) { String id = uri; if (id == null || "".equals(uri)) { return null; } else if (id.charAt(0) == '#') { id = id.substring(1); } if (resultsList != null) { for (WSSecurityEngineResult result : resultsList) { if (result != null) { Integer resultTag = (Integer)result.get(WSSecurityEngineResult.TAG_ACTION); String cId = (String)result.get(WSSecurityEngineResult.TAG_ID); if ((tag.intValue() == resultTag.intValue()) && id.equals(cId)) { return result; } } } } return null; }
protected boolean checkReceiverResultsAnyOrder( List<WSSecurityEngineResult> wsResult, List<Integer> actions ) { List<Integer> recordedActions = new ArrayList<Integer>(actions.size()); for (Integer action : actions) { recordedActions.add(action); } for (WSSecurityEngineResult result : wsResult) { final Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION); int act = actInt.intValue(); if (act == WSConstants.SC || act == WSConstants.BST) { continue; } if (!recordedActions.remove(actInt)) { return false; } } if (!recordedActions.isEmpty()) { return false; } return true; }
protected boolean checkReceiverResultsAnyOrder( List<WSSecurityEngineResult> wsResult, List<Integer> actions ) { List<Integer> recordedActions = new ArrayList<Integer>(actions.size()); for (Integer action : actions) { recordedActions.add(action); } for (WSSecurityEngineResult result : wsResult) { final Integer actInt = (Integer) result.get(WSSecurityEngineResult.TAG_ACTION); int act = actInt.intValue(); if (act == WSConstants.SC || act == WSConstants.BST) { continue; } if (!recordedActions.remove(actInt)) { return false; } } if (!recordedActions.isEmpty()) { return false; } return true; }
protected ArrayList getEncryptedReferences(List<WSSecurityEngineResult> results) { //there can be multiple ref lists List<WSSecurityEngineResult> encrResults = getResults(results, WSConstants.ENCR); ArrayList refs = new ArrayList(); for (WSSecurityEngineResult engineResult : encrResults) { ArrayList dataRefUris = (ArrayList) engineResult .get(WSSecurityEngineResult.TAG_DATA_REF_URIS); //take only the ref list processing results if (dataRefUris != null) { for (Iterator iterator = dataRefUris.iterator(); iterator .hasNext(); ) { WSDataRef uri = (WSDataRef) iterator.next(); refs.add(uri); } } } return refs; }
private void handleInboundMessage(SOAPMessageContext context) throws WSSecurityException { SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); WSSecurityEngine secEngine = new WSSecurityEngine(); List<WSSecurityEngineResult> results = secEngine.processSecurityHeader( soapPart, null, null, null); if (null == results) { throw new SecurityException("no WS-Security results"); } Timestamp timestamp = null; for (WSSecurityEngineResult result : results) { Timestamp resultTimestamp = (Timestamp) result .get(WSSecurityEngineResult.TAG_TIMESTAMP); if (null != resultTimestamp) { timestamp = resultTimestamp; } } if (null == timestamp) { throw new SecurityException("no WS-Security timestamp"); } }
public static void verifySignedElement(Element elem, WSDocInfo wsDocInfo) throws WSSecurityException { List<WSSecurityEngineResult> signedResults = wsDocInfo.getResultsByTag(WSConstants.SIGN); if (signedResults != null) { for (WSSecurityEngineResult signedResult : signedResults) { @SuppressWarnings("unchecked") List<WSDataRef> dataRefs = (List<WSDataRef>)signedResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS); if (dataRefs != null) { for (WSDataRef dataRef : dataRefs) { if (isElementOrAncestorSigned(elem, dataRef.getProtectedElement())) { return; } } } } } throw new WSSecurityException( WSSecurityException.FAILED_CHECK, "requiredElementNotSigned", new Object[] {elem}); }
public static void verifySignedElement(Element elem, WSDocInfo wsDocInfo) throws WSSecurityException { List<WSSecurityEngineResult> signedResults = wsDocInfo.getResultsByTag(WSConstants.SIGN); if (signedResults != null) { for (WSSecurityEngineResult signedResult : signedResults) { @SuppressWarnings("unchecked") List<WSDataRef> dataRefs = (List<WSDataRef>)signedResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS); if (dataRefs != null) { for (WSDataRef dataRef : dataRefs) { if (isElementOrAncestorSigned(elem, dataRef.getProtectedElement())) { return; } } } } } throw new WSSecurityException( WSSecurityException.FAILED_CHECK, "requiredElementNotSigned", new Object[] {elem}); }
/** * Decrypts the EncryptedKey element and returns the secret that was used. * @param callbackHandler Callback handler to pass to WSS4J framework. * @param crypto To get private key information. * @param encryptedKeyElement The encrypted Key element. * @return The secret as a byte stream. * @throws WSSecurityException If an error is occurred while decrypting the element. */ public static byte[] getDecryptedBytes(CallbackHandler callbackHandler, Crypto crypto, Node encryptedKeyElement) throws WSSecurityException { EncryptedKeyProcessor encryptedKeyProcessor = new EncryptedKeyProcessor(); RequestData requestData = new RequestData(); requestData.setCallbackHandler(callbackHandler); requestData.setDecCrypto(crypto); final WSSConfig cfg = WSSConfig.getNewInstance(); requestData.setWssConfig(cfg); WSDocInfo docInfo = new WSDocInfo(encryptedKeyElement.getOwnerDocument()); List<WSSecurityEngineResult> resultList; resultList = encryptedKeyProcessor.handleToken((Element) encryptedKeyElement, requestData, docInfo); WSSecurityEngineResult wsSecurityEngineResult = resultList.get(0); return (byte[]) wsSecurityEngineResult.get(WSSecurityEngineResult.TAG_SECRET); }