Commits

Anonymous committed 9aa0a26

commit for LDAP=>Ldap

  • Participants
  • Parent commits 1125b66

Comments (0)

Files changed (11)

File app/protected/modules/install/serviceHelpers/LdapServiceHelper.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Checks that the Ldap extension for php is installed.
+     */
+    class LdapServiceHelper extends ServiceHelper
+    {
+        protected $required = false;
+
+        protected function checkService()
+        {
+            $passed = InstallUtil::isLdapInstalled();
+            if ($passed)
+            {
+                $this->message = Zurmo::t('InstallModule', 'Ldap is installed.');
+            }
+            else
+            {
+                $this->message = Zurmo::t('InstallModule', 'Ldap is not installed.');
+            }
+            return $passed;
+        }
+    }
+?>

File app/protected/modules/users/UserLdapIdentity.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * UserLdapIdentity represents the data needed to identity a user using ldap server 
+	 * authentication.
+     */
+    class UserLdapIdentity extends UserIdentity
+    {
+        
+        const ERROR_NO_RIGHT_WEB_LOGIN = 3;
+        /**
+         * Authenticates a user against ldap server.
+         * @return boolean whether authentication succeeds.
+         */
+        public function authenticate()
+        {
+            try
+            {                
+                $host                      = Yii::app()->authenticationHelper->ldapHost;
+                $port                      = Yii::app()->authenticationHelper->ldapPort;
+                $baseDomain                = Yii::app()->authenticationHelper->ldapBaseDomain;
+                $bindPassword              = Yii::app()->authenticationHelper->ldapBindPassword;
+                $bindRegisteredDomain      = Yii::app()->authenticationHelper->ldapBindRegisteredDomain;                                 
+                $ldapConnection            = LdapUtil::establishConnection($host,$port,$bindRegisteredDomain,
+                                                                           $bindPassword,$baseDomain);                                                        
+                if($ldapConnection)
+                {                                     
+                    $ldapFilter              = '(|(cn='.$this->username.')(&(uid='.$this->username.')))'; 
+                    $ldapResults             = ldap_search($ldapConnection, $baseDomain,$ldapFilter); 					
+                    $ldapResultsCount        = ldap_count_entries($ldapConnection,$ldapResults);  
+                    if ($ldapResultsCount > 0)
+                    {				 
+                        $result = @ldap_get_entries($ldapConnection, $ldapResults);                                                          					
+                        $zurmoLogin = parent::authenticate();                                           
+                        if(!$zurmoLogin)
+                        {
+                           if ($result[0] && @ldap_bind($ldapConnection, $result[0]['dn'], $this->password))
+                            {                                
+                              if($this->errorCode!=1)
+                              {
+                                 $this->setState('username', $this->username);
+                                 $this->errorCode = self::ERROR_NONE;
+                                 return true;
+                              }                              
+                            }                                                    
+                        }
+                        else
+                        {                             
+                            $this->setState('username', $this->username);
+                            $this->errorCode = self::ERROR_NONE;
+                            return true;
+                        }
+                    }
+                    else
+                    {
+                        return parent::authenticate();	                     
+                    }					
+                }
+                else
+                {
+                    return parent::authenticate();
+                }
+            }
+            catch (NotFoundException $e)
+            {
+                $this->errorCode = self::ERROR_USERNAME_INVALID;
+            }
+            catch (BadPasswordException $e)
+            {
+                $this->errorCode = self::ERROR_PASSWORD_INVALID;
+            }
+            catch (NoRightWebLoginException $e)
+            {
+                $this->errorCode = self::ERROR_NO_RIGHT_WEB_LOGIN;
+            }
+            return false;
+        }
+    }
+?>

File app/protected/modules/users/tests/unit/UserLdapTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    class UserLdapTest extends ZurmoBaseTest
+    {
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();            
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet()) 
+            {            
+                Yii::app()->authenticationHelper->ldapHost                 = 
+                Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapHost'];
+                Yii::app()->authenticationHelper->ldapPort                 = 
+                Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapPort'];
+                Yii::app()->authenticationHelper->ldapBindRegisteredDomain = 
+                Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBindRegisteredDomain'];
+                Yii::app()->authenticationHelper->ldapBindPassword         = 
+                Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBindPassword'];
+                Yii::app()->authenticationHelper->ldapBaseDomain           = 
+                Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBaseDomain'];
+                Yii::app()->authenticationHelper->ldapEnabled              = 
+                Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapEnabled'];            
+                Yii::app()->authenticationHelper->setLdapSettings();
+                Yii::app()->authenticationHelper->init();            
+            }
+        }
+
+        public function setUp()
+        {
+            parent::setUp();
+            Yii::app()->user->userModel = User::getByUsername('super');
+        }
+
+        /**
+        *user exists in zurmo but not on ldap
+        */
+        public function testUserExitsInZurmoButNotOnldap()
+        {   
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet())
+            {
+                $this->markTestSkipped(Yii::t('Default', 'Test Ldap settings are not configured in perInstanceTest.php file.'));
+            }      
+            $user               = new User();
+            $user->username     = 'abcdefg';
+            $user->title->value = 'Mr.';
+            $user->firstName    = 'abcdefg';
+            $user->lastName     = 'abcdefg';
+            $user->setPassword('abcdefgN4');
+            $this->assertTrue($user->save());
+            //Now attempt to login as bill a user in zurmo but not on ldap
+            $bill               = User::getByUsername('abcdefg');
+            $this->assertEquals(md5('abcdefgN4'), $bill->hash);
+            $bill->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB, RIGHT::ALLOW);
+            $this->assertTrue($bill->save());
+            //for normal user
+            $identity           = new UserIdentity('abcdefg', 'abcdefgN4');
+            $authenticated      = $identity->authenticate();
+            $this->assertEquals(0, $identity->errorCode);
+            $this->assertTrue($authenticated);
+            $bill->forget();            
+        }
+        
+        /**
+        *one where it exists in both, but the pass is wrong for ldap, but ok for zurmo pass.
+        */
+        public function testUserExitsInBothButWrongPasswordForldap()
+        {
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet())
+            {
+                $this->markTestSkipped(Yii::t('Default', 'Test Ldap settings are not configured in perInstanceTest.php file.'));
+            } 
+            Yii::app()->user->userModel = User::getByUsername('super');
+            //creating user same as on ldap with different password
+            $admin = new User();
+            $admin->username           = 'admin';
+            $admin->title->value       = 'Mr.';
+            $admin->firstName          = 'admin';
+            $admin->lastName           = 'admin';
+            $admin->setPassword('test123');
+            $this->assertTrue($admin->save());
+            $admin->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB, RIGHT::ALLOW);
+            $this->assertTrue($admin->save());
+            $username = Yii::app()->authenticationHelper->ldapBindRegisteredDomain;
+            $password = Yii::app()->authenticationHelper->ldapBindPassword;
+            $identity = new UserLdapIdentity($username,'test123');                        
+            $authenticated = $identity->authenticate(true);
+            $this->assertEquals(0, $identity->errorCode);
+            $this->assertTrue($authenticated);     
+        }
+        
+        /**
+        *one for when the user exists in ldap but not zurmo
+        */
+        public function testUserExitsInldapNotInZurmo()
+        {
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet())
+            {
+                $this->markTestSkipped(Yii::t('Default', 'Test Ldap settings are not configured in perInstanceTest.php file.'));
+            } 
+            Yii::app()->user->userModel = User::getByUsername('super');     
+            $identity                   = new UserLdapIdentity('john','johnldap');                        
+            $authenticated              = $identity->authenticate(true);
+            $this->assertEquals(1, $identity->errorCode);
+            $this->assertFalse($authenticated);     
+        }                
+        
+        /**
+        *one for when the user exists in ldap and zurmo
+        */
+        public function testUserExitsInldapAndZurmo()
+        {                    
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet())
+            {
+                $this->markTestSkipped(Yii::t('Default', 'Test Ldap settings are not configured in perInstanceTest.php file.'));
+            } 
+            Yii::app()->user->userModel = User::getByUsername('super'); 
+            $username                   = Yii::app()->authenticationHelper->ldapBindRegisteredDomain;
+            $password                   = Yii::app()->authenticationHelper->ldapBindPassword;            
+            $identity                   = new UserLdapIdentity($username,$password);                        
+            $authenticated              = $identity->authenticate(true);
+            $this->assertEquals(0, $identity->errorCode);
+            $this->assertTrue($authenticated);     
+        }                  
+    }
+?>

File app/protected/modules/zurmo/adapters/ldap/LdapConfigurationFormAdapter.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Class to adapt Ldap Configuration values into a configuration form.
+     * Saves global values from a configuration form.
+     */
+    class LdapConfigurationFormAdapter
+    {
+        /**
+         * @return LdapConfigurationForm
+         */
+        public static function makeFormFromGlobalConfiguration()
+        {
+            $form                                    = new LdapConfigurationForm();
+            $form->host                              = Yii::app()->authenticationHelper->ldapHost;
+            $form->port                              = Yii::app()->authenticationHelper->ldapPort;
+            $form->bindRegisteredDomain              = Yii::app()->authenticationHelper->ldapBindRegisteredDomain;            
+            $form->bindPassword                      = Yii::app()->authenticationHelper->ldapBindPassword;
+            $form->baseDomain                        = Yii::app()->authenticationHelper->ldapBaseDomain;
+            $form->enabled                           = Yii::app()->authenticationHelper->ldapEnabled;			
+            return $form;
+        }
+
+        /**
+         * Given a LdapConfigurationForm, save the configuration global values.
+         */
+        public static function setConfigurationFromForm(LdapConfigurationForm $form)
+        {             
+            Yii::app()->authenticationHelper->ldapHost                 = $form->host;
+            Yii::app()->authenticationHelper->ldapPort                 = $form->port;
+            Yii::app()->authenticationHelper->ldapBindRegisteredDomain = $form->bindRegisteredDomain;
+            Yii::app()->authenticationHelper->ldapBindPassword         = $form->bindPassword;
+            Yii::app()->authenticationHelper->ldapBaseDomain           = $form->baseDomain;
+            Yii::app()->authenticationHelper->ldapEnabled                  = $form->enabled;
+            Yii::app()->authenticationHelper->setLdapSettings();
+       }
+    }
+?>

File app/protected/modules/zurmo/controllers/LdapController.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Controller Class for managing Ldap Authentication.
+     *
+     */
+    class ZurmoLdapController extends ZurmoModuleController
+    {       
+        public function actionConfigurationEditLdap()
+        {
+            $configurationForm = LdapConfigurationFormAdapter::makeFormFromGlobalConfiguration();
+            $postVariableName   = get_class($configurationForm);            
+            if (isset($_POST[$postVariableName]))
+            {                                  
+                $configurationForm->setAttributes($_POST[$postVariableName]);                
+                if ($configurationForm->validate())
+                {
+                    LdapConfigurationFormAdapter::setConfigurationFromForm($configurationForm);
+                    Yii::app()->user->setFlash('notification',
+                        Yii::t('Default', 'Ldap Configuration saved successfully.')
+                    );
+                    $this->redirect(Yii::app()->createUrl('configuration/default/index'));
+                }
+            }
+            $editView = new LdapConfigurationEditAndDetailsView(
+                                    'Edit',
+                                    $this->getId(),
+                                    $this->getModule()->getId(),
+                                    $configurationForm);
+            $editView->setCssClasses( array('AdministrativeArea') );
+            $view = new ZurmoConfigurationPageView(ZurmoDefaultAdminViewUtil::
+                                         makeStandardViewForCurrentUser($this, $editView));
+            echo $view->render();
+        }
+        
+        public function actionTestConnection()
+        {
+            $configurationForm = LdapConfigurationFormAdapter::makeFormFromGlobalConfiguration();
+            $postVariableName  = get_class($configurationForm);
+            if (isset($_POST[$postVariableName]) || (isset($_POST['LdapConfigurationForm'])))
+            {
+                if (isset($_POST[$postVariableName]))
+                {
+                    $configurationForm->setAttributes($_POST[$postVariableName]);
+                }
+                else
+                {
+                    $configurationForm->host                  = $_POST['LdapConfigurationForm']['host'];
+                    $configurationForm->port                  = $_POST['LdapConfigurationForm']['port'];
+                    $configurationForm->bindRegisteredDomain  = $_POST['LdapConfigurationForm']['bindRegisteredDomain'];
+                    $configurationForm->bindPassword          = $_POST['LdapConfigurationForm']['bindPassword'];
+                    $configurationForm->baseDomain            = $_POST['LdapConfigurationForm']['baseDomain'];
+                    $configurationForm->enabled               = $_POST['LdapConfigurationForm']['enabled'];                    
+                }
+                if ($configurationForm->host != null && $configurationForm->port != null && 
+                    $configurationForm->bindRegisteredDomain != null && $configurationForm->bindPassword != null &&
+      				$configurationForm->baseDomain != null	)
+                {
+                    $authenticationHelper = new ZurmoAuthenticationHelper;
+                    $authenticationHelper->ldapHost                 = $configurationForm->host;
+                    $authenticationHelper->ldapPort                 = $configurationForm->port;
+                    $authenticationHelper->ldapBindRegisteredDomain = $configurationForm->bindRegisteredDomain;
+                    $authenticationHelper->ldapBindPassword         = $configurationForm->bindPassword;
+                    $authenticationHelper->ldapBaseDomain           = $configurationForm->baseDomain;
+                    $authenticationHelper->ldapEnabled              = $configurationForm->enabled;
+                    
+                    $host                      = $configurationForm->host;             
+                    $port                      = $configurationForm->port;                
+                    $bindRegisteredDomain      = $configurationForm->bindRegisteredDomain;
+                    $bindPassword              = $configurationForm->bindPassword;         
+                    $baseDomain                = $configurationForm->baseDomain;           
+                    $testConnectionResults     = LdapUtil::establishConnection($host,$port,$bindRegisteredDomain,
+                                                                               $bindPassword,$baseDomain);                      
+                    if($testConnectionResults)
+                    {
+                       $messageContent = Yii::t('Default', 'Successfully Connected to Ldap Server') . "\n";  
+                    }
+                    else
+                    {
+                       $messageContent = Yii::t('Default', 'Unable to connect to Ldap server') . "\n";
+                    }                                                                   
+                }
+                else
+                {
+                    $messageContent = Yii::t('Default', 'All fields are required') . "\n";
+                }
+                Yii::app()->getClientScript()->setToAjaxMode();
+                $messageView = new TestLdapConnectionView($messageContent);
+                $view = new ModalView($this, $messageView);				
+                echo $view->render();
+            }
+            else
+            {
+                throw new NotSupportedException();
+            }
+        }
+    }
+	
+?>

File app/protected/modules/zurmo/elements/TestLdapConnectionElement.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Utilize this element to display a  button that can be used to send a test Ldap connection while setting
+     * up the Ldap server configuration.
+     */
+    class TestLdapConnectionElement extends Element
+    {
+        /**
+         * Renders a button.
+         * @return A string containing the element's content.
+         */
+        protected function renderControlEditable()
+        {
+            $htmlOptions             = array();
+            $htmlOptions['id']       = $this->getEditableInputId();
+            $htmlOptions['name']     = $this->getEditableInputName();
+            $htmlOptions['disabled'] = $this->getDisabledValue();
+            $htmlOptions             = array_merge($this->getHtmlOptions(), $htmlOptions);
+            $content                 = $this->renderTestButton();
+            return $content;
+        }
+
+        protected function renderControlNonEditable()
+        {
+            throw new NotImplementedException();
+        }
+
+        protected function renderError()
+        {
+            return null;
+        }
+
+       /**
+         * Render a test button. This link calls a modal
+         * popup.
+         * @return The element's content as a string.
+         */
+        protected function renderTestButton()
+        {
+            $content  = '<span>';
+            $content .= ZurmoHtml::ajaxLink(
+                ZurmoHtml::tag('span', array('class' => 'z-label'), Yii::t('Default', 'Test Connection')),
+                Yii::app()->createUrl('zurmo/ldap/testConnection/', array()),
+                static::resolveAjaxOptionsForTestLdapConnection($this->form->getId()),
+                array('id' => 'TestLdapConnectionButton', 'class' => 'LdapTestingButton z-button')
+            );
+            $content .= '</span>';
+            return $content;
+        }
+
+        protected static function resolveAjaxOptionsForTestLdapConnection($formId)
+        {
+            assert('is_string($formId)');
+            $title               = Yii::t('Default', 'Test Connection Results');
+            $ajaxOptions         = ModalView::getAjaxOptionsForModalLink($title);
+            $ajaxOptions['type'] = 'POST';
+            $ajaxOptions['data'] = 'js:$("#' . $formId . '").serialize()';
+            return $ajaxOptions;
+        }
+    }
+?>

File app/protected/modules/zurmo/forms/ldap/LdapConfigurationForm.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Form to all editing and viewing of Ldap Configuration values in the user interface.
+     */
+    class LdapConfigurationForm extends ConfigurationForm
+    {
+        public $host;
+        public $port = 389;
+        public $bindRegisteredDomain;
+        public $bindPassword;
+        public $baseDomain;		
+        public $testConnection;
+        public $enabled;
+		
+        public function rules()
+        {
+            return array(
+                array('host',                              'required'),
+                array('host',                              'type',      'type' => 'string'),
+                array('host',                              'length',    'min'  => 1, 'max' => 64),
+                array('port',                              'required'),
+                array('port',                              'type',      'type' => 'integer'),
+                array('port',                              'numerical', 'min'  => 1),
+                array('bindRegisteredDomain',              'required'),
+                array('bindRegisteredDomain',              'type',      'type' => 'string'),
+                array('bindRegisteredDomain',              'length',    'min'  => 1, 'max' => 64),
+                array('bindPassword',                      'required'),
+                array('bindPassword',                      'type',      'type' => 'string'),
+                array('bindPassword',                      'length',    'min'  => 1, 'max' => 64),
+                array('baseDomain',                        'required'),
+                array('baseDomain',                        'type',      'type' => 'string'),
+                array('baseDomain',                        'length',    'min'  => 1, 'max' => 64),
+                array('enabled',                           'boolean'),
+            );
+        }
+
+        public function attributeLabels()
+        {
+            return array(
+                'host'                                 => Yii::t('Default', 'Host'),
+                'port'                                 => Yii::t('Default', 'Port'),
+                'bindRegisteredDomain'                 => Yii::t('Default', 'Username'),
+                'bindPassword'                         => Yii::t('Default', 'Password'),
+                'baseDomain'                           => Yii::t('Default', 'Base Domain'),
+                'enabled'                              => Yii::t('Default', 'Turn On Ldap')
+            );
+        }
+    }
+?>

File app/protected/modules/zurmo/tests/unit/walkthrough/LdapConfigurationSuperUserWalkthroughTest.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Testing the views for configuring Ldap server
+     */
+    class LdapConfigurationSuperUserWalkthroughTest extends ZurmoWalkthroughBaseTest
+    {
+        public static function setUpBeforeClass()
+        {
+            parent::setUpBeforeClass();
+            SecurityTestHelper::createSuperAdmin();
+            $super = User::getByUsername('super');
+            Yii::app()->user->userModel = $super;
+        }
+
+        public function testSuperUserAllDefaultControllerActions()
+        {
+            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
+            $this->runControllerWithNoExceptionsAndGetContent('zurmo/ldap/configurationEditLdap');
+        }
+        
+
+        public function testSuperUserModifyLdapConfiguration()
+        {
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet())
+            {
+                $this->markTestSkipped(Yii::t('Default', 'Test Ldap settings are not configured in perInstanceTest.php file.'));
+            } 
+            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');           
+            //Change Ldap settings            
+            $this->resetGetArray();
+            $this->setPostArray(array('LdapConfigurationForm' => array(
+                                      'host'                  =>
+                                      Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapHost'],
+                                      'port'                  => 
+                                      Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapPort'],
+                                      'bindRegisteredDomain'  => 
+                                      Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBindRegisteredDomain'],
+                                      'bindPassword'          => 
+                                      Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBindPassword'],
+                                      'baseDomain'            => 
+                                      Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBaseDomain'],
+                                      'enabled'               => 
+                                      Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapEnabled'])));
+            $this->runControllerWithRedirectExceptionAndGetContent('zurmo/ldap/configurationEditLdap');
+            $this->assertEquals('Ldap Configuration saved successfully.', Yii::app()->user->getFlash('notification'));
+
+            //Confirm the setting did in fact change correctly
+            $authenticationHelper = new ZurmoAuthenticationHelper;
+            $this->assertEquals(Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapHost'],                  
+                                Yii::app()->authenticationHelper->ldapHost);
+            $this->assertEquals(Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapPort'],
+                                Yii::app()->authenticationHelper->ldapPort);
+            $this->assertEquals(Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBindRegisteredDomain'],  
+                                Yii::app()->authenticationHelper->ldapBindRegisteredDomain);
+            $this->assertEquals(Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBindPassword'],          
+                                Yii::app()->authenticationHelper->ldapBindPassword);
+            $this->assertEquals(Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapBaseDomain'],            
+                                Yii::app()->authenticationHelper->ldapBaseDomain);
+            $this->assertEquals(Yii::app()->params['authenticationTestSettings']['ldapSettings']['ldapEnabled'],
+                                Yii::app()->authenticationHelper->ldapEnabled);
+        }
+        
+        /*
+        *@depends testSuperUserModifyLdapConfiguration 
+        */
+        public function testSuperUserTestLdapConnection()
+        {
+            if (!ZurmoTestHelper::isAuthenticationLdapTestConfigurationSet())
+            {
+                $this->markTestSkipped(Yii::t('Default', 'Test Ldap settings are not configured in perInstanceTest.php file.'));
+            } 
+            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
+            //check Ldap connection         
+            $this->resetGetArray();
+            $this->setPostArray(array('LdapConfigurationForm' => array(
+                                      'host'                              => Yii::app()->authenticationHelper->ldapHost,
+                                      'port'                              => Yii::app()->authenticationHelper->ldapPort,
+                                      'bindRegisteredDomain'              => Yii::app()->authenticationHelper->ldapBindRegisteredDomain,
+                                      'bindPassword'                      => Yii::app()->authenticationHelper->ldapBindPassword,
+                                      'baseDomain'                        => Yii::app()->authenticationHelper->ldapBaseDomain,
+                                      'enabled'                           => Yii::app()->authenticationHelper->ldapEnabled)));
+            $content = $this->runControllerWithNoExceptionsAndGetContent('zurmo/ldap/testConnection');            
+            $this->assertTrue(strpos($content, "Successfully Connected to Ldap Server") > 0);                  
+        }
+    }
+?>

File app/protected/modules/zurmo/utils/LdapUtil.php

+<?php
+
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+     
+     /**
+     * Helper class to create a connection object and test connection for Ldap.
+     */
+    class LdapUtil
+    {        
+        /**
+         * Given an host and port, a LdapConnection is created and returned.
+         * @param string $host
+         * @param string $port
+         * @return bool $ldapConnection
+         */
+        public static function makeConnection($host,$port)
+        {  
+            assert('is_string($host)');
+            assert('is_int($port)');        
+            $ldapConnection = ldap_connect($host,$port);            
+            LDAP_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3);
+            LDAP_set_option($ldapConnection, LDAP_OPT_REFERRALS, 0); 
+            return $ldapConnection;                         
+        }
+        
+        /**
+         * Send a connection Request.  Can use to determine if the Ldap settings are configured correctly.
+         * @param ZurmoAuthenticationHelper $zurmoAuthenticationHelper
+         * @param server $host
+         * @param username $bindRegisteredDomain
+         * @param password $bindPassword, 
+         * @param base domain $baseDomain		 
+         */ 
+        public static function establishConnection($host, $port, $bindRegisteredDomain, $bindPassword, $baseDomain)
+        {	
+            assert('is_string($host)');
+            assert('is_int($port)');
+            assert('is_string($bindRegisteredDomain)');
+            assert('is_string($bindPassword)');
+            assert('is_string($baseDomain)');            			
+            $ldapConnection = self::makeConnection($host,$port);
+            //checking user type
+            $bindRegisteredDomain = 'cn='.$bindRegisteredDomain.','.$baseDomain; //for admin access
+            // bind with appropriate dn to give update access
+            if (@ldap_bind($ldapConnection, $bindRegisteredDomain, $bindPassword))  
+            {
+               return $ldapConnection;
+            } 
+            else 
+            { 
+               return false;
+            }                			   				
+        }
+    }

File app/protected/modules/zurmo/views/ldap/LdapConfigurationEditAndDetailsView.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * Edit and details view for the Ldap Configuration view.
+     */
+    class LdapConfigurationEditAndDetailsView extends EditAndDetailsView
+    {
+        public function getTitle()
+        {
+            return Yii::t('Default', 'Ldap Configuration');
+        }
+
+        public static function getDefaultMetadata()
+        {
+            $metadata = array(
+                'global' => array(
+                    'toolbar' => array(
+                        'elements' => array(
+                            array('type' => 'ConfigurationLink'),
+                            array('type' => 'SaveButton',    'renderType' => 'Edit'),
+                            array('type' => 'EditLink',      'renderType' => 'Details'),
+                        ),
+                    ),
+                    'panelsDisplayType' => FormLayout::PANELS_DISPLAY_TYPE_ALL,
+                    'panels' => array(
+                        array(                            
+                            'rows' => array(
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'host', 'type' => 'Text'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'port', 'type' => 'Integer'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'bindRegisteredDomain', 'type' => 'Text'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'bindPassword', 'type' => 'Password'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'baseDomain', 'type' => 'Text'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'enabled', 'type' => 'CheckBox'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                                array('cells' =>
+                                    array(
+                                        array(
+                                            'elements' => array(
+                                                array('attributeName' => 'testConnection',
+                                                      'type' => 'TestLdapConnection'),
+                                            ),
+                                        ),
+                                    )
+                                ),
+                            ),
+                        ),
+                    ),
+                ),
+            );
+            return $metadata;
+        }
+    }
+?>

File app/protected/modules/zurmo/views/ldap/TestLdapConnectionView.php

+<?php
+    /*********************************************************************************
+     * Zurmo is a customer relationship management program developed by
+     * Zurmo, Inc. Copyright (C) 2012 Zurmo Inc.
+     *
+     * Zurmo is free software; you can redistribute it and/or modify it under
+     * the terms of the GNU General Public License version 3 as published by the
+     * Free Software Foundation with the addition of the following permission added
+     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
+     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
+     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
+     *
+     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
+     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+     * details.
+     *
+     * You should have received a copy of the GNU General Public License along with
+     * this program; if not, see http://www.gnu.org/licenses or write to the Free
+     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+     * 02110-1301 USA.
+     *
+     * You can contact Zurmo, Inc. with a mailing address at 113 McHenry Road Suite 207,
+     * Buffalo Grove, IL 60089, USA. or at email address contact@zurmo.com.
+     ********************************************************************************/
+
+    /**
+     * View used to render message content as a result of test connection for Ldap server.  This is rendered in a modal window.
+     */
+    class TestLdapConnectionView extends View
+    {
+        protected $message;
+
+        public function __construct($message)
+        {
+            assert('is_string($message)');
+            $this->message = $message;
+        }
+
+        protected function renderContent()
+        {
+            $this->setCssClasses(array_merge($this->getCssClasses(), array('connection-test-message')));
+            return nl2br($this->message);
+        }
+    }
+?>