Search in sources :

Example 6 with XXGlobalStateDao

use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.

the class TestSecurityZoneDBStore method test4deleteSecurityZoneById.

@Test
public void test4deleteSecurityZoneById() throws Exception {
    XXSecurityZone xxSecurityZone = new XXSecurityZone();
    xxSecurityZone.setId(2L);
    RangerSecurityZone securityZone = new RangerSecurityZone();
    securityZone.setId(2L);
    securityZone.setName("sz1");
    XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(securityZoneService.read(securityZone.getId())).thenReturn(securityZone);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
    Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
    Mockito.when(securityZoneRefUpdater.cleanupRefTables(securityZone)).thenReturn(true);
    Mockito.when(securityZoneService.delete(securityZone)).thenReturn(true);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
    securityZoneDBStore.deleteSecurityZoneById(securityZone.getId());
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Example 7 with XXGlobalStateDao

use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.

the class TestXUserMgr method test120GetUserStoreVersion.

@Test
public void test120GetUserStoreVersion() throws Exception {
    destroySession();
    setup();
    Long lastKnownUserStoreVersion = Long.valueOf(1);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    Mockito.when(xxGlobalStateDao.getAppDataVersion(RANGER_USER_GROUP_GLOBAL_STATE_NAME)).thenReturn(lastKnownUserStoreVersion);
    Long userStoreVersion = xUserMgr.getUserStoreVersion();
    Assert.assertNotNull(userStoreVersion);
    Assert.assertEquals(lastKnownUserStoreVersion, userStoreVersion);
}
Also used : VXLong(org.apache.ranger.view.VXLong) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) Test(org.junit.Test)

Example 8 with XXGlobalStateDao

use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.

the class TestXUserMgr method test112CreateOrUpdateXUsers.

@Test
public void test112CreateOrUpdateXUsers() {
    destroySession();
    setup();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    VXUser vXUser = vxUser();
    vXUser.setFirstName("testuser");
    vXUser.setLastName("testuser");
    vXUser.setPassword("TestPassword@123");
    vXUser.setEmailAddress("");
    vXUser.setUserSource(RangerCommonEnums.USER_APP);
    Collection<String> userRoleList = new ArrayList<String>();
    userRoleList.add(RangerConstants.ROLE_USER);
    userRoleList.add(RangerConstants.ROLE_SYS_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN);
    userRoleList.add(RangerConstants.ROLE_KEY_ADMIN_AUDITOR);
    userRoleList.add(RangerConstants.ROLE_ADMIN_AUDITOR);
    vXUser.setUserRoleList(userRoleList);
    vXUserList.add(vXUser);
    VXUserList users = new VXUserList(vXUserList);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setFirstName("testuser");
    vXPortalUser.setLastName("testuser");
    vXPortalUser.setPassword("TestPassword@123");
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    List<XXUserPermission> xUserPermissionsList = new ArrayList<XXUserPermission>();
    XXUserPermission xUserPermissionObj = xxUserPermission();
    VXUserPermission userPermission = vxUserPermission();
    List<VXUserPermission> userPermList = new ArrayList<VXUserPermission>();
    userPermList.add(userPermission);
    xUserPermissionObj.setModuleId(userPermission.getModuleId());
    xUserPermissionObj.setUserId(userPermission.getUserId());
    xUserPermissionsList.add(xUserPermissionObj);
    UserSessionBase userSession = Mockito.mock(UserSessionBase.class);
    Set<UserSessionBase> userSessions = new HashSet<UserSessionBase>();
    userSessions.add(userSession);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
    Mockito.when(xUserPermissionService.createResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    Mockito.when(xUserService.createResource((VXUser) Mockito.any())).thenReturn(vXUser);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    xUserMgr.createOrUpdateXUsers(users);
    vXUser.setPassword("*****");
    xUserMgr.createOrUpdateXUsers(users);
}
Also used : XXUserDao(org.apache.ranger.db.XXUserDao) XXUserPermissionDao(org.apache.ranger.db.XXUserPermissionDao) ArrayList(java.util.ArrayList) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) XXModuleDefDao(org.apache.ranger.db.XXModuleDefDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserList(org.apache.ranger.view.VXUserList) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with XXGlobalStateDao

use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.

the class TestXUserMgr method test114CreateOrUpdateXGroups.

@Test
public void test114CreateOrUpdateXGroups() {
    destroySession();
    setup();
    VXGroup vXGroup = vxGroup();
    VXGroupList vXGroupListSort = new VXGroupList();
    List<VXGroup> vXGroups = new ArrayList<VXGroup>();
    vXGroups.add(vXGroup);
    VXGroup vXGroup1 = vxGroup();
    vXGroup1.setName("null");
    vXGroups.add(vXGroup1);
    vXGroupListSort.setVXGroups(vXGroups);
    VXUser vXUser = vxUser();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    vXUserList.add(vXUser);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    VXPortalUser vXPortalUser = userProfile();
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    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);
    xUserMgr.createOrUpdateXGroups(vXGroupListSort);
}
Also used : VXGroupList(org.apache.ranger.view.VXGroupList) ArrayList(java.util.ArrayList) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) VXString(org.apache.ranger.view.VXString) VXUser(org.apache.ranger.view.VXUser) XXUserPermission(org.apache.ranger.entity.XXUserPermission) Date(java.util.Date) XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXGroup(org.apache.ranger.view.VXGroup) Test(org.junit.Test)

Example 10 with XXGlobalStateDao

use of org.apache.ranger.db.XXGlobalStateDao in project ranger by apache.

the class TestSecurityZoneDBStore method test3deleteSecurityZoneByName.

@Test
public void test3deleteSecurityZoneByName() throws Exception {
    XXSecurityZone xxSecurityZone = new XXSecurityZone();
    xxSecurityZone.setId(2L);
    RangerSecurityZone securityZone = new RangerSecurityZone();
    securityZone.setId(2L);
    securityZone.setName("sz1");
    XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class);
    XXGlobalStateDao xXGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao);
    Mockito.when(xXSecurityZoneDao.findByZoneName(securityZone.getName())).thenReturn(xxSecurityZone);
    Mockito.when(securityZoneService.read(securityZone.getId())).thenReturn(securityZone);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
    Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
    Mockito.when(securityZoneRefUpdater.cleanupRefTables(securityZone)).thenReturn(true);
    Mockito.when(securityZoneService.delete(securityZone)).thenReturn(true);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
    securityZoneDBStore.deleteSecurityZoneByName(securityZone.getName());
    Assert.assertNotNull(xxSecurityZone);
}
Also used : RangerSecurityZone(org.apache.ranger.plugin.model.RangerSecurityZone) XXSecurityZoneDao(org.apache.ranger.db.XXSecurityZoneDao) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXSecurityZone(org.apache.ranger.entity.XXSecurityZone) Test(org.junit.Test)

Aggregations

XXGlobalStateDao (org.apache.ranger.db.XXGlobalStateDao)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 XXPortalUser (org.apache.ranger.entity.XXPortalUser)4 XXSecurityZone (org.apache.ranger.entity.XXSecurityZone)4 XXTrxLog (org.apache.ranger.entity.XXTrxLog)4 XXUserPermission (org.apache.ranger.entity.XXUserPermission)4 RangerSecurityZone (org.apache.ranger.plugin.model.RangerSecurityZone)4 VXPortalUser (org.apache.ranger.view.VXPortalUser)4 VXString (org.apache.ranger.view.VXString)4 VXUser (org.apache.ranger.view.VXUser)4 Date (java.util.Date)3 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)3 XXSecurityZoneDao (org.apache.ranger.db.XXSecurityZoneDao)3 XXUserDao (org.apache.ranger.db.XXUserDao)3 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)3 XXModuleDef (org.apache.ranger.entity.XXModuleDef)3 VXUserList (org.apache.ranger.view.VXUserList)3 HashSet (java.util.HashSet)2 UserSessionBase (org.apache.ranger.common.UserSessionBase)2