Search in sources :

Example 76 with XXServiceDef

use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.

the class TestServiceREST method test3deleteServiceDef.

@Test
public void test3deleteServiceDef() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    RangerServiceDef rangerServiceDef = rangerServiceDef();
    XXServiceDef xServiceDef = serviceDef();
    XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
    Mockito.when(validatorFactory.getServiceDefValidator(svcStore)).thenReturn(serviceDefValidator);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
    Mockito.when(xServiceDefDao.getById(Id)).thenReturn(xServiceDef);
    serviceREST.deleteServiceDef(rangerServiceDef.getId(), request);
    Mockito.verify(validatorFactory).getServiceDefValidator(svcStore);
    Mockito.verify(daoManager).getXXServiceDef();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) Test(org.junit.Test)

Example 77 with XXServiceDef

use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.

the class PatchForTagServiceDefUpdate_J10008 method updateTagServiceDef.

private void updateTagServiceDef() {
    RangerServiceDef embeddedTagServiceDef = null;
    RangerServiceDef dbTagServiceDef = null;
    List<RangerServiceDef.RangerPolicyConditionDef> embeddedTagPolicyConditionDefs = null;
    XXServiceDef xXServiceDefObj = null;
    try {
        embeddedTagServiceDef = EmbeddedServiceDefsUtil.instance().getEmbeddedServiceDef(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
        if (embeddedTagServiceDef != null) {
            embeddedTagPolicyConditionDefs = embeddedTagServiceDef.getPolicyConditions();
            if (embeddedTagPolicyConditionDefs == null) {
                logger.error("Policy Conditions are empyt in tag service def json");
                return;
            }
            if (checkScriptPolicyCondPresent(embeddedTagPolicyConditionDefs) == false) {
                logger.error(SCRIPT_POLICY_CONDITION_NAME + "policy condition not found!!");
                return;
            }
            xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
            if (xXServiceDefObj == null) {
                logger.error("Service def for " + SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME + " is not found!!");
                return;
            }
            Map<String, String> serviceDefOptionsPreUpdate = null;
            String jsonStrPreUpdate = null;
            jsonStrPreUpdate = xXServiceDefObj.getDefOptions();
            if (!StringUtils.isEmpty(jsonStrPreUpdate)) {
                serviceDefOptionsPreUpdate = jsonUtil.jsonToMap(jsonStrPreUpdate);
            }
            xXServiceDefObj = null;
            dbTagServiceDef = svcDBStore.getServiceDefByName(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
            if (dbTagServiceDef != null) {
                dbTagServiceDef.setPolicyConditions(embeddedTagPolicyConditionDefs);
                RangerServiceDefValidator validator = validatorFactory.getServiceDefValidator(svcStore);
                validator.validate(dbTagServiceDef, Action.UPDATE);
                svcStore.updateServiceDef(dbTagServiceDef);
                xXServiceDefObj = daoMgr.getXXServiceDef().findByName(SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME);
                if (xXServiceDefObj != null) {
                    String jsonStrPostUpdate = xXServiceDefObj.getDefOptions();
                    Map<String, String> serviceDefOptionsPostUpdate = null;
                    if (!StringUtils.isEmpty(jsonStrPostUpdate)) {
                        serviceDefOptionsPostUpdate = jsonUtil.jsonToMap(jsonStrPostUpdate);
                    }
                    if (serviceDefOptionsPostUpdate != null && serviceDefOptionsPostUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
                        if (serviceDefOptionsPreUpdate == null || !serviceDefOptionsPreUpdate.containsKey(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES)) {
                            String preUpdateValue = serviceDefOptionsPreUpdate == null ? null : serviceDefOptionsPreUpdate.get(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
                            if (preUpdateValue == null) {
                                serviceDefOptionsPostUpdate.remove(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES);
                            } else {
                                serviceDefOptionsPostUpdate.put(RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, preUpdateValue);
                            }
                            xXServiceDefObj.setDefOptions(mapToJsonString(serviceDefOptionsPostUpdate));
                            daoMgr.getXXServiceDef().update(xXServiceDefObj);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error("Error while updating " + SERVICEDBSTORE_SERVICEDEFBYNAME_TAG_NAME + "service-def", e);
    }
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerServiceDefValidator(org.apache.ranger.plugin.model.validation.RangerServiceDefValidator)

Example 78 with XXServiceDef

use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.

the class XTrxLogService method searchXTrxLogs.

@Override
public VXTrxLogList searchXTrxLogs(SearchCriteria searchCriteria) {
    EntityManager em = daoManager.getEntityManager();
    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<VXXTrxLog> selectCQ = criteriaBuilder.createQuery(VXXTrxLog.class);
    Root<VXXTrxLog> rootEntityType = selectCQ.from(VXXTrxLog.class);
    Predicate predicate = generatePredicate(searchCriteria, em, criteriaBuilder, rootEntityType);
    selectCQ.where(predicate);
    if ("asc".equalsIgnoreCase(searchCriteria.getSortType())) {
        selectCQ.orderBy(criteriaBuilder.asc(rootEntityType.get("createTime")));
    } else {
        selectCQ.orderBy(criteriaBuilder.desc(rootEntityType.get("createTime")));
    }
    int startIndex = searchCriteria.getStartIndex();
    int pageSize = searchCriteria.getMaxRows();
    List<VXXTrxLog> resultList = em.createQuery(selectCQ).setFirstResult(startIndex).setMaxResults(pageSize).getResultList();
    int maxRowSize = Integer.MAX_VALUE;
    int minRowSize = 0;
    XXServiceDef xxServiceDef = daoManager.getXXServiceDef().findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME);
    UserSessionBase session = ContextUtil.getCurrentUserSession();
    if (session != null && session.isKeyAdmin()) {
        resultList = em.createQuery(selectCQ).setFirstResult(minRowSize).setMaxResults(maxRowSize).getResultList();
    }
    if (session != null && session.isAuditKeyAdmin()) {
        resultList = em.createQuery(selectCQ).setFirstResult(minRowSize).setMaxResults(maxRowSize).getResultList();
    }
    List<VXTrxLog> trxLogList = new ArrayList<VXTrxLog>();
    for (VXXTrxLog xTrxLog : resultList) {
        VXTrxLog trxLog = mapCustomViewToViewObj(xTrxLog);
        if (trxLog.getUpdatedBy() != null) {
            XXPortalUser xXPortalUser = daoManager.getXXPortalUser().getById(Long.parseLong(trxLog.getUpdatedBy()));
            if (xXPortalUser != null) {
                trxLog.setOwner(xXPortalUser.getLoginId());
            }
        }
        trxLogList.add(trxLog);
    }
    List<VXTrxLog> keyAdminTrxLogList = new ArrayList<VXTrxLog>();
    if (session != null && xxServiceDef != null && (session.isKeyAdmin() || session.isAuditKeyAdmin())) {
        List<VXTrxLog> vXTrxLogs = new ArrayList<VXTrxLog>();
        for (VXTrxLog xTrxLog : trxLogList) {
            int parentObjectClassType = xTrxLog.getParentObjectClassType();
            Long parentObjectId = xTrxLog.getParentObjectId();
            if (parentObjectClassType == AppConstants.CLASS_TYPE_XA_SERVICE_DEF && parentObjectId.equals(xxServiceDef.getId())) {
                vXTrxLogs.add(xTrxLog);
            } else if (parentObjectClassType == AppConstants.CLASS_TYPE_XA_SERVICE && !(parentObjectId.equals(xxServiceDef.getId()))) {
                for (VXTrxLog vxTrxLog : trxLogList) {
                    if (parentObjectClassType == vxTrxLog.getObjectClassType() && parentObjectId.equals(vxTrxLog.getObjectId()) && vxTrxLog.getParentObjectId().equals(xxServiceDef.getId())) {
                        vXTrxLogs.add(xTrxLog);
                        break;
                    }
                }
            } else if (xTrxLog.getObjectClassType() == AppConstants.CLASS_TYPE_XA_USER || xTrxLog.getObjectClassType() == AppConstants.CLASS_TYPE_RANGER_POLICY || xTrxLog.getObjectClassType() == AppConstants.HIST_OBJ_STATUS_UPDATED) {
                XXPortalUser xxPortalUser = null;
                if (xTrxLog.getUpdatedBy() != null) {
                    xxPortalUser = daoManager.getXXPortalUser().getById(Long.parseLong(xTrxLog.getUpdatedBy()));
                }
                if (xxPortalUser != null && xxPortalUser.getId() != null) {
                    List<XXPortalUserRole> xxPortalUserRole = daoManager.getXXPortalUserRole().findByUserId(xxPortalUser.getId());
                    if (xxPortalUserRole != null && (xxPortalUserRole.get(0).getUserRole().equalsIgnoreCase("ROLE_KEY_ADMIN") || xxPortalUserRole.get(0).getUserRole().equalsIgnoreCase("ROLE_KEY_ADMIN_AUDITOR"))) {
                        vXTrxLogs.add(xTrxLog);
                    }
                }
            }
        }
        keyadminCount = (long) vXTrxLogs.size();
        if (vXTrxLogs != null && !vXTrxLogs.isEmpty()) {
            for (int k = startIndex; k <= pageSize; k++) {
                if (k < vXTrxLogs.size()) {
                    keyAdminTrxLogList.add(vXTrxLogs.get(k));
                }
            }
        }
    }
    VXTrxLogList vxTrxLogList = new VXTrxLogList();
    vxTrxLogList.setStartIndex(startIndex);
    vxTrxLogList.setPageSize(pageSize);
    if (session != null && (session.isKeyAdmin() || session.isAuditKeyAdmin())) {
        vxTrxLogList.setVXTrxLogs(keyAdminTrxLogList);
    } else {
        vxTrxLogList.setVXTrxLogs(trxLogList);
    }
    return vxTrxLogList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) UserSessionBase(org.apache.ranger.common.UserSessionBase) XXPortalUser(org.apache.ranger.entity.XXPortalUser) EntityManager(javax.persistence.EntityManager) VXTrxLog(org.apache.ranger.view.VXTrxLog) VXTrxLogList(org.apache.ranger.view.VXTrxLogList) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXXTrxLog(org.apache.ranger.entity.view.VXXTrxLog)

Example 79 with XXServiceDef

use of org.apache.ranger.entity.XXServiceDef in project ranger by apache.

the class SolrAccessAuditsService method populateViewBean.

/**
 * @param doc
 * @return
 */
private VXAccessAudit populateViewBean(SolrDocument doc) {
    VXAccessAudit accessAudit = new VXAccessAudit();
    Object value = null;
    if (logger.isDebugEnabled()) {
        logger.debug("doc=" + doc.toString());
    }
    value = doc.getFieldValue("id");
    if (value != null) {
        // TODO: Converting ID to hashcode for now
        accessAudit.setId((long) value.hashCode());
    }
    value = doc.getFieldValue("cluster");
    if (value != null) {
        accessAudit.setClusterName(value.toString());
    }
    value = doc.getFieldValue("access");
    if (value != null) {
        accessAudit.setAccessType(value.toString());
    }
    value = doc.getFieldValue("enforcer");
    if (value != null) {
        accessAudit.setAclEnforcer(value.toString());
    }
    value = doc.getFieldValue("agent");
    if (value != null) {
        accessAudit.setAgentId(value.toString());
    }
    value = doc.getFieldValue("repo");
    if (value != null) {
        accessAudit.setRepoName(value.toString());
    }
    value = doc.getFieldValue("sess");
    if (value != null) {
        accessAudit.setSessionId(value.toString());
    }
    value = doc.getFieldValue("reqUser");
    if (value != null) {
        accessAudit.setRequestUser(value.toString());
    }
    value = doc.getFieldValue("reqData");
    if (value != null) {
        accessAudit.setRequestData(value.toString());
    }
    value = doc.getFieldValue("resource");
    if (value != null) {
        accessAudit.setResourcePath(value.toString());
    }
    value = doc.getFieldValue("cliIP");
    if (value != null) {
        accessAudit.setClientIP(value.toString());
    }
    value = doc.getFieldValue("logType");
    // if (value != null) {
    // TODO: Need to see what logType maps to in UI
    // accessAudit.setAuditType(solrUtil.toInt(value));
    // }
    value = doc.getFieldValue("result");
    if (value != null) {
        accessAudit.setAccessResult(solrUtil.toInt(value));
    }
    value = doc.getFieldValue("policy");
    if (value != null) {
        accessAudit.setPolicyId(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("repoType");
    if (value != null) {
        accessAudit.setRepoType(solrUtil.toInt(value));
        XXServiceDef xServiceDef = daoManager.getXXServiceDef().getById((long) accessAudit.getRepoType());
        if (xServiceDef != null) {
            accessAudit.setServiceType(xServiceDef.getName());
        }
    }
    value = doc.getFieldValue("resType");
    if (value != null) {
        accessAudit.setResourceType(value.toString());
    }
    value = doc.getFieldValue("reason");
    if (value != null) {
        accessAudit.setResultReason(value.toString());
    }
    value = doc.getFieldValue("action");
    if (value != null) {
        accessAudit.setAction(value.toString());
    }
    value = doc.getFieldValue("evtTime");
    if (value != null) {
        accessAudit.setEventTime(solrUtil.toDate(value));
    }
    value = doc.getFieldValue("seq_num");
    if (value != null) {
        accessAudit.setSequenceNumber(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("event_count");
    if (value != null) {
        accessAudit.setEventCount(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("event_dur_ms");
    if (value != null) {
        accessAudit.setEventDuration(solrUtil.toLong(value));
    }
    value = doc.getFieldValue("tags");
    if (value != null) {
        accessAudit.setTags(value.toString());
    }
    return accessAudit;
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) VXAccessAudit(org.apache.ranger.view.VXAccessAudit)

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