}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof SAMLCallback) {
SAMLCallback callback = (SAMLCallback) callbacks[i];
// Set the Subject
if (subjectBean != null) {
callback.setSubject(subjectBean);
}
// Set the token Type.
TokenRequirements tokenRequirements = tokenParameters.getTokenRequirements();
String tokenType = tokenRequirements.getTokenType();
boolean saml1 = false;
if (WSConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType)
|| WSConstants.SAML2_NS.equals(tokenType)) {
callback.setSamlVersion(SAMLVersion.VERSION_20);
} else {
callback.setSamlVersion(SAMLVersion.VERSION_11);
saml1 = true;
setSubjectOnBeans();
}
// Set the issuer
if (issuer == null) {
STSPropertiesMBean stsProperties = tokenParameters.getStsProperties();
callback.setIssuer(stsProperties.getIssuer());
} else {
callback.setIssuer(issuer);
}
// Set the statements
boolean statementAdded = false;
if (attributeBeans != null && !attributeBeans.isEmpty()) {
callback.setAttributeStatementData(attributeBeans);
statementAdded = true;
}
if (authBeans != null && !authBeans.isEmpty()) {
callback.setAuthenticationStatementData(authBeans);
statementAdded = true;
}
if (authDecisionBeans != null && !authDecisionBeans.isEmpty()) {
callback.setAuthDecisionStatementData(authDecisionBeans);
statementAdded = true;
}
// If SAML 1.1 we *must* add a Statement
if (saml1 && !statementAdded) {
AttributeStatementBean defaultStatement =
new DefaultAttributeStatementProvider().getStatement(tokenParameters);
defaultStatement.setSubject(subjectBean);
callback.setAttributeStatementData(Collections.singletonList(defaultStatement));
}
// Set the conditions
callback.setConditions(conditionsBean);
}
}
}