Triggered by {@link IdentityStore::logIn()}. When successfully logged in,
this will update the Member record from LDAP data.

@throws Exception When failures are not acceptable via configuration
432165
public function afterMemberLoggedIn()
    {
        if ($this->owner->GUID) {
            try {
                Injector::inst()->get(LDAPService::class)->updateMemberFromLDAP($this->owner);
            } catch (Exception $e) {
                // If the failure is acceptable, then ignore it and return. Otherwise, re-throw the exception
                if ($this->owner->config()->get('allow_update_failure_during_login')) {
                    return;
                }
                throw $e;
            }
        }
    }
1076742
public function login()
    {
        try {

            if (!$this->hasRequestParameter('successCallback')) {
                throw new \common_exception_MissingParameter ('Internal error, please retry in few moment');
            }

            if ($this->isRequestPost()) {
                $authorizationService = $this->getServiceLocator()->get(Authorization::SERVICE_ID);

                if (!$authorizationService instanceof RequireUsername) {
                    throw new InvalidCallException('Authenticator need to be call by requireusername');
                }

                if ($authorizationService->validateLogin($this->getRequestParameter('login'))) {
                    $baseUrl = $this->getServiceLocator()
                        ->get(\common_ext_ExtensionsManager::SERVICE_ID)
                        ->getExtensionById('taoClientDiagnostic')
                        ->getConstant('BASE_URL');
                    $elements = parse_url($baseUrl);
                    $this->setCookie('login', $this->getRequestParameter('login'), null, $elements['path']);
                    $this->redirect($this->getRequestParameter('successCallback'));
                }
            }

        } catch (InvalidLoginException $e) {
            $this->setData('errorMessage', $e->getUserMessage());
        }

        $this->setData('successCallback', $this->getRequestParameter('successCallback'));
        $this->setData('client_config_url', $this->getClientConfigUrl());
        $this->setData('content-controller', 'taoClientDiagnostic/controller/Authenticator/login');
        $this->setData('content-template', 'Authenticator' . DIRECTORY_SEPARATOR . 'login.tpl');
        $this->setView('index.tpl');
    }
531292
public function setUserReadAccess($user, $allowed)
    {
        if (!$user->getObjectId())
        {
            throw new \Exception("cannot setReadAccess for a user with null id");
        }
        $this->setReadAccess($user->getObjectId(), $allowed);
    }
306550
private void migrateUsers() throws Exception
   {
      Session session = service.getStorageSession();
      try
      {
         if (session.itemExists(usersStorageOld))
         {
            NodeIterator iterator = ((ExtendedNode)session.getItem(usersStorageOld)).getNodesLazily();
            UserHandlerImpl uh = ((UserHandlerImpl)service.getUserHandler());
            while (iterator.hasNext())
            {
               uh.migrateUser(iterator.nextNode());
            }
         }
      }
      finally
      {
         session.logout();
      }
   }
864534
public function setUsername($username)
        {
            if ($this->validateUsername($username) === false) {
                throw new Exception("Username \"$username\" is not a valid HTTP username");
            }

            $oldUsername     = $this->_username;
            $this->_username = $username;

            return $oldUsername;
        }
992668
public function initialize()
    {
        if (false === $this->initialized) {
            if (!$this->container) {
                throw new Exception('A container object is required to access the \'session\' service.');
            }

            $this->session = $this->container->get('session');
            $this->data = $this->session->get($this->name, []);

            $this->initialized = true;
        }
    }
401141
public function connect()
    {
        $this->connect = ldap_connect($this->hostname, $this->port);

        if (!$this->connect) {
            throw new ConnectionException($this);
        }

        // Set Ldap Version to 3
        ldap_set_option($this->connect, LDAP_OPT_PROTOCOL_VERSION, 3);

        if (!is_null($this->username) && !is_null($this->password)) {
            if (!@ldap_bind($this->connect, $this->username, $this->password)) {
                throw new BadIdentificationException($this);
            }
        }

        return new Client($this->connect);
    }
1212148
public function regenerate($id = null, $trydeleteold = false)
    {
        if (headers_sent()) {
            throw new Exception('Cannot modify header information - headers already sent', 2);
        }

        $old = $this->savepath . '/' . $this->prefix . $this->currentId;

        $this->commit(false);

        if (empty($id)) {
            $tmpname = Storage::temp(null, 'session', $this->prefix, '');

            if ($tmpname === false) {
                throw new Exception('Failed to create new session file', 2);
            }

            $id = substr(basename($tmpname), 5);
        } else {
            $tmpname = $this->savepath . '/' . $this->prefix . $id;
        }

        if (copy($this->handle, $tmpname) === false) {
            throw new Exception('Failed to copy new old session', 2);
        }

        flock($this->handle, LOCK_UN);
        fclose($this->handle);

        if ($trydeleteold) {
            unlink($old);
        }

        $this->handle = fopen($tmpname, 'a+');

        $this->currentId = $id;

        $this->cookie();
    }
1354597
private static void updateLibertyServer() throws Exception {
        ServerConfiguration server = emptyConfiguration.clone();

        LdapRegistry ldap = new LdapRegistry();
        ldap.setId("ldap1");
        ldap.setRealm("LDAPRealm");
        ldap.setHost("localhost");
        ldap.setPort(String.valueOf(ds.getListenPort()));
        ldap.setBaseDN(SUB_DN);
        ldap.setBindDN(InMemoryLDAPServer.getBindDN());
        ldap.setBindPassword(InMemoryLDAPServer.getBindPassword());
        ldap.setLdapType("Custom");
        LdapEntityType type1 = new LdapEntityType("Group", null, new String[] { "groupOfNames" }, new String[] { GROUP_BASE_DN });
        LdapEntityType type2 = new LdapEntityType("PersonAccount", null, new String[] { "inetOrgPerson" }, new String[] { USER_BASE_DN });
        ldap.getLdapEntityTypes().add(type1);
        ldap.getLdapEntityTypes().add(type2);

        LDAPFatUtils.createFederatedRepository(server, "LDAPRealmFed", new String[] { SUB_DN });

        server.getLdapRegistries().add(ldap);

        updateConfigDynamically(libertyServer, server);
    }
1355018
final public function loginFail(Request $request, \Exception $exception = null)
    {
        $this->cancelCookie($request);
        $this->onLoginFail($request, $exception);
    }
1076677
protected function connect() : void
    {
        if (! $this->isLaravel()) {
            throw new Exception('This migrator must be ran from inside a Laravel application.');
        }

        $this->manager = app('db');
        $this->database = $this->manager->connection();
        $this->schema = $this->database->getSchemaBuilder();
    }
259890
public function connect(): self
    {
        $this->logger->debug('connect to ldap server ['.$this->uri.']', [
            'category' => get_class($this),
        ]);

        if (null === $this->binddn) {
            $this->logger->warning('no binddn set for ldap connection, you should avoid anonymous bind', [
                'category' => get_class($this),
            ]);
        }

        if (false === $this->tls && 'ldaps' !== substr($this->uri, 0, 5)) {
            $this->logger->warning('neither tls nor ldaps enabled for ldap connection, it is strongly reccommended to encrypt ldap connections', [
                'category' => get_class($this),
            ]);
        }

        $this->connection = ldap_connect($this->uri);

        foreach ($this->options as $opt => $value) {
            ldap_set_option($this->connection, constant($opt), $value);
        }

        if (true === $this->tls) {
            ldap_start_tls($this->connection);
        }

        if ($this->connection) {
            if (null !== $this->binddn) {
                $bind = ldap_bind($this->connection, $this->binddn, $this->bindpw);

                if ($bind) {
                    $this->logger->info('bind to ldap server ['.$this->uri.'] with binddn ['.$this->binddn.'] was succesful', [
                        'category' => get_class($this),
                    ]);

                    return $this;
                }

                throw new Exception('failed bind to ldap server, error: '.ldap_error($this->connection));
            }
        } else {
            throw new Exception('failed connect to ldap server '.$this->uri);
        }

        return $this;
    }
564640
public function login($username = 'anonymous', $password = '')
    {
        $result = @ftp_login($this->connection, $username, $password);

        if ($result === false) {
            throw new Exception('Login incorrect');
        } else {
            // set passive mode
            if (!is_null($this->passive)) {
                $this->passive($this->passive);
            }

            return $this;
        }
    }
142577
public function createOrUpdateUserByLoginEmail($data)
    {
        if (! isset($data['login'])) {
            throw new \Exception(sprintf('Have to specify $data[login].'));
        }

        $data['principal-id'] = $this->getUserByLoginEmail($data['login'], true);

        return $this->createOrUpdateUser($data);
    }
296459
public function login($identity)
    {
        if ($this->needRegenerate) {
            session_regenerate_id(true);
        }
        foreach ($identity as $name => $val) {
            $this->sessionData[$name] = $val;
        }
        $lifetime = ini_get('session.cookie_lifetime');
        $this->sessionData[self::REGENERATE_AFTER] = time() + $lifetime - min($lifetime*0.2, 300);
        $this->getSession()->set($this->sessionKey, $this->sessionData);
    }
1371882
public function createUser(User $user)
    {
        if ($this->userStorage->getUserByField("email", $user->email)) {
            throw new Exception("E-postadress används redan.");
        }
        if ($this->userStorage->getUserByField("username", $user->username)) {
            throw new Exception("Användarnamn redan taget.");
        }
        $this->userStorage->createUser($user);
    }
410151
private function checkFailure() : void
    {
        $failure = (int) $this->session->get('failure', 0);
        $time    = (int) $this->session->get('failure_time', time());
        if ($failure >= static::FAILURE) {
            if ($time >= time()) {
                throw new \DomainException($this->i18n->t(
                    'setrun/user',
                    'Form is blocked for {min} minutes',
                    ['min' => static::FAILURE_TIME / 60])
                );
            }
            $this->removeFailure();
        }
    }