diff options
author | belen-pruvost-sonarsource <belen.pruvost@sonarsource.com> | 2021-12-30 10:33:39 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-12-30 20:03:07 +0000 |
commit | 25e7bb391c9c65dcec037910c72676b9ea12bb94 (patch) | |
tree | ce93651e26d2b54b0097f5aad48eab0cbbc2a58c /server | |
parent | e214060191812769be914d79f4126f801914740c (diff) | |
download | sonarqube-25e7bb391c9c65dcec037910c72676b9ea12bb94.tar.gz sonarqube-25e7bb391c9c65dcec037910c72676b9ea12bb94.zip |
SONAR-15801 - Add accessible field to api/applications/search_projects (#5221)
Diffstat (limited to 'server')
5 files changed, 45 insertions, 0 deletions
diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java index c9902161477..9fec50125fc 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/AbstractUserSession.java @@ -106,6 +106,14 @@ public abstract class AbstractUserSession implements UserSession { } @Override + public final boolean hasProjectPermission(String permission, String projectUuid) { + if (isRoot()) { + return true; + } + return hasProjectUuidPermission(permission, projectUuid); + } + + @Override public final boolean hasChildProjectsPermission(String permission, ComponentDto component) { if (isRoot()) { return true; diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java index 2584b0ac0c2..96096ccefe1 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/ThreadLocalUserSession.java @@ -184,6 +184,11 @@ public class ThreadLocalUserSession implements UserSession { } @Override + public boolean hasProjectPermission(String permission, String projectUuid) { + return get().hasProjectPermission(permission, projectUuid); + } + + @Override public boolean hasChildProjectsPermission(String permission, ComponentDto component) { return get().hasChildProjectsPermission(permission, component); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserSession.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserSession.java index 157042f8f6c..61992db77cc 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserSession.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/user/UserSession.java @@ -195,6 +195,8 @@ public interface UserSession { boolean hasProjectPermission(String permission, ProjectDto project); + boolean hasProjectPermission(String permission, String projectUuid); + boolean hasChildProjectsPermission(String permission, ComponentDto component); boolean hasChildProjectsPermission(String permission, ProjectDto component); diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java index 81abd518045..22dc9cc8745 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java @@ -72,6 +72,31 @@ public class ThreadLocalUserSessionTest { assertThat(threadLocalUserSession.getGroups()).extracting(GroupDto::getUuid).containsOnly(group.getUuid()); assertThat(threadLocalUserSession.hasChildProjectsPermission(USER, new ComponentDto())).isFalse(); assertThat(threadLocalUserSession.hasChildProjectsPermission(USER, new ProjectDto())).isFalse(); + assertThat(threadLocalUserSession.hasProjectPermission(USER, new ProjectDto().getUuid())).isFalse(); + } + + @Test + public void get_session_for_root_user() { + GroupDto group = GroupTesting.newGroupDto(); + MockUserSession expected = new MockUserSession("root") + .setUuid("root-uuid") + .setResetPassword(true) + .setLastSonarlintConnectionDate(1000L) + .setGroups(group); + expected.setRoot(true); + threadLocalUserSession.set(expected); + + UserSession session = threadLocalUserSession.get(); + assertThat(session).isSameAs(expected); + assertThat(threadLocalUserSession.getLastSonarlintConnectionDate()).isEqualTo(1000L); + assertThat(threadLocalUserSession.getLogin()).isEqualTo("root"); + assertThat(threadLocalUserSession.getUuid()).isEqualTo("root-uuid"); + assertThat(threadLocalUserSession.isLoggedIn()).isTrue(); + assertThat(threadLocalUserSession.shouldResetPassword()).isTrue(); + assertThat(threadLocalUserSession.getGroups()).extracting(GroupDto::getUuid).containsOnly(group.getUuid()); + assertThat(threadLocalUserSession.hasChildProjectsPermission(USER, new ComponentDto())).isTrue(); + assertThat(threadLocalUserSession.hasChildProjectsPermission(USER, new ProjectDto())).isTrue(); + assertThat(threadLocalUserSession.hasProjectPermission(USER, new ProjectDto().getUuid())).isTrue(); } @Test diff --git a/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java b/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java index 6077a66fa93..7141fea1111 100644 --- a/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java +++ b/server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java @@ -262,6 +262,11 @@ public class UserSessionRule implements TestRule, UserSession { } @Override + public boolean hasProjectPermission(String permission, String projectUuid) { + return currentUserSession.hasProjectPermission(permission, projectUuid); + } + + @Override public boolean hasChildProjectsPermission(String permission, ComponentDto component) { return currentUserSession.hasChildProjectsPermission(permission, component); } |