Skip to content

Commit 0836bc4

Browse files
author
Dani Pfeil
committed
fix bug using BE form with user/password form
additional reformating
1 parent 3ffeb96 commit 0836bc4

19 files changed

+1057
-618
lines changed

Classes/Backend/LoginProvider/SamlLoginProvider.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33

44
namespace DanielPfeil\Samlauthentication\Backend\LoginProvider;
55

6-
7-
use TYPO3\CMS\Backend\Authentication\PasswordReset;
86
use TYPO3\CMS\Backend\Controller\LoginController;
97
use TYPO3\CMS\Backend\LoginProvider\LoginProviderInterface;
108
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
119
use TYPO3\CMS\Core\Page\PageRenderer;
1210
use TYPO3\CMS\Core\Utility\GeneralUtility;
13-
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
1411
use TYPO3\CMS\Fluid\View\StandaloneView;
1512

1613
class SamlLoginProvider implements LoginProviderInterface
@@ -26,8 +23,12 @@ public function render(StandaloneView $view, PageRenderer $pageRenderer, LoginCo
2623

2724
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/UserPassLogin');
2825

29-
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:samlauthentication/Resources/Private/Templates/Backend/samllogin.html'));
26+
$view->setTemplatePathAndFilename(
27+
GeneralUtility::getFileAbsFileName(
28+
'EXT:samlauthentication/Resources/Private/Templates/Backend/samllogin.html'
29+
)
30+
);
3031

3132
$view->assign('enablePasswordReset', false);
3233
}
33-
}
34+
}

Classes/Domain/Model/Serviceprovider.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct()
6666
/**
6767
* @param int $uid
6868
*/
69-
public function setUid($uid)
69+
public function setUid(int $uid)
7070
{
7171
if (!$this->uid && $uid > 0) {
7272
$this->uid = $uid;
@@ -190,8 +190,9 @@ public function getPrefix(): string
190190
*/
191191
public function setPrefix(?string $prefix)
192192
{
193-
if(is_null($prefix))
193+
if (is_null($prefix)) {
194194
$prefix = "";
195+
}
195196
$this->prefix = $prefix;
196197
}
197198

Classes/Enum/AuthenticationStatus.php

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
<?php
2-
/**
3-
* Copyright (C) 2018 Daniel Pfeil <[email protected]
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*
18-
*/
19-
20-
namespace DanielPfeil\Samlauthentication\Enum;
21-
22-
class AuthenticationStatus
23-
{
24-
const SUCCESS_BREAK = 200;
25-
const FAIL_CONTINUE = 100;
26-
const SUCCESS_CONTINUE = 10;
27-
const FAIL_BREAK = 0;
28-
}
1+
<?php
2+
/**
3+
* Copyright (C) 2018 Daniel Pfeil <[email protected]
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
namespace DanielPfeil\Samlauthentication\Enum;
21+
22+
class AuthenticationStatus
23+
{
24+
const SUCCESS_BREAK = 200;
25+
const FAIL_CONTINUE = 100;
26+
const SUCCESS_CONTINUE = 10;
27+
const FAIL_BREAK = 0;
28+
}

Classes/Enum/ServiceProviderContext.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
namespace DanielPfeil\Samlauthentication\Enum;
2121

22-
2322
class ServiceProviderContext
2423
{
2524
const FRONT_END = "FE";
2625
const BACK_END = "BE";
2726
const FRONT_AND_BACK_END = "FB";
28-
}
27+
}

Classes/Enum/ServiceProviderType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ class ServiceProviderType
2323
{
2424
const APACHE_SHIBBOLETH = 1;
2525
const SIMPLESAMLPHP = 2;
26-
}
26+
}
+100-77
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,100 @@
1-
<?php
2-
/**
3-
* Copyright (C) 2018 Daniel Pfeil <[email protected]
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*
18-
*/
19-
20-
namespace DanielPfeil\Samlauthentication\Service;
21-
22-
use DanielPfeil\Samlauthentication\Enum\AuthenticationStatus;
23-
use DanielPfeil\Samlauthentication\Utility\FactoryUtility;
24-
use DanielPfeil\Samlauthentication\Utility\ServiceProviderUtility;
25-
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
26-
27-
final class AuthenticationService extends \TYPO3\CMS\Core\Authentication\AbstractAuthenticationService
28-
{
29-
final public function authUser(array $user): int
30-
{
31-
$serviceProviderUtility = ServiceProviderUtility::getInstance();
32-
33-
$activeServiceProviders = $serviceProviderUtility->getActive(FactoryUtility::getServiceProviderModels());
34-
35-
foreach ($activeServiceProviders as $activeServiceProvider) {
36-
$samlComponent = FactoryUtility::getSAMLUtility($activeServiceProvider);
37-
$samlUserData = $samlComponent->getUserData($activeServiceProvider);
38-
39-
if (TYPO3_MODE === "FE") {
40-
$samlUsername = $samlUserData["fe_users"]["username"]->getValue();
41-
} else {
42-
$samlUsername = $samlUserData["be_users"]["username"]->getValue();
43-
}
44-
45-
if ($samlUsername == $user["username"]) {
46-
return AuthenticationStatus::SUCCESS_BREAK;
47-
}
48-
}
49-
return AuthenticationStatus::FAIL_CONTINUE;
50-
}
51-
52-
final public function getUser()
53-
{
54-
//todo check if parent is needed before or after?
55-
$user = parent::fetchUserRecord($this->login["uname"]);
56-
if (!$user) {
57-
try {
58-
$serviceProviderUtility = ServiceProviderUtility::getInstance();
59-
$activeServiceProviders = $serviceProviderUtility->getActive(FactoryUtility::getServiceProviderModels());
60-
61-
foreach ($activeServiceProviders as $activeServiceProvider) {
62-
$samlComponent = FactoryUtility::getSAMLUtility($activeServiceProvider);
63-
$storedSuccessfull = $samlComponent->saveUserData($activeServiceProvider);
64-
if ($storedSuccessfull) {
65-
break;
66-
}
67-
}
68-
69-
$user = parent::fetchUserRecord($this->login["uname"]);
70-
} catch (\Exception $exception) {
71-
//TODO implement
72-
DebuggerUtility::var_dump($exception);
73-
}
74-
}
75-
return $user;
76-
}
77-
}
1+
<?php
2+
/**
3+
* Copyright (C) 2018 Daniel Pfeil <[email protected]
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
namespace DanielPfeil\Samlauthentication\Service;
21+
22+
use DanielPfeil\Samlauthentication\Enum\AuthenticationStatus;
23+
use DanielPfeil\Samlauthentication\Utility\FactoryUtility;
24+
use DanielPfeil\Samlauthentication\Utility\ServiceProviderUtility;
25+
use TYPO3\CMS\Core\Utility\GeneralUtility;
26+
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
27+
28+
final class AuthenticationService extends \TYPO3\CMS\Core\Authentication\AbstractAuthenticationService
29+
{
30+
final public function authUser(array $user): int
31+
{
32+
if (!$this->isResponsible()) {
33+
return AuthenticationStatus::FAIL_CONTINUE;
34+
}
35+
36+
$serviceProviderUtility = ServiceProviderUtility::getInstance();
37+
38+
$activeServiceProviders = $serviceProviderUtility->getActive(FactoryUtility::getServiceProviderModels());
39+
40+
foreach ($activeServiceProviders as $activeServiceProvider) {
41+
$samlComponent = FactoryUtility::getSAMLUtility($activeServiceProvider);
42+
$samlUserData = $samlComponent->getUserData($activeServiceProvider);
43+
44+
if (TYPO3_MODE === "FE") {
45+
$samlUsername = $samlUserData["fe_users"]["username"]->getValue();
46+
} else {
47+
$samlUsername = $samlUserData["be_users"]["username"]->getValue();
48+
}
49+
50+
if ($samlUsername == $user["username"]) {
51+
return AuthenticationStatus::SUCCESS_BREAK;
52+
}
53+
}
54+
return AuthenticationStatus::FAIL_CONTINUE;
55+
}
56+
57+
final public function getUser()
58+
{
59+
if (!$this->isResponsible()) {
60+
return false;
61+
}
62+
63+
//todo check if parent is needed before or after?
64+
$user = parent::fetchUserRecord($this->login["uname"]);
65+
if (!$user) {
66+
try {
67+
$serviceProviderUtility = ServiceProviderUtility::getInstance();
68+
$activeServiceProviders = $serviceProviderUtility->getActive(
69+
FactoryUtility::getServiceProviderModels()
70+
);
71+
72+
foreach ($activeServiceProviders as $activeServiceProvider) {
73+
$samlComponent = FactoryUtility::getSAMLUtility($activeServiceProvider);
74+
$storedSuccessfull = $samlComponent->saveUserData($activeServiceProvider);
75+
if ($storedSuccessfull) {
76+
break;
77+
}
78+
}
79+
80+
$user = parent::fetchUserRecord($this->login["uname"]);
81+
} catch (\Exception $exception) {
82+
//TODO implement
83+
DebuggerUtility::var_dump($exception);
84+
}
85+
}
86+
return $user;
87+
}
88+
89+
private function isResponsible(): bool
90+
{
91+
if (GeneralUtility::_POST("login-provider") === "samlauthentication" &&
92+
isset($this->login["uname"]) &&
93+
isset($this->login["status"]) &&
94+
$this->login["status"] === "login"
95+
) {
96+
return true;
97+
}
98+
return false;
99+
}
100+
}

0 commit comments

Comments
 (0)