mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 15:22:15 +00:00
Add saml2.ValidIssuers parameter
Adds the saml2.ValidIssuers parameter into SAML 2.0 Assertion Validators Closes gh-10335
This commit is contained in:
parent
c82722c412
commit
00084cf986
@ -672,11 +672,14 @@ public final class OpenSaml4AuthenticationProvider implements AuthenticationProv
|
||||
|
||||
private static ValidationContext createValidationContext(AssertionToken assertionToken,
|
||||
Consumer<Map<String, Object>> paramsConsumer) {
|
||||
String audience = assertionToken.token.getRelyingPartyRegistration().getEntityId();
|
||||
String recipient = assertionToken.token.getRelyingPartyRegistration().getAssertionConsumerServiceLocation();
|
||||
RelyingPartyRegistration relyingPartyRegistration = assertionToken.token.getRelyingPartyRegistration();
|
||||
String audience = relyingPartyRegistration.getEntityId();
|
||||
String recipient = relyingPartyRegistration.getAssertionConsumerServiceLocation();
|
||||
String assertingPartyEntityId = relyingPartyRegistration.getAssertingPartyDetails().getEntityId();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put(SAML2AssertionValidationParameters.COND_VALID_AUDIENCES, Collections.singleton(audience));
|
||||
params.put(SAML2AssertionValidationParameters.SC_VALID_RECIPIENTS, Collections.singleton(recipient));
|
||||
params.put(SAML2AssertionValidationParameters.VALID_ISSUERS, Collections.singleton(assertingPartyEntityId));
|
||||
paramsConsumer.accept(params);
|
||||
return new ValidationContext(params);
|
||||
}
|
||||
@ -754,6 +757,11 @@ public final class OpenSaml4AuthenticationProvider implements AuthenticationProv
|
||||
protected ValidationResult validateStatements(Assertion assertion, ValidationContext context) {
|
||||
return ValidationResult.VALID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ValidationResult validateIssuer(Assertion assertion, ValidationContext context) {
|
||||
return ValidationResult.VALID;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -628,6 +628,20 @@ public class OpenSaml4AuthenticationProviderTests {
|
||||
verify(validator).convert(any(OpenSaml4AuthenticationProvider.ResponseToken.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticateWhenAssertionIssuerNotValidThenFailsWithInvalidIssuer() {
|
||||
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
|
||||
Response response = response();
|
||||
Assertion assertion = assertion();
|
||||
assertion.setIssuer(TestOpenSamlObjects.issuer("https://invalid.idp.test/saml2/idp"));
|
||||
response.getAssertions().add(assertion);
|
||||
TestOpenSamlObjects.signed(response, TestSaml2X509Credentials.assertingPartySigningCredential(),
|
||||
ASSERTING_PARTY_ENTITY_ID);
|
||||
Saml2AuthenticationToken token = token(response, verifying(registration()));
|
||||
assertThatExceptionOfType(Saml2AuthenticationException.class).isThrownBy(() -> provider.authenticate(token))
|
||||
.withMessageContaining("did not match any valid issuers");
|
||||
}
|
||||
|
||||
private <T extends XMLObject> T build(QName qName) {
|
||||
return (T) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName).buildObject(qName);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user