我在 symfony 3 中的系统登录有问题。所以我security.yml的是:
security:
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_FMTI: ROLE_FMTI
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/admin
anonymous: ~
form_login:
always_use_default_target_path: true
default_target_path: /admin/homepage
login_path: /admin/login
check_path: /admin/login_check
logout:
path: /admin/logout
invalidate_session: true
target: /admin/login
access_control:
- { path: ^/admin/homepage, roles: ROLE_ADMIN }
providers:
in_memory:
memory:
users:
admin: { password: admin, roles: 'ROLE_ADMIN' }
encoders:
Symfony\Component\Security\Core\User\User: plaintext
路由:
app_admin_homepage:
path: /homepage
defaults: { _controller: AppAdminBundle:Login:index }
login:
path: /login
defaults: { _controller: AppAdminBundle:Login:login }
login_check:
path: /login_check
logout:
path: /logout
以及来自 LoginController 的方法 login :
public function loginAction(Request $request)
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('AppAdminBundle:Member:login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
}
问题是,如果我使用凭据登录应用程序:admin/admin。之后我进行注销。
如果我尝试访问
test.dev/admin/homepage----> 我正在重定向 vers 登录页面test.dev/admin/login,所以很好,我登录为admin.如果我尝试访问
test.dev/admin/news/all-----> 我可以在不登录的情况下访问此页面,并且我登录为anonymous
/admin/*因此,如果用户未经过身份验证,我想重定向到所有路由的登录页面。谢谢,对不起我的英语