/** * Authenticates the XML token * * @return Zend_Auth_Result The result of the authentication */ public function authenticate() { try { $claims = $this->_infoCard->process($this->getXmlToken()); } catch(Exception $e) { return new Zend_Auth_Result(Zend_Auth_Result::FAILURE , null, array('Exception Thrown', $e->getMessage(), $e->getTraceAsString(), serialize($e))); } if(!$claims->isValid()) { switch($claims->getCode()) { case Zend_infoCard_Claims::RESULT_PROCESSING_FAILURE: return new Zend_Auth_Result( Zend_Auth_Result::FAILURE, $claims, array( 'Processing Failure', $claims->getErrorMsg() ) ); break; case Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE: return new Zend_Auth_Result( Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $claims, array( 'Validation Failure', $claims->getErrorMsg() ) ); break; default: return new Zend_Auth_Result( Zend_Auth_Result::FAILURE, $claims, array( 'Unknown Failure', $claims->getErrorMsg() ) ); break; } } return new Zend_Auth_Result( Zend_Auth_Result::SUCCESS, $claims ); }
public function testClaims() { $infoCard = new Zend_InfoCard(); $infoCard->addCertificatePair($this->sslPrvKey, $this->sslPubKey); $claims = $infoCard->process($this->_xmlDocument); $this->assertTrue($claims instanceof Zend_InfoCard_Claims); $this->assertFalse($claims->isValid()); $this->assertSame($claims->getCode(), Zend_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(Zend_InfoCard_Exception $e) { } catch(Exception $e) { $this->assertFalse(true); } try { $claims->givenname = "Test"; } catch(Zend_InfoCard_Exception $e) { } catch(Exception $e) { $this->assertFalse(true); } $this->assertTrue(isset($claims->givenname)); }
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 Zend_InfoCard(); } catch (Zend_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 Zend_InfoCard_Claims); $this->assertFalse($claims->isValid()); $this->assertSame($claims->getCode(), Zend_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 (Zend_InfoCard_Exception $e) { } catch (Exception $e) { $this->assertFalse(true); } try { $claims->givenname = "Test"; } catch (Zend_InfoCard_Exception $e) { } catch (Exception $e) { $this->assertFalse(true); } $this->assertTrue(isset($claims->givenname)); }