use of org.sonar.db.DbSession 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()));
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class UserIndexer method doIndex.
private void doIndex(@Nullable String login, Size bulkSize) {
final BulkIndexer bulk = new BulkIndexer(esClient, UserIndexDefinition.INDEX_TYPE_USER.getIndex());
bulk.setSize(bulkSize);
try (DbSession dbSession = dbClient.openSession(false)) {
try (UserResultSetIterator rowIt = UserResultSetIterator.create(dbClient, dbSession, login)) {
doIndex(bulk, rowIt);
}
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ChangePasswordAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
String login = request.mandatoryParam(PARAM_LOGIN);
if (login.equals(userSession.getLogin())) {
String previousPassword = request.mandatoryParam(PARAM_PREVIOUS_PASSWORD);
checkCurrentPassword(dbSession, login, previousPassword);
} else {
userSession.checkIsSystemAdministrator();
}
String password = request.mandatoryParam(PARAM_PASSWORD);
UpdateUser updateUser = UpdateUser.create(login).setPassword(password);
userUpdater.update(dbSession, updateUser);
}
response.noContent();
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class CurrentAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<UserDto> user = Optional.empty();
Collection<String> groups = emptyList();
if (userSession.isLoggedIn()) {
user = selectCurrentUser(dbSession);
groups = selectGroups(dbSession);
}
writeResponse(response, user, groups);
}
}
use of org.sonar.db.DbSession in project sonarqube by SonarSource.
the class ShowAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkIsSystemAdministrator();
try (DbSession dbSession = dbClient.openSession(true)) {
Map<String, PropertyDto> properties = dbClient.propertiesDao().selectGlobalPropertiesByKeys(dbSession, SETTINGS_KEYS).stream().collect(Collectors.uniqueIndex(PropertyDto::getKey, Function.identity()));
writeProtobuf(doHandle(properties), request, response);
}
}
Aggregations