Если у вас нет родителя AuthenticationManager
, оно должно быть:
@EnableResourceServer
@Configuration
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatchers()
.antMatchers( "/login","/oauth/authorize")
.and()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("Admin")
.password("admin")
.roles("ADMIN");
}
}
И если вы это сделаете, то вам придется либо переименовать родительский , либо назвать это child Bean
что-то еще:
@EnableResourceServer
@Configuration
public class ResourceServerConfig extends WebSecurityConfigurerAdapter {
// Option 1) rename the parent somewhere else, like so....
private final AuthenticationManager parentAuthenticationManager;
@Autowired
public ResourceServerConfig(AuthenticationManager parentAuthenticationManager) {
this.parentAuthenticationManager = parentAuthenticationManager;
}
@Override
// Option 2) rename the child AuthenticationManager here
@Bean("childAuthenticationManager")
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatchers()
.antMatchers( "/login","/oauth/authorize")
.and()
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.permitAll();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.parentAuthenticationManager(authenticationManager)
.inMemoryAuthentication()
.withUser("Admin")
.password("admin")
.roles("ADMIN");
}
}