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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations