Commit 4d5a986fb519e09957bb9babbad8bd26303b4304
1 parent
a81998c216
Exists in
master
and in
6 other branches
拦截
Showing 4 changed files with 76 additions and 5 deletions
- platform-common/src/main/java/com/lyms/platform/common/base/ExceptionHandlerController.java
- platform-common/src/main/java/com/lyms/platform/common/exception/ForbiddenException.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/TokenValidateInteceptor.java
- platform-operate-api/src/main/resources/config.properties
platform-common/src/main/java/com/lyms/platform/common/base/ExceptionHandlerController.java
View file @
4d5a986
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | import com.lyms.platform.common.constants.ErrorCodeConstants; |
| 4 | 4 | import com.lyms.platform.common.core.resolve.MessageResolver; |
| 5 | 5 | import com.lyms.platform.common.exception.BusinessException; |
| 6 | +import com.lyms.platform.common.exception.ForbiddenException; | |
| 6 | 7 | import com.lyms.platform.common.exception.ParameterException; |
| 7 | 8 | import com.lyms.platform.common.exception.TokenException; |
| 8 | 9 | import com.lyms.platform.common.result.BaseResponse; |
| 9 | 10 | |
| ... | ... | @@ -106,8 +107,18 @@ |
| 106 | 107 | setHttpResponseHeader(httpServletResponse); |
| 107 | 108 | Map<String, Object> resultMap = new HashMap<>(); |
| 108 | 109 | resultMap.put("errorcode", ErrorCodeConstants.TOKEN_EXPIRE); |
| 109 | -// resultMap.put("errormsg", "您当前用户登录状态异常,暂时无法访问,请重新登录"); | |
| 110 | 110 | resultMap.put("errormsg", "登录过期,请重新登录"); |
| 111 | + return resultMap; | |
| 112 | + } | |
| 113 | + | |
| 114 | + @ResponseStatus(HttpStatus.FORBIDDEN) | |
| 115 | + @ExceptionHandler(ForbiddenException.class) | |
| 116 | + @ResponseBody | |
| 117 | + public Map buildExcExpire(HttpServletResponse httpServletResponse) { | |
| 118 | + setHttpResponseHeader(httpServletResponse); | |
| 119 | + Map<String, Object> resultMap = new HashMap<>(); | |
| 120 | + resultMap.put("errorcode", ErrorCodeConstants.TOKEN_EXPIRE); | |
| 121 | + resultMap.put("errormsg", "Forbidden"); | |
| 111 | 122 | return resultMap; |
| 112 | 123 | } |
| 113 | 124 |
platform-common/src/main/java/com/lyms/platform/common/exception/ForbiddenException.java
View file @
4d5a986
| 1 | +package com.lyms.platform.common.exception; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by Administrator on 2015/9/29 0029. | |
| 5 | + */ | |
| 6 | +public class ForbiddenException extends RuntimeException { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * | |
| 10 | + */ | |
| 11 | + private static final long serialVersionUID = 1L; | |
| 12 | + | |
| 13 | + private String code; | |
| 14 | + | |
| 15 | + private String message; | |
| 16 | + | |
| 17 | + public ForbiddenException() { | |
| 18 | + | |
| 19 | + } | |
| 20 | + | |
| 21 | + public ForbiddenException(String code, String message) { | |
| 22 | + this.code = code; | |
| 23 | + this.message = message; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public String getCode() { | |
| 27 | + return code; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void setCode(String code) { | |
| 31 | + this.code = code; | |
| 32 | + } | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public String getMessage() { | |
| 36 | + return message; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public void setMessage(String message) { | |
| 40 | + this.message = message; | |
| 41 | + } | |
| 42 | +} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/inteceptor/TokenValidateInteceptor.java
View file @
4d5a986
| ... | ... | @@ -5,8 +5,10 @@ |
| 5 | 5 | import com.lyms.platform.common.base.BaseController; |
| 6 | 6 | import com.lyms.platform.common.base.ContextHolder; |
| 7 | 7 | import com.lyms.platform.common.base.LoginContext; |
| 8 | +import com.lyms.platform.common.exception.ForbiddenException; | |
| 8 | 9 | import com.lyms.platform.common.exception.TokenException; |
| 9 | 10 | import com.lyms.platform.common.utils.LogUtil; |
| 11 | +import com.lyms.platform.common.utils.PropertiesUtils; | |
| 10 | 12 | import com.lyms.platform.operate.web.session.SessionProvider; |
| 11 | 13 | import com.lyms.platform.permission.service.UsersService; |
| 12 | 14 | import org.apache.commons.lang.StringUtils; |
| ... | ... | @@ -30,6 +32,9 @@ |
| 30 | 32 | */ |
| 31 | 33 | public class TokenValidateInteceptor extends HandlerInterceptorAdapter { |
| 32 | 34 | |
| 35 | + public static final String XT_VERSION = PropertiesUtils.getPropertyValue("xt_version"); | |
| 36 | + | |
| 37 | + | |
| 33 | 38 | @Autowired |
| 34 | 39 | private SessionProvider sessionProvider; |
| 35 | 40 | |
| ... | ... | @@ -40,10 +45,21 @@ |
| 40 | 45 | @Override |
| 41 | 46 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| 42 | 47 | |
| 43 | - String referer = request.getHeader("Referer"); | |
| 44 | - String url = request.getRequestURL().toString(); | |
| 45 | - System.out.println("referer====="+referer); | |
| 46 | - System.out.println("url====="+url); | |
| 48 | + if (XT_VERSION != null && XT_VERSION.equals("xt_version")) | |
| 49 | + { | |
| 50 | + String referer = request.getHeader("Referer"); | |
| 51 | + String url = request.getRequestURL().toString(); | |
| 52 | + System.out.println("referer====="+referer); | |
| 53 | + System.out.println("url====="+url); | |
| 54 | + if (StringUtils.isNotEmpty(referer) && !referer.contains("area-xtrm.healthbaby.com.cn")) | |
| 55 | + { | |
| 56 | + throw new ForbiddenException(); | |
| 57 | + } | |
| 58 | + else if (StringUtils.isEmpty(referer) && !url.contains("area-xtrm.healthbaby.com.cn")) | |
| 59 | + { | |
| 60 | + throw new ForbiddenException(); | |
| 61 | + } | |
| 62 | + } | |
| 47 | 63 | |
| 48 | 64 | if (!isSiteController(handler)) |
| 49 | 65 | return true; |