CAS簡介
SSO 單點登錄,是企業爲了解決在相互信任的系統上實現一次登錄的解決方案。SSO將一個企業內部所有域中的用戶登錄和用戶帳號管理集中到一起,SSO的好處顯而易見:
- 減少用戶在不同系統中登錄耗費的時間,減少用戶登錄出錯的可能性;
- 實現安全的同時避免了處理和保存多套系統用戶的認證信息;
- 減少了系統管理員增加、刪除用戶和修改用戶權限的時間;
- 增加了安全性:系統管理員有了更好的方法管理用戶,包括可以通過直接禁止和刪除用戶來取消該用戶對所有系統資源的訪問權限。
開源的企業級單點登錄解決方案。
CAS Server 爲需要獨立部署的 Web 應用。
CAS Client 支持非常多的客戶端(這裏指單點登錄系統中的各個 Web 應用),包括 Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。
CAS架構
php接入CAS
1 使用composer安裝
composer require apereo/phpcas
2.tp5使用phpcas
use \phpCAS;
use think\facade\Config;
class Auth
{
/**
* 公司用戶CAS登錄
*/
public function loginCas()
{
// Full Hostname of your CAS Server
$cas_host = Config::get('cas_host');
// Context of the CAS Server
$cas_context = Config::get('cas_context');
// Port of your CAS server. Normally for a https server it's 443
$cas_port = Config::get('cas_port');
// Enable debugging
phpCAS::setDebug();
// Initialize phpCAS
phpCAS::client(CAS_VERSION_3_0, $cas_host, $cas_port, $cas_context);
// 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();
phpCAS::forceAuthentication();
//檢查是否登錄
if(phpCAS::checkAuthentication()){
//獲取登陸的用戶名
$username = phpCAS::getUser();
}
}
}
3.注意事項
- phpCAS::client(CAS_VERSION_3_0, $cas_host, $cas_port, $cas_context)
- 其中四個參數根據CAS服務端進行配置