Search in sources :

Example 16 with FlaggedName

use of org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName in project product-is by wso2.

the class UserManagementServiceAbstractTest method testListUserByClaim.

@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.is", description = "Check list users by claim value", dependsOnMethods = "testGetRolesOfCurrentUser")
public void testListUserByClaim() throws Exception {
    UserProfileMgtServiceClient userProfileMgtServiceClient = new UserProfileMgtServiceClient(backendURL, getSessionCookie());
    UserProfileDTO profile = userProfileMgtServiceClient.getUserProfile(newUserName, "default");
    UserFieldDTO[] fields = userProfileMgtServiceClient.getProfileFieldsForInternalStore().getFieldValues();
    String profileConfigs = profile.getProfileName();
    for (UserFieldDTO field : fields) {
        if (field.getDisplayName().equalsIgnoreCase("Last Name")) {
            field.setFieldValue(newUserName + "LastName");
            continue;
        }
        if (field.getRequired()) {
            if (field.getDisplayName().equalsIgnoreCase("Email")) {
                field.setFieldValue(newUserName + "@wso2.com");
            } else {
                field.setFieldValue(newUserName);
            }
            continue;
        }
        if (field.getFieldValue() == null) {
            field.setFieldValue("");
        }
    }
    // creating a new profile with updated values
    UserProfileDTO newProfile = new UserProfileDTO();
    newProfile.setProfileName(profile.getProfileName());
    newProfile.setFieldValues(fields);
    newProfile.setProfileConifuration(profileConfigs);
    userProfileMgtServiceClient.setUserProfile(newUserName, newProfile);
    ClaimValue claimValue = new ClaimValue();
    claimValue.setClaimURI("http://wso2.org/claims/lastname");
    claimValue.setValue(newUserName + "LastName");
    FlaggedName[] allNames = userMgtClient.listUserByClaim(claimValue, newUserName, 10);
    Assert.assertTrue(nameExists(allNames, newUserName), "List user with claim value has failed");
}
Also used : UserProfileMgtServiceClient(org.wso2.identity.integration.common.clients.UserProfileMgtServiceClient) ClaimValue(org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue) UserFieldDTO(org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO) UserProfileDTO(org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO) FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) SetEnvironment(org.wso2.carbon.automation.engine.annotations.SetEnvironment) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 17 with FlaggedName

use of org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName in project product-is by wso2.

the class UserMgtServiceAbstractTestCase method testUpdateUsersOfRole.

public void testUpdateUsersOfRole() throws Exception {
    String[] userList = new String[] { "user1", "user2" };
    FlaggedName[] userFlagList = new FlaggedName[userList.length];
    for (int i = 0; i < userFlagList.length; i++) {
        FlaggedName flaggedName = new FlaggedName();
        flaggedName.setItemName(userList[i]);
        flaggedName.setSelected(true);
        userFlagList[i] = flaggedName;
    }
    userMgtClient.updateUserListOfRole("umRole1", userList, null);
    Assert.assertTrue(nameExists(userMgtClient.getUsersOfRole("umRole1", "user1", 0), "user1"), "Adding user1 to role has failed");
    Assert.assertTrue(nameExists(userMgtClient.getUsersOfRole("umRole1", "user2", 0), "user2"), "Adding user2 to role has failed");
    // Calling with same user list should delete the users.
    for (int i = 0; i < userFlagList.length; i++) {
        userFlagList[i].setSelected(false);
    }
    userMgtClient.updateUsersOfRole("umRole1", userFlagList);
    Assert.assertFalse(nameExists(userMgtClient.getUsersOfRole("umRole1", "user1", 0), "user1"), "Deleting user1 from role has failed");
    Assert.assertFalse(nameExists(userMgtClient.getUsersOfRole("umRole1", "user2", 0), "user2"), "Deleting user2 from role has failed");
}
Also used : FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)

Example 18 with FlaggedName

use of org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName in project product-is by wso2.

the class UserMgtTestCase method testUpdateUsersOfRole.

@Test(groups = "wso2.is", description = "Check update users of role")
public void testUpdateUsersOfRole() throws Exception {
    String[] userList = new String[] { "user1", "user2" };
    FlaggedName[] userFlagList = new FlaggedName[userList.length];
    for (int i = 0; i < userFlagList.length; i++) {
        FlaggedName flaggedName = new FlaggedName();
        flaggedName.setItemName(userList[i]);
        flaggedName.setSelected(true);
        userFlagList[i] = flaggedName;
    }
    userMgtClient.updateUsersOfRole("umRole1", userFlagList);
    Assert.assertTrue(nameExists(userMgtClient.getUsersOfRole("umRole1", "user1", 0), "user1"), "Adding user1 to role has failed");
    Assert.assertTrue(nameExists(userMgtClient.getUsersOfRole("umRole1", "user2", 0), "user2"), "Adding user2 to role has failed");
    // Calling with same user list should delete the users.
    for (int i = 0; i < userFlagList.length; i++) {
        userFlagList[i].setSelected(false);
    }
    userMgtClient.updateUsersOfRole("umRole1", userFlagList);
    Assert.assertFalse(nameExists(userMgtClient.getUsersOfRole("umRole1", "user1", 0), "user1"), "Deleting user1 from role has failed");
    Assert.assertFalse(nameExists(userMgtClient.getUsersOfRole("umRole1", "user2", 0), "user2"), "Deleting user2 from role has failed");
}
Also used : FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 19 with FlaggedName

use of org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName in project product-is by wso2.

the class UserMgtTestCase method testUpdateRolesOfUser.

@Test(groups = "wso2.is", description = "Check update roles of user")
public void testUpdateRolesOfUser() throws Exception {
    List<String> newRoleList = new ArrayList<String>();
    FlaggedName[] currentRoleList = userMgtClient.getRolesOfUser("user3", null, 0);
    if (currentRoleList != null) {
        for (FlaggedName role : currentRoleList) {
            if (role.getSelected()) {
                newRoleList.add(role.getItemName());
            }
        }
    }
    if (!newRoleList.contains("umRole1")) {
        newRoleList.add("umRole1");
    }
    userMgtClient.updateRolesOfUser("user3", newRoleList.toArray(new String[newRoleList.size()]));
    Assert.assertTrue(nameExists(userMgtClient.getRolesOfUser("user3", "umRole1", 10), "umRole1"), "Adding umRole1 to user has failed");
    newRoleList.remove("umRole1");
    userMgtClient.updateRolesOfUser("user3", newRoleList.toArray(new String[newRoleList.size()]));
    Assert.assertFalse(nameExists(userMgtClient.getUsersOfRole("user3", "umRole1", 10), "umRole1"), "Deleting umRole1 from user has failed");
}
Also used : ArrayList(java.util.ArrayList) FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 20 with FlaggedName

use of org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName in project product-is by wso2.

the class UserManagementClient method userNameExists.

public boolean userNameExists(String roleName, String userName) throws RemoteException, UserAdminUserAdminException {
    FlaggedName[] users;
    users = userAdminStub.getUsersOfRole(roleName, "*", LIMIT);
    for (FlaggedName user : users) {
        if (user.getItemName().equals(userName)) {
            log.info("User name " + userName + " already exists");
            return true;
        }
    }
    return false;
}
Also used : FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)

Aggregations

FlaggedName (org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)31 ArrayList (java.util.ArrayList)14 FlaggedName (org.wso2.carbon.user.mgt.common.FlaggedName)13 Test (org.testng.annotations.Test)12 UserAdminException (org.wso2.carbon.user.mgt.common.UserAdminException)10 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)9 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)8 HashMap (java.util.HashMap)7 RegistryException (org.wso2.carbon.registry.api.RegistryException)7 UserStoreException (org.wso2.carbon.user.core.UserStoreException)7 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)7 JDBCUserStoreManager (org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager)7 ClaimValue (org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue)7 SetEnvironment (org.wso2.carbon.automation.engine.annotations.SetEnvironment)4 Mockito.anyString (org.mockito.Mockito.anyString)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 BeforeTest (org.testng.annotations.BeforeTest)3 AuthorizationManager (org.wso2.carbon.user.api.AuthorizationManager)3 UserAdminUserAdminException (org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)3 Field (java.lang.reflect.Field)2