/*
(non-Javadoc)
@see net.timewalker.ffmq4.security.SecurityContext#checkPermission(java.lang.String, java.lang.String)
339126
@Override
	public void checkPermission(String resourceName, String action) throws JMSException 
	{
		for (int i = 0; i < privileges.size(); i++)
		{
			Privilege privilege = privileges.get(i);
			if (privilege.matches(resourceName, action))
				return;
		}
		throw new FFMQException("Access denied to resource '"+resourceName+"' for action '"+action+"'","ACCESS_DENIED");
	}
1222238
@Override
	public boolean checkPermission(Permission permission)
	{
		if (permission == null)
			return false;

		boolean authorized = false;
		for (Permission accessPermission : permissions)
		{
			if(accessPermission.isAuthorized(permission))
			{
				authorized = true;
				break;
			}
		}
		
		if(negative)
			return !authorized;
		else
			return authorized;
	}
736434
public static void checkSuperuserPrivilege(UserGroupInformation owner, 
                                             String supergroup) 
  throws AccessControlException {
    PermissionChecker checker = 
      new PermissionChecker(owner.getUserName(), supergroup);
    if (!checker.isSuper) {
      throw new AccessControlException("Access denied for user " 
          + checker.user + ". Superuser privilege is required");
    }
  }
681642
protected void checkPermissionsForMassEdit(CmsObject cms) throws CmsException {

        OpenCms.getRoleManager().checkRoleForResource(cms, CmsRole.ADMINISTRATOR, "/");
    }
378276
public final boolean hasPermission(AccessControlList acl, String permission, Identity user)
      throws RepositoryException
   {
      return hasPermission(acl, parseStringPermissions(permission), user);
   }
498256
public static function checkPermission():int
    {
        if (!Server::checkIsExecutable(FEnv::get("framework.root")."elements/") ||
            !Server::checkIsReadable(FEnv::get("framework.root")."elements/") ||
            !Server::checkIsWritable(FEnv::get("framework.root")."elements/")) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Core Error : Folder /elements does not have correct permission",
                "solution" => "Must be read, write, executable permission")));
        }

        if (!Server::checkIsExecutable(FEnv::get("framework.root")."apps/") ||
            !Server::checkIsReadable(FEnv::get("framework.root")."apps/") ||
            !Server::checkIsWritable(FEnv::get("framework.root")."apps/")) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Core Error : Folder /apps does not have correct permission",
                "solution" => "Must be read, write, executable permission")));
        }
        return (1);
    }
864901
@Override
	public synchronized List<Permission> getPermissions()
	{
		if (permissions == null || permissions.isEmpty())
			return null;

		return new ArrayList<Permission>(this.permissions);
	}
808897
private static void checkPermission(final Subject user, 
                                      final Permission... permissions) 
  throws AuthorizationException {
    try{
      Subject.doAs(user, 
                   new PrivilegedExceptionAction<Void>() {
                     @Override
                     public Void run() throws Exception {
                       try {
                         for(Permission permission : permissions) {
                           AccessController.checkPermission(permission);
                         }
                       } catch (AccessControlException ace) {
                         LOG.info("Authorization failed for " + 
                                  UserGroupInformation.getCurrentUGI(), ace);
                         throw new AuthorizationException(ace);
                       }
                      return null;
                     }
                   }
                  );
    } catch (PrivilegedActionException e) {
      throw new AuthorizationException(e.getException());
    }
  }
299553
@NonNull
    private static Single<Boolean> checkPermissionUntilGranted(
            final LocationServicesStatus locationServicesStatus,
            Scheduler timerScheduler
    ) {
        return Observable.interval(0, 1L, TimeUnit.SECONDS, timerScheduler)
                .takeWhile(new Predicate<Long>() {
                    @Override
                    public boolean test(Long timer) {
                        return !locationServicesStatus.isLocationPermissionOk();
                    }
                })
                .count()
                .map(new Function<Long, Boolean>() {
                    @Override
                    public Boolean apply(Long count) {
                        // if no elements were emitted then the permission was granted from the beginning
                        return count == 0;
                    }
                });
    }
1240993
public static void getPermission(@NonNull Fragment context, String permissions, @NonNull Response response) {
        getPermission(context, new String[]{permissions}, response);
    }
170419
protected boolean isPermissionDenied(List<String> output){
        return output.stream().anyMatch(s -> s != null && s.contains(PERMISSION_DENIED_MESSAGE));
    }
488402
public static boolean hasPermissions(Context context, String[]... permissions) {
        for (String[] permission : permissions) {
            boolean hasPermission = PERMISSION_CHECKER.hasPermission(context, permission);
            if (!hasPermission) return false;
        }
        return true;
    }
1345332
public void setPermission(String src, FsPermission permission
  ) throws IOException {
    INode[] inodes = null;
    writeLock();
    try {
      if (isInSafeMode()) {
        throw new SafeModeException("Cannot set permission for " + src, safeMode);
      }
      inodes = dir.getExistingPathINodes(src);
      if (isPermissionCheckingEnabled(inodes)) {
        checkOwner(src, inodes);
      }
      dir.setPermission(src, permission);
    } finally {
      writeUnlock();
    }
    getEditLog().logSync(false);
    if (auditLog.isInfoEnabled()) {
      logAuditEvent(getCurrentUGI(),
        Server.getRemoteIp(),
        "setPermission", src, null, getLastINode(inodes));
    }
  }
395722
private void checkTopicSubscribePermission(String topic) {
        SecurityManager sm = System.getSecurityManager();
        if (sm == null)
            return;

        sm.checkPermission(new TopicPermission(topic, SUBSCRIBE));
    }
203063
@VisibleForTesting
    void checkPermissionStatus(@NonNull Context context) {
        boolean hasPermission = getPermissionChecker().hasAnimationPermission(context);
        if (!hasPermission) {
            throw new IllegalStateException(getPermissionErrorMessage());
        }
    }
1237554
@GET
    @Path("/checkIsUserInRole")
    @RolesAllowed("Tester")
    public Response checkIsUserInRole(@Context SecurityContext sec) {
        Principal user = sec.getUserPrincipal();
        Response response;
        if (!sec.isUserInRole("Echoer")) {
            response = Response.status(new Response.StatusType() {
                @Override
                public int getStatusCode() {
                    return Response.Status.FORBIDDEN.getStatusCode();
                }

                @Override
                public Response.Status.Family getFamily() {
                    return Response.Status.FORBIDDEN.getFamily();
                }

                @Override
                public String getReasonPhrase() {
                    return "SecurityContext.isUserInRole(Echoer) was false";
                }
            }).build();
        } else {
            response = Response.ok(user.getName(), MediaType.TEXT_PLAIN).build();
        }
        return response;
    }
1157226
@Override
	public boolean addPermission(Permission permission)
	{
		if(permissions.contains(permission))
			return false;
		
		return this.permissions.add(permission);
	}