use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test31createXModuleDefPermission.
// Module permission
@Test
public void test31createXModuleDefPermission() {
VXModuleDef vXModuleDef = vXModuleDef();
Mockito.when(xModuleDefService.createResource(vXModuleDef)).thenReturn(vXModuleDef);
XXModuleDefDao obj = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(obj);
VXModuleDef dbMuduleDef = xUserMgr.createXModuleDefPermission(vXModuleDef);
Assert.assertNotNull(dbMuduleDef);
Assert.assertEquals(dbMuduleDef, vXModuleDef);
Assert.assertEquals(dbMuduleDef.getId(), vXModuleDef.getId());
Assert.assertEquals(dbMuduleDef.getOwner(), vXModuleDef.getOwner());
Assert.assertEquals(dbMuduleDef.getUpdatedBy(), vXModuleDef.getUpdatedBy());
Assert.assertEquals(dbMuduleDef.getUrl(), vXModuleDef.getUrl());
Assert.assertEquals(dbMuduleDef.getAddedById(), vXModuleDef.getAddedById());
Assert.assertEquals(dbMuduleDef.getCreateDate(), vXModuleDef.getCreateDate());
Assert.assertEquals(dbMuduleDef.getCreateTime(), vXModuleDef.getCreateTime());
Assert.assertEquals(dbMuduleDef.getUserPermList(), vXModuleDef.getUserPermList());
Assert.assertEquals(dbMuduleDef.getGroupPermList(), vXModuleDef.getGroupPermList());
Mockito.verify(xModuleDefService).createResource(vXModuleDef);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test51assignPermissionToUser.
@Test
public void test51assignPermissionToUser() {
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
VXPortalUser vXPortalUser = userProfile();
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(xXUserPermissionDao.findByModuleIdAndPortalUserId(vXPortalUser.getId(), xXModuleDefs.get(0).getId())).thenReturn(xUserPermissionObj);
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(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
userRoleList.clear();
userRoleList.add("ROLE_SYS_ADMIN");
vXPortalUser.setUserRoleList(userRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
userRoleList.clear();
userRoleList.add("ROLE_KEY_ADMIN");
vXPortalUser.setUserRoleList(userRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
userRoleList.clear();
userRoleList.add("ROLE_KEY_ADMIN_AUDITOR");
vXPortalUser.setUserRoleList(userRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
userRoleList.clear();
userRoleList.add("ROLE_ADMIN_AUDITOR");
vXPortalUser.setUserRoleList(userRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
Assert.assertNotNull(xXModuleDefs);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test109AssignPermissionToUser.
@Test
public void test109AssignPermissionToUser() {
destroySession();
setup();
VXPortalUser vXPortalUser = userProfile();
List<XXModuleDef> xXModuleDefs = xxModuleDefs();
XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
Mockito.when(daoManager.getXXModuleDef().getAll()).thenReturn(xXModuleDefs);
VXUserPermission userPermission = vxUserPermission();
List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
userPermList.add(userPermission);
List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
XXUserPermission xUserPermission = xxUserPermission();
xUserPermission.setModuleId(userPermission.getModuleId());
xUserPermission.setUserId(userPermission.getUserId());
xUserPermissionsList.add(xUserPermission);
XXUserPermissionDao xXUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
Mockito.when(daoManager.getXXUserPermission()).thenReturn(xXUserPermissionDao);
Mockito.when(xXUserPermissionDao.findByModuleIdAndPortalUserId(vXPortalUser.getId(), xXModuleDefs.get(0).getId())).thenReturn(xUserPermission);
VXUser vxUser = vxUser();
XXUser xXUser = xxUser(vxUser);
XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
Mockito.when(xxUserDao.findByPortalUserId(vXPortalUser.getId())).thenReturn(xXUser);
Mockito.when(xUserPermissionService.populateViewBean(xUserPermission)).thenReturn(userPermission);
Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
userSessions.add(userSession);
Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
Collection<String> existingRoleList = new ArrayList<String>();
existingRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
vXPortalUser.setUserRoleList(existingRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
existingRoleList.clear();
existingRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
vXPortalUser.setUserRoleList(existingRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
existingRoleList.clear();
existingRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
vXPortalUser.setUserRoleList(existingRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
existingRoleList.clear();
existingRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
vXPortalUser.setUserRoleList(existingRoleList);
xUserMgr.assignPermissionToUser(vXPortalUser, true);
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test36getGroupsForUser.
@Test
public void test36getGroupsForUser() {
setupUser();
VXUser vxUser = vxUser();
VXGroup vxGroup = vxGroup();
String userName = userLoginID;
Mockito.when(xUserService.getXUserByUserName(userName)).thenReturn(vxUser);
VXGroupUserList vxGroupUserList = vxGroupUserList();
Mockito.when(xGroupUserService.searchXGroupUsers((SearchCriteria) Mockito.any())).thenReturn(vxGroupUserList);
Mockito.when(xGroupService.readResource(userId)).thenReturn(vxGroup);
XXModuleDefDao modDef = Mockito.mock(XXModuleDefDao.class);
Mockito.when(daoManager.getXXModuleDef()).thenReturn(modDef);
List<String> lstModule = new ArrayList<String>();
lstModule.add(RangerConstants.MODULE_USER_GROUPS);
lstModule.add(RangerConstants.MODULE_RESOURCE_BASED_POLICIES);
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(modDef).findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong());
Mockito.when(xUserService.getXUserByUserName(userName)).thenReturn(null);
list = xUserMgr.getGroupsForUser(userName);
Assert.assertTrue(list.isEmpty());
Mockito.verify(xUserService, Mockito.atLeast(2)).getXUserByUserName(userName);
Mockito.verify(modDef).findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong());
Mockito.when(xUserService.getXUserByUserName(userName)).thenReturn(null);
list = xUserMgr.getGroupsForUser(userName);
Assert.assertTrue(list.isEmpty());
Mockito.verify(xUserService, Mockito.atLeast(2)).getXUserByUserName(userName);
Mockito.verify(modDef).findAccessibleModulesByUserId(Mockito.anyLong(), Mockito.anyLong());
}
use of org.apache.ranger.db.XXModuleDefDao in project ranger by apache.
the class TestXUserMgr method test01CreateXUser.
@Test
public void test01CreateXUser() {
setup();
VXUser vxUser = vxUser();
vxUser.setFirstName("user12");
vxUser.setLastName("test12");
Collection<Long> groupIdList = new ArrayList<Long>();
groupIdList.add(userId);
vxUser.setGroupIdList(groupIdList);
VXGroup vxGroup = vxGroup();
vxGroup.setName("user12Grp");
VXGroupUser vXGroupUser = new VXGroupUser();
vXGroupUser.setParentGroupId(userId);
vXGroupUser.setUserId(userId);
vXGroupUser.setName(vxGroup.getName());
Mockito.when(xGroupService.readResource(userId)).thenReturn(vxGroup);
Mockito.when(xGroupUserService.createResource((VXGroupUser) Mockito.any())).thenReturn(vXGroupUser);
ArrayList<String> userRoleListVXPortaUser = getRoleList();
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);
Mockito.when(stringUtil.validateEmail("test@test.com")).thenReturn(true);
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 loggedInUser = vxUser();
List<String> loggedInUserRole = new ArrayList<String>();
loggedInUserRole.add(RangerConstants.ROLE_ADMIN);
loggedInUser.setId(8L);
loggedInUser.setName("testuser");
loggedInUser.setUserRoleList(loggedInUserRole);
Mockito.when(xUserService.getXUserByUserName("admin")).thenReturn(loggedInUser);
VXUser dbvxUser = xUserMgr.getXUser(userId);
Mockito.verify(userMgr).createDefaultAccountUser((VXPortalUser) Mockito.any());
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.getGroupIdList(), vxUser.getGroupIdList());
Assert.assertEquals(dbvxUser.getGroupNameList(), vxUser.getGroupNameList());
Mockito.verify(xUserService).readResourceWithOutLogin(userId);
}
Aggregations