Search in sources :

Example 26 with Status

use of org.opensaml.saml.saml1.core.Status in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorResourceTest method shouldNotReturnADtoResponse_WhenFieldsAreMissing_Match.

@Test
public void shouldNotReturnADtoResponse_WhenFieldsAreMissing_Match() throws Exception {
    final String requestId = "requestId";
    final String msaStatusCode = SamlStatusCode.MATCH;
    final Status status = aStatus().withStatusCode(aStatusCode().withSubStatusCode(aStatusCode().withValue(msaStatusCode).build()).withValue(SUCCESS).build()).build();
    final SamlResponseDto samlResponseDto = new SamlResponseDto(Base64.encodeAsString(aValidMatchResponseFromMatchingServiceWithMissingData(requestId, status, TEST_RP_MS)));
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    ErrorStatusDto errorStatusDto = clientResponse.readEntity(ErrorStatusDto.class);
    assertThat(errorStatusDto.getExceptionType()).isEqualTo(ExceptionType.INVALID_SAML);
}
Also used : Status(org.opensaml.saml.saml2.core.Status) MatchingServiceIdaStatus(uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus) StatusBuilder.aStatus(uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus) SamlResponseDto(uk.gov.ida.hub.samlengine.domain.SamlResponseDto) Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) ErrorStatusDto(uk.gov.ida.common.ErrorStatusDto) Test(org.junit.Test)

Example 27 with Status

use of org.opensaml.saml.saml1.core.Status in project verify-hub by alphagov.

the class ProtectiveMonitoringLogFormatter method formatAuthnResponse.

public String formatAuthnResponse(Response samlResponse, Direction direction, Boolean validSignature) {
    Issuer issuer = samlResponse.getIssuer();
    String issuerString = issuer != null ? issuer.getValue() : "";
    Status status = samlResponse.getStatus();
    StatusCode subStatusCode = status.getStatusCode().getStatusCode();
    String subStatus = subStatusCode != null ? subStatusCode.getValue() : "";
    return String.format(AUTHN_RESPONSE, samlResponse.getID(), samlResponse.getInResponseTo(), direction, samlResponse.getDestination(), issuerString, validSignature, status.getStatusCode().getValue(), subStatus, getStatusDetailValues(status));
}
Also used : Status(org.opensaml.saml.saml2.core.Status) Issuer(org.opensaml.saml.saml2.core.Issuer) StatusCode(org.opensaml.saml.saml2.core.StatusCode)

Example 28 with Status

use of org.opensaml.saml.saml1.core.Status in project cxf by apache.

the class SAML2PResponseComponentBuilder method createStatus.

@SuppressWarnings("unchecked")
public static Status createStatus(String statusCodeValue, String statusMessage) {
    if (statusBuilder == null) {
        statusBuilder = (SAMLObjectBuilder<Status>) builderFactory.getBuilder(Status.DEFAULT_ELEMENT_NAME);
    }
    if (statusCodeBuilder == null) {
        statusCodeBuilder = (SAMLObjectBuilder<StatusCode>) builderFactory.getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
    }
    if (statusMessageBuilder == null) {
        statusMessageBuilder = (SAMLObjectBuilder<StatusMessage>) builderFactory.getBuilder(StatusMessage.DEFAULT_ELEMENT_NAME);
    }
    Status status = statusBuilder.buildObject();
    StatusCode statusCode = statusCodeBuilder.buildObject();
    statusCode.setValue(statusCodeValue);
    status.setStatusCode(statusCode);
    if (statusMessage != null) {
        StatusMessage statusMessageObject = statusMessageBuilder.buildObject();
        statusMessageObject.setMessage(statusMessage);
        status.setStatusMessage(statusMessageObject);
    }
    return status;
}
Also used : Status(org.opensaml.saml.saml2.core.Status) StatusCode(org.opensaml.saml.saml2.core.StatusCode) StatusMessage(org.opensaml.saml.saml2.core.StatusMessage)

Example 29 with Status

use of org.opensaml.saml.saml1.core.Status in project cxf by apache.

the class SAMLResponseValidatorTest method createResponse.

private Response createResponse(SubjectConfirmationDataBean subjectConfirmationData, SAML2CallbackHandler callbackHandler) throws Exception {
    Document doc = DOMUtils.createDocument();
    Status status = SAML2PResponseComponentBuilder.createStatus(SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null);
    Response response = SAML2PResponseComponentBuilder.createSAMLResponse("http://cxf.apache.org/saml", "http://cxf.apache.org/issuer", status);
    // Create an AuthenticationAssertion
    SAMLCallback samlCallback = new SAMLCallback();
    SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
    SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
    response.getAssertions().add(assertion.getSaml2());
    Element policyElement = OpenSAMLUtil.toDom(response, doc);
    doc.appendChild(policyElement);
    assertNotNull(policyElement);
    return (Response) OpenSAMLUtil.fromDom(policyElement);
}
Also used : Status(org.opensaml.saml.saml2.core.Status) Response(org.opensaml.saml.saml2.core.Response) Element(org.w3c.dom.Element) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) Document(org.w3c.dom.Document)

Example 30 with Status

use of org.opensaml.saml.saml1.core.Status in project cxf by apache.

the class SAMLResponseValidatorTest method testFutureAuthnInstant.

@org.junit.Test
public void testFutureAuthnInstant() throws Exception {
    Document doc = DOMUtils.createDocument();
    Status status = SAML2PResponseComponentBuilder.createStatus(SAMLProtocolResponseValidator.SAML2_STATUSCODE_SUCCESS, null);
    Response response = SAML2PResponseComponentBuilder.createSAMLResponse("http://cxf.apache.org/saml", "http://cxf.apache.org/issuer", status);
    // Create an AuthenticationAssertion
    SAML2CallbackHandler callbackHandler = new SAML2CallbackHandler();
    callbackHandler.setStatement(SAML2CallbackHandler.Statement.AUTHN);
    callbackHandler.setIssuer("http://cxf.apache.org/issuer");
    callbackHandler.setConfirmationMethod(SAML2Constants.CONF_SENDER_VOUCHES);
    callbackHandler.setAuthnInstant(new DateTime().plusDays(1));
    SAMLCallback samlCallback = new SAMLCallback();
    SAMLUtil.doSAMLCallback(callbackHandler, samlCallback);
    SamlAssertionWrapper assertion = new SamlAssertionWrapper(samlCallback);
    response.getAssertions().add(assertion.getSaml2());
    Element policyElement = OpenSAMLUtil.toDom(response, doc);
    doc.appendChild(policyElement);
    assertNotNull(policyElement);
    Response marshalledResponse = (Response) OpenSAMLUtil.fromDom(policyElement);
    // Validate the Response
    SAMLProtocolResponseValidator validator = new SAMLProtocolResponseValidator();
    try {
        validator.validateSamlResponse(marshalledResponse, null, null);
        fail("Expected failure on an invalid Assertion AuthnInstant");
    } catch (WSSecurityException ex) {
    // expected
    }
}
Also used : Status(org.opensaml.saml.saml2.core.Status) Response(org.opensaml.saml.saml2.core.Response) Element(org.w3c.dom.Element) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) SAMLCallback(org.apache.wss4j.common.saml.SAMLCallback) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Document(org.w3c.dom.Document) DateTime(org.joda.time.DateTime)

Aggregations

Status (org.opensaml.saml.saml2.core.Status)33 Response (org.opensaml.saml.saml2.core.Response)20 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)18 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)18 Document (org.w3c.dom.Document)17 Element (org.w3c.dom.Element)17 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)13 Response (javax.ws.rs.core.Response)8 DateTime (org.joda.time.DateTime)8 Test (org.junit.Test)8 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)8 StatusBuilder.aStatus (uk.gov.ida.saml.core.test.builders.StatusBuilder.aStatus)8 MatchingServiceIdaStatus (uk.gov.ida.saml.hub.transformers.inbound.MatchingServiceIdaStatus)8 InputStream (java.io.InputStream)7 KeyStore (java.security.KeyStore)7 Crypto (org.apache.wss4j.common.crypto.Crypto)7 Merlin (org.apache.wss4j.common.crypto.Merlin)7 SamlResponseDto (uk.gov.ida.hub.samlengine.domain.SamlResponseDto)7 StatusCode (org.opensaml.saml.saml2.core.StatusCode)5 InboundResponseFromMatchingServiceDto (uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto)4