From: Jean-Baptiste Vilain Date: Fri, 12 Jul 2013 16:01:48 +0000 (+0200) Subject: SONAR-4453 Added a logical key in the permission_templates table and rearranged permi... X-Git-Tag: 3.7~133 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2dc9ca437d7bade2a56cd2e0ec7559aee6c58ecb;p=sonarqube.git SONAR-4453 Added a logical key in the permission_templates table and rearranged permission-related classes --- diff --git a/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java b/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java new file mode 100644 index 00000000000..f6fd58faa39 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java @@ -0,0 +1,31 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.date; + +import java.util.Date; + +/** + * @since 3.7 + */ +public interface DateProvider { + + Date now(); +} diff --git a/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java b/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java new file mode 100644 index 00000000000..eb716b2d57d --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java @@ -0,0 +1,31 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.date; + +import java.util.Date; + +public class DefaultDateProvider implements DateProvider { + + @Override + public Date now() { + return new Date(); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/permission/Permission.java b/sonar-core/src/main/java/org/sonar/core/permission/Permission.java new file mode 100644 index 00000000000..bf8fd3d2e06 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/permission/Permission.java @@ -0,0 +1,67 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * + * Holds the constants representing the various global permissions that can be assigned to users & groups + * + * @since 3.7 + */ +public class Permission { + + public static final Permission SYSTEM_ADMIN = new Permission("admin"); + public static final Permission QUALITY_PROFILE_ADMIN = new Permission("profileadmin"); + public static final Permission DASHBOARD_SHARING = new Permission("shareDashboard"); + public static final Permission SCAN_EXECUTION = new Permission("scan"); + public static final Permission DRY_RUN_EXECUTION = new Permission("dryRunScan"); + + private final String key; + // Use linked hash map to preserve order + private static Map allGlobal = new LinkedHashMap(); + + static { + allGlobal.put(SYSTEM_ADMIN.key, SYSTEM_ADMIN); + allGlobal.put(QUALITY_PROFILE_ADMIN.key, QUALITY_PROFILE_ADMIN); + allGlobal.put(DASHBOARD_SHARING.key, DASHBOARD_SHARING); + allGlobal.put(SCAN_EXECUTION.key, SCAN_EXECUTION); + allGlobal.put(DRY_RUN_EXECUTION.key, DRY_RUN_EXECUTION); + } + + private Permission(String key) { + this.key = key; + } + + public String key() { + return key; + } + + public static Map allGlobal() { + return allGlobal; + } + + public static boolean isValid(String permission) { + return allGlobal.containsKey(permission); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionDao.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionDao.java new file mode 100644 index 00000000000..43555999195 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionDao.java @@ -0,0 +1,224 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +import org.apache.commons.lang.time.DateFormatUtils; +import org.apache.ibatis.session.SqlSession; +import org.sonar.api.ServerComponent; +import org.sonar.api.task.TaskComponent; +import org.sonar.core.date.DateProvider; +import org.sonar.core.date.DefaultDateProvider; +import org.sonar.core.persistence.MyBatis; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import java.text.Normalizer; +import java.util.Date; +import java.util.List; + +public class PermissionDao implements TaskComponent, ServerComponent { + + private final MyBatis myBatis; + private final DateProvider dateProvider; + + public PermissionDao(MyBatis myBatis, DateProvider dateProvider) { + this.myBatis = myBatis; + this.dateProvider = dateProvider; + } + + public PermissionDao(MyBatis myBatis) { + this(myBatis, new DefaultDateProvider()); + } + + @CheckForNull + public PermissionTemplateDto selectTemplateByName(String templateName) { + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + return mapper.selectByName(templateName); + } finally { + MyBatis.closeQuietly(session); + } + } + + @CheckForNull + public PermissionTemplateDto selectTemplateById(Long templateId) { + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + return mapper.selectById(templateId); + } finally { + MyBatis.closeQuietly(session); + } + } + + @CheckForNull + public PermissionTemplateDto selectPermissionTemplate(String templateName) { + PermissionTemplateDto permissionTemplate = null; + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + permissionTemplate = mapper.selectByName(templateName); + PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName); + if(templateUsersPermissions != null) { + permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions()); + } + PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName); + if(templateGroupsPermissions != null) { + permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions()); + } + } finally { + MyBatis.closeQuietly(session); + } + return permissionTemplate; + } + + @CheckForNull + public List selectAllPermissionTemplates() { + SqlSession session = myBatis.openSession(); + try { + return session.selectList("selectAllPermissionTemplates"); + } finally { + MyBatis.closeQuietly(session); + } + } + + public PermissionTemplateDto createPermissionTemplate(String templateName, @Nullable String description) { + Date creationDate = now(); + PermissionTemplateDto permissionTemplate = new PermissionTemplateDto() + .setName(templateName) + .setKee(generateTemplateKee(templateName, creationDate)) + .setDescription(description) + .setCreatedAt(creationDate) + .setUpdatedAt(creationDate); + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.insert(permissionTemplate); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + return permissionTemplate; + } + + public void deletePermissionTemplate(Long templateId) { + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.deleteUsersPermissions(templateId); + mapper.deleteGroupsPermissions(templateId); + mapper.delete(templateId); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description) { + PermissionTemplateDto permissionTemplate = new PermissionTemplateDto() + .setId(templateId) + .setName(templateName) + .setDescription(description) + .setUpdatedAt(now()); + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.update(permissionTemplate); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void addUserPermission(Long templateId, Long userId, String permission) { + PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() + .setTemplateId(templateId) + .setUserId(userId) + .setPermission(permission) + .setCreatedAt(now()) + .setUpdatedAt(now()); + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.insertUserPermission(permissionTemplateUser); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void removeUserPermission(Long templateId, Long userId, String permission) { + PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() + .setTemplateId(templateId) + .setPermission(permission) + .setUserId(userId); + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.deleteUserPermission(permissionTemplateUser); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void addGroupPermission(Long templateId, @Nullable Long groupId, String permission) { + PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() + .setTemplateId(templateId) + .setPermission(permission) + .setGroupId(groupId) + .setCreatedAt(now()) + .setUpdatedAt(now()); + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.insertGroupPermission(permissionTemplateGroup); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void removeGroupPermission(Long templateId, @Nullable Long groupId, String permission) { + PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() + .setTemplateId(templateId) + .setPermission(permission) + .setGroupId(groupId); + SqlSession session = myBatis.openSession(); + try { + PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); + mapper.deleteGroupPermission(permissionTemplateGroup); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + private String generateTemplateKee(String name, Date timeStamp) { + String normalizedName = Normalizer.normalize(name, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "").replace(" ", "_"); + return normalizedName.toLowerCase() + "_" + DateFormatUtils.format(timeStamp, "yyyyMMdd_HHmmss"); + } + + private Date now() { + return dateProvider.now(); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java new file mode 100644 index 00000000000..6eead5a1cc8 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDto.java @@ -0,0 +1,113 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import java.util.Date; +import java.util.List; + +public class PermissionTemplateDto { + + private Long id; + private String name; + private String kee; + private String description; + private List usersPermissions; + private List groupsPermissions; + private Date createdAt; + private Date updatedAt; + + public Long getId() { + return id; + } + + public PermissionTemplateDto setId(Long id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public PermissionTemplateDto setName(String name) { + this.name = name; + return this; + } + + public String getKee() { + return kee; + } + + public PermissionTemplateDto setKee(String kee) { + this.kee = kee; + return this; + } + + @CheckForNull + public String getDescription() { + return description; + } + + public PermissionTemplateDto setDescription(@Nullable String description) { + this.description = description; + return this; + } + + @CheckForNull + public List getUsersPermissions() { + return usersPermissions; + } + + public PermissionTemplateDto setUsersPermissions(@Nullable List usersPermissions) { + this.usersPermissions = usersPermissions; + return this; + } + + @CheckForNull + public List getGroupsPermissions() { + return groupsPermissions; + } + + public PermissionTemplateDto setGroupsByPermission(@Nullable List groupsPermissions) { + this.groupsPermissions = groupsPermissions; + return this; + } + + public Date getCreatedAt() { + return createdAt; + } + + public PermissionTemplateDto setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public PermissionTemplateDto setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + return this; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateGroupDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateGroupDto.java new file mode 100644 index 00000000000..a2818d13ddf --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateGroupDto.java @@ -0,0 +1,98 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +import javax.annotation.Nullable; +import java.util.Date; + +public class PermissionTemplateGroupDto { + + private Long id; + private Long templateId; + private Long groupId; + private String permission; + private String groupName; + private Date createdAt; + private Date updatedAt; + + public Long getId() { + return id; + } + + public PermissionTemplateGroupDto setId(Long id) { + this.id = id; + return this; + } + + public Long getTemplateId() { + return templateId; + } + + public PermissionTemplateGroupDto setTemplateId(Long templateId) { + this.templateId = templateId; + return this; + } + + public Long getGroupId() { + return groupId; + } + + public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) { + this.groupId = groupId; + return this; + } + + public String getPermission() { + return permission; + } + + public PermissionTemplateGroupDto setPermission(String permission) { + this.permission = permission; + return this; + } + + public String getGroupName() { + return groupName; + } + + public PermissionTemplateGroupDto setGroupName(String groupName) { + this.groupName = groupName; + return this; + } + + public Date getCreatedAt() { + return createdAt; + } + + public PermissionTemplateGroupDto setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public PermissionTemplateGroupDto setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + return this; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java new file mode 100644 index 00000000000..f14df167170 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateMapper.java @@ -0,0 +1,53 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +/** + * @since 3.7 + */ +public interface PermissionTemplateMapper { + + void insert(PermissionTemplateDto permissionTemplate); + + void update(PermissionTemplateDto permissionTemplate); + + void delete(Long templateId); + + void deleteUsersPermissions(Long templateId); + + void deleteGroupsPermissions(Long templateId); + + PermissionTemplateDto selectByName(String templateName); + + PermissionTemplateDto selectById(Long templateId); + + PermissionTemplateDto selectTemplateUsersPermissions(String templateName); + + PermissionTemplateDto selectTemplateGroupsPermissions(String templateName); + + void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser); + + void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser); + + void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); + + void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); +} diff --git a/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateUserDto.java b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateUserDto.java new file mode 100644 index 00000000000..62014458d2e --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateUserDto.java @@ -0,0 +1,107 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +import java.util.Date; + +public class PermissionTemplateUserDto { + + private Long id; + private Long templateId; + private Long userId; + private String permission; + private String userName; + private String userLogin; + private Date createdAt; + private Date updatedAt; + + public Long getId() { + return id; + } + + public PermissionTemplateUserDto setId(Long id) { + this.id = id; + return this; + } + + public Long getTemplateId() { + return templateId; + } + + public PermissionTemplateUserDto setTemplateId(Long templateId) { + this.templateId = templateId; + return this; + } + + public Long getUserId() { + return userId; + } + + public PermissionTemplateUserDto setUserId(Long userId) { + this.userId = userId; + return this; + } + + public String getUserName() { + return userName; + } + + public PermissionTemplateUserDto setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getUserLogin() { + return userLogin; + } + + public PermissionTemplateUserDto setUserLogin(String userLogin) { + this.userLogin = userLogin; + return this; + } + + public String getPermission() { + return permission; + } + + public PermissionTemplateUserDto setPermission(String permission) { + this.permission = permission; + return this; + } + + public Date getCreatedAt() { + return createdAt; + } + + public PermissionTemplateUserDto setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public PermissionTemplateUserDto setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + return this; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java index 1798e89e920..3027aada8fa 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java @@ -26,6 +26,7 @@ import org.sonar.core.duplication.DuplicationDao; import org.sonar.core.graph.jdbc.GraphDao; import org.sonar.core.issue.db.*; import org.sonar.core.measure.MeasureFilterDao; +import org.sonar.core.permission.PermissionDao; import org.sonar.core.properties.PropertiesDao; import org.sonar.core.purge.PurgeDao; import org.sonar.core.resource.ResourceDao; @@ -34,7 +35,10 @@ import org.sonar.core.resource.ResourceKeyUpdaterDao; import org.sonar.core.rule.RuleDao; import org.sonar.core.source.jdbc.SnapshotDataDao; import org.sonar.core.template.LoadedTemplateDao; -import org.sonar.core.user.*; +import org.sonar.core.user.AuthorDao; +import org.sonar.core.user.AuthorizationDao; +import org.sonar.core.user.RoleDao; +import org.sonar.core.user.UserDao; import java.util.List; diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index e5e4c015a9c..19a9ecbbf57 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -47,6 +47,10 @@ import org.sonar.core.graph.jdbc.GraphDtoMapper; import org.sonar.core.issue.db.*; import org.sonar.core.measure.MeasureFilterDto; import org.sonar.core.measure.MeasureFilterMapper; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.permission.PermissionTemplateGroupDto; +import org.sonar.core.permission.PermissionTemplateMapper; +import org.sonar.core.permission.PermissionTemplateUserDto; import org.sonar.core.properties.PropertiesMapper; import org.sonar.core.properties.PropertyDto; import org.sonar.core.purge.PurgeMapper; diff --git a/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java b/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java index eeec2bbebef..d5dcbc4fe03 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/DefaultResourcePermissions.java @@ -27,10 +27,10 @@ import org.sonar.api.security.DefaultGroups; import org.sonar.api.security.ResourcePermissions; import org.sonar.api.web.UserRole; import org.sonar.core.permission.ComponentPermissionFacade; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.permission.PermissionTemplateGroupDto; +import org.sonar.core.permission.PermissionTemplateUserDto; import org.sonar.core.persistence.MyBatis; -import org.sonar.core.user.PermissionTemplateDto; -import org.sonar.core.user.PermissionTemplateGroupDto; -import org.sonar.core.user.PermissionTemplateUserDto; import java.util.ArrayList; import java.util.List; diff --git a/sonar-core/src/main/java/org/sonar/core/user/Permission.java b/sonar-core/src/main/java/org/sonar/core/user/Permission.java deleted file mode 100644 index 98bb97723a8..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/user/Permission.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * - * Holds the constants representing the various global permissions that can be assigned to users & groups - * - * @since 3.7 - */ -public class Permission { - - public static final Permission SYSTEM_ADMIN = new Permission("admin"); - public static final Permission QUALITY_PROFILE_ADMIN = new Permission("profileadmin"); - public static final Permission DASHBOARD_SHARING = new Permission("shareDashboard"); - public static final Permission SCAN_EXECUTION = new Permission("scan"); - public static final Permission DRY_RUN_EXECUTION = new Permission("dryRunScan"); - - private final String key; - // Use linked hash map to preserve order - private static Map allGlobal = new LinkedHashMap(); - - static { - allGlobal.put(SYSTEM_ADMIN.key, SYSTEM_ADMIN); - allGlobal.put(QUALITY_PROFILE_ADMIN.key, QUALITY_PROFILE_ADMIN); - allGlobal.put(DASHBOARD_SHARING.key, DASHBOARD_SHARING); - allGlobal.put(SCAN_EXECUTION.key, SCAN_EXECUTION); - allGlobal.put(DRY_RUN_EXECUTION.key, DRY_RUN_EXECUTION); - } - - private Permission(String key) { - this.key = key; - } - - public String key() { - return key; - } - - public static Map allGlobal() { - return allGlobal; - } - - public static boolean isValid(String permission) { - return allGlobal.containsKey(permission); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java deleted file mode 100644 index bad927a8e50..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionDao.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -import org.apache.ibatis.session.SqlSession; -import org.sonar.api.ServerComponent; -import org.sonar.api.task.TaskComponent; -import org.sonar.core.persistence.MyBatis; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Date; -import java.util.List; - -public class PermissionDao implements TaskComponent, ServerComponent { - - private final MyBatis myBatis; - - public PermissionDao(MyBatis myBatis) { - this.myBatis = myBatis; - } - - @CheckForNull - public PermissionTemplateDto selectTemplateByName(String templateName) { - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - return mapper.selectByName(templateName); - } finally { - MyBatis.closeQuietly(session); - } - } - - @CheckForNull - public PermissionTemplateDto selectTemplateById(Long templateId) { - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - return mapper.selectById(templateId); - } finally { - MyBatis.closeQuietly(session); - } - } - - @CheckForNull - public PermissionTemplateDto selectPermissionTemplate(String templateName) { - PermissionTemplateDto permissionTemplate = null; - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - permissionTemplate = mapper.selectByName(templateName); - PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateName); - if(templateUsersPermissions != null) { - permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions()); - } - PermissionTemplateDto templateGroupsPermissions = mapper.selectTemplateGroupsPermissions(templateName); - if(templateGroupsPermissions != null) { - permissionTemplate.setGroupsByPermission(templateGroupsPermissions.getGroupsPermissions()); - } - } finally { - MyBatis.closeQuietly(session); - } - return permissionTemplate; - } - - @CheckForNull - public List selectAllPermissionTemplates() { - SqlSession session = myBatis.openSession(); - try { - return session.selectList("selectAllPermissionTemplates"); - } finally { - MyBatis.closeQuietly(session); - } - } - - public PermissionTemplateDto createPermissionTemplate(String templateName, @Nullable String description) { - PermissionTemplateDto permissionTemplate = new PermissionTemplateDto() - .setName(templateName) - .setDescription(description) - .setCreatedAt(now()) - .setUpdatedAt(now()); - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.insert(permissionTemplate); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - return permissionTemplate; - } - - public void deletePermissionTemplate(Long templateId) { - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.deleteUsersPermissions(templateId); - mapper.deleteGroupsPermissions(templateId); - mapper.delete(templateId); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - public void updatePermissionTemplate(Long templateId, String templateName, @Nullable String description) { - PermissionTemplateDto permissionTemplate = new PermissionTemplateDto() - .setId(templateId) - .setName(templateName) - .setDescription(description) - .setUpdatedAt(now()); - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.update(permissionTemplate); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - public void addUserPermission(Long templateId, Long userId, String permission) { - PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() - .setTemplateId(templateId) - .setUserId(userId) - .setPermission(permission) - .setCreatedAt(now()) - .setUpdatedAt(now()); - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.insertUserPermission(permissionTemplateUser); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - public void removeUserPermission(Long templateId, Long userId, String permission) { - PermissionTemplateUserDto permissionTemplateUser = new PermissionTemplateUserDto() - .setTemplateId(templateId) - .setPermission(permission) - .setUserId(userId); - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.deleteUserPermission(permissionTemplateUser); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - public void addGroupPermission(Long templateId, @Nullable Long groupId, String permission) { - PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() - .setTemplateId(templateId) - .setPermission(permission) - .setGroupId(groupId) - .setCreatedAt(now()) - .setUpdatedAt(now()); - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.insertGroupPermission(permissionTemplateGroup); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - public void removeGroupPermission(Long templateId, @Nullable Long groupId, String permission) { - PermissionTemplateGroupDto permissionTemplateGroup = new PermissionTemplateGroupDto() - .setTemplateId(templateId) - .setPermission(permission) - .setGroupId(groupId); - SqlSession session = myBatis.openSession(); - try { - PermissionTemplateMapper mapper = session.getMapper(PermissionTemplateMapper.class); - mapper.deleteGroupPermission(permissionTemplateGroup); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } - - private Date now() { - return new Date(); - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateDto.java deleted file mode 100644 index 93db1524086..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateDto.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; -import java.util.Date; -import java.util.List; - -public class PermissionTemplateDto { - - private Long id; - private String name; - private String description; - private List usersPermissions; - private List groupsPermissions; - private Date createdAt; - private Date updatedAt; - - public Long getId() { - return id; - } - - public PermissionTemplateDto setId(Long id) { - this.id = id; - return this; - } - - public String getName() { - return name; - } - - public PermissionTemplateDto setName(String name) { - this.name = name; - return this; - } - - @CheckForNull - public String getDescription() { - return description; - } - - public PermissionTemplateDto setDescription(@Nullable String description) { - this.description = description; - return this; - } - - @CheckForNull - public List getUsersPermissions() { - return usersPermissions; - } - - public PermissionTemplateDto setUsersPermissions(@Nullable List usersPermissions) { - this.usersPermissions = usersPermissions; - return this; - } - - @CheckForNull - public List getGroupsPermissions() { - return groupsPermissions; - } - - public PermissionTemplateDto setGroupsByPermission(@Nullable List groupsPermissions) { - this.groupsPermissions = groupsPermissions; - return this; - } - - public Date getCreatedAt() { - return createdAt; - } - - public PermissionTemplateDto setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - return this; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public PermissionTemplateDto setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - return this; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateGroupDto.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateGroupDto.java deleted file mode 100644 index 157c6f78582..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateGroupDto.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -import javax.annotation.Nullable; -import java.util.Date; - -public class PermissionTemplateGroupDto { - - private Long id; - private Long templateId; - private Long groupId; - private String permission; - private String groupName; - private Date createdAt; - private Date updatedAt; - - public Long getId() { - return id; - } - - public PermissionTemplateGroupDto setId(Long id) { - this.id = id; - return this; - } - - public Long getTemplateId() { - return templateId; - } - - public PermissionTemplateGroupDto setTemplateId(Long templateId) { - this.templateId = templateId; - return this; - } - - public Long getGroupId() { - return groupId; - } - - public PermissionTemplateGroupDto setGroupId(@Nullable Long groupId) { - this.groupId = groupId; - return this; - } - - public String getPermission() { - return permission; - } - - public PermissionTemplateGroupDto setPermission(String permission) { - this.permission = permission; - return this; - } - - public String getGroupName() { - return groupName; - } - - public PermissionTemplateGroupDto setGroupName(String groupName) { - this.groupName = groupName; - return this; - } - - public Date getCreatedAt() { - return createdAt; - } - - public PermissionTemplateGroupDto setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - return this; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public PermissionTemplateGroupDto setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - return this; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java deleted file mode 100644 index 8f00c507968..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateMapper.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -/** - * @since 3.7 - */ -public interface PermissionTemplateMapper { - - void insert(PermissionTemplateDto permissionTemplate); - - void update(PermissionTemplateDto permissionTemplate); - - void delete(Long templateId); - - void deleteUsersPermissions(Long templateId); - - void deleteGroupsPermissions(Long templateId); - - PermissionTemplateDto selectByName(String templateName); - - PermissionTemplateDto selectById(Long templateId); - - PermissionTemplateDto selectTemplateUsersPermissions(String templateName); - - PermissionTemplateDto selectTemplateGroupsPermissions(String templateName); - - void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser); - - void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser); - - void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); - - void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup); -} diff --git a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateUserDto.java b/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateUserDto.java deleted file mode 100644 index b0fa21a952b..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/user/PermissionTemplateUserDto.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -import java.util.Date; - -public class PermissionTemplateUserDto { - - private Long id; - private Long templateId; - private Long userId; - private String permission; - private String userName; - private String userLogin; - private Date createdAt; - private Date updatedAt; - - public Long getId() { - return id; - } - - public PermissionTemplateUserDto setId(Long id) { - this.id = id; - return this; - } - - public Long getTemplateId() { - return templateId; - } - - public PermissionTemplateUserDto setTemplateId(Long templateId) { - this.templateId = templateId; - return this; - } - - public Long getUserId() { - return userId; - } - - public PermissionTemplateUserDto setUserId(Long userId) { - this.userId = userId; - return this; - } - - public String getUserName() { - return userName; - } - - public PermissionTemplateUserDto setUserName(String userName) { - this.userName = userName; - return this; - } - - public String getUserLogin() { - return userLogin; - } - - public PermissionTemplateUserDto setUserLogin(String userLogin) { - this.userLogin = userLogin; - return this; - } - - public String getPermission() { - return permission; - } - - public PermissionTemplateUserDto setPermission(String permission) { - this.permission = permission; - return this; - } - - public Date getCreatedAt() { - return createdAt; - } - - public PermissionTemplateUserDto setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - return this; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public PermissionTemplateUserDto setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - return this; - } -} diff --git a/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml new file mode 100644 index 00000000000..525f2c8ee74 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/permission/PermissionTemplateMapper.xml @@ -0,0 +1,136 @@ + + + + + + + INSERT INTO permission_templates (name, kee, description, created_at, updated_at) + VALUES (#{name}, #{kee}, #{description}, #{createdAt}, #{updatedAt}) + + + + UPDATE permission_templates + SET name = #{name}, description = #{description}, updated_at = #{updatedAt} + WHERE id = #{id} + + + + DELETE FROM permission_templates + WHERE id = #{templateId} + + + + DELETE FROM perm_templates_users + WHERE template_id = #{templateId} + + + + DELETE FROM perm_templates_groups + WHERE template_id = #{templateId} + + + + INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at) + VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt}) + + + + DELETE FROM perm_templates_users + WHERE template_id = #{templateId} + AND user_id = #{userId} + AND permission_reference = #{permission} + + + + INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at) + VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt}) + + + + DELETE FROM perm_templates_groups + WHERE template_id = #{templateId} + AND permission_reference = #{permission} + AND + + + group_id = #{groupId} + + + group_id IS NULL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index e55347bdf3b..92f82950400 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -15,7 +15,7 @@ INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 1); INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 2); -- Default permissions - Replaces the previous role-based properties such as 'sonar.role.admin.TRK.defaultGroups' (see migration 418) -INSERT INTO PERMISSION_TEMPLATES(ID, name, description) VALUES (1, 'Default template', 'This permission template will be used as default when no other permission configuration is available'); +INSERT INTO PERMISSION_TEMPLATES(ID, name, kee, description) VALUES (1, 'Default template', 'default_template', 'This permission template will be used as default when no other permission configuration is available'); ALTER TABLE PERMISSION_TEMPLATES ALTER COLUMN ID RESTART WITH 2; INSERT INTO PERM_TEMPLATES_GROUPS(ID, template_id, group_id, permission_reference) VALUES (1, 1, 1, 'admin'); diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 2624837ac89..b450b85b834 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -535,6 +535,7 @@ CREATE TABLE "SNAPSHOT_DATA" ( CREATE TABLE "PERMISSION_TEMPLATES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(100) NOT NULL, + "KEE" VARCHAR(100) NOT NULL, "DESCRIPTION" VARCHAR(4000), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP diff --git a/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml b/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml deleted file mode 100644 index 4e9dc2d47f0..00000000000 --- a/sonar-core/src/main/resources/org/sonar/core/user/PermissionTemplateMapper.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - INSERT INTO permission_templates (name, description, created_at, updated_at) - VALUES (#{name}, #{description}, #{createdAt}, #{updatedAt}) - - - - UPDATE permission_templates - SET name = #{name}, description = #{description}, updated_at = #{updatedAt} - WHERE id = #{id} - - - - DELETE FROM permission_templates - WHERE id = #{templateId} - - - - DELETE FROM perm_templates_users - WHERE template_id = #{templateId} - - - - DELETE FROM perm_templates_groups - WHERE template_id = #{templateId} - - - - INSERT INTO perm_templates_users (template_id, user_id, permission_reference, created_at, updated_at) - VALUES (#{templateId}, #{userId}, #{permission}, #{createdAt}, #{updatedAt}) - - - - DELETE FROM perm_templates_users - WHERE template_id = #{templateId} - AND user_id = #{userId} - AND permission_reference = #{permission} - - - - INSERT INTO perm_templates_groups (template_id, group_id, permission_reference, created_at, updated_at) - VALUES (#{templateId}, #{groupId}, #{permission}, #{createdAt}, #{updatedAt}) - - - - DELETE FROM perm_templates_groups - WHERE template_id = #{templateId} - AND permission_reference = #{permission} - AND - - - group_id = #{groupId} - - - group_id IS NULL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sonar-core/src/test/java/org/sonar/core/permission/ComponentPermissionFacadeTest.java b/sonar-core/src/test/java/org/sonar/core/permission/ComponentPermissionFacadeTest.java index 6760a01ee15..7259c8b7ff2 100644 --- a/sonar-core/src/test/java/org/sonar/core/permission/ComponentPermissionFacadeTest.java +++ b/sonar-core/src/test/java/org/sonar/core/permission/ComponentPermissionFacadeTest.java @@ -23,7 +23,6 @@ package org.sonar.core.permission; import org.junit.Before; import org.junit.Test; import org.sonar.core.persistence.AbstractDaoTestCase; -import org.sonar.core.user.PermissionDao; import org.sonar.core.user.RoleDao; import org.sonar.core.user.UserDao; diff --git a/sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java b/sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java new file mode 100644 index 00000000000..9cf31e25f27 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/permission/PermissionDaoTest.java @@ -0,0 +1,214 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.core.permission; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.utils.DateUtils; +import org.sonar.core.date.DateProvider; +import org.sonar.core.persistence.AbstractDaoTestCase; + +import java.util.Date; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.stub; + +public class PermissionDaoTest extends AbstractDaoTestCase { + + private final Date now = DateUtils.parseDateTime("2013-01-02T03:04:05+0100"); + + private PermissionDao permissionDao; + private DateProvider dateProvider; + + @Before + public void setUpDao() { + dateProvider = mock(DateProvider.class); + stub(dateProvider.now()).toReturn(now); + permissionDao = new PermissionDao(getMyBatis(), dateProvider); + } + + @Test + public void should_create_permission_template() throws Exception { + setupData("createPermissionTemplate"); + PermissionTemplateDto permissionTemplate = permissionDao.createPermissionTemplate("my template", "my description"); + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getId()).isEqualTo(1L); + checkTable("createPermissionTemplate", "permission_templates", "id", "name", "kee", "description"); + } + + @Test + public void should_normalize_kee_on_template_creation() throws Exception { + setupData("createNonAsciiPermissionTemplate"); + PermissionTemplateDto permissionTemplate = permissionDao.createPermissionTemplate("Môü Gnô Gnèçàß", "my description"); + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getId()).isEqualTo(1L); + checkTable("createNonAsciiPermissionTemplate", "permission_templates", "id", "name", "kee", "description"); + } + + @Test + public void should_select_permission_template() throws Exception { + setupData("selectPermissionTemplate"); + PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template"); + + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getName()).isEqualTo("my template"); + assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); + assertThat(permissionTemplate.getUsersPermissions()).hasSize(3); + assertThat(permissionTemplate.getUsersPermissions()).onProperty("userId").containsOnly(1L, 2L, 1L); + assertThat(permissionTemplate.getUsersPermissions()).onProperty("userLogin").containsOnly("login1", "login2", "login2"); + assertThat(permissionTemplate.getUsersPermissions()).onProperty("userName").containsOnly("user1", "user2", "user2"); + assertThat(permissionTemplate.getUsersPermissions()).onProperty("permission").containsOnly("user_permission1", "user_permission1", "user_permission2"); + assertThat(permissionTemplate.getGroupsPermissions()).hasSize(3); + assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupId").containsOnly(1L, 2L, null); + assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupName").containsOnly("group1", "group2", null); + assertThat(permissionTemplate.getGroupsPermissions()).onProperty("permission").containsOnly("group_permission1", "group_permission1", "group_permission2"); + } + + @Test + public void should_select_empty_permission_template() throws Exception { + setupData("selectEmptyPermissionTemplate"); + PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template"); + + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getName()).isEqualTo("my template"); + assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); + assertThat(permissionTemplate.getUsersPermissions()).isNull(); + assertThat(permissionTemplate.getGroupsPermissions()).isNull(); + } + + @Test + public void should_select_permission_template_by_name() throws Exception { + setupData("selectPermissionTemplate"); + + PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByName("my template"); + + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getId()).isEqualTo(1L); + assertThat(permissionTemplate.getName()).isEqualTo("my template"); + assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); + } + + @Test + public void should_select_permission_template_by_id() throws Exception { + setupData("selectPermissionTemplate"); + + PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateById(1L); + + assertThat(permissionTemplate).isNotNull(); + assertThat(permissionTemplate.getId()).isEqualTo(1L); + assertThat(permissionTemplate.getName()).isEqualTo("my template"); + assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); + } + + @Test + public void should_select_all_permission_templates() throws Exception { + setupData("selectAllPermissionTemplates"); + + List permissionTemplates = permissionDao.selectAllPermissionTemplates(); + + assertThat(permissionTemplates).hasSize(3); + assertThat(permissionTemplates).onProperty("id").containsOnly(1L, 2L, 3L); + assertThat(permissionTemplates).onProperty("name").containsOnly("template1", "template2", "template3"); + assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3"); + } + + @Test + public void should_update_permission_template() throws Exception { + setupData("updatePermissionTemplate"); + + permissionDao.updatePermissionTemplate(1L, "new_name", "new_description"); + + checkTable("updatePermissionTemplate", "permission_templates", "id", "name", "kee", "description"); + } + + @Test + public void should_delete_permission_template() throws Exception { + setupData("deletePermissionTemplate"); + + permissionDao.deletePermissionTemplate(1L); + + checkTable("deletePermissionTemplate", "permission_templates", "id", "name", "description"); + checkTable("deletePermissionTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("deletePermissionTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } + + @Test + public void should_add_user_permission_to_template() throws Exception { + setupData("addUserPermissionToTemplate"); + permissionDao.addUserPermission(1L, 1L, "new_permission"); + + checkTable("addUserPermissionToTemplate", "permission_templates", "id", "name", "description"); + checkTable("addUserPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("addUserPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } + + @Test + public void should_remove_user_permission_from_template() throws Exception { + setupData("removeUserPermissionFromTemplate"); + permissionDao.removeUserPermission(1L, 2L, "permission_to_remove"); + + checkTable("removeUserPermissionFromTemplate", "permission_templates", "id", "name", "description"); + checkTable("removeUserPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("removeUserPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } + + @Test + public void should_add_group_permission_to_template() throws Exception { + setupData("addGroupPermissionToTemplate"); + permissionDao.addGroupPermission(1L, 1L, "new_permission"); + + checkTable("addGroupPermissionToTemplate", "permission_templates", "id", "name", "description"); + checkTable("addGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("addGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } + + @Test + public void should_remove_group_permission_from_template() throws Exception { + setupData("removeGroupPermissionFromTemplate"); + permissionDao.removeGroupPermission(1L, 2L, "permission_to_remove"); + + checkTable("removeGroupPermissionFromTemplate", "permission_templates", "id", "name", "description"); + checkTable("removeGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("removeGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } + + @Test + public void should_add_group_permission_with_null_name() throws Exception { + setupData("addNullGroupPermissionToTemplate"); + permissionDao.addGroupPermission(1L, null, "new_permission"); + + checkTable("addNullGroupPermissionToTemplate", "permission_templates", "id", "name", "description"); + checkTable("addNullGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("addNullGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } + + @Test + public void should_remove_group_permission_with_null_name() throws Exception { + setupData("removeNullGroupPermissionFromTemplate"); + permissionDao.removeGroupPermission(1L, null, "permission_to_remove"); + + checkTable("removeNullGroupPermissionFromTemplate", "permission_templates", "id", "name", "description"); + checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); + checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java index 5a6fc165002..c39e89527c1 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/DefaultResourcePermissionsTest.java @@ -28,8 +28,8 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.security.DefaultGroups; import org.sonar.core.permission.ComponentPermissionFacade; +import org.sonar.core.permission.PermissionDao; import org.sonar.core.persistence.AbstractDaoTestCase; -import org.sonar.core.user.PermissionDao; import org.sonar.core.user.RoleDao; import org.sonar.core.user.UserDao; diff --git a/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java deleted file mode 100644 index bfce78a6942..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/user/PermissionDaoTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2013 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.user; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.core.persistence.AbstractDaoTestCase; - -import java.util.List; - -import static org.fest.assertions.Assertions.assertThat; - -public class PermissionDaoTest extends AbstractDaoTestCase { - - private PermissionDao permissionDao; - - @Before - public void setUpDao() { - permissionDao = new PermissionDao(getMyBatis()); - } - - @Test - public void should_create_permission_template() throws Exception { - setupData("createPermissionTemplate"); - PermissionTemplateDto permissionTemplate = permissionDao.createPermissionTemplate("my template", "my description"); - assertThat(permissionTemplate).isNotNull(); - assertThat(permissionTemplate.getId()).isEqualTo(1L); - checkTable("createPermissionTemplate", "permission_templates", "id", "name", "description"); - } - - @Test - public void should_select_permission_template() throws Exception { - setupData("selectPermissionTemplate"); - PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template"); - - assertThat(permissionTemplate).isNotNull(); - assertThat(permissionTemplate.getName()).isEqualTo("my template"); - assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); - assertThat(permissionTemplate.getUsersPermissions()).hasSize(3); - assertThat(permissionTemplate.getUsersPermissions()).onProperty("userId").containsOnly(1L, 2L, 1L); - assertThat(permissionTemplate.getUsersPermissions()).onProperty("userLogin").containsOnly("login1", "login2", "login2"); - assertThat(permissionTemplate.getUsersPermissions()).onProperty("userName").containsOnly("user1", "user2", "user2"); - assertThat(permissionTemplate.getUsersPermissions()).onProperty("permission").containsOnly("user_permission1", "user_permission1", "user_permission2"); - assertThat(permissionTemplate.getGroupsPermissions()).hasSize(3); - assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupId").containsOnly(1L, 2L, null); - assertThat(permissionTemplate.getGroupsPermissions()).onProperty("groupName").containsOnly("group1", "group2", null); - assertThat(permissionTemplate.getGroupsPermissions()).onProperty("permission").containsOnly("group_permission1", "group_permission1", "group_permission2"); - } - - @Test - public void should_select_empty_permission_template() throws Exception { - setupData("selectEmptyPermissionTemplate"); - PermissionTemplateDto permissionTemplate = permissionDao.selectPermissionTemplate("my template"); - - assertThat(permissionTemplate).isNotNull(); - assertThat(permissionTemplate.getName()).isEqualTo("my template"); - assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); - assertThat(permissionTemplate.getUsersPermissions()).isNull(); - assertThat(permissionTemplate.getGroupsPermissions()).isNull(); - } - - @Test - public void should_select_permission_template_by_name() throws Exception { - setupData("selectPermissionTemplate"); - - PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateByName("my template"); - - assertThat(permissionTemplate).isNotNull(); - assertThat(permissionTemplate.getId()).isEqualTo(1L); - assertThat(permissionTemplate.getName()).isEqualTo("my template"); - assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); - } - - @Test - public void should_select_permission_template_by_id() throws Exception { - setupData("selectPermissionTemplate"); - - PermissionTemplateDto permissionTemplate = permissionDao.selectTemplateById(1L); - - assertThat(permissionTemplate).isNotNull(); - assertThat(permissionTemplate.getId()).isEqualTo(1L); - assertThat(permissionTemplate.getName()).isEqualTo("my template"); - assertThat(permissionTemplate.getDescription()).isEqualTo("my description"); - } - - @Test - public void should_select_all_permission_templates() throws Exception { - setupData("selectAllPermissionTemplates"); - - List permissionTemplates = permissionDao.selectAllPermissionTemplates(); - - assertThat(permissionTemplates).hasSize(3); - assertThat(permissionTemplates).onProperty("id").containsOnly(1L, 2L, 3L); - assertThat(permissionTemplates).onProperty("name").containsOnly("template1", "template2", "template3"); - assertThat(permissionTemplates).onProperty("description").containsOnly("description1", "description2", "description3"); - } - - @Test - public void should_update_permission_template() throws Exception { - setupData("updatePermissionTemplate"); - - permissionDao.updatePermissionTemplate(1L, "new_name", "new_description"); - - checkTable("updatePermissionTemplate", "permission_templates", "id", "name", "description"); - } - - @Test - public void should_delete_permission_template() throws Exception { - setupData("deletePermissionTemplate"); - - permissionDao.deletePermissionTemplate(1L); - - checkTable("deletePermissionTemplate", "permission_templates", "id", "name", "description"); - checkTable("deletePermissionTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("deletePermissionTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } - - @Test - public void should_add_user_permission_to_template() throws Exception { - setupData("addUserPermissionToTemplate"); - permissionDao.addUserPermission(1L, 1L, "new_permission"); - - checkTable("addUserPermissionToTemplate", "permission_templates", "id", "name", "description"); - checkTable("addUserPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("addUserPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } - - @Test - public void should_remove_user_permission_from_template() throws Exception { - setupData("removeUserPermissionFromTemplate"); - permissionDao.removeUserPermission(1L, 2L, "permission_to_remove"); - - checkTable("removeUserPermissionFromTemplate", "permission_templates", "id", "name", "description"); - checkTable("removeUserPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("removeUserPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } - - @Test - public void should_add_group_permission_to_template() throws Exception { - setupData("addGroupPermissionToTemplate"); - permissionDao.addGroupPermission(1L, 1L, "new_permission"); - - checkTable("addGroupPermissionToTemplate", "permission_templates", "id", "name", "description"); - checkTable("addGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("addGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } - - @Test - public void should_remove_group_permission_from_template() throws Exception { - setupData("removeGroupPermissionFromTemplate"); - permissionDao.removeGroupPermission(1L, 2L, "permission_to_remove"); - - checkTable("removeGroupPermissionFromTemplate", "permission_templates", "id", "name", "description"); - checkTable("removeGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("removeGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } - - @Test - public void should_add_group_permission_with_null_name() throws Exception { - setupData("addNullGroupPermissionToTemplate"); - permissionDao.addGroupPermission(1L, null, "new_permission"); - - checkTable("addNullGroupPermissionToTemplate", "permission_templates", "id", "name", "description"); - checkTable("addNullGroupPermissionToTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("addNullGroupPermissionToTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } - - @Test - public void should_remove_group_permission_with_null_name() throws Exception { - setupData("removeNullGroupPermissionFromTemplate"); - permissionDao.removeGroupPermission(1L, null, "permission_to_remove"); - - checkTable("removeNullGroupPermissionFromTemplate", "permission_templates", "id", "name", "description"); - checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_users", "id", "template_id", "user_id", "permission_reference"); - checkTable("removeNullGroupPermissionFromTemplate", "perm_templates_groups", "id", "template_id", "group_id", "permission_reference"); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java index 582616cc5a6..6d0c9b0830e 100644 --- a/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/user/RoleDaoTest.java @@ -22,6 +22,7 @@ package org.sonar.core.user; import org.junit.Test; import org.sonar.api.security.DefaultGroups; +import org.sonar.core.permission.Permission; import org.sonar.core.persistence.AbstractDaoTestCase; import static org.fest.assertions.Assertions.assertThat; diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template-result.xml index ab25beb9f07..c512d7e3a61 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template-result.xml @@ -21,7 +21,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template.xml b/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template.xml index f962b008ca8..2c9dd6309fd 100644 --- a/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template.xml +++ b/sonar-core/src/test/resources/org/sonar/core/permission/ComponentPermissionFacadeTest/should_apply_permission_template.xml @@ -12,7 +12,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate-result.xml new file mode 100644 index 00000000000..c80216743b1 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate-result.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate.xml new file mode 100644 index 00000000000..6645e851711 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addGroupPermissionToTemplate.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml new file mode 100644 index 00000000000..7d42701d39f --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate.xml new file mode 100644 index 00000000000..6645e851711 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addNullGroupPermissionToTemplate.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate-result.xml new file mode 100644 index 00000000000..40bf5d45d4e --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate-result.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate.xml new file mode 100644 index 00000000000..6645e851711 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/addUserPermissionToTemplate.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml new file mode 100644 index 00000000000..962c1d62f61 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate-result.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate.xml new file mode 100644 index 00000000000..5ed00ba028b --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createNonAsciiPermissionTemplate.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml new file mode 100644 index 00000000000..0fbf6524539 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate-result.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate.xml new file mode 100644 index 00000000000..5ed00ba028b --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/createPermissionTemplate.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate-result.xml new file mode 100644 index 00000000000..06f6413de31 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate-result.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate.xml new file mode 100644 index 00000000000..b5a8064cd11 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/deletePermissionTemplate.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml new file mode 100644 index 00000000000..140738df7db --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate.xml new file mode 100644 index 00000000000..3258dcc22e5 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeGroupPermissionFromTemplate.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml new file mode 100644 index 00000000000..cc62050281b --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml new file mode 100644 index 00000000000..3e3289534fe --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml new file mode 100644 index 00000000000..89983781b67 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate.xml new file mode 100644 index 00000000000..779bd770de8 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/removeUserPermissionFromTemplate.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml new file mode 100644 index 00000000000..1fa43bea18c --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectAllPermissionTemplates.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectEmptyPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectEmptyPermissionTemplate.xml new file mode 100644 index 00000000000..e8360e44924 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectEmptyPermissionTemplate.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectPermissionTemplate.xml new file mode 100644 index 00000000000..8cfb9606511 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/selectPermissionTemplate.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate-result.xml new file mode 100644 index 00000000000..6f25f75defe --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate-result.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate.xml new file mode 100644 index 00000000000..2c056af7153 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/permission/PermissionDaoTest/updatePermissionTemplate.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_copy_permission_templates.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_copy_permission_templates.xml index 623ed1fd453..6bead9e07e1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_copy_permission_templates.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_copy_permission_templates.xml @@ -1,6 +1,6 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles-result.xml index 88a68afdb6b..8dd0f010003 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles-result.xml @@ -18,7 +18,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles.xml index fea38a879d8..ad5e93d9eeb 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles.xml @@ -10,7 +10,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRolesProject.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRolesProject.xml index 3ef5580c464..dac9bf90929 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRolesProject.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRolesProject.xml @@ -10,7 +10,7 @@ - + @@ -20,7 +20,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group-result.xml index 8158b940535..1aa42985eab 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group-result.xml @@ -12,7 +12,7 @@ - + \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group.xml index 0c4dfd1ab47..bcf1ee02a0e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_unknown_group.xml @@ -9,7 +9,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users-result.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users-result.xml index 75c11a9834c..ca14596bafe 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users-result.xml @@ -13,7 +13,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users.xml b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users.xml index 3f492a44512..bef56d94ebe 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/DefaultResourcePermissionsTest/grantDefaultRoles_users.xml @@ -10,7 +10,7 @@ - + diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml deleted file mode 100644 index ae1db0b574e..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate-result.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate.xml deleted file mode 100644 index 34ffb7f564a..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addGroupPermissionToTemplate.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml deleted file mode 100644 index 4fe3b439832..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate-result.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate.xml deleted file mode 100644 index 34ffb7f564a..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addNullGroupPermissionToTemplate.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml deleted file mode 100644 index 8676d568d5e..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate-result.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate.xml deleted file mode 100644 index 34ffb7f564a..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/addUserPermissionToTemplate.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate-result.xml deleted file mode 100644 index 4602891a02f..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate-result.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate.xml deleted file mode 100644 index 5ed00ba028b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/createPermissionTemplate.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml deleted file mode 100644 index df9b962986d..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate-result.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml deleted file mode 100644 index 61c40436844..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/deletePermissionTemplate.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml deleted file mode 100644 index 33773a8d4e0..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate-result.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml deleted file mode 100644 index 9df53ee7d2b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeGroupPermissionFromTemplate.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml deleted file mode 100644 index 52fd267873b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate-result.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml deleted file mode 100644 index 3e3f93359a2..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeNullGroupPermissionFromTemplate.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml deleted file mode 100644 index 925a1b25692..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate-result.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml deleted file mode 100644 index c160e4edf30..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/removeUserPermissionFromTemplate.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectAllPermissionTemplates.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectAllPermissionTemplates.xml deleted file mode 100644 index fc6e8c15234..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectAllPermissionTemplates.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectEmptyPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectEmptyPermissionTemplate.xml deleted file mode 100644 index 1bc1f3999a0..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectEmptyPermissionTemplate.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml deleted file mode 100644 index f869265575c..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/selectPermissionTemplate.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml deleted file mode 100644 index c29fef833b8..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate-result.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml b/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml deleted file mode 100644 index ef9d2a209af..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/user/PermissionDaoTest/updatePermissionTemplate.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java index 51ba1b246ac..e46717848cb 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueFilterService.java @@ -34,8 +34,8 @@ import org.sonar.core.issue.db.IssueFilterDao; import org.sonar.core.issue.db.IssueFilterDto; import org.sonar.core.issue.db.IssueFilterFavouriteDao; import org.sonar.core.issue.db.IssueFilterFavouriteDto; +import org.sonar.core.permission.Permission; import org.sonar.core.user.AuthorizationDao; -import org.sonar.core.user.Permission; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; @@ -43,7 +43,6 @@ import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.user.UserSession; import javax.annotation.CheckForNull; - import java.util.List; import java.util.Map; diff --git a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java index 825e4d66cd4..162bd1111e0 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionService.java @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; import org.sonar.api.security.DefaultGroups; import org.sonar.core.permission.ComponentPermissionFacade; +import org.sonar.core.permission.Permission; import org.sonar.core.user.*; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.user.UserSession; diff --git a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java index 306771b55ee..dee18cc0d7c 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java @@ -25,8 +25,8 @@ import org.h2.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; -import org.sonar.core.user.PermissionDao; -import org.sonar.core.user.PermissionTemplateDto; +import org.sonar.core.permission.PermissionDao; +import org.sonar.core.permission.PermissionTemplateDto; import org.sonar.core.user.UserDao; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ServerErrorException; diff --git a/sonar-server/src/main/java/org/sonar/server/permission/PermissionChangeQuery.java b/sonar-server/src/main/java/org/sonar/server/permission/PermissionChangeQuery.java index 02197715c7a..92bee097d59 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/PermissionChangeQuery.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/PermissionChangeQuery.java @@ -21,7 +21,7 @@ package org.sonar.server.permission; import org.apache.commons.lang.StringUtils; -import org.sonar.core.user.Permission; +import org.sonar.core.permission.Permission; import org.sonar.server.exceptions.BadRequestException; import java.util.Map; diff --git a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java index 20cd6888bcb..a88bf35d11f 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplate.java @@ -23,9 +23,9 @@ package org.sonar.server.permission; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; -import org.sonar.core.user.PermissionTemplateDto; -import org.sonar.core.user.PermissionTemplateGroupDto; -import org.sonar.core.user.PermissionTemplateUserDto; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.permission.PermissionTemplateGroupDto; +import org.sonar.core.permission.PermissionTemplateUserDto; import javax.annotation.Nullable; import java.util.List; diff --git a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java index ace626614b1..ff0716f1ab2 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/PermissionTemplateUpdater.java @@ -23,7 +23,12 @@ package org.sonar.server.permission; import com.google.common.collect.Lists; import org.sonar.api.security.DefaultGroups; import org.sonar.api.web.UserRole; -import org.sonar.core.user.*; +import org.sonar.core.permission.Permission; +import org.sonar.core.permission.PermissionDao; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.user.GroupDto; +import org.sonar.core.user.UserDao; +import org.sonar.core.user.UserDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.user.UserSession; diff --git a/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java b/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java index b807e92952f..799cf3f2b48 100644 --- a/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java +++ b/sonar-server/src/main/java/org/sonar/server/user/DefaultUserService.java @@ -25,13 +25,12 @@ import org.sonar.api.user.RubyUserService; import org.sonar.api.user.User; import org.sonar.api.user.UserFinder; import org.sonar.api.user.UserQuery; -import org.sonar.core.user.Permission; +import org.sonar.core.permission.Permission; import org.sonar.core.user.UserDao; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.util.RubyUtils; import javax.annotation.CheckForNull; - import java.util.List; import java.util.Map; diff --git a/sonar-server/src/main/java/org/sonar/server/user/UserSession.java b/sonar-server/src/main/java/org/sonar/server/user/UserSession.java index b51f71b0b47..6f153d7c302 100644 --- a/sonar-server/src/main/java/org/sonar/server/user/UserSession.java +++ b/sonar-server/src/main/java/org/sonar/server/user/UserSession.java @@ -23,15 +23,14 @@ import com.google.common.base.Objects; import com.google.common.base.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.core.permission.Permission; import org.sonar.core.user.AuthorizationDao; -import org.sonar.core.user.Permission; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; import org.sonar.server.platform.Platform; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.ArrayList; import java.util.List; import java.util.Locale; diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/415_create_permission_templates.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/415_create_permission_templates.rb index 58ace28ff96..cde3e930306 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/415_create_permission_templates.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/415_create_permission_templates.rb @@ -26,6 +26,7 @@ class CreatePermissionTemplates < ActiveRecord::Migration def self.up create_table :permission_templates do |t| t.column :name, :string, :null => false, :limit => 100 + t.column :kee, :string, :null => false, :limit => 100 t.column :description, :string, :null => true, :limit => 4000 t.column :created_at, :datetime, :null => true t.column :updated_at, :datetime, :null => true diff --git a/sonar-server/src/test/java/org/sonar/server/issue/IssueFilterServiceTest.java b/sonar-server/src/test/java/org/sonar/server/issue/IssueFilterServiceTest.java index 0bac5e1a74b..eab2f15d8dc 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/IssueFilterServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/IssueFilterServiceTest.java @@ -36,8 +36,8 @@ import org.sonar.core.issue.db.IssueFilterDao; import org.sonar.core.issue.db.IssueFilterDto; import org.sonar.core.issue.db.IssueFilterFavouriteDao; import org.sonar.core.issue.db.IssueFilterFavouriteDto; +import org.sonar.core.permission.Permission; import org.sonar.core.user.AuthorizationDao; -import org.sonar.core.user.Permission; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.NotFoundException; diff --git a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java index 5112fe239cd..0f5d9a7af33 100644 --- a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionServiceTest.java @@ -31,6 +31,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.security.DefaultGroups; import org.sonar.core.permission.ComponentPermissionFacade; +import org.sonar.core.permission.Permission; import org.sonar.core.user.*; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; diff --git a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java index 49d9e10a76d..9ddc5e31f09 100644 --- a/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/permission/InternalPermissionTemplateServiceTest.java @@ -26,7 +26,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.web.UserRole; -import org.sonar.core.user.*; +import org.sonar.core.permission.*; +import org.sonar.core.user.GroupDto; +import org.sonar.core.user.UserDao; +import org.sonar.core.user.UserDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.user.MockUserSession; diff --git a/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeQueryTest.java b/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeQueryTest.java index 148147b1408..02f98978fc4 100644 --- a/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeQueryTest.java +++ b/sonar-server/src/test/java/org/sonar/server/permission/PermissionChangeQueryTest.java @@ -24,7 +24,7 @@ import com.google.common.collect.Maps; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonar.core.user.Permission; +import org.sonar.core.permission.Permission; import org.sonar.server.exceptions.BadRequestException; import java.util.Map; diff --git a/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateTest.java b/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateTest.java index db52030e3cc..69a11a8a2ca 100644 --- a/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateTest.java +++ b/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateTest.java @@ -22,9 +22,9 @@ package org.sonar.server.permission; import com.google.common.collect.Lists; import org.junit.Test; -import org.sonar.core.user.PermissionTemplateDto; -import org.sonar.core.user.PermissionTemplateGroupDto; -import org.sonar.core.user.PermissionTemplateUserDto; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.permission.PermissionTemplateGroupDto; +import org.sonar.core.permission.PermissionTemplateUserDto; import static org.fest.assertions.Assertions.assertThat; diff --git a/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java b/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java index e2eda87c932..8a70b2f8c27 100644 --- a/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/permission/PermissionTemplateUpdaterTest.java @@ -25,7 +25,12 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.web.UserRole; -import org.sonar.core.user.*; +import org.sonar.core.permission.Permission; +import org.sonar.core.permission.PermissionDao; +import org.sonar.core.permission.PermissionTemplateDto; +import org.sonar.core.user.GroupDto; +import org.sonar.core.user.UserDao; +import org.sonar.core.user.UserDto; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.exceptions.UnauthorizedException; diff --git a/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java b/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java index 194de223491..df0e60b63cd 100644 --- a/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java +++ b/sonar-server/src/test/java/org/sonar/server/user/DefaultUserServiceTest.java @@ -27,7 +27,7 @@ import org.junit.rules.ExpectedException; import org.mockito.ArgumentMatcher; import org.sonar.api.user.UserFinder; import org.sonar.api.user.UserQuery; -import org.sonar.core.user.Permission; +import org.sonar.core.permission.Permission; import org.sonar.core.user.UserDao; import org.sonar.server.exceptions.BadRequestException; import org.sonar.server.exceptions.ForbiddenException; @@ -35,11 +35,7 @@ import org.sonar.server.exceptions.ForbiddenException; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.*; public class DefaultUserServiceTest { diff --git a/sonar-server/src/test/java/org/sonar/server/user/MockUserSession.java b/sonar-server/src/test/java/org/sonar/server/user/MockUserSession.java index d7dd2de8cbd..7e38dfe808c 100644 --- a/sonar-server/src/test/java/org/sonar/server/user/MockUserSession.java +++ b/sonar-server/src/test/java/org/sonar/server/user/MockUserSession.java @@ -19,10 +19,9 @@ */ package org.sonar.server.user; -import org.sonar.core.user.Permission; +import org.sonar.core.permission.Permission; import javax.annotation.Nullable; - import java.util.Arrays; import java.util.Collections; import java.util.Locale; diff --git a/sonar-server/src/test/java/org/sonar/server/user/UserSessionTest.java b/sonar-server/src/test/java/org/sonar/server/user/UserSessionTest.java index a5890d3d7e1..dcbfe23735a 100644 --- a/sonar-server/src/test/java/org/sonar/server/user/UserSessionTest.java +++ b/sonar-server/src/test/java/org/sonar/server/user/UserSessionTest.java @@ -20,8 +20,8 @@ package org.sonar.server.user; import org.junit.Test; +import org.sonar.core.permission.Permission; import org.sonar.core.user.AuthorizationDao; -import org.sonar.core.user.Permission; import org.sonar.server.exceptions.ForbiddenException; import java.util.Arrays;