Symfony user authentication using Active Directory

Is there a way to authenticate users in symfony apps using Active Directory? Can you please point out some documentation?


What i need is to have a transparent login in my application. The user authenticates once at windows logon, then all applications should be accessed with the same credentials without being asked for the domain\username and password again.

I tried the following in a simple php script:

if (!isset($_SERVER['PHP_AUTH_USER'])) {
  header('WWW-Authenticate: Basic realm="my realm"');
  header('HTTP/1.0 401 Unauthorized');
} else {
  echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
  echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";

but then i get the authentication form popped up. Is there any way to pass the header the credentials used at windows logon?

Thanks, Radu.


You can do that by writing your own authentication callable for sfDoctrineGuardPlugin (if you're using Doctrine). I'll quote plugins' README here:

Check the user password with an external method

If you don't want to store the password in the database because you already have a LDAP server, a .htaccess file or if you store your passwords in another table, you can provide your own checkPassword callable (static method or function) in app.yml:

    check_password_callable: [MyLDAPClass, checkPassword]

When symfony will call the $this->getUser()->checkPassword() method, it will call your method or function. Your function must takes 2 parameters, the first one is the username and the second one is the password. It must returns true or false. Here is a template for such a function:

function checkLDAPPassword($username, $password)
  $user = LDAP::getUser($username);
  if ($user->checkPassword($password))
    return true;
    return false;

You could give the bhLDAPAuthPlugin a try?

Need Your Help

How to package a Mac OS app with Pyinstaller that shows both a console and a GUI?

python osx pyinstaller

I'm packaging a GUI app for MacOS with Pyinstaller, using --windowed flag. Is it possible to package it so that it would show a console in addition to the GUI? When I tried to set console=True, the...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.