ÎļþÃû´Ó se-system/src/main/java/com/terra/system/interceptor/AuthInterceptor.java ÐÞ¸Ä |
| | |
| | | package com.terra.system.interceptor; |
| | | package com.terra.common.interceptor; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.terra.common.entity.all.HttpStatus; |
| | | import com.terra.common.entity.all.ResponseMsg; |
| | | import com.terra.common.entity.all.StaticData; |
| | | import com.terra.system.entity.sys.TokenEntity; |
| | | import com.terra.system.entity.sys.UserEntity; |
| | | import com.terra.common.entity.lf.UserPo; |
| | | import com.terra.common.helper.StringHelper; |
| | | import com.terra.common.helper.WebHelper; |
| | | import com.terra.system.service.all.SysService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | */ |
| | | @Configuration |
| | | public class AuthInterceptor implements HandlerInterceptor { |
| | | private final SysService sysService; |
| | | |
| | | private static final Log log = LogFactory.getLog(AuthInterceptor.class); |
| | | |
| | | private static final String NO_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.TOKEN_ERROR, "æ¾ä¸å°ä»¤ç")); |
| | |
| | | |
| | | private static final String ILLEGAL_TOKEN = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.UNAUTHORIZED, "ä»¤çæ¥æºéæ³")); |
| | | |
| | | public AuthInterceptor(SysService sysService) { |
| | | this.sysService = sysService; |
| | | } |
| | | //public AuthInterceptor(SysService sysService) { |
| | | // this.sysService = sysService; |
| | | //} |
| | | |
| | | /** |
| | | * Controlleræ§è¡ä¹åæ§è¡ï¼å¦æè¿å弿¯trueå代表æ¾è¡ï¼è¿åfalseåæ¦æª |
| | |
| | | } |
| | | |
| | | // 3.è·åç¨æ·ä»¤ç |
| | | UserEntity ue = sysService.tokenService.getUserByToken(token); |
| | | UserPo ue = new UserPo(); //sysService.tokenService.getUserByToken(token); |
| | | if (ue == null) { |
| | | return WebHelper.writeStr2Page(response, NO_LOGIN); |
| | | } |
| | |
| | | } |
| | | |
| | | // 8.æ£æ¥ç¨æ·IDæ¯å¦ç¦ç¨ |
| | | if (sysService.tokenService.isUidDisable(ue)) { |
| | | return WebHelper.writeStr2Page(response, USER_LOCK); |
| | | } |
| | | //if (sysService.tokenService.isUidDisable(ue)) { |
| | | // return WebHelper.writeStr2Page(response, USER_LOCK); |
| | | //} |
| | | |
| | | // 9.æéæ ¡éª |
| | | if (!checkPerms(ue, request)) { |
| | |
| | | /** |
| | | * æ£æ¥æé |
| | | */ |
| | | private boolean checkPerms(UserEntity ue, HttpServletRequest request) { |
| | | List<String> list = sysService.permsService.selectPerms(ue.getUid()); |
| | | private boolean checkPerms(UserPo ue, HttpServletRequest request) { |
| | | List<String> list = null; //sysService.permsService.selectPerms(ue.getUid()); |
| | | if (list == null || list.size() == 0) { |
| | | return false; |
| | | } |
| | |
| | | * æ£æ¥é»åå |
| | | */ |
| | | private boolean checkBlackList(String ip, HttpServletRequest request) { |
| | | List<String> blackList = sysService.blacklistService.selectIpList(1); |
| | | List<String> blackList = null; // sysService.blacklistService.selectIpList(1); |
| | | if (blackList == null || blackList.isEmpty()) { |
| | | return true; |
| | | } |
| | |
| | | * æ£æ¥ç½åå |
| | | */ |
| | | private boolean checkWhiteList(String ip, HttpServletRequest request) { |
| | | List<String> whiteList = sysService.blacklistService.selectIpList(2); |
| | | List<String> whiteList = null; // sysService.blacklistService.selectIpList(2); |
| | | if (whiteList == null || whiteList.isEmpty()) { |
| | | return false; |
| | | } |
| | |
| | | * æ£æ¥IPä¸è´æ§ï¼åºå®ä»¤ç䏿£æ¥ |
| | | */ |
| | | private boolean checkIpSource(String ip, String token) { |
| | | TokenEntity te = sysService.tokenService.getEntityByToken(token); |
| | | //TokenEntity te = sysService.tokenService.getEntityByToken(token); |
| | | |
| | | return StaticData.I1 == te.getType() || te.getIp().equals(ip); |
| | | //return StaticData.I1 == te.getType() || te.getIp().equals(ip); |
| | | |
| | | return true; |
| | | } |
| | | } |