ivan-novakov / zfc-shib
Zend Framework 2 的 Shibboleth 认证
1.1.0
2013-11-28 15:35 UTC
Requires
- php: >=5.3.3
- zendframework/zend-authentication: 2.*
- zendframework/zend-loader: 2.*
- zendframework/zend-modulemanager: 2.*
This package is not auto-updated.
Last update: 2024-09-23 14:21:14 UTC
README
该模块提供 Shibboleth 认证作为标准 Zend Framework 2 认证适配器。
需求
- Shibboleth SP 实例 - 已配置并运行,以将用户属性作为环境变量提供给目标应用程序
安装
推荐的安装方法是通过 composer
php composer.phar require ivan-novakov/zfc-shib:1.*
您可以将它用作 ZF2 MVC 应用程序中的 ZF2 模块,或者只是作为任何其他类型应用程序中的库。如果要将它用作模块,请将模块名称 'ZfcShib' 添加到您的应用程序配置中。
基本用法
适配器接受以下配置选项
id_attr_name
(必需) - 包含用户身份的属性的名称,例如eppn
user_attr_names
(可选) - 要提取并添加到结果用户身份的用户属性名称列表。如果未指定,将添加所有默认属性。system_attr_names
(可选) - 要提取并添加到结果用户身份的系统属性名称列表(例如Shib-Identity-Provider
)。如果未指定,将添加所有默认属性。
示例
$adapter = new \ZfcShib\Authentication\Adapter\Shibboleth(array( 'id_attr_name' => 'eppn', 'user_attr_names' => array( 'eppn', 'cn', 'mail' ) )); $result = $adapter->authenticate(); if ($result->isValid()) { $identity = $result->getIdentity(); }
$identity
数组将包含两个子数组
system
- 包含系统属性user
- 包含所需用户属性eppn
、cn
和mail
。
$identity
变量将包含
Array
(
[system] => Array
(
[Shib-Application-ID] => default
[Shib-Identity-Provider] => https://idp.example.org/idp/shibboleth
[Shib-Authentication-Instant] => 2013-05-13T13:40:45.687Z
[Shib-Authentication-Method] => urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
[Shib-AuthnContext-Class] => urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
[Shib-Session-Index] => cfe418967cd195e568ac000f57234bc287ecb5532365aa46c893d6e7f34300f0
)
[user] => Array
(
[eppn] => test@example.org
[cn] => Test User
[mail] => test.user@example.org
)
)
替代身份容器
默认情况下,身份以数组形式返回。但您可以使适配器返回最适合您的格式的身份。如果将身份工厂对象作为适配器构造函数的第三个参数传递,它将被用于创建身份。该工厂必须实现 ZfcShib\Authentication\Identity\IdentityFactoryInterface
并具有 createIdentity()
方法,该方法接收身份数据值对象作为参数,并应返回结果身份。
use ZfcShib\Authentication\Identity; class MyIdentityFactory implements IdentityFactoryInterface { public function createIdentity(Identity\Data $identityData) { return new MyUser($identityData->getUserData()); } } $identityFactory = new MyIdentityFactory(); $adapter = new \ZfcShib\Authentication\Adapter\Shibboleth($options, null, $identityFactory);
模拟适配器
如果您需要开发和测试您的应用程序,但没有可用的运行中的 Shibboleth SP,可以使用 ZfcShib\Authentication\Adapter\Dummy
适配器,该适配器模拟 Shibboleth 适配器的功能。只需将所有模拟用户和系统数据传递给构造函数,并使用适配器代替“真实”适配器即可
use ZfcShib\Authentication\Adapter; $dummyOptions = array( 'user_data' => array( 'uid' => 'foo', 'cn' => 'Foo Bar', 'mail' => 'foo@bar.cz', 'employeeNumber' => 123456 ), 'system_data' => array( 'Shib-Application-ID' => 'default' ) ); $dummy = new Adapter\Dummy($dummyOptions, null, new MyUserFactory());