83713

#分享# 禅道开源版6.4版本与CAS4.0单点登录。

回帖
回帖数 3
阅读数 6539
发表时间 2015-01-27 10:14:54
😎
先知楼主

本篇文章来自开源中国社区博主夜风飘尘的分享。

原文地址:http://my.oschina.net/u/1159248/blog/371422


原文如下:

禅道开源版6.4与CAS4.0单点登录,网上这方面的信息不多,弄了一天,终于可以实现SSO,特地记录一下。


1.首先下载禅道的源码,现在新版本的是6.4的版本,我测试的时候是在windows下面测试的,使用WAMPSERVER作为PHP的集成环境,服务端口为80,另外开启一个Tomcat服务,部署CAS SERVER应用,端口为8080。

2.在zentaopms\module中添加一个sso模块。就是添加一个sso的文件夹。

3.然后cas php client,下载地址http://downloads.jasig.org/cas-clients/php/current/,拷贝压缩文件中CAS文件夹和CAS.php文件到sso目录。如下图,phpCAS.log是由于CAS client 开启了debug生成的。

4.创建control.php文件,可以修改代码中的配置文件,cas_host的地址,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require_once'CAS.php';
 
classssoextendscontrol
{
publicfunctionlogin()
{
// 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-------------------------------------
}
 
publicfunctionlogout()
{
phpCAS::logout();
}
}
?>

5.修改该页面的权限,创建zentaopms\module\common\ext\model\cas.php文件,如果没有这个文件,就无法调转到SSO的认证页面。代码如下

1
2
3
4
5
6
<?php
publicfunctionisOpenMethod($module,$method)
{
if($module=='sso')returntrue;
returnparent::isOpenMethod($module,$method);
}

6.测试配置效果,打开 http://localhost/zentaopms/www/index.php?m=sso&f=login,查看是否跳转到指定的CAS Server 的登录页面,登录成功之后是否能正常跳转到禅道的主页页面。

sso认证地址http://localhost/zentaopms/www/index.php?m=sso&f=login
sso注销地址http://localhost/zentaopms/www/index.php?m=sso&f=login&logout
认证通过之后的地址为:http://localhost/zentaopms/www/index.php?m=index&f=index

3个回复
石洋洋沙发
2015-01-27 11:10:09 石洋洋 回帖
🚗
hailor板凳
8.0.1中已经有SSO文件夹了,要如何在8.0.1开源版本中与CAS集成呢?
2016-01-12 17:02:23 hailor 回帖
这个sso不是做那个用的。:)
2016-01-13 08:13:56 王春生 回帖
联系我们
联系人
刘斌/高级客户经理
电话(微信)
17685869372
QQ号码
526288068
联系邮箱
liubin@chandao.com
相关帖子
返回顶部
客服头像
刘斌
高级客户经理
客服微信
17685869372
526288068
统一服务热线 4006-8899-23
我要提问提问有任何问题,您都可以在这里提问。问题反馈反馈点击这里,让我们聆听您的建议与反馈。