| | |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import com.ruoyi.framework.config.properties.TokenProperties; |
| | | import io.jsonwebtoken.Claims; |
| | | import io.jsonwebtoken.Jwts; |
| | |
| | | // 获取请求携带的令牌 |
| | | String token = getToken(request); |
| | | if (Validator.isNotEmpty(token)) { |
| | | Claims claims = parseToken(token); |
| | | // 解析对应的权限以及用户信息 |
| | | String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); |
| | | String userKey = getTokenKey(uuid); |
| | | LoginUser user = redisCache.getCacheObject(userKey); |
| | | return user; |
| | | try { |
| | | Claims claims = parseToken(token); |
| | | // 解析对应的权限以及用户信息 |
| | | String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); |
| | | String userKey = getTokenKey(uuid); |
| | | LoginUser user = redisCache.getCacheObject(userKey); |
| | | return user; |
| | | catch (Exception e) { |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | |
| | | */ |
| | | public void setUserAgent(LoginUser loginUser) { |
| | | UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); |
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); |
| | | String ip = ServletUtils.getClientIP(); |
| | | loginUser.setIpaddr(ip); |
| | | loginUser.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); |
| | | loginUser.setBrowser(userAgent.getBrowser().getName()); |