Restore authentications from persisted state.

@param savedAuthorization saved authorizations
494326
@Api
	public void restoreSecurityContext(SavedAuthorization savedAuthorization) {
		List<Authentication> auths = new ArrayList<Authentication>();
		if (null != savedAuthorization) {
			for (SavedAuthentication sa : savedAuthorization.getAuthentications()) {
				Authentication auth = new Authentication();
				auth.setSecurityServiceId(sa.getSecurityServiceId());
				auth.setAuthorizations(sa.getAuthorizations());
				auths.add(auth);
			}
		}
		setAuthentications(null, auths);
		userInfoInit();
	}
1262320
public static void setCurrentAuthentication(Authentication authentication) {
        RequestContext context = RequestContext.getCurrent();
        if (context != null) {
            setAuthentication(context.getRequest(), authentication);
        }
    }
1219309
protected void updateAuthorizationBasedOnCacheEntries(AuthorizationEntity authorization, String userId, String groupId,
                                                        Resource resource, String resourceId) {
    DbEntityManager dbManager = Context.getCommandContext().getDbEntityManager();
    List<AuthorizationEntity> list = dbManager.getCachedEntitiesByType(AuthorizationEntity.class);
    for (AuthorizationEntity authEntity : list) {
      boolean hasSameAuthRights = hasEntitySameAuthorizationRights(authEntity, userId, groupId, resource, resourceId);
      if (hasSameAuthRights) {
        int previousPermissions = authEntity.getPermissions();
        authorization.setPermissions(previousPermissions);
        dbManager.getDbEntityCache().remove(authEntity);
        return;
      }
    }
  }
1225558
public synchronized void obtainAuthorization(Context context, ResponseListener listener, Object... params) {
        authorizationProcessManager.startAuthorizationProcess(context, listener);
    }
929601
public void addMoreContext(CacheContext context) {
		Object cached = context.get(CacheContext.SECURITY_CONTEXT_KEY);
		if (cached == null) {
			SavedAuthorization sa = securityContext.getSavedAuthorization();
			log.debug("Storing SavedAuthorization {}", sa);
			context.put(CacheContext.SECURITY_CONTEXT_KEY, sa);
		}
	}
919608
protected boolean shouldAuthorize(Authentication authentication) {
        Assert.state(getAccessDecisionManager() != null, "The AccessDecisionManager can not be null!");
        boolean authorize = false;
        try {
            if( authentication != null ) {
                Object securedObject = getSecuredObject();
                List<ConfigAttribute> cad = getConfigAttributeDefinition( securedObject );
                getAccessDecisionManager().decide( authentication, getSecuredObject(), cad );
                authorize = true;
            }
        } catch( AccessDeniedException e ) {
            // This means the secured objects should not be authorized
        }
        return authorize;
    }
1073817
private AuthenticationInfo getUncachedAuthenticationInfoForKey(String authenicationId) {
        ApiKey apiKey = _authIdentityReader.getIdentityByAuthenticationId(authenicationId);
        if (apiKey == null) {
            return null;
        }

        return createAuthenticationInfo(authenicationId, apiKey);
    }
1169643
def changeUserAuthorizations(self, login, user, authorizations):
    
    self.send_changeUserAuthorizations(login, user, authorizations)
    self.recv_changeUserAuthorizations()
610632
public function restoreOriginalRestApiAuthenticationObjects()
    {
        $this->removeRestApiAuthenticationObjects();

        foreach ($this->originalRestApiAuthenticationObjects as $className => $object) {
            static::$instances[$className] = $object;
        }
    }
168124
public void setEnableAuthentication( boolean enableAuthentication ) {

		this.logger.fine( "Authentication is now " + (enableAuthentication ? "enabled" : "disabled") + ". Updating the REST resource." );
		this.enableAuthentication = enableAuthentication;

		if( this.authenticationFilter != null )
			this.authenticationFilter.setAuthenticationEnabled( enableAuthentication );
	}
116490
function onAuthorizedAccess() {
          if (angular.isFunction(permission.onAuthorized)) {
            permission.onAuthorized()($element);
          } else {
            var onAuthorizedMethodName = $permission.defaultOnAuthorizedMethod;
            PermPermissionStrategies[onAuthorizedMethodName]($element);
          }
        }
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;
    }
581127
protected void createDefaultAuthorizations(DeploymentEntity deployment) {
    if(isAuthorizationEnabled()) {
      ResourceAuthorizationProvider provider = getResourceAuthorizationProvider();
      AuthorizationEntity[] authorizations = provider.newDeployment(deployment);
      saveDefaultAuthorizations(authorizations);
    }
  }
1083441
public void restoreSecurityContext(CacheContext context) {
		SavedAuthorization cached = context.get(CacheContext.SECURITY_CONTEXT_KEY, SavedAuthorization.class);
		if (cached != null) {
			log.debug("Restoring security context {}", cached);
			securityManager.restoreSecurityContext(cached);
		} else {
			securityManager.clearSecurityContext();
		}
	}
1092609
private User checkExistsAndAuthz(final Cache<String, User> cache, final User user, final AuthenticationBackend authenticationBackend,
            final Set<AuthorizationBackend> authorizers) {
        if (user == null) {
            return null;
        }

        try {
            return cache.get(user.getName(), new Callable<User>() { //no cache miss in case of noop
                @Override
                public User call() throws Exception {
                    if (log.isTraceEnabled()) {
                        log.trace("Credentials for user " + user.getName() + " not cached, return from " + authenticationBackend.getType()
                                + " backend directly");
                    }
                    if (authenticationBackend.exists(user)) {
                        authz(user, null, authorizers); //no role cache because no miss here in case of noop
                        return user;
                    }

                    if (log.isDebugEnabled()) {
                        log.debug("User " + user.getName() + " does not exist in " + authenticationBackend.getType());
                    }
                    return null;
                }
            });
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Can not check and authorize " + user.getName() + " due to " + e.toString(), e);
            }
            return null;
        }
    }
1333971
private void refreshAccessToken() {
    final Long expiresIn = credential.getExpiresInSeconds();

    // trigger refresh if token is about to expire
    String accessToken = credential.getAccessToken();
    if (accessToken == null || expiresIn != null && expiresIn <= 60) {
      try {
        credential.refreshToken();
        accessToken = credential.getAccessToken();
      } catch (final IOException e) {
        log.error("Failed to fetch access token", e);
      }
    }
    if (accessToken != null) {
      this.accessToken = accessToken;
    }
  }
936673
private function savePayloadAuthTokens($operationId)
    {
        if (
            $this->valid
            && $this->apiPayloadAuth->hasAuthRequest($operationId)
        ) {
            $fieldSets = $this->getAggregateActualResponses(null, $operationId);
            $this->apiPayloadAuth->savePayloadAuthTokens($operationId, $fieldSets);
        }
    }