コード例 #1
0
 public function checkAction(Request $request)
 {
     $username = $request->request->get('supra_login', 'admin');
     $password = $request->request->get('supra_password', 'admin');
     $authenticationManager = $this->container['cms_authentication.users.authentication_manager'];
     /* @var $authenticationManager AuthenticationProviderManager */
     $event = new DataAgnosticEvent();
     $event->setData(array('username' => $username, 'password' => $password, 'result' => null));
     try {
         $this->container->getEventDispatcher()->dispatch(self::PRE_AUTHENTICATE_EVENT, $event);
         $result = $authenticationManager->authenticate(new UsernamePasswordToken($event->getData()['username'], $event->getData()['password'], $this->container->getParameter('cms_authentication.provider_key')));
         $event->setData(array_merge($event->getData(), array('result' => $result)));
         $this->container->getEventDispatcher()->dispatch(self::POST_AUTHENTICATE_EVENT, $event);
         $result = $event->getData()['result'];
     } catch (BadCredentialsException $e) {
         $event->setData(array_merge($event->getData(), array('exception' => $e)));
         $this->container->getEventDispatcher()->dispatch(self::AUTHENTICATION_EXCEPTION_EVENT, $event);
         if ($event->getData()['result'] instanceof Response) {
             return $event->getData()['result'];
         }
         //if password is not valid Symfony throws plain BadCredentialException, so we can put "Invalid password" here
         $message = 'Incorrect login name or password';
         $previous = $e->getPrevious();
         if ($previous instanceof UsernameNotFoundException) {
             //"such username does not exist"
             $message = 'Incorrect login name or password';
         }
         return new Response(self::EMPTY_BODY, self::FAILURE_STATUS, array(self::HEADER_401_MESSAGE => $message));
     }
     $event->setData($event->getData(), array('result' => $result));
     $this->container->getEventDispatcher()->dispatch(self::AUTHENTICATION_RESULT_EVENT, $event);
     $result = $event->getData()['result'];
     if ($event->getData()['result'] instanceof Response) {
         return $event->getData()['result'];
     }
     if ($result instanceof TokenInterface) {
         $this->container->getSecurityContext()->setToken($result);
         $event = new DataAgnosticEvent();
         $this->container->getEventDispatcher()->dispatch(self::TOKEN_CHANGE_EVENT, $event);
         return new Response(self::EMPTY_BODY);
     }
     //catch-all
     return new Response(AuthController::EMPTY_BODY, AuthController::FAILURE_STATUS, array(AuthController::HEADER_401_MESSAGE => 'Unknown authentication error'));
 }
コード例 #2
0
ファイル: Supra.php プロジェクト: sitesupra/sitesupra
 /**
  *
  * @return Container
  */
 public function buildContainer()
 {
     if ($this->container) {
         return $this->container;
     }
     //getting container instance, configuring services
     $this->container = $container = new Container();
     $this->buildDirectories();
     $container->setParameter('environment', $this->environment);
     $container->setParameter('debug', $this->debug);
     $container['application'] = $this;
     //routing configuration
     $container['config.universal_loader'] = new UniversalConfigLoader();
     $container['routing.router'] = new Router();
     $container['kernel.kernel'] = function ($container) {
         return new HttpKernel();
     };
     $container['exception.controller'] = function () {
         return new ExceptionController();
     };
     //internal services
     //this actually must be based upon some config and there should be an option to override everything
     $this->buildHttpFoundation($container);
     $this->buildCache($container);
     $this->buildLogger($container);
     $this->buildEvents($container);
     $this->buildCli($container);
     $this->buildTemplating($container);
     $this->buildApplications($container);
     //package configuration
     $this->injectPackages($container);
     //configuration processing
     $this->buildConfiguration($container);
     //last pass to change something or created services based on finished configuration
     $this->finish($container);
     $buildEvent = new DataAgnosticEvent();
     $buildEvent->setData($container);
     $this->container->getEventDispatcher()->dispatch(Supra::EVENT_CONTAINER_BUILD_COMPLETE, $buildEvent);
     return $container;
 }