Search in sources :

Example 76 with Issuer

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

the class VerifiedAttributesLoggerTest method shouldLogSurnameNameHistory.

@Test
public void shouldLogSurnameNameHistory() throws Exception {
    AttributeValue surnameAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.parse("2000-12-31")).withVerified(true).build();
    Attribute surnameAttribute = new AttributeBuilder().buildObject();
    surnameAttribute.setName(IdaConstants.Attributes_1_1.Surname.NAME);
    surnameAttribute.getAttributeValues().add(surnameAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withSurname(surnameAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.Surname.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, null)));
}
Also used : AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) PersonNameAttributeValueBuilder(uk.gov.ida.saml.core.test.builders.PersonNameAttributeValueBuilder) List(java.util.List) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.jupiter.api.Test)

Example 77 with Issuer

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

the class VerifiedAttributesLoggerTest method shouldLogIssuerAndLevelOfAssurance.

@Test
public void shouldLogIssuerAndLevelOfAssurance() throws Exception {
    List<Attribute> anyAttributesList = aMatchingDatasetAttributeStatement_1_1().build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("some-issuer", LEVEL_2, anyAttributesList), AttributeStatementLogData.class);
    assertThat(actual.getIssuer()).isEqualTo("some-issuer");
    assertThat(actual.getLevelOfAssurance()).isEqualTo(LEVEL_2);
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) Test(org.junit.jupiter.api.Test)

Example 78 with Issuer

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

the class VerifiedAttributesLoggerTest method shouldLogMiddleNamesNameHistory.

@Test
public void shouldLogMiddleNamesNameHistory() throws Exception {
    AttributeValue oldMiddleNamesAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.parse("2000-12-31")).withTo(DateTime.now().minusDays(406)).withVerified(true).build();
    AttributeValue currentMiddleNamesAttributeValue = new PersonNameAttributeValueBuilder().withFrom(DateTime.now().minusDays(405)).withVerified(true).build();
    Attribute middleNamesAttribute = new AttributeBuilder().buildObject();
    middleNamesAttribute.setName(IdaConstants.Attributes_1_1.Middlename.NAME);
    middleNamesAttribute.getAttributeValues().add(oldMiddleNamesAttributeValue);
    middleNamesAttribute.getAttributeValues().add(currentMiddleNamesAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withMiddleNames(middleNamesAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.Middlename.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, "more than 405 days"), new VerifiedAttributeLogData(true, null)));
}
Also used : AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) PersonNameAttributeValueBuilder(uk.gov.ida.saml.core.test.builders.PersonNameAttributeValueBuilder) List(java.util.List) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.jupiter.api.Test)

Example 79 with Issuer

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

the class VerifiedAttributesLoggerTest method shouldLogCurrentAddressHistory.

@Test
public void shouldLogCurrentAddressHistory() throws Exception {
    AttributeValue currentAddressAttributeValue = new AddressAttributeValueBuilder_1_1().withFrom(DateTime.now().minusYears(1)).withVerified(true).build();
    Attribute currentAddressAttribute = new AttributeBuilder().buildObject();
    currentAddressAttribute.setName(IdaConstants.Attributes_1_1.CurrentAddress.NAME);
    currentAddressAttribute.getAttributeValues().add(currentAddressAttributeValue);
    List<Attribute> attributes = aMatchingDatasetAttributeStatement_1_1().withCurrentAddress(currentAddressAttribute).build().getAttributes();
    AttributeStatementLogData actual = mapper.readValue(formatAttributes("any-issuer", LEVEL_2, attributes), AttributeStatementLogData.class);
    Map<String, List<VerifiedAttributeLogData>> attributesMap = actual.getAttributes();
    assertThat(attributesMap.get(IdaConstants.Attributes_1_1.CurrentAddress.NAME)).isEqualTo(List.of(new VerifiedAttributeLogData(true, null)));
}
Also used : AttributeValue(org.opensaml.saml.saml2.core.AttributeValue) AddressAttributeValueBuilder_1_1(uk.gov.ida.saml.core.test.builders.AddressAttributeValueBuilder_1_1) AttributeBuilder(org.opensaml.saml.saml2.core.impl.AttributeBuilder) Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatementLogData(uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData) List(java.util.List) VerifiedAttributeLogData(uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData) Test(org.junit.jupiter.api.Test)

Example 80 with Issuer

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

the class IdpResponseValidatorTest method shouldThrowIfAllDecryptersFail.

@Test
public void shouldThrowIfAllDecryptersFail() throws Exception {
    String issuerValue = "issuerValue";
    ValidatedResponse validatedResponse = mock(ValidatedResponse.class);
    Issuer responseIssuer = mock(Issuer.class);
    Counter idpDecryptionErrorCounter = mock(Counter.class);
    Counter.Child childCounter = mock(Counter.Child.class);
    setFinalStatic(IdpResponseValidator.class.getDeclaredField("idpDecryptionErrorCounter"), idpDecryptionErrorCounter);
    when(validatedResponse.getIssuer()).thenReturn(responseIssuer);
    when(responseIssuer.getValue()).thenReturn(issuerValue);
    when(samlResponseSignatureValidator.validate(response, IDPSSODescriptor.DEFAULT_ELEMENT_NAME)).thenReturn(validatedResponse);
    when(assertionDecrypter.decryptAssertions(validatedResponse)).thenThrow(SamlFailedToDecryptException.class);
    when(badAssertionDecrypter.decryptAssertions(validatedResponse)).thenThrow(SamlFailedToDecryptException.class);
    when(idpDecryptionErrorCounter.labels(anyString())).thenReturn(childCounter);
    doNothing().when(childCounter).inc();
    SamlFailedToDecryptException exception = assertThrows(SamlFailedToDecryptException.class, () -> validator.validate(response));
    assertEquals(exception.getMessage(), String.format("IdpResponseValidator could not decrypt assertions from %s with any of the decrypters", issuerValue));
    verify(idpDecryptionErrorCounter, times(2)).labels(validatedResponse.getIssuer().getValue());
    verify(childCounter, times(2)).inc();
}
Also used : Counter(io.prometheus.client.Counter) Issuer(org.opensaml.saml.saml2.core.Issuer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ValidatedResponse(uk.gov.ida.saml.security.validators.ValidatedResponse) SamlFailedToDecryptException(uk.gov.ida.saml.security.exception.SamlFailedToDecryptException) Test(org.junit.jupiter.api.Test)

Aggregations

Issuer (org.opensaml.saml.saml2.core.Issuer)79 Response (org.opensaml.saml.saml2.core.Response)59 DateTime (org.joda.time.DateTime)57 Test (org.junit.jupiter.api.Test)37 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)36 Element (org.w3c.dom.Element)34 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)32 lombok.val (lombok.val)28 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)26 Document (org.w3c.dom.Document)25 Status (org.opensaml.saml.saml2.core.Status)24 Assertion (org.opensaml.saml.saml2.core.Assertion)22 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)20 SubjectConfirmationDataBean (org.apache.wss4j.common.saml.bean.SubjectConfirmationDataBean)20 SAMLObjectBuilder (org.opensaml.saml.common.SAMLObjectBuilder)17 LogoutRequest (org.opensaml.saml.saml2.core.LogoutRequest)16 InputStream (java.io.InputStream)15 IssuerBuilder (org.opensaml.saml.saml2.core.impl.IssuerBuilder)15 Crypto (org.apache.wss4j.common.crypto.Crypto)14 KeyStore (java.security.KeyStore)13