Search in sources :

Example 11 with UserManagementClient

use of org.wso2.identity.scenarios.commons.clients.UserManagementClient in project product-is by wso2.

the class SCIM2MeTestCase method assignUserToGroup.

private void assignUserToGroup(String username) throws Exception {
    AutomationContext automationContext;
    if (tenant.equals(org.wso2.carbon.base.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
        automationContext = new AutomationContext("IDENTITY", TestUserMode.SUPER_TENANT_ADMIN);
    } else {
        automationContext = new AutomationContext("IDENTITY", TestUserMode.TENANT_ADMIN);
    }
    String backendUrl = automationContext.getContextUrls().getBackEndUrl();
    String sessionCookie = new LoginLogoutClient(automationContext).login();
    UserManagementClient userMgtClient = new UserManagementClient(backendUrl, sessionCookie);
    String[] roles = { ADMIN_ROLE };
    userMgtClient.addRemoveRolesOfUser(username, roles, null);
}
Also used : AutomationContext(org.wso2.carbon.automation.engine.context.AutomationContext) LoginLogoutClient(org.wso2.carbon.integration.common.utils.LoginLogoutClient) UserManagementClient(org.wso2.carbon.integration.common.admin.client.UserManagementClient)

Example 12 with UserManagementClient

use of org.wso2.identity.scenarios.commons.clients.UserManagementClient in project product-is by wso2.

the class SCIM2GroupTest method testGetGroupsAfterRemovingHybridRoleOfAMember.

@Test(dependsOnMethods = "testGETGroupDetails", description = "Test whether the assigned user list of a hybrid " + "role created by a Service Provider is updated properly when a secondary user store is disabled/deleted " + "where one of the users in the respective secondary user store was assigned to the respective hybrid role.")
public void testGetGroupsAfterRemovingHybridRoleOfAMember() throws Exception {
    ApplicationManagementServiceClient applicationManagementServiceClient = new ApplicationManagementServiceClient(sessionCookie, backendURL, ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null));
    ServiceProvider serviceProviderApp = new ServiceProvider();
    serviceProviderApp.setApplicationName(APPLICATION_NAME);
    serviceProviderApp.setDescription("sample-description");
    serviceProviderApp.setSaasApp(true);
    applicationManagementServiceClient.createApplication(serviceProviderApp);
    serviceProviderApp = applicationManagementServiceClient.getApplication(APPLICATION_NAME);
    Assert.assertEquals(serviceProviderApp.getApplicationName(), APPLICATION_NAME, "Failed to create the Service Provider: " + APPLICATION_NAME);
    UserManagementClient userMgtClient = new UserManagementClient(backendURL, getSessionCookie());
    userMgtClient.addUser(USERNAME_OF_THE_NEW_USER, "newUserPassword", new String[] { APPLICATION_ROLE_NAME }, null);
    endpointURL = GROUPS_ENDPOINT;
    ExtractableResponse scimResponse = getResponseOfGet(endpointURL, SCIM_CONTENT_TYPE).then().assertThat().statusCode(HttpStatus.SC_OK).and().assertThat().header(HttpHeaders.CONTENT_TYPE, SCIM_CONTENT_TYPE).log().ifValidationFails().extract();
    Assert.assertNotNull(scimResponse);
    Object resourcesAttribute = scimResponse.path("Resources");
    Assert.assertTrue(resourcesAttribute instanceof ArrayList, "'Resources' attribute is not a list of " + "objects");
    Optional<LinkedHashMap> targetSpApplicationRole = ((ArrayList<LinkedHashMap>) resourcesAttribute).stream().filter(resource -> ((String) resource.get("displayName")).contains(APPLICATION_ROLE_NAME)).findFirst();
    Assert.assertTrue(targetSpApplicationRole.isPresent(), "Application role not found for the " + "Service Provider: " + APPLICATION_NAME);
    groupId = (String) targetSpApplicationRole.get().get("id");
    Optional<LinkedHashMap> targetMemberAttribute = ((ArrayList<LinkedHashMap>) targetSpApplicationRole.get().get("members")).stream().filter(member -> StringUtils.equals((String) member.get("display"), USERNAME_OF_THE_NEW_USER)).findFirst();
    Assert.assertTrue(targetMemberAttribute.isPresent(), "User: " + USERNAME_OF_THE_NEW_USER + " is not " + "assigned to the role: " + APPLICATION_ROLE_NAME);
    String targetUserId = (String) targetMemberAttribute.get().get("value");
    UserStoreConfigAdminServiceClient userStoreConfigAdminServiceClient = new UserStoreConfigAdminServiceClient(backendURL, sessionCookie);
    userStoreConfigAdminServiceClient.changeUserStoreState(USER_STORE_DOMAIN, true);
    Thread.sleep(20000);
    endpointURL += "/" + groupId;
    scimResponse = getResponseOfGet(endpointURL, SCIM_CONTENT_TYPE).then().assertThat().statusCode(HttpStatus.SC_OK).and().assertThat().header(HttpHeaders.CONTENT_TYPE, SCIM_CONTENT_TYPE).log().ifValidationFails().extract();
    Assert.assertNotNull(scimResponse);
    Object membersAttribute = scimResponse.path("members");
    Assert.assertTrue(membersAttribute instanceof ArrayList, "'members' attribute is not a list of " + "objects");
    targetMemberAttribute = ((ArrayList<LinkedHashMap>) membersAttribute).stream().filter(member -> StringUtils.equals((String) member.get("value"), targetUserId)).findAny();
    Assert.assertFalse(targetMemberAttribute.isPresent(), "User: " + USERNAME_OF_THE_NEW_USER + " of the disabled user store: " + USER_STORE_DOMAIN + " is assigned to the  application role: " + APPLICATION_ROLE_NAME);
    if (ISTestUtils.nameExists(userMgtClient.listAllUsers(USERNAME_OF_THE_NEW_USER, 10), USERNAME_OF_THE_NEW_USER)) {
        userMgtClient.deleteUser(USERNAME_OF_THE_NEW_USER);
    }
    userStoreConfigAdminServiceClient.changeUserStoreState(USER_STORE_DOMAIN, false);
    Thread.sleep(20000);
}
Also used : ConfigurationContextFactory(org.apache.axis2.context.ConfigurationContextFactory) IntStream(java.util.stream.IntStream) StringUtils(org.apache.commons.lang.StringUtils) UserStoreConfigAdminServiceClient(org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient) GROUPS_ENDPOINT(org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.GROUPS_ENDPOINT) DataProvider(org.testng.annotations.DataProvider) HttpStatus(org.apache.http.HttpStatus) Test(org.testng.annotations.Test) ISTestUtils(org.wso2.identity.integration.test.utils.ISTestUtils) H2DataBaseManager(org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) Assert(org.testng.Assert) ServerConfigurationManager(org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) HttpHeaders(org.apache.http.HttpHeaders) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) AfterClass(org.testng.annotations.AfterClass) Factory(org.testng.annotations.Factory) PERMISSIONS_ENDPOINT(org.wso2.identity.integration.test.scim2.SCIM2BaseTestCase.PERMISSIONS_ENDPOINT) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) TestUserMode(org.wso2.carbon.automation.engine.context.TestUserMode) IOException(java.io.IOException) PropertyDTO(org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO) File(java.io.File) ExtractableResponse(io.restassured.response.ExtractableResponse) Response(io.restassured.response.Response) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) RestAssured(io.restassured.RestAssured) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) ExtractableResponse(io.restassured.response.ExtractableResponse) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) ArrayList(java.util.ArrayList) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) UserStoreConfigAdminServiceClient(org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 13 with UserManagementClient

use of org.wso2.identity.scenarios.commons.clients.UserManagementClient in project product-is by wso2.

the class SCIMServiceProviderGroupTestCase method initiate.

@BeforeClass(alwaysRun = true)
public void initiate() throws Exception {
    AutomationContext automationContext = new AutomationContext("IDENTITY", TestUserMode.SUPER_TENANT_ADMIN);
    userInfo = automationContext.getContextTenant().getContextUser();
    backendUrl = automationContext.getContextUrls().getBackEndUrl();
    serviceEndPoint = automationContext.getContextUrls().getServiceUrl();
    scim_url = backendUrl.substring(0, 22) + "/wso2/scim/";
    sessionCookie = new LoginLogoutClient(automationContext).login();
    userMgtClient = new UserManagementClient(backendUrl, sessionCookie);
    scimConfigAdminClient = new SCIMConfigAdminClient(backendUrl, sessionCookie);
    scimClient = new SCIMClient();
    // creating users for the test
    createUser();
}
Also used : AutomationContext(org.wso2.carbon.automation.engine.context.AutomationContext) LoginLogoutClient(org.wso2.carbon.integration.common.utils.LoginLogoutClient) SCIMConfigAdminClient(org.wso2.identity.integration.common.clients.scim.SCIMConfigAdminClient) SCIMClient(org.wso2.charon.core.client.SCIMClient) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 14 with UserManagementClient

use of org.wso2.identity.scenarios.commons.clients.UserManagementClient in project product-is by wso2.

the class SCIMServiceProviderUserTestCase method initiate.

@BeforeClass(alwaysRun = true)
public void initiate() throws Exception {
    AutomationContext automationContext = new AutomationContext("IDENTITY", TestUserMode.SUPER_TENANT_ADMIN);
    provider_userInfo = automationContext.getContextTenant().getContextUser();
    backendUrl = automationContext.getContextUrls().getBackEndUrl();
    scim_url = backendUrl.substring(0, 22) + "/wso2/scim/";
    serviceEndPoint = automationContext.getContextUrls().getServiceUrl();
    sessionCookie = new LoginLogoutClient(automationContext).login();
    userMgtClient = new UserManagementClient(backendUrl, sessionCookie);
}
Also used : AutomationContext(org.wso2.carbon.automation.engine.context.AutomationContext) LoginLogoutClient(org.wso2.carbon.integration.common.utils.LoginLogoutClient) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 15 with UserManagementClient

use of org.wso2.identity.scenarios.commons.clients.UserManagementClient in project product-is by wso2.

the class UserManagementServiceAbstractTest method testGetRolesOfCurrentUser.

@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.is", description = "Check get shared of current user", dependsOnMethods = "testChangePasswordOfUser")
public void testGetRolesOfCurrentUser() throws Exception {
    String session = authenticatorClient.login(newUserName, newUserPassword, isServer.getInstance().getHosts().get("default"));
    UserManagementClient client = new UserManagementClient(backendURL, session);
    Assert.assertTrue(nameExists(client.getRolesOfCurrentUser(), newUserRole), "Getting current user roles has failed.");
    authenticatorClient.logOut();
}
Also used : UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

UserManagementClient (org.wso2.identity.integration.common.clients.UserManagementClient)47 BeforeClass (org.testng.annotations.BeforeClass)30 AuthenticatorClient (org.wso2.carbon.integration.common.admin.client.AuthenticatorClient)19 File (java.io.File)8 Test (org.testng.annotations.Test)8 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)8 ServerConfigurationManager (org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager)7 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)6 UserProfileMgtServiceClient (org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient)6 RemoteUserStoreManagerServiceClient (org.wso2.identity.integration.common.clients.usermgt.remote.RemoteUserStoreManagerServiceClient)6 LoginLogoutClient (org.wso2.carbon.integration.common.utils.LoginLogoutClient)5 IdentityProviderMgtServiceClient (org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient)5 ApplicationManagementServiceClient (org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient)4 AfterClass (org.testng.annotations.AfterClass)3 AutomationContext (org.wso2.carbon.automation.engine.context.AutomationContext)3 UserManagementClient (org.wso2.carbon.integration.common.admin.client.UserManagementClient)3 UserInformationRecoveryServiceClient (org.wso2.identity.integration.common.clients.mgt.UserInformationRecoveryServiceClient)3 UserStoreConfigAdminServiceClient (org.wso2.identity.integration.common.clients.user.store.config.UserStoreConfigAdminServiceClient)3 UserManagementClient (org.wso2.identity.scenarios.commons.clients.UserManagementClient)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2