String identifier = Base64.encode(encodedBytes);
SecretKeyCallbackHandler secretKeyCallbackHandler = new SecretKeyCallbackHandler();
secretKeyCallbackHandler.addSecretKey(identifier, keyData);
Element securityHeader = WSSecurityUtil.getSecurityHeader(signedDoc, null);
AlgorithmSuite algorithmSuite = createAlgorithmSuite();
WSSecurityEngine secEngine = new WSSecurityEngine();
RequestData data = new RequestData();
SignatureActionToken actionToken = new SignatureActionToken();
actionToken.setCrypto(crypto);
data.setSignatureToken(actionToken);
data.setCallbackHandler(secretKeyCallbackHandler);
data.setAlgorithmSuite(algorithmSuite);
try {
secEngine.processSecurityHeader(securityHeader, data);
fail("Expected failure as HMAC-SHA1 is not allowed");
} catch (WSSecurityException ex) {
// expected
}
algorithmSuite.addSignatureMethod(WSConstants.HMAC_SHA1);
secEngine.processSecurityHeader(securityHeader, data);
algorithmSuite.setMinimumSymmetricKeyLength(256);
try {
secEngine.processSecurityHeader(securityHeader, data);
fail("Expected failure as a 128 bit key is not allowed");
} catch (WSSecurityException ex) {
// expected
}
algorithmSuite.setMinimumSymmetricKeyLength(64);
algorithmSuite.setMaximumSymmetricKeyLength(120);
try {
secEngine.processSecurityHeader(securityHeader, data);
fail("Expected failure as a 128 bit key is not allowed");
} catch (WSSecurityException ex) {
// expected