From: Simon Brandhof Date: Tue, 31 Jan 2017 21:33:13 +0000 (+0100) Subject: SONAR-8704 drop unused UserSession#getUserGroups() X-Git-Tag: 6.3-RC1~259 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=289953c8136993551268dc77049da572e332aae0;p=sonarqube.git SONAR-8704 drop unused UserSession#getUserGroups() --- diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/user/CeUserSession.java b/server/sonar-ce/src/main/java/org/sonar/ce/user/CeUserSession.java index 285b787f83d..75da6c074f1 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/user/CeUserSession.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/user/CeUserSession.java @@ -21,7 +21,6 @@ package org.sonar.ce.user; import java.util.Collection; import java.util.List; -import java.util.Set; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.GroupDto; import org.sonar.server.user.UserSession; @@ -56,11 +55,6 @@ public class CeUserSession implements UserSession { return notImplemented(); } - @Override - public Set getUserGroups() { - return notImplemented(); - } - @Override public boolean isLoggedIn() { return notImplementedBooleanMethod(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java b/server/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java index a2aac204a78..935f08e73be 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/DoPrivileged.java @@ -22,8 +22,6 @@ package org.sonar.server.user; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Set; -import org.sonar.api.security.DefaultGroups; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.GroupDto; @@ -89,11 +87,6 @@ public final class DoPrivileged { return Collections.emptyList(); } - @Override - public Set getUserGroups() { - return Collections.singleton(DefaultGroups.ANYONE); - } - @Override public boolean isLoggedIn() { return false; diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java b/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java index bc866fa866f..7364c9698d7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java @@ -30,11 +30,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Stream; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.security.DefaultGroups; -import org.sonar.core.util.stream.Collectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ResourceDao; @@ -109,15 +106,6 @@ public class ServerUserSession extends AbstractUserSession { return groups.get(); } - @Override - public Set getUserGroups() { - Collection groups = getGroups(); - return Stream.concat( - Stream.of(DefaultGroups.ANYONE), - groups.stream().map(GroupDto::getName)) - .collect(Collectors.toSet(groups.size() + 1)); - } - @Override public boolean isLoggedIn() { return userDto != null; diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java b/server/sonar-server/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java index 97761aebe56..32c3f07f8b5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java @@ -21,7 +21,6 @@ package org.sonar.server.user; import java.util.Collection; import java.util.List; -import java.util.Set; import javax.annotation.CheckForNull; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.GroupDto; @@ -77,11 +76,6 @@ public class ThreadLocalUserSession implements UserSession { return get().getGroups(); } - @Override - public Set getUserGroups() { - return get().getUserGroups(); - } - @Override public boolean isLoggedIn() { return get().isLoggedIn(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java b/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java index 9425b43fbf9..32b3ae81e7a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/UserSession.java @@ -21,9 +21,7 @@ package org.sonar.server.user; import java.util.Collection; import java.util.List; -import java.util.Set; import javax.annotation.CheckForNull; -import org.sonar.api.security.DefaultGroups; import org.sonar.db.component.ComponentDto; import org.sonar.db.user.GroupDto; @@ -43,17 +41,6 @@ public interface UserSession { */ Collection getGroups(); - /** - * The groups that the user is member of, always including - * the virtual group named {@link DefaultGroups#ANYONE}. - * - * @deprecated does not support organizations because group names - * are not unique - * @see #getGroups() - */ - @Deprecated - Set getUserGroups(); - /** * Whether the user is logged-in or anonymous. */ diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/AbstractMockUserSession.java b/server/sonar-server/src/test/java/org/sonar/server/tester/AbstractMockUserSession.java index e60f4624d40..27832abccd0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/tester/AbstractMockUserSession.java +++ b/server/sonar-server/src/test/java/org/sonar/server/tester/AbstractMockUserSession.java @@ -20,15 +20,10 @@ package org.sonar.server.tester; import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Set; -import javax.annotation.Nullable; -import org.sonar.api.security.DefaultGroups; import org.sonar.db.component.ComponentDto; import org.sonar.server.user.AbstractUserSession; @@ -37,7 +32,6 @@ import static com.google.common.collect.Maps.newHashMap; public abstract class AbstractMockUserSession extends AbstractUserSession { private final Class clazz; - private Set userGroups = Sets.newHashSet(DefaultGroups.ANYONE); private List globalPermissions = Collections.emptyList(); private HashMultimap projectKeyByPermission = HashMultimap.create(); private HashMultimap projectUuidByPermission = HashMultimap.create(); @@ -55,18 +49,6 @@ public abstract class AbstractMockUserSession return clazz.cast(this); } - @Override - public Set getUserGroups() { - return ImmutableSet.copyOf(this.userGroups); - } - - T setUserGroups(@Nullable String... userGroups) { - if (userGroups != null) { - this.userGroups.addAll(Arrays.asList(userGroups)); - } - return clazz.cast(this); - } - /** * Deprecated, please use {@link #addProjectUuidPermissions} */ diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/AnonymousMockUserSession.java b/server/sonar-server/src/test/java/org/sonar/server/tester/AnonymousMockUserSession.java index 745c18c15d2..418f7877b92 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/tester/AnonymousMockUserSession.java +++ b/server/sonar-server/src/test/java/org/sonar/server/tester/AnonymousMockUserSession.java @@ -19,11 +19,8 @@ */ package org.sonar.server.tester; -import com.google.common.collect.Sets; import java.util.Collection; import java.util.Collections; -import java.util.Set; -import org.sonar.api.security.DefaultGroups; import org.sonar.db.user.GroupDto; public class AnonymousMockUserSession extends AbstractMockUserSession { @@ -61,9 +58,4 @@ public class AnonymousMockUserSession extends AbstractMockUserSession getGroups() { return Collections.emptyList(); } - - @Override - public Set getUserGroups() { - return Sets.newHashSet(DefaultGroups.ANYONE); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSession.java b/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSession.java index cdc79c89ceb..ebf2acd7833 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSession.java +++ b/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSession.java @@ -23,10 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.sonar.api.security.DefaultGroups; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; @@ -104,10 +100,4 @@ public class MockUserSession extends AbstractMockUserSession { this.groups = asList(groups); return this; } - - @Override - public Set getUserGroups() { - return Stream.concat(Stream.of(DefaultGroups.ANYONE),groups.stream().map(GroupDto::getName)) - .collect(Collectors.toSet()); - } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSessionTest.java b/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSessionTest.java index 66d0c4fb50a..96f16ad4dea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSessionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/tester/MockUserSessionTest.java @@ -33,7 +33,6 @@ public class MockUserSessionTest { assertThat(mock.getLogin()).isEqualTo("foo"); assertThat(mock.getGroups()).extracting(GroupDto::getId).containsOnly(group.getId()); - assertThat(mock.getUserGroups()).containsOnly(group.getName(), "Anyone"); assertThat(mock.globalPermissions()).isEmpty(); assertThat(mock.isLoggedIn()).isTrue(); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java b/server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java index f09ad6c98b5..8ee31d506cc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/tester/UserSessionRule.java @@ -22,7 +22,6 @@ package org.sonar.server.tester; import com.google.common.base.Preconditions; import java.util.Collection; import java.util.List; -import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.junit.rules.TestRule; @@ -289,11 +288,6 @@ public class UserSessionRule implements TestRule, UserSession { return currentUserSession.getGroups(); } - @Override - public Set getUserGroups() { - return currentUserSession.getUserGroups(); - } - @Override public boolean isLoggedIn() { return currentUserSession.isLoggedIn();