/**
  * Initializes the handler with the available encoders.
  */
 public function __construct()
 {
     // the array list with the availalbe encoders
     $this->encoders = new ArrayList();
     // add the available encodees
     $this->encoders->add(new SimpleJsonEncoder());
     $this->encoders->add(new JmsSerializerEncoder());
 }
 /**
  * This method tests the sort method
  * of the CollectionUtils.
  *
  * @return void
  */
 public function testSort()
 {
     // sort all elements by their value
     CollectionUtils::sort($this->list, new TestComparator());
     $this->assertEquals("Adolf", $this->list->get(0));
     $this->assertEquals("Albert", $this->list->get(1));
     $this->assertEquals("Caesar", $this->list->get(2));
     $this->assertEquals("Dodo", $this->list->get(3));
     $this->assertEquals("Franz", $this->list->get(4));
     $this->assertEquals("Julius", $this->list->get(5));
     $this->assertEquals("Zacharias", $this->list->get(6));
 }
 /**
  * Returns an ArrayList of DTOs with the virtual host data.
  *
  * @return \AppserverIo\Collections\ArrayList The ArrayList with the virtual host DTOs
  * @see \AppserverIo\Apps\Api\Assembler\VirtualHostAssemblerInterface::getVirtualHostOverviewData()
  */
 public function getVirtualHostOverviewData()
 {
     // create the ArrayList instance
     $virtualHosts = new ArrayList();
     // load all virtual host nodes
     foreach ($this->getVirtualHostRepository()->findAll() as $virtualHostNode) {
         $virtualHosts->add($this->toVirtualHostOverviewData($virtualHostNode));
     }
     // return the ArrayList instance
     return $virtualHosts;
 }
 /**
  * Will be invoked when login fails for some reasons.
  *
  * @param \AppserverIo\Appserver\ServletEngine\Security\RealmInterface $realm           The realm instance containing the exception stack
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface    $servletRequest  The servlet request instance
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface   $servletResponse The servlet response instance
  *
  * @return void
  */
 protected function onFailure(RealmInterface $realm, HttpServletRequestInterface $servletRequest, HttpServletResponseInterface $servletResponse)
 {
     // load the session from the request
     if ($session = $servletRequest->getSession()) {
         // prepare the ArrayList for the login errors
         $formErrors = new ArrayList();
         // transform the realm's exception stack into simple error messages
         foreach ($realm->getExceptionStack() as $e) {
             $formErrors->add($e->getMessage());
         }
         // add the error messages to the session
         $session->putData(Constants::FORM_ERRORS, $formErrors);
     }
     // forward to the configured error page
     $this->forwardToErrorPage($servletRequest, $servletResponse);
 }
 /**
  * Returns an ArrayList of DTOs with the application data.
  *
  * @return \AppserverIo\Collections\ArrayList The ArrayList with the application DTOs
  * @see \AppserverIo\Apps\Api\Assembler\ApplicationAssemblerInterface::getApplicationOverviewData()
  */
 public function getApplicationOverviewData()
 {
     // create the ArrayList instance
     $applications = new ArrayList();
     // load all applications
     foreach ($this->getApplicationRepository()->findAll() as $application) {
         $applications->add($this->toApplicationOverviewData($application));
     }
     // return the ArrayList instance
     return $applications;
 }
 /**
  * Called by login() to acquire the username and password strings for
  * authentication. This method does no validation of either.
  *
  * @return array Array with name and password, e. g. array(0 => $name, 1 => $password)
  * @throws \AppserverIo\Appserver\Psr\Security\Auth\Login\LoginException Is thrown if name and password can't be loaded
  */
 public function getUsernameAndPassword()
 {
     // create and initialize an ArrayList for the callback handlers
     $list = new ArrayList();
     $list->add($nameCallback = new NameCallback());
     $list->add($passwordCallback = new PasswordCallback());
     // handle the callbacks
     $this->callbackHandler->handle($list);
     // return an array with the username and callback
     return array($nameCallback->getName(), $passwordCallback->getPassword());
 }
 /**
  * Returns an ArrayList of DTOs with the naming directory data.
  *
  * @return \AppserverIo\Collections\ArrayList The ArrayList with the naming directory DTOs
  * @see \AppserverIo\Apps\Api\Assembler\NamingDirectoryAssemblerInterface::getNamingDirectoryOverviewData()
  */
 public function getNamingDirectoryOverviewData()
 {
     // create the ArrayList instance
     $namingDirectories = new ArrayList();
     // load all virtual host nodes
     foreach ($this->getNamingDirectoryRepository()->findAll() as $namingDirectory) {
         $namingDirectories->add($this->toNamingDirectoryOverviewData($namingDirectory));
     }
     // return the ArrayList instance
     return $namingDirectories;
 }
 /**
  * Returns an ArrayList of DTOs with the container data.
  *
  * @return \AppserverIo\Collections\ArrayList The ArrayList with the container DTOs
  * @see \AppserverIo\Apps\Api\Assembler\ContainerAssemblerInterface::getContainerOverviewData()
  */
 public function getContainerOverviewData()
 {
     // create the ArrayList instance
     $containers = new ArrayList();
     // load all virtual host nodes
     foreach ($this->getContainerRepository()->findAll() as $containerNode) {
         $containers->add($this->toContainerOverviewData($containerNode));
     }
     // return the ArrayList instance
     return $containers;
 }
 /**
  * Returns an ArrayList of DTOs with the persistence unit data.
  *
  * @return \AppserverIo\Collections\ArrayList The ArrayList with the persistence unit DTOs
  * @see \AppserverIo\Apps\Api\Assembler\PersistenceUnitAssemblerInterface::getPersistenceUnitOverviewData()
  */
 public function getPersistenceUnitOverviewData()
 {
     // create the ArrayList instance
     $persistenceUnitNodes = new ArrayList();
     // load all persistence unit nodes
     foreach ($this->getPersistenceUnitRepository()->findAll() as $persistenceUnitNode) {
         $persistenceUnitNodes->add($this->toPersistenceUnitOverviewData($persistenceUnitNode));
     }
     // return the ArrayList instance
     return $persistenceUnitNodes;
 }
Exemple #10
0
 /**
  * Identify and return an instance implementing the PrincipalInterface that represens the
  * authenticated user for the specified Subject. The Principal is constructed by scanning
  * the list of Principals returned by the LoginModule. The first Principal object that
  * matches one of the class names supplied as a "user class" is the user Principal. This
  * object is returned to the caller. Any remaining principal objects returned by the
  * LoginModules are mapped to roles, but only if their respective classes match one of the
  * "role class" classes. If a user Principal cannot be constructed, return NULL.
  *
  * @param \AppserverIo\Lang\String                                   $username     The associated user name
  * @param \AppserverIo\Psr\Security\Auth\Subject                     $subject      The Subject representing the logged-in user
  * @param \AppserverIo\Psr\Security\Auth\Login\LoginContextInterface $loginContext Associated with the Principal so {@link LoginContext#logout()} can be called later
  *
  * @return \AppserverIo\Security\PrincipalInterface the principal object
  */
 protected function createPrincipal(string $username, Subject $subject, LoginContextInterface $loginContext)
 {
     // initialize the roles and the user principal
     $roles = new ArrayList();
     $userPrincipal = null;
     // scan the Principals for this Subject
     foreach ($subject->getPrincipals() as $principal) {
         // query whether or not the principal found is a group principal
         if ($principal instanceof GroupInterface && $principal->getName()->equals(new String(Util::DEFAULT_GROUP_NAME))) {
             // if yes, add the role name
             foreach ($principal->getMembers() as $role) {
                 $roles->add($role->getName());
             }
             // query whether or not the principal found is a user principal
         } elseif ($userPrincipal == null && $principal instanceof PrincipalInterface) {
             $userPrincipal = $principal;
         } else {
             // do nothing, because we've no principal or group to deal with
         }
     }
     // return the resulting Principal for our authenticated user
     return new GenericPrincipal($username, null, $roles, $userPrincipal, $loginContext);
 }
 /**
  * Returns an ArrayList of DTOs with the datasource data.
  *
  * @return \AppserverIo\Collections\ArrayList The ArrayList with the datasource DTOs
  * @see \AppserverIo\Apps\Api\Assembler\DatasourceAssemblerInterface::getDatasourceOverviewData()
  */
 public function getDatasourceOverviewData()
 {
     // create the ArrayList instance
     $datasources = new ArrayList();
     // load all virtual host nodes
     foreach ($this->getDatasourceRepository()->findAll() as $datasourceNode) {
         $datasources->add($this->toDatasourceOverviewData($datasourceNode));
     }
     // return the ArrayList instance
     return $datasources;
 }