Skip to content

Commit b651e65

Browse files
committed
[FEATURE] Add support for ext:rsaauth password submission
1 parent aa31980 commit b651e65

5 files changed

Lines changed: 69 additions & 12 deletions

File tree

Classes/Backend/ConfirmationController.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,27 @@ protected function requestAction(ServerRequestInterface $request, ConfirmationBu
102102
if (!empty($bundle->getRequestMetaData()->getReturnUrl())) {
103103
$view->assign('cancelUri', (string)$this->buildActionUriFromBundle('cancel', $bundle));
104104
}
105+
$this->applyAdditionalJavaScriptModules();
105106
return new HtmlResponse($view->render());
106107
}
107108
// @todo Add JSON handling
108109
return new JsonResponse([], 500);
109110
}
110111

111112
/**
112-
* @todo ext:rsaauth not working yet in TYPO3 v9, extract to optional "controller enhancer"
113+
* Load additional JavaScript modules/libraries (e.g. required for `ext:rsaauth` in TYPO3 v9)
113114
*/
114-
protected function applyRsaAuth()
115+
protected function applyAdditionalJavaScriptModules(): void
115116
{
116-
$isEnabled = ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] ?? '') === 'rsa';
117-
if (!$isEnabled) {
118-
return;
119-
}
120-
$rsaEncryptionEncoder = GeneralUtility::makeInstance(\TYPO3\CMS\Rsaauth\RsaEncryptionEncoder::class);
121-
$rsaEncryptionEncoder->enableRsaEncryption(true);
122-
// PageRender contains JavaScript libs and inline code...
117+
(GeneralUtility::makeInstance(ExternalServiceAdapter::class))->emitLoginProviderSignal();
123118
}
124119

125120
protected function verifyAction(ServerRequestInterface $request, ConfirmationBundle $bundle): ResponseInterface
126121
{
127-
$confirmationPassword = (string)($request->getParsedBody()['confirmationPassword'] ?? '');
122+
$parsedBody = $request->getParsedBody();
123+
$confirmationPassword = empty($parsedBody['confirmationPasswordInternal'])
124+
? (string)($parsedBody['confirmationPassword'] ?? '') // default field
125+
: $parsedBody['confirmationPasswordInternal']; // filled e.g. by `ext:rsaauth`
128126
$loggerContext = $this->createLoggerContext($bundle, $this->user);
129127

130128
if (!$this->isJsonRequest($request)) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
declare(strict_types = 1);
3+
namespace FriendsOfTYPO3\SudoMode\Backend;
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
use TYPO3\CMS\Backend\LoginProvider\UsernamePasswordLoginProvider;
19+
use TYPO3\CMS\Core\Page\PageRenderer;
20+
use TYPO3\CMS\Core\Utility\GeneralUtility;
21+
use TYPO3\CMS\Extbase\Object\ObjectManager;
22+
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
23+
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
24+
25+
/**
26+
* Aims to adapt external services or extensions to be working with `ext:sudo_mode`.
27+
*/
28+
class ExternalServiceAdapter
29+
{
30+
public function emitLoginProviderSignal(PageRenderer $pageRenderer = null): void
31+
{
32+
$this->getSignalSlotDispatcher()->dispatch(
33+
UsernamePasswordLoginProvider::class,
34+
UsernamePasswordLoginProvider::SIGNAL_getPageRenderer,
35+
[$pageRenderer ?? $this->getPageRenderer()]
36+
);
37+
}
38+
39+
public function getSignalSlotDispatcher(): Dispatcher
40+
{
41+
return $this->getObjectManager()->get(Dispatcher::class);
42+
}
43+
44+
public function getObjectManager(): ObjectManagerInterface
45+
{
46+
return GeneralUtility::makeInstance(ObjectManager::class);
47+
}
48+
49+
public function getPageRenderer(): PageRenderer
50+
{
51+
return GeneralUtility::makeInstance(PageRenderer::class);
52+
}
53+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ TYPO3 extension providing "sudo mode" to mitigate unintended modifications.
55
> :information_source: **beta** state - feel free to test and provide feedback for this package
66
77
* TYPO3 v10 LTS
8-
* TYPO3 v9 LTS (`ext:rsaauth` not supported, yet)
8+
* TYPO3 v9 LTS (supports `ext:rsaauth` as well)
99

1010
## Installation
1111

Resources/Private/Templates/Backend/Request.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ <h4 class="modal-title">
2929
<f:form id="confirm-sudo" class="form" method="post" actionUri="{verifyUri}">
3030
<div class="form-group">
3131
<div class="form-control-holder">
32-
<f:form.password name="confirmationPassword" class="form-control" placeholder="Password" />
32+
<f:form.password name="confirmationPassword" class="form-control" placeholder="Password"
33+
additionalAttributes="{data-rsa-encryption: 'confirmationPasswordInternal'}" />
34+
<!-- Internal password field, e.g. used for ext:rsaauth -->
35+
<f:form.hidden name="confirmationPasswordInternal" id="confirmationPasswordInternal" />
3336
</div>
3437
</div>
3538
</f:form>

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"issues": "https://github.com/FriendsOfTYPO3/sudo-mode/issues"
1818
},
1919
"require": {
20+
"ext-dom": "*",
21+
"ext-libxml": "*",
22+
"ext-xml": "*",
2023
"typo3/cms-core": "^9.5 || 10.4.x@dev"
2124
},
2225
"autoload": {

0 commit comments

Comments
 (0)