Search in sources :

Example 1 with LogoutResponse

use of org.opensaml.saml.saml2.core.LogoutResponse in project ddf by codice.

the class IdpEndpoint method processPostLogout.

@Override
@POST
@Path("/logout")
public Response processPostLogout(@FormParam(SAML_REQ) final String samlRequest, @FormParam(SAML_RESPONSE) final String samlResponse, @FormParam(RELAY_STATE) final String relayState, @Context final HttpServletRequest request) throws WSSecurityException, IdpException {
    LogoutState logoutState = getLogoutState(request);
    Cookie cookie = getCookie(request);
    try {
        if (samlRequest != null) {
            LogoutRequest logoutRequest = logoutMessage.extractSamlLogoutRequest(RestSecurity.inflateBase64(samlRequest));
            validatePost(request, logoutRequest);
            return handleLogoutRequest(cookie, logoutState, logoutRequest, SamlProtocol.Binding.HTTP_POST, relayState);
        } else if (samlResponse != null) {
            LogoutResponse logoutResponse = logoutMessage.extractSamlLogoutResponse(RestSecurity.inflateBase64(samlResponse));
            String requestId = logoutState != null ? logoutState.getCurrentRequestId() : null;
            validatePost(request, logoutResponse, requestId);
            return handleLogoutResponse(cookie, logoutState, logoutResponse, SamlProtocol.Binding.HTTP_POST);
        }
    } catch (IOException | XMLStreamException e) {
        throw new IdpException("Unable to inflate Saml Object", e);
    } catch (ValidationException e) {
        throw new IdpException("Unable to validate Saml Object", e);
    }
    throw new IdpException("Unable to process logout");
}
Also used : NewCookie(javax.ws.rs.core.NewCookie) Cookie(javax.servlet.http.Cookie) ValidationException(ddf.security.samlp.ValidationException) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) XMLStreamException(javax.xml.stream.XMLStreamException) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with LogoutResponse

use of org.opensaml.saml.saml2.core.LogoutResponse in project ddf by codice.

the class LogoutRequestServiceTest method testPostLogoutRequestResponse.

@Test
public void testPostLogoutRequestResponse() throws Exception {
    String relayState = UUID.randomUUID().toString();
    String encodedSamlResponse = "encodedSamlRequest";
    String issuerStr = "issuer";
    Issuer issuer = mock(Issuer.class);
    LogoutResponse logoutResponse = mock(LogoutResponse.class);
    logoutResponse.setIssuer(issuer);
    when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(logoutResponse);
    when(request.getRequestURL()).thenReturn(new StringBuffer("www.url.com/url"));
    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."));
}
Also used : LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Issuer(org.opensaml.saml.saml2.core.Issuer) Matchers.anyString(org.mockito.Matchers.anyString) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with LogoutResponse

use of org.opensaml.saml.saml2.core.LogoutResponse in project ddf by codice.

the class SamlProtocolTest method testCreateLogoutResponseWithoutInResponseTo.

@Test
public void testCreateLogoutResponseWithoutInResponseTo() {
    LogoutResponse logoutResponse = SamlProtocol.createLogoutResponse(SamlProtocol.createIssuer("myissuer"), SamlProtocol.createStatus("mystatus"), "myid");
    assertEquals("myissuer", logoutResponse.getIssuer().getValue());
    assertEquals("mystatus", logoutResponse.getStatus().getStatusCode().getValue());
    assertEquals("myid", logoutResponse.getID());
    assertNull(logoutResponse.getInResponseTo());
}
Also used : LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Test(org.junit.Test)

Example 4 with LogoutResponse

use of org.opensaml.saml.saml2.core.LogoutResponse in project ddf by codice.

the class LogoutRequestServiceTest method testGetLogoutRequestResponse.

@Test
public void testGetLogoutRequestResponse() throws Exception {
    String signature = "signature";
    String signatureAlgorithm = "sha1";
    String relayState = UUID.randomUUID().toString();
    String deflatedSamlResponse = RestSecurity.deflateAndBase64Encode("deflatedSamlResponse");
    LogoutResponse logoutResponse = mock(LogoutResponse.class);
    when(logoutResponse.getIssueInstant()).thenReturn(new DateTime());
    when(logoutResponse.getVersion()).thenReturn(SAMLVersion.VERSION_20);
    when(logoutResponse.getID()).thenReturn("id");
    when(logoutMessage.extractSamlLogoutResponse(eq("deflatedSamlResponse"))).thenReturn(logoutResponse);
    Response response = logoutRequestService.getLogoutRequest(null, deflatedSamlResponse, relayState, signatureAlgorithm, signature);
    assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
    assertTrue("Expected a successful logout message", response.getLocation().toString().contains("logged+out+successfully."));
}
Also used : LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Response(javax.ws.rs.core.Response) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Matchers.anyString(org.mockito.Matchers.anyString) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with LogoutResponse

use of org.opensaml.saml.saml2.core.LogoutResponse in project ddf by codice.

the class SamlProtocol method createLogoutResponse.

public static LogoutResponse createLogoutResponse(Issuer issuer, Status status, String inResponseTo, String id) {
    LogoutResponse logoutResponse = logoutResponseBuilder.buildObject();
    logoutResponse.setID(id);
    logoutResponse.setIssuer(issuer);
    logoutResponse.setStatus(status);
    if (StringUtils.isNotBlank(inResponseTo)) {
        logoutResponse.setInResponseTo(inResponseTo);
    }
    logoutResponse.setIssueInstant(DateTime.now());
    logoutResponse.setVersion(SAMLVersion.VERSION_20);
    return logoutResponse;
}
Also used : LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse)

Aggregations

LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)11 Test (org.junit.Test)6 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)5 ValidationException (ddf.security.samlp.ValidationException)4 Response (javax.ws.rs.core.Response)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Matchers.anyString (org.mockito.Matchers.anyString)4 IOException (java.io.IOException)3 DateTime (org.joda.time.DateTime)3 Cookie (javax.servlet.http.Cookie)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 NewCookie (javax.ws.rs.core.NewCookie)2 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)2 Issuer (org.opensaml.saml.saml2.core.Issuer)2 SamlValidator (ddf.security.samlp.impl.SamlValidator)1 Produces (javax.ws.rs.Produces)1 LogoutResponseBuilder (org.opensaml.saml.saml2.core.impl.LogoutResponseBuilder)1