assertion = createSAML20Assertion(assertionId, issuer, appliesTo, keyInfo, claimedAttrs);
samlToken = new SAMLToken(assertion,SAMLJAXBUtil.getJAXBContext(),soapVersion);
} else{
log.log(Level.SEVERE,
LogStringsMessages.WST_0031_UNSUPPORTED_TOKEN_TYPE(tokenType, appliesTo));
throw new WSTrustException(LogStringsMessages.WST_0031_UNSUPPORTED_TOKEN_TYPE(tokenType, appliesTo));
}
// Get the STS's public and private key
final SignatureKeyCallback.DefaultPrivKeyCertRequest request =
new SignatureKeyCallback.DefaultPrivKeyCertRequest();
final Callback skc = new SignatureKeyCallback(request);
final Callback[] callbacks = {skc};
callbackHandler.handle(callbacks);
final PrivateKey stsPrivKey = request.getPrivateKey();
// Sign the assertion with STS's private key
//Element signedAssertion = assertion.sign(request.getX509Certificate(), stsPrivKey);
final SecurityHeaderElement signedAssertion = createSignature(request.getX509Certificate().getPublicKey(),stsPrivKey,samlToken,nsContext);
//javax.xml.bind.Unmarshaller u = eleFac.getContext().createUnmarshaller();
//JAXBElement<AssertionType> aType = u.unmarshal(signedAssertion, AssertionType.class);
//assertion = new com.sun.xml.wss.saml.assertion.saml11.jaxb20.Assertion(aType.getValue());
token = new GenericToken(signedAssertion);
if (stsConfig.getEncryptIssuedToken()){
final String id = "uuid-" + UUID.randomUUID().toString();
final int keysizeInBytes = 32;
final byte[] skey = WSTrustUtil.generateRandomSecret(keysizeInBytes);
final Key key = new SecretKeySpec(skey, "AES");
final KeyInfo encKeyInfo = new KeyInfo();
final EncryptedKey encKey = encryptKey(key, serCert);
encKeyInfo.getContent().add(encKey);
final EncryptedDataType edt = createEncryptedData(id,MessageConstants.AES_BLOCK_ENCRYPTION_256,encKeyInfo,false);
final JAXBEncryptedData jed = new JAXBEncryptedData(edt,new SSEData((SecurityElement)signedAssertion,false,nsContext),soapVersion);
token = new GenericToken(jed);
}else{
token = new GenericToken(signedAssertion);
}
} catch (XWSSecurityException ex){
log.log(Level.SEVERE,
LogStringsMessages.WST_0032_ERROR_CREATING_SAML_ASSERTION(), ex);
throw new WSTrustException(LogStringsMessages.WST_0032_ERROR_CREATING_SAML_ASSERTION(), ex);
}catch (Exception ex) {
log.log(Level.SEVERE,
LogStringsMessages.WST_0032_ERROR_CREATING_SAML_ASSERTION(), ex);
throw new WSTrustException(LogStringsMessages.WST_0032_ERROR_CREATING_SAML_ASSERTION(), ex);
}
return token;
}