Performs some checks if logging was requested.

@param bool           $granted
@param EntryInterface $ace
14633
public function logIfNeeded($granted, EntryInterface $ace)
    {
        if (!$ace instanceof AuditableEntryInterface) {
            return;
        }

        if ($granted && $ace->isAuditSuccess()) {
            $this->doLog($granted, $ace);
        } elseif (!$granted && $ace->isAuditFailure()) {
            $this->doLog($granted, $ace);
        }
    }
1011028
public function logJoinPointAccessDecisions(JoinPointInterface $joinPoint)
    {
        $subjectJoinPoint = $joinPoint->getMethodArgument('subject');
        $decision = $joinPoint->getResult() === true ? 'GRANTED' : 'DENIED';
        $message = sprintf('Decided "%s" on method call %s::%s().', $decision, $subjectJoinPoint->getClassName(), $subjectJoinPoint->getMethodName());
        $this->securityLogger->info($message, $this->getLogEnvironmentFromJoinPoint($joinPoint));
    }
731925
public function is_logged_in() {
        // Has the token expired?
        if (isset($this->accesstoken->expires) && time() >= $this->accesstoken->expires) {
            $this->log_out();
            return false;
        }

        // We have a token so we are logged in.
        if (isset($this->accesstoken->token)) {
            // Check that the access token has all the requested scopes.
            $scopemissing = false;
            $scopecheck = ' ' . $this->accesstoken->scope . ' ';

            $requiredscopes = explode(' ', $this->scope);
            foreach ($requiredscopes as $requiredscope) {
                if (strpos($scopecheck, ' ' . $requiredscope . ' ') === false) {
                    $scopemissing = true;
                    break;
                }
            }
            if (!$scopemissing) {
                return true;
            }
        }

        // If we've been passed then authorization code generated by the
        // authorization server try and upgrade the token to an access token.
        $code = optional_param('oauth2code', null, PARAM_RAW);
        // Note - sometimes we may call is_logged_in twice in the same request - we don't want to attempt
        // to upgrade the same token twice.
        if ($code && !in_array($code, self::$upgradedcodes) && $this->upgrade_token($code)) {
            return true;
        }

        return false;
    }
159703
public function handleRequest(AdminEvent $event)
    {
        if (!$this->applicationConfiguration->getParameter('enable_security')) {
            return;
        }
        $user = $this->getUser();

        if (!$this->authorizationChecker->isGranted($user->getRoles(), $user)) {
            throw new AccessDeniedException();
        }
        $configuration = $event->getAdmin()->getConfiguration();
        $allowed = false;

        foreach ($user->getRoles() as $role) {
            if ($role instanceof Role) {
                $role = $role->getRole();
            }

            if ($configuration->getParameter('permissions') === $role) {
                $allowed = true;
            }
        }
        if (!$allowed) {
            throw new AccessDeniedException();
        }
    }
1243207
public function authorizeAtGate(GateInterface $gate, $ability, $arguments)
    {
        try {
            return $gate->authorize($ability, $arguments);
        }
        catch (UnauthorizedException $e) {
            $exception = $this->createGateUnauthorizedException($ability, $arguments, $e->getMessage(), $e);

            throw $exception;
        }
    }
196471
public function checkIpIsInRange($ipGiven, $ipStart, $ipEnd)
    {
        $sReturn     = 'out';
        $startNo     = $this->convertIpToNumber($ipStart);
        $endNo       = $this->convertIpToNumber($ipEnd);
        $evaluatedNo = $this->convertIpToNumber($ipGiven);
        if ($sReturn == 'out') {
            if (($evaluatedNo >= $startNo) && ($evaluatedNo <= $endNo)) {
                $sReturn = 'in';
            }
        }
        return $sReturn;
    }
346462
static function writeAudit( $auditName, $auditAttributes = array() )
    {
        $enabled = eZAudit::isAuditEnabled();
        if ( !$enabled )
            return false;

        $auditNameSettings = eZAudit::auditNameSettings();

        if ( !isset( $auditNameSettings[$auditName] ) )
            return false;

        $ip = eZSys::clientIP();
        if ( !$ip )
            $ip = eZSys::serverVariable( 'HOSTNAME', true );

        $user = eZUser::currentUser();
        $userID = $user->attribute( 'contentobject_id' );
        $userLogin = $user->attribute( 'login' );

        $message = "[$ip] [$userLogin:$userID]\n";

        foreach ( array_keys( $auditAttributes ) as $attributeKey )
        {
            $attributeValue = $auditAttributes[$attributeKey];
            $message .= "$attributeKey: $attributeValue\n";
        }

        $logName = $auditNameSettings[$auditName]['file_name'];
        $dir = $auditNameSettings[$auditName]['dir'];
        eZLog::write( $message, $logName, $dir );

        return true;
    }
1281382
public function report(ServerRequestInterface $request, Throwable $e): void
    {
        $level = $this->getLogLevel($e);
        $message = $this->getMessage($request, $e);

        $this->logger->log($level, $message);
    }
1329299
protected static function hasScope(ContextInterface $context, string $scope): bool
    {
        $result = false;

        if (static::ctxHasCurrentAccount($context) === true) {
            /** @var PassportAccountInterface $account */
            $account = self::ctxGetCurrentAccount($context);
            $result  = $account->hasScope($scope);
        }

        return $result;
    }
826577
public function attachRole($role, $granted = TRUE)
    {
        if($granted)
            return (!$this->grantedRoles()->get()->contains($role)) ? $this->roles()->attach($role, array('granted' => TRUE)) : true;
        else
            return (!$this->deniedRoles()->get()->contains($role)) ? $this->roles()->attach($role, array('granted' => FALSE)) : true;
    }
647915
function isAllowed(/*iAuthResource*/ $resource = null, /*iIdentity*/ $role = null)
    {
        $role = ($role) ?: $this->identity();

        if (!is_object($resource)
            || (!$resource instanceof PermResource || !method_exists($resource, 'getRouteMatch'))
        )
            throw new \Exception('Invalid Resource Type, Can`t Check The Permissions.');

        $return = true;

        $matchedRouteName = $resource->getRouteMatch()->getMatchedRouteName();

        // Access Admin Route Need Authorized User
        if ($matchedRouteName == \yimaAdminor\Module::ADMIN_ROUTE_NAME)
            $return = $return && $role->hasAuthenticated();

        return $return;
    }
546046
public static function checkRestrictedAccess($route)
    {
        Logger::log('Checking admin zone');
        //Chequeamos si entramos en el admin
        if (!Config::getInstance()->checkTryToSaveConfig()
            && (preg_match('/^\/(admin|setup\-admin)/i', $route) || Config::getParam('restricted', false))
        ) {
            if (!self::isTest() &&
                null === Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true)) {
                throw new AdminCredentialsException();
            }
            if (!Security::getInstance()->checkAdmin()) {
                throw new AccessDeniedException();
            }
            Logger::log('Admin access granted');
        }
    }
450424
protected function runBeforeCallback($authority, $ability, $arguments = [], $additional = null)
    {
        if ($this->slot != 'before') {
            return;
        }

        list($model, $additional) = $this->parseGateBeforeArguments(
            $arguments, $additional
        );

        if (! is_null($additional)) {
            return;
        }

        return $this->checkAtClipboard($authority, $ability, $model);
    }
312885
protected function _log($message, $pid = null, $addDetails = true) {
		if (!Configure::read('Queue.log')) {
			return;
		}

		if ($addDetails) {
			$timeNeeded = $this->_timeNeeded();
			$memoryUsage = $this->_memoryUsage();
			$message .= ' [' . $timeNeeded . ', ' . $memoryUsage . ']';
		}

		if ($pid) {
			$message .= ' (pid ' . $pid . ')';
		}
		Log::write('info', $message, ['scope' => 'queue']);
	}
898376
public function pushLogToSession(bool $clean): void
    {
        //====================================================================//
        // Decide if Current Logged User Needs to Be Notified or Not
        if (!$this->isAllowedNotify()) {
            return;
        }
        //====================================================================//
        // Catch Splash Errors
        if (!empty(Splash::log()->err)) {
            foreach (Splash::log()->err as $message) {
                $this->session->getFlashBag()->add('error', $message);
            }
        }
        //====================================================================//
        // Catch Splash Warnings
        if (!empty(Splash::log()->war)) {
            foreach (Splash::log()->war as $message) {
                $this->session->getFlashBag()->add('warning', $message);
            }
        }
        //====================================================================//
        // Catch Splash Messages
        if (!empty(Splash::log()->msg)) {
            foreach (Splash::log()->msg as $message) {
                $this->session->getFlashBag()->add('success', $message);
            }
        }
        //====================================================================//
        // Clear Splash Log
        if ($clean) {
            Splash::log()->cleanLog();
        }
    }
587505
protected function GrantActions(Action $action, array $grantedActions)
    {
        foreach ($grantedActions as $grantedAction)
        {
            if ((string)$action == (string)$grantedAction)
                return GrantResult::Allowed();
        }
        return GrantResult::NoAccess();
    }
962441
public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName)
    {
        $this->loadIdsFromLogActionTable();

        $visitAction = array(
            'idvisit'           => $visitor->getVisitorColumn('idvisit'),
            'idsite'            => $this->request->getIdSite(),
            'idvisitor'         => $visitor->getVisitorColumn('idvisitor'),
            'idaction_url'      => $this->getIdActionUrl(),
            'idaction_url_ref'  => $idReferrerActionUrl,
            'idaction_name_ref' => $idReferrerActionName
        );

        /** @var ActionDimension[] $dimensions */
        $dimensions = ActionDimension::getAllDimensions();

        foreach ($dimensions as $dimension) {
            $value = $dimension->onNewAction($this->request, $visitor, $this);

            if ($value !== false) {
                if (is_float($value)) {
                    $value = Common::forceDotAsSeparatorForDecimalPoint($value);
                }

                $visitAction[$dimension->getColumnName()] = $value;
            }
        }

        // idaction_name is NULLable. we only set it when applicable
        if ($this->isActionHasActionName()) {
            $visitAction['idaction_name'] = (int)$this->getIdActionName();
        }

        foreach ($this->actionIdsCached as $field => $idAction) {
            $visitAction[$field] = ($idAction === false) ? 0 : $idAction;
        }

        $customValue = $this->getCustomFloatValue();
        if ($customValue !== false && $customValue !== null && $customValue !== '') {
            $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue);
        }

        $visitAction = array_merge($visitAction, $this->customFields);

        $this->idLinkVisitAction = $this->getModel()->createAction($visitAction);

        $visitAction['idlink_va'] = $this->idLinkVisitAction;

        Common::printDebug("Inserted new action:");
        $visitActionDebug = $visitAction;
        $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']);
        Common::printDebug($visitActionDebug);
    }