use of org.wso2.carbon.user.mgt.common.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");
}
use of org.wso2.carbon.user.mgt.common.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");
}
use of org.wso2.carbon.user.mgt.common.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");
}
use of org.wso2.carbon.user.mgt.common.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");
}
use of org.wso2.carbon.user.mgt.common.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;
}
Aggregations