sar*_*eeh 9 java security authentication spring spring-security
我已经为标题中的问题苦苦挣扎了几天,我感到非常沮丧。我不知道我做错了什么以及为什么我的实现不起作用。
让我告诉你我有什么:
自定义身份验证提供程序:
@Component
public class AuthProvider implements AuthenticationProvider {
private Logger logger = LoggerFactory.getLogger(AuthProvider.class);
public AuthProvider() {
logger.info("Building...");
}
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
logger.info("Authenticate...");
return null;
}
public boolean supports(Class<?> authentication) {
logger.info("Supports...");
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
网络安全配置:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthProvider authProvider;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider);
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests().anyRequest().authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我已将记录器添加到 AuthenticationProvider 中,但并未调用任何记录器。
我试过的:
@Autowired到configure其中的AuthenticationManagerBuilder是@EnableGlobalMethodSecurity(prePostEnabled=true)到班级AuthenticationProvider直接添加自定义HttpSecurity我如何测试它:
请伙计们以某种方式帮助我。我没电了 我讨厌在应该有效的事情上浪费太多时间:(
您可能错过了 WebSecurityConfigurerAdapter 中的以下方法:
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
Run Code Online (Sandbox Code Playgroud)
我也遇到了同样的情况。
| 归档时间: |
|
| 查看次数: |
5258 次 |
| 最近记录: |