Combine the static permissions with the server.xml and permissions.xml permissions, removing any restricted permission.
This is called back from the dynamic policy to obtain the permissions for the JSP classes.
541813
@Override
    public PermissionCollection getCombinedPermissions(PermissionCollection staticPolicyPermissionCollection, CodeSource codesource) {
        Permissions effectivePermissions = new Permissions();
        List<Permission> staticPolicyPermissions = Collections.list(staticPolicyPermissionCollection.elements());
        String codeBase = codesource.getLocation().getPath(); // TODO: This should be using the CodeSource itself to compare with existing code sources
        ArrayList<Permission> permissions = getEffectivePermissions(staticPolicyPermissions, codeBase);

        for (Permission permission : permissions) {
            effectivePermissions.add(permission);
        }

        return effectivePermissions;
    }
1157226
@Override
	public boolean addPermission(Permission permission)
	{
		if(permissions.contains(permission))
			return false;
		
		return this.permissions.add(permission);
	}
486658
public static void checkPermission(@NonNull final Context context,
                                       @NonNull final String permission) {
        checkPermission(
                context,
                permission,
                String.format(
                        Locale.US,
                        "You must add %s permission to the AndroidManifest.xml",
                        permission
                )
        );
    }
637770
private IAuthorizationPrincipal[] getPrincipalsFromPermissions(IPermission[] permissions)
            throws AuthorizationException {
        Set principals = new HashSet();
        for (int i = 0; i < permissions.length; i++) {
            IAuthorizationPrincipal principal = getPrincipal(permissions[i]);
            principals.add(principal);
        }
        return ((IAuthorizationPrincipal[])
                principals.toArray(new IAuthorizationPrincipal[principals.size()]));
    }
1317932
@PreAuthorize(
            "hasPermission('ALL', 'java.lang.String', new org.apereo.portal.spring.security.evaluator.AuthorizableActivity('UP_PERMISSIONS', 'VIEW_PERMISSIONS'))")
    @RequestMapping(value = "/permissions/{activity}/targets.json", method = RequestMethod.GET)
    public ModelAndView getTargets(
            @PathVariable("activity") Long activityId, @RequestParam("q") String query) {

        IPermissionActivity activity = permissionOwnerDao.getPermissionActivity(activityId);
        Collection<IPermissionTarget> targets = Collections.emptyList();
        if (activity != null) {
            IPermissionTargetProvider provider =
                    targetProviderRegistry.getTargetProvider(activity.getTargetProviderKey());

            SortedSet<IPermissionTarget> matchingTargets = new TreeSet<>();
            // add matching results for this identifier provider to the set
            targets = provider.searchTargets(query);
            for (IPermissionTarget target : targets) {
                if ((StringUtils.isNotBlank(target.getName())
                                && target.getName().toLowerCase().contains(query))
                        || target.getKey().toLowerCase().contains(query)) {
                    matchingTargets.addAll(targets);
                }
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.addObject("targets", targets);
        mv.setViewName("json");

        return mv;
    }
1208161
@RequestMapping(value = "/deletePermission", method = RequestMethod.POST)
    public void deletePermission(
            @RequestParam("principal") String principal,
            @RequestParam("owner") String owner,
            @RequestParam("activity") String activity,
            @RequestParam("target") String target,
            HttpServletRequest request,
            HttpServletResponse response)
            throws Exception {

        // ensure the current user is authorized to update and view permissions
        final IPerson currentUser = personManager.getPerson((HttpServletRequest) request);

        if (!permissionAdministrationHelper.canEditPermission(currentUser, target)
                || !permissionAdministrationHelper.canViewPermission(currentUser, target)) {
            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }
        JsonEntityBean bean = groupListHelper.getEntityForPrincipal(principal);

        if (bean != null) {

            IAuthorizationPrincipal p = groupListHelper.getPrincipalForEntity(bean);

            IPermission[] directPermissions =
                    permissionStore.select(owner, p.getPrincipalString(), activity, target, null);
            this.authorizationService.removePermissions(directPermissions);

        } else {
            log.warn(
                    "Unable to resolve the following principal (will "
                            + "be omitted from the list of assignments):  "
                            + principal);
        }

        response.setStatus(HttpServletResponse.SC_OK);
        return;
    }
370244
private CmsPermissionSet buildPermissionsForCurrentUser() throws CmsException {

        CmsResourceUtil resUtil = new CmsResourceUtil(
            getCms(),
            getCms().readResource(getParamResource(), CmsResourceFilter.ALL));
        return resUtil.getPermissionSet();
    }
599285
public static PermissionDeniedResponse from(@NonNull String permission,
      boolean permanentlyDenied) {
    return new PermissionDeniedResponse(new PermissionRequest(permission), permanentlyDenied);
  }
875041
public static boolean hasPermission(Permission permission) {
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            try {
                security.checkPermission(permission);
            } catch (java.security.AccessControlException e) {
                return false;
            }
        }
        return true;
    }
1240993
public static void getPermission(@NonNull Fragment context, String permissions, @NonNull Response response) {
        getPermission(context, new String[]{permissions}, response);
    }
1264062
public static boolean hasAllPermission(@NonNull Fragment context, @NonNull String... permissions) {
        if (Build.VERSION.SDK_INT < 23) {
            return true;
        } else {
            for (String permission : permissions) {
                if (ContextCompat.checkSelfPermission(context.getContext(), permission) != PackageManager.PERMISSION_GRANTED) {
                    return false;
                }
            }
            return true;
        }
    }
116683
def _create_permissions(**kwargs):
    
    from django.contrib.contenttypes.models import ContentType

    object_tools.autodiscover()
    tools = object_tools.tools._registry

    # This will hold the permissions we're looking for as
    # (content_type, (codename, name))
    searched_perms = list()
    # The codenames and ctypes that should exist.
    ctypes = set()
    for model, tools in tools.items():
        ctype = ContentType.objects.get_for_model(model)
        ctypes.add(ctype)
        for perm in _get_all_permissions(model._meta, tools):
            searched_perms.append((ctype, perm))

    # Find all the Permissions that have a context_type for a model we're
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type__in=ctypes,
    ).values_list(
        "content_type", "codename"
    ))

    for ctype, (codename, name) in searched_perms:
        # If the permissions exists, move on.
        if (ctype.pk, codename) in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if kwargs.get("verbosity", 2) >= 2:
            print("Adding permission '%s'" % p)
981234
public static String permissions(Path path) {
        try {
            return permissions(getUnixMode(path));
        } catch (IOException e) {
            throw Exceptions.propagate(e);
        }
    }
539307
private void requestPermissionsToSystem(Collection<String> permissions) {
    if (!isShowingNativeDialog.get()) {
      androidPermissionService.requestPermissions(activity,
          permissions.toArray(new String[permissions.size()]), PERMISSIONS_REQUEST_CODE);
    }
    isShowingNativeDialog.set(true);
  }
863794
@Override
    public void addPermissions(IPermission[] permissions) throws AuthorizationException {
        if (permissions.length > 0) {
            getPermissionStore().add(permissions);
            if (this.cachePermissions) {
                removeFromPermissionsCache(permissions);
            }
        }
    }
339565
private void ajaxGetPermissions(final Project project, final HashMap<String, Object> ret) {
    final ArrayList<HashMap<String, Object>> permissions =
        new ArrayList<>();
    for (final Pair<String, Permission> perm : project.getUserPermissions()) {
      final HashMap<String, Object> permObj = new HashMap<>();
      final String userId = perm.getFirst();
      permObj.put("username", userId);
      permObj.put("permission", perm.getSecond().toStringArray());

      permissions.add(permObj);
    }

    ret.put("permissions", permissions);
  }
243034
public function setApplicationPermissions()
    {
        $files = (array) $this->config->getContextually('remote.permissions.files');
        foreach ($files as &$file) {
            $this->modulable->setPermissions($file);
        }

        return true;
    }