|
|
@@ -1,7 +1,12 @@
|
|
|
package com.zhongzheng.framework.security.filter;
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.http.HttpStatus;
|
|
|
+import com.zhongzheng.common.core.domain.AjaxResult;
|
|
|
import com.zhongzheng.common.core.domain.model.TopLoginUser;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
import com.zhongzheng.framework.web.service.TopTokenService;
|
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
|
import com.zhongzheng.common.core.domain.model.LoginUser;
|
|
|
@@ -47,39 +52,46 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
|
|
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
|
|
throws ServletException, IOException
|
|
|
{
|
|
|
- String wxToken = wxTokenService.getToken(request);
|
|
|
+ try{
|
|
|
+ String wxToken = wxTokenService.getToken(request);
|
|
|
|
|
|
- if(StringUtils.isNoneEmpty(wxToken)){
|
|
|
- ClientLoginUser clientLoginUser = wxTokenService.getLoginUser(request);
|
|
|
- if(clientLoginUser!=null){
|
|
|
- wxTokenService.verifyToken(clientLoginUser);
|
|
|
- UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(clientLoginUser, null,null);
|
|
|
- authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
- SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(!enabledTenant){
|
|
|
- //SAAS管理员
|
|
|
- TopLoginUser top_loginUser = topTokenService.getLoginUser(request);
|
|
|
- if (Validator.isNotNull(top_loginUser) && Validator.isNull(SecurityUtils.getAuthentication()))
|
|
|
- {
|
|
|
- topTokenService.verifyToken(top_loginUser);
|
|
|
- UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(top_loginUser, null, top_loginUser.getAuthorities());
|
|
|
+ if(StringUtils.isNoneEmpty(wxToken)){
|
|
|
+ ClientLoginUser clientLoginUser = wxTokenService.getLoginUser(request);
|
|
|
+ if(clientLoginUser!=null){
|
|
|
+ wxTokenService.verifyToken(clientLoginUser);
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(clientLoginUser, null,null);
|
|
|
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
}
|
|
|
}else{
|
|
|
- //子系统
|
|
|
- LoginUser loginUser = tokenService.getLoginUser(request);
|
|
|
- if (Validator.isNotNull(loginUser) && Validator.isNull(SecurityUtils.getAuthentication()))
|
|
|
- {
|
|
|
- tokenService.verifyToken(loginUser);
|
|
|
- UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
|
|
- authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
- SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
+ if(!enabledTenant){
|
|
|
+ //SAAS管理员
|
|
|
+ TopLoginUser top_loginUser = topTokenService.getLoginUser(request);
|
|
|
+ if (Validator.isNotNull(top_loginUser) && Validator.isNull(SecurityUtils.getAuthentication()))
|
|
|
+ {
|
|
|
+ topTokenService.verifyToken(top_loginUser);
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(top_loginUser, null, top_loginUser.getAuthorities());
|
|
|
+ authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //子系统
|
|
|
+ LoginUser loginUser = null;
|
|
|
+
|
|
|
+ loginUser = tokenService.getLoginUser(request);
|
|
|
+
|
|
|
+ if (Validator.isNotNull(loginUser) && Validator.isNull(SecurityUtils.getAuthentication()))
|
|
|
+ {
|
|
|
+ tokenService.verifyToken(loginUser);
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
|
|
|
+ authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
+ SecurityContextHolder.getContext().setAuthentication(authenticationToken);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ request.getRequestDispatcher("/filter/token_auth_fail").forward(request, response);
|
|
|
}
|
|
|
chain.doFilter(request, response);
|
|
|
}
|