fillup/zfauthsaml

Zend\Authentication SAML 适配器。使用现有的 simpleSAMLphp 安装。

0.4.1 2013-06-21 12:47 UTC

This package is auto-updated.

Last update: 2024-09-06 08:07:02 UTC


README

目标

本项目的目标是提供一个封装 simpleSAMLphp 的 Zend\Authentication 适配器,以提供 SAML 认证。目前我还不确定是否可以将 simpleSAMLphp 严格用作库,或者它是否需要使用其定义的配置文件等。最初我正在开发适配器以使用现有的已配置的 simpleSAMLphp 实例,然后希望重构以封装库本身,使其完全包含并支持标准的 ZF 应用程序配置策略。

待办事项

  • 实现支持现有的 simpleSAMLphp 安装,并使用 API 检查用户是否已认证,如果已认证则持久化身份信息。
  • 实现支持 BjyAuthorize,根据 SAML 返回的组授予权限或拒绝访问。
  • 将返回 URL 路径移动到配置文件,并启用基于原始请求 URL 的动态返回 URL。
  • 重构用户实体,使其根据 SAML 数据实际填充。
  • 在成功首次登录后实现本地帐户配置。
  • 找到更好的方法来管理角色列表/配置,以防止 SAML 返回尚未配置的组/角色时出错。也许可以支持从 RESTful API 中提取?
  • 进一步抽象用户实体和映射类,以支持用户定义的实体模型,这些模型可以持久化。

需求

如果您对 simpleSAMLphp 或为 ZfcUser 编写扩展/适配器/自定义有专业知识,我将非常乐意得到一些帮助,请通过 github 与我联系。

设置

  1. 更新您的 composer 以要求这些模块(如果尚未要求)
"require": {
    "php": ">=5.3.3",
    "zendframework/zendframework": "~2.2",
    "zf-commons/zfc-user": "dev-master",
    "bjyoungblood/bjy-authorize": "~1.2",
    "fillup/zfauthsaml": "dev-master"
}
  1. vendor/zf-commons/zfc-user/config/zfcuser.global.php.dist 复制到 config/autoload/zfcuser.global.php

  2. 在 zfcuser.global.php 中更改两个设置

$settings = array(
  'user_entity_class' => 'ZfAuthSaml\Entity\User',
  'auth_adapters' => array( 100 => 'ZfAuthSaml\Authentication\Adapter' ),
);
  1. vendor/bjyoungblood/bjy-authorize/config/module.config.php 复制到 config/autoload/module.bjyauthorize.global.php

  2. 在 module.bjyauthorize.global.php 中更改四个设置

return array(
  'identity_provider'  => 'ZfAuthSaml\Provider\Identity\SamlIdentityProvider',
  'role_providers'        => array(
        // format: user_role(role_id(varchar), parent(varchar))
        'BjyAuthorize\Provider\Role\Config' => array(
            'guest' => array(),
            'user'  => array(),
            // List any groups that from SMAL that you want to identify with 
            // in your application. You could also load them from a database.
            // The SamlIdentityProvider will only return roles that are defined
            // here and are part of the user's identity from the IdP
        ),
  ),
  'guards'                => array(
    // Setup your rules for various controllers/actions, these are just some examples.
    'BjyAuthorize\Guard\Controller' => array(
        array('controller' => 'Application\Controller\Index', 'roles' => array('users')),
        array('controller' => 'zfauthsaml', 'roles' => array('users')),
        // Make sure you allow guests access to these two actions so they can actually login:
        array('controller' => 'zfauthsaml', 'action' => array('login','return'), 'roles' => array('guest')), 
        
    ),
  ),
  'unauthorized_strategy' => 'ZfAuthSaml\View\RedirectionStrategy',
);
  1. config/application.config.php 中启用模块
return array(
  'modules' => array(
    //...
    'ZfcBase',
    'ZfcUser',
    'BjyAuthorize',
    'ZfAuthSaml',
  );
);
  1. 更新您的 init_autoloader.php 以自动加载 simpleSAMLphp。在我的开发区域中,它看起来像这样
// simpleSAMLphp autoloading
if (file_exists('vendor/simplesamlphp/lib/_autoload.php')) {
    $loader = include_once 'vendor/simplesamlphp/lib/_autoload.php';
}
  1. 将模式更改应用到您的用户表。这假设您创建了 ZfcUser 定义的初始用户表。模式文件位于 data/schema.sql

这就足够了,未登录且无权访问请求资源的用户将被重定向到 /login,该页面将重定向他们到您已配置的身份提供者进行登录。登录后,他们将回到 simplesaml,然后重定向到您的应用程序的 /return,该页面将加载其身份并创建一个本地用户(如果尚不存在)。