summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Acl/.gitignore3
-rw-r--r--Acl/Dbal/AclProvider.php30
-rw-r--r--Acl/Dbal/MutableAclProvider.php75
-rw-r--r--Acl/Domain/Acl.php16
-rw-r--r--Acl/LICENSE19
-rw-r--r--Acl/Permission/MaskBuilder.php54
-rw-r--r--Acl/README.md23
-rw-r--r--Acl/Tests/Dbal/AclProviderBenchmarkTest.php (renamed from Tests/Acl/Dbal/AclProviderBenchmarkTest.php)2
-rw-r--r--Acl/Tests/Dbal/AclProviderTest.php (renamed from Tests/Acl/Dbal/AclProviderTest.php)2
-rw-r--r--Acl/Tests/Dbal/MutableAclProviderTest.php (renamed from Tests/Acl/Dbal/MutableAclProviderTest.php)32
-rw-r--r--Acl/Tests/Domain/AclTest.php (renamed from Tests/Acl/Domain/AclTest.php)2
-rw-r--r--Acl/Tests/Domain/AuditLoggerTest.php (renamed from Tests/Acl/Domain/AuditLoggerTest.php)6
-rw-r--r--Acl/Tests/Domain/DoctrineAclCacheTest.php (renamed from Tests/Acl/Domain/DoctrineAclCacheTest.php)2
-rw-r--r--Acl/Tests/Domain/EntryTest.php (renamed from Tests/Acl/Domain/EntryTest.php)2
-rw-r--r--Acl/Tests/Domain/FieldEntryTest.php (renamed from Tests/Acl/Domain/FieldEntryTest.php)2
-rw-r--r--Acl/Tests/Domain/ObjectIdentityRetrievalStrategyTest.php (renamed from Tests/Acl/Domain/ObjectIdentityRetrievalStrategyTest.php)2
-rw-r--r--Acl/Tests/Domain/ObjectIdentityTest.php (renamed from Tests/Acl/Domain/ObjectIdentityTest.php)16
-rw-r--r--Acl/Tests/Domain/PermissionGrantingStrategyTest.php (renamed from Tests/Acl/Domain/PermissionGrantingStrategyTest.php)2
-rw-r--r--Acl/Tests/Domain/RoleSecurityIdentityTest.php (renamed from Tests/Acl/Domain/RoleSecurityIdentityTest.php)2
-rw-r--r--Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php (renamed from Tests/Acl/Domain/SecurityIdentityRetrievalStrategyTest.php)4
-rw-r--r--Acl/Tests/Domain/UserSecurityIdentityTest.php (renamed from Tests/Acl/Domain/UserSecurityIdentityTest.php)6
-rw-r--r--Acl/Tests/Permission/BasicPermissionMapTest.php (renamed from Tests/Acl/Permission/BasicPermissionMapTest.php)2
-rw-r--r--Acl/Tests/Permission/MaskBuilderTest.php (renamed from Tests/Acl/Permission/MaskBuilderTest.php)2
-rw-r--r--Acl/Tests/Voter/AclVoterTest.php (renamed from Tests/Acl/Voter/AclVoterTest.php)2
-rw-r--r--Acl/composer.json43
-rw-r--r--Acl/phpunit.xml.dist32
-rw-r--r--CHANGELOG.md16
-rw-r--r--Core/.gitignore3
-rw-r--r--Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php32
-rw-r--r--Core/Authentication/Provider/SimpleAuthenticationProvider.php50
-rw-r--r--Core/Authentication/Provider/UserAuthenticationProvider.php4
-rw-r--r--Core/Authentication/SimpleAuthenticatorInterface.php25
-rw-r--r--Core/Authentication/SimpleFormAuthenticatorInterface.php22
-rw-r--r--Core/Authentication/SimplePreAuthenticatorInterface.php22
-rw-r--r--Core/Authentication/Token/AbstractToken.php12
-rw-r--r--Core/Authentication/Token/Storage/TokenStorage.php43
-rw-r--r--Core/Authentication/Token/Storage/TokenStorageInterface.php36
-rw-r--r--Core/Authorization/AccessDecisionManager.php13
-rw-r--r--Core/Authorization/AuthorizationChecker.php70
-rw-r--r--Core/Authorization/AuthorizationCheckerInterface.php30
-rw-r--r--Core/Authorization/ExpressionLanguage.php33
-rw-r--r--Core/Authorization/ExpressionLanguageProvider.php58
-rw-r--r--Core/Authorization/Voter/AbstractVoter.php113
-rw-r--r--Core/Authorization/Voter/ExpressionVoter.php118
-rw-r--r--Core/Encoder/EncoderAwareInterface.php28
-rw-r--r--Core/Encoder/EncoderFactory.php27
-rw-r--r--Core/Encoder/UserPasswordEncoder.php55
-rw-r--r--Core/Encoder/UserPasswordEncoderInterface.php41
-rw-r--r--Core/Exception/ExceptionInterface.php21
-rw-r--r--Core/Exception/InvalidArgumentException.php21
-rw-r--r--Core/Exception/RuntimeException.php21
-rw-r--r--Core/Exception/UsernameNotFoundException.php8
-rw-r--r--Core/LICENSE19
-rw-r--r--Core/README.md23
-rw-r--r--Core/Resources/translations/security.ar.xlf71
-rw-r--r--Core/Resources/translations/security.ca.xlf71
-rw-r--r--Core/Resources/translations/security.cs.xlf71
-rw-r--r--Core/Resources/translations/security.da.xlf71
-rw-r--r--Core/Resources/translations/security.de.xlf71
-rw-r--r--Core/Resources/translations/security.el.xlf71
-rw-r--r--Core/Resources/translations/security.en.xlf71
-rw-r--r--Core/Resources/translations/security.es.xlf71
-rw-r--r--Core/Resources/translations/security.fa.xlf71
-rw-r--r--Core/Resources/translations/security.fr.xlf71
-rw-r--r--Core/Resources/translations/security.gl.xlf71
-rw-r--r--Core/Resources/translations/security.hu.xlf71
-rw-r--r--Core/Resources/translations/security.it.xlf71
-rw-r--r--Core/Resources/translations/security.lb.xlf71
-rw-r--r--Core/Resources/translations/security.nl.xlf71
-rw-r--r--Core/Resources/translations/security.no.xlf71
-rw-r--r--Core/Resources/translations/security.pl.xlf71
-rw-r--r--Core/Resources/translations/security.pt_BR.xlf71
-rw-r--r--Core/Resources/translations/security.pt_PT.xlf71
-rw-r--r--Core/Resources/translations/security.ro.xlf71
-rw-r--r--Core/Resources/translations/security.ru.xlf71
-rw-r--r--Core/Resources/translations/security.sk.xlf71
-rw-r--r--Core/Resources/translations/security.sl.xlf71
-rw-r--r--Core/Resources/translations/security.sr_Cyrl.xlf71
-rw-r--r--Core/Resources/translations/security.sr_Latn.xlf71
-rw-r--r--Core/Resources/translations/security.sv.xlf71
-rw-r--r--Core/Resources/translations/security.tr.xlf71
-rw-r--r--Core/Resources/translations/security.ua.xlf71
-rw-r--r--Core/Role/RoleHierarchy.php4
-rw-r--r--Core/Security.php24
-rw-r--r--Core/SecurityContext.php70
-rw-r--r--Core/SecurityContextInterface.php36
-rw-r--r--Core/Tests/Authentication/AuthenticationProviderManagerTest.php (renamed from Tests/Core/Authentication/AuthenticationProviderManagerTest.php)4
-rw-r--r--Core/Tests/Authentication/AuthenticationTrustResolverTest.php (renamed from Tests/Core/Authentication/AuthenticationTrustResolverTest.php)2
-rw-r--r--Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php (renamed from Tests/Core/Authentication/Provider/AnonymousAuthenticationProviderTest.php)2
-rw-r--r--Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php (renamed from Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php)2
-rw-r--r--Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php (renamed from Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php)2
-rw-r--r--Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php (renamed from Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php)2
-rw-r--r--Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php (renamed from Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php)2
-rw-r--r--Core/Tests/Authentication/RememberMe/InMemoryTokenProviderTest.php (renamed from Tests/Core/Authentication/RememberMe/InMemoryTokenProviderTest.php)2
-rw-r--r--Core/Tests/Authentication/RememberMe/PersistentTokenTest.php (renamed from Tests/Core/Authentication/RememberMe/PersistentTokenTest.php)2
-rw-r--r--Core/Tests/Authentication/Token/AbstractTokenTest.php (renamed from Tests/Core/Authentication/Token/AbstractTokenTest.php)2
-rw-r--r--Core/Tests/Authentication/Token/AnonymousTokenTest.php (renamed from Tests/Core/Authentication/Token/AnonymousTokenTest.php)2
-rw-r--r--Core/Tests/Authentication/Token/PreAuthenticatedTokenTest.php (renamed from Tests/Core/Authentication/Token/PreAuthenticatedTokenTest.php)2
-rw-r--r--Core/Tests/Authentication/Token/RememberMeTokenTest.php (renamed from Tests/Core/Authentication/Token/RememberMeTokenTest.php)2
-rw-r--r--Core/Tests/Authentication/Token/Storage/TokenStorageTest.php26
-rw-r--r--Core/Tests/Authentication/Token/UsernamePasswordTokenTest.php (renamed from Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php)2
-rw-r--r--Core/Tests/Authorization/AccessDecisionManagerTest.php (renamed from Tests/Core/Authorization/AccessDecisionManagerTest.php)48
-rw-r--r--Core/Tests/Authorization/AuthorizationCheckerTest.php99
-rw-r--r--Core/Tests/Authorization/ExpressionLanguageTest.php79
-rw-r--r--Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php (renamed from Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php)2
-rw-r--r--Core/Tests/Authorization/Voter/ExpressionVoterTest.php97
-rw-r--r--Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php (renamed from Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php)2
-rw-r--r--Core/Tests/Authorization/Voter/RoleVoterTest.php (renamed from Tests/Core/Authorization/Voter/RoleVoterTest.php)2
-rw-r--r--Core/Tests/Encoder/BCryptPasswordEncoderTest.php (renamed from Tests/Core/Encoder/BCryptPasswordEncoderTest.php)2
-rw-r--r--Core/Tests/Encoder/BasePasswordEncoderTest.php (renamed from Tests/Core/Encoder/BasePasswordEncoderTest.php)2
-rw-r--r--Core/Tests/Encoder/EncoderFactoryTest.php (renamed from Tests/Core/Encoder/EncoderFactoryTest.php)72
-rw-r--r--Core/Tests/Encoder/MessageDigestPasswordEncoderTest.php (renamed from Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php)2
-rw-r--r--Core/Tests/Encoder/Pbkdf2PasswordEncoderTest.php (renamed from Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php)2
-rw-r--r--Core/Tests/Encoder/PlaintextPasswordEncoderTest.php (renamed from Tests/Core/Encoder/PlaintextPasswordEncoderTest.php)2
-rw-r--r--Core/Tests/Encoder/UserPasswordEncoderTest.php70
-rw-r--r--Core/Tests/Exception/UsernameNotFoundExceptionTest.php25
-rw-r--r--Core/Tests/Role/RoleHierarchyTest.php (renamed from Tests/Core/Role/RoleHierarchyTest.php)2
-rw-r--r--Core/Tests/Role/RoleTest.php (renamed from Tests/Core/Role/RoleTest.php)2
-rw-r--r--Core/Tests/Role/SwitchUserRoleTest.php (renamed from Tests/Core/Role/SwitchUserRoleTest.php)2
-rw-r--r--Core/Tests/SecurityContextTest.php119
-rw-r--r--Core/Tests/User/ChainUserProviderTest.php (renamed from Tests/Core/User/ChainUserProviderTest.php)2
-rw-r--r--Core/Tests/User/InMemoryUserProviderTest.php (renamed from Tests/Core/User/InMemoryUserProviderTest.php)2
-rw-r--r--Core/Tests/User/UserCheckerTest.php (renamed from Tests/Core/User/UserCheckerTest.php)2
-rw-r--r--Core/Tests/User/UserTest.php (renamed from Tests/Core/User/UserTest.php)2
-rw-r--r--Core/Tests/Util/ClassUtilsTest.php (renamed from Tests/Core/Util/ClassUtilsTest.php)12
-rw-r--r--Core/Tests/Util/SecureRandomTest.php (renamed from Tests/Core/Util/SecureRandomTest.php)2
-rw-r--r--Core/Tests/Util/StringUtilsTest.php (renamed from Tests/Core/Util/StringUtilsTest.php)2
-rw-r--r--Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php26
-rw-r--r--Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php26
-rw-r--r--Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php169
-rw-r--r--Core/Validator/Constraints/UserPassword.php2
-rw-r--r--Core/Validator/Constraints/UserPasswordValidator.php5
-rw-r--r--Core/composer.json48
-rw-r--r--Core/phpunit.xml.dist32
-rw-r--r--Csrf/.gitignore3
-rw-r--r--Csrf/CsrfToken.php72
-rw-r--r--Csrf/CsrfTokenManager.php97
-rw-r--r--Csrf/CsrfTokenManagerInterface.php68
-rw-r--r--Csrf/Exception/TokenNotFoundException.php21
-rw-r--r--Csrf/LICENSE19
-rw-r--r--Csrf/README.md21
-rw-r--r--Csrf/Tests/CsrfTokenManagerTest.php164
-rw-r--r--Csrf/Tests/TokenGenerator/UriSafeTokenGeneratorTest.php70
-rw-r--r--Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php127
-rw-r--r--Csrf/Tests/TokenStorage/SessionTokenStorageTest.php262
-rw-r--r--Csrf/TokenGenerator/TokenGeneratorInterface.php28
-rw-r--r--Csrf/TokenGenerator/UriSafeTokenGenerator.php65
-rw-r--r--Csrf/TokenStorage/NativeSessionTokenStorage.php121
-rw-r--r--Csrf/TokenStorage/SessionTokenStorage.php106
-rw-r--r--Csrf/TokenStorage/TokenStorageInterface.php59
-rw-r--r--Csrf/composer.json39
-rw-r--r--Csrf/phpunit.xml.dist32
-rw-r--r--Http/.gitignore3
-rw-r--r--Http/AccessMap.php6
-rw-r--r--Http/Authentication/AuthenticationUtils.php87
-rw-r--r--Http/Authentication/CustomAuthenticationFailureHandler.php45
-rw-r--r--Http/Authentication/CustomAuthenticationSuccessHandler.php49
-rw-r--r--Http/Authentication/DefaultAuthenticationFailureHandler.php40
-rw-r--r--Http/Authentication/DefaultAuthenticationSuccessHandler.php38
-rw-r--r--Http/Authentication/SimpleAuthenticationHandler.php106
-rw-r--r--Http/Firewall.php28
-rw-r--r--Http/Firewall/AbstractAuthenticationListener.php13
-rw-r--r--Http/Firewall/AnonymousAuthenticationListener.php23
-rw-r--r--Http/Firewall/ContextListener.php7
-rw-r--r--Http/Firewall/DigestAuthenticationListener.php3
-rw-r--r--Http/Firewall/ExceptionListener.php17
-rw-r--r--Http/Firewall/LogoutListener.php30
-rw-r--r--Http/Firewall/RememberMeListener.php9
-rw-r--r--Http/Firewall/RemoteUserAuthenticationListener.php49
-rw-r--r--Http/Firewall/SimpleFormAuthenticationListener.php124
-rw-r--r--Http/Firewall/SimplePreAuthenticationListener.php115
-rw-r--r--Http/Firewall/SwitchUserListener.php4
-rw-r--r--Http/Firewall/UsernamePasswordFormAuthenticationListener.php23
-rw-r--r--Http/HttpUtils.php16
-rw-r--r--Http/LICENSE19
-rw-r--r--Http/README.md23
-rw-r--r--Http/RememberMe/ResponseListener.php3
-rw-r--r--Http/RememberMe/TokenBasedRememberMeServices.php30
-rw-r--r--Http/Tests/AccessMapTest.php (renamed from Tests/Http/AccessMapTest.php)2
-rw-r--r--Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php (renamed from Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php)10
-rw-r--r--Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php (renamed from Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php)2
-rw-r--r--Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php194
-rw-r--r--Http/Tests/EntryPoint/BasicAuthenticationEntryPointTest.php (renamed from Tests/Http/EntryPoint/BasicAuthenticationEntryPointTest.php)2
-rw-r--r--Http/Tests/EntryPoint/DigestAuthenticationEntryPointTest.php (renamed from Tests/Http/EntryPoint/DigestAuthenticationEntryPointTest.php)2
-rw-r--r--Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php (renamed from Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php)2
-rw-r--r--Http/Tests/EntryPoint/RetryAuthenticationEntryPointTest.php (renamed from Tests/Http/EntryPoint/RetryAuthenticationEntryPointTest.php)2
-rw-r--r--Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php (renamed from Tests/Http/Firewall/AbstractPreAuthenticatedListenerTest.php)2
-rw-r--r--Http/Tests/Firewall/AccessListenerTest.php (renamed from Tests/Http/Firewall/AccessListenerTest.php)2
-rw-r--r--Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php (renamed from Tests/Http/Firewall/AnonymousAuthenticationListenerTest.php)36
-rw-r--r--Http/Tests/Firewall/BasicAuthenticationListenerTest.php (renamed from Tests/Http/Firewall/BasicAuthenticationListenerTest.php)2
-rw-r--r--Http/Tests/Firewall/ChannelListenerTest.php (renamed from Tests/Http/Firewall/ChannelListenerTest.php)2
-rw-r--r--Http/Tests/Firewall/ContextListenerTest.php (renamed from Tests/Http/Firewall/ContextListenerTest.php)15
-rw-r--r--Http/Tests/Firewall/DigestDataTest.php (renamed from Tests/Http/Firewall/DigestDataTest.php)2
-rw-r--r--Http/Tests/Firewall/ExceptionListenerTest.php (renamed from Tests/Http/Firewall/ExceptionListenerTest.php)9
-rw-r--r--Http/Tests/Firewall/LogoutListenerTest.php (renamed from Tests/Http/Firewall/LogoutListenerTest.php)32
-rw-r--r--Http/Tests/Firewall/RememberMeListenerTest.php (renamed from Tests/Http/Firewall/RememberMeListenerTest.php)113
-rw-r--r--Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php91
-rw-r--r--Http/Tests/Firewall/SwitchUserListenerTest.php (renamed from Tests/Http/Firewall/SwitchUserListenerTest.php)41
-rw-r--r--Http/Tests/Firewall/X509AuthenticationListenerTest.php (renamed from Tests/Http/Firewall/X509AuthenticationListenerTest.php)2
-rw-r--r--Http/Tests/FirewallMapTest.php (renamed from Tests/Http/FirewallMapTest.php)2
-rw-r--r--Http/Tests/FirewallTest.php (renamed from Tests/Http/FirewallTest.php)2
-rw-r--r--Http/Tests/HttpUtilsTest.php (renamed from Tests/Http/HttpUtilsTest.php)10
-rw-r--r--Http/Tests/Logout/CookieClearingLogoutHandlerTest.php (renamed from Tests/Http/Logout/CookieClearingLogoutHandlerTest.php)2
-rw-r--r--Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php (renamed from Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php)2
-rw-r--r--Http/Tests/Logout/SessionLogoutHandlerTest.php (renamed from Tests/Http/Logout/SessionLogoutHandlerTest.php)2
-rw-r--r--Http/Tests/RememberMe/AbstractRememberMeServicesTest.php (renamed from Tests/Http/RememberMe/AbstractRememberMeServicesTest.php)2
-rw-r--r--Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php (renamed from Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php)2
-rw-r--r--Http/Tests/RememberMe/ResponseListenerTest.php (renamed from Tests/Http/RememberMe/ResponseListenerTest.php)4
-rw-r--r--Http/Tests/RememberMe/TokenBasedRememberMeServicesTest.php (renamed from Tests/Http/RememberMe/TokenBasedRememberMeServicesTest.php)2
-rw-r--r--Http/Tests/Session/SessionAuthenticationStrategyTest.php (renamed from Tests/Http/Session/SessionAuthenticationStrategyTest.php)2
-rw-r--r--Http/composer.json45
-rw-r--r--Http/phpunit.xml.dist32
-rw-r--r--README.md6
-rw-r--r--Tests/Core/Authentication/Voter/AbstractVoterTest.php90
-rw-r--r--Tests/Core/LegacySecurityContextInterfaceTest.php30
-rw-r--r--Tests/Core/SecurityContextTest.php92
-rw-r--r--Tests/Core/Validator/Constraints/UserPasswordValidatorTest.php157
-rw-r--r--composer.json31
-rw-r--r--phpunit.xml.dist8
219 files changed, 7168 insertions, 692 deletions
diff --git a/Acl/.gitignore b/Acl/.gitignore
new file mode 100644
index 0000000..c49a5d8
--- /dev/null
+++ b/Acl/.gitignore
@@ -0,0 +1,3 @@
+vendor/
+composer.lock
+phpunit.xml
diff --git a/Acl/Dbal/AclProvider.php b/Acl/Dbal/AclProvider.php
index 5074614..fd6f5ba 100644
--- a/Acl/Dbal/AclProvider.php
+++ b/Acl/Dbal/AclProvider.php
@@ -177,13 +177,13 @@ class AclProvider implements AclProviderInterface
if ($currentBatchesCount > 0 && (self::MAX_BATCH_SIZE === $currentBatchesCount || ($i + 1) === $c)) {
try {
$loadedBatch = $this->lookupObjectIdentities($currentBatch, $sids, $oidLookup);
- } catch (AclNotFoundException $aclNotFoundexception) {
+ } catch (AclNotFoundException $aclNotFoundException) {
if ($result->count()) {
$partialResultException = new NotAllAclsFoundException('The provider could not find ACLs for all object identities.');
$partialResultException->setPartialResult($result);
throw $partialResultException;
} else {
- throw $aclNotFoundexception;
+ throw $aclNotFoundException;
}
}
foreach ($loadedBatch as $loadedOid) {
@@ -206,7 +206,8 @@ class AclProvider implements AclProviderInterface
foreach ($oids as $oid) {
if (!$result->contains($oid)) {
if (1 === count($oids)) {
- throw new AclNotFoundException(sprintf('No ACL found for %s.', $oid));
+ $objectName = method_exists($oid, '__toString') ? $oid : get_class($oid);
+ throw new AclNotFoundException(sprintf('No ACL found for %s.', $objectName));
}
$partialResultException = new NotAllAclsFoundException('The provider could not find ACLs for all object identities.');
@@ -296,7 +297,8 @@ SELECTCLAUSE;
if (1 === count($types)) {
$ids = array();
for ($i = 0; $i < $count; $i++) {
- $ids[] = $this->connection->quote($batch[$i]->getIdentifier());
+ $identifier = (string) $batch[$i]->getIdentifier();
+ $ids[] = $this->connection->quote($identifier);
}
$sql .= sprintf(
@@ -339,17 +341,17 @@ SELECTCLAUSE;
$query = <<<FINDCHILDREN
SELECT o.object_identifier, c.class_type
FROM
- {$this->options['oid_table_name']} as o
- INNER JOIN {$this->options['class_table_name']} as c ON c.id = o.class_id
- INNER JOIN {$this->options['oid_ancestors_table_name']} as a ON a.object_identity_id = o.id
+ {$this->options['oid_table_name']} o
+ INNER JOIN {$this->options['class_table_name']} c ON c.id = o.class_id
+ INNER JOIN {$this->options['oid_ancestors_table_name']} a ON a.object_identity_id = o.id
WHERE
a.ancestor_id = %d AND a.object_identity_id != a.ancestor_id
FINDCHILDREN;
} else {
$query = <<<FINDCHILDREN
SELECT o.object_identifier, c.class_type
- FROM {$this->options['oid_table_name']} as o
- INNER JOIN {$this->options['class_table_name']} as c ON c.id = o.class_id
+ FROM {$this->options['oid_table_name']} o
+ INNER JOIN {$this->options['class_table_name']} c ON c.id = o.class_id
WHERE o.parent_object_identity_id = %d
FINDCHILDREN;
}
@@ -378,8 +380,8 @@ QUERY;
$query,
$this->options['oid_table_name'],
$this->options['class_table_name'],
- $this->connection->quote($oid->getIdentifier()),
- $this->connection->quote($oid->getType())
+ $this->connection->quote((string) $oid->getIdentifier()),
+ $this->connection->quote((string) $oid->getType())
);
}
@@ -435,8 +437,8 @@ QUERY;
$ancestorIds = array();
foreach ($this->connection->executeQuery($sql)->fetchAll() as $data) {
// FIXME: skip ancestors which are cached
-
- $ancestorIds[] = $data['ancestor_id'];
+ // Fix: Oracle returns keys in uppercase
+ $ancestorIds[] = reset($data);
}
return $ancestorIds;
@@ -542,7 +544,7 @@ QUERY;
$auditSuccess,
$auditFailure,
$username,
- $securityIdentifier) = $data;
+ $securityIdentifier) = array_values($data);
// has the ACL been hydrated during this hydration cycle?
if (isset($acls[$aclId])) {
diff --git a/Acl/Dbal/MutableAclProvider.php b/Acl/Dbal/MutableAclProvider.php
index a710bf7..023a22f 100644
--- a/Acl/Dbal/MutableAclProvider.php
+++ b/Acl/Dbal/MutableAclProvider.php
@@ -51,7 +51,8 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
public function createAcl(ObjectIdentityInterface $oid)
{
if (false !== $this->retrieveObjectIdentityPrimaryKey($oid)) {
- throw new AclAlreadyExistsException(sprintf('%s is already associated with an ACL.', $oid));
+ $objectName = method_exists($oid, '__toString') ? $oid : get_class($oid);
+ throw new AclAlreadyExistsException(sprintf('%s is already associated with an ACL.', $objectName));
}
$this->connection->beginTransaction();
@@ -109,6 +110,19 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
}
/**
+ * Deletes the security identity from the database.
+ * ACL entries have the CASCADE option on their foreign key so they will also get deleted
+ *
+ * @param SecurityIdentityInterface $sid
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function deleteSecurityIdentity(SecurityIdentityInterface $sid)
+ {
+ $this->connection->executeQuery($this->getDeleteSecurityIdentityIdSql($sid));
+ }
+
+ /**
* {@inheritdoc}
*/
public function findAcls(array $oids, array $sids = array())
@@ -253,7 +267,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
}
// check properties for deleted, and created ACEs, and perform deletions
- // we need to perfom deletions before updating existing ACEs, in order to
+ // we need to perform deletions before updating existing ACEs, in order to
// preserve uniqueness of the order field
if (isset($propertyChanges['classAces'])) {
$this->updateOldAceProperty('classAces', $propertyChanges['classAces']);
@@ -352,6 +366,17 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
}
/**
+ * Updates a user security identity when the user's username changes
+ *
+ * @param UserSecurityIdentity $usid
+ * @param string $oldUsername
+ */
+ public function updateUserSecurityIdentity(UserSecurityIdentity $usid, $oldUsername)
+ {
+ $this->connection->executeQuery($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
+ }
+
+ /**
* Constructs the SQL for deleting access control entries.
*
* @param int $oidPK
@@ -626,6 +651,23 @@ QUERY;
}
/**
+ * Constructs the SQL to delete a security identity.
+ *
+ * @param SecurityIdentityInterface $sid
+ *
+ * @throws \InvalidArgumentException
+ *
+ * @return string
+ */
+ protected function getDeleteSecurityIdentityIdSql(SecurityIdentityInterface $sid)
+ {
+ $select = $this->getSelectSecurityIdentityIdSql($sid);
+ $delete = preg_replace('/^SELECT id FROM/', 'DELETE FROM', $select);
+
+ return $delete;
+ }
+
+ /**
* Constructs the SQL for updating an object identity.
*
* @param int $pk
@@ -650,6 +692,32 @@ QUERY;
}
/**
+ * Constructs the SQL for updating a user security identity.
+ *
+ * @param UserSecurityIdentity $usid
+ * @param string $oldUsername
+ *
+ * @return string
+ */
+ protected function getUpdateUserSecurityIdentitySql(UserSecurityIdentity $usid, $oldUsername)
+ {
+ if ($usid->getUsername() == $oldUsername) {
+ throw new \InvalidArgumentException('There are no changes.');
+ }
+
+ $oldIdentifier = $usid->getClass().'-'.$oldUsername;
+ $newIdentifier = $usid->getClass().'-'.$usid->getUsername();
+
+ return sprintf(
+ 'UPDATE %s SET identifier = %s WHERE identifier = %s AND username = %s',
+ $this->options['sid_table_name'],
+ $this->connection->quote($newIdentifier),
+ $this->connection->quote($oldIdentifier),
+ $this->connection->getDatabasePlatform()->convertBooleans(true)
+ );
+ }
+
+ /**
* Constructs the SQL for updating an ACE.
*
* @param int $pk
@@ -785,7 +853,6 @@ QUERY;
{
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
- $currentIds = array();
foreach ($changes[1] as $field => $new) {
for ($i = 0, $c = count($new); $i<$c; $i++) {
$ace = $new[$i];
@@ -813,8 +880,6 @@ QUERY;
$aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id');
$aceIdProperty->setAccessible(true);
$aceIdProperty->setValue($ace, (int) $aceId);
- } else {
- $currentIds[$ace->getId()] = true;
}
}
}
diff --git a/Acl/Domain/Acl.php b/Acl/Domain/Acl.php
index 0366ccf..328f754 100644
--- a/Acl/Domain/Acl.php
+++ b/Acl/Domain/Acl.php
@@ -37,14 +37,14 @@ class Acl implements AuditableAclInterface, NotifyPropertyChanged
private $parentAcl;
private $permissionGrantingStrategy;
private $objectIdentity;
- private $classAces;
- private $classFieldAces;
- private $objectAces;
- private $objectFieldAces;
+ private $classAces = array();
+ private $classFieldAces = array();
+ private $objectAces = array();
+ private $objectFieldAces = array();
private $id;
private $loadedSids;
private $entriesInheriting;
- private $listeners;
+ private $listeners = array();
/**
* Constructor.
@@ -62,12 +62,6 @@ class Acl implements AuditableAclInterface, NotifyPropertyChanged
$this->permissionGrantingStrategy = $permissionGrantingStrategy;
$this->loadedSids = $loadedSids;
$this->entriesInheriting = $entriesInheriting;
- $this->parentAcl = null;
- $this->classAces = array();
- $this->classFieldAces = array();
- $this->objectAces = array();
- $this->objectFieldAces = array();
- $this->listeners = array();
}
/**
diff --git a/Acl/LICENSE b/Acl/LICENSE
new file mode 100644
index 0000000..43028bc
--- /dev/null
+++ b/Acl/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2004-2015 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/Acl/Permission/MaskBuilder.php b/Acl/Permission/MaskBuilder.php
index 39fe4e7..5364c9b 100644
--- a/Acl/Permission/MaskBuilder.php
+++ b/Acl/Permission/MaskBuilder.php
@@ -96,13 +96,7 @@ class MaskBuilder
*/
public function add($mask)
{
- if (is_string($mask) && defined($name = 'static::MASK_'.strtoupper($mask))) {
- $mask = constant($name);
- } elseif (!is_int($mask)) {
- throw new \InvalidArgumentException('$mask must be an integer.');
- }
-
- $this->mask |= $mask;
+ $this->mask |= $this->getMask($mask);
return $this;
}
@@ -152,13 +146,7 @@ class MaskBuilder
*/
public function remove($mask)
{
- if (is_string($mask) && defined($name = 'static::MASK_'.strtoupper($mask))) {
- $mask = constant($name);
- } elseif (!is_int($mask)) {
- throw new \InvalidArgumentException('$mask must be an integer.');
- }
-
- $this->mask &= ~$mask;
+ $this->mask &= ~$this->getMask($mask);
return $this;
}
@@ -193,19 +181,43 @@ class MaskBuilder
$reflection = new \ReflectionClass(get_called_class());
foreach ($reflection->getConstants() as $name => $cMask) {
- if (0 !== strpos($name, 'MASK_')) {
+ if (0 !== strpos($name, 'MASK_') || $mask !== $cMask) {
continue;
}
- if ($mask === $cMask) {
- if (!defined($cName = 'static::CODE_'.substr($name, 5))) {
- throw new \RuntimeException('There was no code defined for this mask.');
- }
-
- return constant($cName);
+ if (!defined($cName = 'static::CODE_'.substr($name, 5))) {
+ throw new \RuntimeException('There was no code defined for this mask.');
}
+
+ return constant($cName);
}
throw new \InvalidArgumentException(sprintf('The mask "%d" is not supported.', $mask));
}
+
+ /**
+ * Returns the mask for the passed code
+ *
+ * @param mixed $code
+ *
+ * @return int
+ *
+ * @throws \InvalidArgumentException
+ */
+ private function getMask($code)
+ {
+ if (is_string($code)) {
+ if (!defined($name = sprintf('static::MASK_%s', strtoupper($code)))) {
+ throw new \InvalidArgumentException(sprintf('The code "%s" is not supported', $code));
+ }
+
+ return constant($name);
+ }
+
+ if (!is_int($code)) {
+ throw new \InvalidArgumentException('$code must be an integer.');
+ }
+
+ return $code;
+ }
}
diff --git a/Acl/README.md b/Acl/README.md
new file mode 100644
index 0000000..bb2d4d7
--- /dev/null
+++ b/Acl/README.md
@@ -0,0 +1,23 @@
+Security Component - ACL (Access Control List)
+==============================================
+
+Security provides an infrastructure for sophisticated authorization systems,
+which makes it possible to easily separate the actual authorization logic from
+so called user providers that hold the users credentials. It is inspired by
+the Java Spring framework.
+
+Resources
+---------
+
+Documentation:
+
+http://symfony.com/doc/2.6/book/security.html
+
+Tests
+-----
+
+You can run the unit tests with the following command:
+
+ $ cd path/to/Symfony/Component/Security/Acl/
+ $ composer.phar install --dev
+ $ phpunit
diff --git a/Tests/Acl/Dbal/AclProviderBenchmarkTest.php b/Acl/Tests/Dbal/AclProviderBenchmarkTest.php
index 1a46d27..46a695a 100644
--- a/Tests/Acl/Dbal/AclProviderBenchmarkTest.php
+++ b/Acl/Tests/Dbal/AclProviderBenchmarkTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Dbal;
+namespace Symfony\Component\Security\Acl\Tests\Dbal;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
diff --git a/Tests/Acl/Dbal/AclProviderTest.php b/Acl/Tests/Dbal/AclProviderTest.php
index d701e22..717a258 100644
--- a/Tests/Acl/Dbal/AclProviderTest.php
+++ b/Acl/Tests/Dbal/AclProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Dbal;
+namespace Symfony\Component\Security\Acl\Tests\Dbal;
use Symfony\Component\Security\Acl\Dbal\AclProvider;
use Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy;
diff --git a/Tests/Acl/Dbal/MutableAclProviderTest.php b/Acl/Tests/Dbal/MutableAclProviderTest.php
index faa9261..5ec23d3 100644
--- a/Tests/Acl/Dbal/MutableAclProviderTest.php
+++ b/Acl/Tests/Dbal/MutableAclProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Dbal;
+namespace Symfony\Component\Security\Acl\Tests\Dbal;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Model\FieldEntryInterface;
@@ -410,6 +410,36 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
$provider->updateAcl($acl);
}
+ public function testUpdateUserSecurityIdentity()
+ {
+ $provider = $this->getProvider();
+ $acl = $provider->createAcl(new ObjectIdentity(1, 'Foo'));
+ $sid = new UserSecurityIdentity('johannes', 'FooClass');
+ $acl->setEntriesInheriting(!$acl->isEntriesInheriting());
+
+ $acl->insertObjectAce($sid, 1);
+ $acl->insertClassAce($sid, 5, 0, false);
+ $acl->insertObjectAce($sid, 2, 1, true);
+ $acl->insertClassFieldAce('field', $sid, 2, 0, true);
+ $provider->updateAcl($acl);
+
+ $newSid = new UserSecurityIdentity('mathieu', 'FooClass');
+ $provider->updateUserSecurityIdentity($newSid, 'johannes');
+
+ $reloadProvider = $this->getProvider();
+ $reloadedAcl = $reloadProvider->findAcl(new ObjectIdentity(1, 'Foo'));
+
+ $this->assertNotSame($acl, $reloadedAcl);
+ $this->assertSame($acl->isEntriesInheriting(), $reloadedAcl->isEntriesInheriting());
+
+ $aces = $acl->getObjectAces();
+ $reloadedAces = $reloadedAcl->getObjectAces();
+ $this->assertEquals(count($aces), count($reloadedAces));
+ foreach ($reloadedAces as $ace) {
+ $this->assertTrue($ace->getSecurityIdentity()->equals($newSid));
+ }
+ }
+
/**
* Imports acls.
*
diff --git a/Tests/Acl/Domain/AclTest.php b/Acl/Tests/Domain/AclTest.php
index 9be4a94..84b9ba9 100644
--- a/Tests/Acl/Domain/AclTest.php
+++ b/Acl/Tests/Domain/AclTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
diff --git a/Tests/Acl/Domain/AuditLoggerTest.php b/Acl/Tests/Domain/AuditLoggerTest.php
index c8522b4..15538d3 100644
--- a/Tests/Acl/Domain/AuditLoggerTest.php
+++ b/Acl/Tests/Domain/AuditLoggerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
class AuditLoggerTest extends \PHPUnit_Framework_TestCase
{
@@ -26,12 +26,12 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase
->expects($this->once())
->method('isAuditSuccess')
->will($this->returnValue($audit))
- ;
+ ;
$ace
->expects($this->never())
->method('isAuditFailure')
- ;
+ ;
} else {
$ace
->expects($this->never())
diff --git a/Tests/Acl/Domain/DoctrineAclCacheTest.php b/Acl/Tests/Domain/DoctrineAclCacheTest.php
index 93c87c1..128f2c8 100644
--- a/Tests/Acl/Domain/DoctrineAclCacheTest.php
+++ b/Acl/Tests/Domain/DoctrineAclCacheTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
diff --git a/Tests/Acl/Domain/EntryTest.php b/Acl/Tests/Domain/EntryTest.php
index 55c8f0a..6a2aac0 100644
--- a/Tests/Acl/Domain/EntryTest.php
+++ b/Acl/Tests/Domain/EntryTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\Entry;
diff --git a/Tests/Acl/Domain/FieldEntryTest.php b/Acl/Tests/Domain/FieldEntryTest.php
index 7f0cbc0..735e2e8 100644
--- a/Tests/Acl/Domain/FieldEntryTest.php
+++ b/Acl/Tests/Domain/FieldEntryTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\FieldEntry;
diff --git a/Tests/Acl/Domain/ObjectIdentityRetrievalStrategyTest.php b/Acl/Tests/Domain/ObjectIdentityRetrievalStrategyTest.php
index e89e1ef..59fc3bd 100644
--- a/Tests/Acl/Domain/ObjectIdentityRetrievalStrategyTest.php
+++ b/Acl/Tests/Domain/ObjectIdentityRetrievalStrategyTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\ObjectIdentityRetrievalStrategy;
diff --git a/Tests/Acl/Domain/ObjectIdentityTest.php b/Acl/Tests/Domain/ObjectIdentityTest.php
index 9281fd5..4eab7b2 100644
--- a/Tests/Acl/Domain/ObjectIdentityTest.php
+++ b/Acl/Tests/Domain/ObjectIdentityTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain
+namespace Symfony\Component\Security\Acl\Tests\Domain
{
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
@@ -26,10 +26,10 @@ namespace Symfony\Component\Security\Tests\Acl\Domain
// Test that constructor never changes passed type, even with proxies
public function testConstructorWithProxy()
{
- $id = new ObjectIdentity('fooid', 'Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject');
+ $id = new ObjectIdentity('fooid', 'Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Acl\Tests\Domain\TestDomainObject');
$this->assertEquals('fooid', $id->getIdentifier());
- $this->assertEquals('Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject', $id->getType());
+ $this->assertEquals('Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Acl\Tests\Domain\TestDomainObject', $id->getType());
}
public function testFromDomainObjectPrefersInterfaceOverGetId()
@@ -54,14 +54,14 @@ namespace Symfony\Component\Security\Tests\Acl\Domain
{
$id = ObjectIdentity::fromDomainObject(new TestDomainObject());
$this->assertEquals('getId()', $id->getIdentifier());
- $this->assertEquals('Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject', $id->getType());
+ $this->assertEquals('Symfony\Component\Security\Acl\Tests\Domain\TestDomainObject', $id->getType());
}
public function testFromDomainObjectWithProxy()
{
- $id = ObjectIdentity::fromDomainObject(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject());
+ $id = ObjectIdentity::fromDomainObject(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Acl\Tests\Domain\TestDomainObject());
$this->assertEquals('getId()', $id->getIdentifier());
- $this->assertEquals('Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject', $id->getType());
+ $this->assertEquals('Symfony\Component\Security\Acl\Tests\Domain\TestDomainObject', $id->getType());
}
/**
@@ -101,9 +101,9 @@ namespace Symfony\Component\Security\Tests\Acl\Domain
}
}
-namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain
+namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Acl\Tests\Domain
{
- class TestDomainObject extends \Symfony\Component\Security\Tests\Acl\Domain\TestDomainObject
+ class TestDomainObject extends \Symfony\Component\Security\Acl\Tests\Domain\TestDomainObject
{
}
}
diff --git a/Tests/Acl/Domain/PermissionGrantingStrategyTest.php b/Acl/Tests/Domain/PermissionGrantingStrategyTest.php
index 4935bff..c7675ea 100644
--- a/Tests/Acl/Domain/PermissionGrantingStrategyTest.php
+++ b/Acl/Tests/Domain/PermissionGrantingStrategyTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
diff --git a/Tests/Acl/Domain/RoleSecurityIdentityTest.php b/Acl/Tests/Domain/RoleSecurityIdentityTest.php
index 341f33c..ad5f236 100644
--- a/Tests/Acl/Domain/RoleSecurityIdentityTest.php
+++ b/Acl/Tests/Domain/RoleSecurityIdentityTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Acl/Domain/SecurityIdentityRetrievalStrategyTest.php b/Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php
index e5fb4ed..160c27c 100644
--- a/Tests/Acl/Domain/SecurityIdentityRetrievalStrategyTest.php
+++ b/Acl/Tests/Domain/SecurityIdentityRetrievalStrategyTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
@@ -88,7 +88,7 @@ class SecurityIdentityRetrievalStrategyTest extends \PHPUnit_Framework_TestCase
new RoleSecurityIdentity('IS_AUTHENTICATED_ANONYMOUSLY'),
)),
array(new CustomUserImpl('johannes'), array('ROLE_FOO'), 'fullFledged', array(
- new UserSecurityIdentity('johannes', 'Symfony\Component\Security\Tests\Acl\Domain\CustomUserImpl'),
+ new UserSecurityIdentity('johannes', 'Symfony\Component\Security\Acl\Tests\Domain\CustomUserImpl'),
new RoleSecurityIdentity('ROLE_FOO'),
new RoleSecurityIdentity('IS_AUTHENTICATED_FULLY'),
new RoleSecurityIdentity('IS_AUTHENTICATED_REMEMBERED'),
diff --git a/Tests/Acl/Domain/UserSecurityIdentityTest.php b/Acl/Tests/Domain/UserSecurityIdentityTest.php
index 1d6a3c5..09d3f0d 100644
--- a/Tests/Acl/Domain/UserSecurityIdentityTest.php
+++ b/Acl/Tests/Domain/UserSecurityIdentityTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Domain;
+namespace Symfony\Component\Security\Acl\Tests\Domain;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
@@ -27,10 +27,10 @@ class UserSecurityIdentityTest extends \PHPUnit_Framework_TestCase
// Test that constructor never changes the type, even for proxies
public function testConstructorWithProxy()
{
- $id = new UserSecurityIdentity('foo', 'Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\Foo');
+ $id = new UserSecurityIdentity('foo', 'Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Acl\Tests\Domain\Foo');
$this->assertEquals('foo', $id->getUsername());
- $this->assertEquals('Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Acl\Domain\Foo', $id->getClass());
+ $this->assertEquals('Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Acl\Tests\Domain\Foo', $id->getClass());
}
/**
diff --git a/Tests/Acl/Permission/BasicPermissionMapTest.php b/Acl/Tests/Permission/BasicPermissionMapTest.php
index 743634b..2afe588 100644
--- a/Tests/Acl/Permission/BasicPermissionMapTest.php
+++ b/Acl/Tests/Permission/BasicPermissionMapTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Permission;
+namespace Symfony\Component\Security\Acl\Tests\Permission;
use Symfony\Component\Security\Acl\Permission\BasicPermissionMap;
diff --git a/Tests/Acl/Permission/MaskBuilderTest.php b/Acl/Tests/Permission/MaskBuilderTest.php
index de034e3..8245669 100644
--- a/Tests/Acl/Permission/MaskBuilderTest.php
+++ b/Acl/Tests/Permission/MaskBuilderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Permission;
+namespace Symfony\Component\Security\Acl\Tests\Permission;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
diff --git a/Tests/Acl/Voter/AclVoterTest.php b/Acl/Tests/Voter/AclVoterTest.php
index 8544b19..2148135 100644
--- a/Tests/Acl/Voter/AclVoterTest.php
+++ b/Acl/Tests/Voter/AclVoterTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Acl\Voter;
+namespace Symfony\Component\Security\Acl\Tests\Voter;
use Symfony\Component\Security\Acl\Exception\NoAceFoundException;
use Symfony\Component\Security\Acl\Voter\FieldVote;
diff --git a/Acl/composer.json b/Acl/composer.json
new file mode 100644
index 0000000..6925f15
--- /dev/null
+++ b/Acl/composer.json
@@ -0,0 +1,43 @@
+{
+ "name": "symfony/security-acl",
+ "type": "library",
+ "description": "Symfony Security Component - ACL (Access Control List)",
+ "keywords": [],
+ "homepage": "http://symfony.com",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3",
+ "symfony/security-core": "~2.4"
+ },
+ "require-dev": {
+ "symfony/phpunit-bridge": "~2.7",
+ "doctrine/common": "~2.2",
+ "doctrine/dbal": "~2.2",
+ "psr/log": "~1.0"
+ },
+ "suggest": {
+ "symfony/class-loader": "For using the ACL generateSql script",
+ "symfony/finder": "For using the ACL generateSql script",
+ "doctrine/dbal": "For using the built-in ACL implementation"
+ },
+ "autoload": {
+ "psr-0": { "Symfony\\Component\\Security\\Acl\\": "" }
+ },
+ "target-dir": "Symfony/Component/Security/Acl",
+ "minimum-stability": "dev",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev"
+ }
+ }
+}
diff --git a/Acl/phpunit.xml.dist b/Acl/phpunit.xml.dist
new file mode 100644
index 0000000..ee662c8
--- /dev/null
+++ b/Acl/phpunit.xml.dist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="vendor/autoload.php"
+>
+ <php>
+ <ini name="error_reporting" value="-1" />
+ </php>
+ <testsuites>
+ <testsuite name="Symfony Security Component ACL Test Suite">
+ <directory>./Tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./vendor</directory>
+ <directory>./Tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92f8073..c08d5cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,22 @@
CHANGELOG
=========
+2.6.0
+-----
+
+ * added Symfony\Component\Security\Http\Authentication\AuthenticationUtils
+ * Deprecated the `SecurityContext` class in favor of the `AuthorizationChecker` and `TokenStorage` classes
+
+2.4.0
+-----
+
+ * The switch user listener now preserves the query string when switching a user
+ * The remember-me cookie hashes now use HMAC, which means that current cookies will be invalidated
+ * added simpler customization options
+ * structured component into three sub-components Acl, Core and Http
+ * added Csrf sub-component
+ * changed Http sub-component to depend on Csrf sub-component instead of the Form component
+
2.3.0
-----
diff --git a/Core/.gitignore b/Core/.gitignore
new file mode 100644
index 0000000..c49a5d8
--- /dev/null
+++ b/Core/.gitignore
@@ -0,0 +1,3 @@
+vendor/
+composer.lock
+phpunit.xml
diff --git a/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php b/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php
index 87b7114..c17a954 100644
--- a/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php
+++ b/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php
@@ -47,28 +47,28 @@ class PreAuthenticatedAuthenticationProvider implements AuthenticationProviderIn
$this->providerKey = $providerKey;
}
- /**
- * {@inheritdoc}
- */
- public function authenticate(TokenInterface $token)
- {
- if (!$this->supports($token)) {
- return;
- }
+ /**
+ * {@inheritdoc}
+ */
+ public function authenticate(TokenInterface $token)
+ {
+ if (!$this->supports($token)) {
+ return;
+ }
- if (!$user = $token->getUser()) {
- throw new BadCredentialsException('No pre-authenticated principal found in request.');
- }
+ if (!$user = $token->getUser()) {
+ throw new BadCredentialsException('No pre-authenticated principal found in request.');
+ }
$user = $this->userProvider->loadUserByUsername($user);
- $this->userChecker->checkPostAuth($user);
+ $this->userChecker->checkPostAuth($user);
- $authenticatedToken = new PreAuthenticatedToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
- $authenticatedToken->setAttributes($token->getAttributes());
+ $authenticatedToken = new PreAuthenticatedToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
+ $authenticatedToken->setAttributes($token->getAttributes());
- return $authenticatedToken;
- }
+ return $authenticatedToken;
+ }
/**
* {@inheritdoc}
diff --git a/Core/Authentication/Provider/SimpleAuthenticationProvider.php b/Core/Authentication/Provider/SimpleAuthenticationProvider.php
new file mode 100644
index 0000000..ffbc72c
--- /dev/null
+++ b/Core/Authentication/Provider/SimpleAuthenticationProvider.php
@@ -0,0 +1,50 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authentication\Provider;
+
+use Symfony\Component\Security\Core\User\UserProviderInterface;
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class SimpleAuthenticationProvider implements AuthenticationProviderInterface
+{
+ private $simpleAuthenticator;
+ private $userProvider;
+ private $providerKey;
+
+ public function __construct(SimpleAuthenticatorInterface $simpleAuthenticator, UserProviderInterface $userProvider, $providerKey)
+ {
+ $this->simpleAuthenticator = $simpleAuthenticator;
+ $this->userProvider = $userProvider;
+ $this->providerKey = $providerKey;
+ }
+
+ public function authenticate(TokenInterface $token)
+ {
+ $authToken = $this->simpleAuthenticator->authenticateToken($token, $this->userProvider, $this->providerKey);
+
+ if ($authToken instanceof TokenInterface) {
+ return $authToken;
+ }
+
+ throw new AuthenticationException('Simple authenticator failed to return an authenticated token.');
+ }
+
+ public function supports(TokenInterface $token)
+ {
+ return $this->simpleAuthenticator->supportsToken($token, $this->providerKey);
+ }
+}
diff --git a/Core/Authentication/Provider/UserAuthenticationProvider.php b/Core/Authentication/Provider/UserAuthenticationProvider.php
index b948135..55ebed4 100644
--- a/Core/Authentication/Provider/UserAuthenticationProvider.php
+++ b/Core/Authentication/Provider/UserAuthenticationProvider.php
@@ -70,7 +70,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
$user = $this->retrieveUser($username, $token);
} catch (UsernameNotFoundException $notFound) {
if ($this->hideUserNotFoundExceptions) {
- throw new BadCredentialsException('Bad credentials', 0, $notFound);
+ throw new BadCredentialsException('Bad credentials.', 0, $notFound);
}
$notFound->setUsername($username);
@@ -87,7 +87,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
$this->userChecker->checkPostAuth($user);
} catch (BadCredentialsException $e) {
if ($this->hideUserNotFoundExceptions) {
- throw new BadCredentialsException('Bad credentials', 0, $e);
+ throw new BadCredentialsException('Bad credentials.', 0, $e);
}
throw $e;
diff --git a/Core/Authentication/SimpleAuthenticatorInterface.php b/Core/Authentication/SimpleAuthenticatorInterface.php
new file mode 100644
index 0000000..868d072
--- /dev/null
+++ b/Core/Authentication/SimpleAuthenticatorInterface.php
@@ -0,0 +1,25 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authentication;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\User\UserProviderInterface;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+interface SimpleAuthenticatorInterface
+{
+ public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey);
+
+ public function supportsToken(TokenInterface $token, $providerKey);
+}
diff --git a/Core/Authentication/SimpleFormAuthenticatorInterface.php b/Core/Authentication/SimpleFormAuthenticatorInterface.php
new file mode 100644
index 0000000..95ee881
--- /dev/null
+++ b/Core/Authentication/SimpleFormAuthenticatorInterface.php
@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authentication;
+
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+interface SimpleFormAuthenticatorInterface extends SimpleAuthenticatorInterface
+{
+ public function createToken(Request $request, $username, $password, $providerKey);
+}
diff --git a/Core/Authentication/SimplePreAuthenticatorInterface.php b/Core/Authentication/SimplePreAuthenticatorInterface.php
new file mode 100644
index 0000000..6164e7d
--- /dev/null
+++ b/Core/Authentication/SimplePreAuthenticatorInterface.php
@@ -0,0 +1,22 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authentication;
+
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+interface SimplePreAuthenticatorInterface extends SimpleAuthenticatorInterface
+{
+ public function createToken(Request $request, $providerKey);
+}
diff --git a/Core/Authentication/Token/AbstractToken.php b/Core/Authentication/Token/AbstractToken.php
index c239f8c..c6bf09f 100644
--- a/Core/Authentication/Token/AbstractToken.php
+++ b/Core/Authentication/Token/AbstractToken.php
@@ -26,9 +26,9 @@ use Symfony\Component\Security\Core\User\EquatableInterface;
abstract class AbstractToken implements TokenInterface
{
private $user;
- private $roles;
- private $authenticated;
- private $attributes;
+ private $roles = array();
+ private $authenticated = false;
+ private $attributes = array();
/**
* Constructor.
@@ -39,10 +39,6 @@ abstract class AbstractToken implements TokenInterface
*/
public function __construct(array $roles = array())
{
- $this->authenticated = false;
- $this->attributes = array();
-
- $this->roles = array();
foreach ($roles as $role) {
if (is_string($role)) {
$role = new Role($role);
@@ -219,7 +215,7 @@ abstract class AbstractToken implements TokenInterface
}
/**
- * Sets a attribute.
+ * Sets an attribute.
*
* @param string $name The attribute name
* @param mixed $value The attribute value
diff --git a/Core/Authentication/Token/Storage/TokenStorage.php b/Core/Authentication/Token/Storage/TokenStorage.php
new file mode 100644
index 0000000..4b6c11f
--- /dev/null
+++ b/Core/Authentication/Token/Storage/TokenStorage.php
@@ -0,0 +1,43 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authentication\Token\Storage;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+
+/**
+ * TokenStorage contains a TokenInterface
+ *
+ * It gives access to the token representing the current user authentication.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class TokenStorage implements TokenStorageInterface
+{
+ private $token;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getToken()
+ {
+ return $this->token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setToken(TokenInterface $token = null)
+ {
+ $this->token = $token;
+ }
+}
diff --git a/Core/Authentication/Token/Storage/TokenStorageInterface.php b/Core/Authentication/Token/Storage/TokenStorageInterface.php
new file mode 100644
index 0000000..218d750
--- /dev/null
+++ b/Core/Authentication/Token/Storage/TokenStorageInterface.php
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authentication\Token\Storage;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+
+/**
+ * The TokenStorageInterface.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+interface TokenStorageInterface
+{
+ /**
+ * Returns the current security token.
+ *
+ * @return TokenInterface|null A TokenInterface instance or null if no authentication information is available
+ */
+ public function getToken();
+
+ /**
+ * Sets the authentication token.
+ *
+ * @param TokenInterface $token A TokenInterface token, or null if no further authentication information should be stored
+ */
+ public function setToken(TokenInterface $token = null);
+}
diff --git a/Core/Authorization/AccessDecisionManager.php b/Core/Authorization/AccessDecisionManager.php
index 6e5effb..b8b6a77 100644
--- a/Core/Authorization/AccessDecisionManager.php
+++ b/Core/Authorization/AccessDecisionManager.php
@@ -22,6 +22,10 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
*/
class AccessDecisionManager implements AccessDecisionManagerInterface
{
+ const STRATEGY_AFFIRMATIVE = 'affirmative';
+ const STRATEGY_CONSENSUS = 'consensus';
+ const STRATEGY_UNANIMOUS = 'unanimous';
+
private $voters;
private $strategy;
private $allowIfAllAbstainDecisions;
@@ -37,14 +41,19 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
*
* @throws \InvalidArgumentException
*/
- public function __construct(array $voters, $strategy = 'affirmative', $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
+ public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
{
if (!$voters) {
throw new \InvalidArgumentException('You must at least add one voter.');
}
+ $strategyMethod = 'decide'.ucfirst($strategy);
+ if (!is_callable(array($this, $strategyMethod))) {
+ throw new \InvalidArgumentException(sprintf('The strategy "%s" is not supported.', $strategy));
+ }
+
$this->voters = $voters;
- $this->strategy = 'decide'.ucfirst($strategy);
+ $this->strategy = $strategyMethod;
$this->allowIfAllAbstainDecisions = (bool) $allowIfAllAbstainDecisions;
$this->allowIfEqualGrantedDeniedDecisions = (bool) $allowIfEqualGrantedDeniedDecisions;
}
diff --git a/Core/Authorization/AuthorizationChecker.php b/Core/Authorization/AuthorizationChecker.php
new file mode 100644
index 0000000..23c190c
--- /dev/null
+++ b/Core/Authorization/AuthorizationChecker.php
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authorization;
+
+use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
+
+/**
+ * AuthorizationChecker is the main authorization point of the Security component.
+ *
+ * It gives access to the token representing the current user authentication.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class AuthorizationChecker implements AuthorizationCheckerInterface
+{
+ private $tokenStorage;
+ private $accessDecisionManager;
+ private $authenticationManager;
+ private $alwaysAuthenticate;
+
+ /**
+ * Constructor.
+ *
+ * @param TokenStorageInterface $tokenStorage
+ * @param AuthenticationManagerInterface $authenticationManager An AuthenticationManager instance
+ * @param AccessDecisionManagerInterface $accessDecisionManager An AccessDecisionManager instance
+ * @param bool $alwaysAuthenticate
+ */
+ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, AccessDecisionManagerInterface $accessDecisionManager, $alwaysAuthenticate = false)
+ {
+ $this->tokenStorage = $tokenStorage;
+ $this->authenticationManager = $authenticationManager;
+ $this->accessDecisionManager = $accessDecisionManager;
+ $this->alwaysAuthenticate = $alwaysAuthenticate;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @throws AuthenticationCredentialsNotFoundException when the token storage has no authentication token.
+ */
+ final public function isGranted($attributes, $object = null)
+ {
+ if (null === ($token = $this->tokenStorage->getToken())) {
+ throw new AuthenticationCredentialsNotFoundException('The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.');
+ }
+
+ if ($this->alwaysAuthenticate || !$token->isAuthenticated()) {
+ $this->tokenStorage->setToken($token = $this->authenticationManager->authenticate($token));
+ }
+
+ if (!is_array($attributes)) {
+ $attributes = array($attributes);
+ }
+
+ return $this->accessDecisionManager->decide($token, $attributes, $object);
+ }
+}
diff --git a/Core/Authorization/AuthorizationCheckerInterface.php b/Core/Authorization/AuthorizationCheckerInterface.php
new file mode 100644
index 0000000..bd24d6f
--- /dev/null
+++ b/Core/Authorization/AuthorizationCheckerInterface.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authorization;
+
+/**
+ * The AuthorizationCheckerInterface.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+interface AuthorizationCheckerInterface
+{
+ /**
+ * Checks if the attributes are granted against the current authentication token and optionally supplied object.
+ *
+ * @param mixed $attributes
+ * @param mixed $object
+ *
+ * @return bool
+ */
+ public function isGranted($attributes, $object = null);
+}
diff --git a/Core/Authorization/ExpressionLanguage.php b/Core/Authorization/ExpressionLanguage.php
new file mode 100644
index 0000000..c2925af
--- /dev/null
+++ b/Core/Authorization/ExpressionLanguage.php
@@ -0,0 +1,33 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authorization;
+
+use Symfony\Component\ExpressionLanguage\ExpressionLanguage as BaseExpressionLanguage;
+use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface;
+
+/**
+ * Adds some function to the default ExpressionLanguage.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @see ExpressionLanguageProvider
+ */
+class ExpressionLanguage extends BaseExpressionLanguage
+{
+ public function __construct(ParserCacheInterface $cache = null, array $providers = array())
+ {
+ // prepend the default provider to let users override it easily
+ array_unshift($providers, new ExpressionLanguageProvider());
+
+ parent::__construct($cache, $providers);
+ }
+}
diff --git a/Core/Authorization/ExpressionLanguageProvider.php b/Core/Authorization/ExpressionLanguageProvider.php
new file mode 100644
index 0000000..9293ba7
--- /dev/null
+++ b/Core/Authorization/ExpressionLanguageProvider.php
@@ -0,0 +1,58 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authorization;
+
+use Symfony\Component\ExpressionLanguage\ExpressionFunction;
+use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
+
+/**
+ * Define some ExpressionLanguage functions.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
+{
+ public function getFunctions()
+ {
+ return array(
+ new ExpressionFunction('is_anonymous', function () {
+ return '$trust_resolver->isAnonymous($token)';
+ }, function (array $variables) {
+ return $variables['trust_resolver']->isAnonymous($variables['token']);
+ }),
+
+ new ExpressionFunction('is_authenticated', function () {
+ return '$token && !$trust_resolver->isAnonymous($token)';
+ }, function (array $variables) {
+ return $variables['token'] && !$variables['trust_resolver']->isAnonymous($variables['token']);
+ }),
+
+ new ExpressionFunction('is_fully_authenticated', function () {
+ return '$trust_resolver->isFullFledged($token)';
+ }, function (array $variables) {
+ return $variables['trust_resolver']->isFullFledged($variables['token']);
+ }),
+
+ new ExpressionFunction('is_remember_me', function () {
+ return '$trust_resolver->isRememberMe($token)';
+ }, function (array $variables) {
+ return $variables['trust_resolver']->isRememberMe($variables['token']);
+ }),
+
+ new ExpressionFunction('has_role', function ($role) {
+ return sprintf('in_array(%s, $roles)', $role);
+ }, function (array $variables, $role) {
+ return in_array($role, $variables['roles']);
+ }),
+ );
+ }
+}
diff --git a/Core/Authorization/Voter/AbstractVoter.php b/Core/Authorization/Voter/AbstractVoter.php
new file mode 100644
index 0000000..43ca558
--- /dev/null
+++ b/Core/Authorization/Voter/AbstractVoter.php
@@ -0,0 +1,113 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authorization\Voter;
+
+use Symfony\Component\Security\Core\User\UserInterface;
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+
+/**
+ * Abstract Voter implementation that reduces boilerplate code required to create a custom Voter
+ *
+ * @author Roman Marintšenko <inoryy@gmail.com>
+ */
+abstract class AbstractVoter implements VoterInterface
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function supportsAttribute($attribute)
+ {
+ return in_array($attribute, $this->getSupportedAttributes());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function supportsClass($class)
+ {
+ foreach ($this->getSupportedClasses() as $supportedClass) {
+ if ($supportedClass === $class || is_subclass_of($class, $supportedClass)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Iteratively check all given attributes by calling isGranted
+ *
+ * This method terminates as soon as it is able to return ACCESS_GRANTED
+ * If at least one attribute is supported, but access not granted, then ACCESS_DENIED is returned
+ * Otherwise it will return ACCESS_ABSTAIN
+ *
+ * @param TokenInterface $token A TokenInterface instance
+ * @param object $object The object to secure
+ * @param array $attributes An array of attributes associated with the method being invoked
+ *
+ * @return int either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED
+ */
+ public function vote(TokenInterface $token, $object, array $attributes)
+ {
+ if (!$object || !$this->supportsClass(get_class($object))) {
+ return self::ACCESS_ABSTAIN;
+ }
+
+ // abstain vote by default in case none of the attributes are supported
+ $vote = self::ACCESS_ABSTAIN;
+
+ foreach ($attributes as $attribute) {
+ if (!$this->supportsAttribute($attribute)) {
+ continue;
+ }
+
+ // as soon as at least one attribute is supported, default is to deny access
+ $vote = self::ACCESS_DENIED;
+
+ if ($this->isGranted($attribute, $object, $token->getUser())) {
+ // grant access as soon as at least one voter returns a positive response
+ return self::ACCESS_GRANTED;
+ }
+ }
+
+ return $vote;
+ }
+
+ /**
+ * Return an array of supported classes. This will be called by supportsClass
+ *
+ * @return array an array of supported classes, i.e. array('Acme\DemoBundle\Model\Product')
+ */
+ abstract protected function getSupportedClasses();
+
+ /**
+ * Return an array of supported attributes. This will be called by supportsAttribute
+ *
+ * @return array an array of supported attributes, i.e. array('CREATE', 'READ')
+ */
+ abstract protected function getSupportedAttributes();
+
+ /**
+ * Perform a single access check operation on a given attribute, object and (optionally) user
+ * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
+ * $user can be one of the following:
+ * a UserInterface object (fully authenticated user)
+ * a string (anonymously authenticated user)
+ *
+ * @param string $attribute
+ * @param object $object
+ * @param UserInterface|string $user
+ *
+ * @return bool
+ */
+ abstract protected function isGranted($attribute, $object, $user = null);
+}
diff --git a/Core/Authorization/Voter/ExpressionVoter.php b/Core/Authorization/Voter/ExpressionVoter.php
new file mode 100644
index 0000000..98b8f50
--- /dev/null
+++ b/Core/Authorization/Voter/ExpressionVoter.php
@@ -0,0 +1,118 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Authorization\Voter;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
+use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
+use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
+use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
+use Symfony\Component\ExpressionLanguage\Expression;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * ExpressionVoter votes based on the evaluation of an expression.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class ExpressionVoter implements VoterInterface
+{
+ private $expressionLanguage;
+ private $trustResolver;
+ private $roleHierarchy;
+
+ /**
+ * Constructor.
+ *
+ * @param ExpressionLanguage $expressionLanguage
+ * @param AuthenticationTrustResolverInterface $trustResolver
+ * @param RoleHierarchyInterface|null $roleHierarchy
+ */
+ public function __construct(ExpressionLanguage $expressionLanguage, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null)
+ {
+ $this->expressionLanguage = $expressionLanguage;
+ $this->trustResolver = $trustResolver;
+ $this->roleHierarchy = $roleHierarchy;
+ }
+
+ public function addExpressionLanguageProvider(ExpressionFunctionProviderInterface $provider)
+ {
+ $this->expressionLanguage->registerProvider($provider);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function supportsAttribute($attribute)
+ {
+ return $attribute instanceof Expression;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function supportsClass($class)
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function vote(TokenInterface $token, $object, array $attributes)
+ {
+ $result = VoterInterface::ACCESS_ABSTAIN;
+ $variables = null;
+ foreach ($attributes as $attribute) {
+ if (!$this->supportsAttribute($attribute)) {
+ continue;
+ }
+
+ if (null === $variables) {
+ $variables = $this->getVariables($token, $object);
+ }
+
+ $result = VoterInterface::ACCESS_DENIED;
+ if ($this->expressionLanguage->evaluate($attribute, $variables)) {
+ return VoterInterface::ACCESS_GRANTED;
+ }
+ }
+
+ return $result;
+ }
+
+ private function getVariables(TokenInterface $token, $object)
+ {
+ if (null !== $this->roleHierarchy) {
+ $roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
+ } else {
+ $roles = $token->getRoles();
+ }
+
+ $variables = array(
+ 'token' => $token,
+ 'user' => $token->getUser(),
+ 'object' => $object,
+ 'roles' => array_map(function ($role) { return $role->getRole(); }, $roles),
+ 'trust_resolver' => $this->trustResolver,
+ );
+
+ // this is mainly to propose a better experience when the expression is used
+ // in an access control rule, as the developer does not know that it's going
+ // to be handled by this voter
+ if ($object instanceof Request) {
+ $variables['request'] = $object;
+ }
+
+ return $variables;
+ }
+}
diff --git a/Core/Encoder/EncoderAwareInterface.php b/Core/Encoder/EncoderAwareInterface.php
new file mode 100644
index 0000000..22ae820
--- /dev/null
+++ b/Core/Encoder/EncoderAwareInterface.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Encoder;
+
+/**
+ * @author Christophe Coevoet <stof@notk.org>
+ */
+interface EncoderAwareInterface
+{
+ /**
+ * Gets the name of the encoder used to encode the password.
+ *
+ * If the method returns null, the standard way to retrieve the encoder
+ * will be used instead.
+ *
+ * @return string
+ */
+ public function getEncoderName();
+}
diff --git a/Core/Encoder/EncoderFactory.php b/Core/Encoder/EncoderFactory.php
index 5f6c20c..0568d41 100644
--- a/Core/Encoder/EncoderFactory.php
+++ b/Core/Encoder/EncoderFactory.php
@@ -30,19 +30,32 @@ class EncoderFactory implements EncoderFactoryInterface
*/
public function getEncoder($user)
{
- foreach ($this->encoders as $class => $encoder) {
- if ((is_object($user) && !$user instanceof $class) || (!is_object($user) && !is_subclass_of($user, $class) && $user != $class)) {
- continue;
+ $encoderKey = null;
+
+ if ($user instanceof EncoderAwareInterface && (null !== $encoderName = $user->getEncoderName())) {
+ if (!array_key_exists($encoderName, $this->encoders)) {
+ throw new \RuntimeException(sprintf('The encoder "%s" was not configured.', $encoderName));
}
- if (!$encoder instanceof PasswordEncoderInterface) {
- return $this->encoders[$class] = $this->createEncoder($encoder);
+ $encoderKey = $encoderName;
+ } else {
+ foreach ($this->encoders as $class => $encoder) {
+ if ((is_object($user) && $user instanceof $class) || (!is_object($user) && (is_subclass_of($user, $class) || $user == $class))) {
+ $encoderKey = $class;
+ break;
+ }
}
+ }
+
+ if (null === $encoderKey) {
+ throw new \RuntimeException(sprintf('No encoder has been configured for account "%s".', is_object($user) ? get_class($user) : $user));
+ }
- return $this->encoders[$class];
+ if (!$this->encoders[$encoderKey] instanceof PasswordEncoderInterface) {
+ $this->encoders[$encoderKey] = $this->createEncoder($this->encoders[$encoderKey]);
}
- throw new \RuntimeException(sprintf('No encoder has been configured for account "%s".', is_object($user) ? get_class($user) : $user));
+ return $this->encoders[$encoderKey];
}
/**
diff --git a/Core/Encoder/UserPasswordEncoder.php b/Core/Encoder/UserPasswordEncoder.php
new file mode 100644
index 0000000..13ee835
--- /dev/null
+++ b/Core/Encoder/UserPasswordEncoder.php
@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Encoder;
+
+use Symfony\Component\Security\Core\User\UserInterface;
+
+/**
+ * A generic password encoder
+ *
+ * @author Ariel Ferrandini <arielferrandini@gmail.com>
+ */
+class UserPasswordEncoder implements UserPasswordEncoderInterface
+{
+ /**
+ * @var EncoderFactoryInterface
+ */
+ private $encoderFactory;
+
+ /**
+ * @param EncoderFactoryInterface $encoderFactory The encoder factory
+ */
+ public function __construct(EncoderFactoryInterface $encoderFactory)
+ {
+ $this->encoderFactory = $encoderFactory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function encodePassword(UserInterface $user, $plainPassword)
+ {
+ $encoder = $this->encoderFactory->getEncoder($user);
+
+ return $encoder->encodePassword($plainPassword, $user->getSalt());
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isPasswordValid(UserInterface $user, $raw)
+ {
+ $encoder = $this->encoderFactory->getEncoder($user);
+
+ return $encoder->isPasswordValid($user->getPassword(), $raw, $user->getSalt());
+ }
+}
diff --git a/Core/Encoder/UserPasswordEncoderInterface.php b/Core/Encoder/UserPasswordEncoderInterface.php
new file mode 100644
index 0000000..39e906a
--- /dev/null
+++ b/Core/Encoder/UserPasswordEncoderInterface.php
@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Encoder;
+
+use Symfony\Component\Security\Core\User\UserInterface;
+
+/**
+ * UserPasswordEncoderInterface is the interface for the password encoder service.
+ *
+ * @author Ariel Ferrandini <arielferrandini@gmail.com>
+ */
+interface UserPasswordEncoderInterface
+{
+ /**
+ *
+ * Encodes the plain password.
+ *
+ * @param UserInterface $user The user
+ * @param string $plainPassword The password to encode
+ *
+ * @return string The encoded password
+ */
+ public function encodePassword(UserInterface $user, $plainPassword);
+
+ /**
+ * @param UserInterface $user The user
+ * @param string $raw A raw password
+ *
+ * @return bool true if the password is valid, false otherwise
+ */
+ public function isPasswordValid(UserInterface $user, $raw);
+}
diff --git a/Core/Exception/ExceptionInterface.php b/Core/Exception/ExceptionInterface.php
new file mode 100644
index 0000000..5000d02
--- /dev/null
+++ b/Core/Exception/ExceptionInterface.php
@@ -0,0 +1,21 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Exception;
+
+/**
+ * Base ExceptionInterface for the Security component.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+interface ExceptionInterface
+{
+}
diff --git a/Core/Exception/InvalidArgumentException.php b/Core/Exception/InvalidArgumentException.php
new file mode 100644
index 0000000..6f85e95
--- /dev/null
+++ b/Core/Exception/InvalidArgumentException.php
@@ -0,0 +1,21 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Exception;
+
+/**
+ * Base InvalidArgumentException for the Security component.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
+{
+}
diff --git a/Core/Exception/RuntimeException.php b/Core/Exception/RuntimeException.php
new file mode 100644
index 0000000..95edec8
--- /dev/null
+++ b/Core/Exception/RuntimeException.php
@@ -0,0 +1,21 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Exception;
+
+/**
+ * Base RuntimeException for the Security component.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class RuntimeException extends \RuntimeException implements ExceptionInterface
+{
+}
diff --git a/Core/Exception/UsernameNotFoundException.php b/Core/Exception/UsernameNotFoundException.php
index 11607d3..6979389 100644
--- a/Core/Exception/UsernameNotFoundException.php
+++ b/Core/Exception/UsernameNotFoundException.php
@@ -69,4 +69,12 @@ class UsernameNotFoundException extends AuthenticationException
parent::unserialize($parentData);
}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getMessageData()
+ {
+ return array('{{ username }}' => $this->username);
+ }
}
diff --git a/Core/LICENSE b/Core/LICENSE
new file mode 100644
index 0000000..43028bc
--- /dev/null
+++ b/Core/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2004-2015 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/Core/README.md b/Core/README.md
new file mode 100644
index 0000000..66c323e
--- /dev/null
+++ b/Core/README.md
@@ -0,0 +1,23 @@
+Security Component - Core
+=========================
+
+Security provides an infrastructure for sophisticated authorization systems,
+which makes it possible to easily separate the actual authorization logic from
+so called user providers that hold the users credentials. It is inspired by
+the Java Spring framework.
+
+Resources
+---------
+
+Documentation:
+
+http://symfony.com/doc/2.6/book/security.html
+
+Tests
+-----
+
+You can run the unit tests with the following command:
+
+ $ cd path/to/Symfony/Component/Security/Core/
+ $ composer.phar install --dev
+ $ phpunit
diff --git a/Core/Resources/translations/security.ar.xlf b/Core/Resources/translations/security.ar.xlf
new file mode 100644
index 0000000..fd18ee6
--- /dev/null
+++ b/Core/Resources/translations/security.ar.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>حدث خطأ اثناء الدخول.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>لم استطع العثور على معلومات الدخول.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>لم يكتمل طلؚ الدخول نتيجه عطل فى الن؞ام.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>معلومات الدخول خاط؊ة.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>ملفات تعريف الارتؚاط(cookies) تم استخدامها من Ù‚ØšÙ„ ؎خص اخر.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>ليست لديك الصلاحيات الكافية لهذا الطلؚ.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>رمز الموقع غير صحيح.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>انتهت صلاحية(digest nonce).</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>لا يوجد معرف للدخول يدعم الرمز المستخدم للدخول.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>لا يوجد صلة ؚينك و ؚين الموقع اما انها انتهت او ان متصفحك لا يدعم خاصية ملفات تعريف الارتؚاط (cookies).</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>لم استطع العثور على الرمز.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>لم استطع العثور على اسم الدخول.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>انتهت صلاحية الحساؚ.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>انتهت صلاحية معلومات الدخول.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>الحساؚ موقوف.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>الحساؚ مغلق.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.ca.xlf b/Core/Resources/translations/security.ca.xlf
new file mode 100644
index 0000000..7ece260
--- /dev/null
+++ b/Core/Resources/translations/security.ca.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Ha succeït un error d'autenticació.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>No s'han trobat les credencials d'autenticació.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>La solicitud d'autenticació no s'ha pogut processar per un problema del sistema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Credencials no vàlides.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>La cookie ja ha estat utilitzada per una altra persona.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>No té privilegis per solicitar el recurs.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Token CSRF no vàlid.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>El vector d'inicialització (digest nonce) ha expirat.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>No s'ha trobat un proveïdor d'autenticació que suporti el token d'autenticació.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>No hi ha sessió disponible, ha expirat o les cookies no estan habilitades.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>No s'ha trobat cap token.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>No s'ha trobat el nom d'usuari.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>El compte ha expirat.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Les credencials han expirat.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>El compte està deshabilitat.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>El compte està bloquejat.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.cs.xlf b/Core/Resources/translations/security.cs.xlf
new file mode 100644
index 0000000..bd146c6
--- /dev/null
+++ b/Core/Resources/translations/security.cs.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Při ověřování došlo k chybě.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Ověřovací údaje nebyly nalezeny.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>PoÅŸadavek na ověření nemohl bÜt zpracován kvůli systémové chybě.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Neplatné přihlašovací údaje.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie jiÅŸ bylo pouÅŸité někÜm jinÜm.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Nemáte oprávnění přistupovat k prostředku.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>NeplatnÜ CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Platnost inicializačního vektoru (digest nonce) vypršela.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Poskytovatel pro ověřovací token nebyl nalezen.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Session není k dispozici, vypršela její platnost, nebo jsou zakázané cookies.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Token nebyl nalezen.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Přihlašovací jméno nebylo nalezeno.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Platnost účtu vypršela.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Platnost přihlašovacích údajů vypršela.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Účet je zakázanÜ.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Účet je zablokovanÜ.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.da.xlf b/Core/Resources/translations/security.da.xlf
new file mode 100644
index 0000000..9c7b886
--- /dev/null
+++ b/Core/Resources/translations/security.da.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="no" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>En fejl indtraf ved godkendelse.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Loginoplysninger kan findes.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Godkendelsesanmodning kan ikke behandles på grund af et systemfejl.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Ugyldige loginoplysninger.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie er allerede brugt af en anden.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Ingen tilladselese at anvende kilden.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Ugyldigt CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce er udlÞbet.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Ingen godkendelsesudbyder er fundet til understÞttelsen af godkendelsestoken.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Ingen session tilgÊngelig, sessionen er enten udlÞbet eller cookies er ikke aktiveret.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Ingen token kan findes.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Brugernavn kan ikke findes.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Brugerkonto er udlÞbet.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Loginoplysninger er udlÞbet.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Brugerkonto er deaktiveret.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Brugerkonto er låst.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.de.xlf b/Core/Resources/translations/security.de.xlf
new file mode 100644
index 0000000..e5946ed
--- /dev/null
+++ b/Core/Resources/translations/security.de.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Es ist ein Fehler bei der Authentifikation aufgetreten.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Es konnten keine Zugangsdaten gefunden werden.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Die Authentifikation konnte wegen eines Systemproblems nicht bearbeitet werden.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Fehlerhafte Zugangsdaten.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie wurde bereits von jemand anderem verwendet.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Keine Rechte, um die Ressource anzufragen.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>UngÃŒltiges CSRF-Token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce ist abgelaufen.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Es wurde kein Authentifizierungs-Provider gefunden, der das Authentifizierungs-Token unterstÃŒtzt.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Keine Session verfÃŒgbar, entweder ist diese abgelaufen oder Cookies sind nicht aktiviert.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Es wurde kein Token gefunden.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Der Benutzername wurde nicht gefunden.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Der Account ist abgelaufen.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Die Zugangsdaten sind abgelaufen.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Der Account ist deaktiviert.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Der Account ist gesperrt.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.el.xlf b/Core/Resources/translations/security.el.xlf
new file mode 100644
index 0000000..07eabe7
--- /dev/null
+++ b/Core/Resources/translations/security.el.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>ΣυΜέβη έΜα σφάλΌα πιστοποίησης.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>΀α στοιχεία πιστοποίησης Ύε βρέΞηκαΜ.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>΀ο αίτηΌα πιστοποίησης Ύε Όπορεί Μα επεΟεργαστεί λόγω σφάλΌατος του συστήΌατος.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>ΛαΜΞασΌέΜα στοιχεία σύΜΎεσης.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>΀ο Cookie έχει ήΎη χρησιΌοποιηΞεί από κάποιοΜ άλλο.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>ΔεΜ είστε εΟουσιοΎοτηΌέΜος για πρόσβαση στο συγκεκριΌέΜο περιεχόΌεΜο.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Μη έγκυρο CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>΀ο digest nonce έχει λήΟει.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Δε βρέΞηκε κάποιος πάροχος πιστοποίησης που Μα υποστηρίζει το token πιστοποίησης.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>ΔεΜ υπάρχει εΜεργή σύΜοΎος (session), είτε έχει λήΟει ή τα cookies ΎεΜ είΜαι εΜεργοποιηΌέΜα.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>ΔεΜ ήταΜ ΎυΜατόΜ Μα βρεΞεί κάποιο token.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>΀ο Username Ύε βρέΞηκε.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Ο λογαριασΌός έχει λήΟει.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>΀α στοιχεία σύΜΎεσης έχουΜ λήΟει.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Ο λογαριασΌός είΜαι απεΜεργοποιηΌέΜος.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Ο λογαριασΌός είΜαι κλειΎωΌέΜος.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.en.xlf b/Core/Resources/translations/security.en.xlf
new file mode 100644
index 0000000..3640698
--- /dev/null
+++ b/Core/Resources/translations/security.en.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>An authentication exception occurred.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Authentication credentials could not be found.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Authentication request could not be processed due to a system problem.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Invalid credentials.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie has already been used by someone else.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Not privileged to request the resource.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Invalid CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce has expired.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>No authentication provider found to support the authentication token.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>No session available, it either timed out or cookies are not enabled.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>No token could be found.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Username could not be found.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Account has expired.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Credentials have expired.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Account is disabled.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Account is locked.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.es.xlf b/Core/Resources/translations/security.es.xlf
new file mode 100644
index 0000000..00cefbb
--- /dev/null
+++ b/Core/Resources/translations/security.es.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Ocurrió un error de autenticación.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>No se encontraron las credenciales de autenticación.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>La solicitud de autenticación no se pudo procesar debido a un problema del sistema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Credenciales no válidas.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>La cookie ya ha sido usada por otra persona.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>No tiene privilegios para solicitar el recurso.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Token CSRF no válido.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>El vector de inicialización (digest nonce) ha expirado.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>No se encontró un proveedor de autenticación que soporte el token de autenticación.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>No hay ninguna sesión disponible, ha expirado o las cookies no están habilitados.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>No se encontró ningún token.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>No se encontró el nombre de usuario.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>La cuenta ha expirado.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Las credenciales han expirado.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>La cuenta está deshabilitada.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>La cuenta está bloqueada.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.fa.xlf b/Core/Resources/translations/security.fa.xlf
new file mode 100644
index 0000000..0b76290
--- /dev/null
+++ b/Core/Resources/translations/security.fa.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>خطایی هنگام تعیین اعتؚار اتفاق افتاد.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>؎رایط تعیین اعتؚار ٟیدا ن؎د.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>درخواست تعیین اعتؚار ØšÙ‡ دلیل Ù…ØŽÚ©Ù„ سیستم قاؚل ؚررسی نیست.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>؎رایط نامعتؚر.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>کوکی قؚلا ؚرای ؎خص دیگری استفاده ؎ده است.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>دسترسی لازم ؚرای درخواست این منؚع را ندارید.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>توکن CSRF معتؚر نیست.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce منقضی ؎ده است.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>هیچ ارایه کننده تعیین اعتؚاری ؚرای ساٟورت توکن تعیین اعتؚار ٟیدا ن؎د.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>جلسه‌ای در دسترس نیست. این میتواند یا ØšÙ‡ دلیل ٟایان یافتن زمان ؚا؎د یا اینکه کوکی ها فعال نیستند.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>هیچ توکنی ٟیدا ن؎د.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>نام ‌کارؚری ٟیدا ن؎د.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>حساؚ کارؚری منقضی ؎ده است.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>ٟارامترهای تعیین اعتؚار منقضی ؎ده‌اند.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>حساؚ کارؚری غیرفعال است.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>حساؚ کارؚری قفل ؎ده است.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.fr.xlf b/Core/Resources/translations/security.fr.xlf
new file mode 100644
index 0000000..f3965d3
--- /dev/null
+++ b/Core/Resources/translations/security.fr.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Une exception d'authentification s'est produite.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Les droits d'authentification n'ont pas pu être trouvés.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>La requête d'authentification n'a pas pu être executée à cause d'un problÚme systÚme.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Droits invalides.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Le cookie a déjà été utilisé par quelqu'un d'autre.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Pas de privilÚges pour accéder à la ressource.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Jeton CSRF invalide.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Le digest nonce a expiré.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Aucun fournisseur d'authentification n'a été trouvé pour supporter le jeton d'authentification.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Pas de session disponible, celle-ci a expiré ou les cookies ne sont pas activés.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Aucun jeton n'a pu être trouvé.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Le nom d'utilisateur ne peut pas être trouvé.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Le compte a expiré.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Les droits ont expirés.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Le compte est désactivé.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Le compte est bloqué.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.gl.xlf b/Core/Resources/translations/security.gl.xlf
new file mode 100644
index 0000000..ed6491f
--- /dev/null
+++ b/Core/Resources/translations/security.gl.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Ocorreu un erro de autenticación.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Non se atoparon as credenciais de autenticación.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>A solicitude de autenticación no puido ser procesada debido a un problema do sistema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Credenciais non válidas.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>A cookie xa foi empregado por outro usuario.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Non ten privilexios para solicitar o recurso.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Token CSRF non válido.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>O vector de inicialización (digest nonce) expirou.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Non se atopou un provedor de autenticación que soporte o token de autenticación.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Non hai ningunha sesión dispoñible, expirou ou as cookies non están habilitadas.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Non se atopou ningún token.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Non se atopou o nome de usuario.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>A conta expirou.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>As credenciais expiraron.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>A conta está deshabilitada.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>A conta está bloqueada.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.hu.xlf b/Core/Resources/translations/security.hu.xlf
new file mode 100644
index 0000000..7243970
--- /dev/null
+++ b/Core/Resources/translations/security.hu.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Hitelesítési hiba lépett fel.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Nem találhatók hitelesítési információk.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>A hitelesítési kérést rendszerhiba miatt nem lehet feldolgozni.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Érvénytelen hitelesítési információk.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Ezt a sÌtit valaki más már felhasználta.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Nem rendelkezik az erőforrás eléréséhez szÃŒkséges jogosultsággal.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Érvénytelen CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>A kivonat bélyege (nonce) lejárt.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Nem található a hitelesítési tokent támogató hitelesítési szolgáltatás.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Munkamenet nem áll rendelkezésre, túllépte az időkeretet vagy a sÃŒtik le vannak tiltva.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Nem található token.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>A felhasználónév nem található.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>A fiók lejárt.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>A hitelesítési információk lejártak.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>FelfÌggesztett fiók.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Zárolt fiók.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.it.xlf b/Core/Resources/translations/security.it.xlf
new file mode 100644
index 0000000..75d81cc
--- /dev/null
+++ b/Core/Resources/translations/security.it.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Si Ú verificato un errore di autenticazione.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Impossibile trovare le credenziali di autenticazione.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>La richiesta di autenticazione non può essere processata a causa di un errore di sistema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Credenziali non valide.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Il cookie Ú già stato usato da qualcun altro.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Non hai i privilegi per richiedere questa risorsa.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>CSRF token non valido.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Il numero di autenticazione Ú scaduto.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Non Ú stato trovato un valido fornitore di autenticazione per supportare il token.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Nessuna sessione disponibile, può essere scaduta o i cookie non sono abilitati.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Nessun token trovato.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Username non trovato.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Account scaduto.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Credenziali scadute.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>L'account Ú disabilitato.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>L'account Ú bloccato.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.lb.xlf b/Core/Resources/translations/security.lb.xlf
new file mode 100644
index 0000000..3dc76d5
--- /dev/null
+++ b/Core/Resources/translations/security.lb.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" target-language="lb" datatype="plaintext" original="security.en.xlf">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Bei der Authentifikatioun ass e Feeler opgetrueden.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Et konnte keng Zouganksdate fonnt ginn.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>D'Ufro fir eng Authentifikatioun konnt wéinst engem Problem vum System net beaarbecht ginn.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Ongëlteg Zouganksdaten.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>De Cookie gouf scho vun engem anere benotzt.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Keng Rechter fir d'Ressource unzefroen.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Ongëltegen CSRF-Token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Den eemolege Schlëssel ass ofgelaf.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Et gouf keen Authentifizéierungs-Provider fonnt deen den Authentifizéierungs-Token ënnerstëtzt.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Keng Sëtzung disponibel. Entweder ass se ofgelaf oder Cookies sinn net aktivéiert.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Et konnt keen Token fonnt ginn.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>De Benotzernumm konnt net fonnt ginn.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Den Account ass ofgelaf.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>D'Zouganksdate sinn ofgelaf.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>De Konto ass deaktivéiert.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>De Konto ass gespaart.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.nl.xlf b/Core/Resources/translations/security.nl.xlf
new file mode 100644
index 0000000..8969e9e
--- /dev/null
+++ b/Core/Resources/translations/security.nl.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Er heeft zich een authenticatieprobleem voorgedaan.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Authenticatiegegevens konden niet worden gevonden.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Authenticatieaanvraag kon niet worden verwerkt door een technisch probleem.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Ongeldige inloggegevens.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie is al door een ander persoon gebruikt.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Onvoldoende rechten om de aanvraag te verwerken.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>CSRF-code is ongeldig.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Serverauthenticatiesleutel (digest nonce) is verlopen.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Geen authenticatieprovider gevonden die de authenticatietoken ondersteunt.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Geen sessie beschikbaar, mogelijk is deze verlopen of cookies zijn uitgeschakeld.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Er kon geen authenticatietoken worden gevonden.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Gebruikersnaam kon niet worden gevonden.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Account is verlopen.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Authenticatiegegevens zijn verlopen.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Account is gedeactiveerd.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Account is geblokkeerd.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.no.xlf b/Core/Resources/translations/security.no.xlf
new file mode 100644
index 0000000..3857ab4
--- /dev/null
+++ b/Core/Resources/translations/security.no.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="no" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>En autentiserings feil har skjedd.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>PÃ¥loggingsinformasjonen kunne ikke bli funnet.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Autentiserings forespÞrselen kunne ikke bli prosessert grunnet en system feil.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Ugyldig påloggingsinformasjonen.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie har allerede blitt brukt av noen andre.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Ingen tilgang til å be om gitt kilde.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Ugyldig CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce er utlÞpt.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Ingen autentiserings tilbyder funnet som stÞtter gitt autentiserings token.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Ingen sesjon tilgjengelig, sesjonen er enten utlÞpt eller cookies ikke skrudd på.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Ingen token kunne bli funnet.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Brukernavn kunne ikke bli funnet.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Brukerkonto har utgått.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Påloggingsinformasjon har utlÞpt.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Brukerkonto er deaktivert.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Brukerkonto er sperret.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.pl.xlf b/Core/Resources/translations/security.pl.xlf
new file mode 100644
index 0000000..8d563d2
--- /dev/null
+++ b/Core/Resources/translations/security.pl.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Wystąpił błąd uwierzytelniania.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Dane uwierzytelniania nie zostały znalezione.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Żądanie uwierzytelniania nie mogło zostać pomyślnie zakończone z powodu problemu z systemem.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Nieprawidłowe dane.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>To ciasteczko jest uÅŒywane przez kogoś innego.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Brak uprawnień dla Ōądania wskazanego zasobu.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Nieprawidłowy token CSRF.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Kod dostępu wygasł.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Nie znaleziono mechanizmu uwierzytelniania zdolnego do obsługi przesłanego tokenu.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Brak danych sesji, sesja wygasła lub ciasteczka nie są włączone.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Nie znaleziono tokenu.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>UÅŒytkownik o podanej nazwie nie istnieje.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Konto wygasło.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Dane uwierzytelniania wygasły.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Konto jest wyłączone.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Konto jest zablokowane.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.pt_BR.xlf b/Core/Resources/translations/security.pt_BR.xlf
new file mode 100644
index 0000000..846fd49
--- /dev/null
+++ b/Core/Resources/translations/security.pt_BR.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Uma exceção ocorreu durante a autenticação.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>As credenciais de autenticação não foram encontradas.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>A autenticação não pÎde ser concluída devido a um problema no sistema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Credenciais inválidas.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Este cookie já esta em uso.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Não possui privilégios o bastante para requisitar este recurso.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Token CSRF inválido.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce expirado.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Nenhum provedor de autenticação encontrado para suportar o token de autenticação.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Nenhuma sessão disponível, ela expirou ou cookies estão desativados.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Nenhum token foi encontrado.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Nome de usuário não encontrado.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>A conta esta expirada.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>As credenciais estão expiradas.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Conta desativada.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>A conta esta travada.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.pt_PT.xlf b/Core/Resources/translations/security.pt_PT.xlf
new file mode 100644
index 0000000..e661000
--- /dev/null
+++ b/Core/Resources/translations/security.pt_PT.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Ocorreu um excepção durante a autenticação.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>As credenciais de autenticação não foram encontradas.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>O pedido de autenticação não foi concluído devido a um problema no sistema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Credenciais inválidas.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Este cookie já esta em uso.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Não possui privilégios para aceder a este recurso.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Token CSRF inválido.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Digest nonce expirado.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Nenhum fornecedor de autenticação encontrado para suportar o token de autenticação.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Não existe sessão disponível, esta expirou ou os cookies estão desativados.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>O token não foi encontrado.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Nome de utilizador não encontrado.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>A conta expirou.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>As credenciais expiraram.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Conta desativada.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>A conta esta trancada.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.ro.xlf b/Core/Resources/translations/security.ro.xlf
new file mode 100644
index 0000000..440f110
--- /dev/null
+++ b/Core/Resources/translations/security.ro.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>A apărut o eroare de autentificare.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Informațiile de autentificare nu au fost găsite.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Sistemul nu a putut procesa cererea de autentificare din cauza unei erori.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Date de autentificare invalide.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookieul este folosit deja de altcineva.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Permisiuni insuficiente pentru resursa cerută.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Tokenul CSRF este invalid.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Tokenul temporar a expirat.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Nu a fost găsit nici un agent de autentificare pentru tokenul specificat.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Sesiunea nu mai este disponibilă, a expirat sau suportul pentru cookieuri nu este activat.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Tokenul nu a putut fi găsit.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Numele de utilizator nu a fost găsit.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Contul a expirat.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Datele de autentificare au expirat.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Contul este dezactivat.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Contul este blocat.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.ru.xlf b/Core/Resources/translations/security.ru.xlf
new file mode 100644
index 0000000..1964f95
--- /dev/null
+++ b/Core/Resources/translations/security.ru.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>ОшОбка аутеМтОфОкацОО.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>АутеМтОфОкацОПММые ЎаММые Ме МайЎеМы.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>ЗапрПс аутеМтОфОкацОО Ме ЌПжет быть ПбрабПтаМ в связО с прПблеЌПй в сОстеЌе.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>НеЎействОтельМые аутеМтОфОкацОПММые ЎаММые.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie уже был ОспПльзПваМ кеЌ-тП ЎругОЌ.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Отсутствуют права Ма запрПс этПгП ресурса.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>НеЎействОтельМый тПкеМ CSRF.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>ВреЌя ЎействОя ПЎМПразПвПгП ключа ЎайЎжеста ОстеклП.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Не МайЎеМ прПвайЎер аутеМтОфОкацОО, пПЎЎержОвающОй тПкеМ аутеМтОфОкацОО.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>СессОя Ме МайЎеМа, ее вреЌя ОстеклП, лОбП cookies Ме включеМы.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>ТПкеМ Ме МайЎеМ.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>ИЌя пПльзПвателя Ме МайЎеМП.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>ВреЌя ЎействОя учетМПй запОсО ОстеклП.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>ВреЌя ЎействОя аутеМтОфОкацОПММых ЎаММых ОстеклП.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>УчетМая запОсь ПтключеМа.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>УчетМая запОсь заблПкОрПваМа.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.sk.xlf b/Core/Resources/translations/security.sk.xlf
new file mode 100644
index 0000000..e6552a6
--- /dev/null
+++ b/Core/Resources/translations/security.sk.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Pri overovaní došlo k chybe.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Overovacie údaje neboli nájdené.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Poşiadavok na overenie nemohol byť spracovanÜ kvÎli systémovej chybe.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Neplatné prihlasovacie údaje.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookie uş bolo pouşité niekÜm inÜm.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Nemáte oprávnenie pristupovať k prostriedku.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>NeplatnÜ CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Platnosť inicializačného vektoru (digest nonce) skončila.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Poskytovateğ pre overovací token nebol nájdenÜ.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Session nie je k dispozíci, vypršala jej platnosť, alebo sú zakázané cookies.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Token nebol nájdenÜ.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Prihlasovacie meno nebolo nájdené.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Platnosť účtu skončila.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Platnosť prihlasovacích údajov skončila.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Účet je zakázanÜ.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Účet je zablokovanÜ.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.sl.xlf b/Core/Resources/translations/security.sl.xlf
new file mode 100644
index 0000000..ee70c9a
--- /dev/null
+++ b/Core/Resources/translations/security.sl.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Prišlo je do izjeme pri preverjanju avtentikacije.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Poverilnic za avtentikacijo ni bilo mogoče najti.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Zahteve za avtentikacijo ni bilo mogoče izvesti zaradi sistemske teşave.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Neveljavne pravice.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Piškotek je uporabil şe nekdo drug.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Nimate privilegijev za zahtevani vir.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Neveljaven CSRF ÅŸeton.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Začasni şeton je potekel.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Ponudnika avtentikacije za podporo prijavnega şetona ni bilo mogoče najti.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Seja ni na voljo, ali je potekla ali pa piškotki niso omogočeni.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Ŝetona ni bilo mogoče najti.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Uporabniškega imena ni bilo mogoče najti.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Račun je potekel.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Poverilnice so potekle.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Račun je onemogočen.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Račun je zaklenjen.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.sr_Cyrl.xlf b/Core/Resources/translations/security.sr_Cyrl.xlf
new file mode 100644
index 0000000..35e4ddf
--- /dev/null
+++ b/Core/Resources/translations/security.sr_Cyrl.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Изузетак прО аутеМтОфОкацОјО.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>АутеМтОфОкацОПМО пПЎацО МОсу прПМађеМО.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Захтев за аутеМтОфОкацОју Ме ЌПже бОтО ПбрађеМ збПг сОстеЌскОх прПблеЌа.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>НевалОЎМО пПЎацО за аутеМтОфОкацОју.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>КПлачОћ је већ ОскПрОшћеМ ПЎ страМе МекПг ЎругПг.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>НеЌате права прОступа ПвПЌ ресурсу.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>НевалОЎаМ CSRF тПкеМ.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>ВреЌе крОптПграфскПг кључа је ОстеклП.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>АутеМтОфОкацОПМО прПвајЎер за пПЎршку тПкеМа МОје прПМађеМ.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>СесОја МОје ЎПступМа, Остекла је ОлО су кПлачОћО ОскључеМО.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>ТПкеМ Ме ЌПже бОтО прПМађеМ.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>КПрОсМОчкП ОЌе Ме ЌПже бОтО прПМађеМП.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>НалПг је ОстекаП.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>ППЎацО за аутеМтОфОкацОју су ОстеклО.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>НалПг је ПМеЌПгућеМ.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>НалПг је закључаМ.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.sr_Latn.xlf b/Core/Resources/translations/security.sr_Latn.xlf
new file mode 100644
index 0000000..ddc4807
--- /dev/null
+++ b/Core/Resources/translations/security.sr_Latn.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Izuzetak pri autentifikaciji.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Autentifikacioni podaci nisu pronađeni.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Zahtev za autentifikaciju ne moÅŸe biti obrađen zbog sistemskih problema.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Nevalidni podaci za autentifikaciju.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Kolačić je već iskorišćen od strane nekog drugog.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Nemate prava pristupa ovom resursu.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Nevalidan CSRF token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Vreme kriptografskog ključa je isteklo.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Autentifikacioni provajder za podršku tokena nije pronađen.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Sesija nije dostupna, istekla je ili su kolačići isključeni.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Token ne moÅŸe biti pronađen.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Korisničko ime ne moÅŸe biti pronađeno.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Nalog je istekao.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Podaci za autentifikaciju su istekli.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Nalog je onemogućen.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Nalog je zaključan.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.sv.xlf b/Core/Resources/translations/security.sv.xlf
new file mode 100644
index 0000000..b5f6209
--- /dev/null
+++ b/Core/Resources/translations/security.sv.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Ett autentiseringsfel har intrÀffat.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Uppgifterna för autentisering kunde inte hittas.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Autentiseringen kunde inte genomföras på grund av systemfel.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Felaktiga uppgifter.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Cookien har redan anvÀnts av någon annan.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Saknar rÀttigheter för resursen.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Ogiltig CSRF-token.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Förfallen digest nonce.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Ingen leverantör för autentisering hittades för angiven autentiseringstoken.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Ingen session finns tillgÀnglig, antingen har den förfallit eller Àr cookies inte aktiverat.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Ingen token kunde hittas.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>AnvÀndarnamnet kunde inte hittas.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Kontot har förfallit.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Uppgifterna har förfallit.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Kontot Àr inaktiverat.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Kontot Àr låst.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.tr.xlf b/Core/Resources/translations/security.tr.xlf
new file mode 100644
index 0000000..fbf9b26
--- /dev/null
+++ b/Core/Resources/translations/security.tr.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>Bir yetkilendirme istisnası oluştu.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>Yetkilendirme girdileri bulunamadı.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>Bir sistem hatası nedeniyle yetkilendirme isteği işleme alınamıyor.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>Geçersiz girdiler.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>Çerez bir başkası tarafından zaten kullanılmıştı.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>Kaynak talebi için imtiyaz bulunamadı.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>Geçersiz CSRF fişi.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>Derleme zaman aşımı gerçekleşti.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Yetkilendirme fişini destekleyecek yetkilendirme sağlayıcısı bulunamadı.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Oturum bulunamadı, zaman aşımına uğradı veya çerezler etkin değil.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>Bilet bulunamadı.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>Kullanıcı adı bulunamadı.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>Hesap zaman aşımına uğradı.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>Girdiler zaman aşımına uğradı.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>Hesap devre dışı bırakılmış.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>Hesap kilitlenmiş.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Resources/translations/security.ua.xlf b/Core/Resources/translations/security.ua.xlf
new file mode 100644
index 0000000..7972121
--- /dev/null
+++ b/Core/Resources/translations/security.ua.xlf
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1">
+ <source>An authentication exception occurred.</source>
+ <target>ППЌОлка автеМтОфікації.</target>
+ </trans-unit>
+ <trans-unit id="2">
+ <source>Authentication credentials could not be found.</source>
+ <target>АвтеМтОфікаційМі ЎаМі Ме зМайЎеМП.</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>Authentication request could not be processed due to a system problem.</source>
+ <target>ЗапОт Ма автеМтОфікацію Ме ЌПже бутО ПпрацьПваМП у зв’язку з прПблеЌПю в сОстеЌі.</target>
+ </trans-unit>
+ <trans-unit id="4">
+ <source>Invalid credentials.</source>
+ <target>НевірМі автеМтОфікаційМі ЎаМі.</target>
+ </trans-unit>
+ <trans-unit id="5">
+ <source>Cookie has already been used by someone else.</source>
+ <target>ХтПсь іМшОй вже вОкПрОстав цей сookie.</target>
+ </trans-unit>
+ <trans-unit id="6">
+ <source>Not privileged to request the resource.</source>
+ <target>ВіЎсутМі права Ма запОт цьПгП ресурсу.</target>
+ </trans-unit>
+ <trans-unit id="7">
+ <source>Invalid CSRF token.</source>
+ <target>НевірМОй тПкеМ CSRF.</target>
+ </trans-unit>
+ <trans-unit id="8">
+ <source>Digest nonce has expired.</source>
+ <target>ЗакіМчОвся терЌіМ ÐŽÑ–Ñ— ПЎМПразПвПгП ключа ЎайЎжесту.</target>
+ </trans-unit>
+ <trans-unit id="9">
+ <source>No authentication provider found to support the authentication token.</source>
+ <target>Не зМайЎеМП прПвайЎера автеМтОфікації, щП піЎтрОЌує тПкеМ автеМтОфікаціії.</target>
+ </trans-unit>
+ <trans-unit id="10">
+ <source>No session available, it either timed out or cookies are not enabled.</source>
+ <target>Сесія МеЎПступМа, її час вОйшПв, абП cookies вОЌкМеМП.</target>
+ </trans-unit>
+ <trans-unit id="11">
+ <source>No token could be found.</source>
+ <target>ТПкеМ Ме зМайЎеМП.</target>
+ </trans-unit>
+ <trans-unit id="12">
+ <source>Username could not be found.</source>
+ <target>ІЌ’я кПрОстувача Ме зМайЎеМП.</target>
+ </trans-unit>
+ <trans-unit id="13">
+ <source>Account has expired.</source>
+ <target>ТерЌіМ ÐŽÑ–Ñ— ПблікПвПгП запОсу вОчерпаМП.</target>
+ </trans-unit>
+ <trans-unit id="14">
+ <source>Credentials have expired.</source>
+ <target>ТерЌіМ ÐŽÑ–Ñ— автеМтОфікаційМОх ЎаМОх вОчерпаМП.</target>
+ </trans-unit>
+ <trans-unit id="15">
+ <source>Account is disabled.</source>
+ <target>ОблікПвОй запОс віЎключеМП.</target>
+ </trans-unit>
+ <trans-unit id="16">
+ <source>Account is locked.</source>
+ <target>ОблікПвОй запОс заблПкПваМП.</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/Core/Role/RoleHierarchy.php b/Core/Role/RoleHierarchy.php
index 2e7df0e..793007e 100644
--- a/Core/Role/RoleHierarchy.php
+++ b/Core/Role/RoleHierarchy.php
@@ -19,7 +19,7 @@ namespace Symfony\Component\Security\Core\Role;
class RoleHierarchy implements RoleHierarchyInterface
{
private $hierarchy;
- private $map;
+ protected $map;
/**
* Constructor.
@@ -52,7 +52,7 @@ class RoleHierarchy implements RoleHierarchyInterface
return $reachableRoles;
}
- private function buildRoleMap()
+ protected function buildRoleMap()
{
$this->map = array();
foreach ($this->hierarchy as $main => $roles) {
diff --git a/Core/Security.php b/Core/Security.php
new file mode 100644
index 0000000..14d32f8
--- /dev/null
+++ b/Core/Security.php
@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core;
+
+/**
+ * This class holds security information.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+final class Security
+{
+ const ACCESS_DENIED_ERROR = '_security.403_error';
+ const AUTHENTICATION_ERROR = '_security.last_error';
+ const LAST_USERNAME = '_security.last_username';
+}
diff --git a/Core/SecurityContext.php b/Core/SecurityContext.php
index 0326f1d..0761c59 100644
--- a/Core/SecurityContext.php
+++ b/Core/SecurityContext.php
@@ -11,10 +11,13 @@
namespace Symfony\Component\Security\Core;
-use Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException;
-use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
+use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
+use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* SecurityContext is the main entry point of the Security component.
@@ -23,48 +26,47 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ * @deprecated Deprecated since version 2.6, to be removed in 3.0.
*/
class SecurityContext implements SecurityContextInterface
{
- private $token;
- private $accessDecisionManager;
- private $authenticationManager;
- private $alwaysAuthenticate;
+ /**
+ * @var TokenStorageInterface
+ */
+ private $tokenStorage;
/**
- * Constructor.
- *
- * @param AuthenticationManagerInterface $authenticationManager An AuthenticationManager instance
- * @param AccessDecisionManagerInterface|null $accessDecisionManager An AccessDecisionManager instance
- * @param bool $alwaysAuthenticate
+ * @var AuthorizationCheckerInterface
*/
- public function __construct(AuthenticationManagerInterface $authenticationManager, AccessDecisionManagerInterface $accessDecisionManager, $alwaysAuthenticate = false)
- {
- $this->authenticationManager = $authenticationManager;
- $this->accessDecisionManager = $accessDecisionManager;
- $this->alwaysAuthenticate = $alwaysAuthenticate;
- }
+ private $authorizationChecker;
/**
- * {@inheritdoc}
+ * For backwards compatibility, the signature of sf <2.6 still works
*
- * @throws AuthenticationCredentialsNotFoundException when the security context has no authentication token.
+ * @param TokenStorageInterface|AuthenticationManagerInterface $tokenStorage
+ * @param AuthorizationCheckerInterface|AccessDecisionManagerInterface $authorizationChecker
+ * @param bool $alwaysAuthenticate only applicable with old signature
*/
- final public function isGranted($attributes, $object = null)
+ public function __construct($tokenStorage, $authorizationChecker, $alwaysAuthenticate = false)
{
- if (null === $this->token) {
- throw new AuthenticationCredentialsNotFoundException('The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.');
- }
+ $oldSignature = $tokenStorage instanceof AuthenticationManagerInterface && $authorizationChecker instanceof AccessDecisionManagerInterface;
+ $newSignature = $tokenStorage instanceof TokenStorageInterface && $authorizationChecker instanceof AuthorizationCheckerInterface;
- if ($this->alwaysAuthenticate || !$this->token->isAuthenticated()) {
- $this->token = $this->authenticationManager->authenticate($this->token);
+ // confirm possible signatures
+ if (!$oldSignature && !$newSignature) {
+ throw new \BadMethodCallException('Unable to construct SecurityContext, please provide the correct arguments');
}
- if (!is_array($attributes)) {
- $attributes = array($attributes);
+ if ($oldSignature) {
+ // renamed for clarity
+ $authenticationManager = $tokenStorage;
+ $accessDecisionManager = $authorizationChecker;
+ $tokenStorage = new TokenStorage();
+ $authorizationChecker = new AuthorizationChecker($tokenStorage, $authenticationManager, $accessDecisionManager, $alwaysAuthenticate);
}
- return $this->accessDecisionManager->decide($this->token, $attributes, $object);
+ $this->tokenStorage = $tokenStorage;
+ $this->authorizationChecker = $authorizationChecker;
}
/**
@@ -72,7 +74,7 @@ class SecurityContext implements SecurityContextInterface
*/
public function getToken()
{
- return $this->token;
+ return $this->tokenStorage->getToken();
}
/**
@@ -80,6 +82,14 @@ class SecurityContext implements SecurityContextInterface
*/
public function setToken(TokenInterface $token = null)
{
- $this->token = $token;
+ return $this->tokenStorage->setToken($token);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isGranted($attributes, $object = null)
+ {
+ return $this->authorizationChecker->isGranted($attributes, $object);
}
}
diff --git a/Core/SecurityContextInterface.php b/Core/SecurityContextInterface.php
index 50c30bb..bceb506 100644
--- a/Core/SecurityContextInterface.php
+++ b/Core/SecurityContextInterface.php
@@ -11,40 +11,18 @@
namespace Symfony\Component\Security\Core;
-use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
+use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* The SecurityContextInterface.
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ * @deprecated Deprecated since version 2.6, to be removed in 3.0.
*/
-interface SecurityContextInterface
+interface SecurityContextInterface extends TokenStorageInterface, AuthorizationCheckerInterface
{
- const ACCESS_DENIED_ERROR = '_security.403_error';
- const AUTHENTICATION_ERROR = '_security.last_error';
- const LAST_USERNAME = '_security.last_username';
-
- /**
- * Returns the current security token.
- *
- * @return TokenInterface|null A TokenInterface instance or null if no authentication information is available
- */
- public function getToken();
-
- /**
- * Sets the authentication token.
- *
- * @param TokenInterface $token A TokenInterface token, or null if no further authentication information should be stored
- */
- public function setToken(TokenInterface $token = null);
-
- /**
- * Checks if the attributes are granted against the current authentication token and optionally supplied object.
- *
- * @param mixed $attributes
- * @param mixed $object
- *
- * @return bool
- */
- public function isGranted($attributes, $object = null);
+ const ACCESS_DENIED_ERROR = Security::ACCESS_DENIED_ERROR;
+ const AUTHENTICATION_ERROR = Security::AUTHENTICATION_ERROR;
+ const LAST_USERNAME = Security::LAST_USERNAME;
}
diff --git a/Tests/Core/Authentication/AuthenticationProviderManagerTest.php b/Core/Tests/Authentication/AuthenticationProviderManagerTest.php
index 32e6cf7..df25874 100644
--- a/Tests/Core/Authentication/AuthenticationProviderManagerTest.php
+++ b/Core/Tests/Authentication/AuthenticationProviderManagerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication;
+namespace Symfony\Component\Security\Core\Tests\Authentication;
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
use Symfony\Component\Security\Core\Exception\ProviderNotFoundException;
@@ -129,7 +129,7 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
} elseif (null !== $exception) {
$provider->expects($this->once())
->method('authenticate')
- ->will($this->throwException($this->getMock($exception, null, array(), '', true)))
+ ->will($this->throwException($this->getMock($exception, null, array(), '')))
;
}
diff --git a/Tests/Core/Authentication/AuthenticationTrustResolverTest.php b/Core/Tests/Authentication/AuthenticationTrustResolverTest.php
index e2fc593..3640981 100644
--- a/Tests/Core/Authentication/AuthenticationTrustResolverTest.php
+++ b/Core/Tests/Authentication/AuthenticationTrustResolverTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication;
+namespace Symfony\Component\Security\Core\Tests\Authentication;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver;
diff --git a/Tests/Core/Authentication/Provider/AnonymousAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php
index d0da147..5a189b0 100644
--- a/Tests/Core/Authentication/Provider/AnonymousAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider;
diff --git a/Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php
index 18e9669..3eedb8e 100644
--- a/Tests/Core/Authentication/Provider/DaoAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
diff --git a/Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php
index 17234b6..5fd7b05 100644
--- a/Tests/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\PreAuthenticatedAuthenticationProvider;
use Symfony\Component\Security\Core\Exception\LockedException;
diff --git a/Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php
index 54fb4ea..a6fff4b 100644
--- a/Tests/Core/Authentication/Provider/RememberMeAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
use Symfony\Component\Security\Core\Exception\DisabledException;
diff --git a/Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php b/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php
index 32f5b10..0503054 100644
--- a/Tests/Core/Authentication/Provider/UserAuthenticationProviderTest.php
+++ b/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
diff --git a/Tests/Core/Authentication/RememberMe/InMemoryTokenProviderTest.php b/Core/Tests/Authentication/RememberMe/InMemoryTokenProviderTest.php
index 1739714..3bdf38c 100644
--- a/Tests/Core/Authentication/RememberMe/InMemoryTokenProviderTest.php
+++ b/Core/Tests/Authentication/RememberMe/InMemoryTokenProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\RememberMe;
+namespace Symfony\Component\Security\Core\Tests\Authentication\RememberMe;
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
use Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider;
diff --git a/Tests/Core/Authentication/RememberMe/PersistentTokenTest.php b/Core/Tests/Authentication/RememberMe/PersistentTokenTest.php
index 3903591..903c030 100644
--- a/Tests/Core/Authentication/RememberMe/PersistentTokenTest.php
+++ b/Core/Tests/Authentication/RememberMe/PersistentTokenTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\RememberMe;
+namespace Symfony\Component\Security\Core\Tests\Authentication\RememberMe;
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
diff --git a/Tests/Core/Authentication/Token/AbstractTokenTest.php b/Core/Tests/Authentication/Token/AbstractTokenTest.php
index b8be628..6f2b6ed 100644
--- a/Tests/Core/Authentication/Token/AbstractTokenTest.php
+++ b/Core/Tests/Authentication/Token/AbstractTokenTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Token;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Core/Authentication/Token/AnonymousTokenTest.php b/Core/Tests/Authentication/Token/AnonymousTokenTest.php
index 135397b..b5cf006 100644
--- a/Tests/Core/Authentication/Token/AnonymousTokenTest.php
+++ b/Core/Tests/Authentication/Token/AnonymousTokenTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Token;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Core/Authentication/Token/PreAuthenticatedTokenTest.php b/Core/Tests/Authentication/Token/PreAuthenticatedTokenTest.php
index 59a533a..77d2608 100644
--- a/Tests/Core/Authentication/Token/PreAuthenticatedTokenTest.php
+++ b/Core/Tests/Authentication/Token/PreAuthenticatedTokenTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Token;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Core/Authentication/Token/RememberMeTokenTest.php b/Core/Tests/Authentication/Token/RememberMeTokenTest.php
index cef3d28..691f54c 100644
--- a/Tests/Core/Authentication/Token/RememberMeTokenTest.php
+++ b/Core/Tests/Authentication/Token/RememberMeTokenTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Token;
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Core/Tests/Authentication/Token/Storage/TokenStorageTest.php b/Core/Tests/Authentication/Token/Storage/TokenStorageTest.php
new file mode 100644
index 0000000..d06e3f0
--- /dev/null
+++ b/Core/Tests/Authentication/Token/Storage/TokenStorageTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Authentication\Token\Storage;
+
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+
+class TokenStorageTest extends \PHPUnit_Framework_TestCase
+{
+ public function testGetSetToken()
+ {
+ $tokenStorage = new TokenStorage();
+ $this->assertNull($tokenStorage->getToken());
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $tokenStorage->setToken($token);
+ $this->assertSame($token, $tokenStorage->getToken());
+ }
+}
diff --git a/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php b/Core/Tests/Authentication/Token/UsernamePasswordTokenTest.php
index 67f431f..0297eff 100644
--- a/Tests/Core/Authentication/Token/UsernamePasswordTokenTest.php
+++ b/Core/Tests/Authentication/Token/UsernamePasswordTokenTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authentication\Token;
+namespace Symfony\Component\Security\Core\Tests\Authentication\Token;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Core/Authorization/AccessDecisionManagerTest.php b/Core/Tests/Authorization/AccessDecisionManagerTest.php
index 74e790a..ae5894d 100644
--- a/Tests/Core/Authorization/AccessDecisionManagerTest.php
+++ b/Core/Tests/Authorization/AccessDecisionManagerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authorization;
+namespace Symfony\Component\Security\Core\Tests\Authorization;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
@@ -55,6 +55,14 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
}
/**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testSetUnsupportedStrategy()
+ {
+ new AccessDecisionManager(array($this->getVoter(VoterInterface::ACCESS_GRANTED)), 'fooBar');
+ }
+
+ /**
* @dataProvider getStrategyTests
*/
public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions, $expected)
@@ -111,34 +119,34 @@ class AccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
{
return array(
// affirmative
- array('affirmative', $this->getVoters(1, 0, 0), false, true, true),
- array('affirmative', $this->getVoters(1, 2, 0), false, true, true),
- array('affirmative', $this->getVoters(0, 1, 0), false, true, false),
- array('affirmative', $this->getVoters(0, 0, 1), false, true, false),
- array('affirmative', $this->getVoters(0, 0, 1), true, true, true),
+ array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 0, 0), false, true, true),
+ array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 2, 0), false, true, true),
+ array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 1, 0), false, true, false),
+ array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), false, true, false),
+ array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), true, true, true),
// consensus
- array('consensus', $this->getVoters(1, 0, 0), false, true, true),
- array('consensus', $this->getVoters(1, 2, 0), false, true, false),
- array('consensus', $this->getVoters(2, 1, 0), false, true, true),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 0, 0), false, true, true),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 2, 0), false, true, false),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 1, 0), false, true, true),
- array('consensus', $this->getVoters(0, 0, 1), false, true, false),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), false, true, false),
- array('consensus', $this->getVoters(0, 0, 1), true, true, true),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), true, true, true),
- array('consensus', $this->getVoters(2, 2, 0), false, true, true),
- array('consensus', $this->getVoters(2, 2, 1), false, true, true),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, true, true),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, true, true),
- array('consensus', $this->getVoters(2, 2, 0), false, false, false),
- array('consensus', $this->getVoters(2, 2, 1), false, false, false),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, false, false),
+ array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, false, false),
// unanimous
- array('unanimous', $this->getVoters(1, 0, 0), false, true, true),
- array('unanimous', $this->getVoters(1, 0, 1), false, true, true),
- array('unanimous', $this->getVoters(1, 1, 0), false, true, false),
+ array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 0), false, true, true),
+ array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 1), false, true, true),
+ array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 1, 0), false, true, false),
- array('unanimous', $this->getVoters(0, 0, 2), false, true, false),
- array('unanimous', $this->getVoters(0, 0, 2), true, true, true),
+ array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), false, true, false),
+ array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), true, true, true),
);
}
diff --git a/Core/Tests/Authorization/AuthorizationCheckerTest.php b/Core/Tests/Authorization/AuthorizationCheckerTest.php
new file mode 100644
index 0000000..64de6ef
--- /dev/null
+++ b/Core/Tests/Authorization/AuthorizationCheckerTest.php
@@ -0,0 +1,99 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Authorization;
+
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
+
+class AuthorizationCheckerTest extends \PHPUnit_Framework_TestCase
+{
+ private $authenticationManager;
+ private $accessDecisionManager;
+ private $authorizationChecker;
+ private $tokenStorage;
+
+ public function setUp()
+ {
+ $this->authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+ $this->accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
+ $this->tokenStorage = new TokenStorage();
+
+ $this->authorizationChecker = new AuthorizationChecker(
+ $this->tokenStorage,
+ $this->authenticationManager,
+ $this->accessDecisionManager
+ );
+ }
+
+ public function testVoteAuthenticatesTokenIfNecessary()
+ {
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $this->tokenStorage->setToken($token);
+
+ $newToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+
+ $this->authenticationManager
+ ->expects($this->once())
+ ->method('authenticate')
+ ->with($this->equalTo($token))
+ ->will($this->returnValue($newToken));
+
+ // default with() isn't a strict check
+ $tokenComparison = function ($value) use ($newToken) {
+ // make sure that the new token is used in "decide()" and not the old one
+ return $value === $newToken;
+ };
+
+ $this->accessDecisionManager
+ ->expects($this->once())
+ ->method('decide')
+ ->with($this->callback($tokenComparison))
+ ->will($this->returnValue(true));
+
+ // first run the token has not been re-authenticated yet, after isGranted is called, it should be equal
+ $this->assertFalse($newToken === $this->tokenStorage->getToken());
+ $this->assertTrue($this->authorizationChecker->isGranted('foo'));
+ $this->assertTrue($newToken === $this->tokenStorage->getToken());
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
+ */
+ public function testVoteWithoutAuthenticationToken()
+ {
+ $this->authorizationChecker->isGranted('ROLE_FOO');
+ }
+
+ /**
+ * @dataProvider isGrantedProvider
+ */
+ public function testIsGranted($decide)
+ {
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $token
+ ->expects($this->once())
+ ->method('isAuthenticated')
+ ->will($this->returnValue(true));
+
+ $this->accessDecisionManager
+ ->expects($this->once())
+ ->method('decide')
+ ->will($this->returnValue($decide));
+ $this->tokenStorage->setToken($token);
+ $this->assertTrue($decide === $this->authorizationChecker->isGranted('ROLE_FOO'));
+ }
+
+ public function isGrantedProvider()
+ {
+ return array(array(true), array(false));
+ }
+}
diff --git a/Core/Tests/Authorization/ExpressionLanguageTest.php b/Core/Tests/Authorization/ExpressionLanguageTest.php
new file mode 100644
index 0000000..5b4aca6
--- /dev/null
+++ b/Core/Tests/Authorization/ExpressionLanguageTest.php
@@ -0,0 +1,79 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Authorization;
+
+use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
+use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver;
+use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
+use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
+use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
+use Symfony\Component\Security\Core\User\User;
+
+class ExpressionLanguageTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider provider
+ */
+ public function testIsAuthenticated($token, $expression, $result, array $roles = array())
+ {
+ $anonymousTokenClass = 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\AnonymousToken';
+ $rememberMeTokenClass = 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\RememberMeToken';
+ $expressionLanguage = new ExpressionLanguage();
+ $trustResolver = new AuthenticationTrustResolver($anonymousTokenClass, $rememberMeTokenClass);
+
+ $context = array();
+ $context['trust_resolver'] = $trustResolver;
+ $context['token'] = $token;
+ $context['roles'] = $roles;
+
+ $this->assertEquals($result, $expressionLanguage->evaluate($expression, $context));
+ }
+
+ public function provider()
+ {
+ $roles = array('ROLE_USER', 'ROLE_ADMIN');
+ $user = new User('username', 'password', $roles);
+
+ $noToken = null;
+ $anonymousToken = new AnonymousToken('firewall', 'anon.');
+ $rememberMeToken = new RememberMeToken($user, 'providerkey', 'firewall');
+ $usernamePasswordToken = new UsernamePasswordToken('username', 'password', 'providerkey', $roles);
+
+ return array(
+ array($noToken, 'is_anonymous()', false),
+ array($noToken, 'is_authenticated()', false),
+ array($noToken, 'is_fully_authenticated()', false),
+ array($noToken, 'is_remember_me()', false),
+ array($noToken, "has_role('ROLE_USER')", false),
+
+ array($anonymousToken, 'is_anonymous()', true),
+ array($anonymousToken, 'is_authenticated()', false),
+ array($anonymousToken, 'is_fully_authenticated()', false),
+ array($anonymousToken, 'is_remember_me()', false),
+ array($anonymousToken, "has_role('ROLE_USER')", false),
+
+ array($rememberMeToken, 'is_anonymous()', false),
+ array($rememberMeToken, 'is_authenticated()', true),
+ array($rememberMeToken, 'is_fully_authenticated()', false),
+ array($rememberMeToken, 'is_remember_me()', true),
+ array($rememberMeToken, "has_role('ROLE_FOO')", false, $roles),
+ array($rememberMeToken, "has_role('ROLE_USER')", true, $roles),
+
+ array($usernamePasswordToken, 'is_anonymous()', false),
+ array($usernamePasswordToken, 'is_authenticated()', true),
+ array($usernamePasswordToken, 'is_fully_authenticated()', true),
+ array($usernamePasswordToken, 'is_remember_me()', false),
+ array($usernamePasswordToken, "has_role('ROLE_FOO')", false, $roles),
+ array($usernamePasswordToken, "has_role('ROLE_USER')", true, $roles),
+ );
+ }
+}
diff --git a/Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php b/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php
index b077712..4679c0f 100644
--- a/Tests/Core/Authorization/Voter/AuthenticatedVoterTest.php
+++ b/Core/Tests/Authorization/Voter/AuthenticatedVoterTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authorization\Voter;
+namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolver;
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
diff --git a/Core/Tests/Authorization/Voter/ExpressionVoterTest.php b/Core/Tests/Authorization/Voter/ExpressionVoterTest.php
new file mode 100644
index 0000000..dc8ea79
--- /dev/null
+++ b/Core/Tests/Authorization/Voter/ExpressionVoterTest.php
@@ -0,0 +1,97 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
+
+use Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter;
+use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
+use Symfony\Component\Security\Core\Role\Role;
+
+class ExpressionVoterTest extends \PHPUnit_Framework_TestCase
+{
+ public function testSupportsAttribute()
+ {
+ $expression = $this->createExpression();
+ $expressionLanguage = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage');
+ $voter = new ExpressionVoter($expressionLanguage, $this->createTrustResolver(), $this->createRoleHierarchy());
+
+ $this->assertTrue($voter->supportsAttribute($expression));
+ }
+
+ /**
+ * @dataProvider getVoteTests
+ */
+ public function testVote($roles, $attributes, $expected, $tokenExpectsGetRoles = true, $expressionLanguageExpectsEvaluate = true)
+ {
+ $voter = new ExpressionVoter($this->createExpressionLanguage($expressionLanguageExpectsEvaluate), $this->createTrustResolver());
+
+ $this->assertSame($expected, $voter->vote($this->getToken($roles, $tokenExpectsGetRoles), null, $attributes));
+ }
+
+ public function getVoteTests()
+ {
+ return array(
+ array(array(), array(), VoterInterface::ACCESS_ABSTAIN, false, false),
+ array(array(), array('FOO'), VoterInterface::ACCESS_ABSTAIN, false, false),
+
+ array(array(), array($this->createExpression()), VoterInterface::ACCESS_DENIED, true, false),
+
+ array(array('ROLE_FOO'), array($this->createExpression(), $this->createExpression()), VoterInterface::ACCESS_GRANTED),
+ array(array('ROLE_BAR', 'ROLE_FOO'), array($this->createExpression()), VoterInterface::ACCESS_GRANTED),
+ );
+ }
+
+ protected function getToken(array $roles, $tokenExpectsGetRoles = true)
+ {
+ foreach ($roles as $i => $role) {
+ $roles[$i] = new Role($role);
+ }
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+
+ if ($tokenExpectsGetRoles) {
+ $token->expects($this->once())
+ ->method('getRoles')
+ ->will($this->returnValue($roles));
+ }
+
+ return $token;
+ }
+
+ protected function createExpressionLanguage($expressionLanguageExpectsEvaluate = true)
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage');
+
+ if ($expressionLanguageExpectsEvaluate) {
+ $mock->expects($this->once())
+ ->method('evaluate')
+ ->will($this->returnValue(true));
+ }
+
+ return $mock;
+ }
+
+ protected function createTrustResolver()
+ {
+ return $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface');
+ }
+
+ protected function createRoleHierarchy()
+ {
+ return $this->getMock('Symfony\Component\Security\Core\Role\RoleHierarchyInterface');
+ }
+
+ protected function createExpression()
+ {
+ return $this->getMockBuilder('Symfony\Component\ExpressionLanguage\Expression')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+}
diff --git a/Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php b/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php
index a50fa79..c50ecf3 100644
--- a/Tests/Core/Authorization/Voter/RoleHierarchyVoterTest.php
+++ b/Core/Tests/Authorization/Voter/RoleHierarchyVoterTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authorization\Voter;
+namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
use Symfony\Component\Security\Core\Authorization\Voter\RoleHierarchyVoter;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
diff --git a/Tests/Core/Authorization/Voter/RoleVoterTest.php b/Core/Tests/Authorization/Voter/RoleVoterTest.php
index 8a5cdc5..03ab2da 100644
--- a/Tests/Core/Authorization/Voter/RoleVoterTest.php
+++ b/Core/Tests/Authorization/Voter/RoleVoterTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Authorization\Voter;
+namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
use Symfony\Component\Security\Core\Authorization\Voter\RoleVoter;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
diff --git a/Tests/Core/Encoder/BCryptPasswordEncoderTest.php b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php
index 61e2afe..2f7b845 100644
--- a/Tests/Core/Encoder/BCryptPasswordEncoderTest.php
+++ b/Core/Tests/Encoder/BCryptPasswordEncoderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Encoder;
+namespace Symfony\Component\Security\Core\Tests\Encoder;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
diff --git a/Tests/Core/Encoder/BasePasswordEncoderTest.php b/Core/Tests/Encoder/BasePasswordEncoderTest.php
index 702efb0..14c488b 100644
--- a/Tests/Core/Encoder/BasePasswordEncoderTest.php
+++ b/Core/Tests/Encoder/BasePasswordEncoderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Encoder;
+namespace Symfony\Component\Security\Core\Tests\Encoder;
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
diff --git a/Tests/Core/Encoder/EncoderFactoryTest.php b/Core/Tests/Encoder/EncoderFactoryTest.php
index 85d4e91..a8ca2f0 100644
--- a/Tests/Core/Encoder/EncoderFactoryTest.php
+++ b/Core/Tests/Encoder/EncoderFactoryTest.php
@@ -9,10 +9,11 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Encoder;
+namespace Symfony\Component\Security\Core\Tests\Encoder;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\EncoderFactory;
+use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Core\User\UserInterface;
@@ -52,7 +53,7 @@ class EncoderFactoryTest extends \PHPUnit_Framework_TestCase
'Symfony\Component\Security\Core\User\UserInterface' => new MessageDigestPasswordEncoder('sha1'),
));
- $encoder = $factory->getEncoder('Symfony\Component\Security\Tests\Core\Encoder\SomeChildUser');
+ $encoder = $factory->getEncoder('Symfony\Component\Security\Core\Tests\Encoder\SomeChildUser');
$expectedEncoder = new MessageDigestPasswordEncoder('sha1');
$this->assertEquals($expectedEncoder->encodePassword('foo', ''), $encoder->encodePassword('foo', ''));
}
@@ -71,10 +72,63 @@ class EncoderFactoryTest extends \PHPUnit_Framework_TestCase
public function testGetEncoderConfiguredForConcreteClassWithClassName()
{
$factory = new EncoderFactory(array(
- 'Symfony\Component\Security\Tests\Core\Encoder\SomeUser' => new MessageDigestPasswordEncoder('sha1'),
+ 'Symfony\Component\Security\Core\Tests\Encoder\SomeUser' => new MessageDigestPasswordEncoder('sha1'),
));
- $encoder = $factory->getEncoder('Symfony\Component\Security\Tests\Core\Encoder\SomeChildUser');
+ $encoder = $factory->getEncoder('Symfony\Component\Security\Core\Tests\Encoder\SomeChildUser');
+ $expectedEncoder = new MessageDigestPasswordEncoder('sha1');
+ $this->assertEquals($expectedEncoder->encodePassword('foo', ''), $encoder->encodePassword('foo', ''));
+ }
+
+ public function testGetNamedEncoderForEncoderAware()
+ {
+ $factory = new EncoderFactory(array(
+ 'Symfony\Component\Security\Core\Tests\Encoder\EncAwareUser' => new MessageDigestPasswordEncoder('sha256'),
+ 'encoder_name' => new MessageDigestPasswordEncoder('sha1'),
+ ));
+
+ $encoder = $factory->getEncoder(new EncAwareUser('user', 'pass'));
+ $expectedEncoder = new MessageDigestPasswordEncoder('sha1');
+ $this->assertEquals($expectedEncoder->encodePassword('foo', ''), $encoder->encodePassword('foo', ''));
+ }
+
+ public function testGetNullNamedEncoderForEncoderAware()
+ {
+ $factory = new EncoderFactory(array(
+ 'Symfony\Component\Security\Core\Tests\Encoder\EncAwareUser' => new MessageDigestPasswordEncoder('sha1'),
+ 'encoder_name' => new MessageDigestPasswordEncoder('sha256'),
+ ));
+
+ $user = new EncAwareUser('user', 'pass');
+ $user->encoderName = null;
+ $encoder = $factory->getEncoder($user);
+ $expectedEncoder = new MessageDigestPasswordEncoder('sha1');
+ $this->assertEquals($expectedEncoder->encodePassword('foo', ''), $encoder->encodePassword('foo', ''));
+ }
+
+ /**
+ * @expectedException RuntimeException
+ */
+ public function testGetInvalidNamedEncoderForEncoderAware()
+ {
+ $factory = new EncoderFactory(array(
+ 'Symfony\Component\Security\Core\Tests\Encoder\EncAwareUser' => new MessageDigestPasswordEncoder('sha1'),
+ 'encoder_name' => new MessageDigestPasswordEncoder('sha256'),
+ ));
+
+ $user = new EncAwareUser('user', 'pass');
+ $user->encoderName = 'invalid_encoder_name';
+ $encoder = $factory->getEncoder($user);
+ }
+
+ public function testGetEncoderForEncoderAwareWithClassName()
+ {
+ $factory = new EncoderFactory(array(
+ 'Symfony\Component\Security\Core\Tests\Encoder\EncAwareUser' => new MessageDigestPasswordEncoder('sha1'),
+ 'encoder_name' => new MessageDigestPasswordEncoder('sha256'),
+ ));
+
+ $encoder = $factory->getEncoder('Symfony\Component\Security\Core\Tests\Encoder\EncAwareUser');
$expectedEncoder = new MessageDigestPasswordEncoder('sha1');
$this->assertEquals($expectedEncoder->encodePassword('foo', ''), $encoder->encodePassword('foo', ''));
}
@@ -102,3 +156,13 @@ class SomeUser implements UserInterface
class SomeChildUser extends SomeUser
{
}
+
+class EncAwareUser extends SomeUser implements EncoderAwareInterface
+{
+ public $encoderName = 'encoder_name';
+
+ public function getEncoderName()
+ {
+ return $this->encoderName;
+ }
+}
diff --git a/Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php b/Core/Tests/Encoder/MessageDigestPasswordEncoderTest.php
index f37d3bc..5189fff 100644
--- a/Tests/Core/Encoder/MessageDigestPasswordEncoderTest.php
+++ b/Core/Tests/Encoder/MessageDigestPasswordEncoderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Encoder;
+namespace Symfony\Component\Security\Core\Tests\Encoder;
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
diff --git a/Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php b/Core/Tests/Encoder/Pbkdf2PasswordEncoderTest.php
index ca16f02..3e9452b 100644
--- a/Tests/Core/Encoder/Pbkdf2PasswordEncoderTest.php
+++ b/Core/Tests/Encoder/Pbkdf2PasswordEncoderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Encoder;
+namespace Symfony\Component\Security\Core\Tests\Encoder;
use Symfony\Component\Security\Core\Encoder\Pbkdf2PasswordEncoder;
diff --git a/Tests/Core/Encoder/PlaintextPasswordEncoderTest.php b/Core/Tests/Encoder/PlaintextPasswordEncoderTest.php
index 8b1b888..c7e0d2a 100644
--- a/Tests/Core/Encoder/PlaintextPasswordEncoderTest.php
+++ b/Core/Tests/Encoder/PlaintextPasswordEncoderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Encoder;
+namespace Symfony\Component\Security\Core\Tests\Encoder;
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
diff --git a/Core/Tests/Encoder/UserPasswordEncoderTest.php b/Core/Tests/Encoder/UserPasswordEncoderTest.php
new file mode 100644
index 0000000..590652d
--- /dev/null
+++ b/Core/Tests/Encoder/UserPasswordEncoderTest.php
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Encoder;
+
+use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
+
+class UserPasswordEncoderTest extends \PHPUnit_Framework_TestCase
+{
+ public function testEncodePassword()
+ {
+ $userMock = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $userMock->expects($this->any())
+ ->method('getSalt')
+ ->will($this->returnValue('userSalt'));
+
+ $mockEncoder = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
+ $mockEncoder->expects($this->any())
+ ->method('encodePassword')
+ ->with($this->equalTo('plainPassword'), $this->equalTo('userSalt'))
+ ->will($this->returnValue('encodedPassword'));
+
+ $mockEncoderFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
+ $mockEncoderFactory->expects($this->any())
+ ->method('getEncoder')
+ ->with($this->equalTo($userMock))
+ ->will($this->returnValue($mockEncoder));
+
+ $passwordEncoder = new UserPasswordEncoder($mockEncoderFactory);
+
+ $encoded = $passwordEncoder->encodePassword($userMock, 'plainPassword');
+ $this->assertEquals('encodedPassword', $encoded);
+ }
+
+ public function testIsPasswordValid()
+ {
+ $userMock = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $userMock->expects($this->any())
+ ->method('getSalt')
+ ->will($this->returnValue('userSalt'));
+ $userMock->expects($this->any())
+ ->method('getPassword')
+ ->will($this->returnValue('encodedPassword'));
+
+ $mockEncoder = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
+ $mockEncoder->expects($this->any())
+ ->method('isPasswordValid')
+ ->with($this->equalTo('encodedPassword'), $this->equalTo('plainPassword'), $this->equalTo('userSalt'))
+ ->will($this->returnValue(true));
+
+ $mockEncoderFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
+ $mockEncoderFactory->expects($this->any())
+ ->method('getEncoder')
+ ->with($this->equalTo($userMock))
+ ->will($this->returnValue($mockEncoder));
+
+ $passwordEncoder = new UserPasswordEncoder($mockEncoderFactory);
+
+ $isValid = $passwordEncoder->isPasswordValid($userMock, 'plainPassword');
+ $this->assertTrue($isValid);
+ }
+}
diff --git a/Core/Tests/Exception/UsernameNotFoundExceptionTest.php b/Core/Tests/Exception/UsernameNotFoundExceptionTest.php
new file mode 100644
index 0000000..98ea374
--- /dev/null
+++ b/Core/Tests/Exception/UsernameNotFoundExceptionTest.php
@@ -0,0 +1,25 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Exception;
+
+use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
+
+class UsernameNotFoundExceptionTest extends \PHPUnit_Framework_TestCase
+{
+ public function testGetMessageData()
+ {
+ $exception = new UsernameNotFoundException('Username could not be found.');
+ $this->assertEquals(array('{{ username }}' => null), $exception->getMessageData());
+ $exception->setUsername('username');
+ $this->assertEquals(array('{{ username }}' => 'username'), $exception->getMessageData());
+ }
+}
diff --git a/Tests/Core/Role/RoleHierarchyTest.php b/Core/Tests/Role/RoleHierarchyTest.php
index a98aed6..df1b6a3 100644
--- a/Tests/Core/Role/RoleHierarchyTest.php
+++ b/Core/Tests/Role/RoleHierarchyTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Role;
+namespace Symfony\Component\Security\Core\Tests\Role;
use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Core/Role/RoleTest.php b/Core/Tests/Role/RoleTest.php
index e2e7ca8..02be07b 100644
--- a/Tests/Core/Role/RoleTest.php
+++ b/Core/Tests/Role/RoleTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Role;
+namespace Symfony\Component\Security\Core\Tests\Role;
use Symfony\Component\Security\Core\Role\Role;
diff --git a/Tests/Core/Role/SwitchUserRoleTest.php b/Core/Tests/Role/SwitchUserRoleTest.php
index bf9b173..f0ce468 100644
--- a/Tests/Core/Role/SwitchUserRoleTest.php
+++ b/Core/Tests/Role/SwitchUserRoleTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Role;
+namespace Symfony\Component\Security\Core\Tests\Role;
use Symfony\Component\Security\Core\Role\SwitchUserRole;
diff --git a/Core/Tests/SecurityContextTest.php b/Core/Tests/SecurityContextTest.php
new file mode 100644
index 0000000..886c596
--- /dev/null
+++ b/Core/Tests/SecurityContextTest.php
@@ -0,0 +1,119 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests;
+
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
+use Symfony\Component\Security\Core\SecurityContext;
+
+class SecurityContextTest extends \PHPUnit_Framework_TestCase
+{
+ private $tokenStorage;
+ private $authorizationChecker;
+ private $securityContext;
+
+ public function setUp()
+ {
+ $this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $this->authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
+ $this->securityContext = new SecurityContext($this->tokenStorage, $this->authorizationChecker);
+ }
+
+ public function testGetTokenDelegation()
+ {
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+
+ $this->tokenStorage
+ ->expects($this->once())
+ ->method('getToken')
+ ->will($this->returnValue($token));
+
+ $this->assertTrue($token === $this->securityContext->getToken());
+ }
+
+ public function testSetTokenDelegation()
+ {
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+
+ $this->tokenStorage
+ ->expects($this->once())
+ ->method('setToken')
+ ->with($token);
+
+ $this->securityContext->setToken($token);
+ }
+
+ /**
+ * @dataProvider isGrantedDelegationProvider
+ */
+ public function testIsGrantedDelegation($attributes, $object, $return)
+ {
+ $this->authorizationChecker
+ ->expects($this->once())
+ ->method('isGranted')
+ ->with($attributes, $object)
+ ->will($this->returnValue($return));
+
+ $this->assertEquals($return, $this->securityContext->isGranted($attributes, $object));
+ }
+
+ public function isGrantedDelegationProvider()
+ {
+ return array(
+ array(array(), new \stdClass(), true),
+ array(array('henk'), new \stdClass(), false),
+ array(null, new \stdClass(), false),
+ array('henk', null, true),
+ array(array(1), 'henk', true),
+ );
+ }
+
+ /**
+ * Test dedicated to check if the backwards compatibility is still working
+ */
+ public function testOldConstructorSignature()
+ {
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+ $accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
+ new SecurityContext($authenticationManager, $accessDecisionManager);
+ }
+
+ /**
+ * @dataProvider oldConstructorSignatureFailuresProvider
+ * @expectedException \BadMethodCallException
+ */
+ public function testOldConstructorSignatureFailures($first, $second)
+ {
+ new SecurityContext($first, $second);
+ }
+
+ public function oldConstructorSignatureFailuresProvider()
+ {
+ $tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
+ $authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+ $accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
+
+ return array(
+ array(new \stdClass(), new \stdClass()),
+ array($tokenStorage, $accessDecisionManager),
+ array($accessDecisionManager, $tokenStorage),
+ array($authorizationChecker, $accessDecisionManager),
+ array($accessDecisionManager, $authorizationChecker),
+ array($tokenStorage, $accessDecisionManager),
+ array($authenticationManager, $authorizationChecker),
+ array('henk', 'hans'),
+ array(null, false),
+ array(true, null),
+ );
+ }
+}
diff --git a/Tests/Core/User/ChainUserProviderTest.php b/Core/Tests/User/ChainUserProviderTest.php
index 9d38a4c..ab01f47 100644
--- a/Tests/Core/User/ChainUserProviderTest.php
+++ b/Core/Tests/User/ChainUserProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\User;
+namespace Symfony\Component\Security\Core\Tests\User;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\ChainUserProvider;
diff --git a/Tests/Core/User/InMemoryUserProviderTest.php b/Core/Tests/User/InMemoryUserProviderTest.php
index 826e390..dfc4237 100644
--- a/Tests/Core/User/InMemoryUserProviderTest.php
+++ b/Core/Tests/User/InMemoryUserProviderTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\User;
+namespace Symfony\Component\Security\Core\Tests\User;
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Core\User\User;
diff --git a/Tests/Core/User/UserCheckerTest.php b/Core/Tests/User/UserCheckerTest.php
index dca6311..ac21781 100644
--- a/Tests/Core/User/UserCheckerTest.php
+++ b/Core/Tests/User/UserCheckerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\User;
+namespace Symfony\Component\Security\Core\Tests\User;
use Symfony\Component\Security\Core\User\UserChecker;
diff --git a/Tests/Core/User/UserTest.php b/Core/Tests/User/UserTest.php
index d05f491..2fe6daa 100644
--- a/Tests/Core/User/UserTest.php
+++ b/Core/Tests/User/UserTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\User;
+namespace Symfony\Component\Security\Core\Tests\User;
use Symfony\Component\Security\Core\User\User;
diff --git a/Tests/Core/Util/ClassUtilsTest.php b/Core/Tests/Util/ClassUtilsTest.php
index 8359236..e8f0143 100644
--- a/Tests/Core/Util/ClassUtilsTest.php
+++ b/Core/Tests/Util/ClassUtilsTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Util
+namespace Symfony\Component\Security\Core\Tests\Util
{
use Symfony\Component\Security\Core\Util\ClassUtils;
@@ -22,9 +22,9 @@ namespace Symfony\Component\Security\Tests\Core\Util
array('Symfony\Component\Security\Core\Util\ClassUtils', 'Symfony\Component\Security\Core\Util\ClassUtils'),
array('MyProject\Proxies\__CG__\stdClass', 'stdClass'),
array('MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass', 'stdClass'),
- array('MyProject\Proxies\__CG__\Symfony\Component\Security\Tests\Core\Util\ChildObject', 'Symfony\Component\Security\Tests\Core\Util\ChildObject'),
- array(new TestObject(), 'Symfony\Component\Security\Tests\Core\Util\TestObject'),
- array(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Core\Util\TestObject(), 'Symfony\Component\Security\Tests\Core\Util\TestObject'),
+ array('MyProject\Proxies\__CG__\Symfony\Component\Security\Core\Tests\Util\ChildObject', 'Symfony\Component\Security\Core\Tests\Util\ChildObject'),
+ array(new TestObject(), 'Symfony\Component\Security\Core\Tests\Util\TestObject'),
+ array(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Core\Tests\Util\TestObject(), 'Symfony\Component\Security\Core\Tests\Util\TestObject'),
);
}
@@ -42,9 +42,9 @@ namespace Symfony\Component\Security\Tests\Core\Util
}
}
-namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Core\Util
+namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Core\Tests\Util
{
- class TestObject extends \Symfony\Component\Security\Tests\Core\Util\TestObject
+ class TestObject extends \Symfony\Component\Security\Core\Tests\Util\TestObject
{
}
}
diff --git a/Tests/Core/Util/SecureRandomTest.php b/Core/Tests/Util/SecureRandomTest.php
index a8cc660..590efd3 100644
--- a/Tests/Core/Util/SecureRandomTest.php
+++ b/Core/Tests/Util/SecureRandomTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Util;
+namespace Symfony\Component\Security\Core\Tests\Util;
use Symfony\Component\Security\Core\Util\SecureRandom;
diff --git a/Tests/Core/Util/StringUtilsTest.php b/Core/Tests/Util/StringUtilsTest.php
index 3b18d48..faeaf25 100644
--- a/Tests/Core/Util/StringUtilsTest.php
+++ b/Core/Tests/Util/StringUtilsTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Core\Util;
+namespace Symfony\Component\Security\Core\Tests\Util;
use Symfony\Component\Security\Core\Util\StringUtils;
diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php
new file mode 100644
index 0000000..4cba363
--- /dev/null
+++ b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidator2Dot4ApiTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Validator\Constraints;
+
+use Symfony\Component\Validator\Validation;
+
+/**
+ * @since 2.5.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class LegacyUserPasswordValidator2Dot4ApiTest extends UserPasswordValidatorTest
+{
+ protected function getApiVersion()
+ {
+ return Validation::API_VERSION_2_4;
+ }
+}
diff --git a/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php
new file mode 100644
index 0000000..5cfe444
--- /dev/null
+++ b/Core/Tests/Validator/Constraints/LegacyUserPasswordValidatorTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Validator\Constraints;
+
+use Symfony\Component\Validator\Validation;
+
+/**
+ * @since 2.5.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class LegacyUserPasswordValidatorApiTest extends UserPasswordValidatorTest
+{
+ protected function getApiVersion()
+ {
+ return Validation::API_VERSION_2_5_BC;
+ }
+}
diff --git a/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php b/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
new file mode 100644
index 0000000..7792913
--- /dev/null
+++ b/Core/Tests/Validator/Constraints/UserPasswordValidatorTest.php
@@ -0,0 +1,169 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Validator\Constraints;
+
+use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
+use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
+use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
+use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+abstract class UserPasswordValidatorTest extends AbstractConstraintValidatorTest
+{
+ const PASSWORD = 's3Cr3t';
+
+ const SALT = '^S4lt$';
+
+ /**
+ * @var SecurityContextInterface
+ */
+ protected $securityContext;
+
+ /**
+ * @var PasswordEncoderInterface
+ */
+ protected $encoder;
+
+ /**
+ * @var EncoderFactoryInterface
+ */
+ protected $encoderFactory;
+
+ protected function createValidator()
+ {
+ return new UserPasswordValidator($this->securityContext, $this->encoderFactory);
+ }
+
+ protected function setUp()
+ {
+ $user = $this->createUser();
+ $this->securityContext = $this->createSecurityContext($user);
+ $this->encoder = $this->createPasswordEncoder();
+ $this->encoderFactory = $this->createEncoderFactory($this->encoder);
+
+ parent::setUp();
+ }
+
+ public function testPasswordIsValid()
+ {
+ $constraint = new UserPassword(array(
+ 'message' => 'myMessage',
+ ));
+
+ $this->encoder->expects($this->once())
+ ->method('isPasswordValid')
+ ->with(static::PASSWORD, 'secret', static::SALT)
+ ->will($this->returnValue(true));
+
+ $this->validator->validate('secret', $constraint);
+
+ $this->assertNoViolation();
+ }
+
+ public function testPasswordIsNotValid()
+ {
+ $constraint = new UserPassword(array(
+ 'message' => 'myMessage',
+ ));
+
+ $this->encoder->expects($this->once())
+ ->method('isPasswordValid')
+ ->with(static::PASSWORD, 'secret', static::SALT)
+ ->will($this->returnValue(false));
+
+ $this->validator->validate('secret', $constraint);
+
+ $this->buildViolation('myMessage')
+ ->assertRaised();
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
+ */
+ public function testUserIsNotValid()
+ {
+ $user = $this->getMock('Foo\Bar\User');
+
+ $this->securityContext = $this->createSecurityContext($user);
+ $this->validator = $this->createValidator();
+ $this->validator->initialize($this->context);
+
+ $this->validator->validate('secret', new UserPassword());
+ }
+
+ protected function createUser()
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+
+ $mock
+ ->expects($this->any())
+ ->method('getPassword')
+ ->will($this->returnValue(static::PASSWORD))
+ ;
+
+ $mock
+ ->expects($this->any())
+ ->method('getSalt')
+ ->will($this->returnValue(static::SALT))
+ ;
+
+ return $mock;
+ }
+
+ protected function createPasswordEncoder($isPasswordValid = true)
+ {
+ return $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
+ }
+
+ protected function createEncoderFactory($encoder = null)
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
+
+ $mock
+ ->expects($this->any())
+ ->method('getEncoder')
+ ->will($this->returnValue($encoder))
+ ;
+
+ return $mock;
+ }
+
+ protected function createSecurityContext($user = null)
+ {
+ $token = $this->createAuthenticationToken($user);
+
+ $mock = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ $mock
+ ->expects($this->any())
+ ->method('getToken')
+ ->will($this->returnValue($token))
+ ;
+
+ return $mock;
+ }
+
+ protected function createAuthenticationToken($user = null)
+ {
+ $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $mock
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue($user))
+ ;
+
+ return $mock;
+ }
+}
diff --git a/Core/Validator/Constraints/UserPassword.php b/Core/Validator/Constraints/UserPassword.php
index aee4cda..35537b3 100644
--- a/Core/Validator/Constraints/UserPassword.php
+++ b/Core/Validator/Constraints/UserPassword.php
@@ -19,7 +19,7 @@ use Symfony\Component\Validator\Constraint;
*/
class UserPassword extends Constraint
{
- public $message = 'This value should be the user current password.';
+ public $message = 'This value should be the user\'s current password.';
public $service = 'security.validator.user_password';
/**
diff --git a/Core/Validator/Constraints/UserPasswordValidator.php b/Core/Validator/Constraints/UserPasswordValidator.php
index ab455f3..5f9ad2a 100644
--- a/Core/Validator/Constraints/UserPasswordValidator.php
+++ b/Core/Validator/Constraints/UserPasswordValidator.php
@@ -17,6 +17,7 @@ use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class UserPasswordValidator extends ConstraintValidator
{
@@ -34,6 +35,10 @@ class UserPasswordValidator extends ConstraintValidator
*/
public function validate($password, Constraint $constraint)
{
+ if (!$constraint instanceof UserPassword) {
+ throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
+ }
+
$user = $this->securityContext->getToken()->getUser();
if (!$user instanceof UserInterface) {
diff --git a/Core/composer.json b/Core/composer.json
new file mode 100644
index 0000000..f8e289b
--- /dev/null
+++ b/Core/composer.json
@@ -0,0 +1,48 @@
+{
+ "name": "symfony/security-core",
+ "type": "library",
+ "description": "Symfony Security Component - Core Library",
+ "keywords": [],
+ "homepage": "http://symfony.com",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "symfony/phpunit-bridge": "~2.7",
+ "symfony/event-dispatcher": "~2.1",
+ "symfony/expression-language": "~2.6",
+ "symfony/http-foundation": "~2.4",
+ "symfony/translation": "~2.0,>=2.0.5",
+ "symfony/validator": "~2.5,>=2.5.5",
+ "psr/log": "~1.0",
+ "ircmaxell/password-compat": "1.0.*"
+ },
+ "suggest": {
+ "symfony/event-dispatcher": "",
+ "symfony/http-foundation": "",
+ "symfony/validator": "For using the user password constraint",
+ "symfony/expression-language": "For using the expression voter",
+ "ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5"
+ },
+ "autoload": {
+ "psr-0": { "Symfony\\Component\\Security\\Core\\": "" }
+ },
+ "target-dir": "Symfony/Component/Security/Core",
+ "minimum-stability": "dev",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev"
+ }
+ }
+}
diff --git a/Core/phpunit.xml.dist b/Core/phpunit.xml.dist
new file mode 100644
index 0000000..6b2ccb0
--- /dev/null
+++ b/Core/phpunit.xml.dist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="vendor/autoload.php"
+>
+ <php>
+ <ini name="error_reporting" value="-1" />
+ </php>
+ <testsuites>
+ <testsuite name="Symfony Security Component Core Test Suite">
+ <directory>./Tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./vendor</directory>
+ <directory>./Tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/Csrf/.gitignore b/Csrf/.gitignore
new file mode 100644
index 0000000..c49a5d8
--- /dev/null
+++ b/Csrf/.gitignore
@@ -0,0 +1,3 @@
+vendor/
+composer.lock
+phpunit.xml
diff --git a/Csrf/CsrfToken.php b/Csrf/CsrfToken.php
new file mode 100644
index 0000000..9ccaaeb
--- /dev/null
+++ b/Csrf/CsrfToken.php
@@ -0,0 +1,72 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf;
+
+/**
+ * A CSRF token.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class CsrfToken
+{
+ /**
+ * @var string
+ */
+ private $id;
+
+ /**
+ * @var string
+ */
+ private $value;
+
+ /**
+ * Constructor.
+ *
+ * @param string $id The token ID
+ * @param string $value The actual token value
+ */
+ public function __construct($id, $value)
+ {
+ $this->id = (string) $id;
+ $this->value = (string) $value;
+ }
+
+ /**
+ * Returns the ID of the CSRF token.
+ *
+ * @return string The token ID
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Returns the value of the CSRF token.
+ *
+ * @return string The token value
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Returns the value of the CSRF token.
+ *
+ * @return string The token value
+ */
+ public function __toString()
+ {
+ return $this->value;
+ }
+}
diff --git a/Csrf/CsrfTokenManager.php b/Csrf/CsrfTokenManager.php
new file mode 100644
index 0000000..e129502
--- /dev/null
+++ b/Csrf/CsrfTokenManager.php
@@ -0,0 +1,97 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf;
+
+use Symfony\Component\Security\Core\Util\StringUtils;
+use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
+use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
+use Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage;
+use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
+
+/**
+ * Default implementation of {@link CsrfTokenManagerInterface}.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class CsrfTokenManager implements CsrfTokenManagerInterface
+{
+ /**
+ * @var TokenGeneratorInterface
+ */
+ private $generator;
+
+ /**
+ * @var TokenStorageInterface
+ */
+ private $storage;
+
+ /**
+ * Creates a new CSRF provider using PHP's native session storage.
+ *
+ * @param TokenGeneratorInterface|null $generator The token generator
+ * @param TokenStorageInterface|null $storage The storage for storing
+ * generated CSRF tokens
+ */
+ public function __construct(TokenGeneratorInterface $generator = null, TokenStorageInterface $storage = null)
+ {
+ $this->generator = $generator ?: new UriSafeTokenGenerator();
+ $this->storage = $storage ?: new NativeSessionTokenStorage();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getToken($tokenId)
+ {
+ if ($this->storage->hasToken($tokenId)) {
+ $value = $this->storage->getToken($tokenId);
+ } else {
+ $value = $this->generator->generateToken();
+
+ $this->storage->setToken($tokenId, $value);
+ }
+
+ return new CsrfToken($tokenId, $value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function refreshToken($tokenId)
+ {
+ $value = $this->generator->generateToken();
+
+ $this->storage->setToken($tokenId, $value);
+
+ return new CsrfToken($tokenId, $value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function removeToken($tokenId)
+ {
+ return $this->storage->removeToken($tokenId);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isTokenValid(CsrfToken $token)
+ {
+ if (!$this->storage->hasToken($token->getId())) {
+ return false;
+ }
+
+ return StringUtils::equals($this->storage->getToken($token->getId()), $token->getValue());
+ }
+}
diff --git a/Csrf/CsrfTokenManagerInterface.php b/Csrf/CsrfTokenManagerInterface.php
new file mode 100644
index 0000000..5abe47c
--- /dev/null
+++ b/Csrf/CsrfTokenManagerInterface.php
@@ -0,0 +1,68 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf;
+
+/**
+ * Manages CSRF tokens.
+ *
+ * @since 2.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+interface CsrfTokenManagerInterface
+{
+ /**
+ * Returns a CSRF token for the given ID.
+ *
+ * If previously no token existed for the given ID, a new token is
+ * generated. Otherwise the existing token is returned (with the same value,
+ * not the same instance).
+ *
+ * @param string $tokenId The token ID. You may choose an arbitrary value
+ * for the ID
+ *
+ * @return CsrfToken The CSRF token
+ */
+ public function getToken($tokenId);
+
+ /**
+ * Generates a new token value for the given ID.
+ *
+ * This method will generate a new token for the given token ID, independent
+ * of whether a token value previously existed or not. It can be used to
+ * enforce once-only tokens in environments with high security needs.
+ *
+ * @param string $tokenId The token ID. You may choose an arbitrary value
+ * for the ID
+ *
+ * @return CsrfToken The CSRF token
+ */
+ public function refreshToken($tokenId);
+
+ /**
+ * Invalidates the CSRF token with the given ID, if one exists.
+ *
+ * @param string $tokenId The token ID
+ *
+ * @return string|null Returns the removed token value if one existed, NULL
+ * otherwise
+ */
+ public function removeToken($tokenId);
+
+ /**
+ * Returns whether the given CSRF token is valid.
+ *
+ * @param CsrfToken $token A CSRF token
+ *
+ * @return bool Returns true if the token is valid, false otherwise
+ */
+ public function isTokenValid(CsrfToken $token);
+}
diff --git a/Csrf/Exception/TokenNotFoundException.php b/Csrf/Exception/TokenNotFoundException.php
new file mode 100644
index 0000000..936afde
--- /dev/null
+++ b/Csrf/Exception/TokenNotFoundException.php
@@ -0,0 +1,21 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\Exception;
+
+use Symfony\Component\Security\Core\Exception\RuntimeException;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class TokenNotFoundException extends RuntimeException
+{
+}
diff --git a/Csrf/LICENSE b/Csrf/LICENSE
new file mode 100644
index 0000000..43028bc
--- /dev/null
+++ b/Csrf/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2004-2015 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/Csrf/README.md b/Csrf/README.md
new file mode 100644
index 0000000..89ed66c
--- /dev/null
+++ b/Csrf/README.md
@@ -0,0 +1,21 @@
+Security Component - CSRF
+=========================
+
+The Security CSRF (cross-site request forgery) component provides a class
+`CsrfTokenManager` for generating and validating CSRF tokens.
+
+Resources
+---------
+
+Documentation:
+
+http://symfony.com/doc/2.6/book/security.html
+
+Tests
+-----
+
+You can run the unit tests with the following command:
+
+ $ cd path/to/Symfony/Component/Security/Csrf/
+ $ composer.phar install --dev
+ $ phpunit
diff --git a/Csrf/Tests/CsrfTokenManagerTest.php b/Csrf/Tests/CsrfTokenManagerTest.php
new file mode 100644
index 0000000..3112038
--- /dev/null
+++ b/Csrf/Tests/CsrfTokenManagerTest.php
@@ -0,0 +1,164 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\Tests;
+
+use Symfony\Component\Security\Csrf\CsrfToken;
+use Symfony\Component\Security\Csrf\CsrfTokenManager;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class CsrfTokenManagerTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $generator;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $storage;
+
+ /**
+ * @var CsrfTokenManager
+ */
+ private $manager;
+
+ protected function setUp()
+ {
+ $this->generator = $this->getMock('Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface');
+ $this->storage = $this->getMock('Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface');
+ $this->manager = new CsrfTokenManager($this->generator, $this->storage);
+ }
+
+ protected function tearDown()
+ {
+ $this->generator = null;
+ $this->storage = null;
+ $this->manager = null;
+ }
+
+ public function testGetNonExistingToken()
+ {
+ $this->storage->expects($this->once())
+ ->method('hasToken')
+ ->with('token_id')
+ ->will($this->returnValue(false));
+
+ $this->generator->expects($this->once())
+ ->method('generateToken')
+ ->will($this->returnValue('TOKEN'));
+
+ $this->storage->expects($this->once())
+ ->method('setToken')
+ ->with('token_id', 'TOKEN');
+
+ $token = $this->manager->getToken('token_id');
+
+ $this->assertInstanceOf('Symfony\Component\Security\Csrf\CsrfToken', $token);
+ $this->assertSame('token_id', $token->getId());
+ $this->assertSame('TOKEN', $token->getValue());
+ }
+
+ public function testUseExistingTokenIfAvailable()
+ {
+ $this->storage->expects($this->once())
+ ->method('hasToken')
+ ->with('token_id')
+ ->will($this->returnValue(true));
+
+ $this->storage->expects($this->once())
+ ->method('getToken')
+ ->with('token_id')
+ ->will($this->returnValue('TOKEN'));
+
+ $token = $this->manager->getToken('token_id');
+
+ $this->assertInstanceOf('Symfony\Component\Security\Csrf\CsrfToken', $token);
+ $this->assertSame('token_id', $token->getId());
+ $this->assertSame('TOKEN', $token->getValue());
+ }
+
+ public function testRefreshTokenAlwaysReturnsNewToken()
+ {
+ $this->storage->expects($this->never())
+ ->method('hasToken');
+
+ $this->generator->expects($this->once())
+ ->method('generateToken')
+ ->will($this->returnValue('TOKEN'));
+
+ $this->storage->expects($this->once())
+ ->method('setToken')
+ ->with('token_id', 'TOKEN');
+
+ $token = $this->manager->refreshToken('token_id');
+
+ $this->assertInstanceOf('Symfony\Component\Security\Csrf\CsrfToken', $token);
+ $this->assertSame('token_id', $token->getId());
+ $this->assertSame('TOKEN', $token->getValue());
+ }
+
+ public function testMatchingTokenIsValid()
+ {
+ $this->storage->expects($this->once())
+ ->method('hasToken')
+ ->with('token_id')
+ ->will($this->returnValue(true));
+
+ $this->storage->expects($this->once())
+ ->method('getToken')
+ ->with('token_id')
+ ->will($this->returnValue('TOKEN'));
+
+ $this->assertTrue($this->manager->isTokenValid(new CsrfToken('token_id', 'TOKEN')));
+ }
+
+ public function testNonMatchingTokenIsNotValid()
+ {
+ $this->storage->expects($this->once())
+ ->method('hasToken')
+ ->with('token_id')
+ ->will($this->returnValue(true));
+
+ $this->storage->expects($this->once())
+ ->method('getToken')
+ ->with('token_id')
+ ->will($this->returnValue('TOKEN'));
+
+ $this->assertFalse($this->manager->isTokenValid(new CsrfToken('token_id', 'FOOBAR')));
+ }
+
+ public function testNonExistingTokenIsNotValid()
+ {
+ $this->storage->expects($this->once())
+ ->method('hasToken')
+ ->with('token_id')
+ ->will($this->returnValue(false));
+
+ $this->storage->expects($this->never())
+ ->method('getToken');
+
+ $this->assertFalse($this->manager->isTokenValid(new CsrfToken('token_id', 'FOOBAR')));
+ }
+
+ public function testRemoveToken()
+ {
+ $this->storage->expects($this->once())
+ ->method('removeToken')
+ ->with('token_id')
+ ->will($this->returnValue('REMOVED_TOKEN'));
+
+ $this->assertSame('REMOVED_TOKEN', $this->manager->removeToken('token_id'));
+ }
+}
diff --git a/Csrf/Tests/TokenGenerator/UriSafeTokenGeneratorTest.php b/Csrf/Tests/TokenGenerator/UriSafeTokenGeneratorTest.php
new file mode 100644
index 0000000..4fb0c99
--- /dev/null
+++ b/Csrf/Tests/TokenGenerator/UriSafeTokenGeneratorTest.php
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\Tests\TokenGenerator;
+
+use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class UriSafeTokenGeneratorTest extends \PHPUnit_Framework_TestCase
+{
+ const ENTROPY = 1000;
+
+ /**
+ * A non alpha-numeric byte string
+ * @var string
+ */
+ private static $bytes;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $random;
+
+ /**
+ * @var UriSafeTokenGenerator
+ */
+ private $generator;
+
+ public static function setUpBeforeClass()
+ {
+ self::$bytes = base64_decode('aMf+Tct/RLn2WQ==');
+ }
+
+ protected function setUp()
+ {
+ $this->random = $this->getMock('Symfony\Component\Security\Core\Util\SecureRandomInterface');
+ $this->generator = new UriSafeTokenGenerator($this->random, self::ENTROPY);
+ }
+
+ protected function tearDown()
+ {
+ $this->random = null;
+ $this->generator = null;
+ }
+
+ public function testGenerateToken()
+ {
+ $this->random->expects($this->once())
+ ->method('nextBytes')
+ ->with(self::ENTROPY/8)
+ ->will($this->returnValue(self::$bytes));
+
+ $token = $this->generator->generateToken();
+
+ $this->assertTrue(ctype_print($token), 'is printable');
+ $this->assertStringNotMatchesFormat('%S+%S', $token, 'is URI safe');
+ $this->assertStringNotMatchesFormat('%S/%S', $token, 'is URI safe');
+ $this->assertStringNotMatchesFormat('%S=%S', $token, 'is URI safe');
+ }
+}
diff --git a/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php b/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php
new file mode 100644
index 0000000..0039deb
--- /dev/null
+++ b/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php
@@ -0,0 +1,127 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\Tests\TokenStorage;
+
+use Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ *
+ * @runTestsInSeparateProcesses
+ * @preserveGlobalState disabled
+ */
+class NativeSessionTokenStorageTest extends \PHPUnit_Framework_TestCase
+{
+ const SESSION_NAMESPACE = 'foobar';
+
+ /**
+ * @var NativeSessionTokenStorage
+ */
+ private $storage;
+
+ public static function setUpBeforeClass()
+ {
+ ini_set('session.save_handler', 'files');
+ ini_set('session.save_path', sys_get_temp_dir());
+
+ parent::setUpBeforeClass();
+ }
+
+ protected function setUp()
+ {
+ $_SESSION = array();
+
+ $this->storage = new NativeSessionTokenStorage(self::SESSION_NAMESPACE);
+ }
+
+ public function testStoreTokenInClosedSession()
+ {
+ $this->storage->setToken('token_id', 'TOKEN');
+
+ $this->assertSame(array(self::SESSION_NAMESPACE => array('token_id' => 'TOKEN')), $_SESSION);
+ }
+
+ public function testStoreTokenInClosedSessionWithExistingSessionId()
+ {
+ if (PHP_VERSION_ID < 50400) {
+ $this->markTestSkipped('This test requires PHP 5.4 or later.');
+ }
+
+ session_id('foobar');
+
+ $this->assertSame(PHP_SESSION_NONE, session_status());
+
+ $this->storage->setToken('token_id', 'TOKEN');
+
+ $this->assertSame(PHP_SESSION_ACTIVE, session_status());
+ $this->assertSame(array(self::SESSION_NAMESPACE => array('token_id' => 'TOKEN')), $_SESSION);
+ }
+
+ public function testStoreTokenInActiveSession()
+ {
+ session_start();
+
+ $this->storage->setToken('token_id', 'TOKEN');
+
+ $this->assertSame(array(self::SESSION_NAMESPACE => array('token_id' => 'TOKEN')), $_SESSION);
+ }
+
+ /**
+ * @depends testStoreTokenInClosedSession
+ */
+ public function testCheckToken()
+ {
+ $this->assertFalse($this->storage->hasToken('token_id'));
+
+ $this->storage->setToken('token_id', 'TOKEN');
+
+ $this->assertTrue($this->storage->hasToken('token_id'));
+ }
+
+ /**
+ * @depends testStoreTokenInClosedSession
+ */
+ public function testGetExistingToken()
+ {
+ $this->storage->setToken('token_id', 'TOKEN');
+
+ $this->assertSame('TOKEN', $this->storage->getToken('token_id'));
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException
+ */
+ public function testGetNonExistingToken()
+ {
+ $this->storage->getToken('token_id');
+ }
+
+ /**
+ * @depends testCheckToken
+ */
+ public function testRemoveNonExistingToken()
+ {
+ $this->assertNull($this->storage->removeToken('token_id'));
+ $this->assertFalse($this->storage->hasToken('token_id'));
+ }
+
+ /**
+ * @depends testCheckToken
+ */
+ public function testRemoveExistingToken()
+ {
+ $this->storage->setToken('token_id', 'TOKEN');
+
+ $this->assertSame('TOKEN', $this->storage->removeToken('token_id'));
+ $this->assertFalse($this->storage->hasToken('token_id'));
+ }
+}
diff --git a/Csrf/Tests/TokenStorage/SessionTokenStorageTest.php b/Csrf/Tests/TokenStorage/SessionTokenStorageTest.php
new file mode 100644
index 0000000..4166c1e
--- /dev/null
+++ b/Csrf/Tests/TokenStorage/SessionTokenStorageTest.php
@@ -0,0 +1,262 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\Tests\TokenStorage;
+
+use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class SessionTokenStorageTest extends \PHPUnit_Framework_TestCase
+{
+ const SESSION_NAMESPACE = 'foobar';
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ private $session;
+
+ /**
+ * @var SessionTokenStorage
+ */
+ private $storage;
+
+ protected function setUp()
+ {
+ if (!interface_exists('Symfony\Component\HttpFoundation\Session\SessionInterface')) {
+ $this->markTestSkipped('The "HttpFoundation" component is not available');
+ }
+
+ $this->session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->storage = new SessionTokenStorage($this->session, self::SESSION_NAMESPACE);
+ }
+
+ public function testStoreTokenInClosedSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(false));
+
+ $this->session->expects($this->once())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('set')
+ ->with(self::SESSION_NAMESPACE.'/token_id', 'TOKEN');
+
+ $this->storage->setToken('token_id', 'TOKEN');
+ }
+
+ public function testStoreTokenInActiveSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->never())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('set')
+ ->with(self::SESSION_NAMESPACE.'/token_id', 'TOKEN');
+
+ $this->storage->setToken('token_id', 'TOKEN');
+ }
+
+ public function testCheckTokenInClosedSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(false));
+
+ $this->session->expects($this->once())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('has')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue('RESULT'));
+
+ $this->assertSame('RESULT', $this->storage->hasToken('token_id'));
+ }
+
+ public function testCheckTokenInActiveSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->never())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('has')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue('RESULT'));
+
+ $this->assertSame('RESULT', $this->storage->hasToken('token_id'));
+ }
+
+ public function testGetExistingTokenFromClosedSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(false));
+
+ $this->session->expects($this->once())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('has')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->once())
+ ->method('get')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue('RESULT'));
+
+ $this->assertSame('RESULT', $this->storage->getToken('token_id'));
+ }
+
+ public function testGetExistingTokenFromActiveSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->never())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('has')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->once())
+ ->method('get')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue('RESULT'));
+
+ $this->assertSame('RESULT', $this->storage->getToken('token_id'));
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException
+ */
+ public function testGetNonExistingTokenFromClosedSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(false));
+
+ $this->session->expects($this->once())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('has')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue(false));
+
+ $this->storage->getToken('token_id');
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException
+ */
+ public function testGetNonExistingTokenFromActiveSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->never())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('has')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue(false));
+
+ $this->storage->getToken('token_id');
+ }
+
+ public function testRemoveNonExistingTokenFromClosedSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(false));
+
+ $this->session->expects($this->once())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('remove')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue(null));
+
+ $this->assertNull($this->storage->removeToken('token_id'));
+ }
+
+ public function testRemoveNonExistingTokenFromActiveSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->never())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('remove')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue(null));
+
+ $this->assertNull($this->storage->removeToken('token_id'));
+ }
+
+ public function testRemoveExistingTokenFromClosedSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(false));
+
+ $this->session->expects($this->once())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('remove')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue('TOKEN'));
+
+ $this->assertSame('TOKEN', $this->storage->removeToken('token_id'));
+ }
+
+ public function testRemoveExistingTokenFromActiveSession()
+ {
+ $this->session->expects($this->any())
+ ->method('isStarted')
+ ->will($this->returnValue(true));
+
+ $this->session->expects($this->never())
+ ->method('start');
+
+ $this->session->expects($this->once())
+ ->method('remove')
+ ->with(self::SESSION_NAMESPACE.'/token_id')
+ ->will($this->returnValue('TOKEN'));
+
+ $this->assertSame('TOKEN', $this->storage->removeToken('token_id'));
+ }
+}
diff --git a/Csrf/TokenGenerator/TokenGeneratorInterface.php b/Csrf/TokenGenerator/TokenGeneratorInterface.php
new file mode 100644
index 0000000..e02ac66
--- /dev/null
+++ b/Csrf/TokenGenerator/TokenGeneratorInterface.php
@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\TokenGenerator;
+
+/**
+ * Generates CSRF tokens.
+ *
+ * @since 2.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+interface TokenGeneratorInterface
+{
+ /**
+ * Generates a CSRF token.
+ *
+ * @return string The generated CSRF token
+ */
+ public function generateToken();
+}
diff --git a/Csrf/TokenGenerator/UriSafeTokenGenerator.php b/Csrf/TokenGenerator/UriSafeTokenGenerator.php
new file mode 100644
index 0000000..122bc02
--- /dev/null
+++ b/Csrf/TokenGenerator/UriSafeTokenGenerator.php
@@ -0,0 +1,65 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\TokenGenerator;
+
+use Symfony\Component\Security\Core\Util\SecureRandomInterface;
+use Symfony\Component\Security\Core\Util\SecureRandom;
+
+/**
+ * Generates CSRF tokens.
+ *
+ * @since 2.4
+ * @author Bernhard Schussek <bernhard.schussek@symfony.com>
+ */
+class UriSafeTokenGenerator implements TokenGeneratorInterface
+{
+ /**
+ * The generator for random values.
+ *
+ * @var SecureRandomInterface
+ */
+ private $random;
+
+ /**
+ * The amount of entropy collected for each token (in bits).
+ *
+ * @var int
+ */
+ private $entropy;
+
+ /**
+ * Generates URI-safe CSRF tokens.
+ *
+ * @param SecureRandomInterface|null $random The random value generator used for
+ * generating entropy
+ * @param int $entropy The amount of entropy collected for
+ * each token (in bits)
+ */
+ public function __construct(SecureRandomInterface $random = null, $entropy = 256)
+ {
+ $this->random = $random ?: new SecureRandom();
+ $this->entropy = $entropy;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function generateToken()
+ {
+ // Generate an URI safe base64 encoded string that does not contain "+",
+ // "/" or "=" which need to be URL encoded and make URLs unnecessarily
+ // longer.
+ $bytes = $this->random->nextBytes($this->entropy / 8);
+
+ return rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=');
+ }
+}
diff --git a/Csrf/TokenStorage/NativeSessionTokenStorage.php b/Csrf/TokenStorage/NativeSessionTokenStorage.php
new file mode 100644
index 0000000..60145c6
--- /dev/null
+++ b/Csrf/TokenStorage/NativeSessionTokenStorage.php
@@ -0,0 +1,121 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\TokenStorage;
+
+use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException;
+
+/**
+ * Token storage that uses PHP's native session handling.
+ *
+ * @since 2.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class NativeSessionTokenStorage implements TokenStorageInterface
+{
+ /**
+ * The namespace used to store values in the session.
+ * @var string
+ */
+ const SESSION_NAMESPACE = '_csrf';
+
+ /**
+ * @var bool
+ */
+ private $sessionStarted = false;
+
+ /**
+ * @var string
+ */
+ private $namespace;
+
+ /**
+ * Initializes the storage with a session namespace.
+ *
+ * @param string $namespace The namespace under which the token is stored
+ * in the session
+ */
+ public function __construct($namespace = self::SESSION_NAMESPACE)
+ {
+ $this->namespace = $namespace;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getToken($tokenId)
+ {
+ if (!$this->sessionStarted) {
+ $this->startSession();
+ }
+
+ if (!isset($_SESSION[$this->namespace][$tokenId])) {
+ throw new TokenNotFoundException('The CSRF token with ID '.$tokenId.' does not exist.');
+ }
+
+ return (string) $_SESSION[$this->namespace][$tokenId];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setToken($tokenId, $token)
+ {
+ if (!$this->sessionStarted) {
+ $this->startSession();
+ }
+
+ $_SESSION[$this->namespace][$tokenId] = (string) $token;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasToken($tokenId)
+ {
+ if (!$this->sessionStarted) {
+ $this->startSession();
+ }
+
+ return isset($_SESSION[$this->namespace][$tokenId]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function removeToken($tokenId)
+ {
+ if (!$this->sessionStarted) {
+ $this->startSession();
+ }
+
+ $token = isset($_SESSION[$this->namespace][$tokenId])
+ ? (string) $_SESSION[$this->namespace][$tokenId]
+ : null;
+
+ unset($_SESSION[$this->namespace][$tokenId]);
+
+ return $token;
+ }
+
+ private function startSession()
+ {
+ if (PHP_VERSION_ID >= 50400) {
+ if (PHP_SESSION_NONE === session_status()) {
+ session_start();
+ }
+ } elseif (!session_id()) {
+ session_start();
+ }
+
+ $this->sessionStarted = true;
+ }
+}
diff --git a/Csrf/TokenStorage/SessionTokenStorage.php b/Csrf/TokenStorage/SessionTokenStorage.php
new file mode 100644
index 0000000..f08eb96
--- /dev/null
+++ b/Csrf/TokenStorage/SessionTokenStorage.php
@@ -0,0 +1,106 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\TokenStorage;
+
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException;
+
+/**
+ * Token storage that uses a Symfony2 Session object.
+ *
+ * @since 2.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class SessionTokenStorage implements TokenStorageInterface
+{
+ /**
+ * The namespace used to store values in the session.
+ * @var string
+ */
+ const SESSION_NAMESPACE = '_csrf';
+
+ /**
+ * The user session from which the session ID is returned
+ * @var SessionInterface
+ */
+ private $session;
+
+ /**
+ * @var string
+ */
+ private $namespace;
+
+ /**
+ * Initializes the storage with a Session object and a session namespace.
+ *
+ * @param SessionInterface $session The user session
+ * @param string $namespace The namespace under which the token
+ * is stored in the session
+ */
+ public function __construct(SessionInterface $session, $namespace = self::SESSION_NAMESPACE)
+ {
+ $this->session = $session;
+ $this->namespace = $namespace;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getToken($tokenId)
+ {
+ if (!$this->session->isStarted()) {
+ $this->session->start();
+ }
+
+ if (!$this->session->has($this->namespace.'/'.$tokenId)) {
+ throw new TokenNotFoundException('The CSRF token with ID '.$tokenId.' does not exist.');
+ }
+
+ return (string) $this->session->get($this->namespace.'/'.$tokenId);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setToken($tokenId, $token)
+ {
+ if (!$this->session->isStarted()) {
+ $this->session->start();
+ }
+
+ $this->session->set($this->namespace.'/'.$tokenId, (string) $token);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function hasToken($tokenId)
+ {
+ if (!$this->session->isStarted()) {
+ $this->session->start();
+ }
+
+ return $this->session->has($this->namespace.'/'.$tokenId);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function removeToken($tokenId)
+ {
+ if (!$this->session->isStarted()) {
+ $this->session->start();
+ }
+
+ return $this->session->remove($this->namespace.'/'.$tokenId);
+ }
+}
diff --git a/Csrf/TokenStorage/TokenStorageInterface.php b/Csrf/TokenStorage/TokenStorageInterface.php
new file mode 100644
index 0000000..0fadfa3
--- /dev/null
+++ b/Csrf/TokenStorage/TokenStorageInterface.php
@@ -0,0 +1,59 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Csrf\TokenStorage;
+
+/**
+ * Stores CSRF tokens.
+ *
+ * @since 2.4
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+interface TokenStorageInterface
+{
+ /**
+ * Reads a stored CSRF token.
+ *
+ * @param string $tokenId The token ID
+ *
+ * @return string The stored token
+ *
+ * @throws \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException If the token ID does not exist
+ */
+ public function getToken($tokenId);
+
+ /**
+ * Stores a CSRF token.
+ *
+ * @param string $tokenId The token ID
+ * @param string $token The CSRF token
+ */
+ public function setToken($tokenId, $token);
+
+ /**
+ * Removes a CSRF token.
+ *
+ * @param string $tokenId The token ID
+ *
+ * @return string|null Returns the removed token if one existed, NULL
+ * otherwise
+ */
+ public function removeToken($tokenId);
+
+ /**
+ * Checks whether a token with the given token ID exists.
+ *
+ * @param string $tokenId The token ID
+ *
+ * @return bool Whether a token exists with the given ID
+ */
+ public function hasToken($tokenId);
+}
diff --git a/Csrf/composer.json b/Csrf/composer.json
new file mode 100644
index 0000000..5c869e0
--- /dev/null
+++ b/Csrf/composer.json
@@ -0,0 +1,39 @@
+{
+ "name": "symfony/security-csrf",
+ "type": "library",
+ "description": "Symfony Security Component - CSRF Library",
+ "keywords": [],
+ "homepage": "http://symfony.com",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3",
+ "symfony/security-core": "~2.4"
+ },
+ "require-dev": {
+ "symfony/phpunit-bridge": "~2.7",
+ "symfony/http-foundation": "~2.1"
+ },
+ "suggest": {
+ "symfony/http-foundation": "For using the class SessionTokenStorage."
+ },
+ "autoload": {
+ "psr-0": { "Symfony\\Component\\Security\\Csrf\\": "" }
+ },
+ "target-dir": "Symfony/Component/Security/Csrf",
+ "minimum-stability": "dev",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev"
+ }
+ }
+}
diff --git a/Csrf/phpunit.xml.dist b/Csrf/phpunit.xml.dist
new file mode 100644
index 0000000..f72d115
--- /dev/null
+++ b/Csrf/phpunit.xml.dist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="vendor/autoload.php"
+>
+ <php>
+ <ini name="error_reporting" value="-1" />
+ </php>
+ <testsuites>
+ <testsuite name="Symfony Security Component CSRF Test Suite">
+ <directory>./Tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./vendor</directory>
+ <directory>./Tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/Http/.gitignore b/Http/.gitignore
new file mode 100644
index 0000000..c49a5d8
--- /dev/null
+++ b/Http/.gitignore
@@ -0,0 +1,3 @@
+vendor/
+composer.lock
+phpunit.xml
diff --git a/Http/AccessMap.php b/Http/AccessMap.php
index 14fcbe1..116874a 100644
--- a/Http/AccessMap.php
+++ b/Http/AccessMap.php
@@ -28,12 +28,12 @@ class AccessMap implements AccessMapInterface
* Constructor.
*
* @param RequestMatcherInterface $requestMatcher A RequestMatcherInterface instance
- * @param array $roles An array of roles needed to access the resource
+ * @param array $attributes An array of attributes to pass to the access decision manager (like roles)
* @param string|null $channel The channel to enforce (http, https, or null)
*/
- public function add(RequestMatcherInterface $requestMatcher, array $roles = array(), $channel = null)
+ public function add(RequestMatcherInterface $requestMatcher, array $attributes = array(), $channel = null)
{
- $this->map[] = array($requestMatcher, $roles, $channel);
+ $this->map[] = array($requestMatcher, $attributes, $channel);
}
/**
diff --git a/Http/Authentication/AuthenticationUtils.php b/Http/Authentication/AuthenticationUtils.php
new file mode 100644
index 0000000..317c8a0
--- /dev/null
+++ b/Http/Authentication/AuthenticationUtils.php
@@ -0,0 +1,87 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Authentication;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\RequestStack;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Core\Security;
+
+/**
+ * Extracts Security Errors from Request
+ *
+ * @author Boris Vujicic <boris.vujicic@gmail.com>
+ */
+class AuthenticationUtils
+{
+ /**
+ * @var RequestStack
+ */
+ private $requestStack;
+
+ /**
+ * @param RequestStack $requestStack
+ */
+ public function __construct(RequestStack $requestStack)
+ {
+ $this->requestStack = $requestStack;
+ }
+
+ /**
+ * @param bool $clearSession
+ *
+ * @return AuthenticationException|null
+ */
+ public function getLastAuthenticationError($clearSession = true)
+ {
+ $request = $this->getRequest();
+ $session = $request->getSession();
+ $authenticationException = null;
+
+ if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
+ $authenticationException = $request->attributes->get(Security::AUTHENTICATION_ERROR);
+ } elseif ($session !== null && $session->has(Security::AUTHENTICATION_ERROR)) {
+ $authenticationException = $session->get(Security::AUTHENTICATION_ERROR);
+
+ if ($clearSession) {
+ $session->remove(Security::AUTHENTICATION_ERROR);
+ }
+ }
+
+ return $authenticationException;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLastUsername()
+ {
+ $session = $this->getRequest()->getSession();
+
+ return null === $session ? '' : $session->get(Security::LAST_USERNAME);
+ }
+
+ /**
+ * @return Request
+ * @throws \LogicException
+ */
+ private function getRequest()
+ {
+ $request = $this->requestStack->getCurrentRequest();
+
+ if (null === $request) {
+ throw new \LogicException('Request should exist so it can be processed for error.');
+ }
+
+ return $request;
+ }
+}
diff --git a/Http/Authentication/CustomAuthenticationFailureHandler.php b/Http/Authentication/CustomAuthenticationFailureHandler.php
new file mode 100644
index 0000000..36d4a78
--- /dev/null
+++ b/Http/Authentication/CustomAuthenticationFailureHandler.php
@@ -0,0 +1,45 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Authentication;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+
+/**
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class CustomAuthenticationFailureHandler implements AuthenticationFailureHandlerInterface
+{
+ private $handler;
+
+ /**
+ * Constructor.
+ *
+ * @param AuthenticationFailureHandlerInterface $handler An AuthenticationFailureHandlerInterface instance
+ * @param array $options Options for processing a successful authentication attempt
+ */
+ public function __construct(AuthenticationFailureHandlerInterface $handler, array $options)
+ {
+ $this->handler = $handler;
+ if (method_exists($handler, 'setOptions')) {
+ $this->handler->setOptions($options);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
+ {
+ return $this->handler->onAuthenticationFailure($request, $exception);
+ }
+}
diff --git a/Http/Authentication/CustomAuthenticationSuccessHandler.php b/Http/Authentication/CustomAuthenticationSuccessHandler.php
new file mode 100644
index 0000000..2d1b26e
--- /dev/null
+++ b/Http/Authentication/CustomAuthenticationSuccessHandler.php
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Authentication;
+
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
+{
+ private $handler;
+
+ /**
+ * Constructor.
+ *
+ * @param AuthenticationSuccessHandlerInterface $handler An AuthenticationSuccessHandlerInterface instance
+ * @param array $options Options for processing a successful authentication attempt
+ * @param string $providerKey The provider key
+ */
+ public function __construct(AuthenticationSuccessHandlerInterface $handler, array $options, $providerKey)
+ {
+ $this->handler = $handler;
+ if (method_exists($handler, 'setOptions')) {
+ $this->handler->setOptions($options);
+ }
+ if (method_exists($handler, 'setProviderKey')) {
+ $this->handler->setProviderKey($providerKey);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onAuthenticationSuccess(Request $request, TokenInterface $token)
+ {
+ return $this->handler->onAuthenticationSuccess($request, $token);
+ }
+}
diff --git a/Http/Authentication/DefaultAuthenticationFailureHandler.php b/Http/Authentication/DefaultAuthenticationFailureHandler.php
index b3c5c4d..8864dae 100644
--- a/Http/Authentication/DefaultAuthenticationFailureHandler.php
+++ b/Http/Authentication/DefaultAuthenticationFailureHandler.php
@@ -15,7 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
-use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\HttpUtils;
/**
@@ -34,6 +34,12 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle
protected $httpUtils;
protected $logger;
protected $options;
+ protected $defaultOptions = array(
+ 'failure_path' => null,
+ 'failure_forward' => false,
+ 'login_path' => '/login',
+ 'failure_path_parameter' => '_failure_path',
+ );
/**
* Constructor.
@@ -43,18 +49,32 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle
* @param array $options Options for processing a failed authentication attempt.
* @param LoggerInterface $logger Optional logger
*/
- public function __construct(HttpKernelInterface $httpKernel, HttpUtils $httpUtils, array $options, LoggerInterface $logger = null)
+ public function __construct(HttpKernelInterface $httpKernel, HttpUtils $httpUtils, array $options = array(), LoggerInterface $logger = null)
{
$this->httpKernel = $httpKernel;
$this->httpUtils = $httpUtils;
$this->logger = $logger;
+ $this->setOptions($options);
+ }
- $this->options = array_merge(array(
- 'failure_path' => null,
- 'failure_forward' => false,
- 'login_path' => '/login',
- 'failure_path_parameter' => '_failure_path',
- ), $options);
+ /**
+ * Gets the options.
+ *
+ * @return array An array of options
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * Sets the options.
+ *
+ * @param array $options An array of options
+ */
+ public function setOptions(array $options)
+ {
+ $this->options = array_merge($this->defaultOptions, $options);
}
/**
@@ -76,7 +96,7 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle
}
$subRequest = $this->httpUtils->createRequest($request, $this->options['failure_path']);
- $subRequest->attributes->set(SecurityContextInterface::AUTHENTICATION_ERROR, $exception);
+ $subRequest->attributes->set(Security::AUTHENTICATION_ERROR, $exception);
return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
@@ -85,7 +105,7 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle
$this->logger->debug(sprintf('Redirecting to %s', $this->options['failure_path']));
}
- $request->getSession()->set(SecurityContextInterface::AUTHENTICATION_ERROR, $exception);
+ $request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
return $this->httpUtils->createRedirectResponse($request, $this->options['failure_path']);
}
diff --git a/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/Http/Authentication/DefaultAuthenticationSuccessHandler.php
index 591a28d..5fa7071 100644
--- a/Http/Authentication/DefaultAuthenticationSuccessHandler.php
+++ b/Http/Authentication/DefaultAuthenticationSuccessHandler.php
@@ -27,6 +27,13 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
protected $httpUtils;
protected $options;
protected $providerKey;
+ protected $defaultOptions = array(
+ 'always_use_default_target_path' => false,
+ 'default_target_path' => '/',
+ 'login_path' => '/login',
+ 'target_path_parameter' => '_target_path',
+ 'use_referer' => false,
+ );
/**
* Constructor.
@@ -34,17 +41,10 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
* @param HttpUtils $httpUtils
* @param array $options Options for processing a successful authentication attempt.
*/
- public function __construct(HttpUtils $httpUtils, array $options)
+ public function __construct(HttpUtils $httpUtils, array $options = array())
{
$this->httpUtils = $httpUtils;
-
- $this->options = array_merge(array(
- 'always_use_default_target_path' => false,
- 'default_target_path' => '/',
- 'login_path' => '/login',
- 'target_path_parameter' => '_target_path',
- 'use_referer' => false,
- ), $options);
+ $this->setOptions($options);
}
/**
@@ -56,6 +56,26 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
}
/**
+ * Gets the options.
+ *
+ * @return array An array of options
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * Sets the options.
+ *
+ * @param array $options An array of options
+ */
+ public function setOptions(array $options)
+ {
+ $this->options = array_merge($this->defaultOptions, $options);
+ }
+
+ /**
* Get the provider key.
*
* @return string
diff --git a/Http/Authentication/SimpleAuthenticationHandler.php b/Http/Authentication/SimpleAuthenticationHandler.php
new file mode 100644
index 0000000..09a55ef
--- /dev/null
+++ b/Http/Authentication/SimpleAuthenticationHandler.php
@@ -0,0 +1,106 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Authentication;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
+
+/**
+ * Class to proxy authentication success/failure handlers
+ *
+ * Events are sent to the SimpleAuthenticatorInterface if it implements
+ * the right interface, otherwise (or if it fails to return a Response)
+ * the default handlers are triggered.
+ *
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class SimpleAuthenticationHandler implements AuthenticationFailureHandlerInterface, AuthenticationSuccessHandlerInterface
+{
+ protected $successHandler;
+ protected $failureHandler;
+ protected $simpleAuthenticator;
+ protected $logger;
+
+ /**
+ * Constructor.
+ *
+ * @param SimpleAuthenticatorInterface $authenticator SimpleAuthenticatorInterface instance
+ * @param AuthenticationSuccessHandlerInterface $successHandler Default success handler
+ * @param AuthenticationFailureHandlerInterface $failureHandler Default failure handler
+ * @param LoggerInterface $logger Optional logger
+ */
+ public function __construct(SimpleAuthenticatorInterface $authenticator, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, LoggerInterface $logger = null)
+ {
+ $this->simpleAuthenticator = $authenticator;
+ $this->successHandler = $successHandler;
+ $this->failureHandler = $failureHandler;
+ $this->logger = $logger;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onAuthenticationSuccess(Request $request, TokenInterface $token)
+ {
+ if ($this->simpleAuthenticator instanceof AuthenticationSuccessHandlerInterface) {
+ if ($this->logger) {
+ $this->logger->debug(sprintf('Using the %s object as authentication success handler', get_class($this->simpleAuthenticator)));
+ }
+
+ $response = $this->simpleAuthenticator->onAuthenticationSuccess($request, $token);
+ if ($response instanceof Response) {
+ return $response;
+ }
+
+ if (null !== $response) {
+ throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationSuccess method must return null to use the default success handler, or a Response object', get_class($this->simpleAuthenticator)));
+ }
+ }
+
+ if ($this->logger) {
+ $this->logger->debug('Fallback to the default authentication success handler');
+ }
+
+ return $this->successHandler->onAuthenticationSuccess($request, $token);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
+ {
+ if ($this->simpleAuthenticator instanceof AuthenticationFailureHandlerInterface) {
+ if ($this->logger) {
+ $this->logger->debug(sprintf('Using the %s object as authentication failure handler', get_class($this->simpleAuthenticator)));
+ }
+
+ $response = $this->simpleAuthenticator->onAuthenticationFailure($request, $exception);
+ if ($response instanceof Response) {
+ return $response;
+ }
+
+ if (null !== $response) {
+ throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationFailure method must return null to use the default failure handler, or a Response object', get_class($this->simpleAuthenticator)));
+ }
+ }
+
+ if ($this->logger) {
+ $this->logger->debug('Fallback to the default authentication failure handler');
+ }
+
+ return $this->failureHandler->onAuthenticationFailure($request, $exception);
+ }
+}
diff --git a/Http/Firewall.php b/Http/Firewall.php
index 7499c6f..7bad47a 100644
--- a/Http/Firewall.php
+++ b/Http/Firewall.php
@@ -11,9 +11,9 @@
namespace Symfony\Component\Security\Http;
-use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -31,6 +31,7 @@ class Firewall implements EventSubscriberInterface
{
private $map;
private $dispatcher;
+ private $exceptionListeners;
/**
* Constructor.
@@ -42,6 +43,7 @@ class Firewall implements EventSubscriberInterface
{
$this->map = $map;
$this->dispatcher = $dispatcher;
+ $this->exceptionListeners = new \SplObjectStorage();
}
/**
@@ -51,14 +53,15 @@ class Firewall implements EventSubscriberInterface
*/
public function onKernelRequest(GetResponseEvent $event)
{
- if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+ if (!$event->isMasterRequest()) {
return;
}
// register listeners for this firewall
- list($listeners, $exception) = $this->map->getListeners($event->getRequest());
- if (null !== $exception) {
- $exception->register($this->dispatcher);
+ list($listeners, $exceptionListener) = $this->map->getListeners($event->getRequest());
+ if (null !== $exceptionListener) {
+ $this->exceptionListeners[$event->getRequest()] = $exceptionListener;
+ $exceptionListener->register($this->dispatcher);
}
// initiate the listener chain
@@ -71,11 +74,24 @@ class Firewall implements EventSubscriberInterface
}
}
+ public function onKernelFinishRequest(FinishRequestEvent $event)
+ {
+ $request = $event->getRequest();
+
+ if (isset($this->exceptionListeners[$request])) {
+ $this->exceptionListeners[$request]->unregister($this->dispatcher);
+ unset($this->exceptionListeners[$request]);
+ }
+ }
+
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
- return array(KernelEvents::REQUEST => array('onKernelRequest', 8));
+ return array(
+ KernelEvents::REQUEST => array('onKernelRequest', 8),
+ KernelEvents::FINISH_REQUEST => 'onKernelFinishRequest',
+ );
}
}
diff --git a/Http/Firewall/AbstractAuthenticationListener.php b/Http/Firewall/AbstractAuthenticationListener.php
index f71089f..39c6951 100644
--- a/Http/Firewall/AbstractAuthenticationListener.php
+++ b/Http/Firewall/AbstractAuthenticationListener.php
@@ -15,6 +15,7 @@ use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterfa
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
@@ -149,14 +150,14 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
if ($returnValue instanceof TokenInterface) {
$this->sessionStrategy->onAuthentication($request, $returnValue);
- $response = $this->onSuccess($event, $request, $returnValue);
+ $response = $this->onSuccess($request, $returnValue);
} elseif ($returnValue instanceof Response) {
$response = $returnValue;
} else {
throw new \RuntimeException('attemptAuthentication() must either return a Response, an implementation of TokenInterface, or null.');
}
} catch (AuthenticationException $e) {
- $response = $this->onFailure($event, $request, $e);
+ $response = $this->onFailure($request, $e);
}
$event->setResponse($response);
@@ -189,7 +190,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
*/
abstract protected function attemptAuthentication(Request $request);
- private function onFailure(GetResponseEvent $event, Request $request, AuthenticationException $failed)
+ private function onFailure(Request $request, AuthenticationException $failed)
{
if (null !== $this->logger) {
$this->logger->info(sprintf('Authentication request failed: %s', $failed->getMessage()));
@@ -209,7 +210,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
return $response;
}
- private function onSuccess(GetResponseEvent $event, Request $request, TokenInterface $token)
+ private function onSuccess(Request $request, TokenInterface $token)
{
if (null !== $this->logger) {
$this->logger->info(sprintf('User "%s" has been authenticated successfully', $token->getUsername()));
@@ -218,8 +219,8 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
$this->securityContext->setToken($token);
$session = $request->getSession();
- $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
- $session->remove(SecurityContextInterface::LAST_USERNAME);
+ $session->remove(Security::AUTHENTICATION_ERROR);
+ $session->remove(Security::LAST_USERNAME);
if (null !== $this->dispatcher) {
$loginEvent = new InteractiveLoginEvent($request, $token);
diff --git a/Http/Firewall/AnonymousAuthenticationListener.php b/Http/Firewall/AnonymousAuthenticationListener.php
index 446dfec..68f8987 100644
--- a/Http/Firewall/AnonymousAuthenticationListener.php
+++ b/Http/Firewall/AnonymousAuthenticationListener.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Security\Http\Firewall;
+use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@@ -26,12 +28,14 @@ class AnonymousAuthenticationListener implements ListenerInterface
{
private $context;
private $key;
+ private $authenticationManager;
private $logger;
- public function __construct(SecurityContextInterface $context, $key, LoggerInterface $logger = null)
+ public function __construct(SecurityContextInterface $context, $key, LoggerInterface $logger = null, AuthenticationManagerInterface $authenticationManager = null)
{
$this->context = $context;
$this->key = $key;
+ $this->authenticationManager = $authenticationManager;
$this->logger = $logger;
}
@@ -46,10 +50,21 @@ class AnonymousAuthenticationListener implements ListenerInterface
return;
}
- $this->context->setToken(new AnonymousToken($this->key, 'anon.', array()));
+ try {
+ $token = new AnonymousToken($this->key, 'anon.', array());
+ if (null !== $this->authenticationManager) {
+ $token = $this->authenticationManager->authenticate($token);
+ }
- if (null !== $this->logger) {
- $this->logger->info('Populated SecurityContext with an anonymous Token');
+ $this->context->setToken($token);
+
+ if (null !== $this->logger) {
+ $this->logger->info('Populated SecurityContext with an anonymous Token');
+ }
+ } catch (AuthenticationException $failed) {
+ if (null !== $this->logger) {
+ $this->logger->info(sprintf('Anonymous authentication failed: %s', $failed->getMessage()));
+ }
}
}
}
diff --git a/Http/Firewall/ContextListener.php b/Http/Firewall/ContextListener.php
index c80fff3..732bbf7 100644
--- a/Http/Firewall/ContextListener.php
+++ b/Http/Firewall/ContextListener.php
@@ -11,7 +11,6 @@
namespace Symfony\Component\Security\Http\Firewall;
-use Symfony\Component\HttpKernel\HttpKernelInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
@@ -66,7 +65,7 @@ class ContextListener implements ListenerInterface
*/
public function handle(GetResponseEvent $event)
{
- if (!$this->registered && null !== $this->dispatcher && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
+ if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
$this->registered = true;
}
@@ -106,7 +105,7 @@ class ContextListener implements ListenerInterface
*/
public function onKernelResponse(FilterResponseEvent $event)
{
- if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+ if (!$event->isMasterRequest()) {
return;
}
@@ -146,7 +145,7 @@ class ContextListener implements ListenerInterface
*
* @throws \RuntimeException
*/
- private function refreshUser(TokenInterface $token)
+ protected function refreshUser(TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
diff --git a/Http/Firewall/DigestAuthenticationListener.php b/Http/Firewall/DigestAuthenticationListener.php
index ea85e77..a5e0222 100644
--- a/Http/Firewall/DigestAuthenticationListener.php
+++ b/Http/Firewall/DigestAuthenticationListener.php
@@ -139,7 +139,7 @@ class DigestAuthenticationListener implements ListenerInterface
class DigestData
{
- private $elements;
+ private $elements = array();
private $header;
private $nonceExpiryTime;
@@ -147,7 +147,6 @@ class DigestData
{
$this->header = $header;
preg_match_all('/(\w+)=("((?:[^"\\\\]|\\\\.)+)"|([^\s,$]+))/', $header, $matches, PREG_SET_ORDER);
- $this->elements = array();
foreach ($matches as $match) {
if (isset($match[1]) && isset($match[3])) {
$this->elements[$match[1]] = isset($match[4]) ? $match[4] : $match[3];
diff --git a/Http/Firewall/ExceptionListener.php b/Http/Firewall/ExceptionListener.php
index fac5dc1..e52f927 100644
--- a/Http/Firewall/ExceptionListener.php
+++ b/Http/Firewall/ExceptionListener.php
@@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Http\Firewall;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
@@ -70,16 +71,22 @@ class ExceptionListener
}
/**
+ * Unregisters the dispatcher.
+ *
+ * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
+ */
+ public function unregister(EventDispatcherInterface $dispatcher)
+ {
+ $dispatcher->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
+ }
+
+ /**
* Handles security related exceptions.
*
* @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
- // we need to remove ourselves as the exception listener can be
- // different depending on the Request
- $event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
-
$exception = $event->getException();
do {
if ($exception instanceof AuthenticationException) {
@@ -140,7 +147,7 @@ class ExceptionListener
}
} elseif (null !== $this->errorPage) {
$subRequest = $this->httpUtils->createRequest($event->getRequest(), $this->errorPage);
- $subRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $exception);
+ $subRequest->attributes->set(Security::ACCESS_DENIED_ERROR, $exception);
$event->setResponse($event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true));
}
diff --git a/Http/Firewall/LogoutListener.php b/Http/Firewall/LogoutListener.php
index 5a68670..3a45e37 100644
--- a/Http/Firewall/LogoutListener.php
+++ b/Http/Firewall/LogoutListener.php
@@ -11,12 +11,16 @@
namespace Symfony\Component\Security\Http\Firewall;
+use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Exception\LogoutException;
+use Symfony\Component\Security\Csrf\CsrfToken;
+use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
@@ -33,19 +37,25 @@ class LogoutListener implements ListenerInterface
private $handlers;
private $successHandler;
private $httpUtils;
- private $csrfProvider;
+ private $csrfTokenManager;
/**
* Constructor.
*
* @param SecurityContextInterface $securityContext
- * @param HttpUtils $httpUtils An HttpUtilsInterface instance
- * @param LogoutSuccessHandlerInterface $successHandler A LogoutSuccessHandlerInterface instance
- * @param array $options An array of options to process a logout attempt
- * @param CsrfProviderInterface $csrfProvider A CsrfProviderInterface instance
+ * @param HttpUtils $httpUtils An HttpUtilsInterface instance
+ * @param LogoutSuccessHandlerInterface $successHandler A LogoutSuccessHandlerInterface instance
+ * @param array $options An array of options to process a logout attempt
+ * @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
*/
- public function __construct(SecurityContextInterface $securityContext, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), CsrfProviderInterface $csrfProvider = null)
+ public function __construct(SecurityContextInterface $securityContext, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), $csrfTokenManager = null)
{
+ if ($csrfTokenManager instanceof CsrfProviderInterface) {
+ $csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
+ } elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
+ throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
+ }
+
$this->securityContext = $securityContext;
$this->httpUtils = $httpUtils;
$this->options = array_merge(array(
@@ -54,7 +64,7 @@ class LogoutListener implements ListenerInterface
'logout_path' => '/logout',
), $options);
$this->successHandler = $successHandler;
- $this->csrfProvider = $csrfProvider;
+ $this->csrfTokenManager = $csrfTokenManager;
$this->handlers = array();
}
@@ -71,7 +81,7 @@ class LogoutListener implements ListenerInterface
/**
* Performs the logout if requested.
*
- * If a CsrfProviderInterface instance is available, it will be used to
+ * If a CsrfTokenManagerInterface instance is available, it will be used to
* validate the request.
*
* @param GetResponseEvent $event A GetResponseEvent instance
@@ -87,10 +97,10 @@ class LogoutListener implements ListenerInterface
return;
}
- if (null !== $this->csrfProvider) {
+ if (null !== $this->csrfTokenManager) {
$csrfToken = $request->get($this->options['csrf_parameter'], null, true);
- if (false === $this->csrfProvider->isCsrfTokenValid($this->options['intention'], $csrfToken)) {
+ if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
throw new LogoutException('Invalid CSRF token.');
}
}
diff --git a/Http/Firewall/RememberMeListener.php b/Http/Firewall/RememberMeListener.php
index beacff3..7ec73e7 100644
--- a/Http/Firewall/RememberMeListener.php
+++ b/Http/Firewall/RememberMeListener.php
@@ -33,6 +33,7 @@ class RememberMeListener implements ListenerInterface
private $authenticationManager;
private $logger;
private $dispatcher;
+ private $catchExceptions = true;
/**
* Constructor.
@@ -42,14 +43,16 @@ class RememberMeListener implements ListenerInterface
* @param AuthenticationManagerInterface $authenticationManager
* @param LoggerInterface $logger
* @param EventDispatcherInterface $dispatcher
+ * @param bool $catchExceptions
*/
- public function __construct(SecurityContextInterface $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
+ public function __construct(SecurityContextInterface $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $catchExceptions = true)
{
$this->securityContext = $securityContext;
$this->rememberMeServices = $rememberMeServices;
$this->authenticationManager = $authenticationManager;
$this->logger = $logger;
$this->dispatcher = $dispatcher;
+ $this->catchExceptions = $catchExceptions;
}
/**
@@ -90,6 +93,10 @@ class RememberMeListener implements ListenerInterface
}
$this->rememberMeServices->loginFail($request);
+
+ if (!$this->catchExceptions) {
+ throw $failed;
+ }
}
}
}
diff --git a/Http/Firewall/RemoteUserAuthenticationListener.php b/Http/Firewall/RemoteUserAuthenticationListener.php
new file mode 100644
index 0000000..f190a17
--- /dev/null
+++ b/Http/Firewall/RemoteUserAuthenticationListener.php
@@ -0,0 +1,49 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Firewall;
+
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Core\Exception\BadCredentialsException;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+
+/**
+ * REMOTE_USER authentication listener.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Maxime Douailin <maxime.douailin@gmail.com>
+ */
+class RemoteUserAuthenticationListener extends AbstractPreAuthenticatedListener
+{
+ private $userKey;
+
+ public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $userKey = 'REMOTE_USER', LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null)
+ {
+ parent::__construct($securityContext, $authenticationManager, $providerKey, $logger, $dispatcher);
+
+ $this->userKey = $userKey;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getPreAuthenticatedData(Request $request)
+ {
+ if (!$request->server->has($this->userKey)) {
+ throw new BadCredentialsException(sprintf('User key was not found: %s', $this->userKey));
+ }
+
+ return array($request->server->get($this->userKey), null);
+ }
+}
diff --git a/Http/Firewall/SimpleFormAuthenticationListener.php b/Http/Firewall/SimpleFormAuthenticationListener.php
new file mode 100644
index 0000000..7f27b7f
--- /dev/null
+++ b/Http/Firewall/SimpleFormAuthenticationListener.php
@@ -0,0 +1,124 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Firewall;
+
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
+use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
+use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
+use Symfony\Component\Security\Csrf\CsrfToken;
+use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
+use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
+use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
+use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
+use Symfony\Component\Security\Core\Authentication\SimpleFormAuthenticatorInterface;
+use Symfony\Component\Security\Core\Security;
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Http\HttpUtils;
+use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
+use Psr\Log\LoggerInterface;
+
+/**
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class SimpleFormAuthenticationListener extends AbstractAuthenticationListener
+{
+ private $simpleAuthenticator;
+ private $csrfTokenManager;
+
+ /**
+ * Constructor.
+ *
+ * @param SecurityContextInterface $securityContext A SecurityContext instance
+ * @param AuthenticationManagerInterface $authenticationManager An AuthenticationManagerInterface instance
+ * @param SessionAuthenticationStrategyInterface $sessionStrategy
+ * @param HttpUtils $httpUtils An HttpUtilsInterface instance
+ * @param string $providerKey
+ * @param AuthenticationSuccessHandlerInterface $successHandler
+ * @param AuthenticationFailureHandlerInterface $failureHandler
+ * @param array $options An array of options for the processing of a
+ * successful, or failed authentication attempt
+ * @param LoggerInterface $logger A LoggerInterface instance
+ * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
+ * @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
+ * @param SimpleFormAuthenticatorInterface $simpleAuthenticator A SimpleFormAuthenticatorInterface instance
+ *
+ * @throws \InvalidArgumentException In case no simple authenticator is provided
+ * @throws InvalidArgumentException In case an invalid CSRF token manager is passed
+ */
+ public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
+ {
+ if (!$simpleAuthenticator) {
+ throw new \InvalidArgumentException('Missing simple authenticator');
+ }
+
+ if ($csrfTokenManager instanceof CsrfProviderInterface) {
+ $csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
+ } elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
+ throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
+ }
+
+ $this->simpleAuthenticator = $simpleAuthenticator;
+ $this->csrfTokenManager = $csrfTokenManager;
+
+ $options = array_merge(array(
+ 'username_parameter' => '_username',
+ 'password_parameter' => '_password',
+ 'csrf_parameter' => '_csrf_token',
+ 'intention' => 'authenticate',
+ 'post_only' => true,
+ ), $options);
+ parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, $options, $logger, $dispatcher);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function requiresAuthentication(Request $request)
+ {
+ if ($this->options['post_only'] && !$request->isMethod('POST')) {
+ return false;
+ }
+
+ return parent::requiresAuthentication($request);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function attemptAuthentication(Request $request)
+ {
+ if (null !== $this->csrfTokenManager) {
+ $csrfToken = $request->get($this->options['csrf_parameter'], null, true);
+
+ if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
+ throw new InvalidCsrfTokenException('Invalid CSRF token.');
+ }
+ }
+
+ if ($this->options['post_only']) {
+ $username = trim($request->request->get($this->options['username_parameter'], null, true));
+ $password = $request->request->get($this->options['password_parameter'], null, true);
+ } else {
+ $username = trim($request->get($this->options['username_parameter'], null, true));
+ $password = $request->get($this->options['password_parameter'], null, true);
+ }
+
+ $request->getSession()->set(Security::LAST_USERNAME, $username);
+
+ $token = $this->simpleAuthenticator->createToken($request, $username, $password, $this->providerKey);
+
+ return $this->authenticationManager->authenticate($token);
+ }
+}
diff --git a/Http/Firewall/SimplePreAuthenticationListener.php b/Http/Firewall/SimplePreAuthenticationListener.php
new file mode 100644
index 0000000..e80cc98
--- /dev/null
+++ b/Http/Firewall/SimplePreAuthenticationListener.php
@@ -0,0 +1,115 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Firewall;
+
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
+use Psr\Log\LoggerInterface;
+use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Security\Core\Authentication\SimplePreAuthenticatorInterface;
+use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
+use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
+
+/**
+ * SimplePreAuthenticationListener implements simple proxying to an authenticator.
+ *
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class SimplePreAuthenticationListener implements ListenerInterface
+{
+ private $securityContext;
+ private $authenticationManager;
+ private $providerKey;
+ private $simpleAuthenticator;
+ private $logger;
+
+ /**
+ * Constructor.
+ *
+ * @param SecurityContextInterface $securityContext A SecurityContext instance
+ * @param AuthenticationManagerInterface $authenticationManager An AuthenticationManagerInterface instance
+ * @param string $providerKey
+ * @param SimplePreAuthenticatorInterface $simpleAuthenticator A SimplePreAuthenticatorInterface instance
+ * @param LoggerInterface $logger A LoggerInterface instance
+ */
+ public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, SimplePreAuthenticatorInterface $simpleAuthenticator, LoggerInterface $logger = null)
+ {
+ if (empty($providerKey)) {
+ throw new \InvalidArgumentException('$providerKey must not be empty.');
+ }
+
+ $this->securityContext = $securityContext;
+ $this->authenticationManager = $authenticationManager;
+ $this->providerKey = $providerKey;
+ $this->simpleAuthenticator = $simpleAuthenticator;
+ $this->logger = $logger;
+ }
+
+ /**
+ * Handles basic authentication.
+ *
+ * @param GetResponseEvent $event A GetResponseEvent instance
+ */
+ public function handle(GetResponseEvent $event)
+ {
+ $request = $event->getRequest();
+
+ if (null !== $this->logger) {
+ $this->logger->info(sprintf('Attempting simple pre-authorization %s', $this->providerKey));
+ }
+
+ if (null !== $this->securityContext->getToken() && !$this->securityContext->getToken() instanceof AnonymousToken) {
+ return;
+ }
+
+ try {
+ $token = $this->simpleAuthenticator->createToken($request, $this->providerKey);
+
+ // allow null to be returned to skip authentication
+ if (null === $token) {
+ return;
+ }
+
+ $token = $this->authenticationManager->authenticate($token);
+ $this->securityContext->setToken($token);
+ } catch (AuthenticationException $e) {
+ $this->securityContext->setToken(null);
+
+ if (null !== $this->logger) {
+ $this->logger->info(sprintf('Authentication request failed: %s', $e->getMessage()));
+ }
+
+ if ($this->simpleAuthenticator instanceof AuthenticationFailureHandlerInterface) {
+ $response = $this->simpleAuthenticator->onAuthenticationFailure($request, $e);
+ if ($response instanceof Response) {
+ $event->setResponse($response);
+ } elseif (null !== $response) {
+ throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationFailure method must return null or a Response object', get_class($this->simpleAuthenticator)));
+ }
+ }
+
+ return;
+ }
+
+ if ($this->simpleAuthenticator instanceof AuthenticationSuccessHandlerInterface) {
+ $response = $this->simpleAuthenticator->onAuthenticationSuccess($request, $token);
+ if ($response instanceof Response) {
+ $event->setResponse($response);
+ } elseif (null !== $response) {
+ throw new \UnexpectedValueException(sprintf('The %s::onAuthenticationSuccess method must return null or a Response object', get_class($this->simpleAuthenticator)));
+ }
+ }
+ }
+}
diff --git a/Http/Firewall/SwitchUserListener.php b/Http/Firewall/SwitchUserListener.php
index 7700096..b46b1bc 100644
--- a/Http/Firewall/SwitchUserListener.php
+++ b/Http/Firewall/SwitchUserListener.php
@@ -92,7 +92,9 @@ class SwitchUserListener implements ListenerInterface
}
}
- $request->server->set('QUERY_STRING', '');
+ $request->query->remove($this->usernameParameter);
+ $request->server->set('QUERY_STRING', http_build_query($request->query->all()));
+
$response = new RedirectResponse($request->getUri(), 302);
$event->setResponse($response);
diff --git a/Http/Firewall/UsernamePasswordFormAuthenticationListener.php b/Http/Firewall/UsernamePasswordFormAuthenticationListener.php
index 2147817..b857fb3 100644
--- a/Http/Firewall/UsernamePasswordFormAuthenticationListener.php
+++ b/Http/Firewall/UsernamePasswordFormAuthenticationListener.php
@@ -11,16 +11,21 @@
namespace Symfony\Component\Security\Http\Firewall;
+use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Psr\Log\LoggerInterface;
+use Symfony\Component\Security\Csrf\CsrfToken;
+use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
use Symfony\Component\Security\Http\HttpUtils;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
+use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -32,13 +37,19 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationListener
{
- private $csrfProvider;
+ private $csrfTokenManager;
/**
* {@inheritdoc}
*/
- public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfProviderInterface $csrfProvider = null)
+ public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null)
{
+ if ($csrfTokenManager instanceof CsrfProviderInterface) {
+ $csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
+ } elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
+ throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
+ }
+
parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
'username_parameter' => '_username',
'password_parameter' => '_password',
@@ -47,7 +58,7 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
'post_only' => true,
), $options), $logger, $dispatcher);
- $this->csrfProvider = $csrfProvider;
+ $this->csrfTokenManager = $csrfTokenManager;
}
/**
@@ -67,10 +78,10 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
*/
protected function attemptAuthentication(Request $request)
{
- if (null !== $this->csrfProvider) {
+ if (null !== $this->csrfTokenManager) {
$csrfToken = $request->get($this->options['csrf_parameter'], null, true);
- if (false === $this->csrfProvider->isCsrfTokenValid($this->options['intention'], $csrfToken)) {
+ if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
throw new InvalidCsrfTokenException('Invalid CSRF token.');
}
}
@@ -83,7 +94,7 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
$password = $request->get($this->options['password_parameter'], null, true);
}
- $request->getSession()->set(SecurityContextInterface::LAST_USERNAME, $username);
+ $request->getSession()->set(Security::LAST_USERNAME, $username);
return $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $password, $this->providerKey));
}
diff --git a/Http/HttpUtils.php b/Http/HttpUtils.php
index 0f47809..ed737a2 100644
--- a/Http/HttpUtils.php
+++ b/Http/HttpUtils.php
@@ -11,7 +11,6 @@
namespace Symfony\Component\Security\Http;
-use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
@@ -19,6 +18,7 @@ use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
+use Symfony\Component\Security\Core\Security;
/**
* Encapsulates the logic needed to create sub-requests, redirect the user, and match URLs.
@@ -71,19 +71,19 @@ class HttpUtils
*/
public function createRequest(Request $request, $path)
{
- $newRequest = $request::create($this->generateUri($request, $path), 'get', array(), $request->cookies->all(), array(), $request->server->all());
+ $newRequest = Request::create($this->generateUri($request, $path), 'get', array(), $request->cookies->all(), array(), $request->server->all());
if ($request->hasSession()) {
$newRequest->setSession($request->getSession());
}
- if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
- $newRequest->attributes->set(SecurityContextInterface::AUTHENTICATION_ERROR, $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR));
+ if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
+ $newRequest->attributes->set(Security::AUTHENTICATION_ERROR, $request->attributes->get(Security::AUTHENTICATION_ERROR));
}
- if ($request->attributes->has(SecurityContextInterface::ACCESS_DENIED_ERROR)) {
- $newRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $request->attributes->get(SecurityContextInterface::ACCESS_DENIED_ERROR));
+ if ($request->attributes->has(Security::ACCESS_DENIED_ERROR)) {
+ $newRequest->attributes->set(Security::ACCESS_DENIED_ERROR, $request->attributes->get(Security::ACCESS_DENIED_ERROR));
}
- if ($request->attributes->has(SecurityContextInterface::LAST_USERNAME)) {
- $newRequest->attributes->set(SecurityContextInterface::LAST_USERNAME, $request->attributes->get(SecurityContextInterface::LAST_USERNAME));
+ if ($request->attributes->has(Security::LAST_USERNAME)) {
+ $newRequest->attributes->set(Security::LAST_USERNAME, $request->attributes->get(Security::LAST_USERNAME));
}
return $newRequest;
diff --git a/Http/LICENSE b/Http/LICENSE
new file mode 100644
index 0000000..43028bc
--- /dev/null
+++ b/Http/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2004-2015 Fabien Potencier
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/Http/README.md b/Http/README.md
new file mode 100644
index 0000000..e19af42
--- /dev/null
+++ b/Http/README.md
@@ -0,0 +1,23 @@
+Security Component - HTTP Integration
+=====================================
+
+Security provides an infrastructure for sophisticated authorization systems,
+which makes it possible to easily separate the actual authorization logic from
+so called user providers that hold the users credentials. It is inspired by
+the Java Spring framework.
+
+Resources
+---------
+
+Documentation:
+
+http://symfony.com/doc/2.6/book/security.html
+
+Tests
+-----
+
+You can run the unit tests with the following command:
+
+ $ cd path/to/Symfony/Component/Security/Http/
+ $ composer.phar install --dev
+ $ phpunit
diff --git a/Http/RememberMe/ResponseListener.php b/Http/RememberMe/ResponseListener.php
index ec5f006..4149fb6 100644
--- a/Http/RememberMe/ResponseListener.php
+++ b/Http/RememberMe/ResponseListener.php
@@ -13,7 +13,6 @@ namespace Symfony\Component\Security\Http\RememberMe;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
-use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
@@ -28,7 +27,7 @@ class ResponseListener implements EventSubscriberInterface
*/
public function onKernelResponse(FilterResponseEvent $event)
{
- if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
+ if (!$event->isMasterRequest()) {
return;
}
diff --git a/Http/RememberMe/TokenBasedRememberMeServices.php b/Http/RememberMe/TokenBasedRememberMeServices.php
index 8283a7c..9042963 100644
--- a/Http/RememberMe/TokenBasedRememberMeServices.php
+++ b/Http/RememberMe/TokenBasedRememberMeServices.php
@@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
+use Symfony\Component\Security\Core\Util\StringUtils;
/**
* Concrete implementation of the RememberMeServicesInterface providing
@@ -53,7 +54,7 @@ class TokenBasedRememberMeServices extends AbstractRememberMeServices
throw new \RuntimeException(sprintf('The UserProviderInterface implementation must return an instance of UserInterface, but returned "%s".', get_class($user)));
}
- if (true !== $this->compareHashes($hash, $this->generateCookieHash($class, $username, $expires, $user->getPassword()))) {
+ if (true !== StringUtils::equals($hash, $this->generateCookieHash($class, $username, $expires, $user->getPassword()))) {
throw new AuthenticationException('The cookie\'s hash is invalid.');
}
@@ -65,31 +66,6 @@ class TokenBasedRememberMeServices extends AbstractRememberMeServices
}
/**
- * Compares two hashes using a constant-time algorithm to avoid (remote)
- * timing attacks.
- *
- * This is the same implementation as used in the BasePasswordEncoder.
- *
- * @param string $hash1 The first hash
- * @param string $hash2 The second hash
- *
- * @return bool true if the two hashes are the same, false otherwise
- */
- private function compareHashes($hash1, $hash2)
- {
- if (strlen($hash1) !== $c = strlen($hash2)) {
- return false;
- }
-
- $result = 0;
- for ($i = 0; $i < $c; $i++) {
- $result |= ord($hash1[$i]) ^ ord($hash2[$i]);
- }
-
- return 0 === $result;
- }
-
- /**
* {@inheritdoc}
*/
protected function onLoginSuccess(Request $request, Response $response, TokenInterface $token)
@@ -147,6 +123,6 @@ class TokenBasedRememberMeServices extends AbstractRememberMeServices
*/
protected function generateCookieHash($class, $username, $expires, $password)
{
- return hash('sha256', $class.$username.$expires.$password.$this->getKey());
+ return hash_hmac('sha256', $class.$username.$expires.$password, $this->getKey());
}
}
diff --git a/Tests/Http/AccessMapTest.php b/Http/Tests/AccessMapTest.php
index c2d9b7f..d8ab7aa 100644
--- a/Tests/Http/AccessMapTest.php
+++ b/Http/Tests/AccessMapTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http;
+namespace Symfony\Component\Security\Http\Tests;
use Symfony\Component\Security\Http\AccessMap;
diff --git a/Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php b/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
index accc45d..e065660 100644
--- a/Tests/Http/Authentication/DefaultAuthenticationFailureHandlerTest.php
+++ b/Http/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
@@ -9,10 +9,10 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Authentication;
+namespace Symfony\Component\Security\Http\Tests\Authentication;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
-use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCase
@@ -47,7 +47,7 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas
$subRequest = $this->getRequest();
$subRequest->attributes->expects($this->once())
- ->method('set')->with(SecurityContextInterface::AUTHENTICATION_ERROR, $this->exception);
+ ->method('set')->with(Security::AUTHENTICATION_ERROR, $this->exception);
$this->httpUtils->expects($this->once())
->method('createRequest')->with($this->request, '/login')
->will($this->returnValue($subRequest));
@@ -79,7 +79,7 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas
public function testExceptionIsPersistedInSession()
{
$this->session->expects($this->once())
- ->method('set')->with(SecurityContextInterface::AUTHENTICATION_ERROR, $this->exception);
+ ->method('set')->with(Security::AUTHENTICATION_ERROR, $this->exception);
$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, array(), $this->logger);
$handler->onAuthenticationFailure($this->request, $this->exception);
@@ -91,7 +91,7 @@ class DefaultAuthenticationFailureHandlerTest extends \PHPUnit_Framework_TestCas
$subRequest = $this->getRequest();
$subRequest->attributes->expects($this->once())
- ->method('set')->with(SecurityContextInterface::AUTHENTICATION_ERROR, $this->exception);
+ ->method('set')->with(Security::AUTHENTICATION_ERROR, $this->exception);
$this->httpUtils->expects($this->once())
->method('createRequest')->with($this->request, '/login')
diff --git a/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php b/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php
index 3d8ebf3..4d1847d 100644
--- a/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
+++ b/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Authentication;
+namespace Symfony\Component\Security\Http\Tests\Authentication;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
diff --git a/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php b/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php
new file mode 100644
index 0000000..97167c9
--- /dev/null
+++ b/Http/Tests/Authentication/SimpleAuthenticationHandlerTest.php
@@ -0,0 +1,194 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Tests;
+
+use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
+use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
+use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
+use Symfony\Component\Security\Http\Authentication\SimpleAuthenticationHandler;
+
+class SimpleAuthenticationHandlerTest extends \PHPUnit_Framework_TestCase
+{
+ private $successHandler;
+
+ private $failureHandler;
+
+ private $request;
+
+ private $token;
+
+ private $authenticationException;
+
+ private $response;
+
+ public function setUp()
+ {
+ $this->successHandler = $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface');
+ $this->failureHandler = $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface');
+
+ $this->request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ // No methods are invoked on the exception; we just assert on its class
+ $this->authenticationException = new AuthenticationException();
+
+ $this->response = $this->getMock('Symfony\Component\HttpFoundation\Response');
+ }
+
+ public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfSimpleIsNotASuccessHandler()
+ {
+ $authenticator = $this->getMock('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface');
+
+ $this->successHandler->expects($this->once())
+ ->method('onAuthenticationSuccess')
+ ->with($this->request, $this->token)
+ ->will($this->returnValue($this->response));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($this->response, $result);
+ }
+
+ public function testOnAuthenticationSuccessCallsSimpleAuthenticator()
+ {
+ $this->successHandler->expects($this->never())
+ ->method('onAuthenticationSuccess');
+
+ $authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestSuccessHandlerInterface');
+ $authenticator->expects($this->once())
+ ->method('onAuthenticationSuccess')
+ ->with($this->request, $this->token)
+ ->will($this->returnValue($this->response));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($this->response, $result);
+ }
+
+ /**
+ * @expectedException \UnexpectedValueException
+ * @expectedExceptionMessage onAuthenticationSuccess method must return null to use the default success handler, or a Response object
+ */
+ public function testOnAuthenticationSuccessThrowsAnExceptionIfNonResponseIsReturned()
+ {
+ $this->successHandler->expects($this->never())
+ ->method('onAuthenticationSuccess');
+
+ $authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestSuccessHandlerInterface');
+ $authenticator->expects($this->once())
+ ->method('onAuthenticationSuccess')
+ ->with($this->request, $this->token)
+ ->will($this->returnValue(new \stdClass()));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $handler->onAuthenticationSuccess($this->request, $this->token);
+ }
+
+ public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfNullIsReturned()
+ {
+ $this->successHandler->expects($this->once())
+ ->method('onAuthenticationSuccess')
+ ->with($this->request, $this->token)
+ ->will($this->returnValue($this->response));
+
+ $authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestSuccessHandlerInterface');
+ $authenticator->expects($this->once())
+ ->method('onAuthenticationSuccess')
+ ->with($this->request, $this->token)
+ ->will($this->returnValue(null));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $result = $handler->onAuthenticationSuccess($this->request, $this->token);
+
+ $this->assertSame($this->response, $result);
+ }
+
+ public function testOnAuthenticationFailureFallsBackToDefaultHandlerIfSimpleIsNotAFailureHandler()
+ {
+ $authenticator = $this->getMock('Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface');
+
+ $this->failureHandler->expects($this->once())
+ ->method('onAuthenticationFailure')
+ ->with($this->request, $this->authenticationException)
+ ->will($this->returnValue($this->response));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $result = $handler->onAuthenticationFailure($this->request, $this->authenticationException);
+
+ $this->assertSame($this->response, $result);
+ }
+
+ public function testOnAuthenticationFailureCallsSimpleAuthenticator()
+ {
+ $this->failureHandler->expects($this->never())
+ ->method('onAuthenticationFailure');
+
+ $authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestFailureHandlerInterface');
+ $authenticator->expects($this->once())
+ ->method('onAuthenticationFailure')
+ ->with($this->request, $this->authenticationException)
+ ->will($this->returnValue($this->response));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $result = $handler->onAuthenticationFailure($this->request, $this->authenticationException);
+
+ $this->assertSame($this->response, $result);
+ }
+
+ /**
+ * @expectedException \UnexpectedValueException
+ * @expectedExceptionMessage onAuthenticationFailure method must return null to use the default failure handler, or a Response object
+ */
+ public function testOnAuthenticationFailureThrowsAnExceptionIfNonResponseIsReturned()
+ {
+ $this->failureHandler->expects($this->never())
+ ->method('onAuthenticationFailure');
+
+ $authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestFailureHandlerInterface');
+ $authenticator->expects($this->once())
+ ->method('onAuthenticationFailure')
+ ->with($this->request, $this->authenticationException)
+ ->will($this->returnValue(new \stdClass()));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $handler->onAuthenticationFailure($this->request, $this->authenticationException);
+ }
+
+ public function testOnAuthenticationFailureFallsBackToDefaultHandlerIfNullIsReturned()
+ {
+ $this->failureHandler->expects($this->once())
+ ->method('onAuthenticationFailure')
+ ->with($this->request, $this->authenticationException)
+ ->will($this->returnValue($this->response));
+
+ $authenticator = $this->getMockForAbstractClass('Symfony\Component\Security\Http\Tests\TestFailureHandlerInterface');
+ $authenticator->expects($this->once())
+ ->method('onAuthenticationFailure')
+ ->with($this->request, $this->authenticationException)
+ ->will($this->returnValue(null));
+
+ $handler = new SimpleAuthenticationHandler($authenticator, $this->successHandler, $this->failureHandler);
+ $result = $handler->onAuthenticationFailure($this->request, $this->authenticationException);
+
+ $this->assertSame($this->response, $result);
+ }
+}
+
+interface TestSuccessHandlerInterface extends AuthenticationSuccessHandlerInterface, SimpleAuthenticatorInterface
+{
+}
+
+interface TestFailureHandlerInterface extends AuthenticationFailureHandlerInterface, SimpleAuthenticatorInterface
+{
+}
diff --git a/Tests/Http/EntryPoint/BasicAuthenticationEntryPointTest.php b/Http/Tests/EntryPoint/BasicAuthenticationEntryPointTest.php
index 5640789..ca5922c 100644
--- a/Tests/Http/EntryPoint/BasicAuthenticationEntryPointTest.php
+++ b/Http/Tests/EntryPoint/BasicAuthenticationEntryPointTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\EntryPoint;
+namespace Symfony\Component\Security\Http\Tests\EntryPoint;
use Symfony\Component\Security\Http\EntryPoint\BasicAuthenticationEntryPoint;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
diff --git a/Tests/Http/EntryPoint/DigestAuthenticationEntryPointTest.php b/Http/Tests/EntryPoint/DigestAuthenticationEntryPointTest.php
index 5c6eccc..181e340 100644
--- a/Tests/Http/EntryPoint/DigestAuthenticationEntryPointTest.php
+++ b/Http/Tests/EntryPoint/DigestAuthenticationEntryPointTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\EntryPoint;
+namespace Symfony\Component\Security\Http\Tests\EntryPoint;
use Symfony\Component\Security\Http\EntryPoint\DigestAuthenticationEntryPoint;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
diff --git a/Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php b/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php
index 097912d..3acb9c2 100644
--- a/Tests/Http/EntryPoint/FormAuthenticationEntryPointTest.php
+++ b/Http/Tests/EntryPoint/FormAuthenticationEntryPointTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\EntryPoint;
+namespace Symfony\Component\Security\Http\Tests\EntryPoint;
use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint;
use Symfony\Component\HttpKernel\HttpKernelInterface;
diff --git a/Tests/Http/EntryPoint/RetryAuthenticationEntryPointTest.php b/Http/Tests/EntryPoint/RetryAuthenticationEntryPointTest.php
index 59ec912..ff5fbc2 100644
--- a/Tests/Http/EntryPoint/RetryAuthenticationEntryPointTest.php
+++ b/Http/Tests/EntryPoint/RetryAuthenticationEntryPointTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\EntryPoint;
+namespace Symfony\Component\Security\Http\Tests\EntryPoint;
use Symfony\Component\Security\Http\EntryPoint\RetryAuthenticationEntryPoint;
use Symfony\Component\HttpFoundation\Request;
diff --git a/Tests/Http/Firewall/AbstractPreAuthenticatedListenerTest.php b/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
index d6373b3..6e34532 100644
--- a/Tests/Http/Firewall/AbstractPreAuthenticatedListenerTest.php
+++ b/Http/Tests/Firewall/AbstractPreAuthenticatedListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
diff --git a/Tests/Http/Firewall/AccessListenerTest.php b/Http/Tests/Firewall/AccessListenerTest.php
index 961c792..f9b0f3c 100644
--- a/Tests/Http/Firewall/AccessListenerTest.php
+++ b/Http/Tests/Firewall/AccessListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\Security\Http\Firewall\AccessListener;
diff --git a/Tests/Http/Firewall/AnonymousAuthenticationListenerTest.php b/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php
index 0666ef3..3bc4eb6 100644
--- a/Tests/Http/Firewall/AnonymousAuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/AnonymousAuthenticationListenerTest.php
@@ -9,8 +9,9 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
+use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener;
class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
@@ -28,7 +29,13 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->method('setToken')
;
- $listener = new AnonymousAuthenticationListener($context, 'TheKey');
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+ $authenticationManager
+ ->expects($this->never())
+ ->method('authenticate')
+ ;
+
+ $listener = new AnonymousAuthenticationListener($context, 'TheKey', null, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
}
@@ -40,16 +47,27 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->method('getToken')
->will($this->returnValue(null))
;
- $context
+
+ $anonymousToken = new AnonymousToken('TheKey', 'anon.', array());
+
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+ $authenticationManager
->expects($this->once())
- ->method('setToken')
+ ->method('authenticate')
->with(self::logicalAnd(
- $this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken'),
- $this->attributeEqualTo('key', 'TheKey')
+ $this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken'),
+ $this->attributeEqualTo('key', 'TheKey')
))
+ ->will($this->returnValue($anonymousToken))
;
- $listener = new AnonymousAuthenticationListener($context, 'TheKey');
+ $context
+ ->expects($this->once())
+ ->method('setToken')
+ ->with($anonymousToken)
+ ;
+
+ $listener = new AnonymousAuthenticationListener($context, 'TheKey', null, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
}
@@ -62,7 +80,9 @@ class AnonymousAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
->with('Populated SecurityContext with an anonymous Token')
;
- $listener = new AnonymousAuthenticationListener($context, 'TheKey', $logger);
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+
+ $listener = new AnonymousAuthenticationListener($context, 'TheKey', $logger, $authenticationManager);
$listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false));
}
}
diff --git a/Tests/Http/Firewall/BasicAuthenticationListenerTest.php b/Http/Tests/Firewall/BasicAuthenticationListenerTest.php
index 65dc185..0ef993f 100644
--- a/Tests/Http/Firewall/BasicAuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/BasicAuthenticationListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
diff --git a/Tests/Http/Firewall/ChannelListenerTest.php b/Http/Tests/Firewall/ChannelListenerTest.php
index 5e583e0..1465224 100644
--- a/Tests/Http/Firewall/ChannelListenerTest.php
+++ b/Http/Tests/Firewall/ChannelListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\Security\Http\Firewall\ChannelListener;
use Symfony\Component\HttpFoundation\Response;
diff --git a/Tests/Http/Firewall/ContextListenerTest.php b/Http/Tests/Firewall/ContextListenerTest.php
index 6b4ef73..00ec418 100644
--- a/Tests/Http/Firewall/ContextListenerTest.php
+++ b/Http/Tests/Firewall/ContextListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Http\Firewall\ContextListener;
@@ -28,8 +29,8 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->securityContext = new SecurityContext(
- $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'),
- $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')
+ new TokenStorage(),
+ $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')
);
}
@@ -190,8 +191,8 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
$listener = new ContextListener($context, array(), 'key123', null, $dispatcher);
$event->expects($this->any())
- ->method('getRequestType')
- ->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
+ ->method('isMasterRequest')
+ ->will($this->returnValue(true));
$event->expects($this->any())
->method('getRequest')
->will($this->returnValue($this->getMock('Symfony\Component\HttpFoundation\Request')));
@@ -219,8 +220,8 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(true));
$event->expects($this->any())
- ->method('getRequestType')
- ->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
+ ->method('isMasterRequest')
+ ->will($this->returnValue(true));
$event->expects($this->any())
->method('getRequest')
->will($this->returnValue($request));
diff --git a/Tests/Http/Firewall/DigestDataTest.php b/Http/Tests/Firewall/DigestDataTest.php
index e5be6f8..a7c8d49 100644
--- a/Tests/Http/Firewall/DigestDataTest.php
+++ b/Http/Tests/Firewall/DigestDataTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\Security\Http\Firewall\DigestData;
diff --git a/Tests/Http/Firewall/ExceptionListenerTest.php b/Http/Tests/Firewall/ExceptionListenerTest.php
index 12f18a6..6b99471 100644
--- a/Tests/Http/Firewall/ExceptionListenerTest.php
+++ b/Http/Tests/Firewall/ExceptionListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -166,12 +166,7 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
}
- $event = new GetResponseForExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception);
-
- $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
- $event->setDispatcher($dispatcher);
-
- return $event;
+ return new GetResponseForExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception);
}
private function createExceptionListener(SecurityContextInterface $context = null, AuthenticationTrustResolverInterface $trustResolver = null, HttpUtils $httpUtils = null, AuthenticationEntryPointInterface $authenticationEntryPoint = null, $errorPage = null, AccessDeniedHandlerInterface $accessDeniedHandler = null)
diff --git a/Tests/Http/Firewall/LogoutListenerTest.php b/Http/Tests/Firewall/LogoutListenerTest.php
index 9301086..041febc 100644
--- a/Tests/Http/Firewall/LogoutListenerTest.php
+++ b/Http/Tests/Firewall/LogoutListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -37,22 +37,21 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
public function testHandleMatchedPathWithSuccessHandlerAndCsrfValidation()
{
$successHandler = $this->getSuccessHandler();
- $csrfProvider = $this->getCsrfProvider();
+ $tokenManager = $this->getTokenManager();
- list($listener, $context, $httpUtils, $options) = $this->getListener($successHandler, $csrfProvider);
+ list($listener, $context, $httpUtils, $options) = $this->getListener($successHandler, $tokenManager);
list($event, $request) = $this->getGetResponseEvent();
- $request->query->set('_csrf_token', $csrfToken = 'token');
+ $request->query->set('_csrf_token', 'token');
$httpUtils->expects($this->once())
->method('checkRequestPath')
->with($request, $options['logout_path'])
->will($this->returnValue(true));
- $csrfProvider->expects($this->once())
- ->method('isCsrfTokenValid')
- ->with('logout', $csrfToken)
+ $tokenManager->expects($this->once())
+ ->method('isTokenValid')
->will($this->returnValue(true));
$successHandler->expects($this->once())
@@ -151,30 +150,29 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
*/
public function testCsrfValidationFails()
{
- $csrfProvider = $this->getCsrfProvider();
+ $tokenManager = $this->getTokenManager();
- list($listener, $context, $httpUtils, $options) = $this->getListener(null, $csrfProvider);
+ list($listener, $context, $httpUtils, $options) = $this->getListener(null, $tokenManager);
list($event, $request) = $this->getGetResponseEvent();
- $request->query->set('_csrf_token', $csrfToken = 'token');
+ $request->query->set('_csrf_token', 'token');
$httpUtils->expects($this->once())
->method('checkRequestPath')
->with($request, $options['logout_path'])
->will($this->returnValue(true));
- $csrfProvider->expects($this->once())
- ->method('isCsrfTokenValid')
- ->with('logout', $csrfToken)
+ $tokenManager->expects($this->once())
+ ->method('isTokenValid')
->will($this->returnValue(false));
$listener->handle($event);
}
- private function getCsrfProvider()
+ private function getTokenManager()
{
- return $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface');
+ return $this->getMock('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface');
}
private function getContext()
@@ -209,7 +207,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
->getMock();
}
- private function getListener($successHandler = null, $csrfProvider = null)
+ private function getListener($successHandler = null, $tokenManager = null)
{
$listener = new LogoutListener(
$context = $this->getContext(),
@@ -221,7 +219,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
'logout_path' => '/logout',
'target_url' => '/',
),
- $csrfProvider
+ $tokenManager
);
return array($listener, $context, $httpUtils, $options);
diff --git a/Tests/Http/Firewall/RememberMeListenerTest.php b/Http/Tests/Firewall/RememberMeListenerTest.php
index 067cacb..12ced6b 100644
--- a/Tests/Http/Firewall/RememberMeListenerTest.php
+++ b/Http/Tests/Firewall/RememberMeListenerTest.php
@@ -9,17 +9,18 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Firewall\RememberMeListener;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Http\SecurityEvents;
class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
{
public function testOnCoreSecurityDoesNotTryToPopulateNonEmptySecurityContext()
{
- list($listener, $context, $service) = $this->getListener();
+ list($listener, $context) = $this->getListener();
$context
->expects($this->once())
@@ -99,6 +100,48 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($event);
}
+ /**
+ * @expectedException Symfony\Component\Security\Core\Exception\AuthenticationException
+ * @expectedExceptionMessage Authentication failed.
+ */
+ public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation()
+ {
+ list($listener, $context, $service, $manager,) = $this->getListener(false, false);
+
+ $context
+ ->expects($this->once())
+ ->method('getToken')
+ ->will($this->returnValue(null))
+ ;
+
+ $service
+ ->expects($this->once())
+ ->method('autoLogin')
+ ->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')))
+ ;
+
+ $service
+ ->expects($this->once())
+ ->method('loginFail')
+ ;
+
+ $exception = new AuthenticationException('Authentication failed.');
+ $manager
+ ->expects($this->once())
+ ->method('authenticate')
+ ->will($this->throwException($exception))
+ ;
+
+ $event = $this->getGetResponseEvent();
+ $event
+ ->expects($this->once())
+ ->method('getRequest')
+ ->will($this->returnValue(new Request()))
+ ;
+
+ $listener->handle($event);
+ }
+
public function testOnCoreSecurity()
{
list($listener, $context, $service, $manager) = $this->getListener();
@@ -138,6 +181,55 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($event);
}
+ public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent()
+ {
+ list($listener, $context, $service, $manager, , $dispatcher) = $this->getListener(true);
+
+ $context
+ ->expects($this->once())
+ ->method('getToken')
+ ->will($this->returnValue(null))
+ ;
+
+ $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $service
+ ->expects($this->once())
+ ->method('autoLogin')
+ ->will($this->returnValue($token))
+ ;
+
+ $context
+ ->expects($this->once())
+ ->method('setToken')
+ ->with($this->equalTo($token))
+ ;
+
+ $manager
+ ->expects($this->once())
+ ->method('authenticate')
+ ->will($this->returnValue($token))
+ ;
+
+ $event = $this->getGetResponseEvent();
+ $request = new Request();
+ $event
+ ->expects($this->once())
+ ->method('getRequest')
+ ->will($this->returnValue($request))
+ ;
+
+ $dispatcher
+ ->expects($this->once())
+ ->method('dispatch')
+ ->with(
+ SecurityEvents::INTERACTIVE_LOGIN,
+ $this->isInstanceOf('Symfony\Component\Security\Http\Event\InteractiveLoginEvent')
+ )
+ ;
+
+ $listener->handle($event);
+ }
+
protected function getGetResponseEvent()
{
return $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
@@ -148,16 +240,18 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
return $this->getMock('Symfony\Component\HttpKernel\Event\FilterResponseEvent', array(), array(), '', false);
}
- protected function getListener()
+ protected function getListener($withDispatcher = false, $catchExceptions = true)
{
$listener = new RememberMeListener(
$context = $this->getContext(),
$service = $this->getService(),
$manager = $this->getManager(),
- $logger = $this->getLogger()
+ $logger = $this->getLogger(),
+ $dispatcher = ($withDispatcher ? $this->getDispatcher() : null),
+ $catchExceptions
);
- return array($listener, $context, $service, $manager, $logger);
+ return array($listener, $context, $service, $manager, $logger, $dispatcher);
}
protected function getLogger()
@@ -177,8 +271,11 @@ class RememberMeListenerTest extends \PHPUnit_Framework_TestCase
protected function getContext()
{
- return $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContext')
- ->disableOriginalConstructor()
- ->getMock();
+ return $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+ }
+
+ protected function getDispatcher()
+ {
+ return $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
}
}
diff --git a/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php b/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php
new file mode 100644
index 0000000..6e6b979
--- /dev/null
+++ b/Http/Tests/Firewall/RemoteUserAuthenticationListenerTest.php
@@ -0,0 +1,91 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Http\Tests\Firewall;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Http\Firewall\RemoteUserAuthenticationListener;
+
+class RemoteUserAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
+{
+ public function testGetPreAuthenticatedData()
+ {
+ $serverVars = array(
+ 'REMOTE_USER' => 'TheUser',
+ );
+
+ $request = new Request(array(), array(), array(), array(), array(), $serverVars);
+
+ $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+
+ $listener = new RemoteUserAuthenticationListener(
+ $context,
+ $authenticationManager,
+ 'TheProviderKey'
+ );
+
+ $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
+ $method->setAccessible(true);
+
+ $result = $method->invokeArgs($listener, array($request));
+ $this->assertSame($result, array('TheUser', null));
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
+ */
+ public function testGetPreAuthenticatedDataNoUser()
+ {
+ $request = new Request(array(), array(), array(), array(), array(), array());
+
+ $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+
+ $listener = new RemoteUserAuthenticationListener(
+ $context,
+ $authenticationManager,
+ 'TheProviderKey'
+ );
+
+ $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
+ $method->setAccessible(true);
+
+ $result = $method->invokeArgs($listener, array($request));
+ }
+
+ public function testGetPreAuthenticatedDataWithDifferentKeys()
+ {
+ $userCredentials = array('TheUser', null);
+
+ $request = new Request(array(), array(), array(), array(), array(), array(
+ 'TheUserKey' => 'TheUser',
+ ));
+ $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
+
+ $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
+
+ $listener = new RemoteUserAuthenticationListener(
+ $context,
+ $authenticationManager,
+ 'TheProviderKey',
+ 'TheUserKey'
+ );
+
+ $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
+ $method->setAccessible(true);
+
+ $result = $method->invokeArgs($listener, array($request));
+ $this->assertSame($result, $userCredentials);
+ }
+}
diff --git a/Tests/Http/Firewall/SwitchUserListenerTest.php b/Http/Tests/Firewall/SwitchUserListenerTest.php
index e86ee83..9fb4e50 100644
--- a/Tests/Http/Firewall/SwitchUserListenerTest.php
+++ b/Http/Tests/Firewall/SwitchUserListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\Security\Http\Firewall\SwitchUserListener;
@@ -34,6 +34,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$this->userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$this->accessDecisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
$this->request = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $this->request->query = $this->getMock('Symfony\Component\HttpFoundation\ParameterBag');
$this->request->server = $this->getMock('Symfony\Component\HttpFoundation\ServerBag');
$this->event = $this->getEvent($this->request);
}
@@ -51,7 +52,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
{
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue(null));
- $this->event->expects($this->never())->method('setResopnse');
+ $this->event->expects($this->never())->method('setResponse');
$this->securityContext->expects($this->never())->method('setToken');
$listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
@@ -86,6 +87,8 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('_exit'));
$this->request->expects($this->any())->method('getUri')->will($this->returnValue('/'));
+ $this->request->query->expects($this->once())->method('remove', '_switch_user');
+ $this->request->query->expects($this->any())->method('all')->will($this->returnValue(array()));
$this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', '');
$this->securityContext->expects($this->once())
@@ -100,7 +103,7 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
*/
- public function testSwitchUserIsDissallowed()
+ public function testSwitchUserIsDisallowed()
{
$token = $this->getToken(array($this->getMock('Symfony\Component\Security\Core\Role\RoleInterface')));
@@ -123,6 +126,9 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
$this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
+ $this->request->query->expects($this->once())->method('remove', '_switch_user');
+ $this->request->query->expects($this->any())->method('all')->will($this->returnValue(array()));
+
$this->request->expects($this->any())->method('getUri')->will($this->returnValue('/'));
$this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', '');
@@ -142,6 +148,35 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($this->event);
}
+ public function testSwitchUserKeepsOtherQueryStringParameters()
+ {
+ $token = $this->getToken(array($this->getMock('Symfony\Component\Security\Core\Role\RoleInterface')));
+ $user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $user->expects($this->any())->method('getRoles')->will($this->returnValue(array()));
+
+ $this->securityContext->expects($this->any())->method('getToken')->will($this->returnValue($token));
+ $this->request->expects($this->any())->method('get')->with('_switch_user')->will($this->returnValue('kuba'));
+ $this->request->query->expects($this->once())->method('remove', '_switch_user');
+ $this->request->query->expects($this->any())->method('all')->will($this->returnValue(array('page' => 3, 'section' => 2)));
+ $this->request->expects($this->any())->method('getUri')->will($this->returnValue('/'));
+ $this->request->server->expects($this->once())->method('set')->with('QUERY_STRING', 'page=3&section=2');
+
+ $this->accessDecisionManager->expects($this->once())
+ ->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
+ ->will($this->returnValue(true));
+
+ $this->userProvider->expects($this->once())
+ ->method('loadUserByUsername')->with('kuba')
+ ->will($this->returnValue($user));
+ $this->userChecker->expects($this->once())
+ ->method('checkPostAuth')->with($user);
+ $this->securityContext->expects($this->once())
+ ->method('setToken')->with($this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken'));
+
+ $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
+ $listener->handle($this->event);
+ }
+
private function getEvent($request)
{
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
diff --git a/Tests/Http/Firewall/X509AuthenticationListenerTest.php b/Http/Tests/Firewall/X509AuthenticationListenerTest.php
index b28c0ac..7f2da3e 100644
--- a/Tests/Http/Firewall/X509AuthenticationListenerTest.php
+++ b/Http/Tests/Firewall/X509AuthenticationListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Firewall;
+namespace Symfony\Component\Security\Http\Tests\Firewall;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Firewall\X509AuthenticationListener;
diff --git a/Tests/Http/FirewallMapTest.php b/Http/Tests/FirewallMapTest.php
index 5d3a72a..85a57ab 100644
--- a/Tests/Http/FirewallMapTest.php
+++ b/Http/Tests/FirewallMapTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http;
+namespace Symfony\Component\Security\Http\Tests;
use Symfony\Component\Security\Http\FirewallMap;
use Symfony\Component\HttpFoundation\Request;
diff --git a/Tests/Http/FirewallTest.php b/Http/Tests/FirewallTest.php
index 7fd2cda..9994737 100644
--- a/Tests/Http/FirewallTest.php
+++ b/Http/Tests/FirewallTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http;
+namespace Symfony\Component\Security\Http\Tests;
use Symfony\Component\Security\Http\Firewall;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
diff --git a/Tests/Http/HttpUtilsTest.php b/Http/Tests/HttpUtilsTest.php
index 019af19..195fc48 100644
--- a/Tests/Http/HttpUtilsTest.php
+++ b/Http/Tests/HttpUtilsTest.php
@@ -9,12 +9,12 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http;
+namespace Symfony\Component\Security\Http\Tests;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
-use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\HttpUtils;
class HttpUtilsTest extends \PHPUnit_Framework_TestCase
@@ -126,9 +126,9 @@ class HttpUtilsTest extends \PHPUnit_Framework_TestCase
public function provideSecurityContextAttributes()
{
return array(
- array(SecurityContextInterface::AUTHENTICATION_ERROR),
- array(SecurityContextInterface::ACCESS_DENIED_ERROR),
- array(SecurityContextInterface::LAST_USERNAME),
+ array(Security::AUTHENTICATION_ERROR),
+ array(Security::ACCESS_DENIED_ERROR),
+ array(Security::LAST_USERNAME),
);
}
diff --git a/Tests/Http/Logout/CookieClearingLogoutHandlerTest.php b/Http/Tests/Logout/CookieClearingLogoutHandlerTest.php
index c443d8d..8474504 100644
--- a/Tests/Http/Logout/CookieClearingLogoutHandlerTest.php
+++ b/Http/Tests/Logout/CookieClearingLogoutHandlerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Logout;
+namespace Symfony\Component\Security\Http\Tests\Logout;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
diff --git a/Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php b/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php
index f18604d..381a48e 100644
--- a/Tests/Http/Logout/DefaultLogoutSuccessHandlerTest.php
+++ b/Http/Tests/Logout/DefaultLogoutSuccessHandlerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Logout;
+namespace Symfony\Component\Security\Http\Tests\Logout;
use Symfony\Component\Security\Http\Logout\DefaultLogoutSuccessHandler;
diff --git a/Tests/Http/Logout/SessionLogoutHandlerTest.php b/Http/Tests/Logout/SessionLogoutHandlerTest.php
index f89a423..c342995 100644
--- a/Tests/Http/Logout/SessionLogoutHandlerTest.php
+++ b/Http/Tests/Logout/SessionLogoutHandlerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Logout;
+namespace Symfony\Component\Security\Http\Tests\Logout;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Logout\SessionLogoutHandler;
diff --git a/Tests/Http/RememberMe/AbstractRememberMeServicesTest.php b/Http/Tests/RememberMe/AbstractRememberMeServicesTest.php
index 0f64730..c3d9260 100644
--- a/Tests/Http/RememberMe/AbstractRememberMeServicesTest.php
+++ b/Http/Tests/RememberMe/AbstractRememberMeServicesTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\RememberMe;
+namespace Symfony\Component\Security\Http\Tests\RememberMe;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
use Symfony\Component\HttpFoundation\Request;
diff --git a/Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php b/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php
index 19f6984..6aee1b1 100644
--- a/Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php
+++ b/Http/Tests/RememberMe/PersistentTokenBasedRememberMeServicesTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\RememberMe;
+namespace Symfony\Component\Security\Http\Tests\RememberMe;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
diff --git a/Tests/Http/RememberMe/ResponseListenerTest.php b/Http/Tests/RememberMe/ResponseListenerTest.php
index bca2c43..78de8e4 100644
--- a/Tests/Http/RememberMe/ResponseListenerTest.php
+++ b/Http/Tests/RememberMe/ResponseListenerTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\RememberMe;
+namespace Symfony\Component\Security\Http\Tests\RememberMe;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Http\RememberMe\ResponseListener;
@@ -94,7 +94,7 @@ class ResponseListenerTest extends \PHPUnit_Framework_TestCase
->getMock();
$event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
- $event->expects($this->any())->method('getRequestType')->will($this->returnValue($type));
+ $event->expects($this->any())->method('isMasterRequest')->will($this->returnValue($type === HttpKernelInterface::MASTER_REQUEST));
$event->expects($this->any())->method('getResponse')->will($this->returnValue($response));
return $event;
diff --git a/Tests/Http/RememberMe/TokenBasedRememberMeServicesTest.php b/Http/Tests/RememberMe/TokenBasedRememberMeServicesTest.php
index 7947753..8c215e2 100644
--- a/Tests/Http/RememberMe/TokenBasedRememberMeServicesTest.php
+++ b/Http/Tests/RememberMe/TokenBasedRememberMeServicesTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\RememberMe;
+namespace Symfony\Component\Security\Http\Tests\RememberMe;
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
diff --git a/Tests/Http/Session/SessionAuthenticationStrategyTest.php b/Http/Tests/Session/SessionAuthenticationStrategyTest.php
index 7296afd..4aef4b2 100644
--- a/Tests/Http/Session/SessionAuthenticationStrategyTest.php
+++ b/Http/Tests/Session/SessionAuthenticationStrategyTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\Security\Tests\Http\Session;
+namespace Symfony\Component\Security\Http\Tests\Session;
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
diff --git a/Http/composer.json b/Http/composer.json
new file mode 100644
index 0000000..6c6dfe3
--- /dev/null
+++ b/Http/composer.json
@@ -0,0 +1,45 @@
+{
+ "name": "symfony/security-http",
+ "type": "library",
+ "description": "Symfony Security Component - HTTP Integration",
+ "keywords": [],
+ "homepage": "http://symfony.com",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.3",
+ "symfony/security-core": "~2.6",
+ "symfony/event-dispatcher": "~2.1",
+ "symfony/http-foundation": "~2.4",
+ "symfony/http-kernel": "~2.4"
+ },
+ "require-dev": {
+ "symfony/phpunit-bridge": "~2.7",
+ "symfony/routing": "~2.2",
+ "symfony/security-csrf": "~2.4",
+ "psr/log": "~1.0"
+ },
+ "suggest": {
+ "symfony/security-csrf": "For using tokens to protect authentication/logout attempts",
+ "symfony/routing": "For using the HttpUtils class to create sub-requests, redirect the user, and match URLs"
+ },
+ "autoload": {
+ "psr-0": { "Symfony\\Component\\Security\\Http\\": "" }
+ },
+ "target-dir": "Symfony/Component/Security/Http",
+ "minimum-stability": "dev",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.6-dev"
+ }
+ }
+}
diff --git a/Http/phpunit.xml.dist b/Http/phpunit.xml.dist
new file mode 100644
index 0000000..7393814
--- /dev/null
+++ b/Http/phpunit.xml.dist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+ bootstrap="vendor/autoload.php"
+>
+ <php>
+ <ini name="error_reporting" value="-1" />
+ </php>
+ <testsuites>
+ <testsuite name="Symfony Security Component HTTP Test Suite">
+ <directory>./Tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./vendor</directory>
+ <directory>./Tests</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/README.md b/README.md
index 21f8a24..713d55c 100644
--- a/README.md
+++ b/README.md
@@ -11,10 +11,10 @@ Resources
Documentation:
-http://symfony.com/doc/2.3/book/security.html
+http://symfony.com/doc/2.6/book/security.html
-Resources
----------
+Tests
+-----
You can run the unit tests with the following command:
diff --git a/Tests/Core/Authentication/Voter/AbstractVoterTest.php b/Tests/Core/Authentication/Voter/AbstractVoterTest.php
new file mode 100644
index 0000000..955b610
--- /dev/null
+++ b/Tests/Core/Authentication/Voter/AbstractVoterTest.php
@@ -0,0 +1,90 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Tests\Core\Authentication\Voter;
+
+use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
+
+/**
+ * @author Roman Marintšenko <inoryy@gmail.com>
+ */
+class AbstractVoterTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var AbstractVoter
+ */
+ private $voter;
+
+ private $token;
+
+ public function setUp()
+ {
+ $this->voter = new VoterFixture();
+
+ $tokenMock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
+ $tokenMock
+ ->expects($this->any())
+ ->method('getUser')
+ ->will($this->returnValue('user'));
+
+ $this->token = $tokenMock;
+ }
+
+ /**
+ * @dataProvider getData
+ */
+ public function testVote($expectedVote, $object, $attributes, $message)
+ {
+ $this->assertEquals($expectedVote, $this->voter->vote($this->token, $object, $attributes), $message);
+ }
+
+ public function getData()
+ {
+ return array(
+ array(AbstractVoter::ACCESS_ABSTAIN, null, array(), 'ACCESS_ABSTAIN for null objects'),
+ array(AbstractVoter::ACCESS_ABSTAIN, new UnsupportedObjectFixture(), array(), 'ACCESS_ABSTAIN for objects with unsupported class'),
+ array(AbstractVoter::ACCESS_ABSTAIN, new ObjectFixture(), array(), 'ACCESS_ABSTAIN for no attributes'),
+ array(AbstractVoter::ACCESS_ABSTAIN, new ObjectFixture(), array('foobar'), 'ACCESS_ABSTAIN for unsupported attributes'),
+ array(AbstractVoter::ACCESS_GRANTED, new ObjectFixture(), array('foo'), 'ACCESS_GRANTED if attribute grants access'),
+ array(AbstractVoter::ACCESS_GRANTED, new ObjectFixture(), array('bar', 'foo'), 'ACCESS_GRANTED if *at least one* attribute grants access'),
+ array(AbstractVoter::ACCESS_GRANTED, new ObjectFixture(), array('foobar', 'foo'), 'ACCESS_GRANTED if *at least one* attribute grants access'),
+ array(AbstractVoter::ACCESS_DENIED, new ObjectFixture(), array('bar', 'baz'), 'ACCESS_DENIED for if no attribute grants access'),
+ );
+ }
+}
+
+class VoterFixture extends AbstractVoter
+{
+ protected function getSupportedClasses()
+ {
+ return array(
+ 'Symfony\Component\Security\Tests\Core\Authentication\Voter\ObjectFixture',
+ );
+ }
+
+ protected function getSupportedAttributes()
+ {
+ return array( 'foo', 'bar', 'baz');
+ }
+
+ protected function isGranted($attribute, $object, $user = null)
+ {
+ return $attribute === 'foo';
+ }
+}
+
+class ObjectFixture
+{
+}
+
+class UnsupportedObjectFixture
+{
+}
diff --git a/Tests/Core/LegacySecurityContextInterfaceTest.php b/Tests/Core/LegacySecurityContextInterfaceTest.php
new file mode 100644
index 0000000..8f68475
--- /dev/null
+++ b/Tests/Core/LegacySecurityContextInterfaceTest.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Tests\Core;
+
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use Symfony\Component\Security\Core\Security;
+
+class LegacySecurityContextInterfaceTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * Test if the BC Layer is working as intended
+ */
+ public function testConstantSync()
+ {
+ $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
+
+ $this->assertSame(Security::ACCESS_DENIED_ERROR, SecurityContextInterface::ACCESS_DENIED_ERROR);
+ $this->assertSame(Security::AUTHENTICATION_ERROR, SecurityContextInterface::AUTHENTICATION_ERROR);
+ $this->assertSame(Security::LAST_USERNAME, SecurityContextInterface::LAST_USERNAME);
+ }
+}
diff --git a/Tests/Core/SecurityContextTest.php b/Tests/Core/SecurityContextTest.php
deleted file mode 100644
index 124ebf9..0000000
--- a/Tests/Core/SecurityContextTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Tests\Core;
-
-use Symfony\Component\Security\Core\SecurityContext;
-
-class SecurityContextTest extends \PHPUnit_Framework_TestCase
-{
- public function testVoteAuthenticatesTokenIfNecessary()
- {
- $authManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
- $decisionManager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
-
- $context = new SecurityContext($authManager, $decisionManager);
- $context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
-
- $authManager
- ->expects($this->once())
- ->method('authenticate')
- ->with($this->equalTo($token))
- ->will($this->returnValue($newToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')))
- ;
-
- $decisionManager
- ->expects($this->once())
- ->method('decide')
- ->will($this->returnValue(true))
- ;
-
- $this->assertTrue($context->isGranted('foo'));
- $this->assertSame($newToken, $context->getToken());
- }
-
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
- */
- public function testVoteWithoutAuthenticationToken()
- {
- $context = new SecurityContext(
- $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'),
- $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')
- );
-
- $context->isGranted('ROLE_FOO');
- }
-
- public function testIsGranted()
- {
- $manager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
- $manager->expects($this->once())->method('decide')->will($this->returnValue(false));
- $context = new SecurityContext($this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'), $manager);
- $context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
- $token
- ->expects($this->once())
- ->method('isAuthenticated')
- ->will($this->returnValue(true))
- ;
- $this->assertFalse($context->isGranted('ROLE_FOO'));
-
- $manager = $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface');
- $manager->expects($this->once())->method('decide')->will($this->returnValue(true));
- $context = new SecurityContext($this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'), $manager);
- $context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
- $token
- ->expects($this->once())
- ->method('isAuthenticated')
- ->will($this->returnValue(true))
- ;
- $this->assertTrue($context->isGranted('ROLE_FOO'));
- }
-
- public function testGetSetToken()
- {
- $context = new SecurityContext(
- $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'),
- $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')
- );
- $this->assertNull($context->getToken());
-
- $context->setToken($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
- $this->assertSame($token, $context->getToken());
- }
-}
diff --git a/Tests/Core/Validator/Constraints/UserPasswordValidatorTest.php b/Tests/Core/Validator/Constraints/UserPasswordValidatorTest.php
deleted file mode 100644
index 4c420c7..0000000
--- a/Tests/Core/Validator/Constraints/UserPasswordValidatorTest.php
+++ /dev/null
@@ -1,157 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Security\Tests\Core\Validator\Constraints;
-
-use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
-use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
-
-class UserPasswordValidatorTest extends \PHPUnit_Framework_TestCase
-{
- const PASSWORD_VALID = true;
- const PASSWORD_INVALID = false;
-
- protected $context;
-
- protected function setUp()
- {
- $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
- }
-
- protected function tearDown()
- {
- $this->context = null;
- }
-
- public function testPasswordIsValid()
- {
- $user = $this->createUser();
- $securityContext = $this->createSecurityContext($user);
-
- $encoder = $this->createPasswordEncoder(static::PASSWORD_VALID);
- $encoderFactory = $this->createEncoderFactory($encoder);
-
- $validator = new UserPasswordValidator($securityContext, $encoderFactory);
- $validator->initialize($this->context);
-
- $this
- ->context
- ->expects($this->never())
- ->method('addViolation')
- ;
-
- $validator->validate('secret', new UserPassword());
- }
-
- public function testPasswordIsNotValid()
- {
- $user = $this->createUser();
- $securityContext = $this->createSecurityContext($user);
-
- $encoder = $this->createPasswordEncoder(static::PASSWORD_INVALID);
- $encoderFactory = $this->createEncoderFactory($encoder);
-
- $validator = new UserPasswordValidator($securityContext, $encoderFactory);
- $validator->initialize($this->context);
-
- $this
- ->context
- ->expects($this->once())
- ->method('addViolation')
- ;
-
- $validator->validate('secret', new UserPassword());
- }
-
- public function testUserIsNotValid()
- {
- $this->setExpectedException('Symfony\Component\Validator\Exception\ConstraintDefinitionException');
-
- $user = $this->getMock('Foo\Bar\User');
- $encoderFactory = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
- $securityContext = $this->createSecurityContext($user);
-
- $validator = new UserPasswordValidator($securityContext, $encoderFactory);
- $validator->initialize($this->context);
- $validator->validate('secret', new UserPassword());
- }
-
- protected function createUser()
- {
- $mock = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
-
- $mock
- ->expects($this->once())
- ->method('getPassword')
- ->will($this->returnValue('s3Cr3t'))
- ;
-
- $mock
- ->expects($this->once())
- ->method('getSalt')
- ->will($this->returnValue('^S4lt$'))
- ;
-
- return $mock;
- }
-
- protected function createPasswordEncoder($isPasswordValid = true)
- {
- $mock = $this->getMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
-
- $mock
- ->expects($this->once())
- ->method('isPasswordValid')
- ->will($this->returnValue($isPasswordValid))
- ;
-
- return $mock;
- }
-
- protected function createEncoderFactory($encoder = null)
- {
- $mock = $this->getMock('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface');
-
- $mock
- ->expects($this->once())
- ->method('getEncoder')
- ->will($this->returnValue($encoder))
- ;
-
- return $mock;
- }
-
- protected function createSecurityContext($user = null)
- {
- $token = $this->createAuthenticationToken($user);
-
- $mock = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
- $mock
- ->expects($this->once())
- ->method('getToken')
- ->will($this->returnValue($token))
- ;
-
- return $mock;
- }
-
- protected function createAuthenticationToken($user = null)
- {
- $mock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- $mock
- ->expects($this->once())
- ->method('getUser')
- ->will($this->returnValue($user))
- ;
-
- return $mock;
- }
-}
diff --git a/composer.json b/composer.json
index 2e85c41..81e8582 100644
--- a/composer.json
+++ b/composer.json
@@ -19,27 +19,34 @@
"php": ">=5.3.3",
"symfony/event-dispatcher": "~2.2",
"symfony/http-foundation": "~2.1",
- "symfony/http-kernel": "~2.1"
+ "symfony/http-kernel": "~2.4"
+ },
+ "replace": {
+ "symfony/security-acl": "self.version",
+ "symfony/security-core": "self.version",
+ "symfony/security-csrf": "self.version",
+ "symfony/security-http": "self.version"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7",
- "symfony/form": "~2.0,>=2.0.5",
"symfony/intl": "~2.3",
"symfony/routing": "~2.2",
- "symfony/validator": "~2.2",
+ "symfony/translation": "~2.0,>=2.0.5",
+ "symfony/validator": "~2.5,>=2.5.5",
"doctrine/common": "~2.2",
"doctrine/dbal": "~2.2",
"psr/log": "~1.0",
- "ircmaxell/password-compat": "~1.0"
+ "ircmaxell/password-compat": "~1.0",
+ "symfony/expression-language": "~2.6"
},
"suggest": {
- "symfony/class-loader": "",
- "symfony/finder": "",
- "symfony/form": "",
- "symfony/validator": "",
- "symfony/routing": "",
- "doctrine/dbal": "to use the built-in ACL implementation",
- "ircmaxell/password-compat": ""
+ "symfony/class-loader": "For using the ACL generateSql script",
+ "symfony/finder": "For using the ACL generateSql script",
+ "symfony/validator": "For using the user password constraint",
+ "symfony/routing": "For using the HttpUtils class to create sub-requests, redirect the user, and match URLs",
+ "doctrine/dbal": "For using the built-in ACL implementation",
+ "symfony/expression-language": "For using the expression voter",
+ "ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5"
},
"autoload": {
"psr-0": { "Symfony\\Component\\Security\\": "" }
@@ -48,7 +55,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
- "dev-master": "2.3-dev"
+ "dev-master": "2.6-dev"
}
}
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 9a20f91..e80320d 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -11,7 +11,9 @@
</php>
<testsuites>
<testsuite name="Symfony Security Component Test Suite">
- <directory>./Tests/</directory>
+ <directory>./Acl/Tests/</directory>
+ <directory>./Core/Tests/</directory>
+ <directory>./Http/Tests/</directory>
</testsuite>
</testsuites>
@@ -20,7 +22,9 @@
<directory>./</directory>
<exclude>
<directory>./vendor</directory>
- <directory>./Tests</directory>
+ <directory>./Acl/Tests</directory>
+ <directory>./Core/Tests</directory>
+ <directory>./Http/Tests</directory>
</exclude>
</whitelist>
</filter>