首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Symfony2 -更改安全入口点

Symfony2 -更改安全入口点
EN

Stack Overflow用户
提问于 2015-08-10 01:10:17
回答 1查看 785关注 0票数 1

使用symonfy作为REST,我希望服务器不要在401上发送这样的头:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 WWW-Authenticate : Basic realm=XXX

但就像

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
WWW-Authenticate : myOwnBasic realm=XXX

我如何重载BasicAuthenticationEntryPoint类或为基本数据创建自己的入口点类?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-10 11:14:17

我终于找到了解决办法:

您需要在parameters.yml中覆盖这个参数:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    security.authentication.basic_entry_point.class: NAMESAPCE\YOURCUSTOM_CLASS

并在您喜欢的地方创建一个文件(我是在MyBundle\Security\Http\EntryPoint中创建的),如下所示:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?php

namespace NAMESAPCE;

use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\EntryPoint\BasicAuthenticationEntryPoint;

class CustomBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint
{
    private $realmName;

    public function __construct($realmName)
    {
        $this->realmName = 'XXX';
    }

    /**
     * {@inheritdoc}
     */
    public function start(Request $request, AuthenticationException $authException = null)
    {
        $response = new Response();
        $response->headers->set('WWW-Authenticate', sprintf('myOwnBasic realm="%s"', $this->realmName));
        $response->setStatusCode(401);

        return $response;
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31915664

复制
相关文章

相似问题

领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文