safire-ac-za / simplesamlphp-module-sqlattribs
SimpleSAMLphp模块,用于从SQL数据库提供额外的属性
Requires
- php: ^8.0
- ext-pdo: ^8.0
- simplesamlphp/assert: ^0.8.0 || ^1.0.0
Requires (Dev)
- simplesamlphp/simplesamlphp: >=2.0.0 <2.3.0
- simplesamlphp/simplesamlphp-test-framework: ^1.5.1
Suggests
- ext-mysql: Needed if a MySQL backend is used
- ext-pgsql: Needed if a PostgreSQL backend is used
This package is auto-updated.
Last update: 2024-09-05 06:31:44 UTC
README
这个SimpleSAMLphp认证进程过滤器允许您从SQL数据存储提供额外的属性。当您的原始认证源是一个您无法直接控制的目录(例如AD)时,此功能非常有用,您需要为特定用户添加额外的属性,但不能将它们添加到目录/修改模式。
安装
一旦您安装了SimpleSAMLphp,安装此模块非常简单。只需在SimpleSAMLphp安装根目录中执行以下命令:
composer.phar require safire-ac-za/simplesamlphp-module-sqlattribs:dev-master
其中 dev-master
指示Composer从Git存储库安装master
(开发)分支。如果您想使用模块的稳定版本,请查看发布版。
然后您需要在您的SQL数据库中创建以下表:
CREATE TABLE IF NOT EXISTS `AttributeFromSQL` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `uid` VARCHAR(100) NOT NULL, `sp` VARCHAR(250) DEFAULT '%', `attribute` VARCHAR(30) NOT NULL, `value` TEXT, `expires` DATE DEFAULT '9999-12-31', PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8;
注意:如果您是从v1.2或更早版本升级,您需要对现有的数据库进行以下更改:
ALTER TABLE `AttributeFromSQL` ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id); ALTER TABLE `AttributeFromSQL` ADD `expires` DATE DEFAULT '9999-12-31';
使用方法
此模块提供sqlattribs:AttributeFromSQL认证进程过滤器,可按以下方式使用:
50 => [ 'class' => 'sqlattribs:AttributeFromSQL', 'identifyingAttribute' => 'eduPersonPrincipalName', 'limit' => ['eduPersonEntitlement', 'eduPersonAffiliation'], 'replace' => false, 'database' => [ 'dsn' => 'mysql:host=localhost;dbname=simplesamlphp', 'username' => 'yourDbUsername', 'password' => 'yourDbPassword', 'table' => 'AttributeFromSQL', ], ],
参数如下:
-
class
- 类名,必须是sqlattribs:AttributeFromSQL -
identifyingAttribute
- 作为数据库搜索的uid/键使用的属性,如果没有指定,则默认为eduPersonPrincipalName。 -
limit
- 可选数组,指定可以添加的属性名称。如果没有指定,则添加在数据库中找到的所有属性。默认允许添加所有属性。 -
replace
- 遇到同名的现有属性时的行为。如果为false
(默认值),则将新值推入数组,创建多值属性。如果为true
,则替换(删除)同名的现有属性。 -
ignoreExpiry
- 忽略任何过期日期(默认情况下,忽略expires
列中日期过期的属性)。 -
database
- 包含有关数据存储信息的数组,具有以下参数:-
dsn
- 数据源名称,默认为mysql:host=localhost;dbname=simplesamlphp -
username
- 连接到数据库的用户名,默认为无(空用户名) -
password
- 连接到数据库的密码,默认为无(空密码) -
table
- 用于搜索属性的表/视图的名称,默认为AttributeFromSQL -
driver_options
- 传递给PDO构造函数的附加驱动程序特定的连接选项
-
添加属性
此模块不提供将属性添加到数据库的界面。可以通过以下类似的SQL手动完成此操作:
INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', '%', 'eduPersonEntitlement', 'urn:mace:exampleIdP.org:demoservice:demo-admin'); INSERT INTO AttributeFromSQL (uid, sp, attribute, value) VALUES ('user@example.org', 'https://idp.example.org/idp/shibboleth', 'eduPersonEntitlement', 'urn:mace:grnet.gr:eduroam:admin'); INSERT INTO AttributeFromSQL (uid, sp, attribute, value, expires) VALUES ('user@example.org', '%', 'eduPersonAffiliation', 'faculty', '2020-12-31'); INSERT INTO AttributeFromSQL (uid, attribute, value) VALUES ('user@example.org', 'mail', 'user@example.org');
可选的sp字段(默认值为与上述SQL CREATE一起的%
)用于限制特定SP可以看到哪些属性。特殊值%
用于表示所有SP。如果您想表示多个SP但不是所有SP,插入多行。
当出现同名多个属性时,这些属性将成为一个多值属性。因此,假设用户user@example.org最初具有以下属性:
$attributes = [ 'eduPersonPrincipalName' => 'user@example.org', 'eduPersonAffiliation' => ['member'], 'displayName' => 'Example User', ],
上述SQL表和示例认证过程过滤器将导致组合属性集为
$attributes = [ 'eduPersonPrincipalName' => 'user@example.org', 'displayName' => 'Example User', 'eduPersonEntitlement' => [ 'urn:mace:exampleIdP.org:demoservice:demo-admin', 'urn:mace:grnet.gr:eduroam:admin', ], 'eduPersonAffiliation' => [ 'member', 'faculty', ], ],
请注意,由于limit
参数,没有添加邮件属性。并且由于replace
为false,eduPersonAffiliation被合并。假设此服务提供者(SP)的实体ID为https://sp.example.org/shibboleth-sp
- 其他SP将不会看到特定于SP的eduPersonEntitlement属性。