Permalink
Browse files

Attempt to enforce role name uniqueness

  • Loading branch information...
1 parent 98b6830 commit 66879be3612c2582f94c798d2d64012bf8d0689d @macintux macintux committed Feb 13, 2014
Showing with 24 additions and 14 deletions.
  1. +24 −14 src/riak_core_security.erl
View
@@ -374,13 +374,18 @@ authenticate(Username, Password, ConnInfo) ->
add_user(Username, Options) ->
case user_exists(Username) of
false ->
- case validate_options(Options) of
- {ok, NewOptions} ->
- riak_core_metadata:put({<<"security">>, <<"users">>},
- Username, NewOptions),
- ok;
- Error ->
- Error
+ case group_exists(Username) of
+ false ->
+ case validate_options(Options) of
+ {ok, NewOptions} ->
+ riak_core_metadata:put({<<"security">>, <<"users">>},
+ Username, NewOptions),
+ ok;
+ Error ->
+ Error
+ end;
+ true ->
+ {error, group_exists_with_same_name}
end;
true ->
{error, user_exists}
@@ -389,13 +394,18 @@ add_user(Username, Options) ->
add_group(Groupname, Options) ->
case group_exists(Groupname) of
false ->
- case validate_groups_option(Options) of
- {ok, NewOptions} ->
- riak_core_metadata:put({<<"security">>, <<"groups">>},
- Groupname, NewOptions),
- ok;
- Error ->
- Error
+ case user_exists(Groupname) of
+ false ->
+ case validate_groups_option(Options) of
+ {ok, NewOptions} ->
+ riak_core_metadata:put({<<"security">>, <<"groups">>},
+ Groupname, NewOptions),
+ ok;
+ Error ->
+ Error
+ end;
+ true ->
+ {error, user_exists_with_same_name}
end;
true ->
{error, group_exists}

0 comments on commit 66879be

Please sign in to comment.