Ver Fonte

优化权限解析

zhou-hao há 4 anos atrás
pai
commit
c5184e7456

+ 6 - 2
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/builder/SimpleAuthenticationBuilder.java

@@ -118,8 +118,12 @@ public class SimpleAuthenticationBuilder implements AuthenticationBuilder {
     public AuthenticationBuilder json(String json) {
         JSONObject jsonObject = JSON.parseObject(json);
         user(jsonObject.getObject("user", SimpleUser.class));
-        role(jsonObject.getJSONArray("roles").toJSONString());
-        permission(jsonObject.getJSONArray("permissions").toJSONString());
+        if(jsonObject.containsKey("roles")){
+            role(jsonObject.getJSONArray("roles").toJSONString());
+        }
+        if(jsonObject.containsKey("permissions")){
+            permission(jsonObject.getJSONArray("permissions").toJSONString());
+        }
         return this;
     }