use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test24GetXUserByUserName.
@Test
public void test24GetXUserByUserName() {
VXUser vxUser = vxUser();
String userName = "test";
Mockito.when(xUserService.getXUserByUserName(userName)).thenReturn(vxUser);
XXModuleDefDao xxModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xxModuleDefDao);
VXUser dbVXUser = xUserMgr.getXUserByUserName(userName);
Assert.assertNotNull(dbVXUser);
userId = dbVXUser.getId();
Assert.assertEquals(userId, dbVXUser.getId());
Assert.assertEquals(dbVXUser.getName(), vxUser.getName());
Assert.assertEquals(dbVXUser.getOwner(), vxUser.getOwner());
Mockito.verify(xUserService, Mockito.atLeast(2)).getXUserByUserName(userName);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test44getGroupsForUser.
/*@Test
public void test43checkPermissionRoleByGivenUrls() {
XXModuleDefDao value = Mockito.mock(XXModuleDefDao.class);
XXPortalUserRoleDao xPortalUserRoleDao = Mockito
.mock(XXPortalUserRoleDao.class);
List<String> lsvalue = new ArrayList<String>();
List<XXPortalUserRole> xPortalUserRolesList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole xPortalUserRole = new XXPortalUserRole();
xPortalUserRole.setAddedByUserId(userId);
xPortalUserRole.setCreateTime(new Date());
xPortalUserRole.setId(userId);
xPortalUserRole.setStatus(0);
xPortalUserRole.setUpdatedByUserId(userId);
xPortalUserRole.setUserId(userId);
xPortalUserRole.setUserRole("admin");
xPortalUserRolesList.add(xPortalUserRole);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(value);
Mockito.when(value.findModuleURLOfPemittedModules(null)).thenReturn(
lsvalue);
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(
xPortalUserRoleDao);
Mockito.when(xPortalUserRoleDao.findByUserId(null)).thenReturn(
xPortalUserRolesList);
String enteredURL = "";
String method = "";
xUserMgr.checkPermissionRoleByGivenUrls(enteredURL, method);
Mockito.verify(daoManager).getXXModuleDef();
Mockito.verify(value).findModuleURLOfPemittedModules(null);
Mockito.verify(daoManager).getXXPortalUserRole();
Mockito.verify(xPortalUserRoleDao).findByUserId(null);
}*/
@Test
public void test44getGroupsForUser() {
VXUser vxUser = vxUser();
String userName = "test";
Mockito.when(xUserService.getXUserByUserName(userName)).thenReturn(vxUser);
XXModuleDefDao modDef = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(modDef);
List<String> lstModule = new ArrayList<String>();
lstModule.add(RangerConstants.MODULE_USER_GROUPS);
Mockito.when(modDef.findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong())).thenReturn(lstModule);
Set<String> list = xUserMgr.getGroupsForUser(userName);
Assert.assertNotNull(list);
Mockito.verify(xUserService, Mockito.atLeast(2)).getXUserByUserName(userName);
// Mockito.verify(daoManager).getXXModuleDef();
Mockito.verify(modDef).findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong());
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test11CreateXUser.
@Test
public void test11CreateXUser() {
setup();
VXUser vxUser = vxUser();
Collection<String> userRoleList = new ArrayList<String>();
userRoleList.add("test");
vxUser.setUserRoleList(userRoleList);
ArrayList<String> userRoleListVXPortaUser = new ArrayList<String>();
VXPortalUser vXPortalUser = new VXPortalUser();
vXPortalUser.setUserRoleList(userRoleListVXPortaUser);
Mockito.when(xUserService.createResource(vxUser)).thenReturn(vxUser);
XXModuleDefDao value = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(value);
Mockito.when(userMgr.createDefaultAccountUser((VXPortalUser) Mockito.any())).thenReturn(vXPortalUser);
VXUser dbUser = xUserMgr.createXUser(vxUser);
Assert.assertNotNull(dbUser);
userId = dbUser.getId();
Assert.assertEquals(userId, dbUser.getId());
Assert.assertEquals(dbUser.getDescription(), vxUser.getDescription());
Assert.assertEquals(dbUser.getName(), vxUser.getName());
Assert.assertEquals(dbUser.getUserRoleList(), vxUser.getUserRoleList());
Assert.assertEquals(dbUser.getGroupNameList(), vxUser.getGroupNameList());
Mockito.verify(xUserService).createResource(vxUser);
Mockito.when(xUserService.readResourceWithOutLogin(userId)).thenReturn(vxUser);
VXUser dbvxUser = xUserMgr.getXUser(userId);
Mockito.verify(userMgr).createDefaultAccountUser((VXPortalUser) Mockito.any());
Mockito.verify(daoManager).getXXModuleDef();
Assert.assertNotNull(dbvxUser);
Assert.assertEquals(userId, dbvxUser.getId());
Assert.assertEquals(dbvxUser.getDescription(), vxUser.getDescription());
Assert.assertEquals(dbvxUser.getName(), vxUser.getName());
Assert.assertEquals(dbvxUser.getUserRoleList(), vxUser.getUserRoleList());
Assert.assertEquals(dbvxUser.getGroupNameList(), vxUser.getGroupNameList());
Mockito.verify(xUserService).readResourceWithOutLogin(userId);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestUserMgr method test33setUserRoles.
@Test
public void test33setUserRoles() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
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());
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(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);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
groupPermList.add(groupPermission);
XXModuleDef xModuleDef = new XXModuleDef();
xModuleDef.setUpdatedByUserId(userId);
xModuleDef.setAddedByUserId(userId);
xModuleDef.setCreateTime(new Date());
xModuleDef.setId(userId);
xModuleDef.setModule("Policy manager");
xModuleDef.setUpdateTime(new Date());
xModuleDef.setUrl("/policy manager");
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(userId)).thenReturn(user);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
userMgr.checkAccess(userId);
userMgr.setUserRoles(userId, vStringRolesList);
Mockito.verify(daoManager).getXXUserPermission();
Mockito.verify(daoManager).getXXGroupPermission();
Mockito.verify(xGroupPermissionService).populateViewBean(xGroupPermissionObj);
Mockito.verify(xUserPermissionService).populateViewBean(xUserPermissionObj);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestUserMgr method test23setUserRoles.
@Test
public void test23setUserRoles() {
setup();
XXPortalUserRoleDao xPortalUserRoleDao = Mockito.mock(XXPortalUserRoleDao.class);
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXGroupPermissionDao xGroupPermissionDao = Mockito.mock(XXGroupPermissionDao.class);
XXModuleDefDao xModuleDefDao = Mockito.mock(XXModuleDefDao.class);
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());
List<VXString> vStringRolesList = new ArrayList<VXString>();
VXString vXStringObj = new VXString();
vXStringObj.setValue("ROLE_USER");
vStringRolesList.add(vXStringObj);
List<XXPortalUserRole> xPortalUserRoleList = new ArrayList<XXPortalUserRole>();
XXPortalUserRole XXPortalUserRole = new XXPortalUserRole();
XXPortalUserRole.setId(userId);
XXPortalUserRole.setUserId(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);
List<VXGroupPermission> groupPermList = new ArrayList<VXGroupPermission>();
VXGroupPermission groupPermission = new VXGroupPermission();
groupPermission.setId(1L);
groupPermission.setIsAllowed(1);
groupPermission.setModuleId(1L);
groupPermission.setGroupId(userId);
groupPermission.setGroupName("xyz");
groupPermission.setOwner("admin");
groupPermList.add(groupPermission);
XXModuleDef xModuleDef = new XXModuleDef();
xModuleDef.setUpdatedByUserId(userId);
xModuleDef.setAddedByUserId(userId);
xModuleDef.setCreateTime(new Date());
xModuleDef.setId(userId);
xModuleDef.setModule("Policy manager");
xModuleDef.setUpdateTime(new Date());
xModuleDef.setUrl("/policy manager");
VXUserPermission userPermission = new VXUserPermission();
userPermission.setId(1L);
userPermission.setIsAllowed(1);
userPermission.setModuleId(1L);
userPermission.setUserId(userId);
userPermission.setUserName("xyz");
userPermission.setOwner("admin");
Mockito.when(daoManager.getXXPortalUserRole()).thenReturn(xPortalUserRoleDao);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.getById(userId)).thenReturn(user);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
Mockito.when(xUserPermissionDao.findByUserPermissionIdAndIsAllowed(userProfile.getId())).thenReturn(xUserPermissionsList);
Mockito.when(daoManager.getXXGroupPermission()).thenReturn(xGroupPermissionDao);
Mockito.when(xGroupPermissionDao.findbyVXPortalUserId(userProfile.getId())).thenReturn(xGroupPermissionList);
Mockito.when(xGroupPermissionService.populateViewBean(xGroupPermissionObj)).thenReturn(groupPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xModuleDefDao);
Mockito.when(xModuleDefDao.findByModuleId(Mockito.anyLong())).thenReturn(xModuleDef);
Mockito.doNothing().when(rangerBizUtil).blockAuditorRoleUser();
userMgr.checkAccess(userId);
userMgr.setUserRoles(userId, vStringRolesList);
Mockito.verify(daoManager).getXXUserPermission();
Mockito.verify(daoManager).getXXGroupPermission();
Mockito.verify(xGroupPermissionService).populateViewBean(xGroupPermissionObj);
Mockito.verify(xUserPermissionService).populateViewBean(xUserPermissionObj);
}
Aggregations