Skip to content

Commit 70022b6

Browse files
committed
Only provide the in-memory storage driver
1 parent b17a66e commit 70022b6

File tree

9 files changed

+5
-298
lines changed

9 files changed

+5
-298
lines changed

config/services.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use BabDev\WebSocketBundle\Authentication\DefaultAuthenticator;
2727
use BabDev\WebSocketBundle\Authentication\Provider\SessionAuthenticationProvider;
2828
use BabDev\WebSocketBundle\Authentication\Storage\Driver\InMemoryStorageDriver;
29-
use BabDev\WebSocketBundle\Authentication\Storage\Driver\PsrCacheStorageDriver;
29+
use BabDev\WebSocketBundle\Authentication\Storage\Driver\StorageDriver;
3030
use BabDev\WebSocketBundle\Authentication\Storage\DriverBackedTokenStorage;
3131
use BabDev\WebSocketBundle\Authentication\Storage\TokenStorage;
3232
use BabDev\WebSocketBundle\Authentication\StorageBackedConnectionRepository;
@@ -105,16 +105,11 @@
105105
;
106106

107107
$services->set('babdev_websocket_server.authentication.storage.driver.in_memory', InMemoryStorageDriver::class);
108-
109-
$services->set('babdev_websocket_server.authentication.storage.driver.psr_cache', PsrCacheStorageDriver::class)
110-
->args([
111-
abstract_arg('cache pool'),
112-
])
113-
;
108+
$services->alias(StorageDriver::class, 'babdev_websocket_server.authentication.storage.driver.in_memory');
114109

115110
$services->set('babdev_websocket_server.authentication.token_storage.driver', DriverBackedTokenStorage::class)
116111
->args([
117-
service('babdev_websocket_server.authentication.storage.driver'),
112+
service(StorageDriver::class),
118113
])
119114
->call('setLogger', [
120115
service('logger'),

docs/authentication.md

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,7 @@ class Kernel extends BaseKernel
102102

103103
After authentication is complete, the token is stored in a `BabDev\WebSocketBundle\Authentication\Storage\TokenStorage` instance. The default implementation uses a `BabDev\WebSocketBundle\Authentication\Storage\Driver\StorageDriver` as an abstraction layer for where authentication tokens are stored.
104104

105-
By default, the bundle uses an in-memory storage driver. The storage driver can be configured with the `storage` section of the authentication configuration.
106-
107-
### In-Memory Storage
108-
109-
The below example represents the default configuration for the in-memory storage driver.
110-
111-
```yaml
112-
babdev_websocket:
113-
authentication:
114-
storage:
115-
type: in_memory
116-
```
117-
118-
### Cache Storage
119-
120-
A cache pool can be used as a storage driver by setting the storage type to `psr_cache` and specifying the cache pool that should be used.
121-
122-
```yaml
123-
babdev_websocket:
124-
authentication:
125-
storage:
126-
type: psr_cache
127-
pool: 'cache.websocket'
128-
```
129-
130-
### Service Storage
131-
132-
You can create your own implementation of the storage driver interface and use that service by setting the storage type to `service` and specifying the container service ID to use.
133-
134-
```yaml
135-
babdev_websocket:
136-
authentication:
137-
storage:
138-
type: storage
139-
id: 'app.websocket.storage.driver'
140-
```
105+
By default, the bundle provides and uses an in-memory storage driver. You can provide your own driver implementation by creating a class implementing the driver interface and updating the service container to point the '`BabDev\WebSocketBundle\Authentication\Storage\Driver\StorageDriver`' alias to your implementation.
141106

142107
## Fetching Tokens
143108

docs/default-configuration.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ babdev_websocket:
88

99
# The firewalls from which the session token can be used; can be an array, a string, or null to allow all firewalls.
1010
firewalls: null
11-
storage:
12-
13-
# The type of storage for the websocket server authentication tokens.
14-
type: in_memory # One of "in_memory"; "psr_cache"; "service", Required
15-
16-
# The cache pool to use when using the PSR cache storage.
17-
pool: null
18-
19-
# The service ID to use when using the service storage.
20-
id: null
2111
server:
2212

2313
# An identifier for the websocket server, disclosed in the response to the WELCOME message from a WAMP client.

src/Authentication/Storage/Driver/PsrCacheStorageDriver.php

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/DependencyInjection/BabDevWebSocketExtension.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace BabDev\WebSocketBundle\DependencyInjection;
44

55
use BabDev\WebSocketBundle\Attribute\AsMessageHandler;
6-
use BabDev\WebSocketBundle\Authentication\Storage\Driver\StorageDriver;
76
use BabDev\WebSocketBundle\DependencyInjection\Factory\Authentication\AuthenticationProviderFactory;
87
use BabDev\WebSocketBundle\PeriodicManager\PeriodicManager;
98
use Doctrine\DBAL\Connection;
@@ -77,31 +76,6 @@ private function registerAuthenticationConfiguration(array $mergedConfig, Contai
7776

7877
$container->getDefinition('babdev_websocket_server.authentication.authenticator')
7978
->replaceArgument(0, new IteratorArgument($authenticators));
80-
81-
$storageId = null;
82-
83-
switch ($mergedConfig['authentication']['storage']['type']) {
84-
case Configuration::AUTHENTICATION_STORAGE_TYPE_IN_MEMORY:
85-
$storageId = 'babdev_websocket_server.authentication.storage.driver.in_memory';
86-
87-
break;
88-
89-
case Configuration::AUTHENTICATION_STORAGE_TYPE_PSR_CACHE:
90-
$storageId = 'babdev_websocket_server.authentication.storage.driver.psr_cache';
91-
92-
$container->getDefinition($storageId)
93-
->replaceArgument(0, new Reference($mergedConfig['authentication']['storage']['pool']));
94-
95-
break;
96-
97-
case Configuration::AUTHENTICATION_STORAGE_TYPE_SERVICE:
98-
$storageId = $mergedConfig['authentication']['storage']['id'];
99-
100-
break;
101-
}
102-
103-
$container->setAlias('babdev_websocket_server.authentication.storage.driver', $storageId);
104-
$container->setAlias(StorageDriver::class, $storageId);
10579
}
10680

10781
private function registerServerConfiguration(array $mergedConfig, ContainerBuilder $container): void

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
final class Configuration implements ConfigurationInterface
1616
{
17-
public const AUTHENTICATION_STORAGE_TYPE_IN_MEMORY = 'in_memory';
18-
public const AUTHENTICATION_STORAGE_TYPE_PSR_CACHE = 'psr_cache';
19-
public const AUTHENTICATION_STORAGE_TYPE_SERVICE = 'service';
20-
2117
/**
2218
* @param list<AuthenticationProviderFactory> $authenticationProviderFactories
2319
*/
@@ -42,37 +38,6 @@ private function addAuthenticationSection(ArrayNodeDefinition $rootNode): void
4238
->addDefaultsIfNotSet();
4339

4440
$this->addAuthenticationProvidersSection($authenticationNode);
45-
46-
$authenticationNode->children()
47-
->arrayNode('storage')
48-
->addDefaultsIfNotSet()
49-
->children()
50-
->enumNode('type')
51-
->isRequired()
52-
->defaultValue(self::AUTHENTICATION_STORAGE_TYPE_IN_MEMORY)
53-
->info('The type of storage for the websocket server authentication tokens.')
54-
->values([self::AUTHENTICATION_STORAGE_TYPE_IN_MEMORY, self::AUTHENTICATION_STORAGE_TYPE_PSR_CACHE, self::AUTHENTICATION_STORAGE_TYPE_SERVICE])
55-
->end()
56-
->scalarNode('pool')
57-
->defaultNull()
58-
->info('The cache pool to use when using the PSR cache storage.')
59-
->end()
60-
->scalarNode('id')
61-
->defaultNull()
62-
->info('The service ID to use when using the service storage.')
63-
->end()
64-
->end()
65-
->validate()
66-
->ifTrue(static fn (array $config): bool => ('' === $config['pool'] || null === $config['pool']) && self::AUTHENTICATION_STORAGE_TYPE_PSR_CACHE === $config['type'])
67-
->thenInvalid('A cache pool must be set when using the PSR cache storage')
68-
->end()
69-
->validate()
70-
->ifTrue(static fn (array $config): bool => ('' === $config['id'] || null === $config['id']) && self::AUTHENTICATION_STORAGE_TYPE_SERVICE === $config['type'])
71-
->thenInvalid('A service ID must be set when using the service storage')
72-
->end()
73-
->end()
74-
->end()
75-
->end();
7641
}
7742

7843
private function addAuthenticationProvidersSection(ArrayNodeDefinition $authenticationNode): void

tests/Authentication/Storage/Driver/PsrCacheStorageDriverTest.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

tests/DependencyInjection/BabDevWebSocketExtensionTest.php

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use BabDev\WebSocketBundle\Authentication\Storage\Driver\StorageDriver;
66
use BabDev\WebSocketBundle\DependencyInjection\BabDevWebSocketExtension;
7-
use BabDev\WebSocketBundle\DependencyInjection\Configuration;
87
use BabDev\WebSocketBundle\DependencyInjection\Factory\Authentication\SessionAuthenticationProviderFactory;
98
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
109
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\ContainerHasParameterConstraint;
@@ -80,7 +79,6 @@ public function testContainerIsLoadedWithValidConfiguration(): void
8079
}
8180

8281
self::assertThat($this->container->findDefinition('babdev_websocket_server.server.server_middleware.establish_websocket_connection'), new LogicalNot(new DefinitionHasMethodCallConstraint('enableKeepAlive')));
83-
$this->assertContainerBuilderHasAlias('babdev_websocket_server.authentication.storage.driver', 'babdev_websocket_server.authentication.storage.driver.in_memory');
8482
$this->assertContainerBuilderHasAlias(StorageDriver::class, 'babdev_websocket_server.authentication.storage.driver.in_memory');
8583
$this->assertContainerBuilderNotHasService('babdev_websocket_server.periodic_manager.ping_doctrine_dbal_connections');
8684
$this->assertContainerBuilderNotHasService('babdev_websocket_server.server.server_middleware.initialize_session');
@@ -164,54 +162,6 @@ public function testContainerIsLoadedWithSessionAuthenticationProviderConfigured
164162
);
165163
}
166164

167-
public function testContainerIsLoadedWithPsrCacheAuthenticationStorageConfigured(): void
168-
{
169-
$this->load([
170-
'authentication' => [
171-
'storage' => [
172-
'type' => Configuration::AUTHENTICATION_STORAGE_TYPE_PSR_CACHE,
173-
'pool' => 'cache.websocket',
174-
],
175-
],
176-
'server' => [
177-
'uri' => 'tcp://127.0.0.1:8080',
178-
'router' => [
179-
'resource' => '%kernel.project_dir%/config/websocket_router.php',
180-
],
181-
],
182-
]);
183-
184-
$this->assertContainerBuilderHasAlias('babdev_websocket_server.authentication.storage.driver', 'babdev_websocket_server.authentication.storage.driver.psr_cache');
185-
$this->assertContainerBuilderHasAlias(StorageDriver::class, 'babdev_websocket_server.authentication.storage.driver.psr_cache');
186-
187-
$this->assertContainerBuilderHasServiceDefinitionWithArgument(
188-
'babdev_websocket_server.authentication.storage.driver.psr_cache',
189-
0,
190-
new Reference('cache.websocket')
191-
);
192-
}
193-
194-
public function testContainerIsLoadedWithServiceAuthenticationStorageConfigured(): void
195-
{
196-
$this->load([
197-
'authentication' => [
198-
'storage' => [
199-
'type' => Configuration::AUTHENTICATION_STORAGE_TYPE_SERVICE,
200-
'id' => 'app.authentication.storage.driver.custom',
201-
],
202-
],
203-
'server' => [
204-
'uri' => 'tcp://127.0.0.1:8080',
205-
'router' => [
206-
'resource' => '%kernel.project_dir%/config/websocket_router.php',
207-
],
208-
],
209-
]);
210-
211-
$this->assertContainerBuilderHasAlias('babdev_websocket_server.authentication.storage.driver', 'app.authentication.storage.driver.custom');
212-
$this->assertContainerBuilderHasAlias(StorageDriver::class, 'app.authentication.storage.driver.custom');
213-
}
214-
215165
public function testContainerIsLoadedWithConfiguredSessionFactory(): void
216166
{
217167
$this->load([

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testConfigurationIsValidWithServerConfiguration(): void
3333
],
3434
[
3535
'server' => ['identity' => Server::VERSION, 'uri' => 'tcp://127.0.0.1:8080', 'context' => ['tls' => ['verify_peer' => false]], 'allowed_origins' => ['example.com'], 'blocked_ip_addresses' => ['192.168.1.1'], 'keepalive' => ['enabled' => true, 'interval' => 60], 'periodic' => ['dbal' => ['connections' => ['database_connection'], 'interval' => 60]], 'router' => ['resource' => '%kernel.project_dir%/config/websocket_router.php'], 'session' => ['handler_service_id' => 'session.handler.test']],
36-
'authentication' => ['storage' => ['type' => Configuration::AUTHENTICATION_STORAGE_TYPE_IN_MEMORY, 'pool' => null, 'id' => null]],
36+
'authentication' => [],
3737
],
3838
);
3939
}

0 commit comments

Comments
 (0)