hslavich/simplesamlphp-bundle

该包最新版本(v1.1.1)没有提供许可证信息。

SimpleSAMLphp Bundle for Symfony

安装次数: 199,257

依赖项: 0

建议者: 0

安全: 0

星标: 22

关注者: 5

分支: 16

开放问题: 4

类型:symfony-bundle

v1.1.1 2017-01-30 17:50 UTC

This package is auto-updated.

Last update: 2024-09-14 04:09:24 UTC


README

这是一个用于 Symfony 的 SimpleSAMLphp Bundle。

注意: 对于 Symfony 2.7 或更低版本,您需要使用此 Bundle 的 1.0.0 版本。

注意 2: 此 Bundle 使用完整的 SimpleSAMLphp 应用程序。我强烈推荐使用这个更轻量级和改进的 OneloginSamlBundle

安装

将此 Bundle 添加到您的 Symfony 项目中。

composer require hslavich/simplesamlphp-bundle

或者在您的 composer.json 文件中手动引入此 Bundle。

"require": {
    ...
    "hslavich/simplesamlphp-bundle": "dev-master"
}

更新您的项目。

composer update hslavich/simplesamlphp-bundle

app/AppKernel.php 中激活此 Bundle。

$bundles = array(
    ...
    new Hslavich\SimplesamlphpBundle\HslavichSimplesamlphpBundle(),
)

配置

将 Bundle 配置设置添加到您的 Symfony 配置中。

# app/config/config.yml
hslavich_simplesamlphp:
    # Service provider name
    sp: default-sp

您需要创建自己的用户提供者。请参阅 Symfony 文档 "如何创建自定义用户提供者"

  1. 首先,创建一个 User 类(您也可以将其放置在您的 Entity/ 文件夹中)

     # src/Acme/MyBundle/Security/User/MyUser.php
     namespace Acme\MyBundle\Security\User;
    
     use Symfony\Component\Security\Core\User\UserInterface;
     use Symfony\Component\Security\Core\User\EquatableInterface;
    
     class MyUser implements UserInterface, EquatableInterface
     {
         ...
     }
    
  2. 然后创建 UserProvider 类

     # src/Acme/MyBundle/Security/User/MyUserProvider.php
     namespace Acme\MyBundle\Security\User;
    
     use Symfony\Component\Security\Core\User\UserProviderInterface;
     use Symfony\Component\Security\Core\User\UserInterface;
     use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
     use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
    
     class MyUserProvider implements UserProviderInterface
     {
         public function loadUserByUsername($username) { ... }
         public function refreshUser(UserInterface $user) { ... }
         public function supportsClass($class) { ... }
     }
    
  3. 然后使您的 UserProvider 成为服务

     # src/Acme/MyBundle/Resources/config/services.yml
     services:
         my_user_provider:
             class: Acme\MyBundle\Security\User\MyUserProvider
    

然后添加 providerfirewalls 设置到您的 Symfony 安全文件中。

# app/config/security.yml
security:
    providers:
        simplesaml:
            id: my_user_provider

    firewalls:
        saml:
            pattern:    ^/
            anonymous: true
            stateless:  true
            simple_preauth:
                authenticator: simplesamlphp.authenticator
                provider: simplesaml
            logout:
                path:   /logout
                success_handler: simplesamlphp.logout_handler

在您的 app/ 文件夹中创建以下文件结构,并将配置文件放置在那里。

app/
  config/
    simplesamlphp/
      cert/
        saml.crt
        saml.pem
      config/
        config.php
        authsources.php
      metadata/
        saml20-idp-remote.php # Example

请确保在您的 config.php 文件中正确设置 cert/metadata/ 文件夹的路径(建议使用绝对路径)。metadata/saml20-idp-remote.php 仅为示例。有关更多信息,请参阅 SimpleSAMLphp 文档,"添加 IdP 到 SP"

您也可以将这些文件夹放置在您的机器上的其他位置,只需确保正确设置 SIMPLESAMLPHP_CONFIG_DIR 环境变量(见下文)。

将环境变量添加到您的 web 服务器配置文件中,例如 /etc/apache2/httpd.conf.local

<Directory *>
    ...
    SetEnv SIMPLESAMLPHP_CONFIG_DIR /var/path/to/my/config
</Directory>

启用会话桥接存储(有关更多信息,请参阅 Symfony 文档)。

# app/config/config.yml
framework:
    session:
        storage_id: session.storage.php_bridge
        handler_id: ~

在您的 web 服务器上创建别名,例如对于 Apache2 服务器,将此行添加到您的 http.conf.local(或您需要的其他配置文件)。

Alias /simplesaml /home/myapp/vendor/simplesamlphp/simplesamlphp/www