use of org.opensaml.saml.saml2.core.Status in project ddf by codice.
the class SamlProtocol method createStatus.
public static Status createStatus(String statusValue) {
Status status = statusBuilder.buildObject();
status.setStatusCode(createStatusCode(statusValue));
return status;
}
use of org.opensaml.saml.saml2.core.Status in project ddf by codice.
the class LogoutRequestService method soapLogoutRequest.
@POST
@Consumes({ "text/xml", "application/soap+xml" })
public Response soapLogoutRequest(InputStream body, @Context HttpServletRequest request) {
XMLObject xmlObject;
try {
String bodyString = IOUtils.toString(body, StandardCharsets.UTF_8);
SOAPPart soapMessage = SamlProtocol.parseSoapMessage(bodyString);
xmlObject = SamlProtocol.getXmlObjectFromNode(soapMessage.getEnvelope().getBody().getFirstChild());
if (!(xmlObject instanceof LogoutRequest)) {
LOGGER.info(UNABLE_TO_PARSE_LOGOUT_REQUEST);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Type of object is {}", xmlObject == null ? "null" : xmlObject.getSchemaType());
}
return Response.serverError().build();
}
} catch (SOAPException | XMLStreamException | IOException | WSSecurityException e) {
LOGGER.debug("Error parsing input", e);
return Response.serverError().build();
}
LogoutRequest logoutRequest = (LogoutRequest) xmlObject;
if (logoutMessage == null) {
LOGGER.info("Logout message not available yet");
return Response.serverError().build();
}
// Pre-build response with success status
LogoutWrapper<LogoutResponse> logoutResponse = logoutMessage.buildLogoutResponse(logoutRequest.getIssuer().getValue(), StatusCode.SUCCESS, logoutRequest.getID());
try {
if (!validateSignature(logoutRequest)) {
return getSamlpSoapLogoutResponse(logoutResponse, StatusCode.AUTHN_FAILED, null);
}
new SamlValidator.Builder(simpleSign).buildAndValidate(this.request.getRequestURL().toString(), SamlProtocol.Binding.HTTP_POST, logoutRequest);
httpSessionInvalidator.invalidateSession(logoutRequest.getNameID().getValue(), this::extractSubject);
securityLogger.audit("Subject logged out by backchannel request: {}", logoutRequest.getNameID().getValue());
return getSamlpSoapLogoutResponse(logoutResponse);
} catch (ValidationException e) {
LOGGER.info(UNABLE_TO_VALIDATE_LOGOUT_REQUEST, e);
return getSamlpSoapLogoutResponse(logoutResponse, StatusCode.RESPONDER, e.getMessage());
}
}
use of org.opensaml.saml.saml2.core.Status in project ddf by codice.
the class LogoutMessageImpl method buildLogoutResponse.
@Override
public LogoutWrapper<LogoutResponse> buildLogoutResponse(String issuerOrEntityId, String topLevelStatusCode, String secondLevelStatusCode, String inResponseTo) {
Validate.notNull(issuerOrEntityId, ISSUER_CANNOT_BE_NULL_MSG);
Validate.notNull(topLevelStatusCode, "Top level Status Code cannot be null");
Validate.notNull(secondLevelStatusCode, "Second level Status Code cannot be null");
Status status = SamlProtocol.createStatus(topLevelStatusCode);
StatusCode statusCode = SamlProtocol.createStatusCode(secondLevelStatusCode);
status.getStatusCode().setStatusCode(statusCode);
return SamlProtocol.createLogoutResponse(SamlProtocol.createIssuer(issuerOrEntityId), status, inResponseTo, generateId());
}
use of org.opensaml.saml.saml2.core.Status in project ddf by codice.
the class SamlAssertionValidatorImpl 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;
}
use of org.opensaml.saml.saml2.core.Status in project verify-hub by alphagov.
the class TransactionIdaStatusMarshallerTest method toSamlStatus_shouldTransformAuthnFailedWithNoSubStatus.
@Test
public void toSamlStatus_shouldTransformAuthnFailedWithNoSubStatus() {
Status transformedStatus = marshaller.toSamlStatus(TransactionIdaStatus.AuthenticationFailed);
assertThat(transformedStatus.getStatusCode().getValue()).isEqualTo(StatusCode.RESPONDER);
assertThat(transformedStatus.getStatusCode().getStatusCode().getValue()).isEqualTo(StatusCode.AUTHN_FAILED);
assertThat(transformedStatus.getStatusCode().getStatusCode().getStatusCode()).isNull();
}
Aggregations