Search in sources :

Example 56 with XXServiceDef

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;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) WebApplicationException(javax.ws.rs.WebApplicationException) RangerPerfTracer(org.apache.ranger.plugin.util.RangerPerfTracer) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 57 with XXServiceDef

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;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) ArrayList(java.util.ArrayList)

Example 58 with XXServiceDef

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;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) HashMap(java.util.HashMap) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) Field(java.lang.reflect.Field) RangerService(org.apache.ranger.plugin.model.RangerService) HashMap(java.util.HashMap) XXServiceConfigMap(org.apache.ranger.entity.XXServiceConfigMap) Map(java.util.Map)

Example 59 with XXServiceDef

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;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo)

Example 60 with XXServiceDef

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());
}
Also used : RangerAccessTypeDef(org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXAccessTypeDef(org.apache.ranger.entity.XXAccessTypeDef) Date(java.util.Date) Test(org.junit.Test)

Aggregations

XXServiceDef (org.apache.ranger.entity.XXServiceDef)79 Test (org.junit.Test)38 XXService (org.apache.ranger.entity.XXService)34 RangerService (org.apache.ranger.plugin.model.RangerService)26 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)25 VXString (org.apache.ranger.view.VXString)22 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)21 WebApplicationException (javax.ws.rs.WebApplicationException)20 ArrayList (java.util.ArrayList)14 Date (java.util.Date)14 XXServiceDao (org.apache.ranger.db.XXServiceDao)13 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)11 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)11 RangerPerfTracer (org.apache.ranger.plugin.util.RangerPerfTracer)9 RangerAccessTypeDef (org.apache.ranger.plugin.model.RangerServiceDef.RangerAccessTypeDef)8 RangerPolicyResource (org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 IOException (java.io.IOException)6 XXPortalUser (org.apache.ranger.entity.XXPortalUser)6