Commit 58ffd387 authored by David Maus's avatar David Maus
Browse files

Factor out auth module factory creation

* lib/Auth/Source/Pica.php (__construct): Factor out auth module factory
  creation.
  (createAuthenticationModuleFactory): New function. Return auth module
  factory.
parent 72c34890
...@@ -50,25 +50,7 @@ class sspmod_pica_Auth_Source_Pica extends sspmod_core_Auth_UserPassBase ...@@ -50,25 +50,7 @@ class sspmod_pica_Auth_Source_Pica extends sspmod_core_Auth_UserPassBase
} }
$configuration = SimpleSAML_Configuration::loadFromArray($config['pica']); $configuration = SimpleSAML_Configuration::loadFromArray($config['pica']);
$module = $configuration->getString('module'); $this->factory = $this->createAuthenticationModuleFactory($configuration);
switch ($module) {
case 'lbs4-webservice':
$serviceUrl = $configuration->getString('serviceUrl');
$catalogNumber = $configuration->getInteger('catalogNumber');
$lbsUserNumber = $configuration->getInteger('lbsUserNumber');
$this->factory = function () use ($serviceUrl, $catalogNumber, $lbsUserNumber) {
return new Auth\LBSAuthentication($serviceUrl, $catalogNumber, $lbsUserNumber);
};
break;
case 'loan3-web':
$serviceUrl = $configuration->getString('serviceUrl');
$this->factory = function () use ($serviceUrl) {
return new Auth\LOAN3WebAuthentication($serviceUrl);
};
break;
default:
throw new Exception("Unknown pica authentication module: '{$module}'");
}
$this->attrmap = $configuration->getArray('attrmap', array()); $this->attrmap = $configuration->getArray('attrmap', array());
} }
...@@ -85,6 +67,35 @@ class sspmod_pica_Auth_Source_Pica extends sspmod_core_Auth_UserPassBase ...@@ -85,6 +67,35 @@ class sspmod_pica_Auth_Source_Pica extends sspmod_core_Auth_UserPassBase
return $this->normalize($attributes); return $this->normalize($attributes);
} }
/**
* Return authentication module factory function.
*
* @param SimpleSAML_Configuration $config
* @return callable
*/
public function createAuthenticationModuleFactory (SimpleSAML_Configuration $config)
{
$module = $config->getString('module');
switch ($module) {
case 'lbs4-webservice':
$serviceUrl = $config->getString('serviceUrl');
$catalogNumber = $config->getInteger('catalogNumber');
$lbsUserNumber = $config->getInteger('lbsUserNumber');
$factory = function () use ($serviceUrl, $catalogNumber, $lbsUserNumber) {
return new Auth\LBSAuthentication($serviceUrl, $catalogNumber, $lbsUserNumber);
};
break;
case 'loan3-web':
$serviceUrl = $config->getString('serviceUrl');
$factory = function () use ($serviceUrl) {
return new Auth\LOAN3WebAuthentication($serviceUrl);
};
break;
default:
throw new Exception("Unknown pica authentication module: '{$module}'");
}
}
/** /**
* Return normalized attributes. * Return normalized attributes.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment