public static RestGrant map(String objectName, Grant grant) { return new RestGrant(grant.getGrantedUsername(), objectName, grant.getAccessMode()); } }
@RequestMapping(value = "/Grants", consumes = "application/json", produces = "application/json", method = POST) public RestEntity writeEntry(@RequestBody RestGrant grant, HttpServletRequest request) throws RestException { RequestContext requestContext = getRequestContext(request); if(requestContext.isSecure()) { if(StringUtils.stringNotEmpty(grant.getObjectName()) && StringUtils.stringNotEmpty(grant.getUsername())) { try { userManager.grantUser(requestContext.getUserSession(), grant.getObjectName(), grant.getUsername(), grant.getMode()); return loadSpecificGrantObject(requestContext, grant.getObjectName()); } catch(JasDBStorageException e) { throw new RestException("Unable to grant", e); } } else { throw new RestException("Incomplete grant details"); } } else { throw new RestException("Unable to create grant, unsecure connection"); } }
@RequestMapping(value = "/Grants({grantId})", produces = "application/json", method = DELETE) public RestEntity removeEntry(@RequestBody RestGrant grant, HttpServletRequest request) throws RestException { if(StringUtils.stringNotEmpty(grant.getObjectName()) && StringUtils.stringNotEmpty(grant.getUsername())) { try { RequestContext requestContext = getRequestContext(request); userManager.revoke(requestContext.getUserSession(), grant.getObjectName(), grant.getUsername()); return null; } catch(JasDBStorageException e) { throw new RestException("Unable to revoke grant", e); } } else { throw new RestException("Cannot remove without user and object specified"); } } }
@Override public void revoke(RemotingContext context, String object, String user) throws RemoteException { try { byte[] serializedGrant = toBytes(new RestGrant(user, object, AccessMode.NONE)); doInternalRequest(context, "Grants", new HashMap<>(), serializedGrant, REQUEST_MODE.DELETE); } catch(RestException e) { throw new RemoteException("Unable to grant", e); } } }
@Override public void grant(RemotingContext context, String object, String user, AccessMode mode) throws RemoteException { try { byte[] serializedGrant = toBytes(new RestGrant(user, object, mode)); doInternalRequest(context, "Grants", new HashMap<>(), serializedGrant, REQUEST_MODE.POST); } catch(RestException e) { throw new RemoteException("Unable to grant", e); } }