Search in sources :

Example 91 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class AuthnRequestFromTransactionValidatorTest method validateRequest_shouldThrowExceptionIfIsDuplicateRequestIdIsPresent.

@Test
public void validateRequest_shouldThrowExceptionIfIsDuplicateRequestIdIsPresent() {
    final String requestId = generateRequestId();
    final String oneIssuerId = "some-issuer-id";
    final String anotherIssuerId = "some-other-issuer-id";
    final AuthnRequest authnRequest = anAuthnRequest().withId(requestId).withIssuer(anIssuer().withIssuerId(oneIssuerId).build()).build();
    validator.validate(authnRequest);
    final AuthnRequest duplicateIdAuthnRequest = anAuthnRequest().withId(requestId).withIssuer(anIssuer().withIssuerId(anotherIssuerId).build()).build();
    validateException(assertThrows(SamlTransformationErrorException.class, () -> validator.validate(duplicateIdAuthnRequest)), SamlTransformationErrorFactory.duplicateRequestId(requestId, duplicateIdAuthnRequest.getIssuer().getValue()));
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) Test(org.junit.jupiter.api.Test)

Example 92 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class AuthnRequestFromTransactionValidatorTest method validate_shouldThrowExceptionIfVersionNumberIsMissing.

@Test
public void validate_shouldThrowExceptionIfVersionNumberIsMissing() {
    AuthnRequest authnRequest = anAuthnRequest().withVersionNumber(null).build();
    validateException(assertThrows(SamlTransformationErrorException.class, () -> validator.validate(authnRequest)), SamlTransformationErrorFactory.missingRequestVersion(authnRequest.getID()));
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) Test(org.junit.jupiter.api.Test)

Example 93 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class AuthnRequestFromTransactionValidatorTest method validateRequest_shouldThrowExceptionIfRequestIsTooOld.

@Test
public void validateRequest_shouldThrowExceptionIfRequestIsTooOld() {
    DateTimeFreezer.freezeTime();
    String requestId = generateRequestId();
    DateTime issueInstant = DateTime.now().minusMinutes(5).minusSeconds(1);
    final AuthnRequest authnRequest = anAuthnRequest().withId(requestId).withIssueInstant(issueInstant).build();
    validateException(assertThrows(SamlTransformationErrorException.class, () -> validator.validate(authnRequest)), SamlTransformationErrorFactory.requestTooOld(requestId, issueInstant.withZone(DateTimeZone.UTC), DateTime.now()));
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 94 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class AuthnRequestFromTransactionValidatorTest method validate_shouldThrowExceptionIfIssueInstantIsMissing.

@Test
public void validate_shouldThrowExceptionIfIssueInstantIsMissing() {
    AuthnRequest authnRequest = anAuthnRequest().withIssueInstant(null).build();
    validateException(assertThrows(SamlTransformationErrorException.class, () -> validator.validate(authnRequest)), SamlTransformationErrorFactory.missingRequestIssueInstant(authnRequest.getID()));
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) Test(org.junit.jupiter.api.Test)

Example 95 with AuthnRequest

use of org.opensaml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class SamlMessageReceiverApiTest method handleRequestPost_shouldLogSamlRequestInCorrectFormat.

@Test
public void handleRequestPost_shouldLogSamlRequestInCorrectFormat() {
    AuthnRequest authnRequest = anAuthnRequest().withIssuer(anIssuer().withIssuerId(ISSUER_ID).build()).withDestination(DESTINATION).build();
    when(samlMessageSignatureValidator.validate(any(AuthnRequest.class), any(QName.class))).thenReturn(SamlValidationResponse.aValidResponse());
    when(stringSamlAuthnRequestTransformer.apply(SAML_REQUEST)).thenReturn(authnRequest);
    when(sessionProxy.createSession(any(SamlAuthnRequestContainerDto.class))).thenReturn(SESSION_ID);
    samlMessageReceiverApi.handleRequestPost(SAML_REQUEST_DTO);
    verify(protectiveMonitoringLogger).logAuthnRequest(authnRequest, Direction.INBOUND, SignatureStatus.VALID_SIGNATURE);
}
Also used : SamlAuthnRequestContainerDto(uk.gov.ida.hub.samlproxy.domain.SamlAuthnRequestContainerDto) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) QName(javax.xml.namespace.QName) Test(org.junit.jupiter.api.Test)

Aggregations

AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)120 Test (org.junit.jupiter.api.Test)35 lombok.val (lombok.val)26 Issuer (org.opensaml.saml.saml2.core.Issuer)21 DateTime (org.joda.time.DateTime)15 AuthnRequest (org.opensaml.saml2.core.AuthnRequest)15 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)15 IdaAuthnRequestFromHub (uk.gov.ida.saml.hub.domain.IdaAuthnRequestFromHub)12 IdaAuthnRequestBuilder.anIdaAuthnRequest (uk.gov.ida.saml.hub.test.builders.IdaAuthnRequestBuilder.anIdaAuthnRequest)12 MessageContext (org.opensaml.messaging.context.MessageContext)10 SAMLObjectBuilder (org.opensaml.saml.common.SAMLObjectBuilder)10 RequestedAuthnContext (org.opensaml.saml.saml2.core.RequestedAuthnContext)9 Document (org.w3c.dom.Document)9 Element (org.w3c.dom.Element)9 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)8 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)8 NameIDPolicy (org.opensaml.saml.saml2.core.NameIDPolicy)8 IOException (java.io.IOException)7 XMLObject (org.opensaml.core.xml.XMLObject)7 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6