logger.trace("AssertionConsumerURL=" + assertionConsumerURL);
ResponseType responseType = null;
SAML2Response saml2Response = new SAML2Response();
// Create a response type
String id = IDGenerator.create("ID_");
IssuerInfoHolder issuerHolder = new IssuerInfoHolder(identityURL);
issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());
IDPInfoHolder idp = new IDPInfoHolder();
idp.setNameIDFormatValue(userPrincipal.getName());
idp.setNameIDFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());
String assertionID = (String) session.getAttribute(GeneralConstants.ASSERTION_ID);
if (assertionID != null) {
// Just renew the assertion
AssertionType latestAssertion = (AssertionType) session.getAttribute(GeneralConstants.ASSERTION);
if (latestAssertion != null)
idp.setAssertion(latestAssertion);
}
SPInfoHolder sp = new SPInfoHolder();
sp.setResponseDestinationURI(assertionConsumerURL);
sp.setRequestID(requestID);
sp.setIssuer(art.getIssuer().getValue());
responseType = saml2Response.createResponseType(id, sp, idp, issuerHolder);
// Add information on the roles
AssertionType assertion = responseType.getAssertions().get(0).getAssertion();
// Create an AuthnStatementType
if (handlerConfig.getParameter(DISABLE_AUTHN_STATEMENT) == null) {
String authContextRef = JBossSAMLURIConstants.AC_PASSWORD.get();
if (StringUtil.isNotNull(authMethod))
authContextRef = authMethod;
AuthnStatementType authnStatement = StatementUtil.createAuthnStatement(XMLTimeUtil.getIssueInstant(),
authContextRef);
authnStatement.setSessionIndex(assertion.getID());
assertion.addStatement(authnStatement);
}
if (handlerConfig.getParameter(DISABLE_SENDING_ROLES) == null && (roles != null && !roles.isEmpty())) {
AttributeStatementType attrStatement = null;
if(handlerConfig.getParameter(USE_MULTI_VALUED_ROLES) != null){
attrStatement = StatementUtil.createAttributeStatementForRoles(roles,true);
}else {
attrStatement = StatementUtil.createAttributeStatement(roles);
}
if(attrStatement != null){
assertion.addStatement(attrStatement);
}
}
// Add in the attributes information
if (attribs != null && attribs.size() > 0) {
AttributeStatementType attStatement = StatementUtil.createAttributeStatement(attribs);
assertion.addStatement(attStatement);
}
// Add assertion to the session
session.setAttribute(GeneralConstants.ASSERTION, assertion);
Map<String, Object> requestOptions = request.getOptions();
PicketLinkAuditHelper auditHelper = (PicketLinkAuditHelper) requestOptions.get(GeneralConstants.AUDIT_HELPER);
if (auditHelper != null) {
PicketLinkAuditEvent auditEvent = new PicketLinkAuditEvent(AuditLevel.INFO);
auditEvent.setWhoIsAuditing((String) requestOptions.get(GeneralConstants.CONTEXT_PATH));
auditEvent.setType(PicketLinkAuditEventType.CREATED_ASSERTION);
auditEvent.setAssertionID(id);
auditHelper.audit(auditEvent);
}
try {
samlResponseDocument = saml2Response.convert(responseType);
if (logger.isTraceEnabled()) {
logger.trace("SAML Response Document: " + DocumentUtil.asString(samlResponseDocument));
}
} catch (Exception e) {