123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class LdapAuthenticationPlugin extends AuthenticationPlugin
- {
- function onInitializePlugin(){
- parent::onInitializePlugin();
- if(!isset($this->attributes['nickname'])){
-
- throw new Exception(_m('You must specify a nickname attribute.'));
- }
- if($this->password_changeable && (! isset($this->attributes['password']) || !isset($this->password_encoding))){
-
- throw new Exception(_m('If password_changeable is set, the password attribute and password_encoding must also be specified.'));
- }
- $this->ldapCommon = new LdapCommon(get_object_vars($this));
- }
- function onAutoload($cls)
- {
- switch ($cls)
- {
- case 'LdapCommon':
- require_once(INSTALLDIR.'/plugins/LdapCommon/LdapCommon.php');
- return false;
- }
- return parent::onAutoload($cls);
- }
- function onEndShowPageNotice($action)
- {
- $name = $action->trimmed('action');
- $instr = false;
- switch ($name)
- {
- case 'register':
- if($this->autoregistration) {
-
- $instr = _m('Do you have an LDAP account? Use your standard username and password.');
- }
- break;
- case 'login':
-
- $instr = _m('Do you have an LDAP account? Use your standard username and password.');
- break;
- default:
- return true;
- }
- if($instr) {
- $output = common_markup_to_html($instr);
- $action->raw($output);
- }
- return true;
- }
-
- function checkPassword($username, $password)
- {
- return $this->ldapCommon->checkPassword($username,$password);
- }
- function autoRegister($username, $nickname)
- {
- if(is_null($nickname)){
- $nickname = $username;
- }
- $entry = $this->ldapCommon->get_user($username,$this->attributes);
- if($entry){
- $registration_data = array();
- foreach($this->attributes as $sn_attribute=>$ldap_attribute){
-
-
-
- if($sn_attribute != 'password'){
- $registration_data[$sn_attribute]=$entry->getValue($ldap_attribute,'single');
- }
- }
- if(isset($registration_data['email']) && !empty($registration_data['email'])){
- $registration_data['email_confirmed']=true;
- }
- $registration_data['nickname'] = $nickname;
-
- $registration_data['password']=common_random_hexstr(16);
- return User::register($registration_data);
- }else{
-
- return false;
- }
- }
- function changePassword($username,$oldpassword,$newpassword)
- {
- return $this->ldapCommon->changePassword($username,$oldpassword,$newpassword);
- }
- function suggestNicknameForUsername($username)
- {
- $entry = $this->ldapCommon->get_user($username, $this->attributes);
- if(!$entry){
-
- $nickname = $username;
- }else{
- $nickname = $entry->getValue($this->attributes['nickname'],'single');
- if(!$nickname){
- $nickname = $username;
- }
- }
- return common_nicknamize($nickname);
- }
- function onPluginVersion(&$versions)
- {
- $versions[] = array('name' => 'LDAP Authentication',
- 'version' => GNUSOCIAL_VERSION,
- 'author' => 'Craig Andrews',
- 'homepage' => 'http://status.net/wiki/Plugin:LdapAuthentication',
- 'rawdescription' =>
-
- _m('The LDAP Authentication plugin allows for StatusNet to handle authentication through LDAP.'));
- return true;
- }
- }
|