|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final String HEADER = "Access-Token"; | 
|---|
|  |  |  | private static final String HEADER = "access-token"; | 
|---|
|  |  |  | private static final String AUDIENCE = "Audience"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final long EXPIRED_THRESHOLD = 10 * 60; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static final long expirationTime = 30; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String createToken(String username, String password) { | 
|---|
|  |  |  | public static String createToken(String username, String password, Integer roleId) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * “iss” (issuer)  发行人 | 
|---|
|  |  |  | 
|---|
|  |  |  | //添加自定义参数,必须是字符串类型 | 
|---|
|  |  |  | claims.setClaim("username", username); | 
|---|
|  |  |  | claims.setClaim("password", password); | 
|---|
|  |  |  | claims.setClaim("roleId", roleId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //jws | 
|---|
|  |  |  | JsonWebSignature jws = new JsonWebSignature(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String username = (String) claims.getClaimValue("username"); | 
|---|
|  |  |  | String password = (String) claims.getClaimValue("password"); | 
|---|
|  |  |  | Long roleId = (Long) claims.getClaimValue("roleId"); | 
|---|
|  |  |  | jwtUser.setUserName(username); | 
|---|
|  |  |  | jwtUser.setPassword(password); | 
|---|
|  |  |  | jwtUser.setRoleId(roleId.intValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return jwtUser; | 
|---|
|  |  |  | } catch (InvalidJwtException e) { | 
|---|