Search in sources :

Example 6 with LogoutWrapperImpl

use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.

the class LogoutRequestServiceTest method testSendLogoutRequestGetPostRequest.

@Test
public void testSendLogoutRequestGetPostRequest() {
    String encryptedNameIdWithTime = nameId + "\n" + time;
    when(encryptionService.decrypt(any(String.class))).thenReturn(nameId + "\n" + time);
    when(idpMetadata.getSingleLogoutBinding()).thenReturn(SamlProtocol.POST_BINDING);
    when(idpMetadata.getSingleLogoutLocation()).thenReturn(postLogoutUrl);
    LogoutRequest logoutRequest = new LogoutRequestBuilder().buildObject();
    LogoutWrapper<LogoutRequest> requestLogoutWrapper = new LogoutWrapperImpl<>(logoutRequest);
    when(logoutMessage.buildLogoutRequest(eq(nameId), anyString(), anyList())).thenReturn(requestLogoutWrapper);
    logoutRequestService.setLogoutMessage(logoutMessage);
    Response response = logoutRequestService.sendLogoutRequest(encryptedNameIdWithTime);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    assertTrue("Expected logout url of " + postLogoutUrl, response.getEntity().toString().contains(postLogoutUrl));
}
Also used : Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) LogoutRequestBuilder(org.opensaml.saml.saml2.core.impl.LogoutRequestBuilder) LogoutWrapperImpl(ddf.security.samlp.impl.LogoutWrapperImpl) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with LogoutWrapperImpl

use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.

the class LogoutRequestServiceTest method testPostLogoutRequest.

@Test
public void testPostLogoutRequest() throws Exception {
    String encodedSamlRequest = "encodedSamlRequest";
    String issuerStr = "issuer";
    LogoutRequest logoutRequest = mock(LogoutRequest.class);
    when(logoutRequest.getIssueInstant()).thenReturn(DateTime.now());
    SessionIndex sessionIndex = mock(SessionIndex.class);
    when(sessionIndex.getSessionIndex()).thenReturn(SESSION_INDEX);
    when(logoutRequest.getSessionIndexes()).thenReturn(Collections.singletonList(sessionIndex));
    LogoutWrapper<LogoutRequest> requestLogoutWrapper = new LogoutWrapperImpl<>(logoutRequest);
    when(logoutMessage.extractSamlLogoutRequest(any(String.class))).thenReturn(requestLogoutWrapper);
    Issuer issuer = mock(Issuer.class);
    OpenSAMLUtil.initSamlEngine();
    LogoutResponse logoutResponse = new LogoutResponseBuilder().buildObject();
    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);
    LogoutWrapper<LogoutResponse> responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse);
    when(logoutMessage.buildLogoutResponse(eq(issuerStr), eq(StatusCode.SUCCESS), anyString())).thenReturn(responseLogoutWrapper);
    logoutRequestService.setLogoutMessage(logoutMessage);
    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));
}
Also used : Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) LogoutWrapperImpl(ddf.security.samlp.impl.LogoutWrapperImpl) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) LogoutResponseBuilder(org.opensaml.saml.saml2.core.impl.LogoutResponseBuilder) Issuer(org.opensaml.saml.saml2.core.Issuer) SessionIndex(org.opensaml.saml.saml2.core.SessionIndex) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with LogoutWrapperImpl

use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.

the class LogoutRequestServiceTest method testGetLogoutRequest.

@Test
public void testGetLogoutRequest() throws Exception {
    SamlSecurity samlSecurity = new SamlSecurity();
    String deflatedSamlRequest = samlSecurity.deflateAndBase64Encode(UNENCODED_SAML_REQUEST);
    doReturn(true).when(simpleSign).validateSignature(anyString(), anyString(), anyString(), any());
    initializeLogoutRequestService();
    insertLogoutRequest();
    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));
}
Also used : LogoutWrapper(ddf.security.samlp.LogoutWrapper) Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) LogoutWrapperImpl(ddf.security.samlp.impl.LogoutWrapperImpl) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SamlSecurity(org.codice.ddf.security.jaxrs.impl.SamlSecurity) URI(java.net.URI) Test(org.junit.Test)

Example 9 with LogoutWrapperImpl

use of ddf.security.samlp.impl.LogoutWrapperImpl in project ddf by codice.

the class LogoutRequestServiceTest method testGetLogoutRequestResponseInvalidSignature.

@Test
public void testGetLogoutRequestResponseInvalidSignature() throws Exception {
    SamlSecurity samlSecurity = new SamlSecurity();
    String deflatedSamlResponse = samlSecurity.deflateAndBase64Encode(UNENCODED_SAML_RESPONSE);
    LogoutResponse logoutResponse = mock(LogoutResponse.class);
    LogoutWrapper<LogoutResponse> responseLogoutWrapper = new LogoutWrapperImpl<>(logoutResponse);
    when(logoutMessage.extractSamlLogoutResponse(eq(UNENCODED_SAML_RESPONSE))).thenReturn(responseLogoutWrapper);
    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();
    Response response = lrs.getLogoutRequest(null, deflatedSamlResponse, relayState, SIGNATURE_ALGORITHM, 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));
}
Also used : Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) LogoutWrapperImpl(ddf.security.samlp.impl.LogoutWrapperImpl) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SamlSecurity(org.codice.ddf.security.jaxrs.impl.SamlSecurity) Test(org.junit.Test)

Aggregations

LogoutWrapperImpl (ddf.security.samlp.impl.LogoutWrapperImpl)9 Response (javax.ws.rs.core.Response)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Test (org.junit.Test)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)9 SamlSecurity (org.codice.ddf.security.jaxrs.impl.SamlSecurity)5 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)5 LogoutWrapper (ddf.security.samlp.LogoutWrapper)4 URI (java.net.URI)4 DateTime (org.joda.time.DateTime)3 Issuer (org.opensaml.saml.saml2.core.Issuer)2 LogoutRequestBuilder (org.opensaml.saml.saml2.core.impl.LogoutRequestBuilder)2 SessionIndex (org.opensaml.saml.saml2.core.SessionIndex)1 LogoutResponseBuilder (org.opensaml.saml.saml2.core.impl.LogoutResponseBuilder)1