Commit 0e7721c351cca033e3dd69a2ad894ba2453d93b1
1 parent
0d6f8627
登录Token失效时间支持分环境配置,dev,test环境有效期1年,prod环境12小时
Signed-off-by: TanYibin <5491541@qq.com>
Showing
11 changed files
with
98 additions
and
41 deletions
ant-design-vue-jeecg/src/components/layouts/UserLayout.vue
ant-design-vue-jeecg/src/components/page/GlobalLayout.vue
... | ... | @@ -354,10 +354,10 @@ body { |
354 | 354 | } |
355 | 355 | |
356 | 356 | .avatar { |
357 | - margin: 20px 10px 20px 0; | |
357 | + margin: 18px 0px 17px 0px; | |
358 | 358 | color: #1890ff; |
359 | 359 | background: hsla(0, 0%, 100%, .85); |
360 | - vertical-align: middle; | |
360 | + vertical-align: top; | |
361 | 361 | } |
362 | 362 | |
363 | 363 | .icon { |
... | ... | @@ -645,7 +645,7 @@ body { |
645 | 645 | padding: 4px 0; |
646 | 646 | |
647 | 647 | .ant-dropdown-menu-item { |
648 | - width: 126px; | |
648 | + width: auto; | |
649 | 649 | } |
650 | 650 | |
651 | 651 | .ant-dropdown-menu-item > .anticon:first-child, |
... | ... |
ant-design-vue-jeecg/src/components/tools/Logo.vue
ant-design-vue-jeecg/src/components/tools/UserMenu.vue
... | ... | @@ -36,8 +36,8 @@ |
36 | 36 | <header-notice class="action"/> |
37 | 37 | <a-dropdown> |
38 | 38 | <span class="action action-full ant-dropdown-link user-dropdown-menu"> |
39 | - <!-- <a-avatar class="avatar" size="small" :src="getAvatar()"/> --> | |
40 | - <span v-if="isDesktop()">欢迎您,{{ nickname() }}</span> | |
39 | + <a-avatar class="avatar" size="small" :src="getAvatar()"/> | |
40 | + <span v-if="isDesktop()" style="padding: 0px 0px 0px 10px;">欢迎您,{{ nickname() }}</span> | |
41 | 41 | </span> |
42 | 42 | <a-menu slot="overlay" class="user-dropdown-menu-wrapper"> |
43 | 43 | <!-- <a-menu-item key="0"> |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/cas/controller/CasClientController.java
... | ... | @@ -5,15 +5,9 @@ import java.util.List; |
5 | 5 | import javax.servlet.http.HttpServletRequest; |
6 | 6 | import javax.servlet.http.HttpServletResponse; |
7 | 7 | |
8 | -import cn.hutool.crypto.SecureUtil; | |
9 | -import cn.monitor4all.logRecord.annotation.OperationLog; | |
10 | - | |
11 | 8 | import org.apache.commons.lang.StringUtils; |
12 | 9 | import org.jeecg.common.api.vo.Result; |
13 | -import org.jeecg.common.constant.CacheConstant; | |
14 | 10 | import org.jeecg.common.constant.CommonConstant; |
15 | -import org.jeecg.utils.HuahengJwtUtil; | |
16 | -import org.jeecg.common.system.vo.LoginUser; | |
17 | 11 | import org.jeecg.common.util.RedisUtil; |
18 | 12 | import org.jeecg.modules.cas.util.CASServiceUtil; |
19 | 13 | import org.jeecg.modules.cas.util.XmlUtils; |
... | ... | @@ -21,7 +15,7 @@ import org.jeecg.modules.system.entity.SysDepart; |
21 | 15 | import org.jeecg.modules.system.entity.SysUser; |
22 | 16 | import org.jeecg.modules.system.service.ISysDepartService; |
23 | 17 | import org.jeecg.modules.system.service.ISysUserService; |
24 | -import org.springframework.beans.BeanUtils; | |
18 | +import org.jeecg.utils.HuahengJwtUtil; | |
25 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
26 | 20 | import org.springframework.beans.factory.annotation.Value; |
27 | 21 | import org.springframework.http.HttpEntity; |
... | ... | @@ -45,11 +39,21 @@ import lombok.extern.slf4j.Slf4j; |
45 | 39 | @RestController |
46 | 40 | @RequestMapping("/sys/cas/client") |
47 | 41 | public class CasClientController { |
42 | + | |
43 | + /** Token失效时间 */ | |
44 | + private Long TOKEN_EXPIRE_TIME; | |
45 | + | |
46 | + @Value("${system.token.expireTime}") | |
47 | + public void setExpireTime(String expireTime) { | |
48 | + TOKEN_EXPIRE_TIME = Long.parseLong(expireTime); | |
49 | + } | |
48 | 50 | |
49 | 51 | @Autowired |
50 | 52 | private ISysUserService sysUserService; |
53 | + | |
51 | 54 | @Autowired |
52 | 55 | private ISysDepartService sysDepartService; |
56 | + | |
53 | 57 | @Autowired |
54 | 58 | private RedisUtil redisUtil; |
55 | 59 | |
... | ... | @@ -83,7 +87,7 @@ public class CasClientController { |
83 | 87 | String token = HuahengJwtUtil.sign(sysUser.getUsername(), sysUser.getPassword()); |
84 | 88 | // 设置超时时间 |
85 | 89 | redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
86 | - redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, HuahengJwtUtil.EXPIRE_TIME / 1000); | |
90 | + redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, TOKEN_EXPIRE_TIME / 1000); | |
87 | 91 | |
88 | 92 | // 获取用户部门信息 |
89 | 93 | JSONObject obj = new JSONObject(); |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/LoginController.java
... | ... | @@ -50,6 +50,7 @@ import org.jeecg.utils.config.ApplicationConfig; |
50 | 50 | import org.jeecg.utils.support.SystemRSA256Key; |
51 | 51 | import org.springframework.beans.BeanUtils; |
52 | 52 | import org.springframework.beans.factory.annotation.Autowired; |
53 | +import org.springframework.beans.factory.annotation.Value; | |
53 | 54 | import org.springframework.context.annotation.Bean; |
54 | 55 | import org.springframework.core.io.DefaultResourceLoader; |
55 | 56 | import org.springframework.core.io.ResourceLoader; |
... | ... | @@ -89,6 +90,15 @@ import lombok.extern.slf4j.Slf4j; |
89 | 90 | @Api(tags = "用户登录") |
90 | 91 | @Slf4j |
91 | 92 | public class LoginController { |
93 | + | |
94 | + /** Token失效时间 */ | |
95 | + private Long TOKEN_EXPIRE_TIME; | |
96 | + | |
97 | + @Value("${system.token.expireTime}") | |
98 | + public void setExpireTime(String expireTime) { | |
99 | + TOKEN_EXPIRE_TIME = Long.parseLong(expireTime); | |
100 | + } | |
101 | + | |
92 | 102 | @Autowired |
93 | 103 | private ISysUserService sysUserService; |
94 | 104 | |
... | ... | @@ -115,7 +125,7 @@ public class LoginController { |
115 | 125 | |
116 | 126 | @Autowired |
117 | 127 | private HuahengRedisUtil huahengRedisUtil; |
118 | - | |
128 | + | |
119 | 129 | @Autowired |
120 | 130 | private ApplicationConfig applicationConfig; |
121 | 131 | |
... | ... | @@ -226,7 +236,7 @@ public class LoginController { |
226 | 236 | private Result<JSONObject> checkSystemActivationCode() throws IOException { |
227 | 237 | Result<JSONObject> result = new Result<JSONObject>(); |
228 | 238 | // 是否需要校验激活码 |
229 | - if(applicationConfig.getCheckSystemActivationCode() != null && !applicationConfig.getCheckSystemActivationCode()) { | |
239 | + if (applicationConfig.getCheckSystemActivationCode() != null && !applicationConfig.getCheckSystemActivationCode()) { | |
230 | 240 | return result; |
231 | 241 | } |
232 | 242 | FileInputStream inputStream = null; |
... | ... | @@ -312,7 +322,7 @@ public class LoginController { |
312 | 322 | } |
313 | 323 | return result; |
314 | 324 | } |
315 | - | |
325 | + | |
316 | 326 | /** |
317 | 327 | * 退出登录 |
318 | 328 | * @param request |
... | ... | @@ -615,7 +625,7 @@ public class LoginController { |
615 | 625 | String token = HuahengJwtUtil.sign(username, syspassword, warehouseCode, roles); |
616 | 626 | // 设置token缓存有效时间 |
617 | 627 | redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
618 | - redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, HuahengJwtUtil.EXPIRE_TIME / 1000); | |
628 | + redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, TOKEN_EXPIRE_TIME / 1000); | |
619 | 629 | obj.put("token", token); |
620 | 630 | obj.put("userInfo", sysUser); |
621 | 631 | obj.put("sysAllDictItems", sysDictService.queryAllDictItems()); |
... | ... | @@ -721,7 +731,7 @@ public class LoginController { |
721 | 731 | String token = JwtUtil.sign(username, syspassword); |
722 | 732 | // 设置超时时间 |
723 | 733 | redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
724 | - redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, HuahengJwtUtil.EXPIRE_TIME / 1000); | |
734 | + redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, TOKEN_EXPIRE_TIME / 1000); | |
725 | 735 | |
726 | 736 | // token 信息 |
727 | 737 | obj.put("token", token); |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/ThirdLoginController.java
1 | 1 | package org.jeecg.modules.system.controller; |
2 | 2 | |
3 | -import com.alibaba.fastjson.JSONObject; | |
4 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
5 | -import com.xkcoding.justauth.AuthRequestFactory; | |
6 | -import io.swagger.annotations.ApiOperation; | |
7 | -import lombok.extern.slf4j.Slf4j; | |
8 | -import me.zhyd.oauth.model.AuthCallback; | |
9 | -import me.zhyd.oauth.model.AuthResponse; | |
10 | -import me.zhyd.oauth.request.AuthRequest; | |
11 | -import me.zhyd.oauth.utils.AuthStateUtils; | |
3 | +import java.io.IOException; | |
4 | +import java.io.UnsupportedEncodingException; | |
5 | +import java.net.URLEncoder; | |
6 | +import java.util.List; | |
7 | + | |
8 | +import javax.servlet.http.HttpServletResponse; | |
9 | + | |
12 | 10 | import org.jeecg.common.api.vo.Result; |
13 | 11 | import org.jeecg.common.constant.CommonConstant; |
14 | -import org.jeecg.utils.HuahengJwtUtil; | |
15 | 12 | import org.jeecg.common.util.PasswordUtil; |
16 | 13 | import org.jeecg.common.util.RedisUtil; |
17 | 14 | import org.jeecg.common.util.RestUtil; |
... | ... | @@ -26,16 +23,30 @@ import org.jeecg.modules.system.service.ISysThirdAccountService; |
26 | 23 | import org.jeecg.modules.system.service.ISysUserService; |
27 | 24 | import org.jeecg.modules.system.service.impl.ThirdAppDingtalkServiceImpl; |
28 | 25 | import org.jeecg.modules.system.service.impl.ThirdAppWechatEnterpriseServiceImpl; |
26 | +import org.jeecg.utils.HuahengJwtUtil; | |
29 | 27 | import org.springframework.beans.factory.annotation.Autowired; |
28 | +import org.springframework.beans.factory.annotation.Value; | |
30 | 29 | import org.springframework.stereotype.Controller; |
31 | 30 | import org.springframework.ui.ModelMap; |
32 | -import org.springframework.web.bind.annotation.*; | |
31 | +import org.springframework.web.bind.annotation.GetMapping; | |
32 | +import org.springframework.web.bind.annotation.PathVariable; | |
33 | +import org.springframework.web.bind.annotation.PostMapping; | |
34 | +import org.springframework.web.bind.annotation.RequestBody; | |
35 | +import org.springframework.web.bind.annotation.RequestMapping; | |
36 | +import org.springframework.web.bind.annotation.RequestMethod; | |
37 | +import org.springframework.web.bind.annotation.RequestParam; | |
38 | +import org.springframework.web.bind.annotation.ResponseBody; | |
33 | 39 | |
34 | -import javax.servlet.http.HttpServletResponse; | |
35 | -import java.io.IOException; | |
36 | -import java.io.UnsupportedEncodingException; | |
37 | -import java.net.URLEncoder; | |
38 | -import java.util.List; | |
40 | +import com.alibaba.fastjson.JSONObject; | |
41 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
42 | +import com.xkcoding.justauth.AuthRequestFactory; | |
43 | + | |
44 | +import io.swagger.annotations.ApiOperation; | |
45 | +import lombok.extern.slf4j.Slf4j; | |
46 | +import me.zhyd.oauth.model.AuthCallback; | |
47 | +import me.zhyd.oauth.model.AuthResponse; | |
48 | +import me.zhyd.oauth.request.AuthRequest; | |
49 | +import me.zhyd.oauth.utils.AuthStateUtils; | |
39 | 50 | |
40 | 51 | /** |
41 | 52 | * @Author scott |
... | ... | @@ -45,22 +56,36 @@ import java.util.List; |
45 | 56 | @RequestMapping("/sys/thirdLogin") |
46 | 57 | @Slf4j |
47 | 58 | public class ThirdLoginController { |
59 | + | |
60 | + /** Token失效时间 */ | |
61 | + private Long TOKEN_EXPIRE_TIME; | |
62 | + | |
63 | + @Value("${system.token.expireTime}") | |
64 | + public void setExpireTime(String expireTime) { | |
65 | + TOKEN_EXPIRE_TIME = Long.parseLong(expireTime); | |
66 | + } | |
67 | + | |
48 | 68 | @Autowired |
49 | 69 | private ISysUserService sysUserService; |
70 | + | |
50 | 71 | @Autowired |
51 | 72 | private ISysThirdAccountService sysThirdAccountService; |
52 | 73 | |
53 | 74 | @Autowired |
54 | 75 | private BaseCommonService baseCommonService; |
76 | + | |
55 | 77 | @Autowired |
56 | 78 | private RedisUtil redisUtil; |
79 | + | |
57 | 80 | @Autowired |
58 | 81 | private AuthRequestFactory factory; |
59 | 82 | |
60 | 83 | @Autowired |
61 | 84 | ThirdAppConfig thirdAppConfig; |
85 | + | |
62 | 86 | @Autowired |
63 | 87 | private ThirdAppWechatEnterpriseServiceImpl thirdAppWechatEnterpriseService; |
88 | + | |
64 | 89 | @Autowired |
65 | 90 | private ThirdAppDingtalkServiceImpl thirdAppDingtalkService; |
66 | 91 | |
... | ... | @@ -198,7 +223,7 @@ public class ThirdLoginController { |
198 | 223 | String token = HuahengJwtUtil.sign(user.getUsername(), user.getPassword()); |
199 | 224 | redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
200 | 225 | // 设置超时时间 |
201 | - redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, HuahengJwtUtil.EXPIRE_TIME / 1000); | |
226 | + redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, TOKEN_EXPIRE_TIME / 1000); | |
202 | 227 | return token; |
203 | 228 | } |
204 | 229 | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java
... | ... | @@ -17,6 +17,7 @@ import org.jeecg.utils.support.ApiAuthentication; |
17 | 17 | import org.jeecg.utils.support.RSA256Key; |
18 | 18 | import org.jeecg.utils.support.SystemAuthentication; |
19 | 19 | import org.jeecg.utils.support.SystemRSA256Key; |
20 | +import org.springframework.beans.factory.annotation.Value; | |
20 | 21 | import org.springframework.stereotype.Component; |
21 | 22 | import org.springframework.util.CollectionUtils; |
22 | 23 | |
... | ... | @@ -35,8 +36,13 @@ import cn.hutool.core.util.StrUtil; |
35 | 36 | @Component |
36 | 37 | public class HuahengJwtUtil { |
37 | 38 | |
38 | - /** token失效时间 1天 */ | |
39 | - public static final long EXPIRE_TIME = 12 * 60 * 60 * 1000; | |
39 | + /** Token失效时间 */ | |
40 | + private static Long TOKEN_EXPIRE_TIME; | |
41 | + | |
42 | + @Value("${system.token.expireTime}") | |
43 | + public void setExpireTime(String expireTime) { | |
44 | + TOKEN_EXPIRE_TIME = Long.parseLong(expireTime); | |
45 | + } | |
40 | 46 | |
41 | 47 | /** 仓库视察员角色 */ |
42 | 48 | public static final String USER_ROLE_INSPECTOR = "inspector"; |
... | ... | @@ -164,7 +170,7 @@ public class HuahengJwtUtil { |
164 | 170 | * @return 加密的token |
165 | 171 | */ |
166 | 172 | public static String sign(String username, String secret) { |
167 | - Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); | |
173 | + Date date = new Date(System.currentTimeMillis() + TOKEN_EXPIRE_TIME); | |
168 | 174 | Algorithm algorithm = Algorithm.HMAC256(secret); |
169 | 175 | // 附带username信息 |
170 | 176 | return JWT.create().withClaim("username", username).withExpiresAt(date).sign(algorithm); |
... | ... | @@ -179,7 +185,7 @@ public class HuahengJwtUtil { |
179 | 185 | * @return 加密的token |
180 | 186 | */ |
181 | 187 | public static String sign(String username, String secret, String warehouseCode, List<String> roles) { |
182 | - Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); | |
188 | + Date date = new Date(System.currentTimeMillis() + TOKEN_EXPIRE_TIME); | |
183 | 189 | Algorithm algorithm = Algorithm.HMAC256(secret); |
184 | 190 | // 附带username信息 |
185 | 191 | return JWT.create().withClaim("username", username).withClaim("warehouseCode", warehouseCode).withClaim("roles", roles).withExpiresAt(date).sign(algorithm); |
... | ... |
huaheng-wms-core/src/main/resources/application-dev.yml
huaheng-wms-core/src/main/resources/application-prod.yml