byte[] secret = null;
byte[] entropyBytes = null;
long keySize = 0;
boolean computedKey = false;
KeyRequirements keyRequirements = tokenParameters.getKeyRequirements();
TokenRequirements tokenRequirements = tokenParameters.getTokenRequirements();
LOG.fine("Handling token of type: " + tokenRequirements.getTokenType());
if (STSConstants.SYMMETRIC_KEY_KEYTYPE.equals(keyRequirements.getKeyType())) {
SymmetricKeyHandler keyHandler = new SymmetricKeyHandler(tokenParameters);
keyHandler.createSymmetricKey();
secret = keyHandler.getSecret();
entropyBytes = keyHandler.getEntropyBytes();
keySize = keyHandler.getKeySize();
computedKey = keyHandler.isComputedKey();
}
try {
Document doc = DOMUtils.createDocument();
AssertionWrapper assertion = createSamlToken(tokenParameters, secret, doc);
Element token = assertion.toDOM(doc);
// set the token in cache (only if the token is signed)
byte[] signatureValue = assertion.getSignatureValue();
if (tokenParameters.getTokenStore() != null && signatureValue != null
&& signatureValue.length > 0) {
Date expires = new Date();
long currentTime = expires.getTime();
expires.setTime(currentTime + (conditionsProvider.getLifetime() * 1000L));
SecurityToken securityToken = new SecurityToken(assertion.getId(), null, expires);
securityToken.setToken(token);
securityToken.setPrincipal(tokenParameters.getPrincipal());
Properties props = new Properties();
securityToken.setProperties(props);
if (tokenParameters.getRealm() != null) {
props.setProperty(STSConstants.TOKEN_REALM, tokenParameters.getRealm());
}
// Handle Renewing logic
Renewing renewing = tokenParameters.getTokenRequirements().getRenewing();
if (renewing != null) {
props.put(
STSConstants.TOKEN_RENEWING_ALLOW,
String.valueOf(renewing.isAllowRenewing())
);
props.put(
STSConstants.TOKEN_RENEWING_ALLOW_AFTER_EXPIRY,
String.valueOf(renewing.isAllowRenewingAfterExpiry())
);
} else {
props.setProperty(STSConstants.TOKEN_RENEWING_ALLOW, "true");
props.setProperty(STSConstants.TOKEN_RENEWING_ALLOW_AFTER_EXPIRY, "false");
}
int hash = Arrays.hashCode(signatureValue);
securityToken.setTokenHash(hash);
String identifier = Integer.toString(hash);
tokenParameters.getTokenStore().add(identifier, securityToken);
}
TokenProviderResponse response = new TokenProviderResponse();
response.setToken(token);
String tokenType = tokenRequirements.getTokenType();
if (WSConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType)
|| WSConstants.SAML2_NS.equals(tokenType)) {
response.setTokenId(token.getAttributeNS(null, "ID"));
} else {
response.setTokenId(token.getAttributeNS(null, "AssertionID"));