【发布时间】:2018-11-09 19:22:25
【问题描述】:
我尝试创建一个简单的登录表单,其中包含通过 web 应用创建或注册的用户。
这是我的 security.yml 文件
security:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
http_basic: ~
provider: our_db_provider
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
encoders:
App\Project\UserBundle\Entity\Users:
algorithm: bcrypt
providers:
our_db_provider:
entity:
class: App\Project\UserBundle\Entity\Users:
property: username
如果我访问像 /nl/admin/.. 这样的页面,即使我没有登录,我也可以访问该页面。 访问控制失败?
即使我尝试登录时,我也得到了无效的凭据..但凭据是正确的..
这是我的控制器
namespace App\Project\UserBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class LoginController extends Controller
{
public function loginAction(Request $request, AuthenticationUtils $authenticationUtils)
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('@ProjectUser/frontend/login/login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
}
}
我错过了什么?
【问题讨论】: