SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext, issuerInfo.getIssuer(), docHolder,
SAML2Handler.HANDLER_TYPE.SP);
request.setTypeOfRequestToBeGenerated(GENERATE_REQUEST_TYPE.AUTH);
SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
handler.generateSAMLRequest(request, response);
Document samlReq = response.getResultingDocument();
SAMLParser parser = new SAMLParser();
AuthnRequestType authnRequest = (AuthnRequestType) parser.parse(DocumentUtil.getNodeAsStream(samlReq));
NameIDPolicyType nameIDPolicy = authnRequest.getNameIDPolicy();
assertEquals(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get(), nameIDPolicy.getFormat().toString());
ProviderType idpType = new IDPType();
chainOptions = new HashMap<String, Object>();
chainOptions.put(GeneralConstants.CONFIGURATION, idpType);
chainConfig.set(chainOptions);
// Initialize the handler
handler.initChainConfig(chainConfig);
handler.initHandlerConfig(handlerConfig);
IdentityServer identityServer = new IdentityServer();
servletContext.setAttribute(GeneralConstants.IDENTITY_SERVER,identityServer);
//Add roles to session to be picked up by the handler
List<String> roles = new ArrayList<String>();
roles.add("role1");
roles.add("role2");
session.setAttribute(GeneralConstants.ROLES_ID,roles);
httpContext = new HTTPContext(servletRequest, servletResponse, servletContext);
docHolder = new SAMLDocumentHolder(authnRequest, null);
request = new DefaultSAML2HandlerRequest(httpContext, issuerInfo.getIssuer(), docHolder,
SAML2Handler.HANDLER_TYPE.IDP);
PicketLinkCoreSTS sts = PicketLinkCoreSTS.instance();
sts.installDefaultConfiguration(null);
handler.handleRequestType(request,response);
samlReq = response.getResultingDocument();
parser = new SAMLParser();
ResponseType responseType = (ResponseType) parser.parse(DocumentUtil.getNodeAsStream(samlReq));
AssertionType assertion = responseType.getAssertions().get(0).getAssertion();
assertNotNull(assertion);