// the RequestData object
protected void decodeEncryptionParameter(RequestData reqData)
throws WSSecurityException {
Object mc = reqData.getMsgContext();
EncryptionActionToken actionToken = reqData.getEncryptionToken();
if (actionToken == null) {
actionToken = new EncryptionActionToken();
reqData.setEncryptionToken(actionToken);
}
//
// If the following parameters are no used (they return null) then the
// default values of WSS4J are used.
//
String encKeyId = getString(WSHandlerConstants.ENC_KEY_ID, mc);
if (encKeyId != null) {
Integer id = WSHandlerConstants.getKeyIdentifier(encKeyId);
if (id == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
"empty",
"WSHandler: Encryption: unknown key identification"
);
}
int tmp = id;
actionToken.setKeyIdentifierId(tmp);
if (!(tmp == WSConstants.ISSUER_SERIAL
|| tmp == WSConstants.X509_KEY_IDENTIFIER
|| tmp == WSConstants.SKI_KEY_IDENTIFIER
|| tmp == WSConstants.BST_DIRECT_REFERENCE
|| tmp == WSConstants.THUMBPRINT_IDENTIFIER
|| tmp == WSConstants.ENCRYPTED_KEY_SHA1_IDENTIFIER)) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
"empty",
"WSHandler: Encryption: illegal key identification"
);
}
}
String encSymAlgo = getString(WSHandlerConstants.ENC_SYM_ALGO, mc);
actionToken.setSymmetricAlgorithm(encSymAlgo);
String encKeyTransport =
getString(WSHandlerConstants.ENC_KEY_TRANSPORT, mc);
actionToken.setKeyTransportAlgorithm(encKeyTransport);
String derivedKeyReference = getString(WSHandlerConstants.DERIVED_TOKEN_REFERENCE, mc);
actionToken.setDerivedKeyTokenReference(derivedKeyReference);
String derivedKeyIdentifier = getString(WSHandlerConstants.DERIVED_TOKEN_KEY_ID, mc);
if (derivedKeyIdentifier != null) {
Integer id = WSHandlerConstants.getKeyIdentifier(derivedKeyIdentifier);
actionToken.setDerivedKeyIdentifier(id);
}
String derivedKeyLength = getString(WSHandlerConstants.DERIVED_ENCRYPTION_KEY_LENGTH, mc);
if (derivedKeyLength != null) {
try {
int dKL = Integer.parseInt(derivedKeyLength);
if (dKL > 0) {
actionToken.setDerivedKeyLength(dKL);
}
} catch (NumberFormatException e) {
LOG.warn("Error in configuring a derived key length: " + e.getMessage());
}
}
boolean use200512Namespace = decodeUse200512Namespace(reqData);
reqData.setUse200512Namespace(use200512Namespace);
String digestAlgo = getString(WSHandlerConstants.ENC_DIGEST_ALGO, mc);
actionToken.setDigestAlgorithm(digestAlgo);
String mgfAlgo = getString(WSHandlerConstants.ENC_MGF_ALGO, mc);
actionToken.setMgfAlgorithm(mgfAlgo);
String encSymEncKey = getString(WSHandlerConstants.ENC_SYM_ENC_KEY, mc);
if (encSymEncKey != null) {
boolean encSymEndKeyBoolean = Boolean.parseBoolean(encSymEncKey);
actionToken.setEncSymmetricEncryptionKey(encSymEndKeyBoolean);
}
String encUser = getString(WSHandlerConstants.ENCRYPTION_USER, mc);
if (encUser != null) {
actionToken.setUser(encUser);
} else {
actionToken.setUser(reqData.getUsername());
}
if (actionToken.isEncSymmetricEncryptionKey() && actionToken.getUser() == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE,
"empty", "WSHandler: Encryption: no username");
}
handleSpecialUser(reqData);
String encParts = getString(WSHandlerConstants.ENCRYPTION_PARTS, mc);
if (encParts != null) {
splitEncParts(true, encParts, actionToken.getParts(), reqData);
}
encParts = getString(WSHandlerConstants.OPTIONAL_ENCRYPTION_PARTS, mc);
if (encParts != null) {
splitEncParts(false, encParts, actionToken.getParts(), reqData);
}
boolean includeToken = decodeIncludeEncryptionToken(reqData);
actionToken.setIncludeToken(includeToken);
}