Search in sources :

Example 86 with Issuer

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

the class EncryptedResponseFromMatchingServiceValidatorTest method validateIssuer_shouldDoNothingIfFormatAttributeIsMissing.

@Test
public void validateIssuer_shouldDoNothingIfFormatAttributeIsMissing() throws Exception {
    Issuer issuer = anIssuer().withFormat(null).build();
    Response response = aResponse().withIssuer(issuer).withStatus(happyStatus).build();
    validator.validate(response);
}
Also used : ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) Response(org.opensaml.saml.saml2.core.Response) Issuer(org.opensaml.saml.saml2.core.Issuer) IssuerBuilder.anIssuer(uk.gov.ida.saml.core.test.builders.IssuerBuilder.anIssuer) Test(org.junit.jupiter.api.Test)

Example 87 with Issuer

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

the class HubAssertionMarshallerTest method transform_shouldTransformAssertionIssuer.

@Test
public void transform_shouldTransformAssertionIssuer() {
    String assertionIssuerId = "assertion issuer";
    HubAssertion assertion = aHubAssertion().withIssuerId(assertionIssuerId).build();
    Assertion transformedAssertion = marshaller.toSaml(assertion);
    assertThat(transformedAssertion.getIssuer().getValue()).isEqualTo(assertionIssuerId);
}
Also used : HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) HubAssertionBuilder.aHubAssertion(uk.gov.ida.saml.core.test.builders.HubAssertionBuilder.aHubAssertion) HubAssertion(uk.gov.ida.saml.core.domain.HubAssertion) Test(org.junit.jupiter.api.Test)

Example 88 with Issuer

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

the class MatchingServiceAssertionToAssertionTransformer method transform.

public Assertion transform(MatchingServiceAssertion originalAssertion) {
    Assertion transformedAssertion = openSamlXmlObjectFactory.createAssertion();
    transformedAssertion.setIssueInstant(originalAssertion.getIssueInstant());
    Issuer transformedIssuer = openSamlXmlObjectFactory.createIssuer(originalAssertion.getIssuerId());
    transformedAssertion.setIssuer(transformedIssuer);
    transformedAssertion.setID(originalAssertion.getId());
    Subject subject = outboundAssertionToSubjectTransformer.transform(originalAssertion);
    transformedAssertion.setSubject(subject);
    MatchingServiceAuthnStatement authnStatement = originalAssertion.getAuthnStatement();
    transformedAssertion.getAuthnStatements().add(matchingServiceAuthnStatementToAuthnStatementTransformer.transform(authnStatement));
    Conditions conditions = openSamlXmlObjectFactory.createConditions();
    AudienceRestriction audienceRestriction = openSamlXmlObjectFactory.createAudienceRestriction(originalAssertion.getAudience());
    conditions.getAudienceRestrictions().add(audienceRestriction);
    transformedAssertion.setConditions(conditions);
    List<Attribute> userAttributesForAccountCreation = originalAssertion.getUserAttributesForAccountCreation();
    if (!userAttributesForAccountCreation.isEmpty()) {
        addAttributes(transformedAssertion, userAttributesForAccountCreation);
    }
    return transformedAssertion;
}
Also used : AudienceRestriction(org.opensaml.saml.saml2.core.AudienceRestriction) Issuer(org.opensaml.saml.saml2.core.Issuer) Attribute(org.opensaml.saml.saml2.core.Attribute) MatchingServiceAssertion(uk.gov.ida.saml.msa.test.domain.MatchingServiceAssertion) Assertion(org.opensaml.saml.saml2.core.Assertion) MatchingServiceAuthnStatement(uk.gov.ida.saml.core.domain.MatchingServiceAuthnStatement) Subject(org.opensaml.saml.saml2.core.Subject) Conditions(org.opensaml.saml.saml2.core.Conditions)

Example 89 with Issuer

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

the class RpAuthnRequestTranslatorServiceTest method shouldTranslateSamlAuthnRequest.

@Test
public void shouldTranslateSamlAuthnRequest() {
    RpAuthnRequestTranslatorService service = new RpAuthnRequestTranslatorService(stringToAuthnRequestTransformer, samlAuthnRequestToAuthnRequestFromRelyingPartyTransformer, vspVersionGauge);
    boolean forceAuthentication = true;
    String id = UUID.randomUUID().toString();
    String issuer = UUID.randomUUID().toString();
    URI assertionConsumerServiceUrl = URI.create("http://someassertionuri");
    int assertionConsumerServiceIndex = 1;
    Signature signature = aSignature().withSignatureAlgorithm(SIGNATURE_ALGORITHM).build();
    ((SignatureImpl) signature).setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_ALGORITHM, new DigestSHA256()));
    SamlRequestWithAuthnRequestInformationDto samlRequestWithAuthnRequestInformationDto = SamlAuthnRequestDtoBuilder.aSamlAuthnRequest().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerIndex(assertionConsumerServiceIndex).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    AuthnRequest authnRequest = AuthnRequestBuilder.anAuthnRequest().build();
    TranslatedAuthnRequestDto expected = TranslatedAuthnRequestDtoBuilder.aTranslatedAuthnRequest().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerServiceUrl(assertionConsumerServiceUrl).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).build();
    AuthnRequestFromRelyingParty intermediateBlah = anAuthnRequestFromRelyingParty().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerServiceUrl(assertionConsumerServiceUrl).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).withSignature(signature).build();
    when(stringToAuthnRequestTransformer.apply(samlRequestWithAuthnRequestInformationDto.getSamlMessage())).thenReturn(authnRequest);
    when(samlAuthnRequestToAuthnRequestFromRelyingPartyTransformer.apply(authnRequest)).thenReturn(intermediateBlah);
    when(vspVersionGauge.labels(anyString(), anyString())).thenReturn(childGauge);
    TranslatedAuthnRequestDto actual = service.translate(samlRequestWithAuthnRequestInformationDto);
    assertThat(actual).isEqualToComparingFieldByField(expected);
    verify(vspVersionGauge).labels(intermediateBlah.getIssuer(), intermediateBlah.getVerifyServiceProviderVersion().get());
    verify(childGauge).set(1.0);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) DigestSHA256(org.opensaml.xmlsec.algorithm.descriptors.DigestSHA256) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty(uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty) Signature(org.opensaml.xmlsec.signature.Signature) SignatureBuilder.aSignature(uk.gov.ida.saml.core.test.builders.SignatureBuilder.aSignature) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TranslatedAuthnRequestDto(uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto) SignatureImpl(org.opensaml.xmlsec.signature.impl.SignatureImpl) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 90 with Issuer

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

the class ProtectiveMonitoringLogFormatter method formatAuthnRequest.

public String formatAuthnRequest(AuthnRequest authnRequest, Direction direction, SignatureStatus signatureStatus) {
    Issuer issuer = authnRequest.getIssuer();
    String issuerId = issuer != null ? issuer.getValue() : "";
    return String.format(AUTHN_REQUEST, authnRequest.getID(), direction, authnRequest.getDestination(), issuerId, signatureStatus.valid());
}
Also used : Issuer(org.opensaml.saml.saml2.core.Issuer)

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