Search in sources :

Example 1 with AddUserWsRequest

use of org.sonarqube.ws.client.permission.AddUserWsRequest in project sonarqube by SonarSource.

the class OrganizationTest method addPermissionsToUser.

private void addPermissionsToUser(String orgKeyAndName, String login, String permission, String... otherPermissions) {
    PermissionsService permissionsService = ItUtils.newAdminWsClient(orchestrator).permissions();
    permissionsService.addUser(new AddUserWsRequest().setLogin(login).setOrganization(orgKeyAndName).setPermission(permission));
    for (String otherPermission : otherPermissions) {
        permissionsService.addUser(new AddUserWsRequest().setLogin(login).setOrganization(orgKeyAndName).setPermission(otherPermission));
    }
}
Also used : AddUserWsRequest(org.sonarqube.ws.client.permission.AddUserWsRequest) PermissionsService(org.sonarqube.ws.client.permission.PermissionsService)

Example 2 with AddUserWsRequest

use of org.sonarqube.ws.client.permission.AddUserWsRequest in project sonarqube by SonarSource.

the class RestartTest method createSystemAdministrator.

private void createSystemAdministrator(String login, String password) {
    WsClient wsClient = newAdminWsClient(orchestrator);
    createNonSystemAdministrator(wsClient, login, password);
    wsClient.permissions().addUser(new AddUserWsRequest().setLogin(login).setPermission("admin"));
}
Also used : AddUserWsRequest(org.sonarqube.ws.client.permission.AddUserWsRequest) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newWsClient(util.ItUtils.newWsClient)

Example 3 with AddUserWsRequest

use of org.sonarqube.ws.client.permission.AddUserWsRequest in project sonarqube by SonarSource.

the class PermissionSearchTest method permission_web_services.

@Test
public void permission_web_services() {
    permissionsWsClient.addUser(new AddUserWsRequest().setPermission("admin").setLogin(LOGIN));
    permissionsWsClient.addGroup(new AddGroupWsRequest().setPermission("admin").setGroupName(GROUP_NAME));
    WsPermissions.WsSearchGlobalPermissionsResponse searchGlobalPermissionsWsResponse = permissionsWsClient.searchGlobalPermissions();
    assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getKey()).isEqualTo("admin");
    assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getUsersCount()).isEqualTo(1);
    // by default, a group has the global admin permission
    assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getGroupsCount()).isEqualTo(2);
    WsPermissions.UsersWsResponse users = permissionsWsClient.users(new UsersWsRequest().setPermission("admin"));
    assertThat(users.getUsersList()).extracting("login").contains(LOGIN);
    WsPermissions.WsGroupsResponse groupsResponse = permissionsWsClient.groups(new GroupsWsRequest().setPermission("admin"));
    assertThat(groupsResponse.getGroupsList()).extracting("name").contains(GROUP_NAME);
}
Also used : UsersWsRequest(org.sonarqube.ws.client.permission.UsersWsRequest) GroupsWsRequest(org.sonarqube.ws.client.permission.GroupsWsRequest) AddUserWsRequest(org.sonarqube.ws.client.permission.AddUserWsRequest) WsPermissions(org.sonarqube.ws.WsPermissions) AddGroupWsRequest(org.sonarqube.ws.client.permission.AddGroupWsRequest) Test(org.junit.Test)

Example 4 with AddUserWsRequest

use of org.sonarqube.ws.client.permission.AddUserWsRequest in project sonarqube by SonarSource.

the class QualityProfileAdminPermissionTest method permission_should_grant_access_to_profile.

@Test
public void permission_should_grant_access_to_profile() {
    userRule.createUser("not_profileadm", "userpwd");
    userRule.createUser("profileadm", "papwd");
    permissionsWsClient.addUser(new AddUserWsRequest().setLogin("profileadm").setPermission("profileadmin"));
    runSelenese(orchestrator, // Verify normal user is not allowed to do any modification
    "/authorisation/QualityProfileAdminPermissionTest/normal-user.html", // Verify profile admin is allowed to do modifications
    "/authorisation/QualityProfileAdminPermissionTest/profile-admin.html");
}
Also used : AddUserWsRequest(org.sonarqube.ws.client.permission.AddUserWsRequest) Test(org.junit.Test)

Example 5 with AddUserWsRequest

use of org.sonarqube.ws.client.permission.AddUserWsRequest in project sonarqube by SonarSource.

the class SettingsTest method initSettingsService.

@BeforeClass
public static void initSettingsService() throws Exception {
    userRule.createUser("setting-user", "setting-user");
    userRule.createUser("scanner-user", "scanner-user");
    adminWsClient = newAdminWsClient(orchestrator);
    // Remove 'Execute Analysis' permission from anyone
    adminWsClient.permissions().removeGroup(new RemoveGroupWsRequest().setGroupName("anyone").setPermission("scan"));
    // Anonymous user, without 'Execute Analysis' permission
    anonymousSettingsService = newWsClient(orchestrator).settingsService();
    // Authenticated user, without 'Execute Analysis' permission
    userSettingsService = newUserWsClient(orchestrator, "setting-user", "setting-user").settingsService();
    // User with 'Execute Analysis' permission
    adminWsClient.permissions().addUser(new AddUserWsRequest().setLogin("scanner-user").setPermission("scan"));
    scanSettingsService = newUserWsClient(orchestrator, "scanner-user", "scanner-user").settingsService();
    // User with 'Administer System' permission but without 'Execute Analysis' permission
    adminSettingsService = adminWsClient.settingsService();
}
Also used : RemoveGroupWsRequest(org.sonarqube.ws.client.permission.RemoveGroupWsRequest) AddUserWsRequest(org.sonarqube.ws.client.permission.AddUserWsRequest) BeforeClass(org.junit.BeforeClass)

Aggregations

AddUserWsRequest (org.sonarqube.ws.client.permission.AddUserWsRequest)5 Test (org.junit.Test)2 BeforeClass (org.junit.BeforeClass)1 WsPermissions (org.sonarqube.ws.WsPermissions)1 WsClient (org.sonarqube.ws.client.WsClient)1 AddGroupWsRequest (org.sonarqube.ws.client.permission.AddGroupWsRequest)1 GroupsWsRequest (org.sonarqube.ws.client.permission.GroupsWsRequest)1 PermissionsService (org.sonarqube.ws.client.permission.PermissionsService)1 RemoveGroupWsRequest (org.sonarqube.ws.client.permission.RemoveGroupWsRequest)1 UsersWsRequest (org.sonarqube.ws.client.permission.UsersWsRequest)1 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)1 ItUtils.newWsClient (util.ItUtils.newWsClient)1