Element tokenElement = (Element)securityToken.getToken();
String namespace = tokenElement.getNamespaceURI();
String localname = tokenElement.getLocalName();
if ((token.isUseSamlVersion11Profile10() || token.isUseSamlVersion11Profile11())
&& WSConstants.SAML_NS.equals(namespace) && "Assertion".equals(localname)) {
return new AssertionWrapper(tokenElement);
} else if (token.isUseSamlVersion20Profile11()
&& WSConstants.SAML2_NS.equals(namespace) && "Assertion".equals(localname)) {
return new AssertionWrapper(tokenElement);
}
}
CallbackHandler handler = null;
if (o instanceof CallbackHandler) {
handler = (CallbackHandler)o;
} else if (o instanceof String) {
try {
handler = (CallbackHandler)ClassLoaderUtils
.loadClass((String)o, this.getClass()).newInstance();
} catch (Exception e) {
handler = null;
}
}
if (handler == null) {
policyNotAsserted(token, "No SAML CallbackHandler available");
return null;
}
SAMLParms samlParms = new SAMLParms();
samlParms.setCallbackHandler(handler);
if (token.isUseSamlVersion11Profile10() || token.isUseSamlVersion11Profile11()) {
samlParms.setSAMLVersion(SAMLVersion.VERSION_11);
} else if (token.isUseSamlVersion20Profile11()) {
samlParms.setSAMLVersion(SAMLVersion.VERSION_20);
}
info.setAsserted(true);
AssertionWrapper assertion = new AssertionWrapper(samlParms);
boolean selfSignAssertion =
MessageUtils.getContextualBoolean(
message, SecurityConstants.SELF_SIGN_SAML_ASSERTION, false
);
if (selfSignAssertion) {
Crypto crypto = getSignatureCrypto(null);
String userNameKey = SecurityConstants.SIGNATURE_USERNAME;
String user = (String)message.getContextualProperty(userNameKey);
if (crypto != null && StringUtils.isEmpty(user)) {
try {
user = crypto.getDefaultX509Identifier();
} catch (WSSecurityException e1) {
throw new Fault(e1);
}
}
if (StringUtils.isEmpty(user)) {
policyNotAsserted(token, "No username found.");
return null;
}
String password = getPassword(user, token, WSPasswordCallback.SIGNATURE);
// TODO configure using a KeyValue here
assertion.signAssertion(user, password, crypto, false);
}
return assertion;
}