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