Search in sources :

Example 71 with Assertion

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

the class IPAddressValidatorTest method validate_shouldNotThrowWhenFirstAttributeStatementContainsAnIPAddressAttribute.

@Test
public void validate_shouldNotThrowWhenFirstAttributeStatementContainsAnIPAddressAttribute() throws Exception {
    Assertion assertion = anAssertion().addAttributeStatement(anAttributeStatement().addAttribute(IPAddressAttributeBuilder.anIPAddress().build()).build()).buildUnencrypted();
    validator.validate(assertion);
}
Also used : AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) Test(org.junit.jupiter.api.Test)

Example 72 with Assertion

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

the class IPAddressValidatorTest method validate_shouldThrowWhenAssertionContainsAttributeStatementsButNoIPAddressAttribute.

@Test
public void validate_shouldThrowWhenAssertionContainsAttributeStatementsButNoIPAddressAttribute() throws Exception {
    Assertion assertion = anAssertion().addAttributeStatement(anAttributeStatement().build()).buildUnencrypted();
    validateException(SamlTransformationErrorFactory.missingIPAddress(assertion.getID()), assertion);
}
Also used : AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) Test(org.junit.jupiter.api.Test)

Example 73 with Assertion

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

the class PassthroughAssertionUnmarshallerTest method transform_shouldThrowExceptionIfGpg45StatusIsNotRecognised.

@Test
public void transform_shouldThrowExceptionIfGpg45StatusIsNotRecognised() {
    Assertions.assertThrows(IllegalStateException.class, () -> {
        String gpg45Status = "status not known";
        Assertion theAssertion = givenAFraudEventAssertion(gpg45Status);
        unmarshaller.fromAssertion(theAssertion);
    });
}
Also used : AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) Test(org.junit.jupiter.api.Test)

Example 74 with Assertion

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

the class PassthroughAssertionUnmarshallerTest method transform_shouldTransformIpAddress.

@Test
public void transform_shouldTransformIpAddress() {
    String ipAddy = "1.2.3.4";
    Assertion theAssertion = anAssertion().addAttributeStatement(anAttributeStatement().addAttribute(anIPAddress().withValue(ipAddy).build()).build()).buildUnencrypted();
    PassthroughAssertion authnStatementAssertion = unmarshaller.fromAssertion(theAssertion);
    assertThat(authnStatementAssertion.getPrincipalIpAddressAsSeenByIdp().isPresent()).isEqualTo(true);
    assertThat(authnStatementAssertion.getPrincipalIpAddressAsSeenByIdp().get()).isEqualTo(ipAddy);
}
Also used : PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) Test(org.junit.jupiter.api.Test)

Example 75 with Assertion

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

the class PassthroughAssertionUnmarshallerTest method transform_shouldHandleFraudAuthnStatementAndSetThatAssertionIsForFraudulentEventAndSetFraudDetails.

@Test
public void transform_shouldHandleFraudAuthnStatementAndSetThatAssertionIsForFraudulentEventAndSetFraudDetails() {
    final AuthnContextClassRef authnContextClassRef = anAuthnContextClassRef().withAuthnContextClasRefValue(IdaAuthnContext.LEVEL_X_AUTHN_CTX).build();
    Assertion theAssertion = anAssertion().addAuthnStatement(anAuthnStatement().withAuthnContext(anAuthnContext().withAuthnContextClassRef(authnContextClassRef).build()).build()).addAttributeStatement(anAttributeStatement().addAttribute(anIdpFraudEventIdAttribute().build()).addAttribute(aGpg45StatusAttribute().build()).build()).buildUnencrypted();
    when(authnContextFactory.authnContextForLevelOfAssurance(IdaAuthnContext.LEVEL_X_AUTHN_CTX)).thenReturn(AuthnContext.LEVEL_X);
    when(assertionStringTransformer.apply(theAssertion)).thenReturn("AUTHN_ASSERTION");
    PassthroughAssertion authnStatementAssertion = unmarshaller.fromAssertion(theAssertion);
    assertThat(authnStatementAssertion.isFraudulent()).isEqualTo(true);
    assertThat(authnStatementAssertion.getFraudDetectedDetails().isPresent()).isEqualTo(true);
}
Also used : PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) AuthnContextClassRef(org.opensaml.saml.saml2.core.AuthnContextClassRef) AuthnContextClassRefBuilder.anAuthnContextClassRef(uk.gov.ida.saml.core.test.builders.AuthnContextClassRefBuilder.anAuthnContextClassRef) AssertionBuilder.anAssertion(uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) PassthroughAssertion(uk.gov.ida.saml.core.domain.PassthroughAssertion) Test(org.junit.jupiter.api.Test)

Aggregations

Assertion (org.opensaml.saml.saml2.core.Assertion)175 Test (org.junit.jupiter.api.Test)118 Response (org.opensaml.saml.saml2.core.Response)62 AssertionBuilder.anAssertion (uk.gov.ida.saml.core.test.builders.AssertionBuilder.anAssertion)61 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)58 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)43 Attribute (org.opensaml.saml.saml2.core.Attribute)25 DateTime (org.joda.time.DateTime)23 Element (org.w3c.dom.Element)22 NameID (org.opensaml.saml.saml2.core.NameID)20 XMLObject (org.opensaml.core.xml.XMLObject)19 PassthroughAssertion (uk.gov.ida.saml.core.domain.PassthroughAssertion)17 ValidatedResponse (uk.gov.ida.saml.security.validators.ValidatedResponse)15 Authentication (org.springframework.security.core.Authentication)14 SubjectConfirmation (org.opensaml.saml.saml2.core.SubjectConfirmation)13 Test (org.junit.Test)12 AuthnStatement (org.opensaml.saml.saml2.core.AuthnStatement)12 Conditions (org.opensaml.saml.saml2.core.Conditions)12 NameIDBuilder (org.opensaml.saml.saml2.core.impl.NameIDBuilder)11 Saml2ResponseValidatorResult (org.springframework.security.saml2.core.Saml2ResponseValidatorResult)11