public class JwtUtil {
private static final long EXPIER_TIME = 15 * 60 * 1000;
private static final String TOKEN_SECRET = "123456";
public static String sign(String userName, String userId,String roleName,String[] listCode) {
Date data = new Date(System.currentTimeMillis() + EXPIER_TIME);
try {
Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
Map<String, Object> header = new HashMap<>(2);
header.put("typ","JWT");
header.put("alg","HS256");
return JWT.create()
.withHeader(header)
.withClaim("userId",userId)
.withClaim("userName",userName)
.withClaim("roleName",roleName)
.withAudience(listCode)
.withExpiresAt(data).sign(algorithm);
基础的JAVA Token权限认证
最新推荐文章于 2024-05-08 21:58:24 发布