关联删除 AuthAccess
判断是否有用户使用此角色,如果有返回使用角色数量
否则删除角色数据,调用authAccess方法如果有数据删除关联AuthAccess模型数据

@return bool
500980
public function authRoleDelete()
    {
        $roleCount = AuthRoleUser::where(['role_id'=>$this->id])->count();
        if($roleCount > 0){
            return "已有{$roleCount}用户在是有此角色不可删除";
        }

        if($this->delete()){
            if($this->authAccess){
                AuthAccess::where(['role_id'=>$this->id,'type'=>'admin_url'])->delete();
            }
            return true;
        }
        return false;
    }
244378
public function isApplicationAuthorized(){

        $application = [];

        if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {

            $autorizzazioni = $this->tokenStorage->getToken()->getUser()->getIdAutorizzazione();

            foreach($autorizzazioni as $autorizzazione){
                $application[] = $autorizzazione->getIdApplicazione()->getIdApplicazione();
            }

        }


        return in_array($this->application_id, $application);
    }
263737
protected function checkUserSecurity()
    {
        $allowedGroup = $this->property('security', self::ALLOW_ALL);
        $allowedUserGroups = $this->property('allowedUserGroups', []);
        $isAuthenticated = Auth::check();

        if ($isAuthenticated) {
            if ($allowedGroup == self::ALLOW_GUEST) {
                return false;
            }

            if (!empty($allowedUserGroups)) {
                $userGroups = Auth::getUser()->groups->lists('code');
                if (!count(array_intersect($allowedUserGroups, $userGroups))) {
                    return false;
                }
            }
        }
        else {
            if ($allowedGroup == self::ALLOW_USER) {
                return false;
            }
        }

        return true;
    }
1314446
public function authenticate()
	{
		$user=User::model()->find('LOWER(username)=?',array(strtolower($this->username)));
		if($user===null)
			$this->errorCode=self::ERROR_USERNAME_INVALID;
		else if(!$user->validatePassword($this->password))
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
		else
		{
			$this->_id=$user->id;
			$this->username=$user->username;
			$this->errorCode=self::ERROR_NONE;
		}
		return $this->errorCode==self::ERROR_NONE;
	}
812922
public static function httpAuthenticate() {
		try { 
			static::httpLogin();
			return true;
		} catch( NotFoundException $e ) {
			if( Config::get('httpauth_autocreate') ) {
				$user = static::httpCreate();
				$user->login();
				return true;
			}
		} catch( UserException $e ) { }
		return false;
	}
137340
public function checkBE()
	{
	    if ($this->isContao45()) 
	    {
	        if ($this->_BackendUser)
	        {
                ModuleVisitorLog::writeLog( __METHOD__ , __LINE__ , ': True' );
                return true;
	        }
	        ModuleVisitorLog::writeLog( __METHOD__ , __LINE__ , ': False' );
	        return false;
	    }
		//Contao <4.5.0
	    $strCookie = 'BE_USER_AUTH';
		$hash = sha1(session_id() . (!\Config::get('privacyAnonymizeIp') ? \Environment::get('ip') : '') . $strCookie);
		if (\Input::cookie($strCookie) == $hash)
		{
			// Try to find the session
			$objSession = \SessionModel::findByHashAndName($hash, $strCookie);
			// Validate the session ID and timeout
			if ($objSession !== null && $objSession->sessionID == session_id() && (\Config::get('privacyAnonymizeIp') || $objSession->ip == \Environment::get('ip')) && ($objSession->tstamp + $GLOBALS['TL_CONFIG']['sessionTimeout']) > time())
			{
			    ModuleVisitorLog::writeLog( __METHOD__ , __LINE__ , ': True' );
				return true;
			}
		}
		ModuleVisitorLog::writeLog( __METHOD__ , __LINE__ , ': False' );
		return false;
	}
1028389
public function check()
	{
		$request = $this->app['request'];
		$getter = new TokenGetter( new Header($request), new  QueryStr($request));
		return $this->auth->check($getter, $this->secretKey);
	}
645033
protected function checkAuth()
	{
		try {

			// get the JWT from the headers
			list($jwt) = sscanf($_SERVER["HTTP_AUTHORIZATION"], 'Bearer %s');

			// init the jwt auth class
			$authenticator = new JWTAuthenticator(new User());

			// get the application secret key
			$config     = \Erdiko::getConfig();
			$secretKey  = $config["site"]["secret_key"];

			// collect login params
			$params = array(
				'secret_key'    =>  $secretKey,
				'jwt'           =>  $jwt
			);

			$user = $authenticator->verify($params, 'jwt_auth');

			//TODO check the user's permissions via Resource & Authorization

			// no exceptions? welp, this is a valid request
			return true;
		} catch (\Exception $e) {
			return true;
		}
	}
313354
public static function check()
    {
        if (Session::exists(static::resource('session'))) {
            return true;
        } elseif (Cookie::existe(static::resource('cookie'))) {
            $token = Cookie::get(static::resource('cookie'));

            $result = Query::from(config('auth.table'))
                ->where('rememberToken', '=', $token)
                ->get();

            if (count($result) > 0) {
                return true;
            }

            return false;
        }

        return false;
    }
848021
public function authorize() : bool
    {
        return Auth::check() && Auth::user()->is($this->user()) && $this->isAllowed();
    }
219752
protected function getAuth()
    {
        if (is_null($this->auth)) {
            $this->auth = app($this->config('auth'));
        }

        return $this->auth;
    }
1309201
public function checkBE()
	{
	    $strCookie = 'BE_USER_AUTH';
	    $hash = sha1(session_id() . (!\Config::get('privacyAnonymizeIp') ? \Environment::get('ip') : '') . $strCookie);
	    if (\Input::cookie($strCookie) == $hash)
	    {
	        $objSession = \Database::getInstance()
                	        ->prepare("SELECT * FROM tl_session WHERE hash=? AND name=?")
                	        ->limit(1)
                	        ->execute($hash, $strCookie);
	        if ($objSession->numRows &&
	            $objSession->sessionID == session_id() &&
	            //$objSession->ip == $this->Environment->ip &&
	            (\Config::get('privacyAnonymizeIp') || $objSession->ip == \Environment::get('ip')) &&
	            ($objSession->tstamp + $GLOBALS['TL_CONFIG']['sessionTimeout']) > time())
	        {
	            $this->BE_Filter = true;
	            return $this->BE_Filter;
	        }
	    }
	    $this->BE_Filter = false;
	    return $this->BE_Filter;
	}
428395
public function authenticate()
    {
        $result = false;

        if (isset($_GET['code'])) {
            $params = array(
                'grant_type' => 'authorization_code',
                'code' => $_GET['code'],
                'client_id' => $this->clientId,
                'client_secret' => $this->clientSecret
            );

            $tokenInfo = $this->post('https://oauth.yandex.ru/token', $params);

            if (isset($tokenInfo['access_token'])) {
                $params = array(
                    'format' => 'json',
                    'oauth_token' => $tokenInfo['access_token']
                );

                $userInfo = $this->get('https://login.yandex.ru/info', $params);

                if (isset($userInfo['id'])) {
                    $this->userInfo = $userInfo;
                    $result = true;
                }
            }
        }

        return $result;
    }
173939
public function checkAuth()
    {
        $response = $this->guzzleClient->get('https://accounts.google.com',
            ['cookies' => $this->cookieJar]
        );

        if (strpos($response->getEffectiveUrl(), 'ServiceLogin') !== false) {
            return false;
        }

        return true;
    }
1056873
public function isAccessible()
    {
        if ($this->hasAccessRestrictions() === false) {
            return true;
        }

        if ($this->securityContext->canBeInitialized() === false) {
            return true;
        }

        foreach ($this->accessRoles as $roleName) {
            if ($this->securityContext->hasRole($roleName)) {
                return true;
            }
        }

        return false;
    }
1300678
protected function getOAuthCode()
    {
        // 1. 如果请求不带code,不再处理
        if (!isset($this->request['code']) || !isset($this->request['state'])) {
            return false;
        }

        // 2. 检查是否为认证服务号
        $account = wei()->wechatAccount->getCurrentAccount();
        if (!$account->isVerifiedService()) {
            $this->logger->info('Got OAuth code, but wechat account is not verified service');

            return false;
        }

        // 3. 如果code已经处理过,不再处理
        if (!wei()->cache->add('wechatOAuth2Code' . $this->request['code'], true, 86400 * 3)) {
            return false;
        }

        return $this->request['code'];
    }
445753
public function getOauthAccessToken()
    {
        $appid = $this->config->get('appid');
        $appsecret = $this->config->get('appsecret');
        $code = isset($_GET['code']) ? $_GET['code'] : '';
        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code";
        return $this->httpGetForJson($url);
    }