@Test public void Permission_生成() throws Exception { NCMBAcl.Permission p1 = new NCMBAcl.Permission(true, false); JSONAssert.assertEquals(new JSONObject("{'read':true}"), p1.toJson(), false); NCMBAcl.Permission p2 = new NCMBAcl.Permission(false, true); JSONAssert.assertEquals(new JSONObject("{'write':true}"), p2.toJson(), false); NCMBAcl.Permission p3 = new NCMBAcl.Permission(true, true); JSONAssert.assertEquals(new JSONObject("{'read':true, 'write':true}"), p3.toJson(), false); }
public JSONObject toJson() throws JSONException { JSONObject result = new JSONObject(); for (Map.Entry<String, Permission> uentry: userAcl.entrySet()) { result.put(uentry.getKey(), uentry.getValue().toJson()); } for (Map.Entry<String, Permission> rentry: roleAcl.entrySet()) { String key = PREFIX_ROLE + rentry.getKey(); result.put(key, rentry.getValue().toJson()); } return result; }
NCMBAcl { public JSONObject toJson() throws JSONException { JSONObject result = new JSONObject(); for (Map.Entry<String, Permission> uentry: userAcl.entrySet()) { result.put(uentry.getKey(), uentry.getValue().toJson()); } for (Map.Entry<String, Permission> rentry: roleAcl.entrySet()) { String key = PREFIX_ROLE + rentry.getKey(); result.put(key, rentry.getValue().toJson()); } return result; } }
NCMBAcl { public JSONObject toJson() throws JSONException { JSONObject result = new JSONObject(); for (Map.Entry<String, Permission> uentry: userAcl.entrySet()) { result.put(uentry.getKey(), uentry.getValue().toJson()); } for (Map.Entry<String, Permission> rentry: roleAcl.entrySet()) { String key = PREFIX_ROLE + rentry.getKey(); result.put(key, rentry.getValue().toJson()); } return result; } NCMBAcl();  NCMBAcl(JSONObject json); }
NCMBAcl { public JSONObject toJson() throws JSONException { JSONObject result = new JSONObject(); for (Map.Entry<String, Permission> uentry: userAcl.entrySet()) { result.put(uentry.getKey(), uentry.getValue().toJson()); } for (Map.Entry<String, Permission> rentry: roleAcl.entrySet()) { String key = PREFIX_ROLE + rentry.getKey(); result.put(key, rentry.getValue().toJson()); } return result; } NCMBAcl();  NCMBAcl(JSONObject json); void parse(JSONObject input); JSONObject toJson(); boolean isEmpty(); void setAccess(String userId, Permission permission); void setRoleAccess(String roleName, Permission permission); Permission getAccess(String userId); Permission getRoleAccess(String roleName); boolean removePermission(String userId); boolean removeRolePermission(String roleName); boolean getReadAccess(String userId); boolean getWriteAccess(String userId); boolean getRoleReadAccess(String roleName); boolean getRoleWriteAccess(String roleName); void setReadAccess(String userId, boolean allowed); void setWriteAccess(String userId, boolean allowed); void setRoleReadAccess(String roleName, boolean allowed); void setRoleWriteAccess(String roleName, boolean allowed); boolean getPublicReadAccess(); boolean getPublicWriteAccess(); void setPublicReadAccess(boolean allowed); void setPublicWriteAccess(boolean allowed); }
NCMBAcl { public JSONObject toJson() throws JSONException { JSONObject result = new JSONObject(); for (Map.Entry<String, Permission> uentry: userAcl.entrySet()) { result.put(uentry.getKey(), uentry.getValue().toJson()); } for (Map.Entry<String, Permission> rentry: roleAcl.entrySet()) { String key = PREFIX_ROLE + rentry.getKey(); result.put(key, rentry.getValue().toJson()); } return result; } NCMBAcl();  NCMBAcl(JSONObject json); void parse(JSONObject input); JSONObject toJson(); boolean isEmpty(); void setAccess(String userId, Permission permission); void setRoleAccess(String roleName, Permission permission); Permission getAccess(String userId); Permission getRoleAccess(String roleName); boolean removePermission(String userId); boolean removeRolePermission(String roleName); boolean getReadAccess(String userId); boolean getWriteAccess(String userId); boolean getRoleReadAccess(String roleName); boolean getRoleWriteAccess(String roleName); void setReadAccess(String userId, boolean allowed); void setWriteAccess(String userId, boolean allowed); void setRoleReadAccess(String roleName, boolean allowed); void setRoleWriteAccess(String roleName, boolean allowed); boolean getPublicReadAccess(); boolean getPublicWriteAccess(); void setPublicReadAccess(boolean allowed); void setPublicWriteAccess(boolean allowed); static final String ACL_PUBLIC; static final String PREFIX_ROLE; }