ldap connection working
This commit is contained in:
parent
c718e76330
commit
3a8e66c438
@ -77,14 +77,21 @@ class LdapAdapter implements LoginAdapter
|
|||||||
public function authenticate() {
|
public function authenticate() {
|
||||||
$adapter = new Ldap();
|
$adapter = new Ldap();
|
||||||
$adapter->setOptions(
|
$adapter->setOptions(
|
||||||
array($this->getConfiguration())
|
array(array(
|
||||||
|
'host' => '127.0.0.1',
|
||||||
|
'accountDomainName' => 'test.com',
|
||||||
|
'username' => 'cn=admin,dc=test,dc=com',
|
||||||
|
'password' => 'admin',
|
||||||
|
'baseDn' => 'OU=organisation,dc=test,dc=com',
|
||||||
|
'bindRequiresDn' => 'true',
|
||||||
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
$adapter->setUsername($this->getUsername());
|
$adapter->setUsername($this->getUsername());
|
||||||
$adapter->setPassword($this->getPassword());
|
$adapter->setPassword($this->getPassword());
|
||||||
|
$result = $adapter->authenticate();
|
||||||
|
|
||||||
|
if($result->isValid()){
|
||||||
if($adapter->authenticate()){
|
|
||||||
|
|
||||||
$result = $adapter->getAccountObject();
|
$result = $adapter->getAccountObject();
|
||||||
$params = get_object_vars($result);
|
$params = get_object_vars($result);
|
||||||
@ -92,9 +99,7 @@ class LdapAdapter implements LoginAdapter
|
|||||||
$user = new LdapUser();
|
$user = new LdapUser();
|
||||||
|
|
||||||
$user->setConfiguration($this->getConfiguration());
|
$user->setConfiguration($this->getConfiguration());
|
||||||
$user->setRoles(array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole'));
|
$user->setUserRawParameters($params);
|
||||||
$user->setLanguageUi($params['preferredlanguage']);
|
|
||||||
$user->setLanguageDefLg($params['preferredlanguage']);
|
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
|
|
||||||
|
@ -96,12 +96,7 @@ class LdapUser extends common_user_User {
|
|||||||
*/
|
*/
|
||||||
public function setLanguageDefLg($languageDefLgUri)
|
public function setLanguageDefLg($languageDefLgUri)
|
||||||
{
|
{
|
||||||
$languageResource = new core_kernel_classes_Resource($languageDefLgUri);
|
$this->languageDefLg = array((string)$languageDefLgUri);
|
||||||
|
|
||||||
$languageCode = $languageResource->getUniquePropertyValue(new core_kernel_classes_Property(RDF_VALUE));
|
|
||||||
if($languageCode) {
|
|
||||||
$this->languageDefLg = array((string)$languageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -132,15 +127,34 @@ class LdapUser extends common_user_User {
|
|||||||
return $this->userExtraParameters;
|
return $this->userExtraParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $property string
|
||||||
|
* @param $value string
|
||||||
|
*/
|
||||||
|
public function setUserParameter($property, $value){
|
||||||
|
$this->userRawParameters[$property] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getUserParameter($property) {
|
||||||
|
if (isset ($this->userRawParameters[$property] ) )
|
||||||
|
return $this->userRawParameters[$property];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rray $userRawParameters
|
* @param array $params
|
||||||
* @return AuthKeyValueUser
|
* @return AuthKeyValueUser
|
||||||
*/
|
*/
|
||||||
public function setUserRawParameters(array $userRawParameters)
|
public function setUserRawParameters(array $params)
|
||||||
{
|
{
|
||||||
$this->userRawParameters = $userRawParameters;
|
$this->setRoles(array('http://www.tao.lu/Ontologies/TAO.rdf#DeliveryRole'));
|
||||||
|
|
||||||
|
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']) ;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -159,12 +173,7 @@ class LdapUser extends common_user_User {
|
|||||||
*/
|
*/
|
||||||
public function setLanguageUi($languageUri)
|
public function setLanguageUi($languageUri)
|
||||||
{
|
{
|
||||||
$languageResource = new core_kernel_classes_Resource($languageUri);
|
$this->languageUi = array((string)$languageUri);
|
||||||
|
|
||||||
$languageCode = $languageResource->getUniquePropertyValue(new core_kernel_classes_Property(RDF_VALUE));
|
|
||||||
if($languageCode) {
|
|
||||||
$this->languageUi = array((string)$languageCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -204,52 +213,18 @@ class LdapUser extends common_user_User {
|
|||||||
{
|
{
|
||||||
$returnValue = null;
|
$returnValue = null;
|
||||||
|
|
||||||
$userParameters = $this->getUserRawParameters();
|
switch ($property) {
|
||||||
|
case PROPERTY_USER_DEFLG :
|
||||||
if( !empty($userParameters) && array_key_exists($property, $userParameters))
|
$returnValue = $this->getLanguageDefLg();
|
||||||
{
|
break;
|
||||||
switch ($property) {
|
case PROPERTY_USER_UILG :
|
||||||
case PROPERTY_USER_DEFLG :
|
$returnValue = $this->getLanguageUi();
|
||||||
$returnValue = $this->getLanguageDefLg();
|
break;
|
||||||
break;
|
case PROPERTY_USER_ROLES :
|
||||||
case PROPERTY_USER_UILG :
|
$returnValue = $this->getRoles();
|
||||||
$returnValue = $this->getLanguageUi();
|
break;
|
||||||
break;
|
default:
|
||||||
case PROPERTY_USER_ROLES :
|
$returnValue = array($this->getUserParameter($property));
|
||||||
$returnValue = $this->getRoles();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$returnValue = array($userParameters[$property]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$extraParameters = $this->getUserExtraParameters();
|
|
||||||
// the element has already been accessed
|
|
||||||
if(!empty($extraParameters) && array_key_exists($property, $extraParameters)){
|
|
||||||
if(!is_array($extraParameters[$property])){
|
|
||||||
$returnValue = array($extraParameters[$property]);
|
|
||||||
} else {
|
|
||||||
$returnValue = $extraParameters[$property];
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// not already accessed, we are going to get it.
|
|
||||||
$serviceUser = new AuthKeyValueUserService();
|
|
||||||
$parameter = $serviceUser->getUserParameter($userParameters[PROPERTY_USER_LOGIN], $property);
|
|
||||||
|
|
||||||
$config = $this->getConfiguration();
|
|
||||||
if(isset($config['max_size_cached_element'])){
|
|
||||||
if( strlen(base64_encode(serialize($parameter))) < $config['max_size_cached_element'] ) {
|
|
||||||
$extraParameters[$property] = $parameter;
|
|
||||||
$this->setUserExtraParameters($extraParameters);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Exception('Missing configuration element max_sized_cached_element');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$returnValue = array($parameter);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $returnValue;
|
return $returnValue;
|
||||||
|
Loading…
Reference in New Issue
Block a user