Skip to content

Commit

Permalink
Switch off Boot default authentication manager
Browse files Browse the repository at this point in the history
To fix spring-atticgh-401 we added some smart stuff to the configuration of a
DefaultTokenServices so that in a refresh grant there is a
UserDetailsService available if one has been configured globally.
Unfortunately when Spring Boot autconfig is on, it creates one
that seems to take precedence over one created by the user. To
switch that off we need to add a @bean of type AuthenticationManager.
  • Loading branch information
Dave Syer committed Mar 12, 2015
1 parent 4697d77 commit f51e5a0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/annotation/jdbc/src/main/java/demo/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter;
Expand Down Expand Up @@ -139,6 +142,14 @@ public void init(AuthenticationManagerBuilder auth) throws Exception {
.roles("USER");
// @formatter:on
}

// Force Spring Boot to switch off the default authentication manager:
@Bean
@Lazy
@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS)
public AuthenticationManager authenticationManager(AuthenticationManagerBuilder auth) {
return auth.getOrBuild();
}

}

Expand Down

0 comments on commit f51e5a0

Please sign in to comment.