From: Simon Brandhof Date: Fri, 10 Feb 2017 00:02:48 +0000 (+0100) Subject: SONAR-8761 clean-up AuthorizationDao X-Git-Tag: 6.3-RC1~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4ee759f2116996ae133bc1e2543c4e8a4d6c6320;p=sonarqube.git SONAR-8761 clean-up AuthorizationDao --- diff --git a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java index 3e1968f5b16..4a168a5a826 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationDao.java @@ -19,16 +19,13 @@ */ package org.sonar.db.permission; -import com.google.common.collect.Sets; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Nullable; import org.sonar.db.Dao; import org.sonar.db.DbSession; -import org.sonar.db.MyBatis; import static org.sonar.db.DatabaseUtils.executeLargeInputs; import static org.sonar.db.DatabaseUtils.executeLargeInputsIntoSet; @@ -44,15 +41,9 @@ public class AuthorizationDao implements Dao { private static final String USER_ID_PARAM = "userId"; - private final MyBatis mybatis; - - public AuthorizationDao(MyBatis mybatis) { - this.mybatis = mybatis; - } - /** - * Loads all the permissions granted to logged-in user for the specified organization - */ + * Loads all the permissions granted to logged-in user for the specified organization + */ public Set selectOrganizationPermissions(DbSession dbSession, String organizationUuid, long userId) { return mapper(dbSession).selectOrganizationPermissions(organizationUuid, userId); } @@ -64,20 +55,6 @@ public class AuthorizationDao implements Dao { return mapper(dbSession).selectOrganizationPermissionsOfAnonymous(organizationUuid); } - /** - * Loads all the permissions granted to logged-in user for the specified root component (project) - */ - public Set selectRootComponentPermissions(DbSession dbSession, long rootComponentId, long userId) { - return mapper(dbSession).selectRootComponentPermissions(rootComponentId, userId); - } - - /** - * Loads all the permissions granted to anonymous user for the specified root component (project) - */ - public Set selectRootComponentPermissionsOfAnonymous(DbSession dbSession, long rootComponentId) { - return mapper(dbSession).selectRootComponentPermissionsOfAnonymous(rootComponentId); - } - /** * The number of users who will still have the permission if the group {@code excludedGroupId} * is deleted. The anyone virtual group is not taken into account. @@ -140,16 +117,6 @@ public class AuthorizationDao implements Dao { }); } - public Collection selectAuthorizedRootProjectsKeys(DbSession dbSession, @Nullable Integer userId, String role) { - String sql; - Map params = new HashMap<>(2); - sql = "selectAuthorizedRootProjectsKeys"; - params.put(USER_ID_PARAM, userId); - params.put("role", role); - - return dbSession.selectList(sql, params); - } - public Collection selectAuthorizedRootProjectsUuids(DbSession dbSession, @Nullable Integer userId, String role) { String sql; Map params = new HashMap<>(2); @@ -160,21 +127,6 @@ public class AuthorizationDao implements Dao { return dbSession.selectList(sql, params); } - /** - * @deprecated because it does not support organizations - */ - @Deprecated - public List selectGlobalPermissions(@Nullable String userLogin) { - DbSession session = mybatis.openSession(false); - try { - Map params = new HashMap<>(1); - params.put("userLogin", userLogin); - return session.selectList("selectGlobalPermissions", params); - } finally { - MyBatis.closeQuietly(session); - } - } - /** * Keep only authorized user that have the given permission on a given project. * Please Note that if the permission is 'Anyone' is NOT taking into account by thie method. @@ -185,23 +137,6 @@ public class AuthorizationDao implements Dao { partitionOfIds -> mapper(dbSession).keepAuthorizedUsersForRoleAndProject(role, projectId, partitionOfIds)); } - public boolean isAuthorizedComponentKey(String componentKey, @Nullable Integer userId, String role) { - DbSession session = mybatis.openSession(false); - try { - return keepAuthorizedComponentKeys(session, componentKey, userId, role).size() == 1; - } finally { - MyBatis.closeQuietly(session); - } - } - - private static List keepAuthorizedComponentKeys(DbSession dbSession, String componentKey, @Nullable Integer userId, String role) { - if (userId == null) { - return mapper(dbSession).keepAuthorizedComponentKeysForAnonymous(role, Sets.newHashSet(componentKey)); - } else { - return mapper(dbSession).keepAuthorizedComponentKeysForUser(userId, role, Sets.newHashSet(componentKey)); - } - } - private static AuthorizationMapper mapper(DbSession dbSession) { return dbSession.getMapper(AuthorizationMapper.class); } diff --git a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java index 8197b297057..f13bbd37f85 100644 --- a/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/permission/AuthorizationMapper.java @@ -33,10 +33,6 @@ public interface AuthorizationMapper { Set selectOrganizationPermissionsOfAnonymous(@Param("organizationUuid") String organizationUuid); - Set selectRootComponentPermissions(@Param("rootComponentId") long rootComponentId, @Param("userId") long userId); - - Set selectRootComponentPermissionsOfAnonymous(@Param("rootComponentId") long rootComponentId); - int countUsersWithGlobalPermissionExcludingGroup(@Param("organizationUuid") String organizationUuid, @Param("permission") String permission, @Param("excludedGroupId") long excludedGroupId); @@ -55,11 +51,6 @@ public interface AuthorizationMapper { Set keepAuthorizedProjectIdsForUser(@Param("userId") long userId, @Param("role") String role, @Param("componentIds") Collection componentIds); - List keepAuthorizedComponentKeysForAnonymous(@Param("role") String role, @Param("componentKeys") Collection componentKeys); - - List keepAuthorizedComponentKeysForUser(@Param("userId") Integer userId, @Param("role") String role, @Param("componentKeys") Collection componentKeys); - List keepAuthorizedUsersForRoleAndProject(@Param("role") String role, @Param("componentId") long componentId, @Param("userIds") List userIds); - } diff --git a/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml index bf9fdcb54b8..b3f13d570d4 100644 --- a/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml @@ -223,39 +223,6 @@ - - - - - - SELECT p.kee as root_project_kee - FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL - where - gr.role=#{role,jdbcType=VARCHAR} - and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where - gu.user_id=#{userId,jdbcType=BIGINT})) - UNION - SELECT p.kee as root_project_kee - FROM user_roles ur - INNER JOIN projects p on p.id = ur.resource_id AND p.module_uuid IS NULL - where - ur.role=#{role,jdbcType=VARCHAR} - and ur.user_id = #{userId,jdbcType=BIGINT} - - - SELECT p.kee as root_project_kee - FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL - where - gr.role=#{role,jdbcType=VARCHAR} - and gr.group_id is null - - - - - - - - - SELECT p.id as root_project_id - FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL - where - gr.role=#{role,jdbcType=VARCHAR} - and (gr.group_id is null or gr.group_id in (select gu.group_id from groups_users gu where - gu.user_id=#{userId,jdbcType=BIGINT})) - UNION - SELECT p.id as root_project_id - FROM user_roles ur - INNER JOIN projects p on p.id = ur.resource_id AND p.module_uuid IS NULL - where - ur.role=#{role,jdbcType=VARCHAR} and - ur.user_id = #{userId,jdbcType=BIGINT} - - - SELECT p.id as root_project_id - FROM group_roles gr - INNER JOIN projects p on p.id = gr.resource_id AND p.module_uuid IS NULL - where - gr.role=#{role,jdbcType=VARCHAR} - and gr.group_id is null - - - - - - - - - -