Ok so here's what I did in case someone wonders:
First in my Security folder, I created my own version of the BasicAuthenticationEntryPoint.php
<?php
/*
* Redefinition of the Symfony's BasicAuthenticationEntryPoint
*/
namespace multikanbanmultikanbanSecurityHttpEntryPoint;
use SymfonyComponentSecurityCoreExceptionAuthenticationException;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentSecurityHttpEntryPointAuthenticationEntryPointInterface;
/**
* BasicAuthenticationEntryPoint starts an HTTP Basic authentication.
*
* @author Fabien Potencier <[email protected]>
*/
class BasicAuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
private $realmName;
public function __construct($realmName)
{
$this->realmName = $realmName;
}
/**
* {@inheritdoc}
*/
public function start(Request $request, AuthenticationException $authException = null)
{
$response = new Response();
$response->headers->set('WWW-Authenticate', 'FormBased');
$response->setStatusCode(401);
return $response;
}
}
Note that I did two things:
- Add the use for the AuthenticationEntryPointInterface.
- Change the WWW-Authenticate value to 'FormBased', this being the actual modification to the original file, so that the browsers don't show the default prompt when the server returns a 401 Unauthorized. (You could also return a 400 but then you wouldn't really be complying with the standard)
Second, I defined the service in my Silex Application like so:
$this['security.entry_point.main.http'] = $this->share(function() {
return new BasicAuthenticationEntryPoint('main');
});
'main' being my firewall name.
Obviously, I also added the use at the top of the Application.php:
use multikanbanmultikanbanSecurityHttpEntryPointBasicAuthenticationEntryPoint;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…