Search in sources :

Example 61 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserMgr method test22getUserProfileByLoginId.

@Test
public void test22getUserProfileByLoginId() {
    setup();
    XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setFirstName(userProfile.getFirstName());
    user.setLastName(userProfile.getLastName());
    user.setLoginId(userProfile.getLoginId());
    user.setPassword(userProfile.getPassword());
    user.setUserSource(userProfile.getUserSource());
    user.setPublicScreenName(userProfile.getPublicScreenName());
    user.setId(userProfile.getId());
    VXPortalUser dbVXPortalUser = userMgr.getUserProfileByLoginId();
    Mockito.when(xPortalUserDao.findByLoginId(Mockito.anyString())).thenReturn(user);
    XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
    List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userId);
    XXPortalUserRole.setUserId(userId);
    XXPortalUserRole.setUserRole("ROLE_USER");
    xPortalUserRoleList.add(XXPortalUserRole);
    Mockito.when(xPortalUserRoleDao.findByParentId(Mockito.anyLong())).thenReturn(xPortalUserRoleList);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
    Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
    Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
    Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
    dbVXPortalUser = userMgr.getUserProfileByLoginId(user.getLoginId());
    Assert.assertNotNull(dbVXPortalUser);
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXGroupPermissionDao(org.apache.ranger.db.XXGroupPermissionDao) ArrayList(java.util.ArrayList) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 62 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserMgr method setupUser.

public void setupUser() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile().getId());
    user.setLoginId(userProfile().getLoginId());
    currentUserSession.setXXPortalUser(user);
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 63 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestUserMgr method test34updateRoleForExternalUsers.

@Test
public void test34updateRoleForExternalUsers() {
    setupRangerUserSyncUser();
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Collection<String> existingRoleList = new ArrayList<String>();
    existingRoleList.add(RangerConstants.ROLE_USER);
    Collection<String> reqRoleList = new ArrayList<String>();
    reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    VXPortalUser userProfile = userProfile();
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile.getId());
    user.setLoginId(userProfile.getLoginId());
    user.setEmailAddress(userProfile.getEmailAddress());
    user.setLoginId(userProfile.getLoginId());
    String encryptedPwd = userMgr.encrypt(userProfile.getLoginId(), userProfile.getPassword());
    user.setPassword(encryptedPwd);
    XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
    XXPortalUserRole.setId(userProfile.getId());
    XXPortalUserRole.setUserRole(RangerConstants.ROLE_USER);
    List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
    list.add(XXPortalUserRole);
    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(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
    Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
    Mockito.when(userDao.getById(userProfile.getId())).thenReturn(user);
    Mockito.when(stringUtil.validateEmail(Mockito.anyString())).thenReturn(true);
    Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(xUserPermissionDao.findByUserPermissionId(userProfile.getId())).thenReturn(xUserPermissionsList);
    VXPortalUser dbVXPortalUser = userMgr.updateRoleForExternalUsers(reqRoleList, existingRoleList, userProfile);
    Assert.assertNotNull(dbVXPortalUser);
    Assert.assertEquals(userId, dbVXPortalUser.getId());
    Assert.assertEquals(userProfile.getFirstName(), dbVXPortalUser.getFirstName());
    Assert.assertEquals(userProfile.getLastName(), dbVXPortalUser.getLastName());
    Assert.assertEquals(userProfile.getLoginId(), dbVXPortalUser.getLoginId());
    Assert.assertEquals(userProfile.getEmailAddress(), dbVXPortalUser.getEmailAddress());
}
Also used : XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Test(org.junit.Test)

Example 64 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestXUserMgr method setupUser.

public void setupUser() {
    RangerSecurityContext context = new RangerSecurityContext();
    context.setUserSession(new UserSessionBase());
    RangerContextHolder.setSecurityContext(context);
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    XXPortalUser user = new XXPortalUser();
    user.setId(userProfile().getId());
    user.setLoginId(userProfile().getLoginId());
    currentUserSession.setXXPortalUser(user);
    currentUserSession.setUserRoleList(getRoleList());
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) RangerSecurityContext(org.apache.ranger.security.context.RangerSecurityContext) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 65 with XXPortalUser

use of org.apache.ranger.entity.XXPortalUser in project ranger by apache.

the class TestXUserMgr method test23CreateVXUserGroupInfo.

@Test
public void test23CreateVXUserGroupInfo() {
    setup();
    VXUserGroupInfo vXUserGroupInfo = new VXUserGroupInfo();
    VXUser vXUser = vxUser();
    List<VXGroupUser> vXGroupUserList = new ArrayList<VXGroupUser>();
    List<VXGroup> vXGroupList = new ArrayList<VXGroup>();
    final VXGroup vXGroup1 = vxGroup();
    vXGroup1.setName("users");
    vXGroup1.setDescription("users -added for unit testing");
    vXGroupList.add(vXGroup1);
    VXGroupUser vXGroupUser1 = vxGroupUser();
    vXGroupUser1.setName("users");
    vXGroupUserList.add(vXGroupUser1);
    final VXGroup vXGroup2 = vxGroup();
    vXGroup2.setName("user1");
    vXGroup2.setDescription("user1 -added for unit testing");
    vXGroupList.add(vXGroup2);
    VXGroupUser vXGroupUser2 = vxGroupUser();
    vXGroupUser2.setName("user1");
    vXGroupUserList.add(vXGroupUser2);
    vXUserGroupInfo.setXuserInfo(vXUser);
    vXUserGroupInfo.setXgroupInfo(vXGroupList);
    Mockito.when(xUserService.createXUserWithOutLogin(vXUser)).thenReturn(vXUser);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup1)).thenReturn(vXGroup1);
    Mockito.when(xGroupService.createXGroupWithOutLogin(vXGroup2)).thenReturn(vXGroup2);
    XXPortalUserDao portalUser = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(portalUser);
    XXPortalUser user = new XXPortalUser();
    user.setId(1L);
    user.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    Mockito.when(portalUser.findByLoginId(vXUser.getName())).thenReturn(user);
    XXPortalUserRoleDao userDao = Mockito.mock(XXPortalUserRoleDao.class);
    Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(userDao);
    List<String> existingRole = new ArrayList<String>();
    existingRole.add(RangerConstants.ROLE_USER);
    List<String> reqRoleList = new ArrayList<String>();
    reqRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    Mockito.when(userDao.findXPortalUserRolebyXPortalUserId(Mockito.anyLong())).thenReturn(reqRoleList);
    VXPortalUser vXPortalUser = userProfile();
    Mockito.when(userMgr.getUserProfileByLoginId(Mockito.anyString())).thenReturn(vXPortalUser);
    Mockito.when(userMgr.updateRoleForExternalUsers(Mockito.any(), Mockito.any(), (VXPortalUser) Mockito.any())).thenReturn(vXPortalUser);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add("ROLE_USER");
    vXPortalUser.setUserRoleList(userRoleList);
    VXUser vxUser = vxUser();
    XXUser xXUser = xxUser(vxUser);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    VXUserGroupInfo vxUserGroupTest = xUserMgr.createXUserGroupFromMap(vXUserGroupInfo);
    Assert.assertEquals(userLoginID, vxUserGroupTest.getXuserInfo().getName());
    List<VXGroup> result = vxUserGroupTest.getXgroupInfo();
    List<VXGroup> expected = new ArrayList<VXGroup>();
    expected.add(vXGroup1);
    expected.add(vXGroup2);
    Assert.assertTrue(result.containsAll(expected));
    Mockito.verify(portalUser).findByLoginId(vXUser.getName());
    Mockito.verify(userDao).findXPortalUserRolebyXPortalUserId(Mockito.anyLong());
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUserRoleDao(org.apache.ranger.db.XXPortalUserRoleDao) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXUserGroupInfo(org.apache.ranger.view.VXUserGroupInfo) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)192 Test (org.junit.Test)113 ArrayList (java.util.ArrayList)93 VXPortalUser (org.apache.ranger.view.VXPortalUser)86 VXString (org.apache.ranger.view.VXString)82 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)74 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)46 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)44 XXUserPermission (org.apache.ranger.entity.XXUserPermission)36 UserSessionBase (org.apache.ranger.common.UserSessionBase)34 VXUser (org.apache.ranger.view.VXUser)34 WebApplicationException (javax.ws.rs.WebApplicationException)33 Date (java.util.Date)30 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)29 XXUser (org.apache.ranger.entity.XXUser)27 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)25 XXModuleDef (org.apache.ranger.entity.XXModuleDef)25 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 VXUserPermission (org.apache.ranger.view.VXUserPermission)19