Kerberos authentication with Symfony2

2019-02-15 08:06发布

问题:

I am trying to authenticate users with kerberos in Symfony2 but I'm a little lost on the way.

When the user is authenticated,the Apache server returns the $ _SERVER ['REMOTE_USER'] variable, giving me his username. I can recover this value :

$request = Request::createFromGlobals();
$user = $request->server->get('REMOTE_USER');

But how to tell Symfony to authenticate the user just with this value ? No password is required.

I hesitate between create a custom authentication provider or create a custom use provider.

What is the best way to do this please ?

回答1:

Added a REMOTE_USER based listener to security firewalls

Several Apache security modules (auth_kerb, auth_cas, etc.) provide the username via an environment variable called REMOTE_USER. For that reason, Symfony 2.6 will include a new authentication listener based on this variable.

To use it in your application, simply define a firewall of the new remote_user type in your security configuration:

# app/config/security.yml
security:
    firewalls:
        secured_area:
            pattern: ^/
            remote_user:
                provider: your_user_provider

Source: http://symfony.com/blog/new-in-symfony-2-6-security-component-improvements