如何解决Spring Security的addFilter和permitAll都不起作用
我有如下配置文件
@Configuration
@EnableWebSecurity
@Order(1)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(jwt -> {
jwt.decoder(jwtDecoder());
})
)
.authorizeRequests().antMatchers("/oauth/authorize").permitAll()
.anyRequest().authenticated()
.and()
.addFilterBefore(new DevHttp302Filter(),BasicAuthenticationFilter.class);
}
@Bean
public JwtDecoder jwtDecoder() {
String key = "abc";
SecretKey secretKey = new SecretKeySpec(key.getBytes(),"HMACSHA256");
return NimbusJwtDecoder
.withSecretKey(secretKey)
.build();
}
}
我希望此安全性不会应用于/ oauth / authorize url,但会应用并返回401,并且addFilter方法也不起作用。 (此过滤器基本上会执行以下操作:如果响应状态为401,则将其更改为302并重定向另一个位置进行登录。)
在使用oauth2ResourceServer()时如何实现这些行为?
谢谢
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。