예제 #1
0
 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() . "\"");
     }
     $this->manager->debug("Adding realm \"" . $realmName . "\"");
     if ($realm->getManager() instanceof ManagerDummy) {
         /** remind people that we don't setup the manager for them if they
          * are creating their own realms */
         $this->manager->warning("Realm \"" . $realmName . "\" is using ManagerDummy");
     }
     $this->realms[$realm->getRealmName()] = $realm;
 }
예제 #2
0
 /**
  * @param Session $session
  * @param Message $msg
  */
 public function onMessage(Session $session, Message $msg)
 {
     if (!$session->isAuthenticated()) {
         if ($msg instanceof HelloMessage) {
             $this->manager->debug("got hello");
             // send welcome message
             if ($this->sessions->contains($session)) {
                 $this->manager->error("Connection tried to rejoin realm when it is already joined to the realm.");
                 $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg));
                 // TODO should shut down session here
             } else {
                 $this->sessions->attach($session);
                 $session->setRealm($this);
                 $session->setState(Session::STATE_UP);
                 // this should probably be after authentication
                 if ($this->getAuthenticationManager() !== null) {
                     $this->getAuthenticationManager()->onAuthenticationMessage($this, $session, $msg);
                 } else {
                     $session->setAuthenticated(true);
                     $session->setAuthenticationDetails(AuthenticationDetails::createAnonymous());
                     // the broker and dealer should give us this information
                     $roles = array("broker" => new \stdClass(), "dealer" => new \stdClass());
                     $session->sendMessage(new WelcomeMessage($session->getSessionId(), array("roles" => $roles)));
                 }
             }
         } else {
             if ($msg instanceof AuthenticateMessage) {
                 if ($this->getAuthenticationManager() !== null) {
                     $this->getAuthenticationManager()->onAuthenticationMessage($this, $session, $msg);
                 } else {
                     // TODO: should shut down here probably
                     $this->manager->error("Authenticate sent to realm without auth manager.");
                 }
             } else {
                 $this->manager->error("Unhandled message sent to unauthenticated realm: " . $msg->getMsgCode());
                 $session->sendMessage(new AbortMessage(new \stdClass(), "wamp.error.not_authorized"));
                 $session->shutdown();
             }
         }
     } else {
         $handled = false;
         /* @var $role AbstractRole */
         foreach ($this->roles as $role) {
             if ($role->handlesMessage($msg)) {
                 $role->onMessage($session, $msg);
                 $handled = true;
                 break;
             }
         }
         if (!$handled) {
             $this->manager->warning("Unhandled message sent to \"{$this->getRealmName()}\": {$msg->getSerializedMessage()}");
         }
     }
 }