PHP Class Neos\Flow\Security\Context

Afficher le fichier Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Свойство Type Description
$activeTokens Neos\Flow\Security\Authentication\TokenInterface[] Array of tokens currently active
$authenticationManager Neos\Flow\Security\Authentication\AuthenticationManagerInterface
$authenticationStrategy integer One of the AUTHENTICATE_* constants to set the authentication strategy.
$authorizationChecksDisabled boolean Whether authorization is disabled @see areAuthorizationChecksDisabled()
$contextHash string @see getContextHash()
$csrfProtectionStrategy integer One of the CSRF_* constants to set the csrf protection strategy
$csrfProtectionTokens array
$hashService Neos\Flow\Security\Cryptography\HashService
$inactiveTokens array Array of tokens currently inactive
$initialized boolean TRUE if the context is initialized in the current request, FALSE or NULL otherwise.
$interceptedRequest Neos\Flow\Mvc\RequestInterface
$policyService Neos\Flow\Security\Policy\PolicyService
$request Neos\Flow\Mvc\ActionRequest
$roles Neos\Flow\Security\Policy\Role[]
$securityLogger Neos\Flow\Log\SecurityLoggerInterface
$sessionManager Neos\Flow\Session\SessionManagerInterface
$tokenStatusLabels array
$tokens array Array of configured tokens (might have request patterns)

Méthodes publiques

Méthode Description
areAuthorizationChecksDisabled ( ) : boolean Returns TRUE if authorization should be ignored, otherwise FALSE This is mainly useful to fetch records without Content Security to kick in (e.g. for AuthenticationProviders)
canBeInitialized ( ) : boolean Check if the securityContext is ready to be initialized. Only after that security will be active.
clearContext ( ) : void Clears the security context.
getAccount ( ) : Account Returns the account of the first authenticated authentication token.
getAccountByAuthenticationProviderName ( string $authenticationProviderName ) : Account Returns an authenticated account for the given provider or NULL if no account was authenticated or no token was registered for the given authentication provider name.
getAuthenticationStrategy ( ) : integer Get the token authentication strategy
getAuthenticationTokens ( ) : Neos\Flow\Security\Authentication\TokenInterface[] Returns all Authentication\Tokens of the security context which are active for the current request. If a token has a request pattern that cannot match against the current request it is determined as not active.
getAuthenticationTokensOfType ( string $className ) : Neos\Flow\Security\Authentication\TokenInterface[] Returns all Authentication\Tokens of the security context which are active for the current request and of the given type. If a token has a request pattern that cannot match against the current request it is determined as not active.
getContextHash ( ) : string Returns a hash that is unique for the current context, depending on hash components, @see setContextHashComponent()
getCsrfProtectionToken ( ) : string Returns the current CSRF protection token. A new one is created when needed, depending on the configured CSRF protection strategy.
getInterceptedRequest ( ) : ActionRequest Returns the request, that has been stored for later resuming after it has been intercepted by a security exception, NULL if there is none.
getRoles ( ) : Role[] Returns the roles of all authenticated accounts, including inherited roles.
hasCsrfProtectionTokens ( ) : boolean Returns TRUE if the context has CSRF protection tokens.
hasRole ( string $roleIdentifier ) : boolean Returns TRUE, if at least one of the currently authenticated accounts holds a role with the given identifier, also recursively.
initialize ( ) : void Initializes the security context for the given request.
injectAuthenticationManager ( Neos\Flow\Security\Authentication\AuthenticationManagerInterface $authenticationManager ) : void Inject the authentication manager
injectSettings ( array $settings ) : void Injects the configuration settings
isCsrfProtectionTokenValid ( string $csrfToken ) : boolean Returns TRUE if the given string is a valid CSRF protection token. The token will be removed if the configured csrf strategy is 'onePerUri'.
isInitialized ( ) : boolean
refreshRoles ( ) : void Refreshes the currently effective roles. In fact the roles first level cache is reset and the effective roles get recalculated by calling getRoles().
refreshTokens ( ) : void Refreshes all active tokens by updating the credentials.
setInterceptedRequest ( ActionRequest $interceptedRequest = null ) : void Sets an action request, to be stored for later resuming after it has been intercepted by a security exception.
setRequest ( ActionRequest $request ) : void Set the current action request
shutdownObject ( ) : void Shut the object down
withoutAuthorizationChecks ( Closure $callback ) : void Lets you switch off authorization checks (CSRF token, policies, content security, .

Méthodes protégées

Méthode Description
isTokenActive ( Neos\Flow\Security\Authentication\TokenInterface $token ) : boolean Evaluates any RequestPatterns of the given token to determine whether it is active for the current request - If no RequestPattern is configured for this token, it is active - Otherwise it is active only if at least one configured RequestPattern per type matches the request
mergeTokens ( array $managerTokens, array $sessionTokens ) : array Merges the session and manager tokens. All manager tokens types will be in the result array If a specific type is found in the session this token replaces the one (of the same type) given by the manager.
separateActiveAndInactiveTokens ( ) : void Stores all active tokens in $this->activeTokens, all others in $this->inactiveTokens
updateTokens ( array $tokens ) : void Updates the token credentials for all tokens in the given array.

Method Details

areAuthorizationChecksDisabled() public méthode

Returns TRUE if authorization should be ignored, otherwise FALSE This is mainly useful to fetch records without Content Security to kick in (e.g. for AuthenticationProviders)
See also: withoutAuthorizationChecks()

canBeInitialized() public méthode

To be able to initialize, there needs to be an ActionRequest available, usually that is provided by the MVC router.
public canBeInitialized ( ) : boolean
Résultat boolean

clearContext() public méthode

Clears the security context.
public clearContext ( ) : void
Résultat void

getAccount() public méthode

Note: There might be a more currently authenticated account in the remaining tokens. If you need them you'll have to fetch them directly from the tokens. (@see getAuthenticationTokens())
public getAccount ( ) : Account
Résultat Account The authenticated account

getAccountByAuthenticationProviderName() public méthode

Returns an authenticated account for the given provider or NULL if no account was authenticated or no token was registered for the given authentication provider name.
public getAccountByAuthenticationProviderName ( string $authenticationProviderName ) : Account
$authenticationProviderName string Authentication provider name of the account to find
Résultat Account The authenticated account

getAuthenticationStrategy() public méthode

Get the token authentication strategy
public getAuthenticationStrategy ( ) : integer
Résultat integer One of the AUTHENTICATE_* constants

getAuthenticationTokens() public méthode

Returns all Authentication\Tokens of the security context which are active for the current request. If a token has a request pattern that cannot match against the current request it is determined as not active.
public getAuthenticationTokens ( ) : Neos\Flow\Security\Authentication\TokenInterface[]
Résultat Neos\Flow\Security\Authentication\TokenInterface[] Array of set tokens

getAuthenticationTokensOfType() public méthode

Returns all Authentication\Tokens of the security context which are active for the current request and of the given type. If a token has a request pattern that cannot match against the current request it is determined as not active.
public getAuthenticationTokensOfType ( string $className ) : Neos\Flow\Security\Authentication\TokenInterface[]
$className string The class name
Résultat Neos\Flow\Security\Authentication\TokenInterface[] Array of set tokens of the specified type

getContextHash() public méthode

Returns a hash that is unique for the current context, depending on hash components, @see setContextHashComponent()
public getContextHash ( ) : string
Résultat string

getCsrfProtectionToken() public méthode

Returns the current CSRF protection token. A new one is created when needed, depending on the configured CSRF protection strategy.
public getCsrfProtectionToken ( ) : string
Résultat string

getInterceptedRequest() public méthode

Returns the request, that has been stored for later resuming after it has been intercepted by a security exception, NULL if there is none.
public getInterceptedRequest ( ) : ActionRequest
Résultat Neos\Flow\Mvc\ActionRequest

getRoles() public méthode

If no authenticated roles could be found the "Anonymous" role is returned. The "Neos.Flow:Everybody" roles is always returned.
public getRoles ( ) : Role[]
Résultat Neos\Flow\Security\Policy\Role[]

hasCsrfProtectionTokens() public méthode

Returns TRUE if the context has CSRF protection tokens.
public hasCsrfProtectionTokens ( ) : boolean
Résultat boolean TRUE, if the token is valid. FALSE otherwise.

hasRole() public méthode

Returns TRUE, if at least one of the currently authenticated accounts holds a role with the given identifier, also recursively.
public hasRole ( string $roleIdentifier ) : boolean
$roleIdentifier string The string representation of the role to search for
Résultat boolean TRUE, if a role with the given string representation was found

initialize() public méthode

Initializes the security context for the given request.
public initialize ( ) : void
Résultat void

injectAuthenticationManager() public méthode

Inject the authentication manager
public injectAuthenticationManager ( Neos\Flow\Security\Authentication\AuthenticationManagerInterface $authenticationManager ) : void
$authenticationManager Neos\Flow\Security\Authentication\AuthenticationManagerInterface The authentication manager
Résultat void

injectSettings() public méthode

Injects the configuration settings
public injectSettings ( array $settings ) : void
$settings array
Résultat void

isCsrfProtectionTokenValid() public méthode

Returns TRUE if the given string is a valid CSRF protection token. The token will be removed if the configured csrf strategy is 'onePerUri'.
public isCsrfProtectionTokenValid ( string $csrfToken ) : boolean
$csrfToken string The token string to be validated
Résultat boolean TRUE, if the token is valid. FALSE otherwise.

isInitialized() public méthode

public isInitialized ( ) : boolean
Résultat boolean TRUE if the Context is initialized, FALSE otherwise.

isTokenActive() protected méthode

Evaluates any RequestPatterns of the given token to determine whether it is active for the current request - If no RequestPattern is configured for this token, it is active - Otherwise it is active only if at least one configured RequestPattern per type matches the request
protected isTokenActive ( Neos\Flow\Security\Authentication\TokenInterface $token ) : boolean
$token Neos\Flow\Security\Authentication\TokenInterface
Résultat boolean TRUE if the given token is active, otherwise FALSE

mergeTokens() protected méthode

Merges the session and manager tokens. All manager tokens types will be in the result array If a specific type is found in the session this token replaces the one (of the same type) given by the manager.
protected mergeTokens ( array $managerTokens, array $sessionTokens ) : array
$managerTokens array Array of tokens provided by the authentication manager
$sessionTokens array Array of tokens restored from the session
Résultat array Array of Authentication\TokenInterface objects

refreshRoles() public méthode

Refreshes the currently effective roles. In fact the roles first level cache is reset and the effective roles get recalculated by calling getRoles().
public refreshRoles ( ) : void
Résultat void

refreshTokens() public méthode

This is useful when doing an explicit authentication inside a request.
public refreshTokens ( ) : void
Résultat void

separateActiveAndInactiveTokens() protected méthode

Stores all active tokens in $this->activeTokens, all others in $this->inactiveTokens
protected separateActiveAndInactiveTokens ( ) : void
Résultat void

setInterceptedRequest() public méthode

Sets an action request, to be stored for later resuming after it has been intercepted by a security exception.
public setInterceptedRequest ( ActionRequest $interceptedRequest = null ) : void
$interceptedRequest Neos\Flow\Mvc\ActionRequest
Résultat void

setRequest() public méthode

This method is called manually by the request handler which created the HTTP request.
public setRequest ( ActionRequest $request ) : void
$request Neos\Flow\Mvc\ActionRequest The current ActionRequest
Résultat void

shutdownObject() public méthode

Shut the object down
public shutdownObject ( ) : void
Résultat void

updateTokens() protected méthode

Updates the token credentials for all tokens in the given array.
protected updateTokens ( array $tokens ) : void
$tokens array Array of authentication tokens the credentials should be updated for
Résultat void

withoutAuthorizationChecks() public méthode

..) for the runtime of $callback Usage: $this->securityContext->withoutAuthorizationChecks(function () use ($accountRepository, $username, $providerName, &$account) { this will disable the PersistenceQueryRewritingAspect for this one call $account = $accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName($username, $providerName) });
public withoutAuthorizationChecks ( Closure $callback ) : void
$callback Closure
Résultat void

Property Details

$activeTokens protected_oe property

Array of tokens currently active
protected TokenInterface[],Neos\Flow\Security\Authentication $activeTokens
Résultat Neos\Flow\Security\Authentication\TokenInterface[]

$authenticationManager protected_oe property

protected AuthenticationManagerInterface,Neos\Flow\Security\Authentication $authenticationManager
Résultat Neos\Flow\Security\Authentication\AuthenticationManagerInterface

$authenticationStrategy protected_oe property

One of the AUTHENTICATE_* constants to set the authentication strategy.
protected int $authenticationStrategy
Résultat integer

$authorizationChecksDisabled protected_oe property

Whether authorization is disabled @see areAuthorizationChecksDisabled()
protected bool $authorizationChecksDisabled
Résultat boolean

$contextHash protected_oe property

@see getContextHash()
protected string $contextHash
Résultat string

$csrfProtectionStrategy protected_oe property

One of the CSRF_* constants to set the csrf protection strategy
protected int $csrfProtectionStrategy
Résultat integer

$csrfProtectionTokens protected_oe property

protected array $csrfProtectionTokens
Résultat array

$hashService protected_oe property

protected HashService,Neos\Flow\Security\Cryptography $hashService
Résultat Neos\Flow\Security\Cryptography\HashService

$inactiveTokens protected_oe property

Array of tokens currently inactive
protected array $inactiveTokens
Résultat array

$initialized protected_oe property

TRUE if the context is initialized in the current request, FALSE or NULL otherwise.
protected bool $initialized
Résultat boolean

$interceptedRequest protected_oe property

protected RequestInterface,Neos\Flow\Mvc $interceptedRequest
Résultat Neos\Flow\Mvc\RequestInterface

$policyService protected_oe property

protected PolicyService,Neos\Flow\Security\Policy $policyService
Résultat Neos\Flow\Security\Policy\PolicyService

$request protected_oe property

protected ActionRequest,Neos\Flow\Mvc $request
Résultat Neos\Flow\Mvc\ActionRequest

$roles protected_oe property

protected Role[],Neos\Flow\Security\Policy $roles
Résultat Neos\Flow\Security\Policy\Role[]

$securityLogger protected_oe property

protected SecurityLoggerInterface,Neos\Flow\Log $securityLogger
Résultat Neos\Flow\Log\SecurityLoggerInterface

$sessionManager protected_oe property

protected SessionManagerInterface,Neos\Flow\Session $sessionManager
Résultat Neos\Flow\Session\SessionManagerInterface

$tokenStatusLabels protected_oe property

protected array $tokenStatusLabels
Résultat array

$tokens protected_oe property

Array of configured tokens (might have request patterns)
protected array $tokens
Résultat array