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);
}
}
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()));
}
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();
}
}
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);
}
}
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;
}
Aggregations