/**
  * @covers \Misd\RavenBundle\Security\Authentication\Token\RavenUserToken::factory
  */
 public function testFactory()
 {
     $wlsResponse = '2!200!!20121024T140812Z!1351087692-2052-8!http://example.cam.ac.uk/!test0001!pwd!!36000!!901!j8xWV8.XvwGoqIyHqXk9eyXeexGZLCc7sFfFciXoSwYnjn.BEvcFAgQy2j9Yt76WNad3Bvja8pLWAGLaAFryjXxnxSLrygy.VREHa5c-DH.UzFlUXssBS1.8LnZv1BVLS12qnqtzMjfgn8lCHnYdMDJ1ZV7pbV0hi-GcGUfgIYk_';
     $token = RavenUserToken::factory($wlsResponse);
     $this->assertEquals(2, $token->getAttribute('ver'));
     $this->assertEquals(200, $token->getAttribute('status'));
     $this->assertNull($token->getAttribute('msg'));
     $this->assertInstanceOf('\\DateTime', $token->getAttribute('issue'));
     $this->assertEquals('2012-10-24 14:08:12', $token->getAttribute('issue')->format('Y-m-d H:i:s'));
     $this->assertEquals('1351087692-2052-8', $token->getAttribute('id'));
     $this->assertEquals('http://example.cam.ac.uk/', $token->getAttribute('url'));
     $this->assertEquals('pwd', $token->getAttribute('auth'));
     $this->assertEquals('', $token->getAttribute('sso'));
     $this->assertEquals(36000, $token->getAttribute('life'));
     $this->assertNull($token->getAttribute('params'));
     $this->assertEquals(901, $token->getAttribute('kid'));
     $this->assertEquals('j8xWV8.XvwGoqIyHqXk9eyXeexGZLCc7sFfFciXoSwYnjn.BEvcFAgQy2j9Yt76WNad3Bvja8pLWAGLaAFryjXxnxSLrygy.VREHa5c-DH.UzFlUXssBS1.8LnZv1BVLS12qnqtzMjfgn8lCHnYdMDJ1ZV7pbV0hi-GcGUfgIYk_', $token->getAttribute('sig'));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $session = $request->getSession();
     if ($session->has('wls_response')) {
         // There's a Raven response to process
         $token = RavenUserToken::factory($session->get('wls_response'));
         $session->remove('wls_response');
         if (null !== $this->logger) {
             $this->logger->debug('Found WLS response', array('CRSid' => $token->getUsername()));
         }
         if (rawurldecode($token->getAttribute('url')) !== $request->getUri()) {
             throw new RavenException('URL mismatch');
         }
         switch ($token->getAttribute('status')) {
             case 200:
                 // Successful authentication
                 break;
             case 410:
                 throw new AuthenticationCancelledException();
                 break;
             default:
                 switch ($token->getAttribute('status')) {
                     case 510:
                         $message = 'No mutually acceptable authentication types available';
                         break;
                     case 520:
                         $message = 'Unsupported protocol version';
                         break;
                     case 530:
                         $message = 'General request parameter error';
                         break;
                     case 540:
                         $message = 'Interaction would be required';
                         break;
                     case 560:
                         $message = 'WAA not authorised';
                         break;
                     case 570:
                         $message = 'Authentication declined';
                         break;
                     default:
                         $message = null;
                         break;
                 }
                 throw new RavenException($message, $token->getAttribute('status'));
                 break;
         }
         $token = $this->authenticationManager->authenticate($token);
         $this->tokens->setToken($token);
         $this->dispatcher->dispatch(RavenEvents::LOGIN, new InteractiveLoginEvent($request, $token));
     } elseif ($this->tokens->getToken() != null && $this->tokens->getToken()->getUser() instanceof UserInterface) {
         // The user is already logged in
     } else {
         $this->requestAuthentication($event, $request->getUri());
     }
 }