Add new realm

@param \Thruway\Realm $realm
@throws \Thruway\Exception\InvalidRealmNameException
@throws \Exception
558909
public function addRealm(Realm $realm)
    {
        $realmName = $realm->getRealmName();

        if (!static::validRealmName($realm->getRealmName())) {
            throw new InvalidRealmNameException;
        }

        if (array_key_exists($realm->getRealmName(), $this->realms)) {
            throw new \Exception('There is already a realm \'' . $realm->getRealmName() . '\'');
        }

        Logger::debug($this, 'Adding realm \'' . $realmName . '\'');

        $this->realms[$realm->getRealmName()] = $realm;

        $this->router->getEventDispatcher()->dispatch('new_realm', new NewRealmEvent($realm));
    }
1046089
public function add(string $name, RepositoryFactoryInterface $factory): void
    {
        $this->factories[$name] = $factory;
    }
155825
public function add($object, $value)
    {
        $newValue = $object->{$this->local};

        if($newValue instanceof PropertyReference)
            $value->saveAfter($object);

        $value->set($this->foreign, $newValue);
    }
1072644
public function import(array $users = array(), $realm = 'Restricted area')
    {
        //realm must be a string
        Argument::i()->test(2, 'string');
        
        $this->realm = $realm;
        $self = $this;
        
        return function (Registry $request, Registry $response) use ($users, $self) {
            //get digest
            $digest = $request->get('server', 'PHP_AUTH_DIGEST');
            
            //if no digest
            if (empty($digest)) {
                //this throws anyways
                return $self->dialog();
            }
            
            // analyze the PHP_AUTH_DIGEST variable
            $data = $self->digest($digest);
            
            //if no username
            if (!isset($users[$data['username']])) {
                //this throws anyways
                return $self->dialog();
            }
            
            // generate the valid response
            $signature = $self->getSignature($users, $data);
            
            //if it doesnt match
            if ($data['response'] !== $signature) {
                //this throws anyways
                return $self->dialog();
            }
        };
    }
1239503
def fill_default_realm(self):
        
        if not getattr(self, 'realms', None):
            # Create a default realm so all hosts without realm will be linked with it
            default = Realm({
                'realm_name': u'All', 'alias': u'Self created default realm', 'default': '1'
            })
            self.realms = Realms([default])
            logger.warning("No realms defined, I am adding one as %s", default.get_name())

        # Check that a default realm (and only one) is defined and get this default realm
        self.realms.fill_default()
880079
protected function loadDrushAliasesByRelam($realm)
    {
        static $cached = [];

        if (empty($cached[$realm])) {
            $project_root = ProjectX::projectRoot();

            if (!file_exists("$project_root/drush")) {
                return [];
            }
            $drush_alias_dir = "$project_root/drush/site-aliases";

            if (!file_exists($drush_alias_dir)) {
                return [];
            }

            if (!file_exists("$drush_alias_dir/$realm.aliases.drushrc.php")) {
                return [];
            }

            include_once "$drush_alias_dir/$realm.aliases.drushrc.php";

            $cached[$realm] = isset($aliases) ? $aliases : array();
        }

        return $cached[$realm];
    }
177817
public function add()
    {
        $group = $this->Groups->newEntity();
        if ($this->request->is('post') && !empty($this->request->data)) {
            $this->Groups->patchEntity($group, $this->request->data);
            if ($this->Groups->save($group)) {
                $this->Flash->success(__d('wasabi_core', 'The group <strong>{0}</strong> has been created.', $this->request->data['name']));
                $this->redirect(['action' => 'index']);
                return;
            } else {
                $this->Flash->error($this->formErrorMessage);
            }
        }
        $this->set('group', $group);
    }
262608
public function addObject( $object )
	{
		if( !is_object( $object ) )
			throw new InvalidArgumentException( 'Not an object given' );
		$reflection	= new ReflectionObject( $object );
		$methods	= $reflection->getMethods();
		foreach( $methods as $method )
		{
			if( in_array( $method->name, $this->delegableMethods ) )
				throw new RuntimeException( 'Method "'.$method->name.'" is already set' );
			$this->delegableMethods[]	= $method->name;
		}
		$this->delegableObjects[]	= $object;
	}
869030
public function to_header($realm=null)
    {
        $first = true;
        if($realm) {
            $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
            $first = false;
        } else
            $out = 'Authorization: OAuth';
        $total = [];
        foreach ($this->parameters as $k => $v) {
            if (substr($k, 0, 5) != "oauth") continue;
            if (is_array($v)) {
                throw new OAuthException('Arrays not supported in headers');
            }
            $out .= ($first) ? ' ' : ',';
            $out .= OAuthUtil::urlencode_rfc3986($k) .
                  '="' .
                  OAuthUtil::urlencode_rfc3986($v) .
                  '"';
            $first = false;
        }
        return $out;
    }
107921
public function add()
    {
        $this->request->allowMethod('post');

        $entity = $this->SavedSearches->newEntity();
        $entity = $this->SavedSearches->patchEntity($entity, (array)$this->request->getData());
        $success = (bool)$this->SavedSearches->save($entity);

        $this->set('success', $success);
        $success ?
            $this->set('data', ['id' => $entity->get('id')]) :
            $this->set('error', $entity->getErrors());
        $this->set('_serialize', ['success', 'data', 'error']);
    }
99841
public void registerAuthenticationListener(String realm, AuthenticationListener listener) {
        if (realm == null || realm.isEmpty()) {
            throw new InvalidParameterException("The realm name can't be null or empty.");
        }

        if (listener == null) {
            throw new InvalidParameterException("The authentication listener object can't be null.");
        }

        ChallengeHandler handler = new ChallengeHandler();
        handler.initialize(realm, listener);
        challengeHandlers.put(realm, handler);
    }
1199657
public function add($username, $password)
    {
        $this->database->table(self::TABLE_NAME)->insert(array(
            self::COLUMN_NAME => $username,
            self::COLUMN_PASSWORD_HASH => Passwords::hash(self::removeCapsLock($password)),
        ));
    }
563926
private function onAuthenticateHandler($authMethod, $authMethodInfo, Realm $realm, Session $session, AuthenticateMessage $msg)
    {

        $onAuthenticateSuccess = function ($res) use ($realm, $session) {

            if (count($res) < 1) {
                $session->abort(new \stdClass(), 'thruway.error.authentication_failure');

                return;
            }

            // we should figure out a way to have the router send the welcome
            // message so that the roles and extras that go along with it can be
            // filled in
            if ($res[0] === 'SUCCESS') {
                $this->sendWelcomeMessage($session, $res[1]);
            } elseif (isset($res[0]) && $res[0] === 'FAILURE') {
                $this->abortSessionUsingResponse($session, $res);
            } else {
                $session->abort(new \stdClass(), 'thruway.error.authentication_failure');
            }
        };

        $onAuthenticateError = function () use ($session) {
            Logger::error($this, 'onauthenticate rejected the promise');
            $session->abort(new \stdClass(), 'thruway.error.unknown');
        };

        $extra                    = new \stdClass();
        $extra->challenge_details = $session->getAuthenticationDetails()->getChallengeDetails();

        $arguments                = new \stdClass();
        $arguments->extra         = $extra;
        $arguments->authid        = $session->getAuthenticationDetails()->getAuthId();
        $arguments->challenge     = $session->getAuthenticationDetails()->getChallenge();
        $arguments->signature     = $msg->getSignature();
        $arguments->authmethod    = $authMethod;
        $arguments->hello_message = $session->getHelloMessage();

        // now we send our authenticate information to the RPC
        $onAuthenticateHandler = $authMethodInfo['handlers']->onauthenticate;

        $this->session->call($onAuthenticateHandler, [$arguments])
            ->then($onAuthenticateSuccess, $onAuthenticateError);

    }
372257
static function OutputHeaders($realm = "Login Required", $terminate = true)
	{
		header("WWW-Authenticate: Basic realm=\"".$realm."\"");
		header("Status: 401 Unauthorized");
		header("HTTP-Status: 401 Unauthorized");
		if ($terminate) die();
	}
257339
public function getAuthorizationHeader($realm = null)
    {
        $first = true;
        if ($realm) {
            $out = 'OAuth realm="' . Util::urlencodeRfc3986($realm) . '"';
            $first = false;
        } else {
            $out = 'OAuth';
        }

        foreach ($this->parameters as $k => $v) {
            if (substr($k, 0, 5) != "oauth") {
                continue;
            }
            if (is_array($v)) {
                throw new Exception('Arrays not supported in headers');
            }
            $out .= ($first) ? ' ' : ',';
            $out .= Util::urlencodeRfc3986($k) .
                '="' .
                Util::urlencodeRfc3986($v) .
                '"';
            $first = false;
        }
        return $out;
    }
31240
final public function authenticateBasic($realm = null)
	{
		if (! (
			array_key_exists('PHP_AUTH_USER', $_SERVER)
			and array_key_exists('PHP_AUTH_PW', $_SERVER))
			and ! empty($_SERVER['PHP_AUTH_USER'])
			and ! empty($_SERER['PHP_AUTH_PW'])
		) {
			$this->HTTPAuthenticate('Basic', array('realm' => $realm));
			return false;
		} else {
			$this->HTTP_user = $_SERVER['PHP_AUTH_USER'];
			$this->HTTP_pass = $_SERVER['PHP_AUTH_PW'];
			return true;
		}
	}
494040
def init_realms(self, realms):
        
        self.realms = tuple(realm for realm in realms
                            if isinstance(realm, realm_abcs.AuthenticatingRealm))
        self.register_cache_clear_listener()
        self.token_realm_resolver = self.init_token_resolution()
        self.init_locking()