Commit 1cb8ef59 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

[REFACTOR] Add error handling

parent e40b2da0
Pipeline #6592 failed with stages
in 27 seconds
......@@ -93,6 +93,7 @@ class Ldap
/**
* LDAP constructor.
* @throws \Exception
*/
public function __construct()
{
......@@ -109,8 +110,21 @@ class Ldap
$this->ldapBaseDnForPasswordChanges = trim($this->extensionConfiguration['ldapBaseDnForPasswordChanges']);
// Connect and bind
$this->createLdapConnection();
try {
if ($this->createLdapConnection()) {
$this->ldapBind($this->ldapConnection, $this->ldapBindDn, $this->ldapBindPassword);
} else {
throw new \Exception(
'createLdapConnection connection failed',
1553856512
);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
......@@ -249,13 +263,21 @@ class Ldap
* Errors are logged to syslog.
*
* @return bool
* @throws \Exception
*/
private function createLdapConnection()
{
$ret = false;
$port = intval($this->ldapServerPort);
try {
if (function_exists('ldap_connect')) {
$this->ldapConnection = @ldap_connect($this->ldapServer, ($port > 0 ? $port : null));
} else {
throw new \Exception(
'LDAP PHP Extension is not available',
1553856513
);
}
if ($this->ldapConnection) {
// Set protocol version
if (ldap_set_option($this->ldapConnection, LDAP_OPT_PROTOCOL_VERSION, $this->ldapProtocolVersion)) {
......
......@@ -32,13 +32,19 @@ class UserCreateUpdateDelete
* @param bool $createIfNotExists Create the user if it does not exist
* @param string $updatePassword
* @return bool
* @throws \Exception
*/
public function updateUser(\In2code\Femanager\Domain\Model\User $user, $createIfNotExists = true, $updatePassword = '')
{
$ret = false;
/** @var \T3o\T3oLdap\Connectors\Ldap $ldap */
$ldap = GeneralUtility::makeInstance(\T3o\T3oLdap\Connectors\Ldap::class);
try {
$ldap =new \T3o\T3oLdap\Connectors\Ldap();
} catch (\Exception $e) {
throw $e;
}
$feUserUid = $user->getUid();
if ($ldap->userExists($user->getUsername())) {
......
<?php
namespace T3o\T3omy\Hooks;
/***************************************************************
......@@ -183,13 +184,20 @@ class FeManagerHooks
*
* @param \In2code\Femanager\Domain\Model\User $user
* @return bool
* @throws \Exception
*/
public function createUser(User $user)
{
$this->persistenceManager->persistAll();
// TODO: Create log entry if user has been successfully added or throw an exception otherwise
return $this->ldapUserCreateUpdateDelete->updateUser($user, true);
try {
$this->ldapUserCreateUpdateDelete->updateUser($user, true);
} catch (\Exception $e) {
throw $e;
}
return true;
}
/**
......@@ -349,6 +357,7 @@ class FeManagerHooks
return $location;
}
return 'No Access key is set in typoscript constants - tx_t3omy.ipapi.access_key';
}
}
......@@ -59,8 +59,19 @@ class ReactivateUserHook implements \TYPO3\CMS\Backend\RecordList\RecordListGetT
$this->persistenceManager->persistAll();
$ldapOperation = $this->objectManager->get(FeManagerHooks::class);
try {
$ldapOperation->createUser($frontendUser);
} catch (\Exception $e) {
$this->addFlashMessage(
$e->getMessage(),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
'Error ' . $e->getCode()
);
return false;
}
return $ldapOperation->createUser($frontendUser);
return true;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment