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);
}
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);
}
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);
}
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);
}
}
}
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);
}
Aggregations