Skip to content

Commit d1dfb2b

Browse files
AbdulR3hmanjzheaux
authored andcommitted
Improve OpenSAML Version Check
Closes gh-10077
1 parent bfe94f9 commit d1dfb2b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,17 @@ private AuthenticationConverter getAuthenticationConverter(B http) {
260260
return this.authenticationConverter;
261261
}
262262

263+
private String version() {
264+
String version = Version.getVersion();
265+
if (version != null) {
266+
return version;
267+
}
268+
return Version.class.getModule().getDescriptor().version().map(Object::toString)
269+
.orElseThrow(() -> new IllegalStateException("cannot determine OpenSAML version"));
270+
}
271+
263272
private void registerDefaultAuthenticationProvider(B http) {
264-
if (Version.getVersion().startsWith("4")) {
273+
if (version().startsWith("4")) {
265274
http.authenticationProvider(postProcess(new OpenSaml4AuthenticationProvider()));
266275
}
267276
else {
@@ -346,7 +355,7 @@ private Filter build(B http) {
346355
private Saml2AuthenticationRequestFactory getResolver(B http) {
347356
Saml2AuthenticationRequestFactory resolver = getSharedOrBean(http, Saml2AuthenticationRequestFactory.class);
348357
if (resolver == null) {
349-
if (Version.getVersion().startsWith("4")) {
358+
if (version().startsWith("4")) {
350359
return new OpenSaml4AuthenticationRequestFactory();
351360
}
352361
return new OpenSamlAuthenticationRequestFactory();

0 commit comments

Comments
 (0)