AuthenticationTokenPolicy.SAMLAssertionBinding ret =
(AuthenticationTokenPolicy.SAMLAssertionBinding)samlBinding.clone();
if (AuthenticationTokenPolicy.SAMLAssertionBinding.SV_ASSERTION.equals(samlBinding.getAssertionType())) {
if (samlHandler != null) {
SAMLCallback sc = new SAMLCallback();
SecurityUtil.copy(sc.getRuntimeProperties(), fpcontext);
sc.setConfirmationMethod(SAMLCallback.SV_ASSERTION_TYPE);
sc.setSAMLVersion(samlBinding.getSAMLVersion());
Callback[] cbs = new Callback[] {sc};
try {
samlHandler.handle(cbs);
} catch (UnsupportedCallbackException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_0718_EXCEPTION_INVOKING_SAML_HANDLER(), ex);
throw new XWSSecurityException(ex);
} catch (IOException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_0718_EXCEPTION_INVOKING_SAML_HANDLER(), ex);
throw new XWSSecurityException(ex);
}
ret.setAssertion(sc.getAssertionElement());
ret.setAssertion(sc.getAssertionReader());
ret.setAuthorityBinding(sc.getAuthorityBindingElement());
ret.setSAMLVersion(sc.getSAMLVersion());
}else {
log.log(Level.SEVERE, LogStringsMessages.WSS_0717_NO_SAML_CALLBACK_HANDLER());
throw new XWSSecurityException(
new UnsupportedCallbackException(null, "A Required SAML Callback Handler was not specified in configuration : Cannot Populate SAML Assertion"));
}
} else {
if (samlHandler != null) {
SAMLCallback sc = new SAMLCallback();
SecurityUtil.copy(sc.getRuntimeProperties(), fpcontext);
sc.setConfirmationMethod(SAMLCallback.HOK_ASSERTION_TYPE);
sc.setSAMLVersion(samlBinding.getSAMLVersion());
Callback[] cbs = new Callback[] {sc};
try {
samlHandler.handle(cbs);
} catch (IOException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_0718_EXCEPTION_INVOKING_SAML_HANDLER(), ex);
throw new XWSSecurityException(ex);
} catch (UnsupportedCallbackException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_0718_EXCEPTION_INVOKING_SAML_HANDLER(), ex);
throw new XWSSecurityException(ex);
}
ret.setAssertion(sc.getAssertionElement());
ret.setAuthorityBinding(sc.getAuthorityBindingElement());
ret.setAssertion(sc.getAssertionReader());
PrivateKeyBinding pkBinding = (PrivateKeyBinding) ret.newPrivateKeyBinding();
PrivateKey key = getPrivateKey(fpcontext, this.myAlias);
pkBinding.setPrivateKey(key);
ret.setAssertionId(sc.getAssertionId());
ret.setSAMLVersion(sc.getSAMLVersion());
} else {
log.log(Level.SEVERE, LogStringsMessages.WSS_0717_NO_SAML_CALLBACK_HANDLER());
throw new XWSSecurityException(
new UnsupportedCallbackException(
null, "A Required SAML Callback Handler was not specified in configuration : Cannot Populate SAML Assertion"));