Conditions | 3 |
Paths | 2 |
Total Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
15 | public function actionMapping() |
||
16 | { |
||
17 | $this->requireAdmin(false); |
||
18 | |||
19 | Saml::getInstance()->loadSaml2Container(); |
||
20 | $settings = Saml::getInstance()->getSettings(); |
||
21 | |||
22 | $userId = \Craft::$app->request->getRequiredParam('userId'); |
||
23 | $providerId = \Craft::$app->request->getRequiredParam('providerId'); |
||
24 | |||
25 | $user = \Craft::$app->users->getUserById($userId); |
||
26 | $provider = Saml::getInstance()->getProvider()->find([ |
||
27 | 'id' => $providerId, |
||
28 | ])->one(); |
||
29 | |||
30 | if (! $user && ! $provider) { |
||
31 | return $this->asErrorJson('Provider or user is invalid'); |
||
32 | } |
||
33 | |||
34 | Saml::getInstance()->getResponseAssertion()->setAssertionAttributes( |
||
35 | $user, |
||
36 | $assertion = new Assertion(), |
||
37 | $provider, |
||
38 | $settings |
||
39 | ); |
||
40 | $doc = $assertion->toXML()->ownerDocument; |
||
41 | $doc->preserveWhiteSpace = false; |
||
42 | $doc->formatOutput = true; |
||
43 | return $this->asJson([ |
||
44 | 'xml' => $doc->saveXML(), |
||
45 | ]); |
||
46 | } |
||
47 | } |
||
48 |