use of org.opensaml.saml.saml2.ecp.RelayState in project ddf by codice.
the class LogoutRequestServiceTest method testGetLogoutRequestNotParsable.
@Test
public void testGetLogoutRequestNotParsable() throws Exception {
String signature = "signature";
String signatureAlgorithm = "sha1";
String relayState = UUID.randomUUID().toString();
String deflatedSamlRequest = RestSecurity.deflateAndBase64Encode("deflatedSamlRequest");
when(logoutMessage.extractSamlLogoutRequest(eq("deflatedSamlRequest"))).thenReturn(null);
Response response = logoutRequestService.getLogoutRequest(deflatedSamlRequest, null, relayState, signatureAlgorithm, signature);
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.ecp.RelayState in project ddf by codice.
the class LogoutRequestServiceTest method testPostLogoutRequestResponseNotParsable.
@Test
public void testPostLogoutRequestResponseNotParsable() throws Exception {
String relayState = UUID.randomUUID().toString();
String encodedSamlResponse = "encodedSamlRequest";
when(logoutMessage.extractSamlLogoutResponse(any(String.class))).thenReturn(null);
Response response = logoutRequestService.postLogoutRequest(null, encodedSamlResponse, relayState);
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.ecp.RelayState 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.ecp.RelayState in project ddf by codice.
the class IdpHandler method doHttpRedirectBinding.
private void doHttpRedirectBinding(HttpServletRequest request, HttpServletResponse response) throws ServletException {
String redirectUrl;
String idpRequest = null;
String relayState = createRelayState(request);
try {
IDPSSODescriptor idpssoDescriptor = idpMetadata.getDescriptor();
if (idpssoDescriptor == null) {
throw new ServletException("IdP metadata is missing. No IDPSSODescriptor present.");
}
String queryParams = String.format("SAMLRequest=%s&RelayState=%s", encodeAuthnRequest(createAndSignAuthnRequest(false, idpssoDescriptor.getWantAuthnRequestsSigned()), false), URLEncoder.encode(relayState, "UTF-8"));
idpRequest = idpMetadata.getSingleSignOnLocation() + "?" + queryParams;
UriBuilder idpUri = new UriBuilderImpl(new URI(idpRequest));
simpleSign.signUriString(queryParams, idpUri);
redirectUrl = idpUri.build().toString();
} catch (UnsupportedEncodingException e) {
LOGGER.info("Unable to encode relay state: {}", relayState, e);
throw new ServletException("Unable to create return location");
} catch (SimpleSign.SignatureException e) {
String msg = "Unable to sign request";
LOGGER.info(msg, e);
throw new ServletException(msg);
} catch (URISyntaxException e) {
LOGGER.info("Unable to parse IDP request location: {}", idpRequest, e);
throw new ServletException("Unable to determine IDP location.");
}
try {
response.sendRedirect(redirectUrl);
response.flushBuffer();
} catch (IOException e) {
LOGGER.info("Unable to redirect AuthnRequest to {}", redirectUrl, e);
throw new ServletException("Unable to redirect to IdP");
}
}
use of org.opensaml.saml.saml2.ecp.RelayState 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."));
}
Aggregations