use of datawave.webservice.query.exception.QueryException in project datawave by NationalSecurityAgency.
the class ExtendedQueryExecutorBeanTest method testCreateQuery_userNotInAllowedDNs.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCreateQuery_userNotInAllowedDNs() throws Exception {
// Set local test input
String queryLogicName = "queryLogicName";
String query = "query";
String queryName = "queryName";
String queryVisibility = "A&B";
long currentTime = System.currentTimeMillis();
Date beginDate = new Date(currentTime - 5000);
Date endDate = new Date(currentTime - 1000);
String queryAuthorizations = "AUTH_1";
Date expirationDate = new Date(currentTime + 9999);
int pagesize = 1000;
int pageTimeout = -1;
Long maxResultsOverride = null;
QueryPersistence persistenceMode = QueryPersistence.PERSISTENT;
String parameters = null;
boolean trace = false;
// Set expectations
MultivaluedMap<String, String> queryParameters = new MultivaluedMapImpl<>();
queryParameters.putAll(QueryParametersImpl.paramsToMap(queryLogicName, query, queryName, queryVisibility, beginDate, endDate, queryAuthorizations, expirationDate, pagesize, pageTimeout, maxResultsOverride, persistenceMode, parameters, trace));
ColumnVisibilitySecurityMarking marking = new ColumnVisibilitySecurityMarking();
marking.validate(queryParameters);
QueryParameters qp = new QueryParametersImpl();
qp.validate(queryParameters);
MultivaluedMap<String, String> op = new MultivaluedMapImpl<>();
op.putAll(qp.getUnknownParameters(queryParameters));
op.putSingle(PrivateAuditConstants.LOGIC_CLASS, queryLogicName);
op.putSingle(PrivateAuditConstants.COLUMN_VISIBILITY, queryVisibility);
expect(this.queryLogicFactory.getQueryLogic(queryLogicName, this.principal)).andReturn((QueryLogic) this.queryLogic1);
expect(this.context.getCallerPrincipal()).andReturn(this.principal).anyTimes();
queryLogic1.validate(queryParameters);
expect(this.principal.getName()).andReturn("userName Full");
expect(this.principal.getShortName()).andReturn("userName");
expect(this.principal.getUserDN()).andReturn(SubjectIssuerDNPair.of("userDN"));
expect(this.principal.getDNs()).andReturn(new String[] { "userDN" });
expect(this.principal.getProxyServers()).andReturn(new ArrayList<>(0)).anyTimes();
expect(this.queryLogic1.containsDNWithAccess(Collections.singletonList("userDN"))).andReturn(false);
// Run the test
PowerMock.replayAll();
QueryExecutorBean subject = new QueryExecutorBean();
setInternalState(subject, EJBContext.class, context);
setInternalState(subject, QueryLogicFactory.class, queryLogicFactory);
setInternalState(subject, QueryExpirationConfiguration.class, queryExpirationConf);
setInternalState(subject, SecurityMarking.class, new ColumnVisibilitySecurityMarking());
setInternalState(subject, QueryParameters.class, new QueryParametersImpl());
setInternalState(subject, QueryMetricFactory.class, new QueryMetricFactoryImpl());
Throwable result1 = null;
try {
subject.createQuery(queryLogicName, queryParameters);
} catch (DatawaveWebApplicationException e) {
result1 = e.getCause();
}
PowerMock.verifyAll();
// Verify results
assertTrue("QueryException expected to have been thrown", result1 instanceof QueryException);
assertEquals("Thrown exception expected to have been due to access denied", "401", ((QueryException) result1).getErrorCode());
assertEquals("Thrown exception expected to detail reason for access denial", "None of the DNs used have access to this query logic: [userDN]", result1.getMessage());
}
use of datawave.webservice.query.exception.QueryException in project datawave by NationalSecurityAgency.
the class JexlNodeFactory method getLiteral.
private static ASTNumberLiteral getLiteral(Number fieldValue) {
ASTNumberLiteral literal = new ASTNumberLiteral(ParserTreeConstants.JJTNUMBERLITERAL);
literal.image = fieldValue.toString();
if (NATURAL_NUMBERS.contains(fieldValue.getClass())) {
literal.setNatural(fieldValue.toString());
} else if (REAL_NUMBERS.contains(fieldValue.getClass())) {
literal.setReal(fieldValue.toString());
} else {
QueryException qe = new QueryException(DatawaveErrorCode.ASTNUMBERLITERAL_TYPE_ASCERTAIN_ERROR, MessageFormat.format("{0}", literal));
throw new DatawaveFatalQueryException(qe);
}
return literal;
}
use of datawave.webservice.query.exception.QueryException in project datawave by NationalSecurityAgency.
the class BaseIndexExpansionVisitor method expand.
/**
* The expand method is the entrypoint which should be called to run index expansion on a given Jexl tree.
*
* @param script
* the Jexl tree to expand, not null
* @param <T>
* the Jexl node type
* @return a rebuilt Jexl tree with applicable fields/terms expanded
*/
@SuppressWarnings("unchecked")
protected <T extends JexlNode> T expand(T script) {
setupExecutor();
try {
if (null == config.getQueryFieldsDatatypes()) {
QueryException qe = new QueryException(DatawaveErrorCode.DATATYPESFORINDEXFIELDS_MULTIMAP_MISSING);
throw new DatawaveFatalQueryException(qe);
}
T rebuiltScript = (T) (script.jjtAccept(this, null));
rebuildFutureJexlNodes();
// handle the case where the root node was expanded
if (rebuiltScript instanceof FutureJexlNode) {
rebuiltScript = (T) ((FutureJexlNode) rebuiltScript).getRebuiltNode();
}
return rebuiltScript;
} finally {
shutdownExecutor();
}
}
use of datawave.webservice.query.exception.QueryException in project datawave by NationalSecurityAgency.
the class ShardIndexQueryTableStaticMethods method getBoundedRangeRange.
/**
* Get the accumulo range for a literal query range. Note that it is assumed that the column family set will include the fieldname.
*
* @param literalRange
* @return
* @throws IllegalRangeArgumentException
*/
public static Range getBoundedRangeRange(LiteralRange<?> literalRange) throws IllegalRangeArgumentException {
String lower = literalRange.getLower().toString(), upper = literalRange.getUpper().toString();
Key startKey = new Key(new Text(lower));
Key endKey = new Key(new Text(literalRange.isUpperInclusive() ? upper + Constants.MAX_UNICODE_STRING : upper));
Range range = null;
try {
range = new Range(startKey, literalRange.isLowerInclusive(), endKey, literalRange.isUpperInclusive());
} catch (IllegalArgumentException e) {
QueryException qe = new QueryException(DatawaveErrorCode.RANGE_CREATE_ERROR, e, MessageFormat.format("{0}", literalRange));
log.debug(qe);
throw new IllegalRangeArgumentException(qe);
}
return range;
}
use of datawave.webservice.query.exception.QueryException in project datawave-spring-boot-starter by NationalSecurityAgency.
the class ProtostuffHttpMessageConverterTest method testProtostuffResponse.
@Test
public void testProtostuffResponse() throws Exception {
MvcResult mvcResult = mvc.perform(get("/vr").accept("application/x-protostuff")).andExpect(status().isOk()).andReturn();
VoidResponse actual = new VoidResponse();
ProtostuffIOUtil.mergeFrom(mvcResult.getResponse().getContentAsByteArray(), actual, actual.cachedSchema());
QueryException qe = new QueryException(DatawaveErrorCode.BAD_RESPONSE_CLASS, "This is a test QueryException");
ArrayList<String> expectedMessages = Lists.newArrayList("This is a test message", "This is another test message");
ArrayList<QueryExceptionType> expectedExceptions = Lists.newArrayList(new QueryExceptionType(qe.getMessage(), "Exception with no cause caught", qe.getErrorCode()), new QueryExceptionType("This is the cause exception", "java.lang.Exception: This is the cause exception", null), new QueryExceptionType("this is a test exception", "Exception with no cause caught", null));
assertTrue(actual.getHasResults());
assertTrue(actual.getOperationTimeMS() >= 0);
assertEquals(expectedMessages, actual.getMessages());
assertEquals(expectedExceptions, actual.getExceptions());
}
Aggregations