List of usage examples for org.json JSONObject JSONObject
public JSONObject()
From source file:org.loklak.server.Authorization.java
/** * create a new authorization object. The given json object must be taken * as value from a parent json. If the parent json is a JsonFile, then that * file can be handed over as well to enable persistency. * @param identity/* w w w .j a v a2 s . c om*/ * @param parent the parent file or null if there is no parent file (no persistency) */ public Authorization(@Nonnull ClientIdentity identity, JsonTray parent, @Nonnull UserRoles urs) { Log.getLog().debug("new authorization"); this.parent = parent; this.accounting = null; this.identity = identity; this.userRoles = urs; if (parent != null) { if (parent.has(identity.toString())) { json = parent.getJSONObject(identity.toString()); } else { json = new JSONObject(); parent.put(identity.toString(), json, identity.isPersistent()); } } else json = new JSONObject(); if (json.has("userRole") && userRoles.has(json.getString("userRole"))) { Log.getLog().debug("user role " + json.getString("userRole") + " valid"); userRole = userRoles.getUserRoleFromString(json.getString("userRole")); Log.getLog().debug("user role: " + userRole.getName()); } else { Log.getLog().debug("user role invalid"); userRole = userRoles.getDefaultUserRole(BaseUserRole.ANONYMOUS); json.put("userRole", userRole.getName()); Log.getLog().debug("user role: " + userRole.getName()); } if (!json.has("permissions")) json.put("permissions", new JSONObject()); permissions = json.getJSONObject("permissions"); }
From source file:org.loklak.server.Authorization.java
public Authorization setRequestFrequency(String path, int reqPerHour) { if (!this.json.has("frequency")) { this.json.put("frequency", new JSONObject()); }//from w w w . ja v a 2 s . c o m JSONObject paths = this.json.getJSONObject("frequency"); paths.put(path, reqPerHour); if (parent != null && getIdentity().isPersistent()) parent.commit(); return this; }
From source file:org.loklak.server.Authorization.java
public Authorization addService(ClientService service) { if (!this.json.has("services")) this.json.put("services", new JSONObject()); JSONObject services = this.json.getJSONObject("services"); services.put(service.toString(), service.toJSON().getJSONObject("meta")); if (parent != null && getIdentity().isPersistent()) parent.commit();/*from w w w. j a v a 2 s . com*/ return this; }
From source file:org.loklak.server.Authorization.java
public ClientService getService(String serviceId) { if (!this.json.has("services")) this.json.put("services", new JSONObject()); JSONObject services = this.json.getJSONObject("services"); if (!services.has(serviceId)) return null; JSONObject s = services.getJSONObject(serviceId); ClientService service = new ClientService(serviceId); service.setMetadata(s.getJSONObject("meta")); return service; }
From source file:org.loklak.server.Authorization.java
public void setPermission(String servletCanonicalName, String key, JSONObject value) { if (!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
From source file:org.loklak.server.Authorization.java
public void setPermission(String servletCanonicalName, String key, String value) { if (!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
From source file:org.loklak.server.Authorization.java
public void setPermission(String servletCanonicalName, String key, int value) { if (!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
From source file:org.loklak.server.Authorization.java
public void setPermission(String servletCanonicalName, String key, long value) { if (!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
From source file:org.loklak.server.Authorization.java
public void setPermission(String servletCanonicalName, String key, double value) { if (!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }
From source file:org.loklak.server.Authorization.java
public void setPermission(String servletCanonicalName, String key, Object value) { if (!permissions.has(servletCanonicalName)) permissions.put(servletCanonicalName, new JSONObject()); permissions.getJSONObject(servletCanonicalName).put(key, value); }