我想在箱子我的Symfony2應用的登錄表單鏈提供商(2.3版本) - 這是我的安全YAML:如何從用戶更改Symfony2的安全明文編碼器用戶界面
jms_security_extra:
secure_all_services: false
expressions: true
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
chain_provider:
chain:
providers: [in_memory, fos_userbundle]
fos_userbundle:
id: fos_user.user_provider.username
in_memory:
memory:
users:
admin: { password: god, roles: [ 'ROLE_ADMIN' ] }
firewalls:
main:
pattern: ^/
form_login:
provider: chain_provider
csrf_provider: form.csrf_provider
logout: true
anonymous: true
security: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/group/, role: ROLE_ADMIN }
由於你可以看到,我使用FOSUserBundle(偉大的東西順便說一句)。
問題是,我用in_memory管理員用戶登錄後,我無法進入/ profile/URL。我收到此錯誤信息:
AccessDeniedHttpException: This user does not have access to this section
我找到了原因這 - 問題是在FOS \ UserBundle \控制器\ ProfileController可類:
public function showAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user));
}
該控制器檢查,如果$ USER對象是UserInterface的一個實例,它不是,因爲它是Symfony \ Component \ Security \ Core \ User \ User(明文編碼器類)的實例。
我試圖改變編碼器配置到這一點:
security:
encoders:
Symfony\Component\Security\Core\User\UserInterface: plaintext
但沒有奏效。我發現用戶類在Symfony引擎的許多地方被硬編碼。
所以我的問題是:如何從安全yaml更改該行爲?我錯過了什麼嗎?
是的,你是對的。謝謝。 – schabluk