Commit a80a54f1de2655723c85adb4ff7f0c7435fe3773
1 parent
29a1303939
Exists in
master
and in
1 other branch
update
Showing 6 changed files with 62 additions and 0 deletions
- platform-common/src/main/java/com/lyms/platform/common/utils/LymsEncodeUtil.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/SessionProvider.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/ISessionProvider.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/LocalCacheSessionStrategy.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/UserCenterStrategy.java
- platform-operate-api/src/main/resources/database.properties
platform-common/src/main/java/com/lyms/platform/common/utils/LymsEncodeUtil.java
View file @
a80a54f
| ... | ... | @@ -29,6 +29,10 @@ |
| 29 | 29 | String json = aesDecrypt("26EB0301C4A2410E90985A3E55856E4BC90B764322A576155B201AFB0BC8C94FFAB29197A8B86F592DD2ABABF896EB89", key); |
| 30 | 30 | System.out.println("解密后:" + json); |
| 31 | 31 | |
| 32 | + String key1 = "Lymsh@2020"; | |
| 33 | + | |
| 34 | + String d = aesEncrypt("2020-04-01",key1); | |
| 35 | + System.out.println("加密:" + d); | |
| 32 | 36 | } |
| 33 | 37 | |
| 34 | 38 | /** |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/SessionProvider.java
View file @
a80a54f
| 1 | 1 | package com.lyms.platform.operate.web.session; |
| 2 | 2 | |
| 3 | 3 | import com.lyms.platform.common.base.LoginContext; |
| 4 | +import com.lyms.platform.common.utils.DateUtil; | |
| 5 | +import com.lyms.platform.common.utils.LymsEncodeUtil; | |
| 4 | 6 | import com.lyms.platform.operate.web.session.strategy.ISessionProvider; |
| 7 | +import org.apache.commons.lang.StringUtils; | |
| 8 | +import org.springframework.beans.factory.annotation.Value; | |
| 5 | 9 | |
| 6 | 10 | import javax.servlet.http.HttpServletRequest; |
| 7 | 11 | import javax.servlet.http.HttpServletResponse; |
| 12 | +import java.util.Date; | |
| 8 | 13 | import java.util.Map; |
| 9 | 14 | |
| 10 | 15 | /** |
| ... | ... | @@ -14,6 +19,12 @@ |
| 14 | 19 | * Created by Administrator on 2016/6/2 0002. |
| 15 | 20 | */ |
| 16 | 21 | public class SessionProvider implements ISessionProvider { |
| 22 | + | |
| 23 | + | |
| 24 | + @Value("#{configProperties['login.licence']}") | |
| 25 | + private String licence; | |
| 26 | + | |
| 27 | + | |
| 17 | 28 | /** |
| 18 | 29 | * 配置 |
| 19 | 30 | */ |
| ... | ... | @@ -52,6 +63,24 @@ |
| 52 | 63 | } |
| 53 | 64 | |
| 54 | 65 | @Override |
| 66 | + public boolean checkLicence() { | |
| 67 | + if (StringUtils.isNotEmpty(licence)) | |
| 68 | + { | |
| 69 | + try { | |
| 70 | + String content = LymsEncodeUtil.aesDecrypt(licence, key); | |
| 71 | + if (StringUtils.isNotEmpty(content)) | |
| 72 | + { | |
| 73 | + Date time = DateUtil.parseYMD(content); | |
| 74 | + return time.getTime() > new Date().getTime(); | |
| 75 | + } | |
| 76 | + } catch (Exception e) { | |
| 77 | + e.printStackTrace(); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + return true; | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Override | |
| 55 | 84 | public LoginContext checkSession(HttpServletRequest request, HttpServletResponse response, String token) { |
| 56 | 85 | ISessionProvider iSessionProvider = iSessionProviderMap.get(currentStrateger); |
| 57 | 86 | if (null != iSessionProvider) { |
| ... | ... | @@ -76,6 +105,12 @@ |
| 76 | 105 | |
| 77 | 106 | @Override |
| 78 | 107 | public LoginContext login(String account, String password, String code) { |
| 108 | + | |
| 109 | + if (!checkLicence()) | |
| 110 | + { | |
| 111 | + return null; | |
| 112 | + } | |
| 113 | + | |
| 79 | 114 | ISessionProvider iSessionProvider = iSessionProviderMap.get(currentStrateger); |
| 80 | 115 | if (null != iSessionProvider) { |
| 81 | 116 | return iSessionProvider.login(account, password, code); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/ISessionProvider.java
View file @
a80a54f
platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/LocalCacheSessionStrategy.java
View file @
a80a54f
| ... | ... | @@ -7,6 +7,8 @@ |
| 7 | 7 | import com.lyms.platform.common.enums.YnEnums; |
| 8 | 8 | import com.lyms.platform.common.exception.BusinessException; |
| 9 | 9 | import com.lyms.platform.common.exception.TokenException; |
| 10 | +import com.lyms.platform.common.utils.DateUtil; | |
| 11 | +import com.lyms.platform.common.utils.LymsEncodeUtil; | |
| 10 | 12 | import com.lyms.platform.common.utils.MD5Utils; |
| 11 | 13 | import com.lyms.platform.common.utils.TokenUtils; |
| 12 | 14 | import com.lyms.platform.permission.model.Users; |
| 13 | 15 | |
| ... | ... | @@ -15,9 +17,11 @@ |
| 15 | 17 | import org.apache.commons.collections.CollectionUtils; |
| 16 | 18 | import org.apache.commons.lang.StringUtils; |
| 17 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | +import org.springframework.beans.factory.annotation.Value; | |
| 18 | 21 | |
| 19 | 22 | import javax.servlet.http.HttpServletRequest; |
| 20 | 23 | import javax.servlet.http.HttpServletResponse; |
| 24 | +import java.util.Date; | |
| 21 | 25 | import java.util.List; |
| 22 | 26 | import java.util.Map; |
| 23 | 27 | import java.util.UUID; |
| ... | ... | @@ -40,6 +44,11 @@ |
| 40 | 44 | public static Cache<String, LoginContext> cache = CacheBuilder.newBuilder() |
| 41 | 45 | .expireAfterAccess(6, TimeUnit.HOURS) |
| 42 | 46 | .build(); |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public boolean checkLicence() { | |
| 50 | + return true; | |
| 51 | + } | |
| 43 | 52 | |
| 44 | 53 | @Override |
| 45 | 54 | public LoginContext checkSession(HttpServletRequest request, HttpServletResponse response, String token) { |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/session/strategy/UserCenterStrategy.java
View file @
a80a54f
| ... | ... | @@ -2,7 +2,9 @@ |
| 2 | 2 | |
| 3 | 3 | import com.lyms.platform.common.base.LoginContext; |
| 4 | 4 | import com.lyms.platform.common.exception.TokenException; |
| 5 | +import com.lyms.platform.common.utils.DateUtil; | |
| 5 | 6 | import com.lyms.platform.common.utils.LoginUtil; |
| 7 | +import com.lyms.platform.common.utils.LymsEncodeUtil; | |
| 6 | 8 | import com.lyms.platform.permission.model.Users; |
| 7 | 9 | import com.lyms.platform.permission.service.UsersService; |
| 8 | 10 | import org.apache.commons.lang.StringUtils; |
| ... | ... | @@ -11,6 +13,7 @@ |
| 11 | 13 | |
| 12 | 14 | import javax.servlet.http.HttpServletRequest; |
| 13 | 15 | import javax.servlet.http.HttpServletResponse; |
| 16 | +import java.util.Date; | |
| 14 | 17 | |
| 15 | 18 | /** |
| 16 | 19 | * 基于用户中心的登录策略 |
| ... | ... | @@ -25,6 +28,11 @@ |
| 25 | 28 | private String token; |
| 26 | 29 | @Value("#{configProperties['login.typeId']}") |
| 27 | 30 | private String typeId; |
| 31 | + @Override | |
| 32 | + public boolean checkLicence() { | |
| 33 | + return true; | |
| 34 | + } | |
| 35 | + | |
| 28 | 36 | @Override |
| 29 | 37 | public LoginContext checkSession(HttpServletRequest request, HttpServletResponse response,String token) { |
| 30 | 38 | LoginContext loginContext = LoginUtil.checkLoginState(token); |