我有以下要求:
我想出了以下Spring Security配置
@EnableWebSecurity
public class MultiHttpSecurityConfig {
@Configuration
@Order(1)
// this one does basic auth
public static class AdminSectionWebSecurityConfigurationAdapter extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(
"/some-endpoint1**",
"/some-endpoint2**",
"/some-endpoint3**",
"/admin-stuff/**"
)
.hasRole("admin")
.and()
.httpBasic();
}
}
@Configuration
// this does open to everything and JWT stuff
public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
@Value("${issuer}")
private String issuer;
@Value("${apiAudience}")
private String apiAudience;
@Override
protected void configure(final HttpSecurity http) throws Exception {
JwtWebSecurityConfigurer.forRS256(apiAudience, issuer)
.configure(http)
.authorizeRequests()
.antMatchers(
"/open-endpoint1",
"/open-endpoint2",
"/open-endpoint3")
.permitAll()
.anyRequest()
.authenticated();
}
}
}
使用此配置,基本身份验证可以正常工作,也可以打开端点,但是我希望对其进行身份验证的所有其余部分仍然对世界开放。
设置为Spring Boot 2.1.4和Spring Security 5.1.5。
JwtWebSecurityConfigurer没什么花哨的,如果我一次进行安全配置,它们也会按预期工作。
我在做什么错了?