NTLM 1.9 - what should it be like?

NTLM 1.9 - what should it be like?

by Lael ... -
Number of replies: 18
Ok, so NTLM seems to be working fine... but a little slow... it takes up to about four seconds does anyone know of any way to troubleshoot this?

The other question I have is 'how' it is supposed to work from the user's perspective?

At the moment it logs the user in if:
  • they try to access a course page (redirects to an 'attempting ntlm sso login' message),
  • click on the 'login' button at top right
  • but not if the user tries to access an activity on the front page (shows a 'would you like to login with a full account?' message that then redirects to the 'normal' login page.
Are the above behaviours 'normal'?

The other question is configuration - the instructions at http://docs.moodle.org/en/NTLM_authentication mention:

"4.You have "some" basic knowledge of php and are able to configure the index.php with the range of internal IP addresses. "

Is this still required for 1.9 (seems to work without it?) and if so, which index.php? and can anyone suggest what to add?

Thanks



Average of ratings: -
In reply to Lael ...

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

but a little slow... it takes up to about four seconds does anyone know of any way to troubleshoot this?

You can edit .../auth/ldap/ntlm_attempt.php and replace the '3' on the last line (the one starting with 'redirect(...') with the number of seconds to wait for the NTLM negotiation to be stablished. If you put too little time here, it may happen that the user doesn't get logged in depending on your setup (client browser, Apache additional NTLM negotation time, network latency, domain controllers load, etc.).

Are the above behaviours 'normal'?

Except the last one, they are considered normal. The plugin doesn't do anything unless the user tries to log in. If you allow guest access to certain parts of your site, then it doesn't do anything. As soon as the user needs to be authenticated, it kicks in (as part of the login process), provided the user comes from one of the configured IP network ranges.

The last one might be a bug. I'll have a look into it (....) Yes, it seems it's bug. It's a bad interaction between the Yes/No submit method for the 'Would you like to log in now with a full user account?' question and the way the NTLM login hook works.

As this is a tricky part of the code, I'll have a closer look into it and see if I can fix it without breaking anything else wink

Is this still required for 1.9 (seems to work without it?) and if so, which index.php?

This is no longer required for 1.9. I have just updated the documentation to reflect it.

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

As this is a tricky part of the code, I'll have a closer look into it and see if I can fix it without breaking anything else

Ok, I think I have fixed it. I've done a little testing and everything seems to work, but I'd like you to test it before commiting the fix to CVS.

Please, edit .../auth/ldap/auth.php and replace function loginpage_hook() (at around line 1789) with the following code:

function loginpage_hook() { global $CFG, $SESSION; if (($_SERVER['REQUEST_METHOD'] === 'GET' // Only on initial GET of loginpage || ($_SERVER['REQUEST_METHOD'] === 'POST' && (get_referer() != strip_querystring(qualified_me())))) // Or when POSTed from another place // See MDL-14071 && !empty($this->config->ntlmsso_enabled) // SSO enabled && !empty($this->config->ntlmsso_subnet) // have a subnet to test for && empty($_GET['authldap_skipntlmsso']) // haven't failed it yet && (isguestuser() || !isloggedin()) // guestuser or not-logged-in users && address_in_subnet($_SERVER['REMOTE_ADDR'],$this->config->ntlmsso_subnet)) { // First, let's remember where the user was trying to get to before they got here if (empty($SESSION->wantsurl)) { $SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) && $_SERVER['HTTP_REFERER'] != $CFG->wwwroot && $_SERVER['HTTP_REFERER'] != $CFG->wwwroot.'/' && $_SERVER['HTTP_REFERER'] != $CFG->httpswwwroot.'/login/' && $_SERVER['HTTP_REFERER'] != $CFG->httpswwwroot.'/login/index.php') ? $_SERVER['HTTP_REFERER'] : NULL; } // Now start the whole NTLM machinery. redirect("{$CFG->wwwroot}/auth/ldap/ntlmsso_attempt.php"); } }

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Lael ... -
Wow! Thankyou for the quick reply!

I will test the patch tomorrow at work. As for the speed of the single sign on... I was using ldap previously which authenticated faster - am I right in thinking that ntlm should not be any slower (theoretically?) and do you know if there is a way to check where the actual bottleneck is?

Lael
In reply to Lael ...

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

am I right in thinking that ntlm should not be any slower (theoretically?)

That depends on your setup. I'm fairly sure NTLM is as fast as LDAP on IIS, but I'm not that sure if we talk about Apache, much less if we talk about Apache running on Linux. There are more software/protocol layers involved in the latter case, which could translate into larger delays (but I have not measured them, to tell the truth).

As I said before, you can lower the timeout value from the default 3 seconds to 1 second for example, and see if it's works for your setup. If your domains controllers are not loaded, you don't have tons of concurrent loggins and you are running your Moodle site on a Windows machine, that could be enough.

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Martín Langhoff -
I like the colour coding but can't diff in my head... Diff? wink
In reply to Martín Langhoff

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I like the colour coding but can't diff in my head... Diff?

The colourful comment says it all smile:

// See MDL-14071

The diff is attached there (and you should have received an email when I uploaded it, as a I added you as a watcher of the bug wink)

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Lael ... -
ok, it partially works well smile

when the prompt for logging in with full account access is shown (eg accessing a front page activity), it attempts ntlm authentication first.

However, if you use the login block on the front page, or the standard login sceren after ntlm fails (if it does) then it re-attempts ntlmsso when you press 'login'.

hopefully this description is clear enough to work with




In reply to Lael ...

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I'm sorry, but I'm not able to reproduce it with either IE 6.0 (the Windows 2003 server version) or FF 2.0.0.4 (Windows versino).

I have tried with the login block on the front page, by simply clicking on the 'Login' button, and it works as expected if the user should auto-login, and redirects to the standard login page otherwise with the authldap_skipntlmsso flag. And when I enter the credentials of a valid user, I log in directly, with no ntlmsso re-attempt.

I'm using Moodle 1.9 ($version = 2007101509; $release = '1.9 + (Build: 20080311)'), on Windows 2003. I'm going to try with Moodle 1.9 current as of today in a minute, just to make sure it doesn't make a difference.

OK, I think I have it big grin. I think you are clicking on the 'Continue' link on the ntlmsso_finish.php page, instead of waiting for it to redirect you back to the normal login page. This makes the browser send a 'Referer:' header back to Moodle pointing to that same page.

The login page then uses that header in certain cases to see where you were coming from, so it can send you back there when you are enter your credentials. And this time things were getting mixed with this additional 'Referer:' header. Instead of sending you back to the front page, you were are redirected to the ntlmsso_finish.php page again, where it tolds you that NTLM authentication has failed, even if it hasn't tried again (this is a static message, it always prints the same).

So here is a new version of the loginpage_hook() functions that fixes that particular case:

function loginpage_hook() { global $CFG, $SESSION; if (($_SERVER['REQUEST_METHOD'] === 'GET' // Only on initial GET of loginpage || ($_SERVER['REQUEST_METHOD'] === 'POST' && (get_referer() != strip_querystring(qualified_me())))) // Or when POSTed from another place // See MDL-14071 && !empty($this->config->ntlmsso_enabled) // SSO enabled && !empty($this->config->ntlmsso_subnet) // have a subnet to test for && empty($_GET['authldap_skipntlmsso']) // haven't failed it yet && (isguestuser() || !isloggedin()) // guestuser or not-logged-in users && address_in_subnet($_SERVER['REMOTE_ADDR'],$this->config->ntlmsso_subnet)) { // First, let's remember where we were trying to get to before we got here if (empty($SESSION->wantsurl)) { $SESSION->wantsurl = (array_key_exists('HTTP_REFERER',$_SERVER) && $_SERVER['HTTP_REFERER'] != $CFG->wwwroot && $_SERVER['HTTP_REFERER'] != $CFG->wwwroot.'/' && $_SERVER['HTTP_REFERER'] != $CFG->httpswwwroot.'/login/' && $_SERVER['HTTP_REFERER'] != $CFG->httpswwwroot.'/login/index.php') ? $_SERVER['HTTP_REFERER'] : NULL; } // Now start the whole NTLM machinery. redirect("{$CFG->wwwroot}/auth/ldap/ntlmsso_attempt.php"); } // No NTLM SSO, Use the normal login page instead. // If $SESSION->wantsurl is emtpy and we have a 'Referer:' header, the login // page insists on redirecting us to that page after user validation. If // we clicked on the redirect link at the ntlmsso_finish.php page instead // of waiting for the redirection to happen, then we have 'Referer:' header // we don't want to be used at all. As we can't get rid of it, just point // $SESSION->wantsurl to $CFG->wwwroot (after all, we came from there). if (empty($SESSION->wantsurl) && (get_referer() == $CFG->httpswwwroot.'/auth/ldap/ntlmsso_finish.php')) { $SESSION->wantsurl = $CFG->wwwroot; } }

(I have attached a .diff file for MartinL wink and I'll add it to the bug tracker if you confirm that it fixes the issue for you too).

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Johnathan Kemp -

This patch has also been linked to the issue of false returns of automated login failure, i.e. a situation in which after an automated login failure message is displayed the Login Page is then presented to the user, whilst in the top right hand corner the message "You are logged in as Username (logout)" is displayed, because the ntlm login was in fact successful.

In this scenario the user does not at any time action the "continue" link.

I have tested this patch against that scenario and it does not resolve the situation. This has been tested with both IE6 with Windows 2000 and on IE7 with Windows XP Professional.

Kind regards

Johnathan

In reply to Johnathan Kemp

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Jonathan,

as I'm unable to reproduce this problem in my test setup, I'd like you to help me track this down and fix it for good smile

Would you be interested in doing a little debugging and report back your results so I can try and guess what could be going on?

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Johnathan Kemp -

Hello Iñaki,

I am happy to help, just let me know what you want me to do.

Kind regards

Johnathan

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Lael ... -
ok - this works great Inaki - thankyou.
In reply to Lael ...

Re: NTLM 1.9 - what should it be like?

by Lael ... -

Sorry - I spoke too soon. The issue now is that trying with the login block on the frontpage also initiates the ntlmsso attempt - rather than just logging in manually.

Thanks for your help so far - its been great!

In reply to Lael ...

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
While I've developed a patch to address this particular case, I'm a bit reluctant to propose it for inclusion in the core for two reasons:

1.- If you are using NTLM SSO, it doesn't make much sense having a login block. After all, you didn't want your users to type their credentials in the firset place!

2.- The patch is a bit ugly, rather than an elegant solution. The login block needs to know about the NTLM SSO login to avoid it, so this makes the login block depend on the LDAP auth plugin, which makes the code less mantainable in the long run. And the set of conditions to trigger the NTLM SSO gets a little bit more complex.

So I'm posting the patch in case you really want it, but I won't upload it to MDL-14071. This time I really need to post a patch file instead of a copy of the modified functions, as the login block function is a bit long to paste it here.

Saludos. Iñaki.
In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Lael ... -
Thanks Inaki,

In some ways you are right - having NTLM SSO does deal with most users for a login block.
But for others using manual accounts, or email verified accounts... a login block is helpful I think - (think k-12 setting with students being handled by ntlm, and parents by other methods). Not sure if others would feel the same way or not, but I would prefer not to force every user without ntlm auth to click 'login', wait for ntlm to fail, then login manually. Hence, I think a login block on the frontpage that allows them to login manually is still desirable.

I just got back from holidays, so will look the patch in the coming days. Thankyou for working at it!

Lael
In reply to Lael ...

Re: NTLM 1.9 - what should it be like?

by Iñaki Arenaza -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

In this particular case, you can use an HTML block an simply put a link to the login page with the authldap_skipntlmsso parameter set. Something like:

<p>If you don't have a school account (e.g., parents, etc.) you can login
<a href="http://your.moodle.site/login/index.php?authldap_skipntlmsso=1">here</a></p>

could do it.

Saludos. Iñaki.

In reply to Iñaki Arenaza

Re: NTLM 1.9 - what should it be like?

by Lael ... -

Thanks Inaki,

Actually, I just updated with CVS and it all 'just seems to work' now. Login block logs in without going to NTLM, and Login link also works through NTLM SSO without a hitch.

Not sure if that was you - but Thankyou!

Lael