Search in sources :

Example 21 with XXModuleDefDao

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);
}
Also used : VXModuleDef(org.apache.ranger.view.VXModuleDef) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) Test(org.junit.Test)

Example 22 with XXModuleDefDao

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);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with XXModuleDefDao

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);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) XXUserDao(org.apache.ranger.db.XXUserDao) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUser(org.apache.ranger.view.VXUser) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with XXModuleDefDao

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());
}
Also used : VXGroupUserList(org.apache.ranger.view.VXGroupUserList) ArrayList(java.util.ArrayList) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 25 with XXModuleDefDao

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);
}
Also used : VXLong(org.apache.ranger.view.VXLong) ArrayList(java.util.ArrayList) VXGroupUser(org.apache.ranger.view.VXGroupUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Aggregations

XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)42 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)37 VXString (org.apache.ranger.view.VXString)33 XXUserPermission (org.apache.ranger.entity.XXUserPermission)27 XXModuleDef (org.apache.ranger.entity.XXModuleDef)26 VXPortalUser (org.apache.ranger.view.VXPortalUser)26 VXUser (org.apache.ranger.view.VXUser)26 VXUserPermission (org.apache.ranger.view.VXUserPermission)22 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)21 XXPortalUser (org.apache.ranger.entity.XXPortalUser)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)18 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)18 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)16 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)15 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)15 Date (java.util.Date)14 UserSessionBase (org.apache.ranger.common.UserSessionBase)14 HashSet (java.util.HashSet)12 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)12