@Override public ServiceResults getEntityDictionary( ServiceContext context, List<EntityRef> refs, String dictionary) throws Exception { if ("rolenames".equalsIgnoreCase(dictionary)) { EntityRef entityRef = refs.get(0); checkPermissionsForEntitySubPath(context, entityRef, "rolenames"); if (context.parameterCount() == 0) { return getUserRoles(entityRef.getUuid()); } else if (context.parameterCount() == 1) { String roleName = context.getParameters().get(1).getName(); if (isBlank(roleName)) { return null; } return getApplicationRolePermissions(roleName); } } else if ("permissions".equalsIgnoreCase(dictionary)) { EntityRef entityRef = refs.get(0); checkPermissionsForEntitySubPath(context, entityRef, "permissions"); return genericServiceResults().withData(em.getUserPermissions(entityRef.getUuid())); } return super.getEntityDictionary(context, refs, dictionary); }
@Override public ServiceResults getEntityDictionary( ServiceContext context, List<EntityRef> refs, String dictionary) throws Exception { if ("rolenames".equalsIgnoreCase(dictionary)) { if (context.parameterCount() == 1) { return getApplicationRoles(); } else if (context.parameterCount() == 2) { String roleName = context.getParameters().get(1).getName(); if (isBlank(roleName)) { return null; } return getApplicationRolePermissions(roleName); } } else if ("counters".equals(dictionary)) { if (context.parameterCount() == 1) { return getApplicationCounterNames(); } else if (context.parameterCount() > 1) { if (context.getParameters().get(1) instanceof QueryParameter) { return getApplicationCounters( ((QueryParameter) context.getParameters().get(1)).getQuery()); } } } return super.getEntityDictionary(context, refs, dictionary); }
@Override public ServiceResults postCollection(ServiceContext context) throws Exception { Iterator<Map<String, Object>> i = context.getPayload().payloadIterator(); while (i.hasNext()) { Map<String, Object> p = i.next(); setGravatar(p); } return super.postCollection(context); }
@Override public ServiceResults deleteEntityDictionary( ServiceContext context, List<EntityRef> refs, String dictionary) throws Exception { if ("rolenames".equalsIgnoreCase(dictionary)) { EntityRef entityRef = refs.get(0); checkPermissionsForEntitySubPath(context, entityRef, "rolenames"); if (context.parameterCount() == 1) { String roleName = context.getParameters().get(1).getName(); if (isBlank(roleName)) { return null; } return deleteUserRole(entityRef.getUuid(), roleName); } } else if ("permissions".equalsIgnoreCase(dictionary)) { EntityRef entityRef = refs.get(0); checkPermissionsForEntitySubPath(context, entityRef, "permissions"); Query q = context.getParameters().get(0).getQuery(); if (q == null) { return null; } List<String> permissions = q.getPermissions(); if (permissions == null) { return null; } for (String permission : permissions) { em.revokeUserPermission(entityRef.getUuid(), permission); } return genericServiceResults().withData(em.getUserPermissions(entityRef.getUuid())); } return super.deleteEntityDictionary(context, refs, dictionary); }
@Override public ServiceResults deleteEntityDictionary( ServiceContext context, List<EntityRef> refs, String dictionary) throws Exception { if ("rolenames".equalsIgnoreCase(dictionary)) { if (context.parameterCount() == 2) { String roleName = context.getParameters().get(1).getName(); if (isBlank(roleName)) { return null; } return deleteApplicationRole(roleName); } else if (context.parameterCount() > 2) { String roleName = context.getParameters().get(1).getName(); if (isBlank(roleName)) { return null; } Query q = context.getParameters().get(2).getQuery(); if (q == null) { return null; } List<String> permissions = q.getPermissions(); if (permissions == null) { return null; } for (String permission : permissions) { revokeApplicationRolePermission(roleName, permission); } } } return super.deleteEntityDictionary(context, refs, dictionary); }
@Override public ServiceResults postEntityDictionary( ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload) throws Exception { if ("rolenames".equalsIgnoreCase(dictionary)) { if (context.parameterCount() == 1) { String name = payload.getStringProperty("name"); if (isBlank(name)) { return null; } String title = payload.getStringProperty("title"); if (isBlank(title)) { title = name; } return newApplicationRole(name, title); } else if (context.parameterCount() == 2) { String roleName = context.getParameters().get(1).getName(); if (isBlank(roleName)) { return null; } String permission = payload.getStringProperty("permission"); if (isBlank(permission)) { return null; } return grantApplicationRolePermission(roleName, permission); } } return super.postEntityDictionary(context, refs, dictionary, payload); }
@Override public ServiceResults putEntityDictionary( ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload) throws Exception { if ("rolenames".equalsIgnoreCase(dictionary)) { EntityRef entityRef = refs.get(0); checkPermissionsForEntitySubPath(context, entityRef, "rolenames"); if (context.parameterCount() == 0) { String name = payload.getStringProperty("name"); if (isBlank(name)) { return null; } return addUserRole(entityRef.getUuid(), name); } } return super.postEntityDictionary(context, refs, dictionary, payload); }
@Override public ServiceResults putItemById(ServiceContext context, UUID id) throws Exception { return updateApplicationEntity(context.getPayload()); }