1<?php
2
3/**
4 * DokuWiki Plugin authsaml (Auth Component).
5 *
6 * @author  Sixto Martin <sixto.martin.garcia@gmail.com>
7 * @author  Andreas Aakre Solberg, UNINETT, http://www.uninett.no
8 * @author  François Kooman
9 * @author  Thijs Kinkhorst, Universiteit van Tilburg
10 * @author  Jorge Hervás <jordihv@gmail.com>, Lukas Slansky <lukas.slansky@upce.cz>
11 * @license GPL2 http://www.gnu.org/licenses/gpl.html
12 * @link https://github.com/pitbulk/dokuwiki-saml
13 */
14
15// must be run within Dokuwiki
16if (! defined('DOKU_INC'))
17    die();
18
19
20class auth_plugin_authsaml extends DokuWiki_Auth_Plugin
21{
22    /**
23     * simplesamlphp auth instance
24     *
25     * @var object
26     */
27    protected $saml;
28
29
30    /**
31     * Constructor.
32     */
33    public function __construct()
34    {
35        global $conf;
36        parent::__construct();
37
38        // $this->cando['external'] = true;
39
40        $this->cando['external'] = true;
41        $this->cando['logoff'] = true;
42        $this->success = true;
43
44        require_once('saml.php');
45        $this->loadConfig();
46        $this->saml = new saml_handler($this->conf);
47    }
48
49
50    /**
51     * Get user data
52     *
53     * @return string|null
54     */
55
56    public function getUserData($user, $requireGroups = true)
57    {
58        return $this->saml->getUserData($user);
59    }
60
61
62    public function checkPass($user, $pass) {
63        return $this->saml->checkPass($user);
64    }
65
66
67    /**
68     * {@inheritdoc}
69     * @see DokuWiki_Auth_Plugin::trustExternal()
70     */
71    public function trustExternal($user, $pass, $sticky = false)
72    {
73        $this->saml->get_ssp_instance();
74
75        if ($this->saml->ssp->isAuthenticated()) {
76            $username = $this->saml->getUsername();
77            $this->saml->login($username);
78            return true;
79        }
80
81        return false;
82    }
83
84}
85