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;
return notImplemented();
}
- @Override
- public Set<String> getUserGroups() {
- return notImplemented();
- }
-
@Override
public boolean isLoggedIn() {
return notImplementedBooleanMethod();
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;
return Collections.emptyList();
}
- @Override
- public Set<String> getUserGroups() {
- return Collections.singleton(DefaultGroups.ANYONE);
- }
-
@Override
public boolean isLoggedIn() {
return false;
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;
return groups.get();
}
- @Override
- public Set<String> getUserGroups() {
- Collection<GroupDto> 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;
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;
return get().getGroups();
}
- @Override
- public Set<String> getUserGroups() {
- return get().getUserGroups();
- }
-
@Override
public boolean isLoggedIn() {
return get().isLoggedIn();
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;
*/
Collection<GroupDto> 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<String> getUserGroups();
-
/**
* Whether the user is logged-in or anonymous.
*/
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;
public abstract class AbstractMockUserSession<T extends AbstractMockUserSession> extends AbstractUserSession {
private final Class<T> clazz;
- private Set<String> userGroups = Sets.newHashSet(DefaultGroups.ANYONE);
private List<String> globalPermissions = Collections.emptyList();
private HashMultimap<String, String> projectKeyByPermission = HashMultimap.create();
private HashMultimap<String, String> projectUuidByPermission = HashMultimap.create();
return clazz.cast(this);
}
- @Override
- public Set<String> 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}
*/
*/
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<AnonymousMockUserSession> {
public Collection<GroupDto> getGroups() {
return Collections.emptyList();
}
-
- @Override
- public Set<String> getUserGroups() {
- return Sets.newHashSet(DefaultGroups.ANYONE);
- }
}
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;
this.groups = asList(groups);
return this;
}
-
- @Override
- public Set<String> getUserGroups() {
- return Stream.concat(Stream.of(DefaultGroups.ANYONE),groups.stream().map(GroupDto::getName))
- .collect(Collectors.toSet());
- }
}
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();
}
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;
return currentUserSession.getGroups();
}
- @Override
- public Set<String> getUserGroups() {
- return currentUserSession.getUserGroups();
- }
-
@Override
public boolean isLoggedIn() {
return currentUserSession.isLoggedIn();