- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一个包来在 Symfony 2.3 上集成 CAS 身份验证。我找到了这些选项,但事实是我不相信任何选项,因为几乎所有捆绑包似乎都没有更新就被放弃了。
1.- sensiolabs/CasBundle:https://github.com/sensiolabs/CasBundle
文档稀疏且不完整。我还没有找到任何关于如何使用它的例子。
2.- BeSimple/BeSimpleSsoAuthBundle:https://github.com/BeSimple/BeSimpleSsoAuthBundle
有了这个,我正在测试,我遇到了一些问题。我想我已经解决了第四个问题,但我落后于另一个。
3.- Symfony CAS 客户端:https://wiki.jasig.org/display/CASC/Symfony+CAS+Client
完全过时了
真的,在 symfony 中使用 CAS 进行身份验证的选项很少吗?
最佳答案
我以前遇到过同样的问题,我使用 BeSimpleSsoAuthBundle 解决了它,但您必须进行一些更改:
假设您的用户实体已经在您的 UserBundle 中实现,您必须覆盖一个唯一的属性 sgid :
1- BeSimple\SsoAuthBundle\Security\Core\User :
<?php
namespace Application\UserBundle\Security\BeSimple\SpawnedUserProvider;
use BeSimple\SsoAuthBundle\Security\Core\User\SpawnedUserProvider;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\HttpFoundation\RedirectResponse;
class SsoUserProvider extends SpawnedUserProvider
{
/**
* @var array
*/
private $roles;
/**
* Constructor.
*
* @param array $roles An array of roles
*/
private $entityManager;
private $securityContext;
public function __construct($em, $securityContext) {
$this->em = $em;
$this->securityContext = $securityContext;
}
/**
* {@inheritdoc}
*/
public function loadUserByUsername($username)
{
$session = $this->securityContext;
$qb = $this->em->createQueryBuilder();
$qb->select("u")
->from('ApplicationUserBundle:User', 'u')
->where('u.sgid = :sgid')
->AndWhere('u.status = 1')
->setParameter("sgid", $username);
$result = $qb->getQuery()->getOneOrNullResult();
if ($result == NULL) {
$session->getFlashBag()->add('error', 'Vous ne pouvez pas vous connecter car votre compte est désactivé');
return new RedirectResponse('login');
}
$user_name = $result->getFirstName().' '.$result->getLastName();
$session->set('userId', $result->getId());
if ($result->getUserType() == 1) {
$this->roles = array('ROLE_ADMIN');
}else if ($result->getUserType() == 0){
$this->roles = array('ROLE_USER');
}else{
$session->getFlashBag()->add('error', 'Vous ne pouvez pas vous connecter car votre compte n\'a pas de rôle');
return new RedirectResponse('logout');
}
return $this->spawnUser($user_name);
}
/**
* {@inheritDoc}
*/
public function refreshUser(UserInterface $user)
{
if (!$user instanceof User) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}
return $this->spawnUser($user->getUsername());
}
/**
* {@inheritDoc}
*/
public function supportsClass($class)
{
return $class === 'Symfony\Component\Security\Core\User\User';
}
/**
* Spawns a new user with given username.
*
* @param string $username
*
* @return \Symfony\Component\Security\Core\User\User
*/
private function spawnUser($username)
{
//$this->roles = $this->userType;
return new User($username, null, (array)$this->roles, true, true, true, true);
}
}
<?php
namespace Application\UserBundle\Security\BeSimple\Authentication\Provider;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use BeSimple\SsoAuthBundle\Security\Core\User\UserFactoryInterface;
/*
* @Override
*/
use BeSimple\SsoAuthBundle\Security\Core\Authentication\Provider\SsoAuthenticationPr ovider;
class AppAuthenticationProvider extends SsoAuthenticationProvider
{
/**
* @var UserProviderInterface
*/
private $userProvider;
/**
* @var bool
*/
private $createUsers;
/**
* @var bool
*/
private $hideUserNotFound;
/**
* @Override file
* @throws \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
* @throws \Symfony\Component\Security\Core\Exception\BadCredentialsException
*
* @param string $username
* @param array $attributes
*
* @return UserInterface
*/
protected function provideUser($username, array $attributes = array())
{
try {
$user = $this->retrieveUser($username);
} catch (UsernameNotFoundException $notFound) {
if ($this->createUsers && $this->userProvider instanceof UserFactoryInterface) {
$user = $this->createUser($username, $attributes);
} elseif ($this->hideUserNotFound) {
throw new BadCredentialsException('Bad credentials', 0, $notFound);
} else {
throw $notFound;
}
}
return $user;
}
}
<?php
namespace Application\UserBundle\Security\Authentication\Handler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Doctrine\ORM\EntityManager;
class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface
{
protected
$router,
$security,
$entityManager;
public function __construct(Router $router, SecurityContext $security, EntityManager $entityManager)
{
$this->router = $router;
$this->security = $security;
$this->entityManager = $entityManager;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$session = $request->getSession();
$attributes = $this->security->getToken()->getAttributes();
$sgid = $attributes['sso:validation']['sgid'];
$em = $this->entityManager;
$qb = $em->createQueryBuilder();
$qb->select("u")
->from('ApplicationUserBundle:User', 'u')
->where('u.sgid = :sgid')
->AndWhere('u.status = 1')
->setParameter("sgid", $sgid);
$result = $qb->getQuery()->getOneOrNullResult();
//en cas où utilisateur est désactivée
//Malgre que si il arrive a cette handler ça veut dire qu'il activé car le test se fait sur le bundle BeSimple
if ($result == NULL) {
return new RedirectResponse($this->router->generate('login'));
}
$session->set('userId', $result->getId());
$response = new RedirectResponse('admin');
return $response;
}
}
parameters:
security.authentication.provider.sso.class: Application\UserBundle\Security\BeSimple\Authentication\Provider\AppAuthenticationProvider
services:
security.authentication.provider.sso:
class: %security.authentication.provider.sso.class%
public: false
arguments: ['', '@security.user_checker', '', '', false]
be_simple_sso_auth:
admin_sso:
protocol:
id: cas
version: 2
server:
id: cas
login_url: https://adresse ip:8443/cas-server-webapp-4.0.0/login
logout_url: https://adresse ip:8443/cas-server-webapp-4.0.0/logout
validation_url: https://adresse ip:8443/cas-server-webapp-4.0.0/serviceValidate
services:
spawned_user_provider:
class: Application\UserBundle\Security\BeSimple\SpawnedUserProvider\SsoUserProvider
arguments: [@doctrine.orm.entity_manager, @session]
be_simple.sso_auth.client.option.curlopt_ssl_verifypeer.value: false
be_simple.sso_auth.client.option.curlopt_sslversion.value: 4 (Optionale)
main:
pattern: ^/admin
context: marketshare_context
logout:
path: /admin/logout
target: /
#provider: sso
trusted_sso:
manager: admin_sso
login_action: ApplicationUserBundle:TrustedSso:login
logout_action: false
login_path: /admin/login
check_path: /admin/check
always_use_default_target_path: true
default_target_path: /admin/potentiel
failure_path: /admin/logout
关于authentication - CAS 认证 Symfony2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19639504/
我开始从事一个用 Symfony 2.8 编写的大型项目。将整个项目升级到 SF 3 需要数百小时,现在还不可能。我想到了一个想法,将 symfony/symfony 包解压到它替换的单个包中(com
我在提交表单后使用 FOSUserEvents,但订阅者调用了两次。 这样我的验证码第一次有效第二次无效 这是我的代码 router = $router; $this->request
我有以下路线: blog_show: path: /test/123 defaults: { _controller: TotalcanBravofillBundle:Te
我是测试新手。我想测试我的功能。我已经成功安装了 phpUnit。我在互联网上查看了许多教程。但我无法获得有关测试的正确信息。这是我的功能代码: public function loginAction
我正在尝试重现 facebook batch requests 的行为在他们的图形 api 上运行。 所以我认为最简单的解决方案是在 Controller 上向我的应用程序发出几个请求,例如: pub
在 Symfony Progress Bar documentation有一个超酷酒吧的示例图像。不幸的是,看起来文档的其余部分没有解释如何获得这样的结果。 这是图片,以防您错过: 我怎么才能得到它?
我使用Finder发送假脱机电子邮件,但是自动名称生成器将点放在文件名中,有时它们出现在文件的开头。 查找程序似乎无法获取具有该名称的文件-那些文件被隐藏了……有人经历过这种行为吗?有什么建议如何使用
我正在尝试进行 LDAP 身份验证,我目前遇到此类错误: ServiceNotFoundException: The service "security.firewall.map.context.ma
有没有办法验证和检查集合数组是否为空。我已经尝试过: /** * @Assert\NotBlank() * @Assert\Length( min = 1) */ protected $work
使用Smyfony2和Doctrin2,可以使用以下示例创建数据固定装置:http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/i
我看到在大多数Symfony 2示例中,例如,不存在记录时,Symfony 2会引发异常。我认为这种方法对最终用户不友好。为什么有人更喜欢引发异常而不在Flashbag上添加一些错误消息? 最佳答案
我对项目中的以下服务有疑问: app.security.guardAuthenticatorLoginPassword: class: AppBundle\Security\LoginPa
symfony缓存和登录Docker容器存在问题。 Web服务器从www-data用户和组执行,当我使用docker上安装的php从docker容器中清除symfony缓存时,它从root执行。 因此
我想了解 symfony 中的服务 我已阅读http://symfony.com/doc/2.3/book/service_container.html#creating-configuring-se
因为我对 Symfony 和 Doctrine 还很陌生,所以我有一个可能很愚蠢的问题;-) 有人可以用简单的词语向我解释集合(尤其是实体中的ArrayCollections)吗?它是什么以及何时以及
我收到了这个表格: {{ form_start(form) }} {{ form_end(form) }} 我想检查用户是否登录,我这样做了: {% if is_g
我的网站已准备好部署,我正在尝试将其设置为在线。 一些信息: 主持人是 OVH。 它不允许 SSH,我必须使用 FTP 发送文件。也没有命令行。 我现在希望能够在子目录中设置网站:/www/test(
过去几个月以来,我一直在尝试与symfony合作。昨晚我自动删除了不需要的存储库。之后,我无法使用symfony命令创建新的symfony项目。当我在终端中运行Symfony new Security
In the environnement variable, then in system variable, I edited the path and added在环境变量中,然后在系统变量
我们有一个 Symfony 1.4 应用程序,想升级到 Symfony 4。是否有可能或者我们必须重新编程该应用程序? 我们询问了我们附近的一家软件公司,他们告诉我们必须重新编写应用程序。 最佳答案
我是一名优秀的程序员,十分优秀!