Author Topic: Auto create user from LDAP [SOLVED]  (Read 5813 times)

deleted

  • Newbie
  • *
  • Posts: 5
    • View Profile
Auto create user from LDAP [SOLVED]
« on: January 31, 2011, 06:44:38 am »
Create function in \fengoffice\application\models\users\User.class.php

Code: [Select]
/**
* Get user attributes from ldap
*
* @return attribute value
*/
function AttribFromLdap($user, $password, $config, $attrib) {

// Connecting using the configuration:
require_once "Net/LDAP2.php";

$ldap = Net_LDAP2::connect($config);

// Testing for connection error
if (PEAR::isError($ldap)) {
return false;
}
$filter = Net_LDAP2_Filter::create($config['uid'], 'equals', $user);
$search = $ldap->search(null, $filter, array());

if (Net_LDAP2::isError($search)) {
return false;
}

if ($search->count() != 1) {
return false;
}

// User exists so we may rebind to authenticate the password
$entries = $search->entries();
$result = $entries[0]->getValue($attrib);

return $result;
} // AttribFromLdap


Change \fengoffice\application\controllers\AccessController.class.php in section // If ldap authentication is enabled ldap.config.php will return true.
Code: [Select]
// If ldap authentication is enabled ldap.config.php will return true.
$config_ldap_file_path = ROOT . '/config/ldap.config.php';
$config_ldap_is_set = file_exists($config_ldap_file_path) && include_once($config_ldap_file_path);

  // create temp object and check LDAP
$temp_user = new User();
$temp_user->setCompanyId(1);
$temp_user->setUsername($username);
$temp_user->setPassword($password);
$userIsValidPassword = $temp_user->isValidPasswordLdap($username, $password, $config_ldap); // Check password

if ($userIsValidPassword && !($user instanceof User)) { //If user found in LDAP and not registered then save user and set properties

$temp_user->setEmail($temp_user->AttribFromLdap($username, $password, $config_ldap, "mail")); // Use custom function. \fengoffice\application\models\users\User.class.php
$temp_user->setDisplayName($temp_user->AttribFromLdap($username, $password, $config_ldap, "cn"));

$temp_user->save();

$user = $temp_user;

$project = new Project();
$project->setName(new_personal_project_name($user->getDisplayName())); // set Project name. For exemple $user->getUsername()
$project->setDescription(lang('files'));
$project->setCreatedById($user->getId());

$project->save();

$user->setPersonalProjectId($project->getId()); // set default project

$project_user = new ProjectUser();
$project_user->setProjectId($project->getId());
$project_user->setUserId($user->getId());
$project_user->setCreatedById($user->getId());
$project_user->setAllPermissions(true);

$project_user->save();
}

if(!($user instanceof User)) {
AdministrationLogs::createLog("invalid login", array_var($_SERVER, 'REMOTE_ADDR'), AdministrationLogs::ADM_LOG_CATEGORY_SECURITY);
tpl_assign('error', new Error(lang('invalid login data')));
$this->render();
} // if

Working!

supadoctor

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Email
Re: Auto create user from LDAP [SOLVED]
« Reply #1 on: January 31, 2011, 08:24:34 pm »
Hmm... Put it into Wiki!

deleted

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Auto create user from LDAP [SOLVED]
« Reply #2 on: February 10, 2011, 05:13:43 am »
Find bug:
When created personal project, P1 field = 0.
Need help. How create correct personal project?

franponce87

  • Administrator
  • Hero Member
  • *****
  • Posts: 1819
    • View Profile
    • Email
Re: Auto create user from LDAP [SOLVED]
« Reply #3 on: February 11, 2011, 01:25:21 pm »
I do not remember the code by heart of course, but to get that info I would suggest looking for the functions called when you add a new user in the controllers, more specifically how does it determine its new workspace.

Best regards,
Francisco
Would you like to install Feng Office Professional or Enterprise Edition in your servers? No problem! Read this article!

supadoctor

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
    • Email
Re: Auto create user from LDAP [SOLVED]
« Reply #4 on: March 17, 2011, 11:27:44 am »
Find bug:
When created personal project, P1 field = 0.
Need help. How create correct personal project?

P1 should contain the workspace id.

CheezItMan

  • Freshman
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Auto create user from LDAP [SOLVED]
« Reply #5 on: April 18, 2011, 08:19:22 am »

I'm trying this with opengoo + the spreadsheet, so far without success.

Could you elaborate which lines in the 2nd file to modify?

does this work with the current version with gelsheet?
http://sourceforge.net/projects/gelsheet/files/Gelsheet%20for%20Fengoffice/Gelsheet%201.02/gelsheet1.02_fengoffice1.7.2.zip/download?use_mirror=ncu