MockCatalinaSession session = new MockCatalinaSession();
MockCatalinaContextClassLoader mclIDP = setupTCL(profile + "/idp");
Thread.currentThread().setContextClassLoader(mclIDP);
MockCatalinaContext catalinaContext = new MockCatalinaContext();
session.setServletContext(catalinaContext);
IdentityServer server = this.getIdentityServer(session);
catalinaContext.setAttribute("IDENTITY_SERVER", server);
IDPWebBrowserSSOValve idp = new IDPWebBrowserSSOValve();
idp.setContainer(catalinaContext);
idp.setSignOutgoingMessages(false);
idp.setIgnoreIncomingSignatures(true);
idp.setStrictPostBinding(false);
idp.start();
// Assume that we already have the principal and roles set in the session
MockCatalinaRealm realm = new MockCatalinaRealm("anil", "test", new Principal() {
public String getName() {
return "anil";
}
});
List<String> roles = new ArrayList<String>();
roles.add("manager");
roles.add("employee");
List<String> rolesList = new ArrayList<String>();
rolesList.add("manager");
MockCatalinaRequest request = new MockCatalinaRequest();
session.clear();
request.setSession(session);
request.addHeader("Referer", sales);
GenericPrincipal genericPrincipal = new GenericPrincipal(realm, "anil", "test", roles);
request.setUserPrincipal(genericPrincipal);
//We start the workflow with the sales application sending a logout request
String samlMessage = RedirectBindingUtil.deflateBase64Encode(createLogOutRequest(sales).getBytes());
request.setParameter("SAMLRequest", samlMessage);
MockCatalinaResponse response = new MockCatalinaResponse();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.setWriter(new PrintWriter(baos));
// The IDP is preloaded with 2 participants : "http://localhost:8080/sales/"
// and "http://localhost:8080/employee"
// Lets start the workflow with get
request.setMethod("GET");
idp.invoke(request, response);
String redirectStr = response.redirectString;
String destination = redirectStr.substring(0, redirectStr.indexOf(SAML_REQUEST_KEY) - 1);
String relayState = redirectStr.substring(redirectStr.indexOf(RELAY_STATE_KEY) + RELAY_STATE_KEY.length());
String logoutRequest = redirectStr.substring(redirectStr.indexOf(SAML_REQUEST_KEY) + SAML_REQUEST_KEY.length(),
redirectStr.indexOf(RELAY_STATE_KEY) - 1);
InputStream stream = RedirectBindingUtil.urlBase64DeflateDecode(logoutRequest);
SAML2Request saml2Request = new SAML2Request();
LogoutRequestType lor = (LogoutRequestType) saml2Request.getRequestType(stream);
assertEquals("Match Employee URL", employee, destination);
assertEquals("Destination exists", employee, lor.getDestination().toString());
// IDP has sent a LogOutRequest which we feed to SPRedirectFormAuthenticator for Employee
MockCatalinaContextClassLoader mclSPEmp = setupTCL(profile + "/sp/employee");
Thread.currentThread().setContextClassLoader(mclSPEmp);
MockCatalinaContext context = new MockCatalinaContext();
context.setRealm(realm);
session.setServletContext(context);
SPRedirectFormAuthenticator sp = new SPRedirectFormAuthenticator();
sp.setContainer(context);
sp.testStart();