Authorizes the client for the annotated permissions.  If any authorizations fail an {@link AuthorizationException}
will be thrown, otherwise the original request is returned.
544611
@Override
    public ContainerRequest filter(ContainerRequest request) {
        Subject subject = ThreadContext.getSubject();

        String[] permissions = resolvePermissions(request);

        if (permissions.length == 1 || _logical == Logical.AND) {
            // Shortcut call to check all permissions at once
            subject.checkPermissions(permissions);
        } else {
            // Check each permission until any passes
            boolean anyPermitted = false;
            int p = 0;
            while (!anyPermitted) {
                try {
                    subject.checkPermission(permissions[p]);
                    anyPermitted = true;
                } catch (AuthorizationException e) {
                    // If this is the last permission then pass the exception along
                    if (++p == permissions.length) {
                        throw e;
                    }
                }
            }
        }

        return request;
    }
857457
private void verifyPermission(Subject subject, String permission)
            throws UnauthorizedException {
        if (!subject.hasPermission(permission)) {
            throw new UnauthorizedException();
        }
    }
451886
public com.google.api.AuthorizationConfig getAuthorization() {
    return authorization_ == null ? com.google.api.AuthorizationConfig.getDefaultInstance() : authorization_;
  }
748996
boolean authorize(String resource) throws IOException {
    if (passwordProvider == null) {
      throw new IOException(
          "Authorization failed - no password provider present "
              + "(you must call setPasswordProvider)");
    }

    if (passwordProvider.canAuthenticate(resource)) {
      // RPC code FOR SANE_NET_AUTHORIZE
      outputStream.write(SaneRpcCode.SANE_NET_AUTHORIZE);
      outputStream.write(resource);
      outputStream.write(passwordProvider.getUsername(resource));
      writePassword(resource, passwordProvider.getPassword(resource));
      outputStream.flush();

      // Read dummy reply and discard (according to the spec, it is unused).
      inputStream.readWord();
      return true;
    }

    return false;
  }
977155
public void setAuthorized( boolean authorized ) {

        if( isAuthorized() != authorized ) {

            this.authorized = authorized;

            // We need to apply a change to our enabled state depending on our
            // new authorized state.
            if( authorized ) {
                // install the last requested enabled state
                setEnabled(maskedEnabledState);
            } else {
                // Record the current enabled state and then disable
                maskedEnabledState = isEnabled();
                internalSetEnabled(false);
            }
        }
    }
144151
public void setAuthorizers(java.util.Collection<AuthorizerSummary> authorizers) {
        if (authorizers == null) {
            this.authorizers = null;
            return;
        }

        this.authorizers = new java.util.ArrayList<AuthorizerSummary>(authorizers);
    }
991197
function authorize(newDoc, oldDoc, userContext, securityInfo, docDefinition) {
    if (utils.isValueNullOrUndefined(userContext)) {
      throw unauthorizedResult();
    }

    var authorizedRoles = resolveRequiredAuthorizations(newDoc, oldDoc, docDefinition.authorizedRoles);
    var authorizedUsers = resolveRequiredAuthorizations(newDoc, oldDoc, docDefinition.authorizedUsers);
    var grantAllMembersWriteAccess = utils.resolveDocumentConstraint(docDefinition.grantAllMembersWriteAccess);

    if (grantAllMembersWriteAccess) {
      // The document definition allows any authenticated DB member to write documents of this type
      return authorizationSuccessResult(authorizedRoles, authorizedUsers);
    } else if (isAdminUser(userContext, securityInfo)) {
      // Database admins have unrestricted access
      return authorizationSuccessResult(authorizedRoles, authorizedUsers);
    } else if (!authorizedRoles && !authorizedUsers) {
      // The document type does not define any authorized roles or users
      throw forbiddenResult();
    }

    var roleMatch = hasAuthorizedRole(authorizedRoles, userContext.roles);
    var usernameMatch = hasAuthorizedUsername(authorizedUsers, userContext.name);
    if (!roleMatch && !usernameMatch) {
      // None of the required authorizations were satisfied
      throw forbiddenResult();
    } else {
      return authorizationSuccessResult(authorizedRoles, authorizedUsers);
    }
  }
1225558
public synchronized void obtainAuthorization(Context context, ResponseListener listener, Object... params) {
        authorizationProcessManager.startAuthorizationProcess(context, listener);
    }
1357789
def AuthorizingClient(
    domain,
    auth,
    request_encoder,
    response_decoder,
    user_agent=None
):
    
    
    http_transport = transport.HttpTransport(
        api_url(domain),
        build_headers(auth, user_agent)
    )
    
    return client.Client(
        request_encoder,
        http_transport,
        response_decoder
    )
326174
protected boolean shouldAuthorize(Authentication authentication, Authorizable controlledObject)
    {
        Assert.state(getAccessDecisionManager() != null, "The AccessDecisionManager can not be null!");
        boolean authorize = false;
        try
        {
            if (authentication != null)
            {
                List<ConfigAttribute> cad = getConfigAttributeDefinition(controlledObject);
                if (cad != null)
                {
                    getAccessDecisionManager().decide(authentication, null, cad);
                }
                authorize = true;
            } else {
                // authentication must be disabled, going through
                authorize = true;
            }
        }
        catch (AccessDeniedException e)
        {
            authorize = false;
            // This means the secured objects should not be authorized
        }
        return authorize;
    }
223837
@Override
    public IPermission newPermission(IAuthorizationPrincipal principal)
            throws AuthorizationException {
        return getAuthorizationService().newPermission(getOwner(), principal);
    }
575666
private void authorizationRequestSend(final Context context, String path, AuthorizationRequestManager.RequestOptions options, ResponseListener listener) {
        try {
            AuthorizationRequestManager authorizationRequestManager = new AuthorizationRequestManager();
            authorizationRequestManager.initialize(context, listener);
            authorizationRequestManager.sendRequest(path, options);
        } catch (Exception e) {
            throw new RuntimeException("Failed to send authorization request", e);
        }
    }
1146453
protected void buildAuthorizationConfig() {
        Properties loaded = new Properties();
        InputStream configuration = this.getClass().getResourceAsStream("/case-authorization.properties");
        if (configuration != null) {            
            try {
                loaded.load(configuration);
            } catch (IOException e) {
                logger.error("Error loading case autorization config from file due to {}", e.getMessage(), e);
            }            
        }        

        Stream.of(ProtectedOperation.values()).forEach(operation -> {
           List<String> roles = new ArrayList<>();
           String grantedRoles = loaded.getProperty(operation.toString());
           if (grantedRoles != null) {
               roles.addAll(Arrays.asList(grantedRoles.split(",")));
           }
           operationAuthorization.put(operation, roles);
        });
    }
150356
private void addURIToAuthorize(final HttpServletRequest httpRequest, final URI uri) {
        @SuppressWarnings("unchecked")
        Set<URI> targetURIs = (Set<URI>) httpRequest.getAttribute(URIS_TO_AUTHORIZE);
        if (targetURIs == null) {
            targetURIs = new HashSet<>();
            httpRequest.setAttribute(URIS_TO_AUTHORIZE, targetURIs);
        }
        targetURIs.add(uri);
    }
1334493
protected void authorizeExport(Map<String,String> headers) throws AuthorizationException {
        String path = headers.get(Listener.METAINFO_REQUEST_PATH);
        User user = authorize(path, new JsonObject(), headers);
        Action action = Action.Export;
        Entity entity = getEntity(path, null, headers);
        Long entityId = new Long(0);
        String descrip = path;
        if (descrip.length() > 1000)
            descrip = descrip.substring(0, 999);
        UserAction exportAction = new UserAction(user == null ? "unknown" : user.getName(), action, entity, entityId, descrip);
        exportAction.setSource(getSource());
        auditLog(exportAction);
    }
960403
public static void addAuthorizationHeader(URLConnection urlConnection, String header) {
        if (header != null) {
            urlConnection.setRequestProperty(AUTHORIZATION_HEADER, header);
        }
    }
1137107
public ApiResponse authorizeAppClient(String clientId, String clientSecret) {
        validateNonEmptyParam(clientId, "client identifier");
        validateNonEmptyParam(clientSecret, "client secret");
        assertValidApplicationId();
        loggedInUser = null;
        accessToken = null;
        currentOrganization = null;
        Map<String, Object> formData = new HashMap<String, Object>();
        formData.put("grant_type", "client_credentials");
        formData.put("client_id", clientId);
        formData.put("client_secret", clientSecret);
        ApiResponse response = apiRequest(HttpMethod.POST, formData, null,
                organizationId, applicationId, "token");
        if (response == null) {
            return response;
        }
        if (!isEmpty(response.getAccessToken())) {
            loggedInUser = null;
            accessToken = response.getAccessToken();
            currentOrganization = null;
            log.info("Client.authorizeAppClient(): Access token: "
                    + accessToken);
        } else {
            log.info("Client.authorizeAppClient(): Response: " + response);
        }
        return response;
    }