【发布时间】:2021-12-30 10:44:54
【问题描述】:
我有以下配置:
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Configuration
@Order(1)
public static class SamlConfig extends WebSecurityConfigurerAdapter {
@Value("${enable_csrf}")
private Boolean enableCsrf;
@Autowired
private SamlUserService samlUserService;
public SamlWebSecurityConfig() {
super();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/secure/sso").permitAll()
.antMatchers("/saml/**").permitAll()
.anyRequest().authenticated()
.and()
.apply(saml())
.userDetailsService(samlUserService)
.serviceProvider()
.keyStore()
.storeFilePath("path")
.password("password")
.keyname("alias")
.keyPassword("password")
.and()
.protocol("https")
.hostname(String.format("%s:%s","localhost", "8080"))
.basePath("/")
.and()
.identityProvider()
.metadataFilePath("metadata");
if (!enableCsrf) {
http.csrf().disable();
}
}
}
@Configuration
@Order(2)
public static class BasicConfig extends WebSecurityConfigurerAdapter {
public BasicWebSecurityConfig() {
super();
}
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/secure/basic").permitAll()
.anyRequest().authenticated();
if (!enableCsrf) {
http.csrf().disable();
}
}
}
这适用于 SAML,但基本登录返回错误:403 禁止。
我用这个修改了BasicConfig,SAML 不再工作,但基本身份验证工作。所有端点都用于 SAML 和基本身份验证,只是登录页面不同。
public static class BasicConfig extends WebSecurityConfigurerAdapter {
public BasicWebSecurityConfig() {
super();
}
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/secure/basic").permitAll()
.antMatchers("/**").permitAll()
.anyRequest().authenticated();
if (!enableCsrf) {
http.csrf().disable();
}
}
}
由于某些原因,它有时有效,有时无效。我也试过修改@Order,还是不行。
【问题讨论】:
标签: spring-security spring-saml