Search in sources :

Example 16 with Status

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;
}
Also used : Status(org.opensaml.saml.saml2.core.Status)

Example 17 with 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());
    }
}
Also used : ValidationException(ddf.security.samlp.impl.ValidationException) LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) SignableXMLObject(org.opensaml.xmlsec.signature.SignableXMLObject) XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPException(javax.xml.soap.SOAPException) SamlValidator(ddf.security.samlp.impl.SamlValidator) SOAPPart(javax.xml.soap.SOAPPart) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 18 with Status

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());
}
Also used : Status(org.opensaml.saml.saml2.core.Status) StatusCode(org.opensaml.saml.saml2.core.StatusCode)

Example 19 with Status

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;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) DateTime(org.joda.time.DateTime)

Example 20 with Status

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();
}
Also used : Status(org.opensaml.saml.saml2.core.Status) TransactionIdaStatus(uk.gov.ida.saml.core.domain.TransactionIdaStatus) Test(org.junit.jupiter.api.Test)

Aggregations

Status (org.opensaml.saml.saml2.core.Status)103 Test (org.junit.jupiter.api.Test)83 Response (org.opensaml.saml.saml2.core.Response)59 StatusCode (org.opensaml.saml.saml2.core.StatusCode)33 IdpIdaStatus (uk.gov.ida.saml.hub.domain.IdpIdaStatus)33 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)27 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)22 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)20 Document (org.w3c.dom.Document)20 TransactionIdaStatus (uk.gov.ida.saml.core.domain.TransactionIdaStatus)20 Element (org.w3c.dom.Element)19 StatusBuilder.aStatus (uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus)19 DateTime (org.joda.time.DateTime)17 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)16 ResponseValidatorTestHelper.createStatus (uk.gov.ida.saml.hub.validators.response.helpers.ResponseValidatorTestHelper.createStatus)16 OpenSamlXmlObjectFactory (uk.gov.ida.saml.core.OpenSamlXmlObjectFactory)14 StatusCodeBuilder.aStatusCode (uk.gov.ida.saml.core.test.builders.StatusCodeBuilder.aStatusCode)14 Crypto (org.apache.wss4j.common.crypto.Crypto)9 SamlStatusCode (uk.gov.ida.saml.core.domain.SamlStatusCode)9 InputStream (java.io.InputStream)8