1 | <?php |
||
28 | class User |
||
29 | { |
||
30 | use AssertionTrait; |
||
31 | /** |
||
32 | * @var FieldLayout|null |
||
33 | */ |
||
34 | private $fieldLayout; |
||
35 | /** |
||
36 | * @var Field[] |
||
37 | */ |
||
38 | private $fields = []; |
||
39 | |||
40 | /** |
||
41 | * @param SamlResponse $response |
||
42 | * @return UserElement |
||
43 | * @throws InvalidMessage |
||
44 | * @throws UserException |
||
45 | */ |
||
46 | public function getByResponse(SamlResponse $response, ProviderRecord $serviceProvider) |
||
47 | { |
||
48 | |||
49 | $assertion = $this->getFirstAssertion($response, $serviceProvider); |
||
50 | |||
51 | if (! $assertion->getNameId()) { |
||
52 | throw new InvalidMessage('Name ID is missing.'); |
||
53 | } |
||
54 | |||
55 | Saml::debug('NameId: ' . $assertion->getNameId()->getValue()); |
||
56 | /** |
||
57 | * Get username from the NameID |
||
58 | * |
||
59 | * @todo Give an option to map another attribute value to $username (like email) |
||
60 | */ |
||
61 | $username = $assertion->getNameId()->getValue(); |
||
62 | |||
63 | return $this->find($username); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param ProviderIdentityRecord $identity |
||
68 | * @return bool |
||
69 | * @throws UserException |
||
70 | * @throws \Throwable |
||
71 | */ |
||
72 | public function login(\flipbox\saml\sp\records\ProviderIdentityRecord $identity) |
||
95 | |||
96 | /** |
||
97 | * @param UserElement $user |
||
98 | * @param SamlResponse $response |
||
99 | * @param ProviderRecord $idp |
||
100 | * @param Settings $settings |
||
101 | * @throws UserException |
||
102 | * @throws \Throwable |
||
103 | * @throws \craft\errors\ElementNotFoundException |
||
104 | * @throws \yii\base\Exception |
||
105 | */ |
||
106 | 3 | public function sync( |
|
107 | UserElement $user, |
||
108 | SamlResponse $response, |
||
109 | ProviderRecord $idp, |
||
110 | ProviderRecord $sp, |
||
111 | Settings $settings |
||
112 | ) { |
||
113 | |||
114 | // enable and transform the user |
||
115 | 3 | $this->construct( |
|
116 | 3 | $user, |
|
117 | 1 | $response, |
|
118 | 1 | $idp, |
|
119 | 1 | $sp, |
|
120 | 1 | $settings |
|
121 | ); |
||
122 | |||
123 | // Save |
||
124 | 3 | $this->save($user); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param UserElement $user |
||
129 | * @return bool |
||
130 | * @throws UserException |
||
131 | * @throws \Throwable |
||
132 | * @throws \craft\errors\ElementNotFoundException |
||
133 | * @throws \yii\base\Exception |
||
134 | */ |
||
135 | 3 | protected function save(UserElement $user) |
|
136 | { |
||
137 | 3 | if (! \Craft::$app->getElements()->saveElement($user)) { |
|
138 | Saml::error( |
||
139 | 'User save failed: ' . \json_encode($user->getErrors()) |
||
140 | ); |
||
141 | throw new UserException("User save failed: " . \json_encode($user->getErrors())); |
||
142 | } |
||
143 | |||
144 | return true; |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Response Based Methods |
||
149 | */ |
||
150 | |||
151 | /** |
||
152 | * @param UserElement $user |
||
153 | * @param SamlResponse $response |
||
154 | * @param ProviderRecord $idp |
||
155 | * @param Settings $settings |
||
156 | * @throws UserException |
||
157 | * @throws \Throwable |
||
158 | */ |
||
159 | 3 | protected function construct( |
|
199 | |||
200 | /** |
||
201 | * @param UserElement $user |
||
202 | * @param SamlResponse $response |
||
203 | * @return UserElement |
||
204 | */ |
||
205 | 3 | protected function transform( |
|
245 | |||
246 | /** |
||
247 | * @param UserElement $user |
||
248 | * @param $attributeName |
||
249 | * @param $attributeValue |
||
250 | * @param $craftProperty |
||
251 | */ |
||
252 | 3 | protected function assignProperty( |
|
288 | |||
289 | /** |
||
290 | * @param UserElement $user |
||
291 | * @return Field|null |
||
292 | */ |
||
293 | 3 | protected function getFieldLayoutField(UserElement $user, $fieldHandle) |
|
309 | |||
310 | /** |
||
311 | * @param UserElement $user |
||
312 | * @param string $name |
||
313 | * @param mixed $value |
||
314 | */ |
||
315 | 3 | private function setSimpleProperty(UserElement $user, $name, $value) |
|
334 | |||
335 | /************************************************** |
||
336 | * Craft User Methods |
||
337 | **************************************************/ |
||
338 | |||
339 | /** |
||
340 | * @param $username |
||
341 | * @return UserElement |
||
342 | * @throws UserException |
||
343 | */ |
||
344 | protected function find($username) |
||
348 | |||
349 | /** |
||
350 | * @param $username |
||
351 | * @return UserElement |
||
352 | * @throws UserException |
||
353 | */ |
||
354 | protected function forceGet($username) |
||
386 | |||
387 | /** |
||
388 | * @param $usernameOrEmail |
||
389 | * @param bool $archived |
||
390 | * @return array|bool|\craft\base\ElementInterface|UserElement|null |
||
391 | */ |
||
392 | protected function getByUsernameOrEmail($usernameOrEmail, $archived = false) |
||
408 | } |
||
409 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.