PHP Class Neos\Flow\Security\Context

Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property 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)

Public Methods

Method 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, .

Protected Methods

Method 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 method

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 method

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

clearContext() public method

Clears the security context.
public clearContext ( ) : void
return void

getAccount() public method

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
return Account The authenticated account

getAccountByAuthenticationProviderName() public method

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
return Account The authenticated account

getAuthenticationStrategy() public method

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

getAuthenticationTokens() public method

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[]
return Neos\Flow\Security\Authentication\TokenInterface[] Array of set tokens

getAuthenticationTokensOfType() public method

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
return Neos\Flow\Security\Authentication\TokenInterface[] Array of set tokens of the specified type

getContextHash() public method

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

getCsrfProtectionToken() public method

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

getInterceptedRequest() public method

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
return Neos\Flow\Mvc\ActionRequest

getRoles() public method

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

hasCsrfProtectionTokens() public method

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

hasRole() public method

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
return boolean TRUE, if a role with the given string representation was found

initialize() public method

Initializes the security context for the given request.
public initialize ( ) : void
return void

injectAuthenticationManager() public method

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

injectSettings() public method

Injects the configuration settings
public injectSettings ( array $settings ) : void
$settings array
return void

isCsrfProtectionTokenValid() public method

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
return boolean TRUE, if the token is valid. FALSE otherwise.

isInitialized() public method

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

isTokenActive() protected method

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
return boolean TRUE if the given token is active, otherwise FALSE

mergeTokens() protected method

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
return array Array of Authentication\TokenInterface objects

refreshRoles() public method

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
return void

refreshTokens() public method

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

separateActiveAndInactiveTokens() protected method

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

setInterceptedRequest() public method

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
return void

setRequest() public method

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
return void

shutdownObject() public method

Shut the object down
public shutdownObject ( ) : void
return void

updateTokens() protected method

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
return void

withoutAuthorizationChecks() public method

..) 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
return void

Property Details

$activeTokens protected property

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

$authenticationManager protected property

protected AuthenticationManagerInterface,Neos\Flow\Security\Authentication $authenticationManager
return Neos\Flow\Security\Authentication\AuthenticationManagerInterface

$authenticationStrategy protected property

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

$authorizationChecksDisabled protected property

Whether authorization is disabled @see areAuthorizationChecksDisabled()
protected bool $authorizationChecksDisabled
return boolean

$contextHash protected property

@see getContextHash()
protected string $contextHash
return string

$csrfProtectionStrategy protected property

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

$csrfProtectionTokens protected property

protected array $csrfProtectionTokens
return array

$hashService protected property

protected HashService,Neos\Flow\Security\Cryptography $hashService
return Neos\Flow\Security\Cryptography\HashService

$inactiveTokens protected property

Array of tokens currently inactive
protected array $inactiveTokens
return array

$initialized protected property

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

$interceptedRequest protected property

protected RequestInterface,Neos\Flow\Mvc $interceptedRequest
return Neos\Flow\Mvc\RequestInterface

$policyService protected property

protected PolicyService,Neos\Flow\Security\Policy $policyService
return Neos\Flow\Security\Policy\PolicyService

$request protected property

protected ActionRequest,Neos\Flow\Mvc $request
return Neos\Flow\Mvc\ActionRequest

$roles protected property

protected Role[],Neos\Flow\Security\Policy $roles
return Neos\Flow\Security\Policy\Role[]

$securityLogger protected property

protected SecurityLoggerInterface,Neos\Flow\Log $securityLogger
return Neos\Flow\Log\SecurityLoggerInterface

$sessionManager protected property

protected SessionManagerInterface,Neos\Flow\Session $sessionManager
return Neos\Flow\Session\SessionManagerInterface

$tokenStatusLabels protected property

protected array $tokenStatusLabels
return array

$tokens protected property

Array of configured tokens (might have request patterns)
protected array $tokens
return array