Skip to content

Commit c35e107

Browse files
committed
Add ProxyRestriction Validator
Closes gh-14931
1 parent 8271258 commit c35e107

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,6 +55,7 @@
5555
import org.opensaml.saml.saml2.assertion.impl.AudienceRestrictionConditionValidator;
5656
import org.opensaml.saml.saml2.assertion.impl.BearerSubjectConfirmationValidator;
5757
import org.opensaml.saml.saml2.assertion.impl.DelegationRestrictionConditionValidator;
58+
import org.opensaml.saml.saml2.assertion.impl.ProxyRestrictionConditionValidator;
5859
import org.opensaml.saml.saml2.core.Assertion;
5960
import org.opensaml.saml.saml2.core.Attribute;
6061
import org.opensaml.saml.saml2.core.AttributeStatement;
@@ -837,6 +838,7 @@ public ValidationResult validate(Condition condition, Assertion assertion, Valid
837838
return ValidationResult.VALID;
838839
}
839840
});
841+
conditions.add(new ProxyRestrictionConditionValidator());
840842
subjects.add(new BearerSubjectConfirmationValidator() {
841843
@Override
842844
protected ValidationResult validateAddress(SubjectConfirmation confirmation, Assertion assertion,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,6 +55,7 @@
5555
import org.opensaml.saml.saml2.core.EncryptedID;
5656
import org.opensaml.saml.saml2.core.NameID;
5757
import org.opensaml.saml.saml2.core.OneTimeUse;
58+
import org.opensaml.saml.saml2.core.ProxyRestriction;
5859
import org.opensaml.saml.saml2.core.Response;
5960
import org.opensaml.saml.saml2.core.StatusCode;
6061
import org.opensaml.saml.saml2.core.SubjectConfirmation;
@@ -63,6 +64,7 @@
6364
import org.opensaml.saml.saml2.core.impl.EncryptedAssertionBuilder;
6465
import org.opensaml.saml.saml2.core.impl.EncryptedIDBuilder;
6566
import org.opensaml.saml.saml2.core.impl.NameIDBuilder;
67+
import org.opensaml.saml.saml2.core.impl.ProxyRestrictionBuilder;
6668
import org.opensaml.xmlsec.encryption.impl.EncryptedDataBuilder;
6769
import org.opensaml.xmlsec.signature.support.SignatureConstants;
6870
import org.w3c.dom.Element;
@@ -777,6 +779,19 @@ public void authenticateWhenAssertionIssuerNotValidThenFailsWithInvalidIssuer()
777779
.withMessageContaining("did not match any valid issuers");
778780
}
779781

782+
// gh-14931
783+
@Test
784+
public void authenticateWhenAssertionHasProxyRestrictionThenParses() {
785+
OpenSaml4AuthenticationProvider provider = new OpenSaml4AuthenticationProvider();
786+
Response response = response();
787+
Assertion assertion = assertion();
788+
ProxyRestriction condition = new ProxyRestrictionBuilder().buildObject();
789+
assertion.getConditions().getConditions().add(condition);
790+
response.getAssertions().add(assertion);
791+
Saml2AuthenticationToken token = token(signed(response), verifying(registration()));
792+
provider.authenticate(token);
793+
}
794+
780795
private <T extends XMLObject> T build(QName qName) {
781796
return (T) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName).buildObject(qName);
782797
}

0 commit comments

Comments
 (0)