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