use of org.apache.ranger.entity.XXAsset in project ranger by apache.
the class TestRangerBizUtil method testGetMObject.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetMObject() {
BaseDao baseDao = Mockito.mock(BaseDao.class);
Mockito.when(daoManager.getDaoForClassType(RangerCommonEnums.CLASS_TYPE_USER_PROFILE)).thenReturn(baseDao);
Mockito.when(baseDao.getById(id)).thenReturn(new XXAsset());
XXDBBase mObjChk = rangerBizUtil.getMObject(RangerCommonEnums.CLASS_TYPE_USER_PROFILE, id);
Assert.assertNotNull(mObjChk);
}
use of org.apache.ranger.entity.XXAsset in project ranger by apache.
the class TestRangerBizUtil method testGetDisplayName_MoreThanMaxLen.
@Test
public void testGetDisplayName_MoreThanMaxLen() {
XXAsset obj = new XXAsset();
String name = resourceName;
for (int i = 0; i < 16; i++) {
name = name + "_" + name + "1";
}
obj.setDescription(name);
String displayNameChk = rangerBizUtil.getDisplayName(obj);
Assert.assertEquals(displayNameChk.length(), 150);
}
use of org.apache.ranger.entity.XXAsset in project ranger by apache.
the class PatchMigration_J10002 method migrateServicesToNewSchema.
public void migrateServicesToNewSchema() throws Exception {
logger.info("==> MigrationPatch.migrateServicesToNewSchema()");
try {
List<XXAsset> repoList = daoMgr.getXXAsset().getAll();
if (repoList.isEmpty()) {
return;
}
if (!repoList.isEmpty()) {
EmbeddedServiceDefsUtil.instance().init(svcDBStore);
}
svcDBStore.setPopulateExistingBaseFields(true);
for (XXAsset xAsset : repoList) {
if (xAsset.getActiveStatus() == AppConstants.STATUS_DELETED) {
continue;
}
RangerService existing = svcDBStore.getServiceByName(xAsset.getName());
if (existing != null) {
logger.info("Repository/Service already exists. Ignoring migration of repo: " + xAsset.getName());
continue;
}
RangerService service = new RangerService();
service = mapXAssetToService(service, xAsset);
service = svcDBStore.createService(service);
serviceCounter++;
logger.info("New Service created. ServiceName: " + service.getName());
}
svcDBStore.setPopulateExistingBaseFields(false);
} catch (Exception e) {
throw new Exception("Error while migrating data to new Plugin Schema.", e);
}
logger.info("<== MigrationPatch.migrateServicesToNewSchema()");
}
use of org.apache.ranger.entity.XXAsset in project ranger by apache.
the class PatchMigration_J10002 method migratePoliciesToNewSchema.
public void migratePoliciesToNewSchema() throws Exception {
logger.info("==> MigrationPatch.migratePoliciesToNewSchema()");
try {
List<XXResource> resList = daoMgr.getXXResource().getAll();
if (resList.isEmpty()) {
return;
}
svcDBStore.setPopulateExistingBaseFields(true);
for (XXResource xRes : resList) {
if (xRes.getResourceStatus() == AppConstants.STATUS_DELETED) {
continue;
}
XXAsset xAsset = daoMgr.getXXAsset().getById(xRes.getAssetId());
if (xAsset == null) {
logger.error("No Repository found for policyName: " + xRes.getPolicyName());
continue;
}
RangerService service = svcDBStore.getServiceByName(xAsset.getName());
if (service == null) {
logger.error("No Service found for policy. Ignoring migration of such policy, policyName: " + xRes.getPolicyName());
continue;
}
XXPolicy existing = daoMgr.getXXPolicy().findByNameAndServiceId(xRes.getPolicyName(), service.getId());
if (existing != null) {
logger.info("Policy already exists. Ignoring migration of policy: " + existing.getName());
continue;
}
RangerPolicy policy = new RangerPolicy();
policy = mapXResourceToPolicy(policy, xRes, service);
if (policy != null) {
policy = svcDBStore.createPolicy(policy);
policyCounter++;
logger.info("New policy created. policyName: " + policy.getName());
}
}
svcDBStore.setPopulateExistingBaseFields(false);
} catch (Exception e) {
throw new Exception("Error while migrating data to new Plugin Schema.", e);
}
logger.info("<== MigrationPatch.migratePoliciesToNewSchema()");
}
use of org.apache.ranger.entity.XXAsset in project ranger by apache.
the class PatchPasswordEncryption_J10001 method encryptLookupUserPassword.
private void encryptLookupUserPassword() {
List<XXAsset> xAssetList = xaDaoManager.getXXAsset().getAll();
String oldConfig = null;
String newConfig = null;
for (XXAsset xAsset : xAssetList) {
oldConfig = null;
newConfig = null;
oldConfig = xAsset.getConfig();
if (!stringUtil.isEmpty(oldConfig)) {
newConfig = xAssetService.getConfigWithEncryptedPassword(oldConfig, false);
xAsset.setConfig(newConfig);
xaDaoManager.getXXAsset().update(xAsset);
}
lineCount++;
logger.info("Lookup Password updated for Asset : " + xAsset.getName());
logger.info("oldconfig : " + oldConfig);
logger.info("newConfig : " + newConfig);
print(lineCount, "Total updated assets count : ");
}
}
Aggregations