use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserAdmin method listAllUsersWithPermission.
/**
* Get list of users which have given permission
*
* @param filter filter to check
* @param permission permission to check
* @param limit
* @return
* @throws UserAdminException
*/
public FlaggedName[] listAllUsersWithPermission(String filter, String permission, int limit) throws UserAdminException {
List<FlaggedName> permittedUsers = new ArrayList<>();
try {
org.wso2.carbon.user.api.UserRealm realm = UserMgtDSComponent.getRealmService().getTenantUserRealm(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
AuthorizationManager authorizationManager = realm.getAuthorizationManager();
FlaggedName[] users = getUserAdminProxy().listAllUsers(filter, limit);
for (int i = 0; i < users.length - 1; i++) {
if (authorizationManager.isUserAuthorized(users[i].getItemName(), permission, UserMgtConstants.EXECUTE_ACTION)) {
permittedUsers.add(users[i]);
}
}
permittedUsers.add(users[users.length - 1]);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new UserAdminException("Error while filtering authorized users.", e);
}
FlaggedName[] permittedUsersArray = new FlaggedName[permittedUsers.size()];
return permittedUsers.toArray(permittedUsersArray);
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserAdminClient method listUserByClaim.
public FlaggedName[] listUserByClaim(ClaimValue claimValue, String filter, int limit) throws AxisFault {
try {
org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue abcdClaimValue = new org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue();
abcdClaimValue.setClaimURI(claimValue.getClaimURI());
abcdClaimValue.setValue(claimValue.getValue());
return stub.listUserByClaim(abcdClaimValue, filter, limit);
} catch (Exception e) {
handleException(e);
}
return new FlaggedName[0];
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project carbon-identity-framework by wso2.
the class UserRealmProxyTest method testGetRolesOfUser.
@Test(dataProvider = "userListCount")
public void testGetRolesOfUser(int listCount, int assertCount) throws Exception {
Mockito.when(realm.getUserStoreManager()).thenReturn(userStoreManagerWithAb);
Mockito.when(((AbstractUserStoreManager) userStoreManagerWithAb).getRoleListOfUser("admin2")).thenReturn(new String[] { "PRIMARY/role1", "PRIMARY/role2" });
Object cc = userStoreManagerWithAb;
HybridRoleManager hybridRoleManager = mock(HybridRoleManager.class);
Field f1 = cc.getClass().getSuperclass().getDeclaredField("hybridRoleManager");
f1.setAccessible(true);
f1.set(cc, hybridRoleManager);
String[] test = { "PRIMARY/role3", "PRIMARY/role4" };
String[] test2 = { "role3", "role4" };
Mockito.when(((AbstractUserStoreManager) userStoreManagerWithAb).getRoleNames("role", listCount, true, true, true)).thenReturn(null);
Mockito.when(hybridRoleManager.getHybridRoles("role")).thenReturn(test);
FlaggedName[] flaggedNames = userRealmProxy.getRolesOfUser("admin2", "role", listCount);
Assert.assertEquals(flaggedNames.length, assertCount);
}
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;
}
use of org.wso2.carbon.user.mgt.common.FlaggedName in project product-is by wso2.
the class UserManagementClient method updateUserListOfRole.
public void updateUserListOfRole(String roleName, String[] addingUsers, String[] deletingUsers) throws UserAdminUserAdminException, RemoteException {
List<FlaggedName> updatedUserList = new ArrayList<FlaggedName>();
if (addingUsers != null) {
for (String addUser : addingUsers) {
FlaggedName fName = new FlaggedName();
fName.setItemName(addUser);
fName.setSelected(true);
updatedUserList.add(fName);
}
}
// add deleted users to the list
if (deletingUsers != null) {
for (String deletedUser : deletingUsers) {
FlaggedName fName = new FlaggedName();
fName.setItemName(deletedUser);
fName.setSelected(false);
updatedUserList.add(fName);
}
}
// call userAdminStub to update user list of role
userAdminStub.updateUsersOfRole(roleName, updatedUserList.toArray(new FlaggedName[updatedUserList.size()]));
// if delete users in retrieved list, fail
if (deletingUsers != null) {
for (String deletedUser : deletingUsers) {
FlaggedName[] verifyingList;
verifyingList = userAdminStub.getUsersOfRole(roleName, deletedUser, LIMIT);
assert (!verifyingList[0].getSelected());
}
}
if (addingUsers != null) {
// if all added users are not in list fail
for (String addingUser : addingUsers) {
FlaggedName[] verifyingList = userAdminStub.getUsersOfRole(roleName, addingUser, LIMIT);
assert (verifyingList[0].getSelected());
}
}
}
Aggregations