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项目的配置,不是都能在Project -- Properties里设置解决的
现象:死活解决不了引入外部库的LPCWSTR参数传递问题.而用VS新建的项目,就没有这个问题. 我怀疑是当初.pro文件产生VC项目文件时候,做了一些设置,但是内容太长了,又很复杂,所以没法核对. 用 ...
- logstash 处理tomcat catalina.out
input { file { type => "zj_api" path => ["/data01/applog_backup/zjzc_log/zj-api ...
- Spark RDD Union
示例 Spark多个RDD(数据格式相同)“组合”为一个RDD 代码 from pyspark import SparkConf, SparkContext conf = SparkCon ...
- Spark处理Json格式数据(Python)
前言 Spark能够自动推断出Json数据集的“数据模式”(Schema),并将它加载为一个SchemaRDD实例.这种“自动”的行为是通过下述两种方法实现的: jsonFile:从一个文件目 ...
- Hadoop Compression
文件压缩主要有两方面的好处:一方面节省文件存储空间:另一方面加速网络数据传输或磁盘读写.当处理大规模的数据时这些效果提升更加明显,因此我们需要仔细斟酌压缩在Hadoop环境下的使用. 目前已经存在 ...
- DOL版USB Loader的下载和运行
下载 在Wii上面玩硬盘版游戏,自然少不了USB Loader,相关教程和下载资源在网上一搜就有. 我在官网(地址:http://gwht.wikidot.com/usb-loader)上找到了一个下 ...
- des加密解密源码 C# key值问题
公司协议安全需求.需要对传输内容做des.md5加密. 因为是新人.刚交给我这个任务的时候有点眩晕.就开始在网上找各种des加密的内容.因为不懂以为需要把原理也搞明白,最后误了时间.把自己也搞糊涂了. ...
- selenium webdriver python 开始
学习资料: Selenium with Python: http://selenium-python.readthedocs.org/en/latest/index.html 乙醇的python se ...
- Objective-C中变量采用@property的各个属性值的含义
我们在OC中定义变量,可以自己来定义变量的setter方法来设置变量值,用getter方法来获取变量值.但是当变量数量增多时,还采用手动添加setter/getter方法来操作变量,就会使得程序代码量 ...
- 八、频繁模式挖掘Frequent Pattern Mining
频繁模式挖掘(Frequent Pattern Mining): 频繁项集挖掘是通常是大规模数据分析的第一步,多年以来它都是数据挖掘领域的活跃研究主题.建议用户参考维基百科的association r ...