/**
  * The main method that creates new instances in a separate context.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface|\AppserverIo\Psr\Naming\NamingDirectoryInterface $application          The application instance to register the class loader with
  * @param \AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface                                          $managerConfiguration The manager configuration
  *
  * @return void
  */
 public static function visit(ApplicationInterface $application, ManagerNodeInterface $managerConfiguration)
 {
     // check if the correct autoloader has been registered, if so we have to get its aspect register.
     // if not we have to fail here
     $classLoader = $application->search('DgClassLoader');
     $aspectRegister = $classLoader->getAspectRegister();
     // initialize the aspect manager
     $aspectManager = new AspectManager();
     $aspectManager->injectApplication($application);
     $aspectManager->injectAspectRegister($aspectRegister);
     // attach the instance
     $application->addManager($aspectManager, $managerConfiguration);
 }
 /**
  * Has been automatically invoked by the container after the application
  * instance has been created.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface|\AppserverIo\Psr\Naming\NamingDirectoryInterface $application The application instance
  *
  * @return void
  */
 public function initialize(ApplicationInterface $application)
 {
     /** @var \AppserverIo\Appserver\Core\DgClassLoader $dgClassLoader */
     $dgClassLoader = $application->search('DgClassLoader');
     // if we did not get the correct class loader our efforts are for naught
     if (!$dgClassLoader instanceof DgClassLoader) {
         $application->getInitialContext()->getSystemLogger()->warning(sprintf('Application %s uses the aspect manager but does not have access to the required Doppelgaenger class loader, AOP functionality will be omitted.', $application->getName()));
         return;
     }
     // register the aspects and tell the class loader it can fill the cache
     $this->registerAspects($application);
     // inject the filled aspect register and create the cache based on it
     $dgClassLoader->injectAspectRegister($this->getAspectRegister());
     $dgClassLoader->createCache();
 }
 /**
  * Initializes the session manager.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  * @see \AppserverIo\Psr\Application\ManagerInterface::initialize()
  */
 public function initialize(ApplicationInterface $application)
 {
     // load the servlet manager with the session settings configured in web.xml
     /** @var \AppserverIo\Psr\Servlet\ServletContextInterface|\AppserverIo\Psr\Application\ManagerInterface $servletManager */
     $servletManager = $application->search('ServletContextInterface');
     // load the settings, set the default session save path
     $sessionSettings = $this->getSessionSettings();
     $sessionSettings->setSessionSavePath($application->getSessionDir());
     // if we've session parameters defined in our servlet context
     if ($servletManager->hasSessionParameters()) {
         // we want to merge the session settings from the servlet context
         $sessionSettings->mergeServletContext($servletManager);
     }
     // initialize the garbage collector and the persistence manager
     $this->getGarbageCollector()->initialize();
     $this->getPersistenceManager()->initialize();
 }
 /**
  * Initializes the manager instance.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  * @see \AppserverIo\Psr\Application\ManagerInterface::initialize()
  *
  * @throws \Exception
  */
 public function initialize(ApplicationInterface $application)
 {
     // iterate over all servlets and return the matching one
     $authenticationAdapters = array();
     foreach ($application->search('ServletContextInterface')->getSecuredUrlConfigs() as $securedUrlConfig) {
         // continue if the can't find a config
         if ($securedUrlConfig == null) {
             continue;
         }
         // extract URL pattern and authentication configuration
         list($urlPattern, $auth) = array_values($securedUrlConfig);
         // load security configuration
         $configuredAuthType = $securedUrlConfig['auth']['auth-type'];
         // check the authentication type
         switch ($configuredAuthType) {
             case "Basic":
                 $authImplementation = '\\AppserverIo\\Http\\Authentication\\BasicAuthentication';
                 break;
             case "Digest":
                 $authImplementation = '\\AppserverIo\\Http\\Authentication\\DigestAuthentication';
                 break;
             default:
                 throw new \Exception(sprintf('Unknown authentication type %s', $configuredAuthType));
         }
         // in preparation we have to flatten the configuration structure
         $config = $securedUrlConfig['auth'];
         array_shift($config);
         $options = $config['options'];
         unset($config['options']);
         // we do need to make some alterations
         if (isset($options['file'])) {
             $options['file'] = $application->getWebappPath() . DIRECTORY_SEPARATOR . $options['file'];
         }
         // initialize the authentication manager
         /** @var \AppserverIo\Http\Authentication\AuthenticationInterface $auth */
         $auth = new $authImplementation(array_merge(array('type' => $authImplementation), $config, $options));
         $authenticationAdapters[$urlPattern] = $auth;
     }
     $this->authenticationAdapters = $authenticationAdapters;
 }
 /**
  * Initializes the session manager.
  *
  * @param \AppserverIo\Psr\Application\ApplicationInterface $application The application instance
  *
  * @return void
  * @see \AppserverIo\Psr\Application\ManagerInterface::initialize()
  */
 public function initialize(ApplicationInterface $application)
 {
     // load the servlet manager with the session settings configured in web.xml
     /** @var \AppserverIo\Psr\Servlet\ServletContextInterface|\AppserverIo\Psr\Application\ManagerInterface $servletManager */
     $servletManager = $application->search(ServletContextInterface::IDENTIFIER);
     // load the settings, set the default session save path
     $sessionSettings = $this->getSessionSettings();
     $sessionSettings->setSessionSavePath($application->getSessionDir());
     // if we've session parameters defined in our servlet context
     if ($servletManager->hasSessionParameters()) {
         // we want to merge the session settings from the servlet context
         $sessionSettings->mergeServletContext($servletManager);
     }
 }