* @throws ProcessingException
*/
protected ResponseType getResponse(Request request, Principal userPrincipal)
throws ParsingException, ConfigurationException, ProcessingException
{
ResponseType responseType = null;
String samlMessage = getSAMLMessage(request);
InputStream is = RedirectBindingUtil.base64DeflateDecode(samlMessage);
SAML2Request saml2Request = new SAML2Request();
AuthnRequestType authnRequestType = null;
try
{
authnRequestType = saml2Request.getAuthnRequestType(is);
}
catch (JAXBException e2)
{
throw new ParsingException(e2);
}
catch (SAXException e2)
{
throw new ParsingException(e2);
}
if(authnRequestType == null)
throw new IllegalStateException("AuthnRequest is null");
if(log.isTraceEnabled())
{
StringWriter sw = new StringWriter();
try
{
saml2Request.marshall(authnRequestType, sw);
}
catch (SAXException e)
{
log.trace(e);
}
catch (JAXBException e)
{
log.trace(e);
}
log.trace("IDPRedirectValve::AuthnRequest="+sw.toString());
}
SAML2Response saml2Response = new SAML2Response();
//Create a response type
String id = IDGenerator.create("ID_");
IssuerInfoHolder issuerHolder = new IssuerInfoHolder(this.identityURL);
issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());
IDPInfoHolder idp = new IDPInfoHolder();
idp.setNameIDFormatValue(userPrincipal.getName());
idp.setNameIDFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());
SPInfoHolder sp = new SPInfoHolder();
sp.setResponseDestinationURI(authnRequestType.getAssertionConsumerServiceURL());
responseType = saml2Response.createResponseType(id, sp, idp, issuerHolder);
//Add information on the roles
List<String> roles = rg.generateRoles(userPrincipal);
AssertionType assertion = (AssertionType) responseType.getAssertionOrEncryptedAssertion().get(0);
AttributeStatementType attrStatement = saml2Response.createAttributeStatement(roles);
assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement().add(attrStatement);
//Add timed conditions