refactoring

This commit is contained in:
Roland Gruber 2025-10-02 21:17:50 +02:00
parent 9c004d2db2
commit c7bf812759
2 changed files with 22 additions and 11 deletions

View file

@ -14,6 +14,7 @@ use Facile\OpenIDClient\Issuer\IssuerBuilder;
use GuzzleHttp\Psr7\ServerRequest; use GuzzleHttp\Psr7\ServerRequest;
use htmlResponsiveRow; use htmlResponsiveRow;
use LAM\LOGIN\WEBAUTHN\WebauthnManager; use LAM\LOGIN\WEBAUTHN\WebauthnManager;
use LAM_INTERFACE;
use SelfServiceLoginHandler; use SelfServiceLoginHandler;
use selfServiceProfile; use selfServiceProfile;
use LAMConfig; use LAMConfig;
@ -461,7 +462,7 @@ class DuoProvider extends BaseProvider {
* @see BaseProvider::addCustomInput * @see BaseProvider::addCustomInput
*/ */
public function addCustomInput(&$row, $userDn) { public function addCustomInput(&$row, $userDn) {
$pathPrefix = $this->config->isSelfService ? '../' : ''; $pathPrefix = ($this->config->interface === LAM_INTERFACE::SELF_SERVICE) ? '../' : '';
$row->add(new htmlImage($pathPrefix . '../graphics/duo.png')); $row->add(new htmlImage($pathPrefix . '../graphics/duo.png'));
if (!empty($_GET['duo_code'])) { if (!empty($_GET['duo_code'])) {
// authentication is verified // authentication is verified
@ -612,7 +613,7 @@ class OktaProvider extends BaseProvider {
return; return;
} }
$pathPrefix = $this->config->isSelfService ? '../' : ''; $pathPrefix = ($this->config->interface === LAM_INTERFACE::SELF_SERVICE) ? '../' : '';
$row->add(new htmlImage($pathPrefix . '../graphics/okta.png')); $row->add(new htmlImage($pathPrefix . '../graphics/okta.png'));
$_SESSION['okta_state'] = bin2hex(random_bytes(10)); $_SESSION['okta_state'] = bin2hex(random_bytes(10));
$_SESSION['okta_code_verifier'] = bin2hex(random_bytes(50)); $_SESSION['okta_code_verifier'] = bin2hex(random_bytes(50));
@ -797,7 +798,7 @@ class OpenIdProvider extends BaseProvider {
return; return;
} }
$content = new htmlResponsiveRow(); $content = new htmlResponsiveRow();
$pathPrefix = $this->config->isSelfService ? '../' : ''; $pathPrefix = ($this->config->interface === LAM_INTERFACE::SELF_SERVICE) ? '../' : '';
$row->add(new htmlImage($pathPrefix . '../graphics/openid.png')); $row->add(new htmlImage($pathPrefix . '../graphics/openid.png'));
include_once __DIR__ . '/3rdParty/composer/autoload.php'; include_once __DIR__ . '/3rdParty/composer/autoload.php';
try { try {
@ -976,8 +977,8 @@ class WebauthnProvider extends BaseProvider {
$row->add(new htmlStatusMessage('INFO', _('Please register a security device.'))); $row->add(new htmlStatusMessage('INFO', _('Please register a security device.')));
} }
$row->addVerticalSpacer('2rem'); $row->addVerticalSpacer('2rem');
$pathPrefix = $this->config->isSelfService ? '../' : ''; $pathPrefix = ($this->config->interface === LAM_INTERFACE::SELF_SERVICE) ? '../' : '';
$selfServiceParam = $this->config->isSelfService ? 'selfservice=true' : ''; $selfServiceParam = ($this->config->interface === LAM_INTERFACE::SELF_SERVICE) ? 'selfservice=true' : '';
$row->add(new htmlImage($pathPrefix . '../graphics/webauthn.svg', '50%')); $row->add(new htmlImage($pathPrefix . '../graphics/webauthn.svg', '50%'));
$row->addVerticalSpacer('1rem'); $row->addVerticalSpacer('1rem');
$errorMessage = new htmlStatusMessage('ERROR', '', _('This service requires a browser with "WebAuthn" support.')); $errorMessage = new htmlStatusMessage('ERROR', '', _('This service requires a browser with "WebAuthn" support.'));
@ -1244,7 +1245,7 @@ class TwoFactorProviderService {
*/ */
private function getConfigSelfService(&$profile): TwoFactorConfiguration { private function getConfigSelfService(&$profile): TwoFactorConfiguration {
$tfConfig = new TwoFactorConfiguration(); $tfConfig = new TwoFactorConfiguration();
$tfConfig->isSelfService = true; $tfConfig->interface = LAM_INTERFACE::SELF_SERVICE;
$tfConfig->twoFactorAuthentication = $profile->twoFactorAuthentication; $tfConfig->twoFactorAuthentication = $profile->twoFactorAuthentication;
$tfConfig->twoFactorAuthenticationInsecure = $profile->twoFactorAuthenticationInsecure; $tfConfig->twoFactorAuthenticationInsecure = $profile->twoFactorAuthenticationInsecure;
$tfConfig->twoFactorAuthenticationOptional = $profile->twoFactorAuthenticationOptional; $tfConfig->twoFactorAuthenticationOptional = $profile->twoFactorAuthenticationOptional;
@ -1294,7 +1295,7 @@ class TwoFactorProviderService {
*/ */
private function getConfigAdmin($conf): TwoFactorConfiguration { private function getConfigAdmin($conf): TwoFactorConfiguration {
$tfConfig = new TwoFactorConfiguration(); $tfConfig = new TwoFactorConfiguration();
$tfConfig->isSelfService = false; $tfConfig->interface = LAM_INTERFACE::ADMIN;
$tfConfig->twoFactorAuthentication = $conf->getTwoFactorAuthentication(); $tfConfig->twoFactorAuthentication = $conf->getTwoFactorAuthentication();
$tfConfig->twoFactorAuthenticationInsecure = $conf->getTwoFactorAuthenticationInsecure(); $tfConfig->twoFactorAuthenticationInsecure = $conf->getTwoFactorAuthenticationInsecure();
$tfConfig->twoFactorAuthenticationOptional = $conf->getTwoFactorAuthenticationOptional(); $tfConfig->twoFactorAuthenticationOptional = $conf->getTwoFactorAuthenticationOptional();
@ -1340,10 +1341,8 @@ class TwoFactorProviderService {
*/ */
class TwoFactorConfiguration { class TwoFactorConfiguration {
/** /** LAM UI */
* @var bool is self service public LAM_INTERFACE $interface = LAM_INTERFACE::ADMIN;
*/
public bool $isSelfService = false;
/** /**
* @var ?string provider id * @var ?string provider id

View file

@ -39,6 +39,18 @@ use function LAM\TYPES\getScopeFromTypeId;
* @author Thomas Manninger * @author Thomas Manninger
*/ */
/**
* Defines the possible LAM user interfaces.
*/
enum LAM_INTERFACE {
/** admin pages to manage any type aof entry */
case ADMIN;
/** user self-service to manage own data */
case SELF_SERVICE;
/** white-pages to display users */
case WHITE_PAGES;
}
/** persistence */ /** persistence */
include_once __DIR__ . '/persistence.inc'; include_once __DIR__ . '/persistence.inc';
/** Used to print messages. */ /** Used to print messages. */