Search in sources :

Example 31 with UserDto

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

the class BasicAuthenticator method authenticate.

private UserDto authenticate(String login, String password, HttpServletRequest request) {
    if (isEmpty(password)) {
        UserDto userDto = authenticateFromUserToken(login);
        authenticationEvent.loginSuccess(request, userDto.getLogin(), Source.local(Method.BASIC_TOKEN));
        return userDto;
    } else {
        return credentialsAuthenticator.authenticate(login, password, request, Method.BASIC);
    }
}
Also used : UserDto(org.sonar.db.user.UserDto)

Example 32 with UserDto

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

the class JwtHttpHandler method validateToken.

private Optional<Token> validateToken(String tokenEncoded, HttpServletRequest request, HttpServletResponse response) {
    Optional<Claims> claims = jwtSerializer.decode(tokenEncoded);
    if (!claims.isPresent()) {
        return Optional.empty();
    }
    Date now = new Date(system2.now());
    Claims token = claims.get();
    if (now.after(addSeconds(token.getIssuedAt(), SESSION_DISCONNECT_IN_SECONDS))) {
        return Optional.empty();
    }
    jwtCsrfVerifier.verifyState(request, (String) token.get(CSRF_JWT_PARAM), token.getSubject());
    if (now.after(addSeconds(getLastRefreshDate(token), SESSION_REFRESH_IN_SECONDS))) {
        refreshToken(token, request, response);
    }
    Optional<UserDto> user = selectUserFromDb(token.getSubject());
    if (!user.isPresent()) {
        return Optional.empty();
    }
    return Optional.of(new Token(user.get(), claims.get()));
}
Also used : Claims(io.jsonwebtoken.Claims) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date)

Example 33 with UserDto

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

the class CreateAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String valueAsString = request.mandatoryParam(PARAM_VALUE);
    String description = request.param(PARAM_DESCRIPTION);
    long now = system.now();
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(PARAM_PROJECT_ID), request.param(PARAM_PROJECT_KEY), PROJECT_ID_AND_KEY);
        MetricDto metric = searchMetric(dbSession, request);
        checkPermissions(userSession, component);
        checkIsProjectOrModule(component);
        checkMeasureDoesNotExistAlready(dbSession, component, metric);
        UserDto user = dbClient.userDao().selectOrFailByLogin(dbSession, userSession.getLogin());
        CustomMeasureDto measure = new CustomMeasureDto().setComponentUuid(component.uuid()).setMetricId(metric.getId()).setDescription(description).setUserLogin(user.getLogin()).setCreatedAt(now).setUpdatedAt(now);
        validator.setMeasureValue(measure, valueAsString, metric);
        dbClient.customMeasureDao().insert(dbSession, measure);
        dbSession.commit();
        JsonWriter json = response.newJsonWriter();
        customMeasureJsonWriter.write(json, measure, metric, component, user, true, CustomMeasureJsonWriter.OPTIONAL_FIELDS);
        json.close();
    }
}
Also used : DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) JsonWriter(org.sonar.api.utils.text.JsonWriter) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 34 with UserDto

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

the class SearchAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String projectUuid = request.param(PARAM_PROJECT_ID);
    String projectKey = request.param(PARAM_PROJECT_KEY);
    List<String> fieldsToReturn = request.paramAsStrings(WebService.Param.FIELDS);
    SearchOptions searchOptions = new SearchOptions().setPage(request.mandatoryParamAsInt(WebService.Param.PAGE), request.mandatoryParamAsInt(WebService.Param.PAGE_SIZE));
    try (DbSession dbSession = dbClient.openSession(false)) {
        ComponentDto component = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey, PROJECT_ID_AND_KEY);
        checkPermissions(userSession, component);
        Long lastAnalysisDateMs = searchLastSnapshotDate(dbSession, component);
        List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, component, searchOptions);
        int nbCustomMeasures = countTotalOfCustomMeasures(dbSession, component);
        Map<String, UserDto> usersByLogin = usersByLogin(dbSession, customMeasures);
        Map<Integer, MetricDto> metricsById = metricsById(dbSession, customMeasures);
        writeResponse(response, customMeasures, nbCustomMeasures, component, metricsById, usersByLogin, lastAnalysisDateMs, searchOptions, fieldsToReturn);
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchOptions(org.sonar.server.es.SearchOptions) DbSession(org.sonar.db.DbSession) MetricDto(org.sonar.db.metric.MetricDto) CustomMeasureDto(org.sonar.db.measure.custom.CustomMeasureDto)

Example 35 with UserDto

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

the class UserUpdater method createNewUserDto.

private UserDto createNewUserDto(DbSession dbSession, NewUser newUser) {
    UserDto userDto = new UserDto();
    List<String> messages = newArrayList();
    String login = newUser.login();
    if (validateLoginFormat(login, messages)) {
        userDto.setLogin(login);
    }
    String name = newUser.name();
    if (validateNameFormat(name, messages)) {
        userDto.setName(name);
    }
    String email = newUser.email();
    if (email != null && validateEmailFormat(email, messages)) {
        userDto.setEmail(email);
    }
    String password = newUser.password();
    if (password != null && validatePasswords(password, messages)) {
        setEncryptedPassWord(password, userDto);
    }
    List<String> scmAccounts = sanitizeScmAccounts(newUser.scmAccounts());
    if (scmAccounts != null && !scmAccounts.isEmpty() && validateScmAccounts(dbSession, scmAccounts, login, email, null, messages)) {
        userDto.setScmAccounts(scmAccounts);
    }
    setExternalIdentity(userDto, newUser.externalIdentity());
    checkRequest(messages.isEmpty(), messages);
    return userDto;
}
Also used : UserDto(org.sonar.db.user.UserDto)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41