diff options
author | Torbjørn Smørgrav <smorgrav@users.noreply.github.com> | 2019-11-08 12:36:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-08 12:36:13 +0100 |
commit | 4006e54d2fec247451d7fee7dc6913096d402031 (patch) | |
tree | 06758e449f419d6b04aa6d8da23d3b92bea72b19 /controller-api | |
parent | 3197465b375861068e78699fb35181b9270a3b22 (diff) | |
parent | 7e94f8ca539eaf2277920e714d8cc551c50d97d3 (diff) |
Merge pull request #11246 from vespa-engine/smorgrav/user_api_add_roles
Smorgrav/user api add roles
Diffstat (limited to 'controller-api')
2 files changed, 21 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java index 03eda33233d..ee7337b524d 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java @@ -6,6 +6,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.user.UserManagement; import com.yahoo.vespa.hosted.controller.api.role.Role; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -42,11 +43,25 @@ public class MockUserManagement implements UserManagement { } @Override + public void addToRoles(UserId user, Collection<Role> roles) { + for (Role role : roles) { + addUsers(role, Collections.singletonList(user)); + } + } + + @Override public void removeUsers(Role role, Collection<UserId> users) { memberships.get(role).removeIf(user -> users.contains(new UserId(user.email()))); } @Override + public void removeFromRoles(UserId user, Collection<Role> roles) { + for (Role role : roles) { + removeUsers(role, Collections.singletonList(user)); + } + } + + @Override public List<User> listUsers(Role role) { return List.copyOf(memberships.get(role)); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java index f56a9f66288..922f0f11244 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java @@ -21,9 +21,15 @@ public interface UserManagement { /** Ensures the given users exist, and are part of the given role, or throws if the role does not exist. */ void addUsers(Role role, Collection<UserId> users); + /** Ensures the given user exist, and are part of the given roles, or throws if the roles does not exist. */ + void addToRoles(UserId user, Collection<Role> roles); + /** Ensures none of the given users are part of the given role, or throws if the role does not exist. */ void removeUsers(Role role, Collection<UserId> users); + /** Ensures the given users are not part of the given role, or throws if the roles does not exist. */ + void removeFromRoles(UserId user, Collection<Role> roles); + /** Returns all users in the given role, or throws if the role does not exist. */ List<User> listUsers(Role role); |