use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class ServiceREST method getServiceDef.
@GET
@Path("/definitions/{id}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_SERVICE_DEF + "\")")
public RangerServiceDef getServiceDef(@PathParam("id") Long id) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getServiceDef(" + id + ")");
}
RangerServiceDef ret = null;
RangerPerfTracer perf = null;
try {
if (RangerPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = RangerPerfTracer.getPerfTracer(PERF_LOG, "ServiceREST.getServiceDef(serviceDefId=" + id + ")");
}
XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById(id);
if (!bizUtil.hasAccess(xServiceDef, null)) {
throw restErrorUtil.createRESTException("User is not allowed to access service-def, id: " + xServiceDef.getId(), MessageEnums.OPER_NO_PERMISSION);
}
ret = svcStore.getServiceDef(id);
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getServiceDef(" + id + ") failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
} finally {
RangerPerfTracer.log(perf);
}
if (ret == null) {
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, "Not found", true);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getServiceDef(" + id + "): " + ret);
}
return ret;
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class RangerServiceDefService method getAllServiceDefs.
public List<RangerServiceDef> getAllServiceDefs() {
List<XXServiceDef> xxServiceDefList = daoMgr.getXXServiceDef().getAll();
List<RangerServiceDef> serviceDefList = new ArrayList<RangerServiceDef>();
for (XXServiceDef xxServiceDef : xxServiceDefList) {
RangerServiceDef serviceDef = populateViewBean(xxServiceDef);
serviceDefList.add(serviceDef);
}
return serviceDefList;
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class RangerServiceService method processFieldToCreateTrxLog.
@SuppressWarnings("unchecked")
private XXTrxLog processFieldToCreateTrxLog(Field field, String objectName, Field nameField, RangerService vObj, XXService mObj, int action) {
String actionString = "";
field.setAccessible(true);
String fieldName = field.getName();
XXTrxLog xTrxLog = new XXTrxLog();
try {
VTrxLogAttr vTrxLogAttr = trxLogAttrs.get(fieldName);
xTrxLog.setAttributeName(vTrxLogAttr.getAttribUserFriendlyName());
String value = null;
boolean isEnum = vTrxLogAttr.isEnum();
if (isEnum) {
} else if ("configs".equalsIgnoreCase(fieldName)) {
Map<String, String> configs = (field.get(vObj) != null) ? (Map<String, String>) field.get(vObj) : new HashMap<String, String>();
value = jsonUtil.readMapToString(configs);
} else {
value = "" + field.get(vObj);
}
if (action == OPERATION_CREATE_CONTEXT) {
if (stringUtil.isEmpty(value)) {
return null;
}
xTrxLog.setNewValue(value);
actionString = actionCreate;
} else if (action == OPERATION_DELETE_CONTEXT) {
xTrxLog.setPreviousValue(value);
actionString = actionDelete;
} else if (action == OPERATION_UPDATE_CONTEXT) {
actionString = actionUpdate;
String oldValue = null;
Field[] mFields = mObj.getClass().getSuperclass().getDeclaredFields();
for (Field mField : mFields) {
mField.setAccessible(true);
String mFieldName = mField.getName();
if (fieldName.equalsIgnoreCase(mFieldName)) {
if (isEnum) {
} else {
oldValue = mField.get(mObj) + "";
}
break;
}
}
if ("configs".equalsIgnoreCase(fieldName)) {
Map<String, String> vConfig = jsonUtil.jsonToMap(value);
RangerService oldService = this.populateViewBean(mObj);
Map<String, String> xConfig = oldService.getConfigs();
Map<String, String> newConfig = new HashMap<String, String>();
Map<String, String> oldConfig = new HashMap<String, String>();
for (Entry<String, String> entry : vConfig.entrySet()) {
String key = entry.getKey();
if (!xConfig.containsKey(key)) {
if (StringUtils.isNotEmpty(entry.getValue())) {
newConfig.put(key, entry.getValue());
}
} else if (!entry.getValue().equalsIgnoreCase(xConfig.get(key))) {
if ("password".equalsIgnoreCase(key) && entry.getValue().equalsIgnoreCase(hiddenPasswordString)) {
continue;
}
newConfig.put(key, entry.getValue());
oldConfig.put(key, xConfig.get(key));
}
}
for (Entry<String, String> entry : xConfig.entrySet()) {
String key = entry.getKey();
if (!vConfig.containsKey(key)) {
oldConfig.put(key, entry.getValue());
newConfig.put(key, null);
}
}
oldValue = jsonUtil.readMapToString(oldConfig);
value = jsonUtil.readMapToString(newConfig);
}
if ("tagService".equalsIgnoreCase(fieldName)) {
if (!StringUtils.isEmpty(oldValue) && !"null".equalsIgnoreCase(oldValue)) {
RangerService oldService = this.populateViewBean(mObj);
oldValue = oldService.getTagService();
}
}
if (oldValue == null || value.equalsIgnoreCase(oldValue)) {
return null;
}
xTrxLog.setPreviousValue(oldValue);
xTrxLog.setNewValue(value);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
LOG.error("Process field to create trx log failure.", e);
}
xTrxLog.setAction(actionString);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_SERVICE);
xTrxLog.setObjectId(vObj.getId());
xTrxLog.setObjectName(objectName);
XXServiceDef parentObj = daoMgr.getXXServiceDef().findByName(vObj.getType());
xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_SERVICE_DEF);
xTrxLog.setParentObjectId(parentObj.getId());
xTrxLog.setParentObjectName(parentObj.getName());
return xTrxLog;
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class RangerServiceServiceBase method mapEntityToViewBean.
@Override
protected V mapEntityToViewBean(V vObj, T xObj) {
XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xObj.getType());
XXService xTagService = xObj.getTagService() != null ? daoMgr.getXXService().getById(xObj.getTagService()) : null;
vObj.setType(xServiceDef.getName());
vObj.setGuid(xObj.getGuid());
vObj.setVersion(xObj.getVersion());
vObj.setName(xObj.getName());
vObj.setDescription(xObj.getDescription());
vObj.setTagService(xTagService != null ? xTagService.getName() : null);
XXServiceVersionInfo versionInfoObj = daoMgr.getXXServiceVersionInfo().findByServiceId(xObj.getId());
if (versionInfoObj != null) {
vObj.setPolicyVersion(versionInfoObj.getPolicyVersion());
vObj.setTagVersion(versionInfoObj.getTagVersion());
vObj.setPolicyUpdateTime(versionInfoObj.getPolicyUpdateTime());
vObj.setTagUpdateTime(versionInfoObj.getTagUpdateTime());
} else {
vObj.setPolicyVersion(xObj.getPolicyVersion());
vObj.setTagVersion(xObj.getTagVersion());
vObj.setPolicyUpdateTime(xObj.getPolicyUpdateTime());
vObj.setTagUpdateTime(xObj.getTagUpdateTime());
}
vObj.setIsEnabled(xObj.getIsenabled());
return vObj;
}
use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.
the class TestRangerServiceDefServiceBase method test7populateRangerAccessTypeDefToXX.
@Test
public void test7populateRangerAccessTypeDefToXX() {
RangerAccessTypeDef rangerAccessTypeDefObj = new RangerAccessTypeDef();
rangerAccessTypeDefObj.setLabel("Read");
rangerAccessTypeDefObj.setName("read");
rangerAccessTypeDefObj.setRbKeyLabel(null);
XXAccessTypeDef accessTypeDefObj = new XXAccessTypeDef();
accessTypeDefObj.setAddedByUserId(Id);
accessTypeDefObj.setCreateTime(new Date());
accessTypeDefObj.setDefid(Id);
accessTypeDefObj.setId(Id);
accessTypeDefObj.setLabel("Read");
accessTypeDefObj.setName("read");
accessTypeDefObj.setOrder(null);
accessTypeDefObj.setRbkeylabel(null);
accessTypeDefObj.setUpdatedByUserId(Id);
accessTypeDefObj.setUpdateTime(new Date());
XXServiceDef serviceDefObj = new XXServiceDef();
serviceDefObj.setAddedByUserId(Id);
serviceDefObj.setCreateTime(new Date());
serviceDefObj.setDescription("HDFS Repository");
serviceDefObj.setGuid("1427365526516_835_0");
serviceDefObj.setId(Id);
Mockito.when((XXAccessTypeDef) rangerAuditFields.populateAuditFields(accessTypeDefObj, serviceDefObj)).thenReturn(accessTypeDefObj);
XXAccessTypeDef dbAccessTypeDef = rangerServiceDefService.populateRangerAccessTypeDefToXX(rangerAccessTypeDefObj, accessTypeDefObj, serviceDefObj, 1);
Assert.assertNotNull(dbAccessTypeDef);
Assert.assertEquals(dbAccessTypeDef, accessTypeDefObj);
Assert.assertEquals(dbAccessTypeDef.getName(), accessTypeDefObj.getName());
Assert.assertEquals(dbAccessTypeDef.getLabel(), accessTypeDefObj.getLabel());
Assert.assertEquals(dbAccessTypeDef.getRbkeylabel(), accessTypeDefObj.getRbkeylabel());
Assert.assertEquals(dbAccessTypeDef.getDefid(), accessTypeDefObj.getDefid());
Assert.assertEquals(dbAccessTypeDef.getId(), accessTypeDefObj.getId());
Assert.assertEquals(dbAccessTypeDef.getCreateTime(), accessTypeDefObj.getCreateTime());
Assert.assertEquals(dbAccessTypeDef.getOrder(), accessTypeDefObj.getOrder());
}
Aggregations