Я настраиваю Spring Security. Для аутентификации и авторизации пользователей я переопределяю configure(AuthenticationManagerBuilder auth)
из WebSecurityConfigurerAdapter
. Это прекрасно работает. Ниже мой код:Spring Security: configure (AuthenticationManagerBuilder auth) vs authenticationManagerBean()
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(customUserDetailsService)
.passwordEncoder(getPasswordEncoder());
}
Но когда я пытаюсь включить защиту на уровень методы, в действие, используя @EnableGlobalMethodSecurity(securedEnabled = true)
он бросает исключение:
Нет AuthenticationManager найденного
В соответствии с мое понимание AuthenticationManager
используется для аутентификации и авторизации пользователей, которые я уже делал, используя configure(AuthenticationManagerBuilder auth)
, а Spring вводил auth
сам объект.
Почему мне нужно зарегистрировать AuthenticationManager
вручную?
@Bean @Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
Каковы differennt цели configure(AuthenticationManagerBuilder auth)
и authenticationManagerBean()
предлагается?
Я расширяю WebSecurityConfigurerAdapter
. Почему мне нужно предоставить пользовательский код AuthenticationManager
, переопределив authenticationManagerBean()
.