Username realm detection.

@return string Username realm (domain)
504710
private function get_realm()
    {
        // When user enters a username without domain part, realm
        // allows to add it to the username (and display correct username in the table)

        if (isset($_SESSION['acl_username_realm'])) {
            return $_SESSION['acl_username_realm'];
        }

        // find realm in username of logged user (?)
        list($name, $domain) = explode('@', $_SESSION['username']);

        // Use (always existent) ACL entry on the INBOX for the user to determine
        // whether or not the user ID in ACL entries need to be qualified and how
        // they would need to be qualified.
        if (empty($domain)) {
            $acl = $this->rc->storage->get_acl('INBOX');
            if (is_array($acl)) {
                $regexp = '/^' . preg_quote($_SESSION['username'], '/') . '@(.*)$/';
                foreach (array_keys($acl) as $name) {
                    if (preg_match($regexp, $name, $matches)) {
                        $domain = $matches[1];
                        break;
                    }
                }
            }
        }

        return $_SESSION['acl_username_realm'] = $domain;
    }
949433
public function get_name($usr = null){
    if ( $this->auth ){
      if ( \is_null($usr) ){
        $usr = $this->get_session();
      }
      else if ( str::is_uid($usr) ){
        $mgr = $this->get_manager();
        $usr = $mgr->get_user($usr);
      }
      if ( isset($usr[$this->class_cfg['show']]) ){
        return $usr[$this->class_cfg['show']];
      }
    }
    return false;
  }
1154560
protected function sanitizeUsername()
    {
        $username = $this->has('username')
            ? $this->get('username')
            : $this->get('first_name').' '.$this->get('last_name');

        return Str::slug($username, config('arcanesoft.auth.slug-separator', '.'));
    }
521273
protected function getUserString()
    {
        $user = $this->core->auth()->user();

        if ( ! $user) return null;

        return $user->getUsername();
    }
1339730
public function getDomainName(): string
    {
        return $this->myDomainParts[count($this->myDomainParts) - 1] . ($this->myTld !== null ? '.' . $this->myTld : '');
    }
374898
public function checkName () {
        $result = true;

        if ($this->name != preg_replace('/[^a-z0-9_ -]/i', '', $this->name)) {
            $result = false;
        }
        return $result;
    }
452503
def usernameAvailable(self, username, domain):
        
        if len(username) < 2:
            return [False, u"Username too short"]
        for char in u"[ ,:;<>@()!\"'%&\\|\t\b":
            if char in username:
                return [False,
                        u"Username contains invalid character: '%s'" % char]

        # The localpart is acceptable if it can be parsed as the local part
        # of an RFC 2821 address.
        try:
            parseAddress("<%s@example.com>" % (username,))
        except ArgumentError:
            return [False, u"Username fails to parse"]

        # The domain is acceptable if it is one which we actually host.
        if domain not in self.getAvailableDomains():
            return [False, u"Domain not allowed"]

        query = self.store.query(userbase.LoginMethod,
                                 AND(userbase.LoginMethod.localpart == username,
                                     userbase.LoginMethod.domain == domain))
        return [not bool(query.count()), u"Username already taken"]
168877
protected function checkUsername()
    {
        $token = $this->tokenStorage->getToken();
        if (!$token instanceof RememberMeToken && !$token instanceof UsernamePasswordToken) {
            throw new ServerErrorException([
                'error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.',
            ]);
        }

        return $token->getUsername();
    }
1294521
private String getRealmName() {
        String realm = "defaultRealm";
        try {
            UserRegistry ur = RegistryHelper.getUserRegistry(null);
            if (ur != null) {
                String r = ur.getRealm();
                if (r != null) {
                    realm = r;
                }
            }
        } catch (Exception ex) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Cannot get the UR service since it may not be available so use the default value for the realm.", ex);
            }
        }

        return realm;
    }
994865
public function getPersonalWorkspaceName()
    {
        $currentUser = $this->userDomainService->getCurrentUser();

        if (!$currentUser instanceof User) {
            return null;
        }

        $username = $this->userDomainService->getUsername($currentUser);
        return ($username === null ? null : UserUtility::getPersonalWorkspaceNameForUsername($username));
    }
1143270
function getCounterKey($username)
    {
        $k = $this->app['config']->get('cache.namespace');
        $k .= ':failed_login_counter.';
        $k .= $username;

        return $k;
    }
693445
protected function findUsersByUsernamePattern($usernamePattern, $authenticationProviderName = null)
    {
        if (preg_match('/[\\?\\*\\{\\[]/u', $usernamePattern)) {
            return array_filter(
                $this->userService->getUsers()->toArray(),
                function ($user) use ($usernamePattern, $authenticationProviderName) {
                    return fnmatch($usernamePattern, $this->userService->getUsername($user, $authenticationProviderName));
                }
            );
        } else {
            $user = $this->userService->getUser($usernamePattern, $authenticationProviderName);
            if ($user instanceof User) {
                return [$user];
            }
        }
        return [];
    }
921780
public function getUsername()
    {
        $info = $this->getUserInfo();
        $username = strstr($info, ':', true);

        return rawurldecode($username === false ? $info : $username);
    }
886312
public String getRealmName() {
        if (realmName == null || realmName.trim().equals("")) {
            realmName = getDefaultRealmName();
        }
        return realmName;
    }
552689
public function getDomainNames()
    {
        return $this->getCache('domainNames', function () {
            $list = array_merge($this->aliases, $this->pointers, [$this->getDomainName()]);
            sort($list);
            return $list;
        });
    }
713635
protected function getUsername()
    {

        // initialize the name
        $name = null;

        // query whether or not we've an principal
        if ($identity = $this->getIdentity()) {
            $name = $identity->getName();
        }

        // return the name
        return $name;
    }
322316
public UserRealm getRealm(String realmName)
    {
        if (realmName==null)
        {
            if (_realmMap.size()==1)
                return (UserRealm)_realmMap.values().iterator().next();
            log.warn("Null realmName with multiple known realms");
        }
        return (UserRealm)_realmMap.get(realmName);
    }