我尝试过使用http_basic身份验证来测试Symfony的安全包。但是当我尝试使用admin / admin凭据登录并提交它们时,它会再次要求它们。
这是security.yml文件
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
providers:
in_memory:
memory:
users:
admin:
password: admin
roles: 'ROLE_ADMIN'
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
http_basic: ~
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }]
这是主控制器
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class MainController extends Controller {
/**
* @Route("/", name="homepage")
*/
public function indexAction() {
return new Response('<html><body>Home page1!</body></html>');
}
/**
* @Route("/admin", name="admin_homepage")
*/
public function adminIndexAction() {
return new Response('<html><body>Admin page1!</body></html>');
}
}
?>
服务器在这里:http://sym.soferonline.ro/admin
问题是什么? 谢谢!
答案 0 :(得分:0)
将这些行添加到web / .htaccess似乎可以使它工作。
RewriteCond%{HTTP:授权} ^(。+)$ RewriteRule。* - [E = HTTP_AUTHORIZATION:%{HTTP:Authorization}]
此主题可能会对您有所帮助symfony2.3 http basic issue