目前这样处理是得不到请求体的,其中一个filter的代码:
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
String authHeader = httpServletRequest.getHeader("Authorization");
if (authHeader != null && authHeader.startsWith("Bearer ")) {
final String authToken = authHeader.substring("Bearer ".length());
try {
String newToken = JwtUtil.refreshToken(authToken);
if (newToken != null) {
httpServletResponse.setHeader("authentication", newToken);
}
} catch (JwtException e) {
log.error(e.toString());
httpServletResponse.getWriter().write(JSON.toJSONString(Result.failure("无效的token,请重新登陆后操作")));
return;
}
String username;
try {
username = JwtUtil.parseToken(authToken);
} catch (JwtException e) {
log.error(e.toString());
httpServletResponse.getWriter().write(JSON.toJSONString(Result.failure("无效的token,请重新登陆后操作")));
return;
}
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
UserDetails userDetails = sysUserDetailsService.loadUserByUsername(username);
if (userDetails != null) {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpServletRequest));
SecurityContextHolder.getContext().setAuthentication(authentication);
}
}
}
filterChain.doFilter(httpServletRequest,httpServletResponse);
有只小跳蛙
相关分类