Skip to content

Commit 6043cee

Browse files
committed
Add OpenSaml4AuthenticationProvider Preparation Steps
Issue gh-11077
1 parent 9a1fae3 commit 6043cee

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

docs/modules/ROOT/pages/migration.adoc

+114
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,120 @@ val verifying: List<Saml2X509Credential> = registration.getAssertingPartyDetails
20742074

20752075
For a complete listing of all changed methods, please see {security-api-url}org/springframework/security/saml2/provider/service/registration/RelyingPartyRegistration.html[``RelyingPartyRegistration``'s JavaDoc].
20762076

2077+
=== Use OpenSAML 4
2078+
2079+
OpenSAML 3 has reached its end-of-life.
2080+
As such, Spring Security 6 drops support for it, bumping up its OpenSAML baseline to 4.
2081+
2082+
To prepare for the upgrade, update your pom to depend on OpenSAML 4 instead of 3:
2083+
2084+
====
2085+
.Maven
2086+
[source,maven,role="primary"]
2087+
----
2088+
<dependencyManagement>
2089+
<dependency>
2090+
<groupId>org.opensaml</groupId>
2091+
<artifactId>opensaml-core</artifactId>
2092+
<version>4.2.1</version>
2093+
</dependency>
2094+
<dependency>
2095+
<groupId>org.opensaml</groupId>
2096+
<artifactId>opensaml-saml-api</artifactId>
2097+
<version>4.2.1</version>
2098+
</dependency>
2099+
<dependency>
2100+
<groupId>org.opensaml</groupId>
2101+
<artifactId>opensaml-saml-impl</artifactId>
2102+
<version>4.2.1</version>
2103+
</dependency>
2104+
</dependencyManagement>
2105+
----
2106+
2107+
.Gradle
2108+
[source,gradle,role="secondary"]
2109+
----
2110+
dependencies {
2111+
constraints {
2112+
api "org.opensaml:opensaml-core:4.2.1"
2113+
api "org.opensaml:opensaml-saml-api:4.2.1"
2114+
api "org.opensaml:opensaml-saml-impl:4.2.1"
2115+
}
2116+
}
2117+
----
2118+
====
2119+
2120+
You must use at least OpenSAML 4.1.1 to update to Spring Security 6's SAML support.
2121+
2122+
=== Use `OpenSaml4AuthenticationProvider`
2123+
2124+
In order to support both OpenSAML 3 and 4 at the same time, Spring Security released `OpenSamlAuthenticationProvider` and `OpenSaml4AuthenticationProvider`.
2125+
In 6.0, because OpenSAML3 support is removed, `OpenSamlAuthenticationProvider` is removed as well.
2126+
2127+
Not all methods in `OpenSamlAuthenticationProvider` were ported 1-to-1 to `OpenSaml4AuthenticationProvider`.
2128+
As such, some adjustment will be required to make the challenge.
2129+
2130+
Consider the following representative usage of `OpenSamlAuthenticationProvider`:
2131+
2132+
====
2133+
.Java
2134+
[source,java,role="primary"]
2135+
----
2136+
OpenSamlAuthenticationProvider versionThree = new OpenSamlAuthenticationProvider();
2137+
versionThree.setAuthoritiesExtractor(myAuthoritiesExtractor);
2138+
versionThree.setResponseTimeValidationSkew(myDuration);
2139+
----
2140+
2141+
.Kotlin
2142+
[source,kotlin,role="secondary"]
2143+
----
2144+
val versionThree: OpenSamlAuthenticationProvider = OpenSamlAuthenticationProvider()
2145+
versionThree.setAuthoritiesExtractor(myAuthoritiesExtractor)
2146+
versionThree.setResponseTimeValidationSkew(myDuration)
2147+
----
2148+
====
2149+
2150+
This should change to:
2151+
2152+
====
2153+
.Java
2154+
[source,java,role="primary"]
2155+
----
2156+
Converter<ResponseToken, Saml2Authentication> delegate = OpenSaml4AuthenticationProvider
2157+
.createDefaultResponseAuthenticationConverter();
2158+
OpenSaml4AuthenticationProvider versionFour = new OpenSaml4AuthenticationProvider();
2159+
versionFour.setResponseAuthenticationConverter((responseToken) -> {
2160+
Saml2Authentication authentication = delegate.convert(responseToken);
2161+
Assertion assertion = responseToken.getResponse().getAssertions().get(0);
2162+
AuthenticatedPrincipal principal = (AuthenticatedPrincipal) authentication.getPrincipal();
2163+
Collection<GrantedAuthority> authorities = myAuthoritiesExtractor.convert(assertion);
2164+
return new Saml2Authentication(principal, authentication.getSaml2Response(), authorities);
2165+
});
2166+
Converter<AssertionToken, Saml2ResponseValidationResult> validator = OpenSaml4AuthenticationProvider
2167+
.createDefaultAssertionValidatorWithParameters((p) -> p.put(CLOCK_SKEW, myDuration));
2168+
versionFour.setAssertionValidator(validator);
2169+
----
2170+
2171+
.Kotlin
2172+
[source,kotlin,role="secondary"]
2173+
----
2174+
val delegate = OpenSaml4AuthenticationProvider.createDefaultResponseAuthenticationConverter()
2175+
val versionFour = OpenSaml4AuthenticationProvider()
2176+
versionFour.setResponseAuthenticationConverter({
2177+
responseToken -> {
2178+
val authentication = delegate.convert(responseToken)
2179+
val assertion = responseToken.getResponse().getAssertions().get(0)
2180+
val principal = (AuthenticatedPrincipal) authentication.getPrincipal()
2181+
val authorities = myAuthoritiesExtractor.convert(assertion)
2182+
return Saml2Authentication(principal, authentication.getSaml2Response(), authorities)
2183+
}
2184+
})
2185+
val validator = OpenSaml4AuthenticationProvider
2186+
.createDefaultAssertionValidatorWithParameters({ p -> p.put(CLOCK_SKEW, myDuration) })
2187+
versionFour.setAssertionValidator(validator)
2188+
----
2189+
====
2190+
20772191
== Reactive
20782192

20792193
=== Use `AuthorizationManager` for Method Security

0 commit comments

Comments
 (0)