antons / silverstripe-ssp
使用simpleSAMLphp库为Silverstripe 3.1+提供的身份验证模块。
Requires
- php: >=5.3
- composer/installers: *
- openid/php-openid: dev-master#ee669c6a9d4d95b58ecd9b6945627276807694fb as 2.2.2
- silverstripe/framework: 3.1.*
- simplesamlphp/saml2: ~0.3
- simplesamlphp/simplesamlphp: 1.13.2
- simplesamlphp/xmlseclibs: 1.3.2
This package is not auto-updated.
Last update: 2024-09-14 16:29:22 UTC
README
由于SilverStripe Ltd发布了他们自己的SAML身份验证模块 - silverstripe/silverstripe-activedirectory,我不再维护此模块。
此模块是SimpleSAMLphp第三方库的包装,提供联合身份验证。
它用SSPSecurity
控制器替换了Security
控制器,该控制器负责用户身份验证。
注意:这不是一个即插即用的模块!此模块只是一个轻量级的包装,需要配置复杂的SimpleSAMLphp库。
本模块的部分基于silverstripe-labs/silverstripe-shibboleth模块,适用于SilverStripe 2.4。
要求
- SilverStripe 3.1+
- PHP 5.3
- SimpleSAMLphp要求
安装
使用Composer
将模块安装到您的SilverStripe网站根目录中
composer require antons/silverstripe-ssp
模块设置
根据以下说明,根据您特定的环境调整路径/域名。
-
使用以下任何一种方法创建到
vendor/simplesamlphp/simplesamlphp/www
文件夹的链接a. 在您的SilverStripe安装的Apache虚拟主机中创建一个mod_alias指令。将其命名为
simplesaml
并将其指向vendor/simplesamlphp/simplesamlphp/www
文件夹。这是首选方法。<VirtualHost *> ServerName yourdomain.com DocumentRoot /var/www/ss Alias /var/www/ss/simplesaml /var/www/ss/vendor/simplesamlphp/simplesamlphp/www </VirtualHost>
b. 不使用mod_alias,您可以在系统上创建一个符号链接
//Linux + Mac ln -s /var/www/ss/vendor/simplesamlphp/simplesamlphp/www /var/www/ss/simplesaml //Windows mklink /D C:\xampp\htdocs\ss\simplesaml C:\xampp\htdocs\ss\vendor\simplesamlphp\simplesamlphp\www
c. 如果您使用的是共享主机环境且无法访问Apache虚拟配置或直接文件系统,您可以在
mysite/_config.php
文件中添加以下代码,PHP将创建符号链接。if(!file_exists(BASE_PATH . '/simplesaml')) { symlink(realpath(dirname(__FILE__)) . '../vendor/simplesamlphp/simplesamlphp/www', realpath(dirname(__FILE__)) . '/../simplesaml'); }
-
复制默认SimpleSAMLphp配置文件
cd vendor/simplesamlphp/simplesamlphp cp -R config-templates config cp -R metadata-templates metadata
-
按照SimpleSAMLphp服务提供商快速入门文档的第1至5步来设置SimpleSAMLphp。
单一注销服务(SLO)
如果您想设置身份提供者元数据的SingleLogoutService
响应位置,URL为
https://yourdomain.com/Security/loggedout
这是身份提供者正确注销所必需的。
SimpleSAMLphp前端
您应该能够通过https://www.yourdomain.com/simplesaml
访问SimpleSAMLphp的前端。请确保您在SimpleSAMLphp配置文件中为前端设置密码。
向SSPSecurity添加身份验证器
要添加新的身份验证器,创建一个新的类,它扩展SSPAuthenticator
并实现SSPAuthenticator->authenticate()
函数
<?php
class MySSPAuthenticator extends SSPAuthenticator {
public function authenticate() {
$attributes = $this->getAttributes();
//Refer to example authenticators in /silverstripe-ssp/code/authenticators
//SSPSecurity will handle the $member->login() so MySSPAuthenticator->authenticate()
//must return a SilverStripe Member object
return $member;
}
}
一旦您有了新的身份验证器,您现在必须将其添加到您的mysite/_config/config.yml
文件中
# auth_source is the authentication source defined in SimpleSAMLphp
# auth_class is a SSPAuthentication class that uses auth_source for authentication
# You can add multiple authenticators but at least one authenticator must be specified
SSPSecurity:
authenticators:
auth_source: auth_class
为SSPSecurity设置默认身份验证器
SSPSecurity:
authenticators:
auth_source: auth_class
default_authenticator:
auth_source
# You can specify default authenticators depending on what the SilverStripe environment mode is
# If an environment is not specified, the first authenticator specified in SSPSecurity::authenticators is used
SSPSecurity:
authenticators:
auth_source_1: auth_class_1
auth_source_2: auth_class_2
auth_source_3: auth_class_3
default_authenticator:
live:
auth_source_1
test:
auth_source_2
dev:
auth_source_3
登录/注销的URL
SSPSecurity
替换了Security
的登录/注销操作
使用默认身份验证器登录
http://yourdomain.com/Security/login
使用自定义身份验证器登录
http://yourdomain.com/Security/login?as=auth_source_1
注销
http://yourdomain.com/Security/logout
注意
-
本模块覆盖了位于
silverstripe/framework
中的 Security 类,因此默认的 SilverStripe 登录页面不使用。这是设计上的考虑。如果认证源使用 SimpleSAMLphp 作为登录页面,您可以遵循此处的指南来主题化 SimpleSAMLphp。如果您使用的是具有自己登录页面的其他认证源(例如 Google Apps、Microsoft ADFS 等),那么您需要参考该提供者的文档来了解如何主题化。 -
虽然此模块直接与 SimpleSAMLphp 集成,但假设 SimpleSAMLphp 将仅作为 SilverStripe 的服务提供商运行。理论上,您可以将 SimpleSAMLphp 与此模块一起作为身份提供者运行,但这种配置不受支持。
-
本模块支持被动登录(或被动单点登录),但您需要手动启用它。为此,将
SSPSecurity::passive_login();
添加到您的Page_Controller->init()
函数末尾。目前,被动登录只能使用当前 SilverStripe 环境的默认认证器进行身份验证。 -
如果
ContentController
调用了Security::permissionFailure()
函数,用户将被重定向到身份提供者登录页面。 -
如果您的 SilverStripe 配置中的
Session::cookie_secure
设置为TRUE
,则在通过身份提供者进行认证后,您可能会在 SimpleSAMLphp 中收到“State Information Lost”错误。当Session::cookie_secure
设置为TRUE
时,Silverstripe 将将 Cookie 名称从熟悉的PHPSESSID
更改为SECSESSID
。默认情况下,SimpleSAMLphp 寻找的是PHPSESSID
而不是SECSESSID
,这就是为什么 SimpleSAMLphp 丢失会话状态的原因。要修复此问题,您需要对您的vendor/simplesamlphp/simplesamlphp/config/config.php
进行以下更改:$config = array ( 'session.phpsession.cookiename' => 'SECSESSID', 'session.phpsession.httponly' => TRUE, );
许可证
版权所有 (c) 2015,Anton Smith,workSpace,奥塔哥理工学院
在满足以下条件的情况下,允许重新分发和使用源代码和二进制代码,无论是修改后还是未修改的:
-
源代码的重新分发必须保留上述版权声明、本条件列表和以下免责声明。
-
二进制形式的重新分发必须在文档和/或其他与分发一起提供的材料中复制上述版权声明、本条件列表和以下免责声明。
-
未经具体事先书面许可,不得使用 workSpace 的名称或其贡献者的名称来认可或推广源自本软件的产品。
本软件由版权所有者和贡献者提供,“现状”和任何明示或暗示的保证,包括但不限于适销性和针对特定目的的适用性的暗示保证,均予以放弃。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、示范性或后续的损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,无论该损害是否由于本软件的使用或本软件使用的可能性而引起,即使被告知此类损害的可能性。