use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestInvalidSignature.
@Test
public void testGetLogoutRequestInvalidSignature() throws Exception {
SamlSecurity samlSecurity = new SamlSecurity();
String deflatedSamlRequest = samlSecurity.deflateAndBase64Encode(UNENCODED_SAML_REQUEST);
LogoutRequest logoutRequest = mock(LogoutRequest.class);
LogoutWrapper<LogoutRequest> requestLogoutWrapper = new LogoutWrapperImpl<>(logoutRequest);
when(logoutMessage.extractSamlLogoutRequest(eq(UNENCODED_SAML_REQUEST))).thenReturn(requestLogoutWrapper);
logoutRequestService.setLogoutMessage(logoutMessage);
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.setSamlSecurity(samlSecurity);
lrs.init();
doReturn(new URI(redirectLogoutUrl)).when(logoutMessage).signSamlGetResponse(any(LogoutWrapper.class), any(URI.class), anyString());
insertLogoutRequest();
Response response = lrs.getLogoutRequest(deflatedSamlRequest, null, relayState, SIGNATURE_ALGORITHM, SIGNATURE);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
String msg = UNABLE_TO_VALIDATE_LOGOUT_REQUEST.replaceAll(" ", "+");
assertTrue("Expected message containing " + msg, response.getLocation().getQuery().contains(msg));
}
use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.
the class LogoutRequestServiceTest method testPostLogoutRequestResponse.
@Test
public void testPostLogoutRequestResponse() throws Exception {
String encodedSamlResponse = "encodedSamlRequest";
String issuerStr = "issuer";
Issuer issuer = mock(Issuer.class);
LogoutResponse logoutResponse = mock(LogoutResponse.class);
logoutResponse.setIssuer(issuer);
LogoutWrapper<LogoutResponse> responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse);
when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(responseLogoutWrapper);
logoutRequestService.setLogoutMessage(logoutMessage);
when(logoutResponse.getIssuer()).thenReturn(issuer);
when(logoutResponse.getIssueInstant()).thenReturn(new DateTime());
when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20);
when(logoutResponse.getID()).thenReturn("id");
when(issuer.getValue()).thenReturn(issuerStr);
when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
Response response = logoutRequestService.postLogoutRequest(null, encodedSamlResponse, relayState);
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
assertTrue("Expected a successful logout message", response.getLocation().toString().contains("logged+out+successfully."));
}
use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestResponse.
@Test
public void testGetLogoutRequestResponse() throws Exception {
SamlSecurity samlSecurity = new SamlSecurity();
String deflatedSamlResponse = samlSecurity.deflateAndBase64Encode(UNENCODED_SAML_RESPONSE);
LogoutResponse logoutResponse = mock(LogoutResponse.class);
when(logoutResponse.getIssueInstant()).thenReturn(new DateTime());
when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20);
when(logoutResponse.getID()).thenReturn("id");
LogoutWrapper<LogoutResponse> responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse);
when(logoutMessage.extractSamlLogoutResponse(eq(UNENCODED_SAML_RESPONSE))).thenReturn(responseLogoutWrapper);
logoutRequestService.setLogoutMessage(logoutMessage);
doReturn(true).when(simpleSign).validateSignature(anyString(), anyString(), anyString(), anyString());
Response response = logoutRequestService.getLogoutRequest(null, deflatedSamlResponse, relayState, SIGNATURE_ALGORITHM, SIGNATURE);
initializeLogoutRequestService();
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
assertTrue("Expected a successful logout message", response.getLocation().toString().contains("logged+out+successfully."));
}
use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestNoSessionIndex.
@Test
public void testGetLogoutRequestNoSessionIndex() throws Exception {
SamlSecurity samlSecurity = new SamlSecurity();
String deflatedSamlRequest = samlSecurity.deflateAndBase64Encode(UNENCODED_SAML_REQUEST);
doReturn(true).when(simpleSign).validateSignature(anyString(), anyString(), anyString(), any());
initializeLogoutRequestService();
LogoutRequest logoutRequest = mock(LogoutRequest.class);
LogoutWrapper logoutRequestWrapper = mock(LogoutWrapper.class);
doReturn(logoutRequest).when(logoutRequestWrapper).getMessage();
// No session index
doReturn(Collections.EMPTY_LIST).when(logoutRequest).getSessionIndexes();
doReturn(DateTime.now()).when(logoutRequest).getIssueInstant();
doReturn(SAMLVersion.VERSION_20).when(logoutRequest).getVersion();
doReturn(ID).when(logoutRequest).getID();
doReturn(logoutRequestWrapper).when(logoutMessage).extractSamlLogoutRequest(eq(UNENCODED_SAML_REQUEST));
LogoutResponse logoutResponse = mock(LogoutResponse.class);
LogoutWrapper<LogoutResponse> responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse);
when(logoutMessage.buildLogoutResponse(anyString(), anyString(), anyString())).thenReturn(responseLogoutWrapper);
when(logoutMessage.signSamlGetResponse(any(LogoutWrapper.class), any(URI.class), anyString())).thenReturn(new URI(redirectLogoutUrl));
logoutRequestService.setLogoutMessage(logoutMessage);
Response response = logoutRequestService.getLogoutRequest(deflatedSamlRequest, null, relayState, SIGNATURE_ALGORITHM, SIGNATURE);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertTrue("Expected logout url of " + redirectLogoutUrl, response.getEntity().toString().contains(redirectLogoutUrl));
}
use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.
the class LogoutRequestServiceTest method testSendLogoutRequestGetRedirectRequest.
@Test
public void testSendLogoutRequestGetRedirectRequest() throws Exception {
String encryptedNameIdWithTime = nameId + "\n" + time;
when(encryptionService.decrypt(any(String.class))).thenReturn(nameId + "\n" + time);
LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject();
LogoutWrapper<LogoutRequest> requestLogoutWrapper = new LogoutWrapperImpl<>(logoutRequest);
when(logoutMessage.buildLogoutRequest(eq(nameId), anyString(), anyList())).thenReturn(requestLogoutWrapper);
String logoutUrl = "https://www.logout.url/logout";
when(logoutMessage.signSamlGetRequest(any(LogoutWrapper.class), any(URI.class), anyString())).thenReturn(new URI(logoutUrl));
logoutRequestService.setLogoutMessage(logoutMessage);
when(relayStates.encode(nameId)).thenReturn("token");
Response response = logoutRequestService.sendLogoutRequest(encryptedNameIdWithTime);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertTrue("Expected logout url of " + logoutUrl, response.getEntity().toString().contains(logoutUrl));
}
Aggregations