1.首先下載禪道的源碼,如今最新版本的是6.4的版本,我測試的時候是在windows下面測試的,使用WAMPSERVER做爲PHP的集成環境,服務端口爲80,另外開啓一個Tomcat服務,部署CAS SERVER應用,端口爲8080。php
2.在zentaopms\module中添加一個sso模塊。就是添加一個sso的文件夾。html
2.因爲禪到8.X後存在sso模塊,爲了避免影響原系統,因此在zentaopms\module中添加一個cas模塊。就是添加一個cas的文件夾。git
3.而後cas php client,下載地址http://downloads.jasig.org/cas-clients/php/current/,新的下載地址https://github.com/Jasig/phpCAS/releases拷貝壓縮文件中CAS文件夾和CAS.php文件到sso目錄。以下圖,(若是運行過,就會產生phpCAS.log是因爲CAS client 開啓了debug生成的,生產環境建議不要配置,建議調試的時候能夠配置該屬性)。github
4.建立control.php文件(zentaopms\module\cas\control.php),能夠修改代碼中的配置文件,$cas_host的地址(也就是代碼中的localhost),代碼以下:windows
<?php require_once 'CAS.php'; class cas extends control { public function login() { // Enable debugging phpCAS::setDebug(); // Initialize phpCAS // phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context); phpCAS::client(CAS_VERSION_2_0, "localhost", 8080, "/cas"); // For production use set the CA certificate that is the issuer of the cert // on the CAS server and uncomment the line below // phpCAS::setCasServerCACert($cas_server_ca_cert_path); // For quick testing you can disable SSL validation of the CAS server. // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION. // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL! phpCAS::setNoCasServerValidation(); // force CAS authentication phpCAS::forceAuthentication(); // at this step, the user has been authenticated by the CAS server // and the user's login name can be read with phpCAS::getUser(). // logout if desired if (isset($_REQUEST['logout'])) { phpCAS::logout(); } // 經過修改的casLogin函數受權 //-------------------------------------start------------------------------------- $account = phpCAS::getUser(); $location = "http://localhost/zentaopms/www/index.php?m=index&f=index"; // 獲取用戶信息 $user = $this->loadModel('user')->getById($account); if($user) { $this->user->cleanLocked($user->account); /* Authorize him and save to session. */ $user->rights = $this->user->authorize($account); $user->groups = $this->user->getGroups($account); $this->dao->update(TABLE_USER)->set('visits = visits + 1')->set('ip')->eq($userIP)->set('last')->eq($last)->where('account')->eq($user->account)->exec(); $this->session->set('user', $user); $this->app->user = $this->session->user; $this->loadModel('action')->create('user', $user->id, 'login'); if (isset($_REQUEST['referer'])) { $this->locate($_REQUEST['referer']); } else { // 跳轉頁面到index頁面或者referer頁面 $this->locate($location); } } else { echo "用戶".$account."不存在,請聯繫管理員申請用戶。"; } //-------------------------------------end------------------------------------- } public function logout() { phpCAS::logout(); } } ?>
5.修改該頁面的權限,建立zentaopms\module\common\ext\model\cas.php文件,若是沒有這個文件,就沒法調轉到SSO的認證頁面,系統自己會攔截請求,跳轉到禪道的登陸頁面,添加了該文件以後,就能夠跳轉到CAS SERVER的登陸頁面,使用cas單點登陸了。代碼以下session
<?php public function isOpenMethod($module, $method) { if($module == 'cas') return true; return parent::isOpenMethod($module, $method); }
6.測試配置效果,打開 http://localhost/zentaopms/www/index.php?m=cas&f=login(禪道8.X之後能夠訪問http://localhost/zentaopms/www/cas-login.html),查看是否跳轉到指定的CAS Server 的登陸頁面,登陸成功以後是否能正常跳轉到禪道的主頁頁面。app
sso認證地址http://localhost/zentaopms/www/index.php?m=cas&f=login
sso註銷地址http://localhost/zentaopms/www/index.php?m=cas&f=login&logout
認證經過以後的地址爲:http://localhost/zentaopms/www/index.php?m=index&f=index函數