use of org.opensaml.saml.saml2.ecp.Response 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.ecp.Response in project ddf by codice.
the class LogoutRequestService method sendLogoutRequest.
@GET
@Path("/request")
public Response sendLogoutRequest(@QueryParam("EncryptedNameIdTime") String encryptedNameIdTime) {
String nameIdTime = encryptionService.decrypt(encryptedNameIdTime);
String[] nameIdTimeArray = StringUtils.split(nameIdTime, "\n");
if (nameIdTimeArray.length == 2) {
try {
String name = nameIdTimeArray[0];
Long time = Long.parseLong(nameIdTimeArray[1]);
if (System.currentTimeMillis() - time > logOutPageTimeOut) {
String msg = String.format("Logout request was older than %sms old so it was rejected. Please refresh page and request again.", logOutPageTimeOut);
LOGGER.info(msg);
return buildLogoutResponse(msg);
}
logout();
LogoutRequest logoutRequest = logoutMessage.buildLogoutRequest(name, getEntityId());
String relayState = relayStates.encode(name);
return getLogoutRequest(relayState, logoutRequest);
} catch (Exception e) {
String msg = "Failed to create logout request.";
LOGGER.info(msg, e);
return buildLogoutResponse(msg);
}
} else {
String msg = "Failed to decrypt logout request params. Invalid number of params.";
LOGGER.info(msg);
return buildLogoutResponse(msg);
}
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestService method getSamlpPostLogoutRequest.
private Response getSamlpPostLogoutRequest(String relayState, LogoutRequest logoutRequest) throws SimpleSign.SignatureException, WSSecurityException {
LOGGER.debug("Configuring SAML LogoutRequest for POST.");
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
LOGGER.debug("Signing SAML POST LogoutRequest.");
simpleSign.signSamlObject(logoutRequest);
LOGGER.debug("Converting SAML Request to DOM");
String assertionResponse = DOM2Writer.nodeToString(OpenSAMLUtil.toDom(logoutRequest, doc));
String encodedSamlRequest = Base64.getEncoder().encodeToString(assertionResponse.getBytes(StandardCharsets.UTF_8));
String singleLogoutLocation = idpMetadata.getSingleLogoutLocation();
String submitFormUpdated = String.format(submitForm, singleLogoutLocation, SAML_REQUEST, encodedSamlRequest, relayState);
Response.ResponseBuilder ok = Response.ok(submitFormUpdated);
return ok.build();
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LogoutRequestService method getSamlpRedirectLogoutRequest.
private Response getSamlpRedirectLogoutRequest(String relayState, LogoutRequest logoutRequest) throws IOException, SimpleSign.SignatureException, WSSecurityException, URISyntaxException {
LOGGER.debug("Configuring SAML Response for Redirect.");
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
URI location = logoutMessage.signSamlGetRequest(logoutRequest, new URI(idpMetadata.getSingleLogoutLocation()), relayState);
String redirectUpdated = String.format(redirectPage, location.toString());
Response.ResponseBuilder ok = Response.ok(redirectUpdated);
return ok.build();
}
use of org.opensaml.saml.saml2.ecp.Response in project ddf by codice.
the class LoginFilter method createSamlResponse.
/**
* Creates the SAML response that we use for validation against the CXF
* code.
*
* @param inResponseTo
* @param issuer
* @param status
* @return Response
*/
private static Response createSamlResponse(String inResponseTo, String issuer, Status status) {
if (responseBuilder == null) {
responseBuilder = (SAMLObjectBuilder<Response>) builderFactory.getBuilder(Response.DEFAULT_ELEMENT_NAME);
}
Response response = responseBuilder.buildObject();
response.setID(UUID.randomUUID().toString());
response.setIssueInstant(new DateTime());
response.setInResponseTo(inResponseTo);
response.setIssuer(createIssuer(issuer));
response.setStatus(status);
response.setVersion(SAMLVersion.VERSION_20);
return response;
}
Aggregations