rozmarbeka / simplesamlphp-bundle
SimpleSAMLphp Bundle for Symfony2
Requires
- rozmarbeka/simplesamlphp: >=1.14.88
- symfony/symfony: >=2.8
This package is not auto-updated.
Last update: 2024-09-21 13:26:12 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文档“如何创建自定义用户提供者”。
-
首先,创建一个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 { ... }
-
然后创建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) { ... } }
-
并将您的
UserProvider
设置为服务# src/Acme/MyBundle/Resources/config/services.yml services: my_user_provider: class: Acme\MyBundle\Security\User\MyUserProvider
然后,将provider
和firewalls
设置添加到您的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