use of org.sonar.db.user.UserTokenDto in project sonarqube by SonarSource.
the class GenerateAction method doHandle.
private WsUserTokens.GenerateWsResponse doHandle(GenerateWsRequest request) {
try (DbSession dbSession = dbClient.openSession(false)) {
checkWsRequest(dbSession, request);
TokenPermissionsValidator.validate(userSession, request.getLogin());
String token = tokenGenerator.generate();
String tokenHash = hashToken(dbSession, token);
UserTokenDto userTokenDto = insertTokenInDb(dbSession, request, tokenHash);
return buildResponse(userTokenDto, token);
}
}
use of org.sonar.db.user.UserTokenDto in project sonarqube by SonarSource.
the class SearchAction method doHandle.
private SearchWsResponse doHandle(SearchWsRequest request) {
TokenPermissionsValidator.validate(userSession, request.getLogin());
try (DbSession dbSession = dbClient.openSession(false)) {
String login = request.getLogin();
checkLoginExists(dbSession, login);
List<UserTokenDto> userTokens = dbClient.userTokenDao().selectByLogin(dbSession, login);
return buildResponse(login, userTokens);
}
}
use of org.sonar.db.user.UserTokenDto in project sonarqube by SonarSource.
the class GenerateAction method insertTokenInDb.
private UserTokenDto insertTokenInDb(DbSession dbSession, GenerateWsRequest request, String tokenHash) {
UserTokenDto userTokenDto = new UserTokenDto().setLogin(request.getLogin()).setName(request.getName()).setTokenHash(tokenHash).setCreatedAt(system.now());
dbClient.userTokenDao().insert(dbSession, userTokenDto);
dbSession.commit();
return userTokenDto;
}
use of org.sonar.db.user.UserTokenDto in project sonarqube by SonarSource.
the class SearchAction method buildResponse.
private static SearchWsResponse buildResponse(String login, List<UserTokenDto> userTokensDto) {
SearchWsResponse.Builder searchWsResponse = SearchWsResponse.newBuilder();
SearchWsResponse.UserToken.Builder userTokenBuilder = SearchWsResponse.UserToken.newBuilder();
searchWsResponse.setLogin(login);
for (UserTokenDto userTokenDto : userTokensDto) {
userTokenBuilder.clear().setName(userTokenDto.getName()).setCreatedAt(formatDateTime(new Date(userTokenDto.getCreatedAt())));
searchWsResponse.addUserTokens(userTokenBuilder);
}
return searchWsResponse.build();
}
Aggregations