Ejemplo n.º 1
0
 /**
  * Add (by name) new users into a user group.
  * 
  * @param Array   $userList List of user identifier (e.g. ldap login)
  * 
  * @return void
  */
 public function addListOfUsersToGroup($userList)
 {
     $ldapUserManager = new LDAP_UserManager($this->getLdap());
     $userIds = $ldapUserManager->getUserIdsFromUserList($userList);
     foreach ($userIds as $userId) {
         $this->addUserToGroup($this->id, $userId);
     }
 }
Ejemplo n.º 2
0
 /**
  * Hook
  * 
  * @params $params $params['login']
  *                 $params['password']
  *                 $params['auth_success']
  *                 $params['auth_user_id']
  *                 $params['auth_user_status']
  */
 function authenticate($params)
 {
     global $Language;
     if ($GLOBALS['sys_auth_type'] == 'ldap') {
         $params['auth_success'] = false;
         $ldap = $this->getLdap();
         // Perform LDAP authentication
         if ($ldap->authenticate($params['loginname'], $params['passwd'])) {
             $lri = $ldap->searchLogin($params['loginname']);
             if ($lri->count() === 1) {
                 // Check if this user is a codendi user or not.
                 $lr = $lri->get(0);
                 $user = UserManager::instance()->getUserByLdapId($lr->getEdUid());
                 $ldapUm = new LDAP_UserManager($ldap);
                 if ($user === null) {
                     // Authenticated user
                     // without codendi account
                     // create account!
                     $user = $ldapUm->createAccountFromLdap($lr);
                     if ($user) {
                         $params['auth_user_id'] = $user->getId();
                         $params['auth_user_status'] = $user->getStatus();
                         $params['auth_success'] = true;
                     }
                 } else {
                     $ldapUm->synchronizeUser($user, $lr, $params['passwd']);
                     $params['auth_user_id'] = $user->getId();
                     $params['auth_user_status'] = $user->getStatus();
                     $params['auth_success'] = true;
                 }
             } else {
                 $GLOBALS['Response']->addFeedback('error', $Language->getText('include_session', 'invalid_ldap_name'));
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Get the Codendi user id of the people in given LDAP group
  * 
  * This method takes an LDAP group Distinguish Name 
  * - Fetch all the members of the group
  * - Creates their Codendi account if it doesn't exist
  * - Return the Codendi id of people 
  * 
  * @param String $groupDn LDAP DN of the group.
  * 
  * @return Array
  */
 public function getLdapGroupMembersIds($groupDn)
 {
     $ldapUserManager = new LDAP_UserManager($this->getLdap());
     $ldapGroupMembers = $this->getLdapGroupMembers($groupDn);
     $ldapGroupUserIds = $ldapUserManager->getUserIdsForLdapUser($ldapGroupMembers);
     return $ldapGroupUserIds;
 }
Ejemplo n.º 4
0
 /**
  * Return LDAP login stored in DB corresponding to given userId.
  *
  * @return String requester login
  */
 function _getRequesterLdapLogin()
 {
     $um = $this->_getUserManager();
     $user = $um->getCurrentUser();
     $pluginManager = $this->_getPluginManager();
     $ldapPlugin = $pluginManager->getPluginByName('ldap');
     if ($ldapPlugin && $pluginManager->isPluginAvailable($ldapPlugin)) {
         $ldapUm = new LDAP_UserManager($ldapPlugin->getLdap());
         $userId[] = $user->getId();
         $ldapLogin = $ldapUm->getLdapLoginFromUserIds($userId);
         if ($ldapLogin && !$ldapLogin->isError() && $ldapLogin->rowCount() > 0) {
             $ldapLoginArray = $ldapLogin->getRow();
             $requester = $ldapLoginArray['ldap_uid'];
         } else {
             $requester = $this->_getPluginProperty('requesthelp_submitter');
         }
     } else {
         $requester = $this->_getPluginProperty('requesthelp_submitter');
     }
     return $requester;
 }
Ejemplo n.º 5
0
        if ($um->updateDb($currentUser)) {
            $ldapUserDao = new LDAP_UserDao(CodendiDataAccess::instance());
            $ldapUserDao->setLoginDate($user_id, $_SERVER['REQUEST_TIME']);
        } else {
            welcome_exit_error($Language->getText('plugin_ldap', 'welcome_error_up'), $Language->getText('plugin_ldap', 'welcome_error_up_expl', array('')));
        }
    }
    account_redirect_after_login();
} else {
    $pv = 0;
    $vPv = new Valid_Pv();
    if ($request->valid($vPv)) {
        $pv = $request->get('pv');
    }
    $timezone = $request->existAndNonEmpty('timezone') ? $request->get('timezone') : 'None';
    $ldapUm = new LDAP_UserManager($ldapPlugin->getLdap());
    $lr = $ldapUm->getLdapFromUserId($user_id);
    $ldap_name = $lr->getLogin();
    $star = '<span class="highlight"><big>*</big></span>';
    if ($pv == 2) {
        $HTML->pv_header(array());
    } else {
        $HTML->header(array('title' => $Language->getText('plugin_ldap', 'welcome_title', array($lr->getCommonName())), 'registeration_process' => true));
    }
    print '<h2>';
    print $Language->getText('plugin_ldap', 'welcome_title', array($lr->getCommonName()));
    print '</h2>';
    print '<h3>';
    print $Language->getText('plugin_ldap', 'welcome_first_login', array($GLOBALS['sys_name']));
    print '</h3>';
    print '<p>' . $Language->getText('plugin_ldap', 'welcome_fill_form', array($GLOBALS['sys_name'])) . '</p>';
Ejemplo n.º 6
0
 function testGetLoginFromString()
 {
     $ldap = new MockLDAP($this);
     $lum = new LDAP_UserManager($ldap, mock('LDAP_UserSync'));
     $this->assertEqual($lum->getLoginFromString('coincoin'), 'coincoin');
     $this->assertEqual($lum->getLoginFromString('coin coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin.coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin:coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin;coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin,coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin?coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin%coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin^coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin*coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin(coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin)coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin{coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin}coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin[coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin]coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin<coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin>coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin+coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin=coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin$coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString('coin\\ coin'), 'coin_coin');
     $this->assertEqual($lum->getLoginFromString("coincoin'"), 'coincoin');
     $this->assertEqual($lum->getLoginFromString('coincoin"'), 'coincoin');
     $this->assertEqual($lum->getLoginFromString('coin/coin'), 'coincoin');
     // Accent test
     $this->assertEqual($lum->getLoginFromString('coiné'), 'coine');
     // getLoginFromString only accept utf8 strings.
     //$this->assertEqual($lum->getLoginFromString(utf8_decode('coiné')), 'coine');
 }
Ejemplo n.º 7
0
$pluginManager = PluginManager::instance();
$ldapPlugin = $pluginManager->getPluginByName('ldap');
if ($ldapPlugin && $pluginManager->isPluginAvailable($ldapPlugin)) {
    // -h --help help
    // --ldapid="" ldap_id(required)
    // --realname="" realname (required)
    // --email="" email (required)
    // --uid="" uid (required);
    //print_r($_SERVER['argv']);
    $arg = extract_params($_SERVER['argv']);
    //print_r($arg);
    if (isset($arg['ldapid']) && isset($arg['realname']) && isset($arg['email']) && isset($arg['uid'])) {
        //  Check if user exists
        $user = UserManager::instance()->getUserByLdapId($arg['ldapid']);
        if ($user) {
            echo "Error: ldap id already in the database\n";
            exit;
        } else {
            $ldapUm = new LDAP_UserManager($ldapPlugin->getLdap());
            $user = $ldapUm->createAccount($arg['ldapid'], $arg['uid'], $arg['realname'], $arg['email']);
            if ($user) {
                echo "ID=" . $user->getId() . ":STATUS=" . $user->getStatus() . "\n";
                return 0;
            }
        }
    }
}
echo "Error\n";
return 1;
//phpinfo();
//