Laravel5中集成Jasig cas统一认证系统
CAS : CAS(Central Authentication Service)是一款不错的针对 Web 应用的单点登录框架,这里介绍下我刚在laravel5上搭建成功的cas。提前准备工作:可运行的laravel5的工程,cas的服务器端已经存在。
环境:Linux(ubuntu)
一,下载phpcas源代码。
在laravel5的项目app目录下创建library目录,下载phpcas库,git clone https://github.com/Jasig/phpCAS.git,clone下来是一个phpcas的文件目录。
二,创建provider
在app下创建目录cas,创建CasAuthProvider.php,内容如下:
<?php namespace cas; use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\GenericUser; class CasAuthProvider implements UserProvider { /**
* Retrieve a user by their unique identifier.
*
* @param mixed $id
* @return \Illuminate\Auth\UserInterface|null
*/
public function retrieveById($id) {
return $this->casUser();
} /**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Auth\UserInterface|null
*/
public function retrieveByCredentials(array $credentials) {
return $this->casUser();
} /**
* Validate a user against the given credentials.
*
* @param \Illuminate\Auth\UserInterface $user
* @param array $credentials
* @return bool
*/
public function validateCredentials(Authenticatable $user, array $credentials) {
return true;
} protected function casUser() {
$cas_host = \Config::get('app.cas_host');
//dump($cas_host);
$cas_context = \Config::get('app.cas_context');
$cas_port = \Config::get('app.cas_port');
\phpCAS::setDebug();
\phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context);
\phpCAS::setNoCasServerValidation(); if (\phpCAS::isAuthenticated()) {
$attributes = array(
'id' => \phpCAS::getUser(),
'name' => \phpCAS::getUser()
);
return new GenericUser($attributes);
} else {
//\phpCAS::setServerURL(\Config::get('app.url'));
\phpCAS::forceAuthentication();
}
return null;
} /**
* Needed by Laravel 4.1.26 and above
*/
public function retrieveByToken($identifier, $token) {
return new \Exception('not implemented');
} /**
* Needed by Laravel 4.1.26 and above
*/
public function updateRememberToken(Authenticatable $user, $token) {
return new \Exception('not implemented');
} } ?>
三,修改config
在config/app.php中添加如下三个配置项:
'cas_host'=>'****', //认证服务器
'cas_context'=>'',//还没弄明白是什么
'cas_port'=>000,//认证服务端口
'url'=>'http://localhost/',
四,加载认证库
在app/providers/AppServiceProvider.php里,在类AppServiceProvider的register函数里添加认证方式:
Auth::extend('cas', function($app) {
return new CasAuthProvider;
});
修改app/config/auth.php认证driver:'driver' => 'cas',
在composer.json里配置加载项,在autoload里的classmap中添加如下路径:
"autoload": {
"classmap": [
**************
"app/library",
"app/library/phpCAS",
"app/cas"
]
}
在项目根目录下执行:composer dump-autoload
五,实现
在app/http/controllers/下创建CasAuthController.php,添加login和logout方法:
public function login() {
$message_error = "";
if (Auth::check()) {
} else {
if (Auth::attempt(array())) {
// Redirect to link after login
}
// Redirect to un-logged in page
}
dump(\phpCAS::getUser());
dump(Auth::user());
}
public function logout() {
$cas_host = \Config::get('app.cas_host');
//dump($cas_host);
$cas_context = \Config::get('app.cas_context');
$cas_port = \Config::get('app.cas_port');
\phpCAS::setDebug();
\phpCAS::client(CAS_VERSION_2_0, $cas_host, $cas_port, $cas_context);
\phpCAS::setNoCasServerValidation();
\phpCAS::logoutWithRedirectService(\Config::get('app.url'));
}
在routes.php里添加路由规则就OK了,把项目默认的登陆和注销方法指到这里来,当login的时候,会出现服务器的登陆页面。
有个问题,就是这么改动之后,原来我设置的不需要登陆就能浏览的页面,现在进入的时候也会跳出登陆页面,不知道为什么,希望高手指导下,谢谢!
参考:https://sonnguyen.ws/how-to-integrate-phpcas-in-laravel/
Laravel5中集成Jasig cas统一认证系统的更多相关文章
- CAS统一认证系统学习
Yale CAS(耶鲁集中认证服务)简介 http://www.5iops.com/html/2012/sso_0713/181.html 单点登陆框架CAS的研究 http://www.cnblog ...
- #研发解决方案介绍#IdCenter(内部统一认证系统)
郑昀 基于朱传志的设计文档 最后更新于2014/11/13 关键词:LDAP.认证.权限分配.IdCenter. 本文档适用人员:研发 曾经一个IT内部系统配一套帐号体系和授权 线上生产环境里 ...
- 云方案,依托H3C彩虹云存储架构,结合UIA统一认证系统,实现了用户数据的集中存储和管理
客户的声音 资料云项目在迷你云基础上二次开发,通过使用云存储技术及文件秒传技术,对文件进行统一存储与管理,以达到节约文件管理成本.存储成本目的:通过有效的文件版本控制机制,以达到风险管控的目的:通过多 ...
- 金瓯无缺江河一统|Win10系统基于Docker和Python3搭建并维护统一认证系统OpenLdap
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_180 OpenLdap(Lightweight Directory Access Protocol)是什么?它其实是一个开源的.具 ...
- 集成基于CAS协议的单点登陆
相信大家对单点登陆(SSO,Single Sign On)这个名词并不感到陌生吧?简单地说,单点登陆允许多个应用使用同一个登陆服务.一旦一个用户登陆了一个支持单点登陆的应用,那么在进入其它使用同一单点 ...
- [原创]django+ldap实现统一认证部分一(django-auth-ldap实践)
前言 接之前我的文章,django+ldap+memcache实现单点登录+统一认证 ,ldap部署相关,ldap双机\LAM配置管理\ldap备份还原,目前来说,我们已经有了高可用性的ldap环境了 ...
- 中国科学技术大学统一身份认证系统CAS
CAS | Apereohttps://www.apereo.org/projects/cas 中国科学技术大学统一身份认证系统https://passport.ustc.edu.cn/login?s ...
- cas单点登录系统:客户端(client)详细配置(包含统一单点注销配置)
最近一直在研究cas登录中心这一块的应用,分享一下记录的一些笔记和心得.后面会把cas-server端的配置和重构,另外还有这几天再搞nginx+cas的https反向代理配置,以及cas的证书相关的 ...
- [原]CAS和Shiro在spring中集成
shiro是权限管理框架,现在已经会利用它如何控制权限.为了能够为多个系统提供统一认证入口,又研究了单点登录框架cas.因为二者都会涉及到对session的管理,所以需要进行集成. Shiro在1.2 ...
随机推荐
- VC++大数据量绘图时无闪烁刷屏技术实现(我的理解是,在内存上作画,然后手动显示,而不再直接需要经过WM_PAINT来处理了)
http://hantayi.blog.51cto.com/1100843/383578 引言 当我们需要在用户区显示一些图形时,先把图形在客户区画上,虽然已经画好但此时我们还无法看到,还要通过 程序 ...
- linux wenjian
文件锁是一种文件读写机制,在任何特定的时间只允许一个进程访问一个文件.利用这种机制能够使读写单个文件的过程变得更安全. 在这篇文章中,我们将探讨Linux中不同类型的文件锁,并通过示例程序来理解它们之 ...
- COJ 3018 求1~n之间的素数
求1~n之间的素数 难度级别:A: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 素数是大于1,且除1和本身以外不能被其他整数所整除的数. ...
- DateTime用法二
任何项目,难免会碰到DateTime的显示问题,.net框架虽提供丰富多样的显示方法,但我很少使用,因老忘记细节,每次都要纠结到底月份在前还是年份在前:日期分隔符到底是“/”,还是“\”,还是“-”等 ...
- HDOJ(HDU) 1859 最小长方形(水题、、)
Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- Linux网卡驱动架构分析
一.网卡驱动架构 由上到下层次依次为:应用程序→系统调用接口→协议无关接口→网络协议栈→设备无关接口→设备驱动. 二.重要数据结构 1.Linux内核中每一个网卡由一个net_device结构来描述. ...
- 1036 : Trie图 (AC自动机)
题目大意: 输入 n 个目标单词和一个文本串,判断文本串中是否存在某些目标单词. 思路 赤裸裸的 AC自动机. 代码: #include<iostream> #include<cst ...
- 自定义UINavigationItem的两种方法以及相应的隐藏方法
第一种: UIImage *searchimage=[UIImage imageNamed:@"search.png"]; UIBarButtonItem *barbtn=[[[U ...
- ubuntu进入命令登录界面
按ctrl+alt+F1或者ctrl+alt+F2进入系统终端,可以以命令行界面登录系统.