use of org.opensaml.saml.saml2.core.Response in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestResponseNotParsable.
@Test
public void testGetLogoutRequestResponseNotParsable() throws Exception {
String signature = "signature";
String signatureAlgorithm = "sha1";
String relayState = UUID.randomUUID().toString();
String deflatedSamlResponse = RestSecurity.deflateAndBase64Encode("deflatedSamlResponse");
when(logoutMessage.extractSamlLogoutResponse(eq("deflatedSamlResponse"))).thenReturn(null);
Response response = logoutRequestService.getLogoutRequest(null, deflatedSamlResponse, relayState, signatureAlgorithm, signature);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = "Unable to parse logout response.".replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of org.opensaml.saml.saml2.core.Response in project ddf by codice.
the class LogoutRequestServiceTest method getPostLogoutRequestNotParsable.
@Test
public void getPostLogoutRequestNotParsable() throws Exception {
String relayState = UUID.randomUUID().toString();
String encodedSamlRequest = "encodedSamlRequest";
Response response = logoutRequestService.postLogoutRequest(encodedSamlRequest, null, relayState);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = "Unable to parse logout request.".replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of org.opensaml.saml.saml2.core.Response in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestResponseInvalidSignature.
@Test
public void testGetLogoutRequestResponseInvalidSignature() throws Exception {
String signature = "signature";
String signatureAlgorithm = "sha1";
String relayState = UUID.randomUUID().toString();
String deflatedSamlResponse = RestSecurity.deflateAndBase64Encode("deflatedSamlResponse");
LogoutResponse logoutResponse = mock(LogoutResponse.class);
when(logoutMessage.extractSamlLogoutResponse(eq("deflatedSamlResponse"))).thenReturn(logoutResponse);
LogoutRequestService lrs = new LogoutRequestService(simpleSign, idpMetadata, relayStates);
lrs.setEncryptionService(encryptionService);
lrs.setLogOutPageTimeOut(LOGOUT_PAGE_TIMEOUT);
lrs.setLogoutMessage(logoutMessage);
lrs.setRequest(request);
lrs.setSessionFactory(sessionFactory);
lrs.init();
Response response = lrs.getLogoutRequest(null, deflatedSamlResponse, relayState, signatureAlgorithm, signature);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = "Unable to validate".replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of org.opensaml.saml.saml2.core.Response in project ddf by codice.
the class LogoutRequestServiceTest method getPostLogoutRequest.
@Test
public void getPostLogoutRequest() throws Exception {
String relayState = UUID.randomUUID().toString();
String encodedSamlRequest = "encodedSamlRequest";
String issuerStr = "issuer";
LogoutRequest logoutRequest = mock(LogoutRequest.class);
Issuer issuer = mock(Issuer.class);
OpenSAMLUtil.initSamlEngine();
LogoutResponse logoutResponse = new LogoutResponseBuilder().buildObject();
when(logoutMessage.extractSamlLogoutRequest(any(String.class))).thenReturn(logoutRequest);
when(logoutRequest.getIssuer()).thenReturn(issuer);
when(logoutRequest.getIssueInstant()).thenReturn(new DateTime());
when(logoutRequest.getVersion()).thenReturn(SAMLVersion.VERSION_20);
when(logoutRequest.getID()).thenReturn("id");
when(issuer.getValue()).thenReturn(issuerStr);
when(logoutMessage.buildLogoutResponse(eq(issuerStr), eq(StatusCode.SUCCESS), anyString())).thenReturn(logoutResponse);
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
Response response = logoutRequestService.postLogoutRequest(encodedSamlRequest, null, relayState);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertTrue("Expected logout url of " + postLogoutUrl, response.getEntity().toString().contains(postLogoutUrl));
}
Aggregations