diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 21d57da..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "tools/phptools"] - path = tools/phptools - url = git://github.com/ralphschindler/PHPTools.git diff --git a/.travis/run-tests.sh b/.travis/run-tests.sh deleted file mode 100755 index a84e0ba..0000000 --- a/.travis/run-tests.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -travisdir=$(dirname "$0") -testdir="$travisdir/../tests" -testedcomponents=(`cat "$travisdir/tested-components"`) -result=0 - -for tested in "${testedcomponents[@]}" - do - echo "$tested:" - phpunit -c $testdir/phpunit.xml.dist $testdir/$tested - result=$(($result || $?)) -done - -exit $result diff --git a/.travis/skipped-components b/.travis/skipped-components deleted file mode 100644 index 171dfe9..0000000 --- a/.travis/skipped-components +++ /dev/null @@ -1,7 +0,0 @@ -Zend/Amf -Zend/Date -Zend/Dojo -Zend/Queue -Zend/Service -Zend/Test -Zend/Wildfire diff --git a/.travis/tested-components b/.travis/tested-components deleted file mode 100644 index b0b9438..0000000 --- a/.travis/tested-components +++ /dev/null @@ -1,61 +0,0 @@ -Zend/Acl -Zend/Authentication -Zend/Barcode -Zend/Cache -Zend/Captcha -Zend/Cloud -Zend/Code -Zend/Config -Zend/Console -Zend/Crypt -Zend/Currency -Zend/Db -Zend/Di -Zend/DocBook -Zend/Dojo -Zend/Dom -Zend/EventManager -Zend/Feed -Zend/File -Zend/Filter -Zend/Form -Zend/GData -Zend/Http -Zend/InfoCard -Zend/InputFilter -Zend/Json -Zend/Ldap -Zend/Loader -Zend/Locale -Zend/Log -Zend/Mail -Zend/Markup -Zend/Math -Zend/Measure -Zend/Memory -Zend/Mime -Zend/ModuleManager -Zend/Mvc -Zend/Navigation -Zend/OAuth -Zend/OpenId -Zend/Paginator -Zend/Pdf -Zend/ProgressBar -Zend/RegistryTest.php -Zend/Rest -Zend/Search -Zend/Serializer -Zend/Server -Zend/Session -Zend/Soap -Zend/Stdlib -Zend/Tag -Zend/Text -Zend/TimeSync -Zend/Translator -Zend/Uri -Zend/Validator -Zend/VersionTest.php -Zend/View -Zend/XmlRpc diff --git a/composer.json b/composer.json index f908f59..f48e124 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zendframework/zend-authentication", - "description": "Zend\\Authentication component", + "description": "provides an API for authentication and includes concrete authentication adapters for common use case scenarios", "license": "BSD-3-Clause", "keywords": [ "zf2", @@ -9,11 +9,11 @@ "homepage": "/~https://github.com/zendframework/zend-authentication", "autoload": { "psr-4": { - "Zend\\Authentication\\": "src/" + "Zend\\Authentication": "src/" } }, "require": { - "php": ">=5.3.23", + "php": ">=5.3.3", "zendframework/zend-stdlib": "self.version" }, "require-dev": { diff --git a/src/Adapter/AdapterInterface.php b/src/Adapter/AdapterInterface.php index d5584d5..e85a202 100644 --- a/src/Adapter/AdapterInterface.php +++ b/src/Adapter/AdapterInterface.php @@ -1,22 +1,11 @@ prepareStatement($this->_zendDb, $statement); $resultSet = new ResultSet(); try { - $resultSet->setDataSource($statement->execute(array($this->_credential, $this->_identity))); + $resultSet->initialize($statement->execute(array($this->_credential, $this->_identity))); $resultIdentities = $resultSet->toArray(); } catch (\Exception $e) { throw new Exception\RuntimeException( diff --git a/src/Adapter/Digest.php b/src/Adapter/Digest.php index ff2c403..b10df9e 100644 --- a/src/Adapter/Digest.php +++ b/src/Adapter/Digest.php @@ -1,22 +1,11 @@ _request->headers(); + $headers = $this->_request->getHeaders(); if (!$headers->has($getHeader)) { return $this->_challengeClient(); } @@ -412,7 +399,7 @@ protected function _challengeClient() $this->_response->setStatusCode($statusCode); // Send a challenge in each acceptable authentication scheme - $headers = $this->_response->headers(); + $headers = $this->_response->getHeaders(); if (in_array('basic', $this->_acceptSchemes)) { $headers->addHeaderLine($headerName, $this->_basicHeader()); } @@ -496,14 +483,19 @@ protected function _basicAuth($header) return $this->_challengeClient(); } - $password = $this->_basicResolver->resolve($creds[0], $this->_realm); - if ($password && - $this->_secureStringCompare($password, $creds[1])) { + $result = $this->_basicResolver->resolve($creds[0], $this->_realm, $creds[1]); + + if ($result + && !is_array($result) + && $this->_secureStringCompare($result, $creds[1]) + ) { $identity = array('username'=>$creds[0], 'realm'=>$this->_realm); return new Authentication\Result(Authentication\Result::SUCCESS, $identity); - } else { - return $this->_challengeClient(); + } elseif (is_array($result)) { + return new Authentication\Result(Authentication\Result::SUCCESS, $result); } + + return $this->_challengeClient(); } /** @@ -614,7 +606,7 @@ protected function _calcNonce() // would be surprising if the user just logged in. $timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout; - $nonce = hash('md5', $timeout . ':' . $this->_request->server()->get('HTTP_USER_AGENT') . ':' . __CLASS__); + $nonce = hash('md5', $timeout . ':' . $this->_request->getServer()->get('HTTP_USER_AGENT') . ':' . __CLASS__); return $nonce; } @@ -688,7 +680,7 @@ protected function _parseDigestAuth($header) // Section 3.2.2.5 in RFC 2617 says the authenticating server must // verify that the URI field in the Authorization header is for the // same resource requested in the Request Line. - $rUri = $this->_request->uri(); + $rUri = $this->_request->getUri(); $cUri = UriFactory::factory($temp[1]); // Make sure the path portion of both URIs is the same @@ -744,7 +736,7 @@ protected function _parseDigestAuth($header) if (!$ret || empty($temp[1])) { // Big surprise: IE isn't RFC 2617-compliant. - $headers = $this->_request->headers(); + $headers = $this->_request->getHeaders(); if (!$headers->has('User-Agent')) { return false; } diff --git a/src/Adapter/Http/Exception/ExceptionInterface.php b/src/Adapter/Http/Exception/ExceptionInterface.php index 2998aad..738ba57 100644 --- a/src/Adapter/Http/Exception/ExceptionInterface.php +++ b/src/Adapter/Http/Exception/ExceptionInterface.php @@ -1,22 +1,11 @@ _xmlToken = $strXmlDocument; - $this->_infoCard = new ZendInfoCard\InfoCard(); - } - - /** - * Sets the InfoCard component Adapter to use - * - * @param ZendInfoCard\Adapter\AdapterInterface $a - * @return InfoCard Provides a fluent interface - */ - public function setAdapter(ZendInfoCard\Adapter\AdapterInterface $a) - { - $this->_infoCard->setAdapter($a); - return $this; - } - - /** - * Retrieves the InfoCard component adapter being used - * - * @return AdapterInterface - */ - public function getAdapter() - { - return $this->_infoCard->getAdapter(); - } - - /** - * Retrieves the InfoCard public key cipher object being used - * - * @return ZendInfoCard\Cipher\PKI\PKIInterface - */ - public function getPKCipherObject() - { - return $this->_infoCard->getPKCipherObject(); - } - - /** - * Sets the InfoCard public key cipher object to use - * - * @param ZendInfoCard\Cipher\PKI\PKIInterface $cipherObj - * @return InfoCard Provides a fluent interface - */ - public function setPKICipherObject(ZendInfoCard\Cipher\PKI\PKIInterface $cipherObj) - { - $this->_infoCard->setPKICipherObject($cipherObj); - return $this; - } - - /** - * Retrieves the Symmetric cipher object being used - * - * @return ZendInfoCard\Cipher\Symmetric\AES128CBCInterface - */ - public function getSymCipherObject() - { - return $this->_infoCard->getSymCipherObject(); - } - - /** - * Sets the InfoCard symmetric cipher object to use - * - * @param ZendInfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj - * @return InfoCard Provides a fluent interface - */ - public function setSymCipherObject(ZendInfoCard\Cipher\Symmetric\AES128CBCInterface $cipherObj) - { - $this->_infoCard->setSymCipherObject($cipherObj); - return $this; - } - - /** - * Remove a Certificate Pair by Key ID from the search list - * - * @param string $keyId The Certificate Key ID returned from adding the certificate pair - * @throws ZendInfoCard\Exception\ExceptionInterface - * @return InfoCard Provides a fluent interface - */ - public function removeCertificatePair($keyId) - { - $this->_infoCard->removeCertificatePair($keyId); - return $this; - } - - /** - * Add a Certificate Pair to the list of certificates searched by the component - * - * @param string $privateKeyFile The path to the private key file for the pair - * @param string $publicKeyFile The path to the certificate / public key for the pair - * @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding) - * @param string $password (optional) The password for the private key file if necessary - * @throws ZendInfoCard\Exception\ExceptionInterface - * @return string A key ID representing this key pair in the component - */ - public function addCertificatePair($privateKeyFile, $publicKeyFile, $type = ZendInfoCard\Cipher::ENC_RSA_OAEP_MGF1P, $password = null) - { - return $this->_infoCard->addCertificatePair($privateKeyFile, $publicKeyFile, $type, $password); - } - - /** - * Return a Certificate Pair from a key ID - * - * @param string $keyId The Key ID of the certificate pair in the component - * @throws ZendInfoCard\Exception\ExceptionInterface - * @return array An array containing the path to the private/public key files, - * the type URI and the password if provided - */ - public function getCertificatePair($keyId) - { - return $this->_infoCard->getCertificatePair($keyId); - } - - /** - * Set the XML Token to be processed - * - * @param string $strXmlToken The XML token to process - * @return \Zend\Authentication\Adapter\InfoCard Provides a fluent interface - */ - public function setXmlToken($strXmlToken) - { - $this->_xmlToken = $strXmlToken; - return $this; - } - - /** - * Get the XML Token being processed - * - * @return string The XML token to be processed - */ - public function getXmlToken() - { - return $this->_xmlToken; - } - - /** - * 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 - ); - } -} diff --git a/src/Adapter/Ldap.php b/src/Adapter/Ldap.php index e248c6f..4c874b3 100644 --- a/src/Adapter/Ldap.php +++ b/src/Adapter/Ldap.php @@ -1,22 +1,11 @@ getMessage(); - } else if ($err == LdapException::LDAP_INVALID_CREDENTIALS) { + } elseif ($err == LdapException::LDAP_INVALID_CREDENTIALS) { $code = AuthenticationResult::FAILURE_CREDENTIAL_INVALID; $messages[0] = 'Invalid credentials'; $failedAuthorities[$dname] = $zle->getMessage(); diff --git a/src/AuthenticationService.php b/src/AuthenticationService.php index 26b9095..4a63f72 100644 --- a/src/AuthenticationService.php +++ b/src/AuthenticationService.php @@ -1,21 +1,11 @@ _adapter->setIdentity('non_existent_username'); $this->_adapter->setCredential('my_password'); - try { - $result = $this->_adapter->authenticate(); - $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); - } catch (Adapter\Exception\RuntimeException $e) { - $this->fail('Exception should have been thrown'); - } + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); } /** @@ -134,12 +117,8 @@ public function testAuthenticateFailureIdentityAmbiguous() $this->_adapter->setIdentity('my_username'); $this->_adapter->setCredential('my_password'); - try { - $result = $this->_adapter->authenticate(); - $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_AMBIGUOUS, $result->getCode()); - } catch (Adapter\Exception\RuntimeException $e) { - $this->fail('Exception should have been thrown'); - } + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_AMBIGUOUS, $result->getCode()); } /** @@ -208,12 +187,9 @@ public function testAdapterCanUseModifiedDbSelectObject() $select->where('1 = 0'); $this->_adapter->setIdentity('my_username'); $this->_adapter->setCredential('my_password'); - try { - $result = $this->_adapter->authenticate(); - $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); - } catch (Adapter\Exception\RuntimeException $e) { - $this->fail('Exception should have been thrown'); - } + + $result = $this->_adapter->authenticate(); + $this->assertEquals(Authentication\Result::FAILURE_IDENTITY_NOT_FOUND, $result->getCode()); } /** diff --git a/test/Adapter/DigestTest.php b/test/Adapter/DigestTest.php index 309abd8..5352c9d 100644 --- a/test/Adapter/DigestTest.php +++ b/test/Adapter/DigestTest.php @@ -1,22 +1,11 @@ setUri('http://localhost/'); $request->setMethod('GET'); $request->setServer(new Parameters(array('HTTP_USER_AGENT' => 'PHPUnit'))); - $headers = $request->headers(); + $headers = $request->getHeaders(); $headers->addHeaderLine('Authorization', $clientHeader); // Select an Authentication scheme @@ -370,7 +357,7 @@ protected function _doAuth($clientHeader, $scheme) $return = array( 'result' => $result, 'status' => $response->getStatusCode(), - 'headers' => $response->headers(), + 'headers' => $response->getHeaders(), ); return $return; } diff --git a/test/Adapter/Http/FileResolverTest.php b/test/Adapter/Http/FileResolverTest.php index 0d75554..098fc45 100644 --- a/test/Adapter/Http/FileResolverTest.php +++ b/test/Adapter/Http/FileResolverTest.php @@ -1,22 +1,11 @@ _basicConfig); - } catch (Adapter\Exception\ExceptionInterface $e) { - $this->fail('Valid config deemed invalid'); - } - $this->assertFalse(empty($t)); - $this->assertInstanceOf('Zend\\Authentication\\Adapter\\Http', $t); - unset($t); - - try { - $t = new Adapter\Http($this->_digestConfig); - } catch (Adapter\Exception\ExceptionInterface $e) { - $this->fail('Valid config deemed invalid'); - } - $this->assertFalse(empty($t)); - $this->assertInstanceOf('Zend\\Authentication\\Adapter\\Http', $t); - unset($t); - - try { - $t = new Adapter\Http($this->_bothConfig); - } catch (Adapter\Exception\ExceptionInterface $e) { - $this->fail('Valid config deemed invalid'); - } - $this->assertFalse(empty($t)); - $this->assertInstanceOf('Zend\\Authentication\\Adapter\\Http', $t); - unset($t); + $configs = array ( + $this->_basicConfig, + $this->_digestConfig, + $this->_bothConfig, + ); + foreach($configs as $config) + new Adapter\Http($config); } public function testInvalidConfigs() diff --git a/test/Adapter/Http/ProxyTest.php b/test/Adapter/Http/ProxyTest.php index 346bd07..5bbdc5f 100644 --- a/test/Adapter/Http/ProxyTest.php +++ b/test/Adapter/Http/ProxyTest.php @@ -1,38 +1,25 @@ $result, 'status' => $response->getStatusCode(), - 'headers' => $response->headers(), + 'headers' => $response->getHeaders(), ); return $return; } diff --git a/test/Adapter/Ldap/OfflineTest.php b/test/Adapter/Ldap/OfflineTest.php index 4676c42..55696b1 100644 --- a/test/Adapter/Ldap/OfflineTest.php +++ b/test/Adapter/Ldap/OfflineTest.php @@ -1,35 +1,22 @@