Search in sources :

Example 26 with FlaggedName

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);
}
Also used : FlaggedName(org.wso2.carbon.user.mgt.common.FlaggedName) ArrayList(java.util.ArrayList) AuthorizationManager(org.wso2.carbon.user.api.AuthorizationManager) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException)

Example 27 with FlaggedName

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];
}
Also used : ClaimValue(org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue) FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) ClaimValue(org.wso2.carbon.user.mgt.stub.types.carbon.ClaimValue) UserAdminUserAdminException(org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)

Example 28 with FlaggedName

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);
}
Also used : Field(java.lang.reflect.Field) HybridRoleManager(org.wso2.carbon.user.core.hybrid.HybridRoleManager) FlaggedName(org.wso2.carbon.user.mgt.common.FlaggedName) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with FlaggedName

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;
}
Also used : FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName)

Example 30 with FlaggedName

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());
        }
    }
}
Also used : FlaggedName(org.wso2.carbon.user.mgt.stub.types.carbon.FlaggedName) ArrayList(java.util.ArrayList)

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