【发布时间】:2015-07-22 22:32:12
【问题描述】:
我已经安装了 symfony 2.6.6,我一直按照本教程进行操作,直到第 1 步。)b.) http://symfony.com/doc/2.7/book/security.html
1.) http_basic登录后如何清除tokenStorage(session等)?
通过 http_basic 登录后 我找不到任何方法来清除我的 tokenStorage
Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage Object
(
[token:Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage:private] => Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken Object
(
[credentials:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] =>
[providerKey:Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken:private] => default
[user:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Symfony\Component\Security\Core\User\User Object
(
[username:Symfony\Component\Security\Core\User\User:private] => admin
[password:Symfony\Component\Security\Core\User\User:private] => kitten
[enabled:Symfony\Component\Security\Core\User\User:private] => 1
[accountNonExpired:Symfony\Component\Security\Core\User\User:private] => 1
[credentialsNonExpired:Symfony\Component\Security\Core\User\User:private] => 1
[accountNonLocked:Symfony\Component\Security\Core\User\User:private] => 1
[roles:Symfony\Component\Security\Core\User\User:private] => Array
(
[0] => ROLE_ADMIN
)
)
[roles:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
[0] => Symfony\Component\Security\Core\Role\Role Object
(
[role:Symfony\Component\Security\Core\Role\Role:private] => ROLE_ADMIN
)
)
[authenticated:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => 1
[attributes:Symfony\Component\Security\Core\Authentication\Token\AbstractToken:private] => Array
(
)
)
)
这是我的 security.yml
security:
# http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password
encoders:
Symfony\Component\Security\Core\User\User: plaintext
# http://symfony.com/doc/current/book/security.html#hierarchical-roles
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
in_memory:
memory:
users:
ryan:
password: ryanpass
roles: 'ROLE_USER'
admin:
password: kitten
roles: 'ROLE_ADMIN'
# the main part of the security, where you can set up firewalls
# for specific sections of your app
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
default:
anonymous: ~
http_basic: ~
logout:
path: /logout
target: /
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/admin/logout, roles: ROLE_ADMIN }
p.s:第一次访问/admin http基本表单按预期弹出,但登录并清除缓存后,即使浏览器仍然无法清理tokenStorage
【问题讨论】:
-
你有没有试过去 url
.../admin/logout注销? -
@Med:这是我尝试解决问题的方法之一。我添加了一条路由`logout:path:/logout`然后访问了../logout 我也尝试了你的建议,但无论哪种方式都失败了
标签: php symfony cookies session-cookies browser-cache