Skip to content

Commit 4a4da83

Browse files
committed
Upgrade to Spring Boot 3.3.2
Updated to Spring Boot 3.3.2 in order to reproduce a bug. The problem is caused by directly instantiating the DefaultSaml2CredentialsManager that contains annotated methods and post processing the instantiated manager. Currently, it is not possible to instantiate the manager in this fashion and the postProcess call was removed. As a result, it is now necessary to pass a bean as Saml2CredentialsManager. It seems to be caused by the same change, that led to spring-projects/spring-framework#33286 and was fixed just hours ago. It's a breaking change! The two credential methods in the PartnerNetSaml2Configurer are package-private now. Replace the call by simply passing a DefaultSaml2CredentialsManager bean initialized with the configSupplier instead of using the credentials methods with the configSupplier. The methods will be restored with the Upgrade to 3.3.3, if the change in Spring Boot is fixing for our error, too.
1 parent ebd0076 commit 4a4da83

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

pnet-idp-client-saml2/src/main/java/at/porscheinformatik/idp/saml2/PartnerNetSaml2Configurer.java

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public static PartnerNetSaml2Configurer apply(HttpSecurity http, String entityId
7474
throws Exception
7575
{
7676
http //
77-
.authorizeHttpRequests()
78-
.requestMatchers(HttpMethod.GET, DEFAULT_ENTITY_ID_PATH)
79-
.permitAll();
77+
.authorizeHttpRequests().requestMatchers(HttpMethod.GET, DEFAULT_ENTITY_ID_PATH).permitAll();
8078

8179
return http.apply(new PartnerNetSaml2Configurer(entityId, metadataUrl));
8280
}
@@ -128,23 +126,48 @@ public PartnerNetSaml2Configurer failOnStartup()
128126
/**
129127
* @param credentialConfigs static list of credentials to use for authentication
130128
* @return the builder for a fluent api
129+
* @deprecated Do not use this method, as it is buggy! It instantiates the DefaultSaml2CredentialsManager, that
130+
* contains annotated methods which only work inside a Spring bean! This is not fixable. As a result, this is an
131+
* intended breaking change. Use the {@link #credentials(Saml2CredentialsManager)} method instead and pass a
132+
* DefaultSaml2CredentialsManager bean as manager!
131133
*/
132-
public PartnerNetSaml2Configurer credentials(Saml2CredentialsConfig... credentialConfigs)
134+
@Deprecated(forRemoval = true)
135+
PartnerNetSaml2Configurer credentials(Saml2CredentialsConfig... credentialConfigs)
133136
{
134-
return credentials(() -> Arrays.asList(credentialConfigs));
137+
credentialsManager = new DefaultSaml2CredentialsManager(() -> Arrays.asList(credentialConfigs));
138+
139+
return this;
135140
}
136141

137142
/**
138143
* @param supplier the supplier that will be called periodically to load the most up to date set of credentials
139144
* @return the builder for a fluent api
145+
* @deprecated Do not use this method, as it is buggy! It instantiates the DefaultSaml2CredentialsManager, that
146+
* contains annotated methods which only work inside a Spring bean! This is not fixable. As a result, this is an
147+
* intended breaking change. Use the {@link #credentials(Saml2CredentialsManager)} method instead and pass a
148+
* DefaultSaml2CredentialsManager bean as manager!
140149
*/
141-
public PartnerNetSaml2Configurer credentials(Supplier<List<Saml2CredentialsConfig>> supplier)
150+
@Deprecated(forRemoval = true)
151+
PartnerNetSaml2Configurer credentials(Supplier<List<Saml2CredentialsConfig>> supplier)
142152
{
143153
credentialsManager = new DefaultSaml2CredentialsManager(supplier);
144154

145155
return this;
146156
}
147157

158+
/**
159+
* Set the credentials manager to use for loading the credentials.
160+
*
161+
* @param credentialsManager the credentials manager to use
162+
* @return the builder for a fluent api
163+
*/
164+
public PartnerNetSaml2Configurer credentials(Saml2CredentialsManager credentialsManager)
165+
{
166+
this.credentialsManager = credentialsManager;
167+
168+
return this;
169+
}
170+
148171
/**
149172
* Override the default client factory to be used for loading SAML metadata
150173
*
@@ -335,7 +358,7 @@ private Saml2ResponseProcessor getResponseProcessor()
335358

336359
private Saml2CredentialsManager getCredentialsManager()
337360
{
338-
return postProcess(requireNonNull(credentialsManager, "No credentials configured"));
361+
return requireNonNull(credentialsManager, "No credentials configured");
339362
}
340363

341364
private RelyingPartyRegistrationRepository getRelyingPartyRegistrationRepository(
@@ -361,11 +384,12 @@ private Saml2AuthenticationRequestResolver buildRequestResolver(
361384
new OpenSaml4AuthenticationRequestResolver(relyingPartyRegistrationResolver);
362385

363386
resolver.setAuthnRequestCustomizer(getAuthnRequestCustomizer());
364-
resolver
365-
.setRelayStateResolver(request -> Saml2Utils //
366-
.getRelayState(request)
367-
.map(relayState -> String.format(AUTO_GENERATED_RELAY_STATE_FORMAT, UUID.randomUUID(), relayState)) // pre-append a random string
368-
.orElseGet(() -> String.format(AUTO_GENERATED_RELAY_STATE_FORMAT, UUID.randomUUID(), ""))); // default to the auto generated UUID;
387+
resolver.setRelayStateResolver(request -> Saml2Utils //
388+
.getRelayState(request)
389+
.map(relayState -> String.format(AUTO_GENERATED_RELAY_STATE_FORMAT, UUID.randomUUID(),
390+
relayState)) // pre-append a random string
391+
.orElseGet(() -> String.format(AUTO_GENERATED_RELAY_STATE_FORMAT, UUID.randomUUID(),
392+
""))); // default to the auto generated UUID;
369393

370394
return resolver;
371395
}

pnet-idp-client-showcase/src/main/java/at/porscheinformatik/pnet/idp/clientshowcase/security/ClientShowcaseSecurityConfig.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.context.annotation.Configuration;
1010
import org.springframework.core.env.Environment;
1111
import org.springframework.core.env.Profiles;
12+
import org.springframework.scheduling.annotation.EnableScheduling;
1213
import org.springframework.security.authentication.AuthenticationManager;
1314
import org.springframework.security.authentication.AuthenticationProvider;
1415
import org.springframework.security.authentication.ProviderManager;
@@ -21,9 +22,11 @@
2122
import at.porscheinformatik.idp.openidconnect.EnablePartnerNetOpenIdConnect;
2223
import at.porscheinformatik.idp.openidconnect.PartnerNetOpenIdConnectConfigurer;
2324
import at.porscheinformatik.idp.openidconnect.PartnerNetOpenIdConnectProvider;
25+
import at.porscheinformatik.idp.saml2.DefaultSaml2CredentialsManager;
2426
import at.porscheinformatik.idp.saml2.EnablePartnerNetSaml2;
2527
import at.porscheinformatik.idp.saml2.PartnerNetSaml2Configurer;
2628
import at.porscheinformatik.idp.saml2.PartnerNetSaml2Provider;
29+
import at.porscheinformatik.idp.saml2.Saml2CredentialsManager;
2730
import at.porscheinformatik.idp.saml2.Saml2CredentialsProperties;
2831

2932
/**
@@ -33,6 +36,7 @@
3336
@EnableWebSecurity
3437
@EnablePartnerNetOpenIdConnect
3538
@EnablePartnerNetSaml2
39+
@EnableScheduling
3640
public class ClientShowcaseSecurityConfig
3741
{
3842
private static final Profiles PROD = Profiles.of("prod");
@@ -44,11 +48,13 @@ public class ClientShowcaseSecurityConfig
4448
public AuthenticationManager authenticationManager(List<AuthenticationProvider> providers)
4549
{
4650
/*
47-
* To get rid of the default AuthenticationManager registered by spring boot, that uses a auto generated password
51+
* To get rid of the default AuthenticationManager registered by spring boot, that uses a auto generated
52+
* password
4853
* visible in the logs, we register our own AuthenticationManager.
4954
*
5055
* If no providers are registered, we register a dummy provider that does nothing.
51-
* If custom authentication mechanisms are registered, they have to register a authentication provider, or handle the authentication
56+
* If custom authentication mechanisms are registered, they have to register a authentication provider, or
57+
* handle the authentication
5258
* on their own.
5359
*/
5460
if (providers.isEmpty())
@@ -59,9 +65,15 @@ public AuthenticationManager authenticationManager(List<AuthenticationProvider>
5965
return new ProviderManager(providers);
6066
}
6167

68+
@Bean
69+
public Saml2CredentialsManager saml2CredentialsManager(Saml2CredentialsProperties samlCredentialsConfig)
70+
{
71+
return new DefaultSaml2CredentialsManager(samlCredentialsConfig);
72+
}
73+
6274
@Bean
6375
public SecurityFilterChain securityFilterChain(HttpSecurity http, Environment environment,
64-
Saml2CredentialsProperties samlCredentialsConfig, ForceAuthenticationFilter forceAuthenticationFilter,
76+
Saml2CredentialsManager saml2CredentialsManager, ForceAuthenticationFilter forceAuthenticationFilter,
6577
ForceTenantFilter forceTenantFilter) throws Exception
6678
{
6779
if (environment.acceptsProfiles(LOCAL))
@@ -82,7 +94,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, Environment en
8294

8395
PartnerNetSaml2Configurer
8496
.apply(http, getPartnerNetSaml2Provider(environment))
85-
.credentials(samlCredentialsConfig)
97+
.credentials(saml2CredentialsManager)
8698
.customizer(saml2 -> saml2.failureUrl("/loginerror"));
8799

88100
http.logout(logout -> {

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<parent>
45
<groupId>org.springframework.boot</groupId>
56
<artifactId>spring-boot-starter-parent</artifactId>
6-
<version>3.0.2</version>
7+
<version>3.3.2</version>
78
<!-- HINT: When upgrading to a newer version, check if the following bug is fixed: https://github.com/spring-projects/spring-security/issues/12665 -->
89
<!-- If fixed, Remove the workaround in ClientShowcaseSecurityConfig. -->
910
</parent>
@@ -106,4 +107,4 @@
106107
</plugins>
107108
</pluginManagement>
108109
</build>
109-
</project>
110+
</project>

0 commit comments

Comments
 (0)