I need some info on configuring SSO on IIS 6 (no clean URLs available, no rewrites). How to make IIS perform authentication and pass $_SERVER['REMOTE_USER'] to LDAP SSO on http://mysite/?q=user/login/sso? I'm kinda lost. Is it possible at all? Switching to Apache is not an option, unfortunately, so is upgrading IIS to a newer version.

What I want to achieve: everyone is unauthenticated (guests), when someone needs to log in he/she clicks the link and logs in automatically, using their windows (domain) login.

Comments

johnbarclay’s picture

Here are the moodle docs on this: http://docs.moodle.org/22/en/NTLM_authentication It should be the same. I added some notes at: #1371478: LDAP SSO which are basically the readme. Please add to them as you set this up.

I found the following interesting also, but not as direct:
http://moodle.org/mod/forum/discuss.php?d=145171
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/I...

scoff’s picture

I guess the Moodle stuff isn't very helpful.
They have a separate php file for that and we only have an URL.

IIS Configuration
Open the IIS Management Console and navigate to the auth/ldap/ntlmsso_magic.php file.
IIS 6.0
right click on the file, choose properties
under the "file security" tab, click on the Authentication and Access control "edit" button
untick "Enable Anonymous Access" and tick "Integrated Windows Authentication"

This article looks closer to the subject but I'm not that much of a windows guy.
http://support.microsoft.com/kb/326020/en-us?fr=1

Thanks anyway!

johnbarclay’s picture

so in drupal, the equivalent to to the auth/ldap/ntlmsso_magic.php file would be the path [drupal root]/user/login/sso. Since there is no actual directory, you have to figure out a way to apply sso to only that path. Seems like you could create a virtual directory, but its fuzzy to me.

In IIS 7, you just add something like the following to applicationHost.config, but in IIS6, the metabase isn't stored in a text file.

   <location path="myserver.com/user/login/sso">
       <system.webServer>
           <security>
               <authentication>
                   <windowsAuthentication enabled="true" />
               </authentication>
           </security>
       </system.webServer>
   </location>

to the auth/ldap/ntlmsso_magic.php file

user/login/sso

scoff’s picture

in my case the path is [drupal_root]/?q=user/login/sso or [drupal_root]/index.php?q=user/login/sso
I know that iis7 allows for the url rewrites and more easy to configure in general, but I have to deal with iis6.

scoff’s picture

Well, this code doesn't work in IIS 7 with URL Rewrite. is only good for a real file or folder and doesn't respect the rewrite rules or query string.

I wonder is there a way to make a separate php file to simulate index.php with q=user/login/sso? Sounds easy, I guess I should try.

scoff’s picture

Ok here's to get it (somewhat) working. IIS7, PHP as FastCGI, Drupal 7.10, latest LDAP dev with some hacks.

First of all, looks like you don't have to authenticate user on /user/login/sso itself, any page will do. Just ask for authentication on any page and then redirect to sso. Web server keeps setting $_SERVER['REMOTE_USER'] on every consequent request.

1. Make a copy of index.php and add these 2 lines after bootstrap.

if(!$user->uid) drupal_goto('user/login/sso');
else drupal_goto('user'); // or whatever location you prefer

I was trying to rely on automated sso setting by removing the cookies, but current function ldap_sso_boot() does not work at all.

2. Modify ldap_sso.module. Looks like IIS sets the variable in form 'DOMAIN\user', not 'user@domain'.

$exploded = explode('\\', $remote_user);
if (count($exploded) == 2) {
  $remote_user = $exploded[1];
}

3. Secure you copy of index.php by removing Anonymous auth from it in web.config

   <location path="index2.php">
          <system.webServer>
             <security>
                    <authentication>
                        <anonymousAuthentication enabled="false" />
                        <windowsAuthentication enabled="true" />
                    </authentication>
             </security>
          </system.webServer>
  </location>

4. Point your browser to your index copy. If you're not logged in to Drupal, it should authenticate you (windows auth) and redirect to user/login/sso, which will do the rest.

It's obviously not the best way but it's working. I couldn't test it without entering windows login/password so far, but I hope it doesnt matter how the needed variable was set.

I'm not familiar with patching etc, but someone could add another ldapImplementation for IIS. The only difference so far is how ssoRemoteUserStripDomainName should work. It would be best to check $remote_user for '@' or '\' and explode it accordingly.

Thanks for the module!

johnbarclay’s picture

great. thanks for figuring this out and writing it up. 1. and 2. can be worked into the module.

It looks like 1. would not let anyone see anonymous pages so would only be appropriate for an intranet. Is that correct?

I think part 1. can be accomplished either with hook_boot in ldap_sso or with a new file in the module called ldap_sso/sso_magic.php.

scoff’s picture

no, 1. is for anon users who want to login (to post or comment), it's the only file/url which requires authentication (windows auth on, anon auth off), main index.php and all the other files are available for everybody as configured in drupal permissions (anon auth on).

It would be great to make 1. in hook_boot alone (or even wouldn't be important in case of non-automatic authentication), but I still don't know how to configure IIS to authenticate on url access instead of file access. We still need IIS to ask user for windows authentication and set the variable. Here's the code (IIS specific, I believe), but I haven't tested it.

if (!isset($_SERVER["REMOTE_USER"]) || $_SERVER["REMOTE_USER"] == '') {
    header('HTTP/1.1 401 Unauthorized');
    header('WWW-Authenticate: Negotiate');
    header('WWW-Authenticate: NTLM', false);
    exit;
} 

Tomorrow I'll try to disable authentication in web.config and use this code instead.
johnbarclay’s picture

To have a directory behind windows authentication, create a virtual directory inside of drupal with pointing to an empty directory above drupal root. In applicationHost.config you will end up with:

  <site name="my.edu" id="53" serverAutoStart="true">
....
        <application path="/" applicationPool="my.edu">
              <virtualDirectory path="/sso" physicalPath="E:\inetpub\wwwroot\Drupal\d7win\sso" />
         </application>
...
            </site>
....
  <location path="my.edu/sso">
        <system.webServer>
            <security>
                <authentication>
                    <windowsAuthentication enabled="true" />
                    <anonymousAuthentication enabled="false" />
                </authentication>
            </security>
        </system.webServer>
    </location>
scoff’s picture

How is this different to just create a folder named 'sso' (which is created in you example) and protect it exactly the same way? What it has to do with Drupal? I really don't understand.

scoff’s picture

I can confirm that code at #8 works as it should, so there's no need to configure IIS to ask for user credentials.

Pasting this code into ldap_sso.module → ldap_sso_user_login_sso() after if ($enabled == TRUE) will log you in to Drupal or ask for windows password if you navigate to /user/login/sso.

Again, it's tested on IIS7 (both anon and win authentication turned on), PHP 5.2 as FastCGI, I dont have a chance to check if it works on IIS6/php-isapi/etc.

I think custom module with another hook_menu (user/login/iisauth for example) with this code and redirect to user/login/sso will do the trick. Not sure if it's worth to be in ldap_sso, not untill there's a separate "implementation" for IIS.

jrsinclair’s picture

Could item 2 of #6 be incorporated into the module? I have successfully used it to configure ldap_sso with IIS. I'm happy to roll a patch if that helps. Otherwise I will have to keep re-patching every time a module update comes out.

johnbarclay’s picture

This is in 7.x-1.x-dev already, see #1491244: Authentication/SSO: Strip domain name for IIS. This is a documentation thread, so in lieue of a patch, a read through and update to http://drupal.org/node/1371478 would be appreciated.

larowlan’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

no update for > 12 months - closing