示例#1
0
 /**
  * Activate security using the provided Authentication Factory and User Provider
  * @param AuthenticationFactoryInterface $authFactory
  * @param UserProviderInterface $userProvider
  */
 public function activateSecurity(AuthenticationFactoryInterface $authFactory, UserProviderInterface $userProvider)
 {
     if (!$this->security) {
         $this->security = new ServiceProvider();
         $this->firewall = new Firewall('/', '/login/');
         $this->firewall->addAuthenticationFactory($authFactory, $userProvider);
         $this->security->addFirewall($this->firewall);
         $this->security->addAuthorizationVoter(new SecuredAccessVoter());
         $this->register($this->security);
         /* Auth controller */
         $this['auth.controller'] = $this->share(function () {
             return new Auth($this);
         });
         /* Add routes */
         $this->match('/login/', 'auth.controller:login')->bind('login');
     } else {
         $this->firewall->addAuthenticationFactory($authFactory, $userProvider);
     }
 }
示例#2
0
 /**
  * Register the Firewall
  * @param ServiceProvider $provider Service Provider
  */
 public function register(ServiceProvider $provider)
 {
     $this->provider = $provider;
     if ($this->loginPath) {
         $this->provider->addUnsecurePattern("^{$this->loginPath}\$");
     }
     $config = array('logout' => array('logout_path' => $this->logoutPath), 'pattern' => implode('|', $this->patterns));
     $app = $this->provider->getApp();
     foreach ($this->authFactories as $id => $authFactory) {
         $this->registerAuthenticationFactory($app, $id, $authFactory['factory'], $authFactory['userProvider']);
         $config[$id] = array();
         if ($this->loginPath) {
             $config[$id]['login_path'] = $this->loginPath;
             $config[$id]['check_path'] = $this->loginCheckPath;
         }
     }
     $this->registerUserProvider($app);
     $this->registerContextListener($app);
     $this->registerEntryPoint($app);
     $this->provider->appendFirewallConfig($this->name, $config);
 }