Skip to content

Commit 00084cf

Browse files
marcusdacoregiojzheaux
authored andcommitted
Add saml2.ValidIssuers parameter
Adds the saml2.ValidIssuers parameter into SAML 2.0 Assertion Validators Closes gh-10335
1 parent c82722c commit 00084cf

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,14 @@ private static Converter<AssertionToken, Saml2ResponseValidatorResult> createAss
672672

673673
private static ValidationContext createValidationContext(AssertionToken assertionToken,
674674
Consumer<Map<String, Object>> paramsConsumer) {
675-
String audience = assertionToken.token.getRelyingPartyRegistration().getEntityId();
676-
String recipient = assertionToken.token.getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
675+
RelyingPartyRegistration relyingPartyRegistration = assertionToken.token.getRelyingPartyRegistration();
676+
String audience = relyingPartyRegistration.getEntityId();
677+
String recipient = relyingPartyRegistration.getAssertionConsumerServiceLocation();
678+
String assertingPartyEntityId = relyingPartyRegistration.getAssertingPartyDetails().getEntityId();
677679
Map<String, Object> params = new HashMap<>();
678680
params.put(SAML2AssertionValidationParameters.COND_VALID_AUDIENCES, Collections.singleton(audience));
679681
params.put(SAML2AssertionValidationParameters.SC_VALID_RECIPIENTS, Collections.singleton(recipient));
682+
params.put(SAML2AssertionValidationParameters.VALID_ISSUERS, Collections.singleton(assertingPartyEntityId));
680683
paramsConsumer.accept(params);
681684
return new ValidationContext(params);
682685
}
@@ -754,6 +757,11 @@ protected ValidationResult validateSubjectConfirmation(Assertion assertion, Vali
754757
protected ValidationResult validateStatements(Assertion assertion, ValidationContext context) {
755758
return ValidationResult.VALID;
756759
}
760+
761+
@Override
762+
protected ValidationResult validateIssuer(Assertion assertion, ValidationContext context) {
763+
return ValidationResult.VALID;
764+
}
757765
};
758766

759767
}

saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProviderTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,20 @@ public void authenticateWhenCustomResponseValidatorThenUses() {
628628
verify(validator).convert(any(OpenSaml4AuthenticationProvider.ResponseToken.class));
629629
}
630630

631+
@Test
632+
public void authenticateWhenAssertionIssuerNotValidThenFailsWithInvalidIssuer() {
633+
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
634+
Response response = response();
635+
Assertion assertion = assertion();
636+
assertion.setIssuer(TestOpenSamlObjects.issuer("https://invalid.idp.test/saml2/idp"));
637+
response.getAssertions().add(assertion);
638+
TestOpenSamlObjects.signed(response, TestSaml2X509Credentials.assertingPartySigningCredential(),
639+
ASSERTING_PARTY_ENTITY_ID);
640+
Saml2AuthenticationToken token = token(response, verifying(registration()));
641+
assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token))
642+
.withMessageContaining("did not match any valid issuers");
643+
}
644+
631645
private <T extends XMLObject> T build(QName qName) {
632646
return (T) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName).buildObject(qName);
633647
}

0 commit comments

Comments
 (0)