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");
}
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."));
}
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());
}
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."));
}
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;
}
Aggregations