我在最近的 symfony2 中遇到了最简单的授权问题,
我的 security.yml :
安全性:编码器:Symfony\Component\Security\Core\User\User:明文
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' ] }
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
# pattern: ^/demo/secured/login$
pattern: /login
security: false
secured_area:
pattern: ^/admin
form_login:
check_path: check
login_path: login
logout:
path: /logout
target: /index
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/admin/, roles: ROLE_ADMIN }
和 DefaultControler.php 的一部分
public function loginAction() {
$request = $this->getRequest();
$session = $request->getSession();
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->render('JimmyTestBundle:Default:login.html.twig', array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
));
}
public function checkAction()
{
}
我是 symfony 网站的休闲烹饪书,checkAction 应该由防火墙层解释,但当我尝试登录时,它可能不是这样的。
控制器必须返回一个响应(给定 null)。您是否忘记在控制器的某处添加 return 语句?500 内部服务器错误 - LogicException
我的 login.html.twig 也几乎是从教程中复制和粘贴的。有什么建议吗?