Skip to content

Using OAuth2ClientPropertiesMapper throws NoClassDefFoundError when CommonOAuth2Provider is not on classpath #18036

@nstdio

Description

@nstdio

Expected Behavior

To not throw an exception and create Map<String, ClientRegistration> properly

Current Behavior

Throws java.lang.NoClassDefFoundError

Caused by: java.lang.NoClassDefFoundError: org/springframework/security/config/oauth2/client/CommonOAuth2Provider
	at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesMapper.getCommonProvider(OAuth2ClientPropertiesMapper.java:139)
	at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesMapper.getBuilder(OAuth2ClientPropertiesMapper.java:107)
	at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesMapper.getClientRegistration(OAuth2ClientPropertiesMapper.java:73)
	at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesMapper.lambda$asClientRegistrations$0(OAuth2ClientPropertiesMapper.java:65)
	at java.base/java.util.HashMap.forEach(HashMap.java:1430)
	at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesMapper.asClientRegistrations(OAuth2ClientPropertiesMapper.java:64)

Context
We are trying to create client registrations as follows

OAuth2ClientProperties oAuth2ClientProperties = ...
var clientRegistrations = new OAuth2ClientPropertiesMapper(oAuth2ClientProperties) .asClientRegistrations()

We don't want to include org.springframework.security:spring-security-config as dependency and we don't have any google, github, facebook, okta OAuth2 provider types configured.

Two workaround we found. We copy/pasted OAuth2ClientPropertiesMapper in our code base patch related code to be conditional depending on CommonOAuth2Provider presence.

Obviously second workaround is to include spring-security-config dependency, but we don't want security autoconfiguration to kick in, still struggling to exclude all relevant autoconfigurations.

Metadata

Metadata

Assignees

Labels

for: external-projectFor an external project and not something we can fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions