use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class UserMgr method mapXXPortalUserToVXPortalUser.
/**
* @param user
* @return
*/
public VXPortalUser mapXXPortalUserToVXPortalUser(XXPortalUser user, Collection<String> userRoleList) {
if (user == null) {
return null;
}
UserSessionBase sess = ContextUtil.getCurrentUserSession();
if (sess == null) {
return null;
}
VXPortalUser userProfile = new VXPortalUser();
gjUserToUserProfile(user, userProfile);
if (sess.isUserAdmin() || sess.isKeyAdmin() || sess.getXXPortalUser().getId().equals(user.getId())) {
if (userRoleList == null) {
userRoleList = new ArrayList<String>();
List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
for (XXPortalUserRole userRole : gjUserRoleList) {
userRoleList.add(userRole.getUserRole());
}
}
userProfile.setUserRoleList(userRoleList);
}
userProfile.setUserSource(user.getUserSource());
return userProfile;
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestRangerBizUtil method testGeneratePublicName_withPortalUser.
@Test
public void testGeneratePublicName_withPortalUser() {
VXPortalUser vXPortalUser = new VXPortalUser();
vXPortalUser.setFirstName("Test");
vXPortalUser.setLastName(null);
String publicNameChk = rangerBizUtil.generatePublicName(vXPortalUser, null);
Assert.assertNull(publicNameChk);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test15searchUsers.
@Test
public void test15searchUsers() {
Query query = Mockito.mock(Query.class);
EntityManager entityManager = Mockito.mock(EntityManager.class);
SearchCriteria searchCriteria = new SearchCriteria();
searchCriteria.setDistinct(true);
searchCriteria.setGetChildren(true);
searchCriteria.setGetCount(true);
searchCriteria.setMaxRows(12);
searchCriteria.setOwnerId(userId);
searchCriteria.setStartIndex(1);
searchCriteria.setSortBy("userId");
searchCriteria.setSortType("asc");
Long count = 1l;
Mockito.when(daoManager.getEntityManager()).thenReturn(entityManager);
Mockito.when(entityManager.createQuery(Mockito.anyString())).thenReturn(query);
Mockito.when(query.getSingleResult()).thenReturn(count);
VXPortalUserList dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
searchCriteria.setSortBy("loginId");
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
searchCriteria.setSortBy("emailAddress");
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
searchCriteria.setSortBy("firstName");
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
searchCriteria.setSortBy("lastName");
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
searchCriteria.setSortBy("source");
searchCriteria.setSortType("");
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
searchCriteria.setSortBy("");
searchCriteria.setSortType("desc");
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
VXPortalUser userProfile = userProfile();
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
user.setEmailAddress(userProfile.getEmailAddress());
user.setLoginId(userProfile.getLoginId());
List<XXPortalUser> resultList = new ArrayList<XXPortalUser>();
resultList.add(user);
Mockito.when(query.getResultList()).thenReturn(resultList);
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
count = 0l;
Mockito.when(query.getSingleResult()).thenReturn(count);
dbVXPortalUserList = userMgr.searchUsers(searchCriteria);
Assert.assertNotNull(dbVXPortalUserList);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test21getUserProfile.
@Test
public void test21getUserProfile() {
setup();
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUser xPortalUser = Mockito.mock(XXPortalUser.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserRole("ROLE_USER");
xPortalUserRoleList.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);
List<XXGroupPermission> xGroupPermissionList = new ArrayList<XXGroupPermission>();
XXGroupPermission xGroupPermissionObj = new XXGroupPermission();
xGroupPermissionObj.setAddedByUserId(userId);
xGroupPermissionObj.setCreateTime(new Date());
xGroupPermissionObj.setId(userId);
xGroupPermissionObj.setIsAllowed(1);
xGroupPermissionObj.setModuleId(1L);
xGroupPermissionObj.setUpdatedByUserId(userId);
xGroupPermissionObj.setUpdateTime(new Date());
xGroupPermissionObj.setGroupId(userId);
xGroupPermissionList.add(xGroupPermissionObj);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(null);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
VXPortalUser dbVXPortalUser = userMgr.getUserProfile(userId);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(xPortalUser);
dbVXPortalUser = userMgr.getUserProfile(userId);
Assert.assertNotNull(dbVXPortalUser);
}
use of org.apache.ranger.view.VXPortalUser in project ranger by apache.
the class TestUserMgr method test02CreateUser.
@Test
public void test02CreateUser() {
setup();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXPortalUserRoleDao roleDao = Mockito.mock(XXPortalUserRoleDao.class);
VXPortalUser userProfile = userProfile();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("ROLE_USER");
userProfile.setUserRoleList(userRoleList);
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());
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(user.getId());
XXPortalUserRole.setUserRole("ROLE_USER");
List<XXPortalUserRole> list = new ArrayList<XXPortalUserRole>();
list.add(XXPortalUserRole);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.create((XXPortalUser) Mockito.any())).thenReturn(user);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(roleDao);
Mockito.when(roleDao.findByUserId(userId)).thenReturn(list);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
XXPortalUser dbxxPortalUser = userMgr.createUser(userProfile, 1);
userId = dbxxPortalUser.getId();
Assert.assertNotNull(dbxxPortalUser);
Assert.assertEquals(userId, dbxxPortalUser.getId());
Assert.assertEquals(userProfile.getFirstName(), dbxxPortalUser.getFirstName());
Assert.assertEquals(userProfile.getFirstName(), dbxxPortalUser.getFirstName());
Assert.assertEquals(userProfile.getLastName(), dbxxPortalUser.getLastName());
Assert.assertEquals(userProfile.getLoginId(), dbxxPortalUser.getLoginId());
Assert.assertEquals(userProfile.getEmailAddress(), dbxxPortalUser.getEmailAddress());
Assert.assertEquals(userProfile.getPassword(), dbxxPortalUser.getPassword());
Mockito.verify(daoManager, Mockito.atLeast(1)).getXXPortalUser();
Mockito.verify(daoManager).getXXPortalUserRole();
}
Aggregations