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
if (tokenParameters.getTokenStore() != null) {
SecurityToken securityToken = new SecurityToken(assertion.getId());
securityToken.setToken(token);
securityToken.setPrincipal(tokenParameters.getPrincipal());
int hash = 0;
byte[] signatureValue = assertion.getSignatureValue();
if (signatureValue != null && signatureValue.length > 0) {
hash = Arrays.hashCode(signatureValue);
securityToken.setAssociatedHash(hash);
}
if (tokenParameters.getRealm() != null) {
Properties props = securityToken.getProperties();
if (props == null) {
props = new Properties();
}
props.setProperty(STSConstants.TOKEN_REALM, tokenParameters.getRealm());
securityToken.setProperties(props);
}
Integer timeToLive = (int)(conditionsProvider.getLifetime() * 1000);
tokenParameters.getTokenStore().add(securityToken, timeToLive);
}
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.getAttribute("ID"));
} else {
response.setTokenId(token.getAttribute("AssertionID"));