Actions

Authentication plugins: Difference between revisions

From LimeSurvey Manual

No edit summary
m (Reverted edits by C schmitz (talk) to last revision by Mdekker)
Line 1: Line 1:
An authentication plugin has some additional requirements over a regular plugin. Here we list the requirements.


==Enabling and configuring settings for plugin AuthLDAP v2.05+== <!--T:6-->
To make creating your own authentication plugin easier, you should extend the abstract [https://github.com/LimeSurvey/LimeSurvey/blob/master/application/libraries/PluginManager/AuthPluginBase.php AuthPluginBase] class.


# Enable LDAP in PHP.INI.
To get an idea of the possibilities, check out the three core authentication plugins (check their pages for more information about configuration options):
# Verify that phpinfo.php shows that LDAP is enabled.
* [https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/plugins/Authdb/Authdb.php Authdb] Database authentication - this is the default method for all new LimeSurvey installations.[[Core_plugins#Internal_database|info]]
# Go to LimeSurvey Plugin Manager.
* [https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/plugins/Authwebserver/Authwebserver.php Authwebserver] Webserver authentication - This one skips the login form, and provides methods for user creation. [[Core_plugins#Webserver_authentication|info]]
# Configure LDAP plugin.
* [https://github.com/LimeSurvey/LimeSurvey/blob/master/application/core/plugins/AuthLDAP/AuthLDAP.php AuthLDAP] LDAP authentication - Adds a custom error message and relies on a user being present in the LimeSurvey database. [[Core_plugins#LDAP|info]]
#* '''Example settings''':
 
#::Ldap server e.g. ldap://ldap.mydomain.com: '''''ldap://ldap.mydomain.com'''''
There are 6 events you can subscribe to:
#::Port number (default when omitted is 389):
 
#::LDAP version (LDAPv2 = 2), e.g. 3: '''''3'''''
== beforeLogin ==
#::Username prefix cn= or uid=: '''''cn='''''
This is called first, and can possibly disable the loginform, for example when webserver authentication is used and we trust on that. To do this, use ''$this->setAuthPlugin()''
#::Username suffix e.g. @mydomain.com or remaining part of ldap query: ''''',OU=people,DC=mydomain,DC=com'''''
 
#Create a LimeSurvey administrator with the same name as a AD(active directory) user account.
== newLoginForm ==
#Log in using the AD credentials(username and password).
Here you can add your own elements to the form. You should add your username/password elements, but could also add a domain selector or anything else you need. This will only be shown when the selected authentication method was chosen on the selector that is added when more then one plugin is present. When your authentication plugin does not need a form, and can not be selected as an option (like webserver authentication) you should not add a form element here.
<syntaxhighlight lang="php">
$this->getEvent()                  // Get the current event
    ->getContent($this)           // Get the content for this plugin
    ->addContent(CHtml::tag(      // And add some content to it
        'li',
        array(),  
        "<label for='user'>"  . gT("Username") . "</label><input name='user' id='user' type='text' size='40' maxlength='40' value='' />"))
    ->addContent(CHtml::tag(
        'li',
        array(),
        "<label for='password'>"  . gT("Password") . "</label><input name='password' id='password' type='password' size='40' maxlength='40' value='' />"));
</syntaxhighlight>
 
== afterLoginFormSubmit ==
When the form for this plugin was submitted, this event is called. Here you can handle setting the values to the plugin. This event is also called when there was no form submitted and form display was canceled in the beforeLogin event.
 
== newUserSession ==
This is where the real authentication takes place. You should use $this->setAuthSuccess($oUser) for a successful attempt and provide a User object. If you fail to do so it will result in an authentication failure. If you need to provide a message about why the authentication failed, you can do so by using $this->setAuthFailure($code, $message) where code is any code other than 0. The code is not used at this moment. The message should be a message in English, localised using the available tools in the plugin api. See the general plugin documenation for more information about that topic.
 
== beforeLogout ==
This is fired before the user is destroyed and the session regenerated. This is the time for cleanup / logout in external systems if needed.
 
== afterLogout ==
When the user is destroyed, you might want to redirect to a different page then currently defined. This is the right place to do so.
 
[[Category:Plugins]]

Revision as of 14:47, 12 March 2014

An authentication plugin has some additional requirements over a regular plugin. Here we list the requirements.

To make creating your own authentication plugin easier, you should extend the abstract AuthPluginBase class.

To get an idea of the possibilities, check out the three core authentication plugins (check their pages for more information about configuration options):

  • Authdb Database authentication - this is the default method for all new LimeSurvey installations.info
  • Authwebserver Webserver authentication - This one skips the login form, and provides methods for user creation. info
  • AuthLDAP LDAP authentication - Adds a custom error message and relies on a user being present in the LimeSurvey database. info

There are 6 events you can subscribe to:

beforeLogin

This is called first, and can possibly disable the loginform, for example when webserver authentication is used and we trust on that. To do this, use $this->setAuthPlugin()

newLoginForm

Here you can add your own elements to the form. You should add your username/password elements, but could also add a domain selector or anything else you need. This will only be shown when the selected authentication method was chosen on the selector that is added when more then one plugin is present. When your authentication plugin does not need a form, and can not be selected as an option (like webserver authentication) you should not add a form element here.

$this->getEvent()                  // Get the current event
     ->getContent($this)           // Get the content for this plugin
     ->addContent(CHtml::tag(      // And add some content to it
         'li', 
         array(), 
         "<label for='user'>"  . gT("Username") . "</label><input name='user' id='user' type='text' size='40' maxlength='40' value='' />"))
     ->addContent(CHtml::tag(
         'li', 
         array(), 
         "<label for='password'>"  . gT("Password") . "</label><input name='password' id='password' type='password' size='40' maxlength='40' value='' />"));

afterLoginFormSubmit

When the form for this plugin was submitted, this event is called. Here you can handle setting the values to the plugin. This event is also called when there was no form submitted and form display was canceled in the beforeLogin event.

newUserSession

This is where the real authentication takes place. You should use $this->setAuthSuccess($oUser) for a successful attempt and provide a User object. If you fail to do so it will result in an authentication failure. If you need to provide a message about why the authentication failed, you can do so by using $this->setAuthFailure($code, $message) where code is any code other than 0. The code is not used at this moment. The message should be a message in English, localised using the available tools in the plugin api. See the general plugin documenation for more information about that topic.

beforeLogout

This is fired before the user is destroyed and the session regenerated. This is the time for cleanup / logout in external systems if needed.

afterLogout

When the user is destroyed, you might want to redirect to a different page then currently defined. This is the right place to do so.