From d2b1a0a3b5e51cb6bdaf81d0374b126341544a16 Mon Sep 17 00:00:00 2001 From: Christophe Massin Date: Tue, 29 Jul 2014 14:25:07 +0200 Subject: [PATCH] adding custom feature from ldap auth --- model/LdapAdapter.php | 31 ++++++++++++++++++++++++++----- model/LdapUser.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/model/LdapAdapter.php b/model/LdapAdapter.php index cded547..1d3004e 100644 --- a/model/LdapAdapter.php +++ b/model/LdapAdapter.php @@ -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 */ diff --git a/model/LdapUser.php b/model/LdapUser.php index 8377726..c848075 100644 --- a/model/LdapUser.php +++ b/model/LdapUser.php @@ -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; }