File: DefaultAuth.php

package info (click to toggle)
simplesamlphp 1.19.7-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,920 kB
  • sloc: php: 202,044; javascript: 14,867; xml: 2,700; sh: 225; perl: 82; makefile: 70; python: 5
file content (169 lines) | stat: -rw-r--r-- 4,521 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php

declare(strict_types=1);

namespace SimpleSAML\Auth;

use Exception;
use SimpleSAML\Module\saml\Auth\Source\SP;
use SimpleSAML\Session;
use SimpleSAML\Utils;

/**
 * Implements the default behaviour for authentication.
 *
 * This class contains an implementation for default behaviour when authenticating. It will
 * save the session information it got from the authentication client in the users session.
 *
 * @author Olav Morken, UNINETT AS.
 * @package SimpleSAMLphp
 *
 * @deprecated This class will be removed in SSP 2.0.
 */

class DefaultAuth
{
    /**
     * @deprecated This method will be removed in SSP 2.0. Use Source::initLogin() instead.
     * @param string $authId
     * @param string $return
     * @param string|null $errorURL
     * @param array $params
     * @return void
     */
    public static function initLogin(
        $authId,
        $return,
        $errorURL = null,
        array $params = []
    ) {

        $as = self::getAuthSource($authId);
        $as->initLogin($return, $errorURL, $params);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0. Please use
     * State::getPersistentAuthData() instead.
     * @param array &$state
     * @return array
     */
    public static function extractPersistentAuthState(array &$state)
    {
        return State::getPersistentAuthData($state);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0. Please use Source::loginCompleted() instead.
     * @param array $state
     * @return void
     */
    public static function loginCompleted($state)
    {
        Source::loginCompleted($state);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0.
     * @param string $returnURL
     * @param string $authority
     * @return void
     */
    public static function initLogoutReturn($returnURL, $authority)
    {
        assert(is_string($returnURL));
        assert(is_string($authority));

        $session = Session::getSessionFromRequest();

        $state = $session->getAuthData($authority, 'LogoutState');
        $session->doLogout($authority);

        $state['\SimpleSAML\Auth\DefaultAuth.ReturnURL'] = $returnURL;
        $state['LogoutCompletedHandler'] = [get_class(), 'logoutCompleted'];

        $as = Source::getById($authority);
        if ($as === null) {
            // The authority wasn't an authentication source...
            self::logoutCompleted($state);
        }

        $as->logout($state);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0.
     * @param string $returnURL
     * @param string $authority
     * @return void
     */
    public static function initLogout($returnURL, $authority)
    {
        assert(is_string($returnURL));
        assert(is_string($authority));

        self::initLogoutReturn($returnURL, $authority);

        Utils\HTTP::redirectTrustedURL($returnURL);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0.
     * @param array $state
     * @return void
     */
    public static function logoutCompleted($state)
    {
        assert(is_array($state));
        assert(array_key_exists('\SimpleSAML\Auth\DefaultAuth.ReturnURL', $state));

        Utils\HTTP::redirectTrustedURL($state['\SimpleSAML\Auth\DefaultAuth.ReturnURL']);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0. Please use Source::logoutCallback() instead.
     * @param array $state
     * @return void
     */
    public static function logoutCallback($state)
    {
        Source::logoutCallback($state);
    }


    /**
     * @deprecated This method will be removed in SSP 2.0. Please use
     * \SimpleSAML\Module\saml\Auth\Source\SP::handleUnsolicitedAuth() instead.
     * @param string $authId
     * @param array $state
     * @param string $redirectTo
     * @return void
     */
    public static function handleUnsolicitedAuth($authId, array $state, $redirectTo)
    {
        SP::handleUnsolicitedAuth($authId, $state, $redirectTo);
    }


    /**
     * Return an authentication source by ID.
     *
     * @param string $id The id of the authentication source.
     * @return Source The authentication source.
     * @throws \Exception If the $id does not correspond with an authentication source.
     */
    private static function getAuthSource($id): Source
    {
        $as = Source::getById($id);
        if ($as === null) {
            throw new Exception('Invalid authentication source: ' . $id);
        }
        return $as;
    }
}