Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.
This repository was archived by the owner on May 31, 2022. It is now read-only.

EnableAuthorizationServer creates multiple beans of the same type #984

@wilkinsona

Description

@wilkinsona

This was originally raised against Spring Boot, but the underlying problem is in Spring Security OAuth. Please see this Spring Boot issue for the details.

The summary is that multiple beans that implement ResourceServerTokenServices are registered with the application context. Depending on what other calls are made to the bean factory, one or both of those beans may be found. When both are found, neither is primary and a NoUniqueBeanDefinitionException is thrown.

This is the simplest reproduction that I'm aware of:

package com.example;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;

@EnableAuthorizationServer
@EnableWebSecurity
public class BrokenOAuthApplication extends AuthorizationServerConfigurerAdapter {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(BrokenOAuthApplication.class);
		context.getBean(ResourceServerTokenServices.class);
		context.close();
	}

}

This fails with Security OAuth 2.0.12.RELEASE, Security 4.2.1.RELEASE, and Framework 4.3.5.RELEASE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions