@SuppressWarnings("deprecation")
public void testSAML2Post() throws Exception {
System.setProperty("picketlink.schema.validate", "true");
String id = IDGenerator.create("ID_");
SAML2Request saml2Request = new SAML2Request();
AuthnRequestType art = saml2Request.createAuthnRequestType(id, employee, identity, employee);
MockCatalinaContext servletContext = new MockCatalinaContext();
// First we go to the employee application
MockCatalinaContextClassLoader mclSPEmp = setupTCL(profile + "/sp/employee");
Thread.currentThread().setContextClassLoader(mclSPEmp);
SPPostFormAuthenticator spEmpl = new SPPostFormAuthenticator();
MockCatalinaContext context = new MockCatalinaContext();
spEmpl.setContainer(context);
spEmpl.testStart();
MockCatalinaRequest catalinaRequest = new MockCatalinaRequest();
MockCatalinaResponse catalinaResponse = new MockCatalinaResponse();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
catalinaResponse.setOutputStream(baos);
LoginConfig loginConfig = new LoginConfig();
spEmpl.authenticate(catalinaRequest, catalinaResponse, loginConfig);
String spResponse = new String(baos.toByteArray());
Document spHTMLResponse = DocumentUtil.getDocument(spResponse);
NodeList nodes = spHTMLResponse.getElementsByTagName("INPUT");
Element inputElement = (Element) nodes.item(0);
String idpResponse = inputElement.getAttributeNode("VALUE").getValue();
@SuppressWarnings("unused")
String relayState = null;
if (nodes.getLength() > 1)
relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();
// Lets call the IDPServlet
MockCatalinaSession session = new MockCatalinaSession();
servletContext = new MockCatalinaContext();
session.setServletContext(servletContext);
IdentityServer server = this.getIdentityServer(session);
servletContext.setAttribute("IDENTITY_SERVER", server);
MockCatalinaContextClassLoader mclIDP = setupTCL(profile + "/idp");
Thread.currentThread().setContextClassLoader(mclIDP);
MockCatalinaRequest request = new MockCatalinaRequest();
request.addHeader("Referer", "http://localhost:8080/employee/");
request.setParameter(GeneralConstants.USERNAME_FIELD, "anil");
request.setParameter(GeneralConstants.PASS_FIELD, "anil");
MockCatalinaResponse response = new MockCatalinaResponse();
baos = new ByteArrayOutputStream();
response.setOutputStream(baos);
context = new MockCatalinaContext();
IDPWebBrowserSSOValve idp = new IDPWebBrowserSSOValve();
idp.setContainer(context);
idp.setSignOutgoingMessages(false);
idp.start();
String samlAuth = DocumentUtil.getDocumentAsString(saml2Request.convert(art));
String samlMessage = Base64.encodeBytes(samlAuth.getBytes());
MockCatalinaRealm realm = new MockCatalinaRealm("anil", "test", new Principal() {
public String getName() {