Search in sources :

Example 51 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class OrganizationCreationImpl method insertOwnersGroup.

/**
   * Owners group has an hard coded name, a description based on the organization's name and has all global permissions.
   */
private GroupDto insertOwnersGroup(DbSession dbSession, OrganizationDto organization) {
    GroupDto group = dbClient.groupDao().insert(dbSession, new GroupDto().setOrganizationUuid(organization.getUuid()).setName(OWNERS_GROUP_NAME).setDescription(format(OWNERS_GROUP_DESCRIPTION_PATTERN, organization.getName())));
    OrganizationPermission.all().forEach(p -> addPermissionToGroup(dbSession, group, p));
    return group;
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto)

Example 52 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class OrganizationCreationImpl method create.

@Override
public OrganizationDto create(DbSession dbSession, int creatorUserId, NewOrganization newOrganization) throws KeyConflictException {
    validate(newOrganization);
    String key = newOrganization.getKey();
    if (organizationKeyIsUsed(dbSession, key)) {
        throw new KeyConflictException(format("Organization key '%s' is already used", key));
    }
    OrganizationDto organization = insertOrganization(dbSession, newOrganization, dto -> {
    });
    GroupDto group = insertOwnersGroup(dbSession, organization);
    insertDefaultTemplate(dbSession, organization, group);
    addCurrentUserToGroup(dbSession, group, creatorUserId);
    dbSession.commit();
    return organization;
}
Also used : UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 53 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class UserUpdater method addDefaultGroup.

private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
    String defaultGroupName = settings.getString(CoreProperties.CORE_DEFAULT_GROUP);
    if (defaultGroupName == null) {
        return;
    }
    String defOrgUuid = defaultOrganizationProvider.get().getUuid();
    List<GroupDto> userGroups = dbClient.groupDao().selectByUserLogin(dbSession, userDto.getLogin());
    if (!userGroups.stream().anyMatch(g -> defOrgUuid.equals(g.getOrganizationUuid()) && g.getName().equals(defaultGroupName))) {
        Optional<GroupDto> groupDto = dbClient.groupDao().selectByName(dbSession, defOrgUuid, defaultGroupName);
        if (!groupDto.isPresent()) {
            throw new ServerException(HttpURLConnection.HTTP_INTERNAL_ERROR, format("The default group '%s' for new users does not exist. Please update the general security settings to fix this issue.", defaultGroupName));
        }
        dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(userDto.getId()).setGroupId(groupDto.get().getId()));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) UserGroupDto(org.sonar.db.user.UserGroupDto) UserDto(org.sonar.db.user.UserDto) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Random(java.util.Random) ServerException(org.sonar.server.exceptions.ServerException) DbSession(org.sonar.db.DbSession) SecureRandom(java.security.SecureRandom) Strings(com.google.common.base.Strings) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OrganizationCreation(org.sonar.server.organization.OrganizationCreation) WsUtils.checkFound(org.sonar.server.ws.WsUtils.checkFound) WsUtils.checkRequest(org.sonar.server.ws.WsUtils.checkRequest) Validation(org.sonar.server.util.Validation) NewUserHandler(org.sonar.api.platform.NewUserHandler) Nullable(javax.annotation.Nullable) GroupDto(org.sonar.db.user.GroupDto) DefaultOrganizationProvider(org.sonar.server.organization.DefaultOrganizationProvider) System2(org.sonar.api.utils.System2) CoreProperties(org.sonar.api.CoreProperties) Collectors(org.sonar.core.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) UserIndexer(org.sonar.server.user.index.UserIndexer) DbClient(org.sonar.db.DbClient) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) UserDto.encryptPassword(org.sonar.db.user.UserDto.encryptPassword) Settings(org.sonar.api.config.Settings) ServerSide(org.sonar.api.server.ServerSide) Optional(java.util.Optional) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) ServerException(org.sonar.server.exceptions.ServerException) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto)

Example 54 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupWsSupport method findGroup.

/**
   * Finds a user group by its reference. If organization is not defined then group
   * is searched in default organization.
   *
   * @return non-null group
   * @throws NotFoundException if the requested group does not exist
   * @throws NotFoundException if the requested group is Anyone
   */
public GroupId findGroup(DbSession dbSession, GroupWsRef ref) {
    if (ref.hasId()) {
        GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId());
        checkFound(group, "No group with id '%s'", ref.getId());
        return GroupId.from(group);
    }
    OrganizationDto org = findOrganizationByKey(dbSession, ref.getOrganizationKey());
    Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, org.getUuid(), ref.getName());
    checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", ref.getName(), org.getKey());
    return GroupId.from(group.get());
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Example 55 with GroupDto

use of org.sonar.db.user.GroupDto in project sonarqube by SonarSource.

the class GroupWsSupport method findGroupOrAnyone.

public GroupIdOrAnyone findGroupOrAnyone(DbSession dbSession, GroupWsRef ref) {
    if (ref.hasId()) {
        GroupDto group = dbClient.groupDao().selectById(dbSession, ref.getId());
        checkFound(group, "No group with id '%s'", ref.getId());
        return GroupIdOrAnyone.from(group);
    }
    OrganizationDto org = findOrganizationByKey(dbSession, ref.getOrganizationKey());
    if (ref.isAnyone()) {
        return GroupIdOrAnyone.forAnyone(org.getUuid());
    }
    Optional<GroupDto> group = dbClient.groupDao().selectByName(dbSession, org.getUuid(), ref.getName());
    checkFoundWithOptional(group, "No group with name '%s' in organization '%s'", ref.getName(), org.getKey());
    return GroupIdOrAnyone.from(group.get());
}
Also used : GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto)

Aggregations

GroupDto (org.sonar.db.user.GroupDto)177 Test (org.junit.Test)158 OrganizationDto (org.sonar.db.organization.OrganizationDto)74 UserDto (org.sonar.db.user.UserDto)67 ComponentDto (org.sonar.db.component.ComponentDto)38 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)31 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)18 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)17 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)14 UserGroupDto (org.sonar.db.user.UserGroupDto)12 DbSession (org.sonar.db.DbSession)11 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)9 PermissionTemplateTesting.newPermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateGroupDto)8 WsGroupsResponse (org.sonarqube.ws.WsPermissions.WsGroupsResponse)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)3 System2 (org.sonar.api.utils.System2)3 DbClient (org.sonar.db.DbClient)3 PermissionTemplateTesting.newPermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateTesting.newPermissionTemplateDto)3 Strings (com.google.common.base.Strings)2