|
@@ -1,14 +1,10 @@
|
|
|
package com.fs.app.utils;
|
|
package com.fs.app.utils;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
-import com.fs.config.saas.ProjectConfig;
|
|
|
|
|
-import com.fs.core.config.TenantConfigContext;
|
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
import io.jsonwebtoken.Claims;
|
|
|
import io.jsonwebtoken.Jwts;
|
|
import io.jsonwebtoken.Jwts;
|
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
import io.jsonwebtoken.SignatureAlgorithm;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
@@ -29,26 +25,15 @@ public class JwtUtils {
|
|
|
private String header;
|
|
private String header;
|
|
|
|
|
|
|
|
|
|
|
|
|
- private void getJwtConfig(){
|
|
|
|
|
- String str = TenantConfigContext.getString("fs.jwt");
|
|
|
|
|
- ProjectConfig.Fs.Jwt jwt = JSONObject.parseObject(str, ProjectConfig.Fs.Jwt.class);
|
|
|
|
|
- this.setSecret(jwt.getSecret());
|
|
|
|
|
- this.setExpire(jwt.getExpire());
|
|
|
|
|
- this.setHeader(jwt.getHeader());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成jwt token
|
|
* 生成jwt token
|
|
|
*/
|
|
*/
|
|
|
public String generateToken(long userId) {
|
|
public String generateToken(long userId) {
|
|
|
- getJwtConfig();
|
|
|
|
|
|
|
|
|
|
Date nowDate = new Date();
|
|
Date nowDate = new Date();
|
|
|
//过期时间
|
|
//过期时间
|
|
|
Date expireDate = new Date(nowDate.getTime() + expire * 1000);
|
|
Date expireDate = new Date(nowDate.getTime() + expire * 1000);
|
|
|
-// System.out.println("==============================="+secret);
|
|
|
|
|
-// logger.info("secret:{}",secret);
|
|
|
|
|
|
|
+
|
|
|
return Jwts.builder()
|
|
return Jwts.builder()
|
|
|
.setHeaderParam("typ", "JWT")
|
|
.setHeaderParam("typ", "JWT")
|
|
|
.setSubject(userId+"")
|
|
.setSubject(userId+"")
|
|
@@ -59,7 +44,6 @@ public class JwtUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Claims getClaimByToken(String token) {
|
|
public Claims getClaimByToken(String token) {
|
|
|
- getJwtConfig();
|
|
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
return Jwts.parser()
|
|
return Jwts.parser()
|
|
@@ -97,7 +81,6 @@ public class JwtUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public String getHeader() {
|
|
public String getHeader() {
|
|
|
- getJwtConfig();
|
|
|
|
|
return header;
|
|
return header;
|
|
|
}
|
|
}
|
|
|
|
|
|