leuven/authentication-bundle

Symfony3 Bundle for KU Leuven Shibboleth authentication,具有LDAP和Person Data API集成

安装: 117

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 0

开放性问题: 0

类型:symfony-bundle

0.2.4 2016-09-14 12:15 UTC

README

此bundle为您的Symfony3项目添加了Shibboleth身份验证防火墙。

SensioLabsInsight Build Status Code Coverage Scrutinizer Code Quality

Latest Stable Version Dependency Status Latest Unstable Version Dependency Status

安装

下载Bundle

打开命令行界面,进入您的项目目录,并执行以下命令以下载此bundle的最新稳定版本

$ composer require kuleuven/authentication-bundle

此命令要求您全局安装了Composer,如Composer文档中的安装章节所述。

启用Bundle

然后,通过将其添加到项目中的app/AppKernel.php文件中注册的bundle列表来启用该bundle。

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Kuleuven\AuthenticationBundle\KuleuvenAuthenticationBundle(),
        );

        // ...
    }

    // ...
}

Shibboleth

设置Symfony防火墙

# app/config/security.yml
security:
    ...
    providers:
        ...
        kuleuven_authentication.service.shibboleth_user_provider:
            id: kuleuven_authentication.service.shibboleth_user_provider
    ...
    firewalls:
        ...
        kuleuven_authentication:
            pattern: ^/secured # change this to your application's secured path
            stateless: true
            kuleuven_authentication: ~
            logout:
                path: /logout
                success_handler: kuleuven_authentication.security.http.logout.handler

默认情况下,该bundle将使用默认的Shibboleth用户提供者。这是一个内存中的用户提供者,它将根据服务器属性动态获取您的用户。

您可以在身份验证之前设置防火墙以检查特定的属性要求。默认情况下,这设置为Shib-Identity-Provider需要是'urn:mace:kuleuven.be:kulassoc:kuleuven.be'。

# app/config/config.yml
...
kuleuven_authentication:
    authentication_attribute_requirements: { Shib-Identity-Provider: 'urn:mace:kuleuven.be:kulassoc:kuleuven.be' }

在公共文件夹中的.htaccess文件中设置Shibboleth

# web/.htaccess
# Shibboleth
<IfModule mod_shib>
    AuthType shibboleth
    Require shibboleth
    ShibRequireSession On
</IfModule>

更改Shibboleth服务提供者设置(可选)

# app/config/config.yml
...
kuleuven_authentication:
    shibboleth_is_secured_handler: true
    shibboleth_handler_path: /Shibboleth.sso
    shibboleth_status_path: /Status
    shibboleth_session_login_path: /Login
    shibboleth_session_logout_path: /Logout
    shibboleth_session_logout_target: ~
    shibboleth_session_overview_path: /Session
    shibboleth_username_attribute: Shib-Person-uid
    shibboleth_authenticated_attribute: Shib-Identity-Provider
    shibboleth_logout_url_attribute: Shib-logoutURL
    shibboleth_default_charset: ISO-8859-1

覆盖Shibboleth服务器属性(可选)

Shibboleth防火墙默认使用服务器环境。要成功认证,至少应存在两个属性

  • 'Shib-Identity-Provider'属性将告诉您哪个提供者提供了您的身份
  • 'Shib-Person-uid'属性包含您的身份的uid

如果您没有在本地上运行Shibboleth,您可以将这些属性手动添加到您的服务器环境中,或者添加到例如app_dev.php中的$_SERVER数组中。

####参数注入器

但是,此bundle允许您通过'\Kuleuven\AuthenticationBundle\Service\ParameterAttributesProvider'服务覆盖任何属性,该服务使用'authentication_attribute_overwrites'参数注入一组服务器属性。

默认情况下,此功能是禁用的,因此您必须明确启用它。

# app/config/config_dev.yml
kuleuven_authentication:
    ...
    authentication_attribute_overwrites_enabled: true

现在,您可以将您的覆盖添加到parameters.yml中。

# app/config/parameters.yml
parameters:
    ...
    authentication_attribute_overwrites:
        Shib-Identity-Provider: 'urn:mace:kuleuven.be:kulassoc:kuleuven.be'
        Shib-Person-uid: '<(string)your-uid>'

参数注入器将始终覆盖任何其他服务器属性,除非您覆盖了服务的优先级。默认优先级设置为-INF。

####头部注入器

您也可以通过使用'\Kuleuven\AuthenticationBundle\Service\HeaderAttributesProvider'服务来覆盖请求中的特定属性,该服务使用symfony请求头注入一组服务器属性。

默认情况下,此功能是禁用的,因此您必须明确启用它。

# app/config/config_dev.yml
kuleuven_authentication:
    ...
    authentication_attribute_headers_enabled: true

现在,您可以使用像Requestly这样的工具来覆盖应用中的属性,通过将它们作为请求头发送。

头部注入器将始终覆盖任何其他服务器属性,除非您覆盖了服务的优先级。默认优先级设置为-INF。

####LDAP属性注入器

您可以使用LDAP通过'\Kuleuven\AuthenticationBundle\Service\LdapAttributesProvider'服务请求某些服务器属性,该服务使用'authentication_attribute_ldap_filter'参数注入一组LDAP服务器属性结果。

默认情况下,此功能是禁用的,因此您必须明确启用它。

# app/config/config_dev.yml
kuleuven_authentication:
    ...
    authentication_attribute_ldap_enabled: true

一旦启用,您可以添加您的LDAP过滤器。确保过滤器足够独特,只能提供一位用户。

# app/config/parameters.yml
parameters:
    ...
    authentication_attribute_ldap_filter: {uid: '<(string)your-uid>'}

可能还需要启用LDAP - 如果如此,请跳转到下面的LDAP章节。

####自定义注入器

如果您想添加其他服务来填充服务器属性,它们应该实现 '\Kuleuven\AuthenticationBundle\Service\AttributesInjectionProviderInterface',并且应该带有 'kuleuven_authentication.shibboleth_attributes_injector' 标签。

# app/config/services.yml
    ...
    my_attributes_provider:
        class: "%my_attributes_provider.class%"
        tags:
            - { name: kuleuven_authentication.shibboleth_attributes_injector }

更改默认防火墙设置(可选)

为了有更多的控制,还有两个额外的防火墙设置可以被覆盖

  • 'provider' 的值定义了用户提供者 - 默认为 "kuleuven_authentication.service.shibboleth_user_provider"
  • 'default_roles' 的值定义了一些默认角色 - 默认为空数组
# app/config/security.yml
security:
    ...
    firewalls:
        ...
        kuleuven_authentication:
            ...
            kuleuven_authentication:
                provider: 'kuleuven_authentication.service.shibboleth_user_provider'
                default_roles: ~

覆盖属性定义

默认情况下,该组件通过用户令牌 KuleuvenUserToken 或用户 KuleuvenUser 暴露了几个 Shibboleth 属性。可以通过 getAttributegetSingleAttributegetArrayAttributehasAttributeValue 访问属性,它们的 id 或别名作为参数。

内置的 SP 变量是

库勒勒文提供了一个长列表的可用属性。以下是一个非详尽的列表

您可以通过将定义添加到参数 'authentication_attribute_definitions' 中来扩展这些定义。

LDAP

更改 LDAP 设置(可选)

如果您有自己的 LDAP 凭证,您可以使用这些凭据通过设置 LDAP 参数。然而,默认设置应该在没有连接到库勒勒文网络的情况下正常工作。

# app/config/parameters.yml
parameters:
    ldap_rdn: ''
    ldap_password: ''
    ldap_base: 'ou=people,dc=kuleuven,dc=be'
    ldap_domain: 'ldap.kuleuven.be'
    ldap_port: '389'

模拟用户(可选)

通过 LDAP,我们有模拟任何库勒勒文成员的可能性。

虽然 Shibboleth 认证本身是无状态的,但为了使其工作,它需要在会话中保存一个令牌。但您不需要更改无状态密钥,因为 Shibboleth 认证仍然会检查源用户的 Shibboleth 会话以确保会话保持活跃。

要启用此功能,您需要添加一个 LDAP 用户提供者。但是,我们仍然需要我们的 Shibboleth 用户提供者。因此,让我们添加一个链式提供者,并覆盖防火墙提供者。还要添加 switch_user 属性,并检测一些默认角色以检查用户是否可以模拟。

# app/config/security.yml
security:
    ...
    providers:
       chain_provider:
            chain:
                providers: [kuleuven_authentication.service.shibboleth_user_provider, kuleuven_authentication.service.shibboleth_via_ldap_user_provider]
        kuleuven_authentication.service.shibboleth_user_provider:
            id: kuleuven_authentication.service.shibboleth_user_provider 
        kuleuven_authentication.service.shibboleth_via_ldap_user_provider:
            id: kuleuven_authentication.service.shibboleth_via_ldap_user_provider
    ...
    firewalls:
        ...
        kuleuven_authentication:
            ...
            kuleuven_authentication:
                provider: chain_provider
                default_roles: [ROLE_SHIBBOLETH_AUTHENTICATED]
            switch_user: { role: ROLE_SHIBBOLETH_AUTHENTICATED, parameter: _switch_user }

典型开发设置

在使用覆盖和 LDAP 的同时,有一个非常简单的设置来启用本地开发而无需安装 Shibboleth。

在 config_dev.yml 中启用覆盖,并提供 Shib-Identity-Provider 属性的覆盖。同时,在 config_dev.yml 中启用 LDAP。

# app/config/config_dev.yml
...
kuleuven_authentication:
    authentication_attribute_overwrites_enabled: true
    authentication_attribute_overwrites: {Shib-Identity-Provider: 'urn:mace:kuleuven.be:kulassoc:kuleuven.be'}
    authentication_attribute_ldap_enabled: true

通过添加此内容到您的参数.yml(.dist) 中添加您的 uid。在生产环境中将被忽略。

# app/config/parameters.yml.dist
...
parameters:
    authentication_attribute_ldap_filter: {uid: '<(string)your-uid>'}

额外

默认路由为 "/authentication"。

使用 FirewallHelper 服务检查您是否在某个防火墙后面。

即将推出

安全

  • 使添加自己的 attribute-map.xml 文件(包括外部 URL)成为可能 - 在编译器阶段下载?
  • 找到一种方法来检测哪些字段是多值字段,而不是将它们硬编码到 AttributeDefinitionsProvider 中
  • 在令牌支持检查中添加 providerKey

日志记录

  • 使用一个中央代理日志记录器用于认证组件
  • 在一些额外类中实现 LoggerAware

数据收集器

  • 将认证(包括使用标题)、LDAP、PersonDataAPI 和模拟添加到 DataCollector

切换用户

  • 而不是覆盖 switchuser_listener,添加一个新的安全工厂
  • 添加 KuleuvenSwitchUserToken
  • ShibbolethSwitchUserPersistenceSubscriber 应该在 onKernelRequest 中使用 ShibbolethAuthenticationProvider 验证令牌

Docker

额外

  • 如果LDAP过滤器返回超过1个用户,则发送通知
  • 提供示例:如何在访问时自动保存用户

参考资料

Reference Status