Search in sources :

Example 1 with VXAccessAudit

use of org.apache.ranger.view.VXAccessAudit in project ranger by apache.

the class TestAssetREST method testGetAccessLogsForKms.

@Test
public void testGetAccessLogsForKms() {
    SearchCriteria searchCriteria = new SearchCriteria();
    List<SortField> sortFields = null;
    List<VXAccessAudit> vXAccessAudits = new ArrayList<VXAccessAudit>();
    VXAccessAuditList vXAccessAuditList = new VXAccessAuditList();
    vXAccessAuditList.setVXAccessAudits(vXAccessAudits);
    Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
    Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("test");
    Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Integer) 8);
    Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(new Date());
    Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l);
    Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l);
    Mockito.when(msBizUtil.isKeyAdmin()).thenReturn(true);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xxServiceDefDao);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(Id);
    Mockito.when(xxServiceDefDao.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME)).thenReturn(xServiceDef);
    Mockito.when(assetMgr.getAccessLogs(searchCriteria)).thenReturn(vXAccessAuditList);
    VXAccessAuditList expectedVXAccessAuditList = assetREST.getAccessLogs(request);
    Assert.assertEquals(vXAccessAuditList, expectedVXAccessAuditList);
    Mockito.verify(msBizUtil).isKeyAdmin();
    Mockito.verify(assetMgr).getAccessLogs(searchCriteria);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(searchUtil, Mockito.times(12)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.nullable(String.class));
    Mockito.verify(searchUtil, Mockito.times(4)).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil).extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXAccessAudit(org.apache.ranger.view.VXAccessAudit) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date) Test(org.junit.Test)

Example 2 with VXAccessAudit

use of org.apache.ranger.view.VXAccessAudit in project ranger by apache.

the class XAccessAuditService method searchXAccessAudits.

/**
 * @param searchCriteria
 * @return
 */
public VXAccessAuditList searchXAccessAudits(SearchCriteria searchCriteria) {
    VXAccessAuditList returnList = new VXAccessAuditList();
    List<VXAccessAudit> xAccessAuditList = new ArrayList<VXAccessAudit>();
    List<XXAccessAudit> resultList = (List<XXAccessAudit>) searchResources(searchCriteria, searchFields, sortFields, returnList);
    final boolean hiveQueryVisibility = PropertiesUtil.getBooleanProperty("ranger.audit.hive.query.visibility", true);
    // Iterate over the result list and create the return list
    for (XXAccessAudit gjXAccessAudit : resultList) {
        VXAccessAudit vXAccessAudit = populateViewBean(gjXAccessAudit);
        if (vXAccessAudit != null) {
            if (StringUtils.equalsIgnoreCase(vXAccessAudit.getAclEnforcer(), RangerHadoopConstants.DEFAULT_XASECURE_MODULE_ACL_NAME)) {
                vXAccessAudit.setAclEnforcer(RangerHadoopConstants.DEFAULT_RANGER_MODULE_ACL_NAME);
            }
            if (!hiveQueryVisibility && "hive".equalsIgnoreCase(vXAccessAudit.getServiceType())) {
                vXAccessAudit.setRequestData(null);
            } else if ("hive".equalsIgnoreCase(vXAccessAudit.getServiceType()) && ("grant".equalsIgnoreCase(vXAccessAudit.getAccessType()) || "revoke".equalsIgnoreCase(vXAccessAudit.getAccessType()))) {
                try {
                    vXAccessAudit.setRequestData(java.net.URLDecoder.decode(vXAccessAudit.getRequestData(), "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    logger.warn("Error while encoding request data");
                }
            }
            xAccessAuditList.add(vXAccessAudit);
        }
    }
    returnList.setVXAccessAudits(xAccessAuditList);
    return returnList;
}
Also used : XXAccessAudit(org.apache.ranger.entity.XXAccessAudit) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VXAccessAudit(org.apache.ranger.view.VXAccessAudit) ArrayList(java.util.ArrayList) List(java.util.List) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList)

Example 3 with VXAccessAudit

use of org.apache.ranger.view.VXAccessAudit in project ranger by apache.

the class SolrAccessAuditsService method searchXAccessAudits.

public VXAccessAuditList searchXAccessAudits(SearchCriteria searchCriteria) {
    // Make call to Solr
    SolrClient solrClient = solrMgr.getSolrClient();
    final boolean hiveQueryVisibility = PropertiesUtil.getBooleanProperty("ranger.audit.hive.query.visibility", true);
    if (solrClient == null) {
        logger.warn("Solr client is null, so not running the query.");
        throw restErrorUtil.createRESTException("Error connecting to search engine", MessageEnums.ERROR_SYSTEM);
    }
    List<VXAccessAudit> xAccessAuditList = new ArrayList<VXAccessAudit>();
    QueryResponse response = solrUtil.searchResources(searchCriteria, searchFields, sortFields, solrClient);
    SolrDocumentList docs = response.getResults();
    for (int i = 0; i < docs.size(); i++) {
        SolrDocument doc = docs.get(i);
        VXAccessAudit vXAccessAudit = populateViewBean(doc);
        if (vXAccessAudit != null) {
            if (!hiveQueryVisibility && "hive".equalsIgnoreCase(vXAccessAudit.getServiceType())) {
                vXAccessAudit.setRequestData(null);
            } else if ("hive".equalsIgnoreCase(vXAccessAudit.getServiceType()) && "grant".equalsIgnoreCase(vXAccessAudit.getAccessType()) || "revoke".equalsIgnoreCase(vXAccessAudit.getAccessType())) {
                try {
                    vXAccessAudit.setRequestData(java.net.URLDecoder.decode(vXAccessAudit.getRequestData(), "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    logger.warn("Error while encoding request data");
                }
            }
        }
        xAccessAuditList.add(vXAccessAudit);
    }
    VXAccessAuditList returnList = new VXAccessAuditList();
    returnList.setPageSize(searchCriteria.getMaxRows());
    returnList.setResultSize(docs.size());
    returnList.setTotalCount((int) docs.getNumFound());
    returnList.setStartIndex((int) docs.getStart());
    returnList.setVXAccessAudits(xAccessAuditList);
    return returnList;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VXAccessAudit(org.apache.ranger.view.VXAccessAudit) SolrDocumentList(org.apache.solr.common.SolrDocumentList) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList)

Example 4 with VXAccessAudit

use of org.apache.ranger.view.VXAccessAudit in project ranger by apache.

the class XAccessAuditServiceBase method searchXAccessAudits.

/**
 * @param searchCriteria
 * @return
 */
public VXAccessAuditList searchXAccessAudits(SearchCriteria searchCriteria) {
    VXAccessAuditList returnList = new VXAccessAuditList();
    List<VXAccessAudit> xAccessAuditList = new ArrayList<VXAccessAudit>();
    List<T> resultList = searchResources(searchCriteria, searchFields, sortFields, returnList);
    // Iterate over the result list and create the return list
    for (T gjXAccessAudit : resultList) {
        VXAccessAudit vXAccessAudit = populateViewBean(gjXAccessAudit);
        xAccessAuditList.add(vXAccessAudit);
    }
    returnList.setVXAccessAudits(xAccessAuditList);
    return returnList;
}
Also used : ArrayList(java.util.ArrayList) VXAccessAudit(org.apache.ranger.view.VXAccessAudit) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList)

Example 5 with VXAccessAudit

use of org.apache.ranger.view.VXAccessAudit in project ranger by apache.

the class TestAssetREST method testGetAccessLogs.

@Test
public void testGetAccessLogs() {
    SearchCriteria searchCriteria = new SearchCriteria();
    List<SortField> sortFields = null;
    List<VXAccessAudit> vXAccessAudits = new ArrayList<VXAccessAudit>();
    VXAccessAuditList vXAccessAuditList = new VXAccessAuditList();
    vXAccessAuditList.setVXAccessAudits(vXAccessAudits);
    Mockito.when(searchUtil.extractCommonCriterias(request, sortFields)).thenReturn(searchCriteria);
    Mockito.when(searchUtil.extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("test");
    Mockito.when(searchUtil.extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Integer) 8);
    Mockito.when(searchUtil.extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(new Date());
    Mockito.when(searchUtil.extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString())).thenReturn((Long) 8l);
    Mockito.when(msBizUtil.isKeyAdmin()).thenReturn(false);
    Mockito.when(daoManager.getXXServiceDef()).thenReturn(xxServiceDefDao);
    XXServiceDef xServiceDef = new XXServiceDef();
    xServiceDef.setId(Id);
    Mockito.when(xxServiceDefDao.findByName(EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_KMS_NAME)).thenReturn(xServiceDef);
    Mockito.when(assetMgr.getAccessLogs(searchCriteria)).thenReturn(vXAccessAuditList);
    VXAccessAuditList expectedVXAccessAuditList = assetREST.getAccessLogs(request);
    Assert.assertEquals(vXAccessAuditList, expectedVXAccessAuditList);
    Mockito.verify(msBizUtil).isKeyAdmin();
    Mockito.verify(assetMgr).getAccessLogs(searchCriteria);
    Mockito.verify(daoManager).getXXServiceDef();
    Mockito.verify(searchUtil, Mockito.times(12)).extractString((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.nullable(String.class));
    Mockito.verify(searchUtil, Mockito.times(4)).extractInt((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil, Mockito.times(2)).extractDate((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    Mockito.verify(searchUtil).extractLong((HttpServletRequest) Mockito.any(), (SearchCriteria) Mockito.any(), Mockito.anyString(), Mockito.anyString());
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) ArrayList(java.util.ArrayList) SortField(org.apache.ranger.common.SortField) VXAccessAudit(org.apache.ranger.view.VXAccessAudit) VXAccessAuditList(org.apache.ranger.view.VXAccessAuditList) SearchCriteria(org.apache.ranger.common.SearchCriteria) Date(java.util.Date) Test(org.junit.Test)

Aggregations

VXAccessAudit (org.apache.ranger.view.VXAccessAudit)6 ArrayList (java.util.ArrayList)5 VXAccessAuditList (org.apache.ranger.view.VXAccessAuditList)5 XXServiceDef (org.apache.ranger.entity.XXServiceDef)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 SearchCriteria (org.apache.ranger.common.SearchCriteria)2 SortField (org.apache.ranger.common.SortField)2 Test (org.junit.Test)2 List (java.util.List)1 XXAccessAudit (org.apache.ranger.entity.XXAccessAudit)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1