Search in sources :

Example 1 with UsersGroupRoleAssignments

use of org.apache.ranger.ugsyncutil.model.UsersGroupRoleAssignments in project ranger by apache.

the class TestXUserMgr method test115UpdateUserRoleAssignments.

@Test
public void test115UpdateUserRoleAssignments() {
    destroySession();
    setup();
    UsersGroupRoleAssignments ugRoleAssignments = new UsersGroupRoleAssignments();
    Set<String> addUsers = new HashSet<String>();
    Set<String> delUsers = new HashSet<String>();
    addUsers.add("testuser");
    addUsers.add("testuser2");
    delUsers.add("testuser2");
    Map<String, String> userMap = new HashMap<String, String>();
    Map<String, String> groupMap = new HashMap<>();
    List<String> allUsers = new ArrayList<>(addUsers);
    userMap.put("testuser", "role1");
    userMap.put("testuser2", "role2");
    groupMap.put("testgroup1", "role1");
    groupMap.put("testgroup2", "role2");
    ugRoleAssignments.setUsers(allUsers);
    ugRoleAssignments.setGroupRoleAssignments(groupMap);
    ugRoleAssignments.setUserRoleAssignments(userMap);
    ugRoleAssignments.setWhiteListUserRoleAssignments(new HashMap<>());
    ugRoleAssignments.setWhiteListGroupRoleAssignments(new HashMap<>());
    VXUser vXUser = vxUser();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    vXUserList.add(vXUser);
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = new XXUserPermission();
    xUserPermissionObj.setAddedByUserId(userId);
    xUserPermissionObj.setCreateTime(new Date());
    xUserPermissionObj.setId(userId);
    xUserPermissionObj.setIsAllowed(1);
    xUserPermissionObj.setModuleId(1L);
    xUserPermissionObj.setUpdatedByUserId(userId);
    xUserPermissionObj.setUpdateTime(new Date());
    xUserPermissionObj.setUserId(userId);
    xUserPermissionsList.add(xUserPermissionObj);
    Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXModuleDef().getAll()).thenReturn(xXModuleDefs);
    xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
    allUsers.clear();
    allUsers.add("UnMappedUser");
    ugRoleAssignments.setUsers(allUsers);
    ugRoleAssignments.setGroupRoleAssignments(groupMap);
    ugRoleAssignments.setUserRoleAssignments(userMap);
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList1 = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj1 = xxUserPermission();
    xUserPermissionObj1.setModuleId(userPermission.getModuleId());
    xUserPermissionObj1.setUserId(userPermission.getUserId());
    xUserPermissionsList1.add(xUserPermissionObj1);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
    vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
    Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(vXPortalUser);
    xUserMgr.updateUserRoleAssignments(ugRoleAssignments);
}
Also used : HashMap(java.util.HashMap) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) UsersGroupRoleAssignments(org.apache.ranger.ugsyncutil.model.UsersGroupRoleAssignments) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 UserSessionBase (org.apache.ranger.common.UserSessionBase)1 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)1 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)1 XXModuleDef (org.apache.ranger.entity.XXModuleDef)1 XXPortalUser (org.apache.ranger.entity.XXPortalUser)1 XXUserPermission (org.apache.ranger.entity.XXUserPermission)1 UsersGroupRoleAssignments (org.apache.ranger.ugsyncutil.model.UsersGroupRoleAssignments)1 VXPortalUser (org.apache.ranger.view.VXPortalUser)1 VXString (org.apache.ranger.view.VXString)1 VXUser (org.apache.ranger.view.VXUser)1 VXUserPermission (org.apache.ranger.view.VXUserPermission)1 Test (org.junit.Test)1