. */ namespace SP\Modules\Web\Controllers\ConfigLdap; use Exception; use JsonException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\UnauthorizedPageException; use SP\Domain\Core\Exceptions\CheckException; use SP\Domain\Core\Exceptions\SessionTimeout; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\Http\Dtos\JsonMessage; use SP\Modules\Web\Controllers\SimpleControllerBase; use SP\Modules\Web\Controllers\Traits\ConfigTrait; /** * Class ConfigLdapController * * @package SP\Modules\Web\Controllers */ final class SaveController extends SimpleControllerBase { use ConfigLdapTrait; use ConfigTrait; /** * @return bool * @throws JsonException */ public function saveAction(): bool { try { $eventMessage = EventMessage::build(); $configData = $this->config->getConfigData(); $ldapEnabled = $this->request->analyzeBool('ldap_enabled', false); $ldapDefaultGroup = $this->request->analyzeInt('ldap_defaultgroup'); $ldapDefaultProfile = $this->request->analyzeInt('ldap_defaultprofile'); $ldapParams = $this->getLdapParamsFromRequest($this->request); if ($ldapEnabled && !($ldapParams->getServer() || $ldapParams->getSearchBase() || $ldapParams->getBindDn())) { throw new ValidationException(SPException::ERROR, __u('Missing LDAP parameters')); } if ($ldapEnabled) { $configData->setLdapEnabled(true); $configData->setLdapType($ldapParams->getType()); $configData->setLdapTlsEnabled($ldapParams->isTlsEnabled()); $configData->setLdapServer($this->request->analyzeString('ldap_server')); $configData->setLdapBase($ldapParams->getSearchBase()); $configData->setLdapGroup($ldapParams->getGroup()); $configData->setLdapDefaultGroup($ldapDefaultGroup); $configData->setLdapDefaultProfile($ldapDefaultProfile); $configData->setLdapBindUser($ldapParams->getBindDn()); $configData->setLdapFilterUserObject($ldapParams->getFilterUserObject()); $configData->setLdapFilterGroupObject($ldapParams->getFilterGroupObject()); $configData->setLdapFilterUserAttributes($ldapParams->getFilterUserAttributes()); $configData->setLdapFilterGroupAttributes($ldapParams->getFilterGroupAttributes()); $databaseEnabled = $this->request->analyzeBool('ldap_database_enabled', false); $configData->setLdapDatabaseEnabled($databaseEnabled); if ($ldapParams->getBindPass() !== '***') { $configData->setLdapBindPass($ldapParams->getBindPass()); } if ($configData->isLdapEnabled() === false) { $eventMessage->addDescription(__u('LDAP enabled')); } } elseif ($configData->isLdapEnabled()) { $configData->setLdapEnabled(false); $eventMessage->addDescription(__u('LDAP disabled')); } else { return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('No changes')); } return $this->saveConfig( $configData, $this->config, function () use ($eventMessage) { $this->eventDispatcher->notify('save.config.ldap', new Event($this, $eventMessage)); } ); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } /** * @return void * @throws JsonException * @throws SessionTimeout */ protected function initialize(): void { try { $this->checks(); $this->checkAccess(AclActionsInterface::CONFIG_LDAP); $this->extensionChecker->checkLdap(true); } catch (UnauthorizedPageException|CheckException $e) { $this->eventDispatcher->notify('exception', new Event($e)); $this->returnJsonResponseException($e); } } }