throw new UnauthorizedException("Authorization Required");
@Override public Set<Privilege> listPrivileges(Principal principal) throws Exception { return delegateAuthorizer.listPrivileges(principal); } }
@Override public void grant(Authorizable authorizable, Principal principal, Set<Action> actions) throws Exception { delegateAuthorizer.grant(authorizable, principal, actions); }
@Override public void revoke(Authorizable authorizable, Principal principal, Set<Action> actions) throws Exception { delegateAuthorizer.revoke(authorizable, principal, actions); }
@Override public void testAuthorizationEnforcer() throws Exception { super.testAuthorizationEnforcer(); // The super class revokes all privileges after test is done. Since cache is enabled, enforce should still work. authorizationEnforcer.enforce(APP, ALICE, Action.ADMIN); authorizationEnforcer.enforce(PROGRAM, ALICE, Action.EXECUTE); }
private void verifyAuthFailure(EntityId entity, Principal principal, Action action) throws Exception { try { get().enforce(entity, principal, action); Assert.fail(String.format("Expected authorization failure, but it succeeded for entity %s, principal %s," + " action %s", entity, principal, action)); } catch (UnauthorizedException expected) { // expected } } }
@Override public void dropRole(Role role) throws NotFoundException { Set<Principal> removed = roleToPrincipals.remove(role); if (removed == null) { throw new NotFoundException(role); } }
@Override public void initialize(AuthorizationContext context) throws Exception { this.properties = context.getExtensionProperties(); }
@Override public void enforce(EntityId entity, Principal principal, Action action) throws Exception { enforce(entity, principal, Collections.singleton(action)); } }
@ApiMethod(name = "test", path = "myApi/test", scopes = {Constants.EMAIL_SCOPE}, clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID}, audiences = {Constants.ANDROID_AUDIENCE}) public User test(User user) throws UnauthorizedException { if (user == null) throw new UnauthorizedException("User not valid!"); return user; }
@Override public void revoke(Authorizable authorizable) throws Exception { delegateAuthorizer.revoke(authorizable); }
User auth) throws UnauthorizedException { if (auth!=null){ ... return event } else throw new UnauthorizedException("Please authenticate first."); } public Event getEvent(@Named("eventID") Long eventID, User auth) throws UnauthorizedException { if (auth != null) { ... return event; } else throw new UnauthorizedException("Please authenticate first."); }
@ApiMethod(name = "insertRecord", path = "insert_record", httpMethod = HttpMethod.POST) public Record insertRecord(User user, Record record) // check if google user is authenticated throws UnauthorizedException { if (user == null) { throw new UnauthorizedException("Authorization required"); } // user is authenticated... do some stuff! }
public void apiMethod(User user) { if (user == null) { throw new UnauthorizedException(); } ... }
public Collection<Campagne> getCampagnes(@Named("NumPortable")String NumPortable, User user) throws UnauthorizedException { if (user == null) throw new UnauthorizedException("User is Not Valid"); return CampagneCRUD.getInstance().findCampagne(NumPortable); }
public Collection<Campagne> getCampagnes(@Named("NumPortable")String NumPortable, User user) throws UnauthorizedException { if (user == null) throw new UnauthorizedException("User is Not Valid"); return CampagneCRUD.getInstance().findCampagne(NumPortable); }
public Collection<Campagne> getCampagnes(@Named("NumPortable")String NumPortable, User user) throws UnauthorizedException { if (user == null) throw new UnauthorizedException("User is Not Valid"); return CampagneCRUD.getInstance().findCampagne(NumPortable); }
@PUT @Path("{id: [A-Fa-f0-9]+}") @Consumes(MediaType.APPLICATION_JSON) public T update(@Context HttpServletRequest request, final T item, @PathParam("id") final String id) { final Post post = getPostbyId(id); if (!post.allowedToUpdate(request.getUserPrincipal()) { throw new UnauthorizedException(); } // Authorized, carry on }
@Override public void enforce(EntityId entity, Principal principal, Action action) throws Exception { if (!allowedActions.contains(action)) { throw new UnauthorizedException("Not allow to perform " + action + " " + entity + " by " + principal); } }
@Override public void enforce(EntityId entity, Principal principal, Set<Action> actions) throws Exception { if (!allowedActions.containsAll(actions)) { throw new UnauthorizedException("Not allow to perform " + actions + " " + entity + " by " + principal); } }