Browse Source

fix auto approve

MrBird 5 years ago
parent
commit
65bba18f34

+ 13 - 1
febs-auth/src/main/java/cc/mrbird/febs/auth/service/impl/RedisClientDetailsService.java

@@ -13,6 +13,8 @@ import org.springframework.stereotype.Service;
 
 import javax.sql.DataSource;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @author Yuuki
@@ -54,7 +56,12 @@ public class RedisClientDetailsService extends JdbcClientDetailsService {
         ClientDetails clientDetails = null;
         clientDetails = super.loadClientByClientId(clientId);
         if (clientDetails != null) {
-            redisService.hset(CACHE_CLIENT_KEY, clientId, JSONObject.toJSONString(clientDetails));
+            BaseClientDetails baseClientDetails = (BaseClientDetails) clientDetails;
+            Set<String> autoApproveScopes = baseClientDetails.getAutoApproveScopes();
+            baseClientDetails.setAutoApproveScopes(
+                    autoApproveScopes.stream().map(this::convert).collect(Collectors.toSet())
+            );
+            redisService.hset(CACHE_CLIENT_KEY, clientId, JSONObject.toJSONString(baseClientDetails));
         }
         return clientDetails;
     }
@@ -84,4 +91,9 @@ public class RedisClientDetailsService extends JdbcClientDetailsService {
         }
         list.forEach(client -> redisService.hset(CACHE_CLIENT_KEY, client.getClientId(), JSONObject.toJSONString(client)));
     }
+
+    private String convert(String value) {
+        final String logicTrue = "1";
+        return logicTrue.equals(value) ? Boolean.TRUE.toString() : Boolean.FALSE.toString();
+    }
 }