smurfy / crowd-bundle
此包最新版本(dev-master)没有提供许可证信息。
允许对atlassian crowd进行身份验证
dev-master
2013-08-08 14:37 UTC
Requires
- php: >=5.3.0
- smurfy/atlassian-services-crowd: 1.0
This package is not auto-updated.
Last update: 2024-09-23 14:19:36 UTC
README
提供Atlassian Crowd授权AsaAyersCrowdBundle
特性
- 独立的SSO支持
- 表单登录支持
作者
- 原始作者AsaAyers (https://bitbucket.org/AsaAyers/crowdbundle/)
- smurfy进行了大量修改并推送到github
安装
将AsaAyersCrowdBundle添加到你的vendor/bundles/目录下
使用 vendors 脚本
在你的 deps
文件中添加以下行
[AsaAyersCrowdBundle]
git=git://github.com/smurfy/AsaAyersCrowdBundle.git
target=bundles/AsaAyers/CrowdBundle
[AtlassianServicesCrowd]
git=git://github.com/smurfy/AtlassianServicesCrowd.git
target=Atlassian
运行 vendors 脚本
./bin/vendors install
将AsaAyers命名空间添加到你的自动加载器中
// app/autoload.php
$loader->registerNamespaces(array(
'AsaAyers' => __DIR__.'/../vendor/bundles',
// your other namespaces
);
$loader->registerPrefixes(array(
'Services_Atlassian' => __DIR__.'/../vendor/Atlassian/lib',
//Other prfixes
));
// on the bottom of autoload.php For Atlassian Lib include path
set_include_path(get_include_path() . ':' . __DIR__ . '/../vendor/Atlassian/lib');
将AsaAyersCrowdBundle添加到你的应用程序内核中
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new AsaAyers\CrowdBundle\AsaAyersCrowdBundle(),
// ...
);
}
配置
在config.yml(或parameters.ini)中配置参数
parameters:
crowd_application_user: username
crowd_application_password: password
crowd_wsdl: https://yourdomain.com/crowd/services/SecurityServer?wsdl
配置你的防火墙
security:
factories:
- "%kernel.root_dir%/../vendor/bundles/AsaAyers/CrowdBundle/Resources/config/security_factories.xml"
providers:
crowd: ~
# All of a user's Crowd groups will become ROLE_${group_name} with spaces and dashes converted to underscores.
# crowd-administorators becomes ROLE_CROWD_ADMINISTRATORS
firewalls:
main:
# You can use sso standalone, but the crowd login itself also needs crowd_sso enabled
crowd_sso: true
crowd:
# You can use here the same as of form_login
cookie_domain: yourdomain.com
logout:
delete_cookies:
crowd.token_key: { path: /, domain: yourdomain.com }
将AsaAyersCrowdBundle与FOSUserBundle结合使用
此示例展示了如何使用AsaAyersCrowdBundle与FOSUserBundle。用户角色将与来自crowd的已存在角色合并。如果用户不在FOSUserBundle数据库中,则会创建用户。
创建一个新的UserProvider
namespace Acme\MyBundle\Security\User\Provider;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class CrowdUserProvider implements UserProviderInterface
{
protected $crowd;
protected $userManager;
/**
* Cosntructor
*
* @param Services_Atlassian_Crowd $crowd The Crowd
* @param mixed $userManager The Fos UserManager
*
* @return void
*/
public function __construct(\Services_Atlassian_Crowd $crowd, $userManager)
{
$this->crowd = $crowd;
$this->userManager = $userManager;
}
/**
* {@inheritDoc}
*/
public function supportsClass($class)
{
return $this->userManager->supportsClass($class);
}
/**
* Loads the user from the crowd, but other stuff from db over userbundle
*
* @param string $username The username
*
* @return User
*/
public function loadUserByUsername($username)
{
$groups = $this->crowd->findGroupMemberships($username);
if (isset($groups->string))
{
$user = $this->userManager->findUserByUsername($username);
if (empty($user)) {
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setUsername($username);
$user->setPassword('');
$user->setEmail($username);
}
foreach ($groups->string as $group_name)
{
$group_name = 'ROLE_'.strtoupper($group_name);
$group_name = str_replace(array(' ', '-'), '_', $group_name);
$user->addRole($group_name);
}
$this->userManager->updateUser($user);
return $user;
}
throw new UsernameNotFoundException($username);
}
/**
* {@inheritDoc}
*/
function refreshUser(UserInterface $user)
{
return $this->loadUserByUsername($user->getUsername());
}
}
配置你的服务
services:
my.crowd.user:
class: Acme\MyBundle\Security\User\Provider\CrowdUserProvider
arguments:
crowd: "@crowd"
userManager: "@fos_user.user_manager"
配置你的防火墙
security:
factories:
- "%kernel.root_dir%/../vendor/bundles/AsaAyers/CrowdBundle/Resources/config/security_factories.xml"
providers:
fos_userbundle:
id: my.crowd.user
firewalls:
main:
# You can use sso standalone, but the crowd login itself also needs crowd_sso enabled
crowd_sso: true
crowd:
# You can use here the same as of form_login
provider: fos_userbundle
cookie_domain: yourdomain.com
logout:
delete_cookies:
crowd.token_key: { path: /, domain: yourdomain.com }