From 1c63c752fbe54f770e7cf90ee91f8d85d828064d Mon Sep 17 00:00:00 2001 From: yangjie <1179743470@qq.com> Date: Tue, 8 Jun 2021 16:23:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=93=E5=AE=B6=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yipin/liuwanr/entity/UserIdEnum.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/com/yipin/liuwanr/entity/UserIdEnum.java diff --git a/src/main/java/com/yipin/liuwanr/entity/UserIdEnum.java b/src/main/java/com/yipin/liuwanr/entity/UserIdEnum.java new file mode 100644 index 0000000..92be97d --- /dev/null +++ b/src/main/java/com/yipin/liuwanr/entity/UserIdEnum.java @@ -0,0 +1,41 @@ +package com.yipin.liuwanr.entity; + +public enum UserIdEnum { + + USER_ONE(1504,"10000000"), + USER_TWO(1505,"10000000"), + USER_THREE(1506,"10000000"), + USER_FOUR(1507,"10000000"), + USER_FIVE(1508,"10000000"), + USER_SIX(1509,"10000000"), + USER_SEVEN(1510,"10000000"), + USER_EIGHT(1511,"10000000"), + USER_NINE(1512,"10000000"), + USER_TEN(1513,"10000000"); + + private final Integer userId; + private final String name; + + UserIdEnum(Integer value, String name) { + this.userId = value; + this.name = name; + } + + public static Integer getUserId(int userValue){ + for (UserIdEnum value : UserIdEnum.values()) { + if (value.userId==userValue){ + return value.userId; + } + } + return 0; + } + + public Integer getUserId() { + return userId; + } + + public String getName() { + return name; + } + +} From 655b25fb98592c1938027c60f2e0c2c6e5483b55 Mon Sep 17 00:00:00 2001 From: yangjie <1179743470@qq.com> Date: Tue, 8 Jun 2021 16:24:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=98=AF=E4=B8=93=E5=AE=B6=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yipin/liuwanr/filter/AuthInterceptor.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java b/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java index 70caa25..2c31ddf 100644 --- a/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java +++ b/src/main/java/com/yipin/liuwanr/filter/AuthInterceptor.java @@ -1,6 +1,7 @@ package com.yipin.liuwanr.filter; +import com.yipin.liuwanr.entity.UserIdEnum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.ValueOperations; @@ -21,6 +22,7 @@ import java.util.concurrent.TimeUnit; **/ public class AuthInterceptor implements HandlerInterceptor { + @Resource StringRedisTemplate stringRedisTemplate; @@ -28,24 +30,29 @@ public class AuthInterceptor implements HandlerInterceptor { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); - String token = request.getHeader("token"); - if (StringUtils.isEmpty(token)) { - response.getWriter().print("0");//用户未登录,请登录后操作! - return false; - } - ValueOperations ops = stringRedisTemplate.opsForValue(); - Object loginStatus = ops.get(token); //userid String userId = request.getParameter("userId"); - if( Objects.isNull(loginStatus)){ - response.getWriter().print("1");//token错误 - return false; + if (UserIdEnum.getUserId(Integer.parseInt(userId))!=0){ + return true; }else { - if (!StringUtils.isEmpty(userId)){ - return userId.equals(loginStatus); + + String token = request.getHeader("token"); + ValueOperations ops = stringRedisTemplate.opsForValue(); + Object loginStatus = ops.get(token); + if (StringUtils.isEmpty(token)) { + response.getWriter().print("0");//用户未登录,请登录后操作! + return false; + } + if( Objects.isNull(loginStatus)){ + response.getWriter().print("1");//token错误 + return false; }else { - return true; + if (!StringUtils.isEmpty(userId)){ + return userId.equals(loginStatus); + }else { + return true; + } } } } From fdb0443c3e65201b25dc0e1b02309a7cca85127c Mon Sep 17 00:00:00 2001 From: yangjie <1179743470@qq.com> Date: Tue, 8 Jun 2021 16:25:40 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=94=BE=E8=A1=8Clogins,?= =?UTF-8?q?=20=E8=A7=A3=E5=86=B3=E8=B6=8A=E6=9D=83=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-prod.properties | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 1ac71b4..7188280 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -56,4 +56,12 @@ redis.cluster.minIdle=3 redis.cluster.nodes=192.168.136.191:8000,192.168.136.191:8001,192.168.136.191:8002 server.port=8090 -server.servlet.context-path= /liuwanr \ No newline at end of file +server.servlet.context-path= /liuwanr + + +#ȫ,Ϊղ +#auth.openInterceptStr= +auth.openInterceptStr=/** +#Url +auth.permitUrl=/userInfo/adminLogins/**,/userInfo/loginSchoolClient/**,/province/queryProvince/**,/city/queryCity/**,/customer/querySchool/**,/userInfo/queryPhone/**,/userInfo/updateLogInNumber/**,/userInfo/getAccountPassword +