|
|
@ -17,7 +17,6 @@ import javax.servlet.ServletException;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.AccessDeniedException;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -40,10 +39,11 @@ public class AuthInnerTokenFilter extends OncePerRequestFilter {
|
|
|
|
// 验证 authToken 合法
|
|
|
|
// 验证 authToken 合法
|
|
|
|
TmdUserDetail tmdUserDetail = jwtTokenUtil.getValidUserDetail(request);
|
|
|
|
TmdUserDetail tmdUserDetail = jwtTokenUtil.getValidUserDetail(request);
|
|
|
|
if (tmdUserDetail == null) {
|
|
|
|
if (tmdUserDetail == null) {
|
|
|
|
log.error("authToken authentication failed");
|
|
|
|
log.error("authToken authentication failed: {}", request.getHeader("x-auth-authToken"));
|
|
|
|
throw new AccessDeniedException("无权限");
|
|
|
|
SecurityContextHolder.clearContext(); // 验证失败不应该在此处抛出异常,应该维护好 context 的值,以便整个过滤器链正常运行
|
|
|
|
|
|
|
|
filterChain.doFilter(request, response);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println(tmdUserDetail.getUser());
|
|
|
|
|
|
|
|
// 组装 authToken 的 jwt 进 authentication
|
|
|
|
// 组装 authToken 的 jwt 进 authentication
|
|
|
|
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
|
|
|
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
|
|
|
|
UsernamePasswordAuthenticationToken finalAuthentication = new UsernamePasswordAuthenticationToken(tmdUserDetail, null, authorities);
|
|
|
|
UsernamePasswordAuthenticationToken finalAuthentication = new UsernamePasswordAuthenticationToken(tmdUserDetail, null, authorities);
|
|
|
|