Skip to content

AUTH option form config #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"wiki": "https://github.com/ColourboxDevelopment/simplesamlphp-module-redis/wiki"
},
"require": {
"php": "^5.4",
"php": ">=5.4",
"predis/predis": "~1.0",
"simplesamlphp/composer-module-installer": "^1.1"
},
Expand Down
14 changes: 14 additions & 0 deletions lib/Redis/DualRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ public function set($key, $value)
$this->newHost->set($key, $value);
}

public function auth($key)
{
$this->newHost->auth($key);
$this->oldHost->auth($key);
}

public function keys($pattern)
{
return array_unique(array_merge(
$this->newHost->keys($pattern),
$this->oldHost->keys($pattern)
));
}

public function del($key)
{
$this->newHost->del($key);
Expand Down
56 changes: 44 additions & 12 deletions lib/Store/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,31 @@ class sspmod_redis_Store_Redis extends SimpleSAML_Store

public function __construct()
{
$config = SimpleSAML_Configuration::getConfig('module_redis.php');
$redisConfig = SimpleSAML_Configuration::getConfig('module_redis.php');

if ($config->hasValue('oldHost')) {
$oldHost = $config->getValue('oldHost');
if ($redisConfig->hasValue('oldHost')) {
$oldHost = $redisConfig->getValue('oldHost');
$this->redis = new sspmod_redis_Redis_DualRedis(
new Predis\Client($oldHost['parameters'], $oldHost['options']),
new Predis\Client($config->getValue('parameters'), $config->getValue('options'))
new Predis\Client($redisConfig->getValue('parameters'), $redisConfig->getValue('options'))
);
} else {
$this->redis = new Predis\Client($config->getValue('parameters'), $config->getValue('options'));
$this->redis = new Predis\Client($redisConfig->getValue('parameters'), $redisConfig->getValue('options'));
}

$this->auth();

$this->prefix = $redisConfig->getString('prefix', 'simpleSAMLphp');
$this->lifeTime = $redisConfig->getInteger('lifetime', 28800); // 8 hours
}

protected function auth()
{
$redisConfig = SimpleSAML_Configuration::getConfig('module_redis.php');
if($auth = $redisConfig->getString('auth', ''))
{
$this->redis->auth($auth);
}
$this->prefix = $config->getString('prefix', 'simpleSAMLphp');
$this->lifeTime = $config->getInteger('lifetime', 28800); // 8 hours
}

/**
Expand Down Expand Up @@ -66,12 +78,23 @@ public function get($type, $key)
public function set($type, $key, $value, $expire = null)
{
$redisKey = "{$this->prefix}.$type.$key";
$this->redis->set($redisKey, serialize($value));

if (is_null($expire)) {
if (is_null($expire))
{
$expire = time() + $this->lifeTime;
}
$this->redis->expireat($redisKey, $expire);

try
{
$this->redis->set($redisKey, serialize($value));
$this->redis->expireat($redisKey, $expire);
}
catch(\ Exception $e)
{
//on shutdown sometime the auth is not set !
$this->auth();
$this->redis->set($redisKey, serialize($value));
$this->redis->expireat($redisKey, $expire);
}
}

/**
Expand All @@ -83,6 +106,15 @@ public function set($type, $key, $value, $expire = null)
public function delete($type, $key)
{
$redisKey = "{$this->prefix}.$type.$key";
$this->redis->del($redisKey);
try
{
$this->redis->del($redisKey);
}
catch(\ Exception $e)
{
//on shutdown sometime the auth is not set !
$this->auth();
$this->redis->del($redisKey);
}
}
}