diff options
| author | Michael Klishin <mklishin@pivotal.io> | 2017-01-04 16:26:13 +0800 |
|---|---|---|
| committer | Michael Klishin <mklishin@pivotal.io> | 2017-01-04 16:26:13 +0800 |
| commit | 833e65ef52fac14664fd82f808aa55f306a0ce72 (patch) | |
| tree | e16527253c72b99ba541d61c52de25ed1c841ced /src | |
| parent | ccebf4a0043d2c346f33cb95ece1995a10e8735c (diff) | |
| download | rabbitmq-server-git-833e65ef52fac14664fd82f808aa55f306a0ce72.tar.gz | |
Introduce rabbit_credential_validation; fix validators for successful integration
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_credential_validation.erl | 52 | ||||
| -rw-r--r-- | src/rabbit_credential_validator.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_credential_validator_accept_everything.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_credential_validator_min_length.erl | 4 | ||||
| -rw-r--r-- | src/rabbit_credential_validator_regexp.erl | 12 |
5 files changed, 62 insertions, 10 deletions
diff --git a/src/rabbit_credential_validation.erl b/src/rabbit_credential_validation.erl new file mode 100644 index 0000000000..696024548a --- /dev/null +++ b/src/rabbit_credential_validation.erl @@ -0,0 +1,52 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is GoPivotal, Inc. +%% Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. +%% + +-module(rabbit_credential_validation). + +-include("rabbit.hrl"). + +%% used for backwards compatibility +-define(DEFAULT_BACKEND, rabbit_credential_validator_accept_everything). + +%% +%% API +%% + +-export([validate_password/1, backend/0]). + +-spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string()}. + +%% Validates a password by delegating to the effective +%% `rabbit_credential_validator`. Used by `rabbit_auth_backend_internal`. +%% +%% Possible return values: +%% +%% * ok: provided password passed validation. +%% * {error, Error, Args}: provided password password failed validation. + +validate_password(Value) -> + Backend = backend(), + Backend:validate_password(Value). + +-spec backend() -> atom(). + +backend() -> + case application:get_env(rabbit, credential_validator) of + undefined -> + ?DEFAULT_BACKEND; + {ok, Proplist} -> + proplists:get_value(validation_backend, Proplist, ?DEFAULT_BACKEND) + end. diff --git a/src/rabbit_credential_validator.erl b/src/rabbit_credential_validator.erl index 3fb5c481cc..b556995f51 100644 --- a/src/rabbit_credential_validator.erl +++ b/src/rabbit_credential_validator.erl @@ -25,4 +25,4 @@ %% * ok: provided password passed validation. %% * {error, Error, Args}: provided password password failed validation. --callback validate_password(rabbit_types:password()) -> 'ok' | {'error', string(), [any()]}. +-callback validate_password(rabbit_types:password()) -> 'ok' | {'error', string()}. diff --git a/src/rabbit_credential_validator_accept_everything.erl b/src/rabbit_credential_validator_accept_everything.erl index e43e898416..ea04d09ce1 100644 --- a/src/rabbit_credential_validator_accept_everything.erl +++ b/src/rabbit_credential_validator_accept_everything.erl @@ -26,7 +26,7 @@ -export([validate_password/1]). --spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string(), [any()]}. +-spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string()}. validate_password(_Password) -> ok. diff --git a/src/rabbit_credential_validator_min_length.erl b/src/rabbit_credential_validator_min_length.erl index d4bb36778d..cb5973d3ed 100644 --- a/src/rabbit_credential_validator_min_length.erl +++ b/src/rabbit_credential_validator_min_length.erl @@ -32,13 +32,13 @@ %% for tests -export([validate_password/2]). --spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string(), [any()]}. +-spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string()}. validate_password(Password) -> MinLength = case application:get_env(rabbit, credential_validator) of undefined -> ?DEFAULT_MIN_LENGTH; - Proplist -> + {ok, Proplist} -> case proplists:get_value(min_length, Proplist) of undefined -> ?DEFAULT_MIN_LENGTH; Value -> rabbit_data_coercion:to_integer(Value) diff --git a/src/rabbit_credential_validator_regexp.erl b/src/rabbit_credential_validator_regexp.erl index a8d4f36d1b..3c58529bf3 100644 --- a/src/rabbit_credential_validator_regexp.erl +++ b/src/rabbit_credential_validator_regexp.erl @@ -28,14 +28,14 @@ %% for tests -export([validate_password/2]). --spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string(), [any()]}. +-spec validate_password(rabbit_types:password()) -> 'ok' | {'error', string()}. validate_password(Password) -> - Proplist = application:get_env(rabbit, credential_validator), - Regexp = case proplists:get_value(regexp, Proplist) of - undefined -> {error, "rabbit.credential_validator.regexp config key is undefined"}; - Value -> rabbit_data_coercion:to_list(Value) - end, + {ok, Proplist} = application:get_env(rabbit, credential_validator), + Regexp = case proplists:get_value(regexp, Proplist) of + undefined -> {error, "rabbit.credential_validator.regexp config key is undefined"}; + Value -> rabbit_data_coercion:to_list(Value) + end, validate_password(Password, Regexp). |
