|
3 | 3 | import com.laigeoffer.pmhub.base.core.config.redis.RedisService;
|
4 | 4 | import com.laigeoffer.pmhub.base.core.constant.CacheConstants;
|
5 | 5 | import com.laigeoffer.pmhub.base.core.constant.Constants;
|
| 6 | +import com.laigeoffer.pmhub.base.core.constant.SecurityConstants; |
6 | 7 | import com.laigeoffer.pmhub.base.core.core.domain.model.LoginUser;
|
7 | 8 | import com.laigeoffer.pmhub.base.core.utils.JwtUtils;
|
8 | 9 | import com.laigeoffer.pmhub.base.core.utils.ServletUtils;
|
@@ -41,6 +42,9 @@ public class TokenService {
|
41 | 42 | protected static final long MILLIS_SECOND = 1000;
|
42 | 43 | protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
|
43 | 44 | private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L;
|
| 45 | + |
| 46 | + private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY; |
| 47 | + |
44 | 48 | // 令牌自定义标识
|
45 | 49 | @Value("${token.header}")
|
46 | 50 | private String header;
|
@@ -133,19 +137,29 @@ public void delLoginUser(String token) {
|
133 | 137 |
|
134 | 138 | /**
|
135 | 139 | * 创建令牌
|
136 |
| - * |
137 |
| - * @param loginUser 用户信息 |
138 |
| - * @return 令牌 |
139 | 140 | */
|
140 |
| - public String createToken(LoginUser loginUser) { |
| 141 | + public Map<String, Object> createToken(LoginUser loginUser) |
| 142 | + { |
141 | 143 | String token = IdUtils.fastUUID();
|
| 144 | + Long userId = loginUser.getUser().getUserId(); |
| 145 | + String userName = loginUser.getUser().getUserName(); |
142 | 146 | loginUser.setToken(token);
|
143 |
| - setUserAgent(loginUser); |
| 147 | + loginUser.setUserId(userId); |
| 148 | + loginUser.setUsername(userName); |
| 149 | + loginUser.setIpaddr(IpUtils.getIpAddr()); |
144 | 150 | refreshToken(loginUser);
|
145 | 151 |
|
146 |
| - Map<String, Object> claims = new HashMap<>(); |
147 |
| - claims.put(Constants.LOGIN_USER_KEY, token); |
148 |
| - return createToken(claims); |
| 152 | + // Jwt存储信息 |
| 153 | + Map<String, Object> claimsMap = new HashMap<String, Object>(); |
| 154 | + claimsMap.put(SecurityConstants.USER_KEY, token); |
| 155 | + claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId); |
| 156 | + claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); |
| 157 | + |
| 158 | + // 接口返回信息 |
| 159 | + Map<String, Object> rspMap = new HashMap<String, Object>(); |
| 160 | + rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
| 161 | + rspMap.put("expires_in", expireTime); |
| 162 | + return rspMap; |
149 | 163 | }
|
150 | 164 |
|
151 | 165 |
|
@@ -308,7 +322,7 @@ private String getToken(HttpServletRequest request) {
|
308 | 322 | return token;
|
309 | 323 | }
|
310 | 324 |
|
311 |
| - private String getTokenKey(String uuid) { |
312 |
| - return CacheConstants.LOGIN_TOKEN_KEY + uuid; |
| 325 | + private String getTokenKey(String token) { |
| 326 | + return ACCESS_TOKEN + token; |
313 | 327 | }
|
314 | 328 | }
|
0 commit comments