Пример #1
0
    /**
     * Authenticates the XML token
     *
     * @return AuthenticationResult The result of the authentication
     */
    public function authenticate()
    {
        try {
            $claims = $this->_infoCard->process($this->getXmlToken());
        } catch(\Exception $e) {
            return new AuthenticationResult(
                AuthenticationResult::FAILURE,
                null,
                array('Exception Thrown',
                      $e->getMessage(),
                      $e->getTraceAsString(),
                      serialize($e)));
        }

        if (!$claims->isValid()) {
            switch($claims->getCode()) {
                case ZendInfoCard\Claims::RESULT_PROCESSING_FAILURE:
                    return new AuthenticationResult(
                        AuthenticationResult::FAILURE,
                        $claims,
                        array(
                            'Processing Failure',
                            $claims->getErrorMsg()
                        )
                    );
                    break;
                case ZendInfoCard\Claims::RESULT_VALIDATION_FAILURE:
                    return new AuthenticationResult(
                        AuthenticationResult::FAILURE_CREDENTIAL_INVALID,
                        $claims,
                        array(
                            'Validation Failure',
                            $claims->getErrorMsg()
                        )
                    );
                    break;
                default:
                    return new AuthenticationResult(
                        AuthenticationResult::FAILURE,
                        $claims,
                        array(
                            'Unknown Failure',
                            $claims->getErrorMsg()
                        )
                    );
                    break;
            }
        }

        return new AuthenticationResult(
            AuthenticationResult::SUCCESS,
            $claims
        );
    }
Пример #2
0
 public function testClaimsThrowsExceptionOnMutation()
 {
     $this->requireMcryptAndOpensslOrSkip();
     $infoCard = new InfoCard\InfoCard();
     $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey);
     $claims = $infoCard->process($this->_xmlDocument);
     $this->setExpectedException('Zend\\InfoCard\\Exception\\InvalidArgumentException', 'Claim objects are read-only');
     $claims->givenname = "Test";
 }
Пример #3
0
 public function testClaims()
 {
     if (version_compare(PHP_VERSION, '5.2.0', '<')) {
         $this->markTestSkipped('DOMDocument::C14N() not available until PHP 5.2.0');
     }
     try {
         $infoCard = new InfoCard\InfoCard();
     } catch (InfoCard\Exception $e) {
         $message = $e->getMessage();
         if (preg_match('/requires.+mcrypt/', $message)) {
             $this->markTestSkipped($message);
         } else {
             throw $e;
         }
     }
     $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey);
     $claims = $infoCard->process($this->_xmlDocument);
     $this->assertTrue($claims instanceof InfoCard\Claims);
     $this->assertFalse($claims->isValid());
     $this->assertSame($claims->getCode(), InfoCard\Claims::RESULT_VALIDATION_FAILURE);
     $errormsg = $claims->getErrorMsg();
     $this->assertTrue(!empty($errormsg));
     @$claims->forceValid();
     $this->assertTrue($claims->isValid());
     $this->assertSame($claims->emailaddress, "*****@*****.**");
     $this->assertSame($claims->givenname, "John");
     $this->assertSame($claims->surname, "Coggeshall");
     $this->assertSame($claims->getCardID(), "rW1/y9BuncoBK4WSipF2hHYParxxgMHk6ANBrhz1Zr4=");
     $this->assertSame($claims->getClaim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"), "*****@*****.**");
     $this->assertSame($claims->getDefaultNamespace(), "http://schemas.xmlsoap.org/ws/2005/05/identity/claims");
     try {
         unset($claims->givenname);
     } catch (InfoCard\Exception $e) {
     } catch (\Exception $e) {
         $this->assertFalse(true);
     }
     try {
         $claims->givenname = "Test";
     } catch (InfoCard\Exception $e) {
     } catch (\Exception $e) {
         $this->assertFalse(true);
     }
     $this->assertTrue(isset($claims->givenname));
 }