Search in sources :

Example 1 with UserTokenDto

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserTokenDto(org.sonar.db.user.UserTokenDto)

Example 2 with UserTokenDto

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) UserTokenDto(org.sonar.db.user.UserTokenDto)

Example 3 with UserTokenDto

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;
}
Also used : UserTokenDto(org.sonar.db.user.UserTokenDto)

Example 4 with 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();
}
Also used : SearchWsResponse(org.sonarqube.ws.WsUserTokens.SearchWsResponse) UserTokenDto(org.sonar.db.user.UserTokenDto) Date(java.util.Date)

Aggregations

UserTokenDto (org.sonar.db.user.UserTokenDto)4 DbSession (org.sonar.db.DbSession)2 Date (java.util.Date)1 SearchWsResponse (org.sonarqube.ws.WsUserTokens.SearchWsResponse)1