diff --git a/docs/simplesamlphp-maintenance.md b/docs/simplesamlphp-maintenance.md index ff4581b034555c381e814763afddcb3d0383f299..1d99f19f777552072fc47df262afce1324f84150 100644 --- a/docs/simplesamlphp-maintenance.md +++ b/docs/simplesamlphp-maintenance.md @@ -161,7 +161,7 @@ The required tables are created automatically. If you are storing data from mult To store sessions in Redis, set the `store.type` option to `redis`. -By default SimpleSAMLphp will attempt to connect to Redis on the `localhost` at port `6379`. These can be configured via the `store.redis.host` and `store.redis.port` options, respectively. You may also set a key prefix with the `store.redis.prefix` option. +By default SimpleSAMLphp will attempt to connect to Redis on the `localhost` at port `6379`. These can be configured via the `store.redis.host` and `store.redis.port` options, respectively. You may also set a key prefix with the `store.redis.prefix` option. For Redis instances that [require authentication](https://redis.io/commands/auth), use the `store.redis.password` option. ## Metadata storage diff --git a/lib/SimpleSAML/Store/Redis.php b/lib/SimpleSAML/Store/Redis.php index 9091ddd631ebb9fffa80c48706fa73919f2d9af8..310caa98f42cb480cc1e8d17102a20d7f7c0cc82 100644 --- a/lib/SimpleSAML/Store/Redis.php +++ b/lib/SimpleSAML/Store/Redis.php @@ -31,13 +31,14 @@ class Redis extends Store $host = $config->getString('store.redis.host', 'localhost'); $port = $config->getInteger('store.redis.port', 6379); $prefix = $config->getString('store.redis.prefix', 'SimpleSAMLphp'); + $password = $config->getString('store.redis.password', ''); $redis = new \Predis\Client( [ 'scheme' => 'tcp', 'host' => $host, 'port' => $port, - ], + ] + (!empty($password) ? ['password' => $password] : []), [ 'prefix' => $prefix, ] diff --git a/tests/lib/SimpleSAML/Store/RedisTest.php b/tests/lib/SimpleSAML/Store/RedisTest.php index 7774a5dd211cf72b069bd9535bdbb592a3110890..b1e8cc0e0b4d6564b812a7c5aea57bbc5058463c 100644 --- a/tests/lib/SimpleSAML/Store/RedisTest.php +++ b/tests/lib/SimpleSAML/Store/RedisTest.php @@ -88,6 +88,27 @@ class RedisTest extends TestCase $this->clearInstance($store, '\SimpleSAML\Store'); } + /** + * @covers \SimpleSAML\Store::getInstance + * @covers \SimpleSAML\Store\Redis::__construct + * @test + */ + public function testRedisInstanceWithPassword() + { + $config = Configuration::loadFromArray([ + 'store.type' => 'redis', + 'store.redis.prefix' => 'phpunit_', + 'store.redis.password' => 'password', + ], '[ARRAY]', 'simplesaml'); + + $store = Store::getInstance(); + + $this->assertInstanceOf('SimpleSAML\Store\Redis', $store); + + $this->clearInstance($config, '\SimpleSAML\Configuration'); + $this->clearInstance($store, '\SimpleSAML\Store'); + } + /** * @covers \SimpleSAML\Store\Redis::get * @covers \SimpleSAML\Store\Redis::set