Skip to content

Commit 7d2299e

Browse files
Bernhard Schmittmficzel
authored andcommitted
Adjust Neos.Flow Security subcontext
1 parent 205a240 commit 7d2299e

File tree

61 files changed

+308
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+308
-223
lines changed

Neos.Flow/Classes/Security/Account.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Account
5555
protected $creationDate;
5656

5757
/**
58-
* @var \DateTime
58+
* @var \DateTime|null
5959
* @ORM\Column(nullable=true)
6060
*/
6161
protected $expirationDate;
@@ -73,7 +73,7 @@ class Account
7373
protected $failedAuthenticationCount;
7474

7575
/**
76-
* @var array of strings
76+
* @var array<string>
7777
* @ORM\Column(type="simple_array", nullable=true)
7878
*/
7979
protected $roleIdentifiers = [];
@@ -225,9 +225,6 @@ public function setRoles(array $roles)
225225
$this->roleIdentifiers = [];
226226
$this->roles = [];
227227
foreach ($roles as $role) {
228-
if (!$role instanceof Role) {
229-
throw new \InvalidArgumentException(sprintf('setRoles() only accepts an array of %s instances, given: "%s"', Role::class, gettype($role)), 1397125997);
230-
}
231228
$this->addRole($role);
232229
}
233230
}
@@ -310,7 +307,7 @@ public function getExpirationDate()
310307
/**
311308
* Sets the date on which this account will become inactive
312309
*
313-
* @param \DateTime $expirationDate
310+
* @param ?\DateTime $expirationDate
314311
* @return void
315312
* @api
316313
*/

Neos.Flow/Classes/Security/AccountFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AccountFactory
3737
*
3838
* @param string $identifier Identifier of the account, must be unique
3939
* @param string $password The clear text password
40-
* @param array $roleIdentifiers Optionally an array of role identifiers to assign to the new account
40+
* @param array<string> $roleIdentifiers Optionally an array of role identifiers to assign to the new account
4141
* @param string $authenticationProviderName Optional name of the authentication provider the account is affiliated with
4242
* @param string $passwordHashingStrategy Optional password hashing strategy to use for the password
4343
* @return Account A new account, not yet added to the account repository

Neos.Flow/Classes/Security/AccountRepository.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AccountRepository extends Repository
3030
const ENTITY_CLASSNAME = Account::class;
3131

3232
/**
33-
* @var array
33+
* @var array<string,string>
3434
*/
3535
protected $defaultOrderings = ['creationDate' => QueryInterface::ORDER_DESCENDING];
3636

@@ -51,6 +51,9 @@ class AccountRepository extends Repository
5151
*/
5252
public function remove($object): void
5353
{
54+
if (!$object instanceof Account) {
55+
throw new \InvalidArgumentException('Can only remove account objects.', 1743961393);
56+
}
5457
parent::remove($object);
5558

5659
// destroy the sessions for the account to be removed
@@ -67,12 +70,14 @@ public function remove($object): void
6770
public function findByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, $authenticationProviderName)
6871
{
6972
$query = $this->createQuery();
70-
return $query->matching(
73+
$result = $query->matching(
7174
$query->logicalAnd(
7275
$query->equals('accountIdentifier', $accountIdentifier),
7376
$query->equals('authenticationProviderName', $authenticationProviderName)
7477
)
7578
)->execute()->getFirst();
79+
80+
return $result instanceof Account ? $result : null;
7681
}
7782

7883
/**
@@ -85,7 +90,7 @@ public function findByAccountIdentifierAndAuthenticationProviderName($accountIde
8590
public function findActiveByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, $authenticationProviderName)
8691
{
8792
$query = $this->createQuery();
88-
return $query->matching(
93+
$result = $query->matching(
8994
$query->logicalAnd(
9095
$query->equals('accountIdentifier', $accountIdentifier),
9196
$query->equals('authenticationProviderName', $authenticationProviderName),
@@ -95,5 +100,7 @@ public function findActiveByAccountIdentifierAndAuthenticationProviderName($acco
95100
)
96101
)
97102
)->execute()->getFirst();
103+
104+
return $result instanceof Account ? $result : null;
98105
}
99106
}

Neos.Flow/Classes/Security/Aspect/LoggingAspect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public function logManagerLogout(JoinPointInterface $joinPoint)
100100
}
101101

102102
/**
103-
* @param array $collectedIdentifiers
103+
* @param array<string> $collectedIdentifiers
104104
* @param TokenInterface $token
105-
* @return array
105+
* @return array<string>
106106
*/
107107
protected function reduceTokenToAccountIdentifier(array $collectedIdentifiers, TokenInterface $token): array
108108
{
@@ -170,7 +170,7 @@ public function logPrivilegeAccessDecisions(JoinPointInterface $joinPoint)
170170

171171
/**
172172
* @param JoinPointInterface $joinPoint
173-
* @return array
173+
* @return array<string,array{packageKey: string, className: string, methodName: string}>
174174
*/
175175
protected function getLogEnvironmentFromJoinPoint(JoinPointInterface $joinPoint): array
176176
{

Neos.Flow/Classes/Security/Authentication/AuthenticationProviderInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface AuthenticationProviderInterface
2121
* Constructs an instance with the given name and options.
2222
*
2323
* @param string $name
24-
* @param array $options
24+
* @param array<mixed> $options
2525
* @return self
2626
*/
2727
public static function create(string $name, array $options);
@@ -37,7 +37,7 @@ public function canAuthenticate(TokenInterface $token);
3737
/**
3838
* Returns the classnames of the tokens this provider is responsible for.
3939
*
40-
* @return array The classname of the token this provider is responsible for
40+
* @return array<class-string<TokenInterface>> The classname of the token this provider is responsible for
4141
*/
4242
public function getTokenClassNames();
4343

Neos.Flow/Classes/Security/Authentication/AuthenticationProviderManager.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
5151
* Injected configuration for providers.
5252
* Will be null'd again after building the object instances.
5353
*
54-
* @var array|null
54+
* @var array<mixed>|null
5555
*/
5656
protected $providerConfigurations;
5757

@@ -81,7 +81,7 @@ public function __construct(TokenAndProviderFactoryInterface $tokenAndProviderFa
8181
/**
8282
* Inject the settings and does a fresh build of tokens based on the injected settings
8383
*
84-
* @param array $settings The settings
84+
* @param array<string,mixed> $settings The settings
8585
* @return void
8686
* @throws Exception
8787
*/
@@ -206,7 +206,10 @@ public function isAuthenticated(): bool
206206
} catch (AuthenticationRequiredException $exception) {
207207
}
208208
}
209-
return $this->isAuthenticated;
209+
210+
return $this->isAuthenticated !== null
211+
? $this->isAuthenticated
212+
: false;
210213
}
211214

212215
/**

Neos.Flow/Classes/Security/Authentication/AuthenticationProviderResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public function __construct(ObjectManagerInterface $objectManager)
4747
public function resolveProviderClass($providerName)
4848
{
4949
$className = $this->objectManager->getClassNameByObjectName($providerName);
50-
if ($className !== false) {
50+
if ($className !== false && is_subclass_of($className, AuthenticationProviderInterface::class)) {
5151
return $className;
5252
}
5353

5454
$className = $this->objectManager->getClassNameByObjectName('Neos\Flow\Security\Authentication\Provider\\' . $providerName);
55-
if ($className !== false) {
55+
if ($className !== false && is_subclass_of($className, AuthenticationProviderInterface::class)) {
5656
return $className;
5757
}
5858

Neos.Flow/Classes/Security/Authentication/Controller/AbstractAuthenticationController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ public function authenticateAction()
8585

8686
if (!$this->authenticationManager->isAuthenticated()) {
8787
$this->onAuthenticationFailure($authenticationException);
88-
return call_user_func([$this, $this->errorMethodName]);
88+
$callable = [$this, $this->errorMethodName];
89+
if (!is_callable($callable)) {
90+
throw new \Exception('Invalid error method ' . $this->errorMethodName, 1743955562);
91+
}
92+
return call_user_func($callable);
8993
}
9094

9195
$storedRequest = $this->securityContext->getInterceptedRequest();

Neos.Flow/Classes/Security/Authentication/EntryPoint/AbstractEntryPoint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ abstract class AbstractEntryPoint implements EntryPointInterface
2121
/**
2222
* The configurations options
2323
*
24-
* @var array
24+
* @var array<mixed>
2525
*/
2626
protected $options = [];
2727

2828
/**
2929
* Sets the options array
3030
*
31-
* @param array $options An array of configuration options
31+
* @param array<mixed> $options An array of configuration options
3232
* @return void
3333
*/
3434
public function setOptions(array $options)
@@ -39,7 +39,7 @@ public function setOptions(array $options)
3939
/**
4040
* Returns the options array
4141
*
42-
* @return array The configuration options of this entry point
42+
* @return array<mixed> The configuration options of this entry point
4343
*/
4444
public function getOptions()
4545
{

Neos.Flow/Classes/Security/Authentication/EntryPoint/WebRedirect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function startAuthentication(ServerRequestInterface $request, ResponseInt
7575
}
7676

7777
/**
78-
* @param array $routeValues
78+
* @param array<string,mixed> $routeValues
7979
* @param ServerRequestInterface $request
8080
* @return string
8181
* @throws \Neos\Flow\Mvc\Routing\Exception\MissingActionNameException
@@ -96,7 +96,7 @@ protected function generateUriFromRouteValues(array $routeValues, ServerRequestI
9696
* Returns the entry $key from the array $routeValues removing the original array item.
9797
* If $key does not exist, NULL is returned.
9898
*
99-
* @param array $routeValues
99+
* @param array<string,mixed> $routeValues
100100
* @param string $key
101101
* @return mixed the specified route value or NULL if it is not set
102102
*/

0 commit comments

Comments
 (0)