Skip to content

Saml2LoginConfigure Null pointer exception due to Java module introduction #10077

@AbdulR3hman

Description

@AbdulR3hman

Describe the bug

The issue is a Java null pointer exception resulted from checking for OpenSAML version within the SAML2 login configurer when used with Java Modules rather than Classpath.

Exception:

Caused by: java.lang.NullPointerException: null
	at spring.security.config@5.5.1/org.springframework.security.config.annotation.web.configurers.saml2.Saml2LoginConfigurer$AuthenticationRequestEndpointConfig.getResolver(Saml2LoginConfigurer.java:349) ~[spring-security-config-5.5.1.jar:na]
	at spring.security.config@5.5.1/org.springframework.security.config.annotation.web.configurers.saml2.Saml2LoginConfigurer$AuthenticationRequestEndpointConfig.build(Saml2LoginConfigurer.java:340) ~[spring-security-config-5.5.1.jar:na]
	at 

This is due to the code that doesn't check if the nullable Version class is null:

private Saml2AuthenticationRequestFactory getResolver(B http) {
Saml2AuthenticationRequestFactory resolver = getSharedOrBean(http, Saml2AuthenticationRequestFactory.class);
if (resolver == null) {
if (Version.getVersion().startsWith("4")) {
return new OpenSaml4AuthenticationRequestFactory();
}
return new OpenSamlAuthenticationRequestFactory();
}
return resolver;
}

This was introduced by this issue: #9095

To Reproduce

Simply import saml2 provider: (with spring-boot version: 2.5.2)

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-saml2-service-provider</artifactId>
        </dependency

And build with maven without module-info.java file, which means it will be using the classpath instead. This will work, however migrating to module will make the Version of Opensaml completely null resulting in the above exception.

Expected behavior

Check for null Version class as it is allowed to be nullable org.opensaml.core.Version .

Metadata

Metadata

Labels

in: saml2An issue in SAML2 modulesstatus: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions