示例#1
0
 public function handle(GetResponseEvent $evt)
 {
     $request = $evt->getRequest();
     // check if username is set, let it override
     if ($request->get('_username')) {
         return;
     }
     // check if another token exists, then skip
     if ($this->context->getToken() && !$this->context->getToken() instanceof SspiUserToken) {
         return;
     }
     $server = $request->server;
     $remote_user = $server->get('REMOTE_USER');
     if (!$remote_user) {
         return;
     }
     $cred = explode('\\', $remote_user);
     if (count($cred) == 1) {
         array_unshift($cred, "unknown");
     }
     $token = new SspiUserToken();
     $token->setUser($cred[1]);
     try {
         $token = $this->manager->authenticate($token);
         $this->context->setToken($token);
         return;
     } catch (AuthenticationException $failed) {
         $this->context->setToken(null);
         return;
     }
 }
 public function authenticate(TokenInterface $token)
 {
     $user = $this->provider->loadUserByUsername($token->getUsername());
     if ($user) {
         $this->checker->checkPostAuth($user);
         $authToken = new SspiUserToken(true, $user->getRoles());
         $authToken->setUser($user);
         return $authToken;
     }
     throw new AuthenticationException('No such user.');
 }