| | |
| | | import io.jsonwebtoken.Jwts; |
| | | import io.jsonwebtoken.SignatureAlgorithm; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Component |
| | | @Service |
| | | public class TokenServiceImpl implements TokenService { |
| | | |
| | | protected static final long MILLIS_SECOND = 1000; |
| | |
| | | // 获取请求携带的令牌 |
| | | String token = getToken(request); |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | try { |
| | | Claims claims = parseToken(token); |
| | | // 解析对应的权限以及用户信息 |
| | | String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); |
| | | String userKey = getTokenKey(uuid); |
| | | LoginUser user = RedisUtils.getCacheObject(userKey); |
| | | return user; |
| | | } catch (Exception e) { |
| | | try { |
| | | Claims claims = parseToken(token); |
| | | // 解析对应的权限以及用户信息 |
| | | String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); |
| | | String userKey = getTokenKey(uuid); |
| | | LoginUser user = RedisUtils.getCacheObject(userKey); |
| | | return user; |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |