1<?php
2/**
3 * Abstract IMSP authentication class.
4 *
5 * Required Parameters:<pre>
6 *   'username'  Username to logon to IMSP server as.
7 *   'password'  Password for current user.
8 *   'server'    The hostname of the IMSP server.
9 *   'port'      The port of the IMSP server.</pre>
10 *
11 * Copyright 2003-2017 Horde LLC (http://www.horde.org/)
12 *
13 * See the enclosed file COPYING for license information (LGPL). If you
14 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
15 *
16 * @author  Michael Rubinsky <mrubinsk@horde.org>
17 * @package Horde_Imsp
18 */
19abstract class Horde_Imsp_Auth_Base
20{
21    protected $_params = array();
22
23    /**
24     * Class variable to hold the resulting Horde_Imsp object
25     *
26     * @var Horde_Imsp_Client_Base
27     */
28    protected $_imsp;
29
30    /**
31     * Constructor
32     *
33     * @param array $params
34     */
35    public function __construct(array $params = array())
36    {
37        $this->_params = $params;
38    }
39
40    /**
41     * Attempts to login to IMSP server.
42     *
43     * @param Horde_Imsp_Client_Base $client  The Imsp client connection.
44     * @param boolean $login                  Remain logged in after auth?
45     *
46     * @return boolean
47     */
48    public function authenticate(Horde_Imsp_Client_Base $client, $login = true)
49    {
50        $this->_imsp = $client;
51        if(!$this->_authenticate()) {
52            return false;
53        }
54        if (!$login) {
55            $this->_imsp->logout();
56        }
57
58        return true;
59    }
60
61    /**
62     * Private authentication function. Provides actual authentication code.
63     *
64     * @return boolean
65     */
66    abstract protected function _authenticate();
67
68    /**
69     * Returns the type of this driver.
70     *
71     *
72     * @return string Type of IMSP_Auth driver instance
73     */
74    abstract public function getDriverType();
75
76    /**
77     * Force a logout from the underlying IMSP stream.
78     *
79     */
80    abstract public function logout();
81}
82