private EventQueryResponseBase validatePagedResponse(final BaseQueryResponse response) { final EventQueryResponseBase pagedResponse; if (response instanceof EventQueryResponseBase) { pagedResponse = (EventQueryResponseBase) response; } else { final EventQueryResponseBase er = responseObjectFactory.getEventQueryResponse(); er.addMessage("Unhandled response type from Query/createQueryAndNext"); throw new PreConditionFailedException(null, er); } return pagedResponse; }
/** * Helper to throw Response Error for create/define Query */ private void throwBadRequest(DatawaveErrorCode ec, GenericResponse<String> response) { BadRequestQueryException qe = new BadRequestQueryException(ec); response.addException(qe); throw new BadRequestException(qe, response); }
private FileSystem getFS(String hdfs, BaseResponse response) { org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration(); conf.set("fs.defaultFS", hdfs); // Override default buffer size (4K) to 16K conf.setInt("io.file.buffer.size", 16384); final FileSystem fs; try { fs = FileSystem.get(conf); return fs; } catch (IOException e1) { NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.HDFS_CONNECTION_ERROR, e1, MessageFormat.format("Location: {0}", hdfs)); log.error(qe); response.addException(qe); throw new NotFoundException(qe, response); } }
@GET @Path("/reloadAccumuloAuths") @Produces({"application/xml", "text/xml", "application/json"}) public GenericResponse<String> reloadAccumuloAuthorizations() { GenericResponse<String> response = new GenericResponse<>(); try { retrieveAccumuloAuthorizations(); response.setResult("Authorizations reloaded. Remember to flush the principals cache to ensure principals are reloaded with new auths applied."); return response; } catch (Exception e) { response.setResult("Unable to reload Accumulo authorizations."); throw new DatawaveWebApplicationException(e, response); } }
throw new NotFoundException(e, response); } else { if (query.getSettings().getOwner().equals(owner)) { UnauthorizedQueryException e = new UnauthorizedQueryException(DatawaveErrorCode.QUERY_OWNER_MISMATCH, MessageFormat.format("{0} != {1}", query.getSettings().getOwner(), owner)); throw new UnauthorizedException(e, response); response.addException(qe.getBottomQueryException()); int statusCode = qe.getBottomQueryException().getStatusCode(); throw new DatawaveWebApplicationException(qe, response, statusCode);
log.error(qe); response.addException(qe); throw new NotFoundException(qe, response); throw new NotFoundException(qe, response); log.error("Error removing job state information", e); response.addException(e.getBottomQueryException()); throw new DatawaveWebApplicationException(e, response);
List<Query> userQueries = persister.findByUser(userId); if (null == userQueries) { throw new NoResultsException(null); } else { response.setQuery(userQueries); response.addException(qe.getBottomQueryException()); int statusCode = qe.getBottomQueryException().getStatusCode(); throw new DatawaveWebApplicationException(qe, response, statusCode);
response.addException(e); response.setResult("CachedResult not found"); throw new PreConditionFailedException(e, response); response.addException(e); response.setResult("CachedResult not found"); throw new NotFoundException(e, response); response.addException(e); response.setResult("Current user does not match user that defined query."); throw new UnauthorizedException(e, response);
@Override public QueryLogic<?> getQueryLogic(String name, Principal principal) throws IllegalArgumentException, CloneNotSupportedException { QueryLogic<?> logic; try { logic = (QueryLogic<?>) applicationContext.getBean(name); logic.setPrincipal(principal); } catch (ClassCastException | NoSuchBeanDefinitionException cce) { throw new IllegalArgumentException("Logic name '" + name + "' does not exist in the configuration"); } if (!logic.canRunQuery(principal)) { throw new UnauthorizedException(new IllegalAccessException("User does not have required role(s): " + logic.getRoleManager().getRequiredRoles()), new VoidResponse()); } logic.setLogicName(name); if (logic.getMaxPageSize() == 0) { logic.setMaxPageSize(queryLogicFactoryConfiguration.getMaxPageSize()); } if (logic.getPageByteTrigger() == 0) { logic.setPageByteTrigger(queryLogicFactoryConfiguration.getPageByteTrigger()); } return logic; }
result = (BaseResponse) r; } catch (NoResultsException e) { e.setStartTime(start); e.setEndTime(System.currentTimeMillis()); throw e;
final GenericResponse<String> errorReponse = new GenericResponse<>(); errorReponse.addMessage(message); throw new DatawaveWebApplicationException(new IllegalArgumentException(message), errorReponse); final GenericResponse<String> errorReponse = new GenericResponse<>(); errorReponse.addMessage(message); throw new DatawaveWebApplicationException(new IllegalArgumentException(message), errorReponse); final GenericResponse<String> errorReponse = new GenericResponse<>(); errorReponse.addMessage(message); throw new DatawaveWebApplicationException(new IllegalArgumentException(message), errorReponse);
throw new NotFoundException(e, response); } else { accumuloConnectionRequestBean.adminCancelConnectionRequest(originalQueryId); response.addException(qe.getBottomQueryException()); int statusCode = qe.getBottomQueryException().getStatusCode(); throw new DatawaveWebApplicationException(qe, response, statusCode);
BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.QUERY_REGEX_OR_USER_REQUIRED); response.addException(qe); throw new BadRequestException(qe, response); } else { PatternWrapper p = PatternWrapper.wrap(queryRegex);
private VoidResponse deleteModel(@Required("name") String name, String modelTableName, boolean reloadCache) { if (log.isDebugEnabled()) { log.debug("model name: " + name); log.debug("modelTableName: " + (null == modelTableName ? "" : modelTableName)); } VoidResponse response = new VoidResponse(); ModelList models = listModelNames(modelTableName); if (!models.getNames().contains(name)) throw new NotFoundException(null, response); datawave.webservice.model.Model model = getModel(name, modelTableName); deleteMapping(model, modelTableName, reloadCache); return response; }
/** * Clears any cached credentials for the calling user. The end result is that future calls to other methods on this application will require outside contact * with the authentication provider. * * If the credentials are for a single user with no proxy involved, these are the only credentials flushed. Otherwise, if there is a proxy chain, this will * flush the DN for the user in the proxy (assumes there is never more than one user in the proxy chain). */ @GET @Path("/flushCachedCredentials") @Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff"}) @PermitAll public GenericResponse<String> flushCachedCredentials() { GenericResponse<String> response = new GenericResponse<>(); Principal callerPrincipal = context.getCallerPrincipal(); log.info("Flushing credentials for " + callerPrincipal + " from the cache."); if (callerPrincipal instanceof DatawavePrincipal) { DatawavePrincipal dp = (DatawavePrincipal) callerPrincipal; response.setResult(credentialsCache.evict(dp.getUserDN().subjectDN())); } else { log.warn(callerPrincipal + " is not a DatawavePrincipal. Cannot flush credentials."); response.addMessage("Unable to determine calling user name. Values were not flushed!"); throw new DatawaveWebApplicationException(new IllegalStateException("Unable to flush credentials. Unknown principal type."), response); } return response; }
BadRequestQueryException qe = new BadRequestQueryException(DatawaveErrorCode.QUERY_REGEX_OR_USER_REQUIRED); response.addException(qe); throw new BadRequestException(qe, response); } else if (queryRegex == null) { traceInfos.removeAll(user);
NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.NO_QUERY_OBJECT_MATCH); response.addException(qe); throw new NotFoundException(qe, response); throw new NotFoundException(qe, response);
@POST @Path("/audit") @Consumes("*/*") @Produces({"application/xml", "text/xml", "application/json", "text/yaml", "text/x-yaml", "application/x-yaml", "application/x-protobuf", "application/x-protostuff"}) @GZIP public VoidResponse auditRest(MultivaluedMap<String,String> parameters) { VoidResponse response = new VoidResponse(); try { auditService.audit(auditParameterBuilder.validate(parameters)); return response; } catch (Exception e) { QueryException qe = new QueryException(DatawaveErrorCode.AUDITING_ERROR, e); log.error(qe); response.addException(qe.getBottomQueryException()); int statusCode = qe.getBottomQueryException().getStatusCode(); throw new DatawaveWebApplicationException(qe, response, statusCode); } }
/** * Removes all cached {@link DatawaveUser}s. There are potentially two caches in use. First, Wildfly uses a security cache that stores {@link Principal}s * under the incoming credential key. This is normally a very short-lived cache (5-30 minutes). Second, a {@link CachedDatawaveUserService} may be in use, * which means that it caches according to its own rules. This method attempts to clear both caches. * * @return a string indicating cache flush was successful */ @GET @Path("/flushAll") @JmxManaged public String flushAll() { try { // Remove principals from the Wildfly cached authentication manager, if we have one in use. authManager.flushCache(); if (!cachedDatawaveUserServiceInstance.isUnsatisfied()) { cachedDatawaveUserServiceInstance.get().evictAll(); } return "All credentials caches cleared."; } catch (Exception e) { GenericResponse<String> response = new GenericResponse<>(); response.addException(new QueryException(UNKNOWN_SERVER_ERROR, e)); throw new DatawaveWebApplicationException(e, response); } }
response.addException(qe.getBottomQueryException()); int statusCode = qe.getBottomQueryException().getStatusCode(); throw new DatawaveWebApplicationException(qe, response, statusCode);