summaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authortoby <smorgrav@yahoo-inc.com>2019-11-07 16:35:22 +0100
committertoby <smorgrav@yahoo-inc.com>2019-11-07 16:35:22 +0100
commit5c53251ef2d984d9dc201e4db4fc65adfe77201a (patch)
tree24166715894452c19f7a47a9e5963bb203ee975e /controller-api
parent7b07a0e1ae676c764d404aa13e62cc8bb2877257 (diff)
Add method and use this in already supported restapi
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/stubs/MockUserManagement.java8
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/user/UserManagement.java3
2 files changed, 11 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..145b468688c 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,6 +43,13 @@ public class MockUserManagement implements UserManagement {
}
@Override
+ public void addRoles(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())));
}
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..efe31f6f118 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,6 +21,9 @@ 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 addRoles(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);