Search in sources :

Example 1 with GenerateWsRequest

use of org.sonarqube.ws.client.usertoken.GenerateWsRequest in project sonarqube by SonarSource.

the class GenerateAction method toCreateWsRequest.

private GenerateWsRequest toCreateWsRequest(Request request) {
    GenerateWsRequest generateWsRequest = new GenerateWsRequest().setLogin(request.param(PARAM_LOGIN)).setName(request.mandatoryParam(PARAM_NAME).trim());
    if (generateWsRequest.getLogin() == null) {
        generateWsRequest.setLogin(userSession.getLogin());
    }
    checkRequest(!generateWsRequest.getName().isEmpty(), "The '%s' parameter must not be blank", PARAM_NAME);
    return generateWsRequest;
}
Also used : GenerateWsRequest(org.sonarqube.ws.client.usertoken.GenerateWsRequest)

Example 2 with GenerateWsRequest

use of org.sonarqube.ws.client.usertoken.GenerateWsRequest in project sonarqube by SonarSource.

the class PermissionTest method scanner_can_authenticate_with_authentication_token.

@Test
public void scanner_can_authenticate_with_authentication_token() {
    createUserWithProvisioningAndScanPermissions();
    String tokenName = "For test";
    WsUserTokens.GenerateWsResponse generateWsResponse = userTokensWsClient.generate(new GenerateWsRequest().setLogin(A_LOGIN).setName(tokenName));
    SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample"));
    sampleProject.setProperties("sonar.login", generateWsResponse.getToken(), "sonar.password", "");
    BuildResult buildResult = orchestrator.executeBuild(sampleProject);
    assertThat(buildResult.isSuccess()).isTrue();
    userTokensWsClient.revoke(new RevokeWsRequest().setLogin(A_LOGIN).setName(tokenName));
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) RevokeWsRequest(org.sonarqube.ws.client.usertoken.RevokeWsRequest) GenerateWsRequest(org.sonarqube.ws.client.usertoken.GenerateWsRequest) WsUserTokens(org.sonarqube.ws.WsUserTokens) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 3 with GenerateWsRequest

use of org.sonarqube.ws.client.usertoken.GenerateWsRequest in project sonarqube by SonarSource.

the class LocalAuthenticationTest method basic_authentication_based_on_token.

@Test
public void basic_authentication_based_on_token() {
    String tokenName = "Validate token based authentication";
    WsUserTokens.GenerateWsResponse generateWsResponse = userTokensWsClient.generate(new GenerateWsRequest().setLogin(LOGIN).setName(tokenName));
    WsClient wsClient = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder().url(ORCHESTRATOR.getServer().getUrl()).token(generateWsResponse.getToken()).build());
    WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate"));
    assertThat(response.content()).isEqualTo("{\"valid\":true}");
    WsUserTokens.SearchWsResponse searchResponse = userTokensWsClient.search(new SearchWsRequest().setLogin(LOGIN));
    assertThat(searchResponse.getUserTokensCount()).isEqualTo(1);
    userTokensWsClient.revoke(new RevokeWsRequest().setLogin(LOGIN).setName(tokenName));
    searchResponse = userTokensWsClient.search(new SearchWsRequest().setLogin(LOGIN));
    assertThat(searchResponse.getUserTokensCount()).isEqualTo(0);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) SearchWsRequest(org.sonarqube.ws.client.usertoken.SearchWsRequest) RevokeWsRequest(org.sonarqube.ws.client.usertoken.RevokeWsRequest) WsResponse(org.sonarqube.ws.client.WsResponse) GenerateWsRequest(org.sonarqube.ws.client.usertoken.GenerateWsRequest) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) WsUserTokens(org.sonarqube.ws.WsUserTokens) Test(org.junit.Test)

Aggregations

GenerateWsRequest (org.sonarqube.ws.client.usertoken.GenerateWsRequest)3 Test (org.junit.Test)2 WsUserTokens (org.sonarqube.ws.WsUserTokens)2 RevokeWsRequest (org.sonarqube.ws.client.usertoken.RevokeWsRequest)2 BuildResult (com.sonar.orchestrator.build.BuildResult)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 GetRequest (org.sonarqube.ws.client.GetRequest)1 WsClient (org.sonarqube.ws.client.WsClient)1 WsResponse (org.sonarqube.ws.client.WsResponse)1 SearchWsRequest (org.sonarqube.ws.client.usertoken.SearchWsRequest)1 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)1