Search in sources :

Example 1 with QueryParametersImpl

use of datawave.webservice.query.QueryParametersImpl in project datawave by NationalSecurityAgency.

the class CompositeIndexTest method getQueryRangesIterator.

private Iterator getQueryRangesIterator(String queryString, ShardQueryLogic logic) throws Exception {
    MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
    params.putSingle(QUERY_STRING, queryString);
    params.putSingle(QUERY_NAME, "geoQuery");
    params.putSingle(QUERY_LOGIC_NAME, "EventQueryLogic");
    params.putSingle(QUERY_PERSISTENCE, "PERSISTENT");
    params.putSingle(QUERY_AUTHORIZATIONS, AUTHS);
    params.putSingle(QUERY_EXPIRATION, "20200101 000000.000");
    params.putSingle(QUERY_BEGIN, BEGIN_DATE);
    params.putSingle(QUERY_END, END_DATE);
    QueryParameters queryParams = new QueryParametersImpl();
    queryParams.validate(params);
    Set<Authorizations> auths = new HashSet<>();
    auths.add(new Authorizations(AUTHS));
    Query query = new QueryImpl();
    query.initialize(USER, Arrays.asList(USER_DN), null, queryParams, null);
    ShardQueryConfiguration config = ShardQueryConfiguration.create(logic, query);
    logic.initialize(config, instance.getConnector("root", PASSWORD), query, auths);
    logic.setupQuery(config);
    return config.getQueries();
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) QueryImpl(datawave.webservice.query.QueryImpl) Query(datawave.webservice.query.Query) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParameters(datawave.webservice.query.QueryParameters) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet)

Example 2 with QueryParametersImpl

use of datawave.webservice.query.QueryParametersImpl in project datawave by NationalSecurityAgency.

the class MultiValueCompositeIndexTest method getResultsIterator.

private Iterator getResultsIterator(String queryString, ShardQueryLogic logic) throws Exception {
    MultivaluedMap<String, String> params = new MultivaluedMapImpl<>();
    params.putSingle(QUERY_STRING, queryString);
    params.putSingle(QUERY_NAME, "geoQuery");
    params.putSingle(QUERY_LOGIC_NAME, "EventQueryLogic");
    params.putSingle(QUERY_PERSISTENCE, "PERSISTENT");
    params.putSingle(QUERY_AUTHORIZATIONS, AUTHS);
    params.putSingle(QUERY_EXPIRATION, "20200101 000000.000");
    params.putSingle(QUERY_BEGIN, BEGIN_DATE);
    params.putSingle(QUERY_END, END_DATE);
    QueryParameters queryParams = new QueryParametersImpl();
    queryParams.validate(params);
    Set<Authorizations> auths = new HashSet<>();
    auths.add(new Authorizations(AUTHS));
    Query query = new QueryImpl();
    query.initialize(USER, Arrays.asList(USER_DN), null, queryParams, null);
    ShardQueryConfiguration config = ShardQueryConfiguration.create(logic, query);
    logic.initialize(config, instance.getConnector("root", PASSWORD), query, auths);
    logic.setupQuery(config);
    return logic.getTransformIterator(query);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) QueryImpl(datawave.webservice.query.QueryImpl) Query(datawave.webservice.query.Query) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) QueryParameters(datawave.webservice.query.QueryParameters) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) ShardQueryConfiguration(datawave.query.config.ShardQueryConfiguration) HashSet(java.util.HashSet)

Example 3 with QueryParametersImpl

use of datawave.webservice.query.QueryParametersImpl in project datawave by NationalSecurityAgency.

the class ExtendedQueryExecutorBeanTest method testList_HappyPath.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testList_HappyPath() throws Exception {
    // Set local test input
    String queryName = "queryName";
    String queryLogicName = "queryLogicName";
    String userName = "userName";
    String sid = "sid";
    UUID queryId = UUID.randomUUID();
    List<String> dnList = Collections.singletonList("userDn");
    HashMap<String, Collection<String>> authsMap = new HashMap<>();
    authsMap.put("USERDN", Arrays.asList("AUTH_1"));
    // Set expectations
    expect(this.context.getCallerPrincipal()).andReturn(this.principal);
    expect(this.principal.getName()).andReturn(userName);
    expect(this.principal.getShortName()).andReturn(sid);
    expect(this.principal.getPrimaryUser()).andReturn(dwUser);
    expect(this.dwUser.getAuths()).andReturn(Collections.singletonList("AUTH_1"));
    expect(this.principal.getProxiedUsers()).andReturn(Collections.singletonList(dwUser));
    expect(this.principal.getAuthorizations()).andReturn((Collection) Arrays.asList(Arrays.asList("AUTH_1")));
    expect(this.persister.findByName(queryName)).andReturn(Arrays.asList((Query) this.query));
    expect(this.query.getOwner()).andReturn(sid).anyTimes();
    expect(this.query.getUserDN()).andReturn(sid).anyTimes();
    expect(this.query.getQueryLogicName()).andReturn(queryLogicName).anyTimes();
    expect(this.queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn((QueryLogic) this.queryLogic1);
    expect(this.queryLogic1.getConnectionPriority()).andReturn(Priority.HIGH);
    expect(this.query.getQueryAuthorizations()).andReturn(null).anyTimes();
    expect(this.queryLogic1.getCollectQueryMetrics()).andReturn(false);
    expect(this.query.getId()).andReturn(queryId).anyTimes();
    expect(this.query.getQuery()).andReturn(queryName).anyTimes();
    expect(this.query.getBeginDate()).andReturn(null).anyTimes();
    expect(this.query.getEndDate()).andReturn(null).anyTimes();
    expect(this.query.getColumnVisibility()).andReturn(null).anyTimes();
    expect(this.cache.containsKey(queryId.toString())).andReturn(false);
    expect(this.query.getQueryName()).andReturn(null).anyTimes();
    expect(this.query.getPagesize()).andReturn(0).anyTimes();
    expect(this.query.getPageTimeout()).andReturn(-1).anyTimes();
    expect(this.query.getExpirationDate()).andReturn(null).anyTimes();
    expect(this.query.getParameters()).andReturn((Set) Collections.emptySet()).anyTimes();
    expect(this.query.getDnList()).andReturn(dnList).anyTimes();
    expect(this.queryLogic1.getResultLimit(dnList)).andReturn(-1L);
    expect(this.queryLogic1.getMaxResults()).andReturn(-1L);
    this.cache.put(eq(queryId.toString()), isA(RunningQuery.class));
    // Run the test
    PowerMock.replayAll();
    QueryExecutorBean subject = new QueryExecutorBean();
    setInternalState(subject, EJBContext.class, context);
    setInternalState(subject, QueryCache.class, cache);
    setInternalState(subject, ClosedQueryCache.class, closedCache);
    setInternalState(subject, Persister.class, persister);
    setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
    setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
    setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    QueryImplListResponse result1 = subject.list(queryName);
    PowerMock.verifyAll();
    // Verify results
    assertNotNull("QueryLogicResponse should not be returned null", result1);
}
Also used : QueryImplListResponse(datawave.webservice.result.QueryImplListResponse) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Query(datawave.webservice.query.Query) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Collection(java.util.Collection) UUID(java.util.UUID) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with QueryParametersImpl

use of datawave.webservice.query.QueryParametersImpl in project datawave by NationalSecurityAgency.

the class QueryExecutorBeanTest method setup.

@Before
public void setup() throws Exception {
    System.setProperty(NpeUtils.NPE_OU_PROPERTY, "iamnotaperson");
    System.setProperty("dw.metadatahelper.all.auths", "A,B,C,D");
    QueryTraceCache traceCache = new QueryTraceCache();
    Whitebox.invokeMethod(traceCache, "init");
    cache = new QueryCache();
    cache.init();
    closedCache = new ClosedQueryCache();
    bean = new QueryExecutorBean();
    connectionFactory = createStrictMock(AccumuloConnectionFactory.class);
    auditor = new AuditBean();
    auditService = createStrictMock(AuditService.class);
    metrics = createStrictMock(QueryMetricsBean.class);
    queryLogicFactory = createStrictMock(QueryLogicFactoryImpl.class);
    persister = createStrictMock(Persister.class);
    predictor = createStrictMock(QueryPredictor.class);
    ctx = createStrictMock(EJBContext.class);
    qlCache = new CreatedQueryLogicCacheBean();
    queryExpirationConf = new QueryExpirationConfiguration();
    queryExpirationConf.setPageSizeShortCircuitCheckTime(45);
    queryExpirationConf.setPageShortCircuitTimeout(58);
    queryExpirationConf.setCallTime(60);
    connectionRequestBean = createStrictMock(AccumuloConnectionRequestBean.class);
    setInternalState(auditor, AuditService.class, auditService);
    setInternalState(auditor, AuditParameterBuilder.class, new DefaultAuditParameterBuilder());
    setInternalState(connectionRequestBean, EJBContext.class, ctx);
    setInternalState(bean, QueryCache.class, cache);
    setInternalState(bean, ClosedQueryCache.class, closedCache);
    setInternalState(bean, AccumuloConnectionFactory.class, connectionFactory);
    setInternalState(bean, AuditBean.class, auditor);
    setInternalState(bean, QueryMetricsBean.class, metrics);
    setInternalState(bean, QueryLogicFactory.class, queryLogicFactory);
    setInternalState(bean, QueryExpirationConfiguration.class, queryExpirationConf);
    setInternalState(bean, Persister.class, persister);
    setInternalState(bean, QueryPredictor.class, predictor);
    setInternalState(bean, EJBContext.class, ctx);
    setInternalState(bean, CreatedQueryLogicCacheBean.class, qlCache);
    setInternalState(bean, QueryTraceCache.class, traceCache);
    setInternalState(bean, Multimap.class, HashMultimap.create());
    setInternalState(bean, LookupUUIDConfiguration.class, new LookupUUIDConfiguration());
    setInternalState(bean, SecurityMarking.class, new ColumnVisibilitySecurityMarking());
    setInternalState(bean, QueryParameters.class, new QueryParametersImpl());
    setInternalState(bean, QueryMetricFactory.class, new QueryMetricFactoryImpl());
    setInternalState(bean, AccumuloConnectionRequestBean.class, connectionRequestBean);
    // RESTEasy mock stuff
    dispatcher = MockDispatcherFactory.createDispatcher();
    dispatcher.getRegistry().addSingletonResource(bean, "/DataWave/Query");
    response = new MockHttpResponse();
}
Also used : LookupUUIDConfiguration(datawave.webservice.query.configuration.LookupUUIDConfiguration) ClosedQueryCache(datawave.webservice.query.cache.ClosedQueryCache) QueryCache(datawave.webservice.query.cache.QueryCache) EJBContext(javax.ejb.EJBContext) QueryLogicFactoryImpl(datawave.webservice.query.logic.QueryLogicFactoryImpl) QueryExpirationConfiguration(datawave.webservice.query.cache.QueryExpirationConfiguration) AuditBean(datawave.webservice.common.audit.AuditBean) CreatedQueryLogicCacheBean(datawave.webservice.query.cache.CreatedQueryLogicCacheBean) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) ClosedQueryCache(datawave.webservice.query.cache.ClosedQueryCache) AccumuloConnectionFactory(datawave.webservice.common.connection.AccumuloConnectionFactory) ColumnVisibilitySecurityMarking(datawave.marking.ColumnVisibilitySecurityMarking) QueryTraceCache(datawave.webservice.query.cache.QueryTraceCache) QueryMetricsBean(datawave.webservice.query.metric.QueryMetricsBean) DefaultAuditParameterBuilder(datawave.webservice.common.audit.DefaultAuditParameterBuilder) Persister(datawave.webservice.query.factory.Persister) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl) AuditService(datawave.webservice.common.audit.AuditService) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) Before(org.junit.Before)

Example 5 with QueryParametersImpl

use of datawave.webservice.query.QueryParametersImpl in project datawave by NationalSecurityAgency.

the class QueryExecutorBeanTest method testCreateWithNoSelectedAuths.

@SuppressWarnings("unchecked")
@Test(expected = DatawaveWebApplicationException.class)
public void testCreateWithNoSelectedAuths() throws Exception {
    String queryLogicName = "EventQueryLogic";
    String queryName = "Something";
    String query = "FOO == BAR";
    Date beginDate = new Date();
    Date expirationDate = DateUtils.addDays(new Date(), 1);
    int pagesize = 10;
    QueryPersistence persist = QueryPersistence.TRANSIENT;
    Set<QueryImpl.Parameter> parameters = new HashSet<>();
    // need to call the getQueryByName() method. Maybe a partial mock of QueryExecutorBean would be better
    // setup principal mock
    String userDN = "CN=Guy Some Other soguy, OU=MY_SUBDIVISION, OU=MY_DIVISION, O=ORG, C=US";
    String[] auths = new String[2];
    auths[0] = "PRIVATE";
    auths[1] = "PUBLIC";
    QueryImpl q = new QueryImpl();
    q.setBeginDate(beginDate);
    q.setEndDate(beginDate);
    q.setExpirationDate(expirationDate);
    q.setPagesize(pagesize);
    q.setParameters(parameters);
    q.setQuery(query);
    q.setQueryAuthorizations(StringUtils.join(auths, ","));
    q.setQueryLogicName(queryLogicName);
    q.setUserDN(userDN);
    q.setId(UUID.randomUUID());
    @SuppressWarnings("rawtypes") QueryLogic logic = createMock(BaseQueryLogic.class);
    MultivaluedMap<String, String> p = new MultivaluedMapImpl<>();
    p.putSingle(QueryParameters.QUERY_AUTHORIZATIONS, "");
    p.putSingle(QueryParameters.QUERY_BEGIN, QueryParametersImpl.formatDate(beginDate));
    p.putSingle(QueryParameters.QUERY_END, QueryParametersImpl.formatDate(beginDate));
    p.putSingle(QueryParameters.QUERY_EXPIRATION, QueryParametersImpl.formatDate(expirationDate));
    p.putSingle(QueryParameters.QUERY_NAME, queryName);
    p.putSingle(QueryParameters.QUERY_PAGESIZE, Integer.toString(pagesize));
    p.putSingle(QueryParameters.QUERY_STRING, query);
    p.putSingle(QueryParameters.QUERY_PERSISTENCE, persist.name());
    p.putSingle(ColumnVisibilitySecurityMarking.VISIBILITY_MARKING, "PRIVATE|PUBLIC");
    InMemoryInstance instance = new InMemoryInstance();
    Connector c = instance.getConnector("root", new PasswordToken(""));
    QueryParameters qp = new QueryParametersImpl();
    MultivaluedMap<String, String> optionalParameters = new MultivaluedMapImpl<>();
    optionalParameters.putAll(qp.getUnknownParameters(p));
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of(userDN, "<CN=MY_CA, OU=MY_SUBDIVISION, OU=MY_DIVISION, O=ORG, C=US>"), UserType.USER, Arrays.asList(auths), null, null, 0L);
    DatawavePrincipal principal = new DatawavePrincipal(Collections.singletonList(user));
    String[] dns = principal.getDNs();
    Arrays.sort(dns);
    List<String> dnList = Arrays.asList(dns);
    PowerMock.resetAll();
    EasyMock.expect(ctx.getCallerPrincipal()).andReturn(principal).anyTimes();
    suppress(constructor(QueryParametersImpl.class));
    EasyMock.expect(persister.create(userDN, dnList, (SecurityMarking) Whitebox.getField(bean.getClass(), "marking").get(bean), queryLogicName, (QueryParameters) Whitebox.getField(bean.getClass(), "qp").get(bean), optionalParameters)).andReturn(q);
    EasyMock.expect(queryLogicFactory.getQueryLogic(queryLogicName, principal)).andReturn(logic);
    EasyMock.expect(logic.getRequiredQueryParameters()).andReturn(Collections.EMPTY_SET);
    EasyMock.expect(logic.containsDNWithAccess(dnList)).andReturn(true);
    EasyMock.expect(logic.getMaxPageSize()).andReturn(0);
    EasyMock.expect(logic.getAuditType(EasyMock.<Query>anyObject())).andReturn(AuditType.ACTIVE).anyTimes();
    EasyMock.expect(logic.getSelectors(anyObject())).andReturn(null);
    Map<String, String> auditParams = new HashMap<>();
    auditParams.put(QueryParameters.QUERY_STRING, p.getFirst(QueryParameters.QUERY_STRING));
    auditParams.put(AuditParameters.USER_DN, userDN);
    auditParams.put(AuditParameters.QUERY_SECURITY_MARKING_COLVIZ, "PRIVATE|PUBLIC");
    auditParams.put(AuditParameters.QUERY_AUDIT_TYPE, AuditType.ACTIVE.name());
    auditParams.put(AuditParameters.QUERY_LOGIC_CLASS, "EventQueryLogic");
    EasyMock.expect(auditService.audit(eq(auditParams))).andReturn(null);
    logic.close();
    EasyMock.expectLastCall();
    persister.remove(anyObject(Query.class));
    PowerMock.replayAll();
    bean.createQuery(queryLogicName, p);
    PowerMock.verifyAll();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Query(datawave.webservice.query.Query) HashMap(java.util.HashMap) DatawaveUser(datawave.security.authorization.DatawaveUser) MultivaluedMapImpl(org.jboss.resteasy.specimpl.MultivaluedMapImpl) InMemoryInstance(datawave.accumulo.inmemory.InMemoryInstance) BaseQueryLogic(datawave.webservice.query.logic.BaseQueryLogic) QueryLogic(datawave.webservice.query.logic.QueryLogic) QueryParameters(datawave.webservice.query.QueryParameters) QueryParametersImpl(datawave.webservice.query.QueryParametersImpl) Date(java.util.Date) DatawavePrincipal(datawave.security.authorization.DatawavePrincipal) QueryImpl(datawave.webservice.query.QueryImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) QueryPersistence(datawave.webservice.query.QueryPersistence) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

QueryParametersImpl (datawave.webservice.query.QueryParametersImpl)37 MultivaluedMapImpl (org.jboss.resteasy.specimpl.MultivaluedMapImpl)31 QueryMetricFactoryImpl (datawave.microservice.querymetric.QueryMetricFactoryImpl)26 Test (org.junit.Test)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)26 QueryParameters (datawave.webservice.query.QueryParameters)25 Date (java.util.Date)24 QueryPersistence (datawave.webservice.query.QueryPersistence)23 HashSet (java.util.HashSet)19 ColumnVisibilitySecurityMarking (datawave.marking.ColumnVisibilitySecurityMarking)16 ArrayList (java.util.ArrayList)15 UUID (java.util.UUID)14 DatawaveWebApplicationException (datawave.webservice.common.exception.DatawaveWebApplicationException)13 Query (datawave.webservice.query.Query)13 QueryImpl (datawave.webservice.query.QueryImpl)13 SubjectIssuerDNPair (datawave.security.authorization.SubjectIssuerDNPair)12 Authorizations (org.apache.accumulo.core.security.Authorizations)11 NoResultsQueryException (datawave.webservice.query.exception.NoResultsQueryException)10 Collection (java.util.Collection)10 ShardQueryConfiguration (datawave.query.config.ShardQueryConfiguration)9