Search in sources :

Example 1 with XXGlobalStateDao

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

the class TestXUserMgr method test113CreateOrUpdateXUsers.

@Test
public void test113CreateOrUpdateXUsers() {
    destroySession();
    setup();
    VXUser vXUser = vxUser();
    vXUser.setFirstName("null");
    vXUser.setLastName("null");
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    vXUserList.add(vXUser);
    VXUserList users = new VXUserList(vXUserList);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    XXUser xXUser = xxUser(vXUser);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setFirstName("null");
    vXPortalUser.setLastName("null");
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    List<XXModuleDef> xXModuleDefs = new ArrayList<XXModuleDef>();
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(xUserService.updateResource(vXUser)).thenReturn(vXUser);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    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);
    Mockito.when(xUserPermissionDao.findByUserPermissionId(vXPortalUser.getId())).thenReturn(xUserPermissionsList);
    xUserMgr.createOrUpdateXUsers(users);
    vXUserList.clear();
    vXUser.setUserSource(RangerCommonEnums.USER_APP);
    vXUser.setFirstName("testuser");
    vXUser.setLastName("testuser");
    vXUser.setPassword("TestPassword@123");
    vXUserList.add(vXUser);
    users = new VXUserList(vXUserList);
    vXPortalUser = userProfile();
    vXPortalUser.setUserSource(RangerCommonEnums.USER_APP);
    vXPortalUser.setFirstName("testuser");
    vXPortalUser.setLastName("testuser");
    vXPortalUser.setPassword("TestPassword@123");
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(vXPortalUser);
    Mockito.when(userMgr.updateUserWithPass((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    xUserMgr.createOrUpdateXUsers(users);
    vXUser.setPassword("*****");
    xUserMgr.createOrUpdateXUsers(users);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) 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) Date(java.util.Date) XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXModuleDef(org.apache.ranger.entity.XXModuleDef) VXPortalUser(org.apache.ranger.view.VXPortalUser) Test(org.junit.Test)

Example 2 with XXGlobalStateDao

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

the class TestXUserMgr method test111CreateOrUpdateXUsers.

@Test
public void test111CreateOrUpdateXUsers() {
    destroySession();
    setup();
    List<VXUser> vXUserList = new ArrayList<VXUser>();
    VXUser vXUser = vxUser();
    VXUser vXUser1 = vxUser();
    vXUser.setFirstName("null");
    vXUser.setLastName("null");
    vXUser.setEmailAddress("");
    vXUser1.setName("null");
    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);
    vXUser1.setUserRoleList(userRoleList);
    vXUserList.add(vXUser);
    vXUserList.add(vXUser1);
    VXUserList users = new VXUserList(vXUserList);
    XXUserDao xxUserDao = Mockito.mock(XXUserDao.class);
    XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
    XXModuleDefDao xXModuleDefDao = Mockito.mock(XXModuleDefDao.class);
    XXGlobalStateDao xxGlobalStateDao = Mockito.mock(XXGlobalStateDao.class);
    XXUser xXUser = xxUser(vXUser);
    VXPortalUser vXPortalUser = userProfile();
    vXPortalUser.setFirstName("null");
    vXPortalUser.setLastName("null");
    XXPortalUser xXPortalUser = xxPortalUser(vXPortalUser);
    xXPortalUser.setUserSource(RangerCommonEnums.USER_EXTERNAL);
    List<String> lstRole = new ArrayList<String>();
    lstRole.add(RangerConstants.ROLE_SYS_ADMIN);
    List<XXModuleDef> xXModuleDefs = xxModuleDefs();
    vXPortalUser.setUserRoleList(lstRole);
    Mockito.when(userMgr.getUserProfileByLoginId(vXUser.getName())).thenReturn(null);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(xxUserDao.findByUserName(vXUser.getName())).thenReturn(xXUser);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
    Mockito.when(daoManager.getXXModuleDef()).thenReturn(xXModuleDefDao);
    Mockito.when(daoManager.getXXGlobalState()).thenReturn(xxGlobalStateDao);
    Mockito.when(xXModuleDefDao.getAll()).thenReturn(xXModuleDefs);
    Mockito.when(userMgr.mapVXPortalUserToXXPortalUser((VXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    XXPortalUserDao xXPortalUserDao = Mockito.mock(XXPortalUserDao.class);
    Mockito.when(daoManager.getXXPortalUser()).thenReturn(xXPortalUserDao);
    Mockito.when(daoManager.getXXPortalUser().create((XXPortalUser) Mockito.any())).thenReturn(xXPortalUser);
    XXUser xUser = xxUser(vXUser);
    Mockito.when(daoManager.getXXUser()).thenReturn(xxUserDao);
    Mockito.when(daoManager.getXXUser().findByUserName(vXUser.getName())).thenReturn(xUser);
    Mockito.when(xUserService.populateViewBean(xUser)).thenReturn(vXUser);
    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);
    XXUserPermissionDao xUserPermissionDao = Mockito.mock(XXUserPermissionDao.class);
    Mockito.when(daoManager.getXXUserPermission()).thenReturn(xUserPermissionDao);
    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(sessionMgr.getActiveUserSessionsForPortalUserId(userId)).thenReturn(userSessions);
    xUserMgr.createOrUpdateXUsers(users);
    Mockito.when(xUserPermissionDao.findByModuleIdAndPortalUserId(null, null)).thenReturn(xUserPermissionObj);
    Mockito.when(xUserPermissionService.populateViewBean(xUserPermissionObj)).thenReturn(userPermission);
    Mockito.when(xUserPermissionService.updateResource((VXUserPermission) Mockito.any())).thenReturn(userPermission);
    xUserMgr.createOrUpdateXUsers(users);
}
Also used : XXUser(org.apache.ranger.entity.XXUser) 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) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with XXGlobalStateDao

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

the class TestXUserMgr method test119GetRangerUserStore.

@Test
public void test119GetRangerUserStore() 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);
    xUserMgr.getRangerUserStore(lastKnownUserStoreVersion);
}
Also used : VXLong(org.apache.ranger.view.VXLong) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) Test(org.junit.Test)

Example 4 with XXGlobalStateDao

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

the class ServiceDBStore method persistVersionChange.

public static void persistVersionChange(ServiceVersionUpdater serviceVersionUpdater) {
    RangerDaoManager daoMgr = serviceVersionUpdater.daoManager;
    Long id = serviceVersionUpdater.serviceId;
    VERSION_TYPE versionType = serviceVersionUpdater.versionType;
    XXServiceVersionInfoDao serviceVersionInfoDao = daoMgr.getXXServiceVersionInfo();
    XXServiceVersionInfo serviceVersionInfoDbObj = serviceVersionInfoDao.findByServiceId(id);
    XXService service = daoMgr.getXXService().getById(id);
    Long nextVersion = 1L;
    Date now = new Date();
    if (serviceVersionInfoDbObj != null) {
        if (versionType == VERSION_TYPE.POLICY_VERSION) {
            nextVersion = getNextVersion(serviceVersionInfoDbObj.getPolicyVersion());
            serviceVersionInfoDbObj.setPolicyVersion(nextVersion);
            serviceVersionInfoDbObj.setPolicyUpdateTime(now);
        } else if (versionType == VERSION_TYPE.TAG_VERSION) {
            nextVersion = getNextVersion(serviceVersionInfoDbObj.getTagVersion());
            serviceVersionInfoDbObj.setTagVersion(nextVersion);
            serviceVersionInfoDbObj.setTagUpdateTime(now);
        } else if (versionType == VERSION_TYPE.ROLE_VERSION) {
            // get the LatestRoleVersion from the GlobalTable and update ServiceInfo for a service
            XXGlobalStateDao xxGlobalStateDao = daoMgr.getXXGlobalState();
            if (xxGlobalStateDao != null) {
                Long roleVersion = xxGlobalStateDao.getAppDataVersion("RangerRole");
                if (roleVersion != null) {
                    nextVersion = roleVersion;
                } else {
                    LOG.error("No Global state for 'RoleVersion'. Cannot execute this object:[" + serviceVersionUpdater + "]");
                }
                serviceVersionInfoDbObj.setRoleVersion(nextVersion);
                serviceVersionInfoDbObj.setRoleUpdateTime(now);
            } else {
                LOG.error("No Global state DAO. Cannot execute this object:[" + serviceVersionUpdater + "]");
                return;
            }
        } else {
            LOG.error("Unknown VERSION_TYPE:" + versionType + ". Cannot execute this object:[" + serviceVersionUpdater + "]");
            return;
        }
        serviceVersionUpdater.version = nextVersion;
        serviceVersionInfoDao.update(serviceVersionInfoDbObj);
    } else {
        if (service != null) {
            serviceVersionInfoDbObj = new XXServiceVersionInfo();
            serviceVersionInfoDbObj.setServiceId(service.getId());
            serviceVersionInfoDbObj.setPolicyVersion(nextVersion);
            serviceVersionInfoDbObj.setPolicyUpdateTime(new Date());
            serviceVersionInfoDbObj.setTagVersion(nextVersion);
            serviceVersionInfoDbObj.setTagUpdateTime(new Date());
            serviceVersionInfoDbObj.setRoleVersion(nextVersion);
            serviceVersionInfoDbObj.setRoleUpdateTime(new Date());
            serviceVersionUpdater.version = nextVersion;
            serviceVersionInfoDao.create(serviceVersionInfoDbObj);
        }
    }
    if (service != null) {
        if (versionType == VERSION_TYPE.POLICY_VERSION) {
            persistChangeLog(service, versionType, serviceVersionInfoDbObj.getPolicyVersion(), serviceVersionUpdater);
        } else if (versionType == VERSION_TYPE.TAG_VERSION) {
            persistChangeLog(service, versionType, serviceVersionInfoDbObj.getTagVersion(), serviceVersionUpdater);
        }
    }
}
Also used : RangerDaoManager(org.apache.ranger.db.RangerDaoManager) XXGlobalStateDao(org.apache.ranger.db.XXGlobalStateDao) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) Date(java.util.Date) XXServiceVersionInfoDao(org.apache.ranger.db.XXServiceVersionInfoDao)

Example 5 with XXGlobalStateDao

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

the class TestSecurityZoneDBStore method test1createSecurityZone.

@Test
public void test1createSecurityZone() throws Exception {
    XXSecurityZone xxSecurityZone = null;
    RangerSecurityZone securityZone = new RangerSecurityZone();
    RangerSecurityZone createdSecurityZone = new RangerSecurityZone();
    createdSecurityZone.setId(2L);
    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(daoManager.getXXGlobalState()).thenReturn(xXGlobalStateDao);
    Mockito.doNothing().when(xXGlobalStateDao).onGlobalStateChange(RANGER_GLOBAL_STATE_NAME);
    Mockito.when(securityZoneService.create(securityZone)).thenReturn(createdSecurityZone);
    Mockito.doNothing().when(securityZoneRefUpdater).createNewZoneMappingForRefTable(createdSecurityZone);
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Mockito.doNothing().when(bizUtil).createTrxLog(trxLogList);
    RangerSecurityZone expectedSecurityZone = securityZoneDBStore.createSecurityZone(securityZone);
    Assert.assertNull(xxSecurityZone);
    Assert.assertEquals(createdSecurityZone.getId(), expectedSecurityZone.getId());
    Mockito.verify(daoManager).getXXSecurityZoneDao();
    Mockito.verify(daoManager).getXXGlobalState();
    Mockito.verify(securityZoneService).create(securityZone);
}
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