Sel*_*lva 6 spring spring-security
下面是我的安全配置代码。请帮助我解决此代码中缺少的内容。如何配置过滤器,以便对 /login 和 /register 以外的 URL 模式进行 JWT 身份验证
弹簧安全核心:4.2.3,弹簧引导:1.5.4
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.antMatchers(HttpMethod.POST, "/users/register").permitAll()
.anyRequest().authenticated()
.and()
// We filter the api/login requests
.addFilterBefore(new LoginFilter("/login", authenticationManager()),
UsernamePasswordAuthenticationFilter.class)
// And filter other requests to check the presence of JWT in header
.addFilterBefore(new NoLoginAuthenticationFilter("/users/register"), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new JWTAuthenticationFilter("/**", authenticationManager()),
UsernamePasswordAuthenticationFilter.class);
}
Run Code Online (Sandbox Code Playgroud)
您想要的是忽略某些 URL。为此,覆盖采用 WebSecurity 对象并忽略模式的配置方法。
尝试将以下方法覆盖添加到您的配置类。
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers("/users/register/**");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4553 次 |
| 最近记录: |