| | |
| | | package com.ruoyi.framework.web.service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.ServletUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.ip.AddressUtils; |
| | | import com.ruoyi.common.utils.ip.IpUtils; |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | import io.jsonwebtoken.Claims; |
| | | import io.jsonwebtoken.Jwts; |
| | | import io.jsonwebtoken.SignatureAlgorithm; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * token验证处理 |
| | |
| | | { |
| | | // 获取请求携带的令牌 |
| | | String token = getToken(request); |
| | | if (StringUtils.isNotEmpty(token)) |
| | | if (Validator.isNotEmpty(token)) |
| | | { |
| | | Claims claims = parseToken(token); |
| | | // 解析对应的权限以及用户信息 |
| | |
| | | */ |
| | | public void setLoginUser(LoginUser loginUser) |
| | | { |
| | | if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) |
| | | if (Validator.isNotNull(loginUser) && Validator.isNotEmpty(loginUser.getToken())) |
| | | { |
| | | refreshToken(loginUser); |
| | | } |
| | |
| | | */ |
| | | public void delLoginUser(String token) |
| | | { |
| | | if (StringUtils.isNotEmpty(token)) |
| | | if (Validator.isNotEmpty(token)) |
| | | { |
| | | String userKey = getTokenKey(token); |
| | | redisCache.deleteObject(userKey); |
| | |
| | | private String getToken(HttpServletRequest request) |
| | | { |
| | | String token = request.getHeader(header); |
| | | if (StringUtils.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) |
| | | if (Validator.isNotEmpty(token) && token.startsWith(Constants.TOKEN_PREFIX)) |
| | | { |
| | | token = token.replace(Constants.TOKEN_PREFIX, ""); |
| | | } |