File: Store.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 (154 lines) | stat: -rw-r--r-- 4,571 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
<?php

namespace SimpleSAML\Module\consent;

/**
 * Base class for consent storage handlers.
 *
 * @package SimpleSAMLphp
 * @author Olav Morken <olav.morken@uninett.no>
 * @author JAcob Christiansen <jach@wayf.dk>
 */

abstract class Store
{
    /**
     * Constructor for the base class.
     *
     * This constructor should always be called first in any class which implements this class.
     *
     * @param array &$config The configuration for this storage handler.
     */
    protected function __construct(&$config)
    {
        assert(is_array($config));
    }


    /**
     * Check for consent.
     *
     * This function checks whether a given user has authorized the release of the attributes identified by
     * $attributeSet from $source to $destination.
     *
     * @param string $userId        The hash identifying the user at an IdP.
     * @param string $destinationId A string which identifyes the destination.
     * @param string $attributeSet  A hash which identifies the attributes.
     *
     * @return bool True if the user has given consent earlier, false if not
     *              (or on error).
     */
    abstract public function hasConsent($userId, $destinationId, $attributeSet);


    /**
     * Save consent.
     *
     * Called when the user asks for the consent to be saved. If consent information for the given user and destination
     * already exists, it should be overwritten.
     *
     * @param string $userId        The hash identifying the user at an IdP.
     * @param string $destinationId A string which identifyes the destination.
     * @param string $attributeSet  A hash which identifies the attributes.
     *
     * @return bool True if consent is succesfully saved otherwise false.
     */
    abstract public function saveConsent($userId, $destinationId, $attributeSet);


    /**
     * Delete consent.
     *
     * Called when a user revokes consent for a given destination.
     *
     * @param string $userId        The hash identifying the user at an IdP.
     * @param string $destinationId A string which identifyes the destination.
     *
     * @return mixed Should be the number of consent deleted.
     */
    abstract public function deleteConsent($userId, $destinationId);


    /**
     * Delete all consents.
     *
     * Called when a user revokes all consents
     *
     * @param string $userId The hash identifying the user at an IdP.
     *
     * @return mixed Should be the number of consent removed
     *
     * @throws \Exception
     */
    public function deleteAllConsents($userId)
    {
        throw new \Exception('Not implemented: deleteAllConsents()');
    }


    /**
     * Get statistics for all consent given in the consent store
     *
     * @return mixed Statistics from the consent store
     *
     * @throws \Exception
     */
    public function getStatistics()
    {
        throw new \Exception('Not implemented: getStatistics()');
    }


    /**
     * Retrieve consents.
     *
     * This function should return a list of consents the user has saved.
     *
     * @param string $userId The hash identifying the user at an IdP.
     *
     * @return array Array of all destination ids the user has given consent for.
     */
    abstract public function getConsents($userId);


    /**
     * Parse consent storage configuration.
     *
     * This function parses the configuration for a consent storage method. An exception will be thrown if
     * configuration parsing fails.
     *
     * @param mixed $config The configuration.
     *
     * @return \SimpleSAML\Module\consent\Store An object which implements the \SimpleSAML\Module\consent\Store class.
     *
     * @throws \Exception if the configuration is invalid.
     */
    public static function parseStoreConfig($config)
    {
        if (is_string($config)) {
            $config = [$config];
        }

        if (!is_array($config)) {
            throw new \Exception('Invalid configuration for consent store option: '.var_export($config, true));
        }

        if (!array_key_exists(0, $config)) {
            throw new \Exception('Consent store without name given.');
        }

        $className = \SimpleSAML\Module::resolveClass(
            $config[0],
            'Consent\Store',
            '\SimpleSAML\Module\consent\Store'
        );

        unset($config[0]);
        /**
         * @psalm-suppress InvalidStringClass
         * @var \SimpleSAML\Module\consent\Store $retval
         */
        $retval = new $className($config);
        return $retval;
    }
}