gao.qiang hace 2 años
padre
commit
2dad023b0e

+ 16 - 6
base-common/src/main/java/com/ozs/common/utils/ApiTokenUtils.java

@@ -11,6 +11,7 @@ import eu.bitwalker.useragentutils.UserAgent;
 import io.jsonwebtoken.Claims;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureAlgorithm;
+import io.swagger.models.auth.In;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -58,8 +59,8 @@ public class ApiTokenUtils {
             try {
                 Claims claims = parseToken(token);
                 // 解析对应的权限
-                String uuid = (String) claims.get(Constants.GEOHAZARDMONITOR_KEY);
-                String userKey = getGeoHazardMonitorTokenKey(uuid);
+                String clientId = (String) claims.get(Constants.GEOHAZARDMONITOR_KEY);
+                String userKey = getGeoHazardMonitorTokenKey(clientId);
                 String tokens = redisCache.getCacheObject(userKey);
                 return tokens;
             } catch (Exception e) {
@@ -74,14 +75,23 @@ public class ApiTokenUtils {
      *
      * @return
      */
-    public ArrayList<String> createGeoHazardMonitorToken() {
+    public ArrayList<String> createGeoHazardMonitorToken(String grantType, String clientId, String clientSecret) {
         ArrayList<String> parameter = new ArrayList<>();
         String token = IdUtils.fastUUID();
-        String tokenKey = getGeoHazardMonitorTokenKey(token);
+        String tokenKey = getGeoHazardMonitorTokenKey(clientId);
         parameter.add(String.valueOf(System.currentTimeMillis() + expireTime * MILLIS_MINUTE));
-        redisCache.setCacheObject(tokenKey, token, expireTime, TimeUnit.MINUTES);
+        StringBuilder stringBuilder=new StringBuilder();
+        stringBuilder.append(token);
+        stringBuilder.append("-");
+        stringBuilder.append(grantType);
+        stringBuilder.append("-");
+        stringBuilder.append(clientId);
+        stringBuilder.append("-");
+        stringBuilder.append(clientSecret);
+        String tokens = stringBuilder.toString();
+        redisCache.setCacheObject(tokenKey, tokens, expireTime, TimeUnit.MINUTES);
         Map<String, Object> claims = new HashMap<>();
-        claims.put(Constants.GEOHAZARDMONITOR_KEY, token);
+        claims.put(Constants.GEOHAZARDMONITOR_KEY, clientId);
         parameter.add(createToken(claims));
         return parameter;
     }