Private method for parsing policy (grant or deny) entry.

@param grantOrDeny true for grant entry, false for deny entry
@throws throws Exception when any problem occurred during parsing policy entry
338936
private void parseGrantOrDenyEntry(boolean grantOrDeny) throws Exception {
        ParsedPolicyEntry policyEntry = new ParsedPolicyEntry();
        boolean nextPartExpected = true; // next part means permissions section
        lookahead = st.nextToken();
        while (lookahead != '{') {
            switch (lookahead) {
                case StreamTokenizer.TT_WORD:
                    String readWord = st.sval;
                    nextPartExpected = true;
                    if (readWord.toLowerCase().equals("codebase")) {
                        if (policyEntry.getCodebase() != null) {
                            throw new Exception("ER010: More codebase expression!");
                        }
                        lookahead = st.nextToken();
                        if (lookahead == '\"') {
                            policyEntry.setCodebase(st.sval);
                        } else {
                            throw new Exception("ER011: Codebase parameter have to start with \".");
                        }
                    } else {
                        if (readWord.toLowerCase().equals("signedby")) {
                            if (policyEntry.getSignedBy() != null) {
                                throw new Exception("ER012: More signedBy expression!");
                            }
                            lookahead = st.nextToken();
                            if (lookahead == '\"') {
                                policyEntry.setSignedBy(st.sval);
                            } else {
                                throw new Exception("ER013: SignedBy parameter have to start with \".");
                            }
                        } else {
                            if (readWord.toLowerCase().equals("principal")) {
                                policyEntry.addPrincipal(parsePrincipal());
                            } else {
                                throw new Exception("ER014: Codebase, signedBy or principal expected.");
                            }
                        }

                    }
                    break;
                case ',':
                    if (!nextPartExpected) {
                        throw new Exception("ER015: Some of keywords expected, but there was [,,] instead.");
                    }
                    nextPartExpected = false;
                    break;
                default:
                    throw new Exception("ER016: Some of keywords or '{' expected.");
            }
            lookahead = st.nextToken();
        }
        if (!nextPartExpected) {
            throw new Exception("ER017: Some of keywords expected, but there was [,{] instead.");
        }
        lookahead = st.nextToken();
        while (lookahead != '}') {
            String readPermission = st.sval;
            if (readPermission.toLowerCase().equals("permission")) {
                policyEntry.addPermission(parsePermission());
            }
            lookahead = st.nextToken();
        }

        if (grantOrDeny) {
            grantEntries.add(policyEntry);
        } else {
            denyEntries.add(policyEntry);
        }

    }
1101749
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
		if (requestCode == permissionRequestCode) {
			if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
				if (onRequestPermissionsResultListener != null) {
					onRequestPermissionsResultListener.onRequestPermissionsGranted();
				}
			} else {
				if (onRequestPermissionsResultListener != null) {
					onRequestPermissionsResultListener.onRequestPermissionsDenied();
				}

				if (previouslyShouldShowRequestPermissionRationale != null && !previouslyShouldShowRequestPermissionRationale && !permissionDelegate.shouldShowRequestPermissionRationale(permission)) {
					//Note: onRequestPermissionsResult(...) is called immediately before onResume() (like onActivityResult(...)),
					// if the dialog is show immediately in this case an exception occurs ("java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState").
					pendingAppInfoDialog = true;
				}
			}
		}
	}
685666
private void initPermissionsForPrincipal(JsonEntityBean principal) {
        permissions.add(
                principal.getTypeAndIdHash()
                        + "_"
                        + PortletAdministrationHelper.PortletPermissionsOnForm.BROWSE
                                .getActivity());
        permissions.add(
                principal.getTypeAndIdHash()
                        + "_"
                        + PortletAdministrationHelper.PortletPermissionsOnForm.SUBSCRIBE
                                .getActivity());
    }
477696
public void grant(String granteeName, String roleName, Grantee grantor) {

        Grantee grantee = get(granteeName);

        if (grantee == null) {
            throw Error.error(ErrorCode.X_28501, granteeName);
        }

        if (isImmutable(granteeName)) {
            throw Error.error(ErrorCode.X_28502, granteeName);
        }

        Grantee role = getRole(roleName);

        if (role == null) {
            throw Error.error(ErrorCode.X_0P000, roleName);
        }

        if (role == grantee) {
            throw Error.error(ErrorCode.X_0P501, granteeName);
        }

        // boucherb@users 20050515
        // SQL 2003 Foundation, 4.34.3
        // No cycles of role grants are allowed.
        if (role.hasRole(grantee)) {

            // boucherb@users

            /** @todo: Correct reporting of actual grant path */
            throw Error.error(ErrorCode.X_0P501, roleName);
        }

        if (!grantor.isGrantable(role)) {
            throw Error.error(ErrorCode.X_0L000, grantor.getNameString());
        }

        grantee.grant(role);
        grantee.updateAllRights();

        if (grantee.isRole) {
            updateAllRights(grantee);
        }
    }
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);
  }
1285981
public void revoke(String granteeName, String roleName, Grantee grantor) {

        if (!grantor.isAdmin()) {
            throw Error.error(ErrorCode.X_42507);
        }

        Grantee grantee = get(granteeName);

        if (grantee == null) {
            throw Error.error(ErrorCode.X_28000, granteeName);
        }

        Grantee role = (Grantee) roleMap.get(roleName);

        grantee.revoke(role);
        grantee.updateAllRights();

        if (grantee.isRole) {
            updateAllRights(grantee);
        }
    }
638443
private void invokeAuthorizationRequest(Context context) {

        AuthorizationRequestManager.RequestOptions options = new AuthorizationRequestManager.RequestOptions();

        options.parameters = createAuthorizationParams();
        options.headers = new HashMap<>(1);
        addSessionIdHeader(options.headers);
        options.requestMethod = Request.GET;

        InnerAuthorizationResponseListener listener = new InnerAuthorizationResponseListener() {
            @Override
            public void handleAuthorizationSuccessResponse(Response response) throws Exception {

                String location = extractLocationHeader(response);
                String grantCode = extractGrantCode(location);
                invokeTokenRequest(grantCode);
            }
        };

        authorizationRequestSend(context, "authorization", options, listener);
    }
833921
private static boolean isGrantTypeSupported(final String type, final OAuth20GrantTypes... expectedTypes) {
        LOGGER.debug("Grant type received: [{}]", type);
        for (val expectedType : expectedTypes) {
            if (OAuth20Utils.isGrantType(type, expectedType)) {
                return true;
            }
        }
        LOGGER.error("Unsupported grant type: [{}]", type);
        return false;
    }
816941
@Override
    public void error(SAXParseException exception) throws SAXException {
        logger.warn("Error on line " + exception.getLineNumber() + ": "
                + exception.getMessage() + " ... "
                + "Policy will not be available");

        throw new SAXException("error parsing policy");
    }
665968
public static AuditEntryBean policiesReordered(PlanVersionBean pvb, PolicyType policyType,
            ISecurityContext securityContext) {
        AuditEntryBean entry = newEntry(pvb.getPlan().getOrganization().getId(), AuditEntityType.Plan, securityContext);
        entry.setEntityId(pvb.getPlan().getId());
        entry.setEntityVersion(pvb.getVersion());
        entry.setWhat(AuditEntryType.ReorderPolicies);
        return entry;
    }
242237
def resolve_grant_endpoint(doi_grant_code):
    """"""
    # jsonresolver will evaluate current_app on import if outside of function.
    from flask import current_app
    pid_value = '10.13039/{0}'.format(doi_grant_code)
    try:
        _, record = Resolver(pid_type='grant', object_type='rec',
                             getter=Record.get_record).resolve(pid_value)
        return record
    except Exception:
        current_app.logger.error(
            'Grant {0} does not exists.'.format(pid_value), exc_info=True)
        raise
867756
private boolean passes(final AuthScope scope, final AuthConstraint constraint, final CurrentUser user)
	{
		if (scope.getSkip(constraint))
		{
			if (log.isTraceEnabled())
				log.trace("Allowing method invocation (skip=true).");

			return true;
		}
		else
		{
			final boolean pass = user.hasRole(scope.getRole(constraint));

			if (log.isTraceEnabled())
				if (pass)
					log.trace("Allow method invocation: user " + user + " has role " + scope.getRole(constraint));
				else
					log.trace("Deny method invocation: user " + user + " does not have role " + scope.getRole(constraint));

			return pass;
		}
	}
1083558
public void setPolicyList(java.util.Collection<PolicySummary> policyList) {
        if (policyList == null) {
            this.policyList = null;
            return;
        }

        this.policyList = new java.util.ArrayList<PolicySummary>(policyList);
    }
1168056
def granted(self, lock):
        ''''''
        unit = hookenv.local_unit()
        ts = self.requests[unit].get(lock)
        if ts and self.grants.get(unit, {}).get(lock) == ts:
            return True
        return False
82242
public void setGrants(java.util.Collection<GrantListEntry> grants) {
        if (grants == null) {
            this.grants = null;
            return;
        }

        this.grants = new com.ibm.cloud.objectstorage.internal.SdkInternalList<GrantListEntry>(grants);
    }
514026
private boolean isPermissionGranted(String permission) {
        if (permission == null) {
            throw new IllegalArgumentException("permission is null");
        }

        return context.checkPermission(permission, android.os.Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
    }
893331
public boolean addPolicy(String sec, String ptype, List<String> rule) {
        if (!hasPolicy(sec, ptype, rule)) {
            model.get(sec).get(ptype).policy.add(rule);
            return true;
        }
        return false;
    }