我已经完成了一个带有 spring 安全集成和自定义身份验证提供程序的 spring boot 应用程序。现在我希望某些链接将使用自定义 Authent 提供程序和其他一些内存身份验证。我怎样才能做到这一点?
2 回答
1
你是对的。这是我的 SecurityConfig 类。现在我想用基本身份验证保护像'/api/**'这样的路径。
@Autowired
private CustomAuthenticationProvider authProvider;
@Autowired
DataSource dataSource;
@Autowired
CustomLogoutSuccessHandler customLogoutSuccessHandler;
@Autowired
CustomAuthenticationSuccessHandler customAutheincationSuccessHandler;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/list/**").hasAnyAuthority("Administrator","Operator")
.antMatchers("/api/**").permitAll()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/authenticateTheUser")
.successHandler(customAutheincationSuccessHandler)
.and().logout()
.logoutUrl("/logout")
.logoutSuccessHandler(customLogoutSuccessHandler)
.logoutSuccessUrl("/login").and().exceptionHandling().accessDeniedPage("/accessDenied")
.and()
.csrf().disable();
}
于 2019-10-07T12:26:23.537 回答
0
您可以创建两个具有不同路径的弹簧安全配置。在第一个配置中,您可以排除 /api/**。但是第二个配置将能够检查它。
于 2019-10-08T16:19:14.510 回答