使用 symfony2.1 和 FOSFacebookBundle:
如果用户正在键入 www.example.com,例如用户关闭了他的浏览器,那么如果他仍然经过身份验证,我想重定向到 www.example.com/secured。
如果用户通过身份验证,我无法进入 indexAction。
我的安全.yml:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
in_memory:
memory:
users:
user: { password: userpass, roles: [ 'ROLE_USER' ] }
admin: { password: adminpass, roles: [ 'ROLE_ADMIN' ] }
my_fos_facebook_provider:
id: my.facebook.user
//How can I add here a ROLE_USER?
firewalls:
//standard thing from FosFacebookBundle
access_control:
- { path: ^/, roles: [IS_AUTHENTICATED_ANONYMOUSLY] }
我的索引操作:
if( $this->container->get('security.context')
->isGranted('IS_AUTHENTICATED_FULLY') ){
echo 'asdf'; //this is working in the secured area www.example.com/secured/
}
我的错误消息:安全上下文不包含身份验证令牌。一个可能的原因可能是没有为此 URL 配置防火墙。
在安全区域中,用户没有角色。我怎样才能改变它?
怎么了?
更新
namespace Frontend\FbAccountBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
*/
class User
{
/**
* @var integer
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="facebook_id", type="bigint", nullable=false)
*/
private $facebookId;
/**
* @param Array
*/
public function setFBData($fbdata)
{
if (isset($fbdata['id'])) {
$this->setFacebookId($fbdata['id']);
$this->addRole('ROLE_FACEBOOK');
}
}
安全性.yml:
services:
my.facebook.user:
class: Frontend\FbAccountBundle\Security\User\Provider\FacebookProvider
arguments:
facebook: "@fos_facebook.api"
userManager: "@fos_user.user_manager"
validator: "@validator"
container: "@service_container"