| | |
| | | import java.util.Map;
|
| | | import java.util.concurrent.TimeUnit;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.constant.CacheConstants;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.utils.IdUtils;
|
| | | 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 com.ruoyi.common.utils.uuid.IdUtils;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import eu.bitwalker.useragentutils.UserAgent;
|
| | |
| | | @Component
|
| | | public class TokenService
|
| | | {
|
| | | private static final Logger log = LoggerFactory.getLogger(TokenService.class);
|
| | |
|
| | | // 令牌自定义标识
|
| | | @Value("${token.header}")
|
| | | private String header;
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | log.error("获取用户信息异常'{}'", e.getMessage());
|
| | | }
|
| | | }
|
| | | return null;
|
| | |
| | |
|
| | | Map<String, Object> claims = new HashMap<>();
|
| | | claims.put(Constants.LOGIN_USER_KEY, token);
|
| | | claims.put(Constants.JWT_USERNAME, loginUser.getUsername());
|
| | | return createToken(claims);
|
| | | }
|
| | |
|
| | |
| | | public void setUserAgent(LoginUser loginUser)
|
| | | {
|
| | | UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent"));
|
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
| | | String ip = IpUtils.getIpAddr();
|
| | | loginUser.setIpaddr(ip);
|
| | | loginUser.setLoginLocation(AddressUtils.getRealAddressByIP(ip));
|
| | | loginUser.setBrowser(userAgent.getBrowser().getName());
|
| | |
| | |
|
| | | private String getTokenKey(String uuid)
|
| | | {
|
| | | return Constants.LOGIN_TOKEN_KEY + uuid;
|
| | | return CacheConstants.LOGIN_TOKEN_KEY + uuid;
|
| | | }
|
| | | }
|