Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: zendframework/zend-authentication
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: release-2.6.0
Choose a base ref
...
head repository: zendframework/zend-authentication
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: release-2.7.0
Choose a head ref

Commits on Oct 14, 2016

  1. Copy the full SHA
    db92a61 View commit details

Commits on Apr 12, 2018

  1. 2.6.0 readiness

    weierophinney committed Apr 12, 2018
    Copy the full SHA
    47f2803 View commit details
  2. Copy the full SHA
    01769cc View commit details
  3. Bumped version

    weierophinney committed Apr 12, 2018
    Copy the full SHA
    026005f View commit details
  4. Bumped version

    weierophinney committed Apr 12, 2018
    Copy the full SHA
    8713734 View commit details

Commits on May 8, 2018

  1. Copy the full SHA
    9bb42ea View commit details

Commits on Jun 8, 2018

  1. There is a fault in a function name.

    setCredentialValidatinCallback($passwordValidation); => setCredentialValidationCallback($passwordValidation);
    Antoine Blanchard authored Jun 8, 2018
    Copy the full SHA
    21b1276 View commit details

Commits on Jul 9, 2018

  1. Copy the full SHA
    7d8a01a View commit details

Commits on Dec 15, 2018

  1. Copy the full SHA
    aa627c3 View commit details

Commits on Dec 16, 2018

  1. Copy the full SHA
    de87a7d View commit details

Commits on Jan 24, 2019

  1. Fixed typo in link syntax

    arueckauer authored and weierophinney committed Jan 24, 2019
    Copy the full SHA
    6f54071 View commit details
  2. Copy the full SHA
    0a97ea6 View commit details

Commits on Jan 26, 2019

  1. Removed support for zend-stdlib v2 releases

    The latest version 2.7.7 of v2 series is no longer supported and doesn't
    have PHP 7.3 support. We can drop it and leave just v3 series support.
    michalbundyra committed Jan 26, 2019
    Copy the full SHA
    99825fd View commit details
  2. Copy the full SHA
    fd55d07 View commit details

Commits on May 6, 2019

  1. Merge branch 'feature/44' into develop

    Close #44
    Xerkus committed May 6, 2019
    Copy the full SHA
    f77d3de View commit details
  2. Copy the full SHA
    ef8e1c1 View commit details
  3. Copy the full SHA
    8a5064d View commit details
  4. Copy the full SHA
    9c49a5e View commit details
  5. Merge branch 'hotfix/40'

    Close #40
    Xerkus committed May 6, 2019
    Copy the full SHA
    96878e4 View commit details
  6. Merge branch 'hotfix/40' into develop

    Forward port #40
    Xerkus committed May 6, 2019
    Copy the full SHA
    11c0f68 View commit details
  7. Merge branch 'feature/46'

    Close #46
    Xerkus committed May 6, 2019
    Copy the full SHA
    cbfec9c View commit details
  8. Merge branch 'feature/46' into develop

    Forward port #46
    Xerkus committed May 6, 2019
    Copy the full SHA
    adf3951 View commit details
  9. Merge branch 'feature/38' into develop

    Close #38
    Xerkus committed May 6, 2019
    Copy the full SHA
    19f407d View commit details
  10. Merge branch 'feature/39' into develop

    Close #39
    Xerkus committed May 6, 2019
    Copy the full SHA
    832fe58 View commit details

Commits on May 13, 2019

  1. Copy the full SHA
    2fb10c5 View commit details
  2. Copy the full SHA
    bf739e8 View commit details
  3. Document new feature

    Xerkus committed May 13, 2019
    Copy the full SHA
    a45cd0d View commit details
  4. Copy the full SHA
    d7cc1ac View commit details
  5. Add CHANGELOG for #42

    Xerkus committed May 13, 2019
    Copy the full SHA
    55959bd View commit details
  6. Merge branch 'feature/42' into develop

    Close #42
    Xerkus committed May 13, 2019
    Copy the full SHA
    9b3620e View commit details

Commits on May 14, 2019

  1. Copy the full SHA
    45ec999 View commit details
  2. Apply suggestions from code review

    Co-Authored-By: Matthew Weier O'Phinney <matthew@weierophinney.net>
    Xerkus and weierophinney authored May 14, 2019
    Copy the full SHA
    da6c111 View commit details
  3. Add CHANGELOG for #47

    Xerkus committed May 14, 2019
    Copy the full SHA
    2268e32 View commit details
  4. Merge branch 'feature/47' into develop

    Close #47
    Xerkus committed May 14, 2019
    Copy the full SHA
    8a0edbd View commit details
  5. Merge branch 'develop'

    Xerkus committed May 14, 2019
    Copy the full SHA
    a12f650 View commit details
  6. 2.7.0 readiness

    Xerkus committed May 14, 2019
    Copy the full SHA
    1f379f6 View commit details
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
sudo: false

language: php

cache:
@@ -54,6 +52,15 @@ matrix:
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=locked
- php: 7.3
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,33 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.0 - 2019-05-14

### Added

- [#44](https://github.com/zendframework/zend-authentication/pull/44) adds support for PHP 7.3.
- [#47](https://github.com/zendframework/zend-authentication/pull/47) adds
configuration option to `Zend\Authentication\Validator\Authentication` for
mapping custom authentication result codes to existing and new validation
message types.

### Changed

- [#42](https://github.com/zendframework/zend-authentication/pull/42) Changes authentication using Basic scheme
to re-challenge the client when credentials in Authorization header can not be base64 decoded.

### Deprecated

- Nothing.

### Removed

- [#44](https://github.com/zendframework/zend-authentication/pull/44) removes support for zend-stdlib v2 releases.

### Fixed

- Nothing.

## 2.6.0 - 2018-04-12

### Added
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
},
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-stdlib": "^2.7.7 || ^3.1"
"zendframework/zend-stdlib": "^3.2.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.2",
@@ -57,8 +57,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.6.x-dev",
"dev-develop": "2.7.x-dev"
"dev-master": "2.7.x-dev",
"dev-develop": "2.8.x-dev"
}
},
"scripts": {
29 changes: 15 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/book/adapter/dbtable/callback-check.md
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@ $authAdapter
->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password')
->setCredentialValidatinCallback($passwordValidation);
->setCredentialValidationCallback($passwordValidation);
```

At this point, the authentication adapter instance is ready to accept
@@ -214,7 +214,7 @@ As an example, many websites require a user to activate their account before
allowing them to login for the first time. We can add that criteria as follows:

```php
// Create a basic adapter, with only an MD5() credential treatment:
// Create a basic adapter
$adapter = new AuthAdapter(
$db,
'users',
44 changes: 34 additions & 10 deletions docs/book/adapter/dbtable/credential-treatment.md
Original file line number Diff line number Diff line change
@@ -3,8 +3,30 @@
`Zend\Authentication\Adapter\DbTable\CredentialTreatmentAdapter` will execute a
SQL query containing the provided identity and credentials, passing the
credentials to a *credential treatment* function defined on the RDBMS server;
if an identity is returned, authentication succeeds. Common credential
treatments include `MD5()` and `PASSWORD()`.
if an identity is returned, authentication succeeds. Credential
treatments depends on your RDBMS, and while simple hashing function such as
`md5` and `sha1` are generally available, it is recommended not to use them and
rather use the RDBMS specific function such as
[`PASSWORD(?)` for MySQL](http://dev.mysql.com/doc/refman/5.7/en/password-hashing.html) or
[`crypt()` for PostgreSQL](https://www.postgresql.org/docs/11/pgcrypto.html#id-1.11.7.34.6).
More details are available in the next section.

## Security considerations

Passing passwords to database in plaintext for insert or verification is
generally not recommended.
Sql statements can and usually are logged by the database, and passwords in them
become visible to anyone with access to the logs or monitoring tools that
consume those logs.

The safer approach is to hash passwords, and to verify them against a stored
hash in your application code. This way the password never leaves the
application, and only the hashed value is exchanged with the database.

As such, this adapter is not recommended for new applications, and existing
applications should consider migrating to using PHP-provided password handling
functions such as `password_hash()` and `password_verify()`. See
[CallbackCheckAdapter](callback-check.md) for more info.

## Configuration Options

@@ -23,7 +45,7 @@ The available configuration options include:
- `credentialTreatment`: In many cases, passwords and other sensitive data
are encrypted, hashed, encoded, obscured, salted or otherwise treated through
some function or algorithm. By specifying a parameterized treatment string
with this method, such as '`MD5(?)`' or '`PASSWORD(?)`', a developer may
with this method, such as '`PASSWORD(?)`', a developer may
apply such arbitrary SQL upon input credential data. Since these functions
are specific to the underlying RDBMS, check the database manual for the
availability of such functions for your database system.
@@ -186,7 +208,7 @@ credential treatment to solve more complex problems.

### Check for compromised user

In this scenario, we use the credential treatment `MD5()`, but also check to see
In this scenario, we use the credential treatment `PASSWORD()`, but also check to see
that the user has not been flagged as "compromised", which is a potential value
of the `status` field for the user record.

@@ -199,7 +221,7 @@ $adapter = new AuthAdapter(
'users',
'username',
'password',
'MD5(?) AND status != "compromised"'
'PASSWORD(?) AND status != "compromised"'
);
```

@@ -218,7 +240,7 @@ $adapter = new AuthAdapter(
'users',
'username',
'password',
'MD5(?) AND active = "TRUE"'
'PASSWORD(?) AND active = "TRUE"'
);
```

@@ -238,7 +260,9 @@ $sqlAlter = "ALTER TABLE [users] "
. "AFTER [password]";
```

Salts should be created *for each user* using a cryptographically sound pseudo-random number generator (CSPRNG). PHP 7 provides an implementation via `random_bytes`:
Salts should be created *for each user* using a cryptographically sound pseudo-random number generator (CSPRNG).
PHP 7 provides an implementation via `random_bytes()` (and
the [random_compat package provides them for older, supported versions of PHP](https://github.com/paragonie/random_compat)):

```php
$salt = random_bytes(32);
@@ -267,7 +291,7 @@ $db,
'users',
'username',
'password',
"MD5(CONCAT('staticSalt', ?, password_salt))"
"PASSWORD(CONCAT('staticSalt', ?, password_salt))"
);
```

@@ -304,13 +328,13 @@ The following uses the second example in this section, adding another `WHERE`
clause to determine if the user is active in the system.

```php
// Create a basic adapter, with only an MD5() credential treatment:
// Create a basic adapter, with only an PASSWORD() credential treatment:
$adapter = new AuthAdapter(
$db,
'users',
'username',
'password',
'MD5(?)'
'PASSWORD(?)'
);

// Now retrieve the Select instance and modify it:
2 changes: 1 addition & 1 deletion docs/book/adapter/ldap.md
Original file line number Diff line number Diff line change
@@ -172,7 +172,7 @@ Name | Description
`password` | The password of the account used to perform account DN lookups. If this option is not supplied, the LDAP client will attempt an “anonymous bind” when performing account DN lookups.
`bindRequiresDn` | Some LDAP servers require that the username used to bind be in DN form like `CN=Alice Baker,OU=Sales,DC=foo,DC=net` (basically all servers except Active Directory). If this option is `TRUE`, this instructs `Zend\Ldap\Ldap` to automatically retrieve the DN corresponding to the username being authenticated, if it is not already in DN form, and then re-bind with the proper DN. The default value is `FALSE`. Currently only Microsoft Active Directory Server (ADS) is known not to require usernames to be in DN form when binding, and therefore this option may be `FALSE` with AD (and it should be, as retrieving the DN requires an extra round trip to the server). Otherwise, this option must be set to `TRUE` (e.g. for OpenLDAP). This option also controls the default `accountFilterFormat` used when searching for accounts. See the `accountFilterFormat` option.
`baseDn` | The DN under which all accounts being authenticated are located. This option is required. if you are uncertain about the correct baseDn value, it should be sufficient to derive it from the user’s DNS domain using `DC=` components. For example, if the user’s principal name is `alice@foo.net`, a `baseDn` of `DC=foo,DC=net` should work. A more precise location (e.g., `OU=Sales,DC=foo,DC=net`) will be more efficient, however.
`accountCanonicalForm` | A value of 2, 3, or 4 indicating the form to which account names should be canonicalized after successful authentication. Values are as follows: 2 for traditional username style names (e.g., `alice`), 3 for backslash-style names (e.g., `FOO\alice`) or 4 for principal style usernames (e.g., `alice@foo.net`). The default value is 4 (e.g., `alice@foo.net`). For example, with a value of 3, the identity returned by `Zend\Authentication\Result::getIdentity()` (and `Zend\Authentication\AuthenticationService::getIdentity()`, if `Zend\Authentication\AuthenticationService` was used) will always be `FOO\alice`, regardless of what form Alice supplied, whether it be `alice`, `alice@foo.net`, `FOO\alice`, `FoO\aLicE`, `foo.net\alice`, etc. See the []Account Name Canonicalization](http://framework.zend.com/manual/current/en/modules/zend.ldap.introduction.html#account-name-canonicalization) section in the zend-ldap documentation for details. Note that when using multiple sets of server options it is recommended, but not required, that the same `accountCanonicalForm` be used with all server options so that the resulting usernames are always canonicalized to the same form (e.g., if you canonicalize to `EXAMPLE\username` with an AD server but to `username@example.com` with an OpenLDAP server, that may be awkward for the application’s high-level logic).
`accountCanonicalForm` | A value of 2, 3, or 4 indicating the form to which account names should be canonicalized after successful authentication. Values are as follows: 2 for traditional username style names (e.g., `alice`), 3 for backslash-style names (e.g., `FOO\alice`) or 4 for principal style usernames (e.g., `alice@foo.net`). The default value is 4 (e.g., `alice@foo.net`). For example, with a value of 3, the identity returned by `Zend\Authentication\Result::getIdentity()` (and `Zend\Authentication\AuthenticationService::getIdentity()`, if `Zend\Authentication\AuthenticationService` was used) will always be `FOO\alice`, regardless of what form Alice supplied, whether it be `alice`, `alice@foo.net`, `FOO\alice`, `FoO\aLicE`, `foo.net\alice`, etc. See the [Account Name Canonicalization](http://framework.zend.com/manual/current/en/modules/zend.ldap.introduction.html#account-name-canonicalization) section in the zend-ldap documentation for details. Note that when using multiple sets of server options it is recommended, but not required, that the same `accountCanonicalForm` be used with all server options so that the resulting usernames are always canonicalized to the same form (e.g., if you canonicalize to `EXAMPLE\username` with an AD server but to `username@example.com` with an OpenLDAP server, that may be awkward for the application’s high-level logic).
`accountDomainName` | The FQDN domain name for which the target LDAP server is an authority (e.g., `example.com`). This option is used to canonicalize names so that the username supplied by the user can be converted as necessary for binding. It is also used to determine if the server is an authority for the supplied username (e.g., if `accountDomainName` is `foo.net` and the user supplies `bob@bar.net`, the server will not be queried, and a failure will result). This option is not required, but if it is not supplied, usernames in principal name form (e.g., `alice@foo.net`) are not supported. It is strongly recommended that you supply this option, as there are many use-cases that require generating the principal name form.
`accountDomainNameShort` | The ‘short’ domain for which the target LDAP server is an authority (e.g., `FOO`). Note that there is a 1:1 mapping between the `accountDomainName` and `accountDomainNameShort`. This option should be used to specify the NetBIOS domain name for Windows networks, but may also be used by non-AD servers (e.g., for consistency when multiple sets of server options with the backslash style `accountCanonicalForm`). This option is not required but if it is not supplied, usernames in backslash form (e.g., `FOO\alice`) are not supported.
`accountFilterFormat` | The LDAP search filter used to search for accounts. This string is a `printf()`-style expression that must contain one `%s` to accommodate the username. The default value is `(&(objectClass=user)(sAMAccountName=%s))`, unless `bindRequiresDn` is set to `TRUE`, in which case the default is `(&(objectClass=posixAccount)(uid=%s))`. For example, if for some reason you wanted to use `bindRequiresDn = true` with AD you would need to set `accountFilterFormat = '(&(objectClass=user)(sAMAccountName=%s))'`.
63 changes: 63 additions & 0 deletions docs/book/validator.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ The available configuration options include:
- `identity`: the identity or name of the identity field in the provided context.
- `credential`: credential or the name of the credential field in the provided context.
- `service`: an instance of `Zend\Authentication\AuthenticationService`.
- `code_map`: map of `Zend\Authentication\Result` codes to validator message identifiers.

## Usage

@@ -33,3 +34,65 @@ $validator->isValid('myIdentity', [
'myCredentialContext' => 'myCredential',
]);
```

## Validation messages

The authentication validator defines five failure message types; identifiers
for them are available as constants for convenience.
Common authentication failure codes, defined as constants in
`Zend\Authentication\Result`, are mapped to validation messages
using a map in `CODE_MAP` constant. Other authentication codes default to the
`general` message type.

```php
namespace Zend\Authentication\Validator;

use Zend\Authentication\Result;

class Authentication
{
const IDENTITY_NOT_FOUND = 'identityNotFound';
const IDENTITY_AMBIGUOUS = 'identityAmbiguous';
const CREDENTIAL_INVALID = 'credentialInvalid';
const UNCATEGORIZED = 'uncategorized';
const GENERAL = 'general';

const CODE_MAP = [
Result::FAILURE_IDENTITY_NOT_FOUND => self::IDENTITY_NOT_FOUND,
Result::FAILURE_CREDENTIAL_INVALID => self::CREDENTIAL_INVALID,
Result::FAILURE_IDENTITY_AMBIGUOUS => self::IDENTITY_AMBIGUOUS,
Result::FAILURE_UNCATEGORIZED => self::UNCATEGORIZED,
];
}
```

The authentication validator extends `Zend\Validator\AbstractValidator`, providing
a way common for all framework validators to access, change or translate message templates.
More information is available in the
[zend-validator documentation](https://docs.zendframework.com/zend-validator/messages/)

## Configure validation messages for custom authentication result codes

The constructor configuration option `code_map` allows mapping custom codes
from `Zend\Authentication\Result` to validation message identifiers.
`code_map` is an array of integer code => string message identifier pairs

A new custom message identifier can be specified in `code_map` which will then
be registered as a new message type with the template value set to the `general` message.
Once registered, the message template for the new identifier can be changed
as described in the [zend-validator documentation](https://docs.zendframework.com/zend-validator/messages/).

```php
use Zend\Authentication\Validator\Authentication as AuthenticationValidator;

$validator = new AuthenticationValidator([
'code_map' => [
// map custom result code to existing message
-990 => AuthenticationValidator::IDENTITY_NOT_FOUND,
// map custom result code to a new message type
-991 => 'custom_failure_identifier',
],
]);

$validator->setMessage('Custom Error Happened', 'custom_failure_identifier');
```
2 changes: 1 addition & 1 deletion src/Adapter/DbTable/AbstractAdapter.php
Original file line number Diff line number Diff line change
@@ -348,7 +348,7 @@ protected function authenticateQuerySelect(Sql\Select $dbSelect)
*/
protected function authenticateValidateResultSet(array $resultIdentities)
{
if (count($resultIdentities) < 1) {
if (! $resultIdentities) {
$this->authenticateResultInfo['code'] = AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND;
$this->authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.';
return $this->authenticateCreateAuthResult();
3 changes: 1 addition & 2 deletions src/Adapter/Digest.php
Original file line number Diff line number Diff line change
@@ -162,7 +162,6 @@ public function authenticate()
}

$id = "$this->identity:$this->realm";
$idLength = strlen($id);

$result = [
'code' => AuthenticationResult::FAILURE,
@@ -178,7 +177,7 @@ public function authenticate()
if (empty($line)) {
break;
}
if (substr($line, 0, $idLength) === $id) {
if (0 === strpos($line, $id)) {
if (CryptUtils::compareStrings(
substr($line, -32),
md5("$this->identity:$this->realm:$this->credential")
Loading