/**
  * Create and return a new instance of the session handler with
  * the passed configuration.
  *
  * @param \AppserverIo\Appserver\Core\Api\Node\SessionHandlerNodeInterface $sessionHandlerNode The session handler configuration
  * @param \AppserverIo\Appserver\ServletEngine\SessionSettingsInterface    $sessionSettings    The session settings
  *
  * @return \AppserverIo\Appserver\ServletEngine\Session\SessionHandlerInterface The session handler instance
  */
 public static function create(SessionHandlerNodeInterface $sessionHandlerNode, SessionSettingsInterface $sessionSettings)
 {
     // reflect the class
     $reflectionClass = new ReflectionClass($sessionHandlerNode->getType());
     // create and initialize the session handler instance
     $sessionHandler = $reflectionClass->newInstanceArgs($sessionHandlerNode->getParamsAsArray());
     $sessionHandler->injectSessionSettings($sessionSettings);
     // return the initialzed instance
     return $sessionHandler;
 }
 /**
  * Utility method to create a Principal for the given username. This
  * creates an instance of the principalClassName type if this option was
  * specified. If principalClassName was not specified, a SimplePrincipal
  * is created.
  *
  * @param \AppserverIo\Lang\String $name The name of the principal
  *
  * @return Principal The principal instance
  * @throws \Exception Is thrown if the custom principal type cannot be created
  */
 public function createIdentity(string $name)
 {
     //initialize the principal
     $principal = null;
     // query whether or not a principal class name has been specified
     if ($this->principalClassName == null) {
         $principal = new SimplePrincipal($name);
     } else {
         $reflectionClass = new ReflectionClass($this->principalClassName->__toString());
         $principal = $reflectionClass->newInstanceArgs(array($name));
     }
     // return the principal instance
     return $principal;
 }
 /**
  * Parses the servlet context's deployment descriptor file for servlets
  * that has to be registered in the object manager.
  *
  * @return void
  */
 public function parse()
 {
     // load the web application base directory
     $webappPath = $this->getAuthenticationContext()->getWebappPath();
     // prepare the deployment descriptor
     $deploymentDescriptor = $webappPath . DIRECTORY_SEPARATOR . 'WEB-INF' . DIRECTORY_SEPARATOR . 'web.xml';
     // query whether we found epb.xml deployment descriptor file
     if (file_exists($deploymentDescriptor) === false) {
         return;
     }
     // validate the passed configuration file
     /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
     $configurationService = $this->getApplication()->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService');
     $configurationService->validateFile($deploymentDescriptor, null, true);
     // prepare and initialize the configuration node
     $webAppNode = new WebAppNode();
     $webAppNode->initFromFile($deploymentDescriptor);
     // query whether or not we've a login configuration
     /** @var \AppserverIo\Appserver\Core\Api\Node\LoginConfigNode $loginConfig */
     if ($loginConfig = $webAppNode->getLoginConfig()) {
         // create the authentication method instance
         $reflectionClass = new ReflectionClass($this->mapAuthenticator($loginConfig->getAuthMethod()->__toString()));
         $authenticator = $reflectionClass->newInstanceArgs(array($loginConfig, $this->getAuthenticationContext(), new Boolean(true)));
         // add the authentication method itself
         $this->getAuthenticationContext()->addAuthenticator($authenticator);
         // initialize the security roles, that are part of the new security subsystem
         /** @var \AppserverIo\Appserver\Core\Api\Node\SecurityRoleNode $securityRoleNode */
         foreach ($webAppNode->getSecurityRoles() as $securityRoleNode) {
             // do something here
         }
         // initialize the security roles, that are part of the new security subsystem
         /** @var \AppserverIo\Appserver\Core\Api\Node\SecurityConstraintNode $securityContstraintNode */
         foreach ($webAppNode->getSecurityConstraints() as $securityContstraintNode) {
             // prepare the array with the authentication constraint role names
             $roleNames = array();
             if ($authConstraint = $securityContstraintNode->getAuthConstraint()) {
                 $roleNames = $authConstraint->getRoleNamesAsArray();
             }
             /** @var \AppserverIo\Appserver\Core\Api\Node\WebResourceCollectionNode $webResourceCollectionNode */
             foreach ($securityContstraintNode->getWebResourceCollections() as $webResourceCollectionNode) {
                 // prepare the arrays for the HTTP methods and the method omissions
                 $httpMethods = $webResourceCollectionNode->getHttpMethodsAsArray();
                 $httpMethodOmissions = $webResourceCollectionNode->getHttpMethodOmissionsAsArray();
                 /** @var \AppserverIo\Appserver\Core\Api\Node\UrlPatternNode $urlPatternNode */
                 foreach ($webResourceCollectionNode->getUrlPatterns() as $urlPatternNode) {
                     // prepare the URL pattern to authenticator mapping with the necessary data
                     $mapping = new Mapping($urlPatternNode->__toString(), $authenticator->getSerial(), $roleNames, $httpMethods, $httpMethodOmissions);
                     // add the URL pattern to authenticator mapping
                     $this->getAuthenticationContext()->addMapping($mapping);
                 }
             }
         }
     }
 }