rozmarbeka/simplesamlphp-bundle

此包的最新版本(v1.1.19)没有可用的许可信息。

SimpleSAMLphp Bundle for Symfony2

安装: 821

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 16

类型:symfony-bundle

v1.1.19 2016-11-04 10:27 UTC

README

这是一个SimpleSAMLphp Bundle for Symfony2。

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

安装

将此包添加到您的Symfony2项目中。

composer require hslavich/simplesamlphp-bundle

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

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

更新您的项目。

composer update hslavich/simplesamlphp-bundle

app/AppKernel.php中激活此包。

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

配置

将包配置设置添加到您的Symfony2配置中。

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

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

  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设置添加到您的Symfony2安全文件中。

# 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 Web服务器,将以下行添加到http.conf.local(或其他所需的配置文件)。

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