Files
DomFramework/authsympa.php
Dominique Fournier 17168aaaef Update gettext : add spaces
DomCi : remove line too longs on all the files


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5280 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
2019-05-23 14:19:30 +00:00

112 lines
4.0 KiB
PHP

<?php
/** DomFramework
@package domframework
@author Dominique Fournier <dominique@fournier38.fr> */
require_once ("domframework/auth.php");
/** User authentication against SYMPA server
Sympa is a mailling list server. It can handle authentication with
- a username (a email adress)
- a password
- a list to check if the user is recorded in
- a Sympa SOAP server WSDL
- the part of list which should be test : subscriber, owner, editor
It use the SOAP protocol. So the PHP SOAP library is needed and the network
must be open between the Web server and the Sympa server.
POC :
$auth = new authsympa ();
$auth->wsdl = "https://lists.domain.tld/sympa/wsdl";
$auth->list = "listtest@lists.domain.tld";
$auth->connect ();
var_dump ($auth->authentication ("user@domain.tld", "Pa$$word!"));
*/
class authsympa extends auth
{
/** URL of the WSDL Sympa server */
public $wsdl = null;
/** Mailling list to be checked if user is present */
public $list = null;
/** Function of the user in the mailling list
can be subscriber, owner, editor */
public $function = "subscriber";
/** Soap Client identifier */
private $client = null;
/** Temporary auth key used betwwen commands */
private $authkey = null;
/** Email of the user if the authentication is correct */
private $details = null;
/** Check if the SOAP module is available in PHP */
public function __construct ()
{
if (! class_exists ("SoapClient"))
throw new \Exception (dgettext ("domframework",
"No SOAP PHP library available"), 500);
}
/** Connect to the Sympa server */
public function connect ()
{
if ($this->wsdl === null)
throw new \Exception (dgettext ("domframework",
"No WSDL provided to Sympa auth"), 401);
$this->client = new \SoapClient($this->wsdl);
}
/** Try to authenticate the email/password of the user
@param string $email Email to authenticate
@param string $password Password to authenticate */
public function authentication ($email, $password)
{
if ($this->client === null)
throw new \Exception (dgettext ("domframework",
"The SOAP connection is not opened"), 401);
if ($this->list === null)
throw new \Exception (dgettext ("domframework",
"The list to check is not defined"), 401);
$this->authkey = $this->client->login ($email, $password);
if ($this->authkey === null)
throw new \Exception (dgettext ("domframework",
"Can't connect with provided email/password to sympa"),
401);
$rc = $this->client->authenticateAndRun ($email, $this->authkey,
'amI', array ($this->list, $this->function, $email));
if ($rc === null || $rc === false)
throw new \Exception (dgettext ("domframework",
"User not in Sympa list or bad password"), 401);
$this->details = array ("email"=>$email);
return $rc;
}
/** Return all the parameters recorded for the authenticate user */
public function getdetails ()
{
return $this->details;
}
/** Method to change the password
@param string $oldpassword The old password (to check if the user have the
rights to change the password)
@param string $newpassword The new password to be recorded */
public function changepassword ($oldpassword, $newpassword)
{
throw new \Exception (dgettext ("domframework",
"The password can't be change for SYMPA users"),
405);
}
/** Method to overwrite the password (without oldpassword check)
Must be reserved to the administrators. For the users, use changepassword
method
@param string $email the user identifier to select
@param string $newpassword The new password to be recorded */
public function overwritepassword ($email, $newpassword)
{
throw new \Exception (dgettext ("domframework",
"The password can't be overwrite for Sympa users"),
405);
}
}