Check if NTLM SSO is enabled

Check if NTLM SSO is enabled

by Luis de Vasconcelos -
Number of replies: 2

I want to check if NTLM SSO under Site administration / Plugins / Authentication / LDAP server is enabled and then redirect the user appropriately. Is this a workable way to do it?

$authplugin = get_auth_plugin('ldap');
if (empty($authplugin->config->ntlmsso_enabled)) {
    redirect($CFG->wwwroot . '/login/index.php');
} else {
    redirect($CFG->wwwroot . '/auth/ldap/ntlmsso_attempt.php');
}

Thanks.

Average of ratings: -
In reply to Luis de Vasconcelos

Re: Check if NTLM SSO is enabled

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 would say so (testing for $authplugin->config->ntlmsso_enabled). As for the redirections, without additional context I won't dare to comment if that's sensible or not smile

Saludos.
Iñaki.
Average of ratings: Useful (1)
In reply to Iñaki Arenaza

Re: Check if NTLM SSO is enabled

by Luis de Vasconcelos -

Thanks Iñaki

I mainly wanted to confirm if using $authplugin->config->ntlmsso_enabled is the right way to do it. The actual re-directs aren't causing any problems.

A bit of an explanation: I have a custom admin report under \admin\report\test_report which currently assumes that NTML SSO will always be enabled on the site and so it always tries to do the SSO via wwwroot . '/auth/ldap/ntlmsso_attempt.php' - even when NTLM SSO is disabled. Making the assumption that NTLM SSO was not very cmart - it causes an SSO error when SSO is disabled:

[19-Apr-2012 12:16:22] Default exception handler: NTLM SSO is disabled. Debug:
* line 429 of \lib\setuplib.php: moodle_exception thrown
* line 21 of \auth\ldap\ntlmsso_attempt.php: call to print_error()

A better approach was for me to put in that ntlmsso_enabled check and re-direct the user to the Moodle login page ($CFG->wwwroot . '/login/index.php') if NTLM SSO is disabled on the site. That seems to solve the problem.

Thanks for your help.

FYI, your reply to http://moodle.org/mod/forum/discuss.php?d=112970 is a similar concept. Nice work! Thanks.