}
@SuppressWarnings("unchecked")
public Document getResponse(SAML2HandlerRequest request) throws ConfigurationException, ProcessingException {
HTTPContext httpContext = (HTTPContext) request.getContext();
AuthnRequestType art = (AuthnRequestType) request.getSAML2Object();
HttpSession session = BaseSAML2Handler.getHttpSession(request);
Principal userPrincipal = (Principal) session.getAttribute(GeneralConstants.PRINCIPAL_ID);
if (userPrincipal == null)
userPrincipal = httpContext.getRequest().getUserPrincipal();
String assertionConsumerURL = art.getAssertionConsumerServiceURL().toASCIIString();
List<String> roles = (List<String>) session.getAttribute(GeneralConstants.ROLES_ID);
String identityURL = request.getIssuer().getValue();
Map<String, Object> attribs = (Map<String, Object>) request.getOptions().get(GeneralConstants.ATTRIBUTES);
String requestID = art.getID();
Document samlResponseDocument = null;
String authMethod = (String) request.getOptions().get(GeneralConstants.LOGIN_TYPE);
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();