adding custom feature from ldap auth

This commit is contained in:
Christophe Massin 2014-07-29 14:25:07 +02:00
parent 0de6b3e6f3
commit d2b1a0a3b5
2 changed files with 62 additions and 5 deletions

View File

@ -23,7 +23,7 @@
* Authentication adapter interface to be implemented by authentication methodes
*
* @author christophe massin
* @package authKeyValue
* @package authLdap
*/
@ -31,7 +31,8 @@ namespace oat\authLdap\model;
use core_kernel_users_Service;
use core_kernel_users_InvalidLoginException;
use oat\authKeyValue\model\AuthKeyValueUser;
use oat\authLdap\model\LdapUser;
use oat\generisHard\models\hardsql\Exception;
use oat\oatbox\user\auth\LoginAdapter;
use Zend\Authentication\Adapter\Ldap;
use common_persistence_Manager;
@ -53,6 +54,9 @@ class LdapAdapter implements LoginAdapter
/** @var $configuration array $configuration */
protected $configuration;
/** @var $mapping array $mapping */
protected $mapping;
/**
* @var \Zend\Authentication\Adapter\Ldap
*/
@ -66,6 +70,7 @@ class LdapAdapter implements LoginAdapter
$this->adapter = new Ldap();
$this->adapter->setOptions($configuration['config']);
$this->setMapping($configuration['mapping']);
}
@ -94,11 +99,9 @@ class LdapAdapter implements LoginAdapter
$result = $adapter->getAccountObject();
$params = get_object_vars($result);
$user = new LdapUser();
$user = new LdapUser($this->getMapping());
$user->setConfiguration($this->getConfiguration());
$user->setUserRawParameters($params);
return $user;
} else {
@ -141,6 +144,24 @@ class LdapAdapter implements LoginAdapter
return $this->configuration;
}
/**
* @param array $mapping
*/
public function setMapping($mapping)
{
$this->mapping = $mapping;
}
/**
* @return array
*/
public function getMapping()
{
return $this->mapping;
}
/**
* @param string $password
*/

View File

@ -73,6 +73,27 @@ class LdapUser extends common_user_User {
protected $languageDefLg = array(DEFAULT_LANG);
/**
* The mapping of custom parameter from ldap to TAO property
*
* @var array
*/
protected $mapping;
public function __construct(array $mapping = null){
$this->mapping = $mapping;
}
/**
* @return array
*/
public function getMapping()
{
return $this->mapping;
}
/**
* Sets the language URI
*
@ -119,11 +140,26 @@ class LdapUser extends common_user_User {
{
$this->setRoles(array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole'));
// initialize parameter that should be set
isset($params['preferredlanguage']) ? $this->setLanguageUi($params['preferredlanguage']) : DEFAULT_LANG;
isset($params['preferredlanguage']) ? $this->setLanguageDefLg($params['preferredlanguage']) : DEFAULT_LANG;
isset($params['mail']) ? $this->setUserParameter(PROPERTY_USER_MAIL, $params['mail']) : '';
isset($params['displayname']) ? $this->setUserParameter(PROPERTY_USER_LASTNAME, $params['displayname']) : $this->setUserParameter(PROPERTY_USER_LASTNAME, $params['cn']) ;
$mapping = $this->getMapping();
foreach($params as $key => $value) {
if(! in_array($key, array('preferredlanguage','mail', 'displayname'))) {
if(array_key_exists($key, $mapping)){
$this->setUserParameter($mapping[$key], $value);
}
}
}
return $this;
}