--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.server.permission;
+
+import static java.lang.String.format;
+
+public class DefaultPermissionTemplates {
+ public static final String DEFAULT_TEMPLATE_PROPERTY = "sonar.permission.template.default";
+ private static final String DEFAULT_ROOT_QUALIFIER_TEMPLATE_PROPERTY = "sonar.permission.template.%s.default";
+
+ public static String defaultRootQualifierTemplateProperty(String qualifier) {
+ return format(DEFAULT_ROOT_QUALIFIER_TEMPLATE_PROPERTY, qualifier);
+ }
+}
}
private Long templateId(String templateKey) {
- PermissionTemplateDto dto = permissionTemplateDao.selectByKey(templateKey);
+ PermissionTemplateDto dto = permissionTemplateDao.selectByUuid(templateKey);
if (dto == null) {
throw new NotFoundException(String.format("Template '%s' does not exist", templateKey));
}
@CheckForNull
public PermissionTemplate selectPermissionTemplate(String templateKey) {
checkGlobalAdminUser(userSession);
- PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectByKeyWithUserAndGroupPermissions(templateKey);
+ PermissionTemplateDto permissionTemplateDto = permissionTemplateDao.selectByUuidWithUserAndGroupPermissions(templateKey);
return PermissionTemplate.create(permissionTemplateDto);
}
public void deletePermissionTemplate(Long templateId) {
checkGlobalAdminUser(userSession);
- permissionTemplateDao.deleteById(templateId);
+ DbSession dbSession = dbClient.openSession(false);
+ try {
+ permissionTemplateDao.deleteById(dbSession, templateId);
+ dbSession.commit();
+ } finally {
+ dbClient.closeSession(dbSession);
+ }
}
/**
}
private Long getTemplateId(String key) {
- PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().selectByKey(key);
+ PermissionTemplateDto permissionTemplateDto = dbClient.permissionTemplateDao().selectByUuid(key);
if (permissionTemplateDto == null) {
throw new BadRequestException("Unknown template: " + key);
}
import org.sonarqube.ws.Permissions;
import org.sonarqube.ws.Permissions.PermissionTemplate;
+import static java.lang.String.format;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_DESCRIPTION;
import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_NAME;
validateTemplateNameFormat(name);
PermissionTemplateDto permissionTemplateWithSameName = dbClient.permissionTemplateDao().selectByName(dbSession, name);
- checkRequest(permissionTemplateWithSameName == null, String.format
- (MSG_TEMPLATE_WITH_SAME_NAME, name));
+ checkRequest(permissionTemplateWithSameName == null, format(MSG_TEMPLATE_WITH_SAME_NAME, name));
}
private PermissionTemplateDto insertTemplate(DbSession dbSession, String name, String description, String projectPattern) {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.server.permission.ws;
+
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
+import javax.annotation.Nonnull;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.ResourceTypes;
+
+import static com.google.common.base.Objects.firstNonNull;
+import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
+import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
+import static org.sonar.server.permission.ws.ResourceTypeToQualifier.RESOURCE_TYPE_TO_QUALIFIER;
+
+public class DefaultPermissionTemplateFinder {
+ private final Settings settings;
+ private final ResourceTypes resourceTypes;
+
+ public DefaultPermissionTemplateFinder(Settings settings, ResourceTypes resourceTypes) {
+ this.settings = settings;
+ this.resourceTypes = resourceTypes;
+ }
+
+ public Set<String> getDefaultTemplateUuids() {
+ return ImmutableSet.<String>builder()
+ .addAll(
+ FluentIterable.from(resourceTypes.getRoots())
+ .transform(RESOURCE_TYPE_TO_QUALIFIER)
+ .transform(new QualifierToDefaultTemplate(settings))
+ .toSet())
+ .add(settings.getString(DEFAULT_TEMPLATE_PROPERTY))
+ .build();
+ }
+
+ private static class QualifierToDefaultTemplate implements Function<String, String> {
+ private final Settings settings;
+
+ QualifierToDefaultTemplate(Settings settings) {
+ this.settings = settings;
+ }
+
+ @Override
+ public String apply(@Nonnull String qualifier) {
+ String qualifierProperty = settings.getString(defaultRootQualifierTemplateProperty(qualifier));
+ return firstNonNull(qualifierProperty, settings.getString(DEFAULT_TEMPLATE_PROPERTY));
+ }
+ }
+
+}
package org.sonar.server.permission.ws;
+import java.util.Set;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.permission.PermissionTemplateDto;
import org.sonar.server.user.UserSession;
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID;
import static org.sonar.server.permission.ws.Parameters.createTemplateKeyParameter;
+import static org.sonar.server.ws.WsUtils.checkRequest;
public class DeleteTemplateAction implements PermissionsWsAction {
private final DbClient dbClient;
private final UserSession userSession;
+ private final PermissionDependenciesFinder finder;
+ private final DefaultPermissionTemplateFinder defaultPermissionTemplateFinder;
- public DeleteTemplateAction(DbClient dbClient, UserSession userSession) {
+ public DeleteTemplateAction(DbClient dbClient, UserSession userSession, PermissionDependenciesFinder finder, DefaultPermissionTemplateFinder defaultPermissionTemplateFinder) {
this.dbClient = dbClient;
this.userSession = userSession;
+ this.finder = finder;
+ this.defaultPermissionTemplateFinder = defaultPermissionTemplateFinder;
}
@Override
@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
checkGlobalAdminUser(userSession);
- String key = wsRequest.mandatoryParam(PARAM_TEMPLATE_ID);
+ String uuid = wsRequest.mandatoryParam(PARAM_TEMPLATE_ID);
+ checkTemplateUuidIsNotDefault(uuid);
+
+ deleteTemplate(uuid);
+
+ wsResponse.noContent();
+ }
+
+ private void deleteTemplate(String uuid) {
DbSession dbSession = dbClient.openSession(false);
try {
- dbClient.permissionTemplateDao().deleteByKey(dbSession, key);
+ PermissionTemplateDto template = finder.getTemplate(dbSession, uuid);
+ dbClient.permissionTemplateDao().deleteById(dbSession, template.getId());
dbSession.commit();
-
- wsResponse.noContent();
} finally {
dbClient.closeSession(dbSession);
}
}
+
+ private void checkTemplateUuidIsNotDefault(String key) {
+ Set<String> defaultTemplateUuids = defaultPermissionTemplateFinder.getDefaultTemplateUuids();
+ checkRequest(!defaultTemplateUuids.contains(key), "It is not possible to delete a default template");
+ }
}
format("User with login '%s' is not found'", userLogin));
}
- PermissionTemplateDto getTemplate(DbSession dbSession, String templateKey) {
- return checkFound(dbClient.permissionTemplateDao().selectByKey(dbSession, templateKey),
- format("Permission template with key '%s' is not found", templateKey));
+ PermissionTemplateDto getTemplate(DbSession dbSession, String uuid) {
+ return checkFound(dbClient.permissionTemplateDao().selectByUuid(dbSession, uuid),
+ format("Permission template with id '%s' is not found", uuid));
}
}
protected void configureModule() {
add(
PermissionsWs.class,
+ // actions
AddGroupAction.class,
AddUserAction.class,
RemoveGroupAction.class,
UsersAction.class,
GroupsAction.class,
SearchGlobalPermissionsAction.class,
- PermissionChangeBuilder.class,
SearchProjectPermissionsAction.class,
- SearchProjectPermissionsDataLoader.class,
- PermissionDependenciesFinder.class,
- AddUserToTemplateAction.class,
RemoveUserFromTemplateAction.class,
+ AddUserToTemplateAction.class,
AddGroupToTemplateAction.class,
RemoveGroupFromTemplateAction.class,
CreateTemplateAction.class,
UpdateTemplateAction.class,
- DeleteTemplateAction.class);
+ DeleteTemplateAction.class,
+ // utility classes
+ PermissionChangeBuilder.class,
+ SearchProjectPermissionsDataLoader.class,
+ PermissionDependenciesFinder.class,
+ DefaultPermissionTemplateFinder.class);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.server.permission.ws;
+
+import com.google.common.base.Function;
+import javax.annotation.Nonnull;
+import org.sonar.api.resources.ResourceType;
+
+class ResourceTypeToQualifier {
+
+ static final Function<ResourceType, String> RESOURCE_TYPE_TO_QUALIFIER = Singleton.INSTANCE;
+
+ private enum Singleton implements Function<ResourceType, String> {
+ INSTANCE;
+
+ @Override
+ public String apply(@Nonnull ResourceType resourceType) {
+ return resourceType.getQualifier();
+ }
+ }
+}
import javax.annotation.Nonnull;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
-import org.sonar.api.resources.ResourceType;
import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.Request;
import org.sonar.api.utils.Paging;
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
import static org.sonar.api.utils.Paging.forPageIndex;
+import static org.sonar.server.permission.ws.ResourceTypeToQualifier.RESOURCE_TYPE_TO_QUALIFIER;
import static org.sonar.server.permission.ws.SearchProjectPermissionsData.newBuilder;
public class SearchProjectPermissionsDataLoader {
public SearchProjectPermissionsDataLoader(DbClient dbClient, ComponentFinder componentFinder, ResourceTypes resourceTypes) {
this.dbClient = dbClient;
this.componentFinder = componentFinder;
- this.rootQualifiers = Collections2.transform(resourceTypes.getRoots(), new ResourceTypeToQualifierFunction());
+ this.rootQualifiers = Collections2.transform(resourceTypes.getRoots(), RESOURCE_TYPE_TO_QUALIFIER);
}
public SearchProjectPermissionsData load(Request wsRequest) {
return component.getId();
}
}
-
- private static class ResourceTypeToQualifierFunction implements Function<ResourceType, String> {
- @Override
- public String apply(@Nonnull ResourceType resourceType) {
- return resourceType.getQualifier();
- }
- }
}
package org.sonar.server.startup;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.db.user.GroupDto;
import org.sonar.server.platform.PersistentSettings;
-public class RegisterPermissionTemplates {
+import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
+import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
- public static final String DEFAULT_TEMPLATE_PROPERTY = "sonar.permission.template.default";
- public static final String DEFAULT_PROJECTS_TEMPLATE_PROPERTY = "sonar.permission.template.TRK.default";
+public class RegisterPermissionTemplates {
private static final Logger LOG = Loggers.get(RegisterPermissionTemplates.class);
if (shouldRegister()) {
if (hasExistingPermissionsConfig()) {
- String projectsPermissionsKey = settings.getString(DEFAULT_PROJECTS_TEMPLATE_PROPERTY);
+ String projectsPermissionsKey = settings.getString(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT));
setDefaultProperty(projectsPermissionsKey);
} else {
insertDefaultTemplate();
}
private boolean hasExistingPermissionsConfig() {
- return settings.getString(DEFAULT_PROJECTS_TEMPLATE_PROPERTY) != null;
+ return settings.getString(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT)) != null;
}
private boolean shouldRegister() {
@Test
public void find_users_from_permission_template() {
- when(permissionTemplateDao.selectByKey(anyString())).thenReturn(new PermissionTemplateDto().setId(1L).setKee("my_template"));
+ when(permissionTemplateDao.selectByUuid(anyString())).thenReturn(new PermissionTemplateDto().setId(1L).setKee("my_template"));
when(permissionTemplateDao.selectUsers(any(DbSession.class), any(PermissionQuery.class), anyLong(), anyInt(), anyInt())).thenReturn(
newArrayList(new UserWithPermissionDto().setName("user1").setPermission("user"))
@Test
public void fail_to_find_users_from_permission_template_when_template_not_found() {
- when(permissionTemplateDao.selectByKey(anyString())).thenReturn(null);
+ when(permissionTemplateDao.selectByUuid(anyString())).thenReturn(null);
try {
underTest.findUsersWithPermissionTemplate(PermissionQuery.builder().permission("user").template("Unknown").build());
@Test
public void find_groups_from_permission_template() {
- when(permissionTemplateDao.selectByKey(anyString())).thenReturn(new PermissionTemplateDto().setId(1L).setKee("my_template"));
+ when(permissionTemplateDao.selectByUuid(anyString())).thenReturn(new PermissionTemplateDto().setId(1L).setKee("my_template"));
when(permissionTemplateDao.selectGroups(any(DbSession.class), any(PermissionQuery.class), anyLong())).thenReturn(
newArrayList(new GroupWithPermissionDto().setName("users").setPermission("user"))
@Test
public void fail_to_find_groups_from_permission_template_when_template_not_found() {
- when(permissionTemplateDao.selectByKey(anyString())).thenReturn(null);
+ when(permissionTemplateDao.selectByUuid(anyString())).thenReturn(null);
try {
underTest.findGroupsWithPermissionTemplate(PermissionQuery.builder().permission("user").template("Unknown").build());
@Test
public void should_delete_permission_template() {
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.deletePermissionTemplate(1L);
- verify(permissionTemplateDao, times(1)).deleteById(1L);
+ verify(permissionTemplateDao).deleteById(any(DbSession.class), eq(1L));
}
@Test
.setUsersPermissions(usersPermissions)
.setGroupsByPermission(groupsPermissions);
- when(permissionTemplateDao.selectByKeyWithUserAndGroupPermissions("my template")).thenReturn(permissionTemplateDto);
+ when(permissionTemplateDao.selectByUuidWithUserAndGroupPermissions("my template")).thenReturn(permissionTemplateDto);
PermissionTemplate permissionTemplate = underTest.selectPermissionTemplate("my template");
public void should_add_user_permission() {
UserDto userDto = new UserDto().setId(1L).setLogin("user").setName("user");
when(userDao.selectActiveUserByLogin("user")).thenReturn(userDto);
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.addUserPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "user");
expected.expect(BadRequestException.class);
expected.expectMessage("Unknown user:");
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
when(userDao.selectActiveUserByLogin("unknown")).thenReturn(null);
underTest.addUserPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "unknown");
public void should_remove_user_permission() {
UserDto userDto = new UserDto().setId(1L).setLogin("user").setName("user");
when(userDao.selectActiveUserByLogin("user")).thenReturn(userDto);
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.removeUserPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "user");
public void should_add_group_permission() {
GroupDto groupDto = new GroupDto().setId(1L).setName("group");
when(groupDao.selectByName(any(DbSession.class), eq("group"))).thenReturn(groupDto);
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.addGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "group");
expected.expect(BadRequestException.class);
expected.expectMessage("Unknown group:");
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
when(groupDao.selectByName(any(DbSession.class), eq("unknown"))).thenReturn(null);
underTest.addGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "unknown");
public void should_remove_group_permission() {
GroupDto groupDto = new GroupDto().setId(1L).setName("group");
when(groupDao.selectByName(any(DbSession.class), eq("group"))).thenReturn(groupDto);
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.removeGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "group");
@Test
public void should_add_permission_to_anyone_group() {
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.addGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "Anyone");
@Test
public void should_remove_permission_from_anyone_group() {
- when(permissionTemplateDao.selectByKey(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
+ when(permissionTemplateDao.selectByUuid(DEFAULT_KEY)).thenReturn(DEFAULT_TEMPLATE);
underTest.removeGroupPermission(DEFAULT_KEY, DEFAULT_PERMISSION, "Anyone");
public void should_execute_on_valid_parameters() {
final PermissionTemplateDao permissionTemplateDao = mock(PermissionTemplateDao.class);
- when(permissionTemplateDao.selectByKey("my_template")).thenReturn(new PermissionTemplateDto().setId(1L));
+ when(permissionTemplateDao.selectByUuid("my_template")).thenReturn(new PermissionTemplateDto().setId(1L));
when(dbClient.permissionTemplateDao()).thenReturn(permissionTemplateDao);
PermissionTemplateUpdater updater =
expected.expectMessage("Unknown template:");
final PermissionTemplateDao permissionTemplateDao = mock(PermissionTemplateDao.class);
- when(permissionTemplateDao.selectByKey("my_template")).thenReturn(null);
+ when(permissionTemplateDao.selectByUuid("my_template")).thenReturn(null);
PermissionTemplateUpdater updater =
new PermissionTemplateUpdater(dbClient, userSessionRule, "my_template", UserRole.USER, "user") {
expected.expect(BadRequestException.class);
final PermissionTemplateDao permissionTemplateDao = mock(PermissionTemplateDao.class);
- when(permissionTemplateDao.selectByKey("my_template")).thenReturn(new PermissionTemplateDto().setId(1L));
+ when(permissionTemplateDao.selectByUuid("my_template")).thenReturn(new PermissionTemplateDto().setId(1L));
when(dbClient.permissionTemplateDao()).thenReturn(permissionTemplateDao);
PermissionTemplateUpdater updater =
@Test
public void fail_if_template_key_does_not_exist() {
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Permission template with key 'unknown-key' is not found");
+ expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
newRequest(GROUP_NAME, "unknown-key", CODEVIEWER);
}
@Test
public void fail_if_template_key_does_not_exist() {
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Permission template with key 'unknown-key' is not found");
+ expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
newRequest(USER_LOGIN, "unknown-key", CODEVIEWER);
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.server.permission.ws;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.ResourceType;
+import org.sonar.api.resources.ResourceTypes;
+
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
+import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
+
+public class DefaultPermissionTemplateFinderTest {
+
+ ResourceTypes resourceTypes = mock(ResourceTypes.class);
+ Settings settings = new Settings();
+
+ DefaultPermissionTemplateFinder underTest;
+
+ @Before
+ public void setUp() {
+ underTest = new DefaultPermissionTemplateFinder(settings, resourceTypes);
+ settings
+ .setProperty(DEFAULT_TEMPLATE_PROPERTY, "default-template-uuid")
+ .setProperty(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT), "default-project-template-uuid")
+ .setProperty(defaultRootQualifierTemplateProperty("DEV"), "default-dev-template-uuid")
+ .setProperty(defaultRootQualifierTemplateProperty(Qualifiers.VIEW), "default-view-template-uuid");
+ when(resourceTypes.getRoots()).thenReturn(rootResourceTypes());
+ }
+
+ @Test
+ public void get_default_template_uuids_in_settings() {
+ Set<String> result = underTest.getDefaultTemplateUuids();
+
+ assertThat(result).containsOnly("default-template-uuid", "default-project-template-uuid", "default-view-template-uuid", "default-dev-template-uuid");
+ }
+
+ @Test
+ public void get_default_template_uuid_if_no_root_resource() {
+ when(resourceTypes.getRoots()).thenReturn(Collections.<ResourceType>emptySet());
+
+ Set<String> result = underTest.getDefaultTemplateUuids();
+
+ assertThat(result).containsOnly("default-template-uuid");
+ }
+
+ @Test
+ public void get_default_template_uuid_if_no_property() {
+ settings = new Settings();
+ settings.setProperty(DEFAULT_TEMPLATE_PROPERTY, "default-template-uuid");
+ underTest = new DefaultPermissionTemplateFinder(settings, resourceTypes);
+
+ Set<String> result = underTest.getDefaultTemplateUuids();
+
+ assertThat(result).containsOnly("default-template-uuid");
+ }
+
+ private static List<ResourceType> rootResourceTypes() {
+ ResourceType project = ResourceType.builder(Qualifiers.PROJECT).build();
+ ResourceType view = ResourceType.builder(Qualifiers.VIEW).build();
+ ResourceType dev = ResourceType.builder("DEV").build();
+
+ return asList(project, view, dev);
+ }
+}
package org.sonar.server.permission.ws;
+import java.util.Collections;
import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
+import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.permission.PermissionTemplateDto;
+import org.sonar.db.user.GroupDto;
+import org.sonar.db.user.GroupTesting;
+import org.sonar.db.user.UserDto;
+import org.sonar.db.user.UserTesting;
+import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.exceptions.UnauthorizedException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.internal.util.collections.Sets.newSet;
import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
import static org.sonar.server.permission.ws.Parameters.PARAM_TEMPLATE_ID;
public class DeleteTemplateActionTest {
- static final String TEMPLATE_KEY = "permission-template-key";
+ static final String TEMPLATE_UUID = "permission-template-uuid";
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
WsActionTester ws;
DbClient dbClient;
DbSession dbSession;
+ DefaultPermissionTemplateFinder defautTemplatePermissionFinder;
+
PermissionTemplateDto permissionTemplate;
@Before
dbClient = db.getDbClient();
dbSession = db.getSession();
- ws = new WsActionTester(new DeleteTemplateAction(dbClient, userSession));
-
- permissionTemplate = insertTemplate(newPermissionTemplateDto().setKee("permission-template-key"));
- commit();
- assertThat(dbClient.permissionTemplateDao().selectByKey(dbSession, TEMPLATE_KEY)).isNotNull();
+ defautTemplatePermissionFinder = mock(DefaultPermissionTemplateFinder.class);
+ when(defautTemplatePermissionFinder.getDefaultTemplateUuids()).thenReturn(Collections.<String>emptySet());
+ PermissionDependenciesFinder finder = new PermissionDependenciesFinder(dbClient, new ComponentFinder(dbClient));
+ ws = new WsActionTester(new DeleteTemplateAction(dbClient, userSession, finder, defautTemplatePermissionFinder));
+
+ permissionTemplate = insertTemplateAndAssociatedPermissions(newPermissionTemplateDto().setKee(TEMPLATE_UUID));
+ PermissionTemplateDto permissionTemplateInDatabase = dbClient.permissionTemplateDao().selectByUuidWithUserAndGroupPermissions(dbSession, TEMPLATE_UUID);
+ assertThat(permissionTemplateInDatabase.getKee()).isEqualTo(TEMPLATE_UUID);
+ assertThat(permissionTemplateInDatabase.getGroupsPermissions()).isNotEmpty();
+ assertThat(permissionTemplateInDatabase.getUsersPermissions()).isNotEmpty();
}
@Test
public void delete_template_in_db() {
-
- TestResponse result = newRequest(TEMPLATE_KEY);
+ TestResponse result = newRequest(TEMPLATE_UUID);
assertThat(result.getInput()).isEmpty();
- assertThat(dbClient.permissionTemplateDao().selectByKey(dbSession, TEMPLATE_KEY)).isNull();
+ assertThat(dbClient.permissionTemplateDao().selectByUuidWithUserAndGroupPermissions(dbSession, TEMPLATE_UUID)).isNull();
+ }
+
+ @Test
+ public void fail_if_uuid_is_not_known() {
+ expectedException.expect(NotFoundException.class);
+
+ newRequest("unknown-template-uuid");
+ }
+
+ @Test
+ public void fail_if_template_is_default() {
+ expectedException.expect(BadRequestException.class);
+ expectedException.expectMessage("It is not possible to delete a default template");
+ when(defautTemplatePermissionFinder.getDefaultTemplateUuids()).thenReturn(newSet(TEMPLATE_UUID));
+
+ newRequest(TEMPLATE_UUID);
}
@Test
expectedException.expect(UnauthorizedException.class);
userSession.anonymous();
- newRequest(TEMPLATE_KEY);
+ newRequest(TEMPLATE_UUID);
}
@Test
expectedException.expect(ForbiddenException.class);
userSession.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
- newRequest(TEMPLATE_KEY);
+ newRequest(TEMPLATE_UUID);
}
@Test
- public void fail_if_key_is_not_provided() {
+ public void fail_if_uuid_is_not_provided() {
expectedException.expect(IllegalArgumentException.class);
newRequest(null);
}
- private PermissionTemplateDto insertTemplate(PermissionTemplateDto template) {
- return dbClient.permissionTemplateDao().insert(dbSession, template);
+ private PermissionTemplateDto insertTemplateAndAssociatedPermissions(PermissionTemplateDto template) {
+ dbClient.permissionTemplateDao().insert(dbSession, template);
+ UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto().setActive(true));
+ GroupDto group = dbClient.groupDao().insert(dbSession, GroupTesting.newGroupDto());
+ dbClient.permissionTemplateDao().insertUserPermission(dbSession, template.getId(), user.getId(), UserRole.ADMIN);
+ dbClient.permissionTemplateDao().insertGroupPermission(dbSession, template.getId(), group.getId(), UserRole.CODEVIEWER);
+ commit();
+
+ return template;
}
private void commit() {
dbSession.commit();
}
- private TestResponse newRequest(@Nullable String key) {
+ private TestResponse newRequest(@Nullable String id) {
TestRequest request = ws.newRequest();
- if (key != null) {
- request.setParam(PARAM_TEMPLATE_ID, key);
+ if (id != null) {
+ request.setParam(PARAM_TEMPLATE_ID, id);
}
TestResponse result = executeRequest(request);
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new PermissionsWsModule().configure(container);
- assertThat(container.size()).isEqualTo(21);
+ assertThat(container.size()).isEqualTo(22);
}
}
@Test
public void fail_if_template_key_does_not_exist() {
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Permission template with key 'unknown-key' is not found");
+ expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
newRequest(GROUP_NAME, "unknown-key", PERMISSION);
}
@Test
public void fail_if_template_key_does_not_exist() {
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Permission template with key 'unknown-key' is not found");
+ expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
newRequest(USER_LOGIN, "unknown-key", DEFAULT_PERMISSION);
}
public void update_with_the_same_values() {
newRequest(templateDto.getKee(), templateDto.getName(), templateDto.getDescription(), templateDto.getKeyPattern());
- PermissionTemplateDto updatedTemplate = dbClient.permissionTemplateDao().selectByKey(dbSession, templateDto.getKee());
+ PermissionTemplateDto updatedTemplate = dbClient.permissionTemplateDao().selectByUuid(dbSession, templateDto.getKee());
assertThat(updatedTemplate.getName()).isEqualTo(templateDto.getName());
assertThat(updatedTemplate.getDescription()).isEqualTo(templateDto.getDescription());
assertThat(updatedTemplate.getKeyPattern()).isEqualTo(templateDto.getKeyPattern());
@Test
public void fail_if_key_is_not_found() {
expectedException.expect(NotFoundException.class);
- expectedException.expectMessage("Permission template with key 'unknown-key' is not found");
+ expectedException.expectMessage("Permission template with id 'unknown-key' is not found");
newRequest("unknown-key", null, null, null);
}
import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Test;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
+import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
+import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
public class RegisterPermissionTemplatesTest {
verify(permissionTemplateDao).insertGroupPermission(1L, null, UserRole.USER);
verify(permissionTemplateDao).insertGroupPermission(1L, null, UserRole.CODEVIEWER);
verifyNoMoreInteractions(permissionTemplateDao);
- verify(settings).saveProperty(RegisterPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY, PermissionTemplateDto.DEFAULT.getKee());
+ verify(settings).saveProperty(DEFAULT_TEMPLATE_PROPERTY, PermissionTemplateDto.DEFAULT.getKee());
}
@Test
@Test
public void should_reference_TRK_template_as_default_when_present() {
- when(settings.getString(RegisterPermissionTemplates.DEFAULT_PROJECTS_TEMPLATE_PROPERTY)).thenReturn("my_projects_template");
+ when(settings.getString(defaultRootQualifierTemplateProperty(Qualifiers.PROJECT))).thenReturn("my_projects_template");
LoadedTemplateDto expectedTemplate = new LoadedTemplateDto().setKey(PermissionTemplateDto.DEFAULT.getKee())
.setType(LoadedTemplateDto.PERMISSION_TEMPLATE_TYPE);
initializer.start();
verify(loadedTemplateDao).insert(argThat(Matches.template(expectedTemplate)));
- verify(settings).saveProperty(RegisterPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY, "my_projects_template");
+ verify(settings).saveProperty(DEFAULT_TEMPLATE_PROPERTY, "my_projects_template");
verifyZeroInteractions(permissionTemplateDao);
}
* When selecting by id or key, the methods respect one of the following pattern:
* <ul>
* <li>selectOrFailByKey return the element or throws a RowNotFoundException</li>
- * <li>selectByKey return an Optional (now) or a nullable element (legacy)</li>
+ * <li>selectByUuid return an Optional (now) or a nullable element (legacy)</li>
* </ul>
*/
public class RowNotFoundException extends RuntimeException {
}
@CheckForNull
- public PermissionTemplateDto selectByKey(DbSession session, String templateKey) {
- return mapper(session).selectByKey(templateKey);
+ public PermissionTemplateDto selectByUuid(DbSession session, String templateKey) {
+ return mapper(session).selectByUuid(templateKey);
}
@CheckForNull
- public PermissionTemplateDto selectByKey(String templateKey) {
+ public PermissionTemplateDto selectByUuid(String templateKey) {
DbSession session = myBatis.openSession(false);
try {
- return selectByKey(session, templateKey);
+ return selectByUuid(session, templateKey);
} finally {
MyBatis.closeQuietly(session);
}
}
@CheckForNull
- public PermissionTemplateDto selectByKeyWithUserAndGroupPermissions(DbSession session, String templateKey) {
+ public PermissionTemplateDto selectByUuidWithUserAndGroupPermissions(DbSession session, String templateKey) {
PermissionTemplateDto permissionTemplate = null;
PermissionTemplateMapper mapper = mapper(session);
- permissionTemplate = mapper.selectByKey(templateKey);
+ permissionTemplate = mapper.selectByUuid(templateKey);
PermissionTemplateDto templateUsersPermissions = mapper.selectTemplateUsersPermissions(templateKey);
if (templateUsersPermissions != null) {
permissionTemplate.setUsersPermissions(templateUsersPermissions.getUsersPermissions());
}
@CheckForNull
- public PermissionTemplateDto selectByKeyWithUserAndGroupPermissions(String templateKey) {
+ public PermissionTemplateDto selectByUuidWithUserAndGroupPermissions(String templateKey) {
DbSession session = myBatis.openSession(false);
try {
- return selectByKeyWithUserAndGroupPermissions(session, templateKey);
+ return selectByUuidWithUserAndGroupPermissions(session, templateKey);
} finally {
MyBatis.closeQuietly(session);
}
return permissionTemplate;
}
- public void deleteByKey(DbSession dbSession, String key) {
- mapper(dbSession).deleteByKey(key);
- }
-
- public void deleteById(Long templateId) {
- SqlSession session = myBatis.openSession(false);
- try {
- PermissionTemplateMapper mapper = mapper(session);
- mapper.deleteUsersPermissions(templateId);
- mapper.deleteGroupsPermissions(templateId);
- mapper.delete(templateId);
- session.commit();
- } finally {
- MyBatis.closeQuietly(session);
- }
+ public void deleteById(DbSession session, long templateId) {
+ PermissionTemplateMapper mapper = mapper(session);
+ mapper.deleteUserPermissions(templateId);
+ mapper.deleteGroupPermissions(templateId);
+ mapper.delete(templateId);
}
/**
session.commit();
}
+ public void deleteGroupPermissions(DbSession session, long templateId) {
+ mapper(session).deleteGroupPermissions(templateId);
+ }
+
+ public void deleteUserPermissions(DbSession session, long templateId) {
+ mapper(session).deleteUserPermissions(templateId);
+ }
+
/**
* Load permission template and load associated collections of users and groups permissions
*/
@VisibleForTesting
PermissionTemplateDto selectPermissionTemplateWithPermissions(DbSession session, String templateKey) {
- PermissionTemplateDto permissionTemplateDto = selectByKey(session, templateKey);
+ PermissionTemplateDto permissionTemplateDto = selectByUuid(session, templateKey);
if (permissionTemplateDto == null) {
throw new IllegalArgumentException("Could not retrieve permission template with key " + templateKey);
}
- PermissionTemplateDto templateWithPermissions = selectByKeyWithUserAndGroupPermissions(session, permissionTemplateDto.getKee());
+ PermissionTemplateDto templateWithPermissions = selectByUuidWithUserAndGroupPermissions(session, permissionTemplateDto.getKee());
if (templateWithPermissions == null) {
throw new IllegalArgumentException("Could not retrieve permissions for template with key " + templateKey);
}
return templateWithPermissions;
}
- public PermissionTemplateDto selectByName(DbSession dbSession, String templateName) {
- char wildcard = '%';
- return mapper(dbSession).selectByName(wildcard + templateName.toUpperCase() + wildcard);
+ public PermissionTemplateDto selectByName(DbSession dbSession, String name) {
+ return mapper(dbSession).selectByName(name.toUpperCase());
}
/**
void delete(long templateId);
- void deleteUsersPermissions(long templateId);
+ void deleteUserPermissions(long templateId);
- void deleteGroupsPermissions(long templateId);
+ void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
+
+ void deleteGroupPermissions(long templateId);
- PermissionTemplateDto selectByKey(String templateKey);
+ void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
+
+ PermissionTemplateDto selectByUuid(String templateUuid);
PermissionTemplateDto selectTemplateUsersPermissions(String templateKey);
void insertUserPermission(PermissionTemplateUserDto permissionTemplateUser);
- void deleteUserPermission(PermissionTemplateUserDto permissionTemplateUser);
-
void insertGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
- void deleteGroupPermission(PermissionTemplateGroupDto permissionTemplateGroup);
-
void deleteByGroupId(long groupId);
List<GroupWithPermissionDto> selectGroups(Map<String, Object> params);
int countUsers(Map<String, Object> params);
int countGroups(Map<String, Object> parameters);
-
- void deleteByKey(String key);
}
WHERE id = #{templateId}
</delete>
- <delete id="deleteByKey" parameterType="string">
- DELETE FROM permission_templates
- WHERE kee = #{key}
- </delete>
-
- <delete id="deleteUsersPermissions" parameterType="long">
+ <delete id="deleteUserPermissions" parameterType="long">
DELETE FROM perm_templates_users
WHERE template_id = #{templateId}
</delete>
- <delete id="deleteGroupsPermissions" parameterType="long">
+ <delete id="deleteGroupPermissions" parameterType="long">
DELETE FROM perm_templates_groups
WHERE template_id = #{templateId}
</delete>
id, name, kee, description, key_pattern AS keyPattern, created_at AS createdAt, updated_at AS updatedAt
</sql>
- <select id="selectByKey" parameterType="String" resultType="PermissionTemplate">
+ <select id="selectByUuid" parameterType="String" resultType="PermissionTemplate">
SELECT
<include refid="templateColumns"/>
FROM permission_templates
- WHERE kee = #{kee}
+ WHERE kee=#{uuid}
</select>
<select id="selectAllPermissionTemplates" resultType="PermissionTemplate">
SELECT
<include refid="templateColumns"/>
FROM permission_templates
- WHERE UPPER(name) LIKE #{templateName} ESCAPE '/'
+ WHERE UPPER(name)=#{templateName}
</select>
<select id="selectTemplateUsersPermissions" parameterType="String" resultMap="fullPermissionsTemplateResult">
public void should_select_permission_template() {
db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
- PermissionTemplateDto permissionTemplate = underTest.selectByKeyWithUserAndGroupPermissions("my_template_20130102_030405");
+ PermissionTemplateDto permissionTemplate = underTest.selectByUuidWithUserAndGroupPermissions("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
public void should_select_empty_permission_template() {
db.prepareDbUnit(getClass(), "selectEmptyPermissionTemplate.xml");
- PermissionTemplateDto permissionTemplate = underTest.selectByKeyWithUserAndGroupPermissions("my_template_20130102_030405");
+ PermissionTemplateDto permissionTemplate = underTest.selectByUuidWithUserAndGroupPermissions("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getName()).isEqualTo("my template");
public void should_select_permission_template_by_key() {
db.prepareDbUnit(getClass(), "selectPermissionTemplate.xml");
- PermissionTemplateDto permissionTemplate = underTest.selectByKey("my_template_20130102_030405");
+ PermissionTemplateDto permissionTemplate = underTest.selectByUuid("my_template_20130102_030405");
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getId()).isEqualTo(1L);
public void should_delete_permission_template() {
db.prepareDbUnit(getClass(), "deletePermissionTemplate.xml");
- underTest.deleteById(1L);
+ underTest.deleteById(session, 1L);
+ session.commit();
checkTemplateTables("deletePermissionTemplate-result.xml");
}
- @Test
- public void delete_by_key() {
- String templateKey = "permission-template-key";
- underTest.insert(session, newPermissionTemplateDto().setKee(templateKey));
- assertThat(underTest.selectByKey(session, templateKey)).isNotNull();
-
- underTest.deleteByKey(session, templateKey);
-
- assertThat(underTest.selectByKey(session, templateKey)).isNull();
- }
-
@Test
public void should_add_user_permission_to_template() {
db.prepareDbUnit(getClass(), "addUserPermissionToTemplate.xml");
PermissionTemplateDto permissionTemplateDto = new PermissionTemplateDto().setName("Test template").setKee("test_template");
PermissionTemplateDto templateWithPermissions = new PermissionTemplateDto().setKee("test_template");
underTest = mock(PermissionTemplateDao.class);
- when(underTest.selectByKey(db.getSession(), "test_template")).thenReturn(permissionTemplateDto);
- when(underTest.selectByKeyWithUserAndGroupPermissions(db.getSession(), "test_template")).thenReturn(templateWithPermissions);
+ when(underTest.selectByUuid(db.getSession(), "test_template")).thenReturn(permissionTemplateDto);
+ when(underTest.selectByUuidWithUserAndGroupPermissions(db.getSession(), "test_template")).thenReturn(templateWithPermissions);
when(underTest.selectPermissionTemplateWithPermissions(db.getSession(), "test_template")).thenCallRealMethod();
PermissionTemplateDto permissionTemplate = underTest.selectPermissionTemplateWithPermissions(db.getSession(), "test_template");