public function init($options) { parent::init($options); $this->useQueue = $this->pluginConf["USE_QUEUE"]; try { $this->msgExchanger = ConfService::instanciatePluginFromGlobalParams($this->pluginConf["UNIQUE_MS_INSTANCE"], "AJXP_MessageExchanger"); if (AuthService::$bufferedMessage != null && AuthService::getLoggedUser() != null) { $this->sendInstantMessage(AuthService::$bufferedMessage, ConfService::getCurrentRepositoryId(), AuthService::getLoggedUser()->getId()); AuthService::$bufferedMessage = null; } } catch (Exception $e) { } }
/** * Log the user from its credentials * @static * @param string $user_id The user id * @param string $pwd The password * @param bool $bypass_pwd Ignore password or not * @param bool $cookieLogin Is it a logging from the remember me cookie? * @param string $returnSeed The unique seed * @return int */ public static function logUser($user_id, $pwd, $bypass_pwd = false, $cookieLogin = false, $returnSeed = "") { $user_id = self::filterUserSensitivity($user_id); if ($cookieLogin && !isset($_COOKIE["AjaXplorer-remember"])) { return -5; // SILENT IGNORE } if ($cookieLogin) { list($user_id, $pwd) = explode(":", $_COOKIE["AjaXplorer-remember"]); } $confDriver = ConfService::getConfStorageImpl(); if ($user_id == null) { if (self::$useSession) { if (isset($_SESSION["AJXP_USER"]) && is_object($_SESSION["AJXP_USER"])) { /** * @var AbstractAjxpUser $u */ $u = $_SESSION["AJXP_USER"]; if ($u->reloadRolesIfRequired()) { ConfService::getInstance()->invalidateLoadedRepositories(); self::$bufferedMessage = AJXP_XMLWriter::reloadRepositoryList(false); $_SESSION["AJXP_USER"] = $u; } return 1; } } else { if (isset(self::$currentUser) && is_object(self::$currentUser)) { return 1; } } if (ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth") && !isset($_SESSION["CURRENT_MINISITE"])) { $authDriver = ConfService::getAuthDriverImpl(); if (!$authDriver->userExists("guest")) { self::createUser("guest", ""); $guest = $confDriver->createUserObject("guest"); $guest->save("superuser"); } self::logUser("guest", null); return 1; } return -1; } $authDriver = ConfService::getAuthDriverImpl(); // CHECK USER PASSWORD HERE! $loginAttempt = self::getBruteForceLoginArray(); $bruteForceLogin = self::checkBruteForceLogin($loginAttempt); self::setBruteForceLoginArray($loginAttempt); if (!$authDriver->userExists($user_id)) { AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => AJXP_Utils::sanitize($user_id, AJXP_SANITIZE_EMAILCHARS), "error" => "Invalid user")); if ($bruteForceLogin === FALSE) { return -4; } else { return -1; } } if (!$bypass_pwd) { if (!self::checkPassword($user_id, $pwd, $cookieLogin, $returnSeed)) { AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => AJXP_Utils::sanitize($user_id, AJXP_SANITIZE_EMAILCHARS), "error" => "Invalid password")); if ($bruteForceLogin === FALSE) { return -4; } else { if ($cookieLogin) { return -5; } return -1; } } } // Successful login attempt unset($loginAttempt[$_SERVER["REMOTE_ADDR"]]); self::setBruteForceLoginArray($loginAttempt); // Setting session credentials if asked in config if (ConfService::getCoreConf("SESSION_SET_CREDENTIALS", "auth")) { list($authId, $authPwd) = $authDriver->filterCredentials($user_id, $pwd); AJXP_Safe::storeCredentials($authId, $authPwd); } $user = $confDriver->createUserObject($user_id); if ($user->getLock() == "logout") { AJXP_Logger::warning(__CLASS__, "Login failed", array("user" => AJXP_Utils::sanitize($user_id, AJXP_SANITIZE_EMAILCHARS), "error" => "Locked user")); return -1; } if (AuthService::$useSession && ConfService::getCoreConf("ALLOW_GUEST_BROWSING", "auth")) { ConfService::getInstance()->invalidateLoadedRepositories(); } if ($authDriver->isAjxpAdmin($user_id)) { $user->setAdmin(true); } if (self::$useSession) { $_SESSION["AJXP_USER"] = $user; } else { self::$currentUser = $user; } if ($user->isAdmin()) { $user = self::updateAdminRights($user); self::updateUser($user); } if ($authDriver->autoCreateUser() && !$user->storageExists()) { $user->save("superuser"); // make sure update rights now } AJXP_Logger::info(__CLASS__, "Log In", array("context" => self::$useSession ? "WebUI" : "API")); return 1; }