我需要在我的代码上使用请求范围来获取和使用 JWT 令牌上的授权,每个请求都有一个单独的令牌,每个请求都需要一个独立的验证。当任何请求过程没有任何错误时,一切正常,但如果应用程序抛出任何运行时异常,例如 BadRequestException,响应中断:java.lang.IllegalStateException: No thread-bound request found
我正在使用带有 Ribbon、Feign 和 Hystrix 的 Spring 云环境。
这里的 WebSecurityConfigurerAdapter 实现:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilterBefore(new JWTAuthenticationFilter(enviroment, jwtAuthenticationService, authScope),
UsernamePasswordAuthenticationFilter.class)
.httpBasic()
.and()
.csrf().disable();
http.headers().frameOptions().sameOrigin();
}
我之前的过滤器
package br.com.qisi.twoface.configuration.security.jwt;
import br.com.qisi.twoface.authorization.model.Authorization;
import br.com.qisi.twoface.configuration.security.AuthRequestScope;
import io.jsonwebtoken.Claims;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.GenericFilterBean;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
}
慕哥6287543
相关分类