1<?php 2 3/** 4 * Authentication backend using a Sympa Soap server 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author David Pepin <sympa-authors AT cru.fr> 7 * Version: 1.3 8 * last modified: 2008-02-15 9 * 10 * Work based on : 11 * ssl authentication backend: 12 * @author Dominique Launay <dominique.launay AT cru.fr> 13 * htaccess authentication backend: 14 * @author Samuele Tognini<samuele@cli.di.unipi.it 15 * 16 * Soap has to be enabled in php to use SoapClient 17 * 18 **/ 19 20 21define('DOKU_AUTH', dirname(__FILE__)); 22require_once(DOKU_AUTH.'/basic.class.php'); 23 24 25 26class auth_sympa extends auth_basic { 27 var $users = null; 28 var $sympaDefaultGroup = null; 29 var $soap_client = null; 30 var $sympaSoapService = null; 31 /** 32 * 33 * Constructor 34 * 35 * @author David Pepin <sympa-authors AT cru.fr> 36 * 37 **/ 38 function auth_sympa() { 39 global $conf; 40 if (method_exists($this, 'auth_basic')) 41 parent::auth_basic(); 42 43 // check if the server configuration has correctly been done 44 if (empty($conf['plugin']['sympaauth']['sympaSoapService'])) { 45 $this->success = false; 46 return; 47 } 48 if (isset($conf['defaultgroup'])) { 49 $this->sympaDefaultGroup = $conf['defaultgroup']; 50 } 51 52 if(isset($_SESSION[DOKU_COOKIE]['auth']['user'])){ 53 $this->success = true; 54 return ; 55 } 56 57 $this->sympaSoapService = $conf['plugin']['sympaauth']['sympaSoapService']; 58 try{ 59 $this->soap_client = new SoapClient($this->sympaSoapService); 60 }catch(SoapFault $fault){ 61 $this->success = false; 62 return; 63 } 64 65 $this->success = true; 66 return; 67 } 68 69 70 71 /** 72 * Checks user and password using the Soap frontend to Sympa 73 * 74 * @author David Pepin <sympa-authors AT cru.fr> 75 * based on nusoap.php which provides functions to access sympa through soap 76 * 77 **/ 78 79 function checkPass($user,$pass){ 80 global $conf; 81 if (!isset($this->soap_client) || empty($this->soap_client)){ 82 $this->soap_client = new SoapClient($conf['plugin']['sympaauth']['sympaSoapService']); 83 } 84 try{ 85 $auth_key = $this->soap_client->login($user,$pass); 86 }catch (SoapFault $fault){ 87 return(false); 88 }; 89 if(!empty($auth_key)) { 90 $_SESSION['sympapass'] = $auth_key; 91 return(true); 92 }else{ 93 return(false); 94 } 95 } 96 97 98 99 /** 100 * Return user info 101 * 102 * Accessing to sympa is done through the nusoap library 103 * 104 * The returned field are : 105 * 106 * name string full name of the user 107 * mail string email addres of the user 108 * groups array list of groups the user is in 109 * 110 * @author David Pepin <sympa-authors AT cru.fr> 111 * 112 **/ 113 function getUserData($user) { 114 // Name is mail 115 $name = $user; 116 117 // mail address 118 $mail = $user; 119 120 121 if(isset($_SESSION[DOKU_COOKIE]['auth']['info'])) { 122 return ($_SESSION[DOKU_COOKIE]['auth']['info']); 123 }else{ 124 // groups the person belongs to 125 $grps = array(); 126 try{ 127 $res = $this->soap_client->authenticateAndRun($user,$_SESSION['sympapass'],'complexWhich'); 128 }catch(SoapFault $fault){ 129 return false; 130 } 131 if (isset($res) && gettype($res) == 'array') { 132 foreach ($res as $list) { 133 if (empty($grps[0])) { 134 $grps[0] = $list->listAddress; 135 }else{ 136 array_unshift($grps,$list->listAddress); 137 } 138 if($list->isOwner == 'true'){ 139 $listrequest = preg_replace('/@/','-request@',$list->listAddress); 140 array_unshift($grps,$listrequest); 141 } 142 if ($list->isEditor == 'true') { 143 $listeditor = preg_replace('/@/','-editor@',$list->listAddress); 144 array_unshift($grps,$listeditor); 145 } 146 } 147 } 148 //sympadefaultgroup is put in first position, if set 149 if(isset($this->sympaDefaultGroup)) { 150 (empty($grps[0]) ? $grps[0] = $this->sympaDefaultGroup : array_unshift($grps,$this->sympaDefaultGroup) ); 151 } 152 153 // Return the collected pieces of information about the user 154 $this->users[$user] = compact('name','mail','grps'); 155 return (isset($this->users[$user]) ? $this->users[$user] : false); 156 } 157 } 158 159 160 /** 161 * Logoff user : 162 * 163 * everything that was about the session is unset 164 * 165 * @author David Pepin <sympa-authors AT cru.fr> 166 * 167 **/ 168 function logOff() { 169 unset($this->soap_client); 170 unset($_SESSION['sympapass']); 171 exit; 172 } 173 174 function server() { 175 return($this->sympaSoapService); 176 } 177} 178