@Test public void testSearchWithFilter() { thrown.expect(IllegalStateException.class); ElkConnectorImpl impl = new ElkConnectorImpl(); impl.search(PolicyIndexType.config, "search", null); fail("Expected exception to be thrown"); }
@Override public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("ENTER: " + text); } if (text == null || text.isEmpty()) { throw new IllegalArgumentException("No search string provided"); } if (!isAlphaNumeric(text)) { throw new IllegalArgumentException("Search must be alpha numeric"); } QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*" + text + "*"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ); Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY) .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS); if (type == null || type == PolicyIndexType.all) { for (PolicyIndexType pT : PolicyIndexType.values()) { if (pT != PolicyIndexType.all) { searchBuilder.addType(pT.toString()); } } } else { searchBuilder.addType(type.toString()); } Search search = searchBuilder.build(); JestResult result; try { result = jestClient.execute(search); } catch (IOException ioe) { LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe); throw new IllegalStateException(ioe); } if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":" + System.lineSeparator() + result.getJsonString()); } } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": " + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":" + result.getErrorMessage()); } String errorMessage = result.getErrorMessage(); if (errorMessage != null && !errorMessage.isEmpty()) { String xMessage; if (errorMessage.contains("TokenMgrError")) { int indexError = errorMessage.lastIndexOf("TokenMgrError"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("QueryParsingException")) { int indexError = errorMessage.lastIndexOf("QueryParsingException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("JsonParseException")) { int indexError = errorMessage.lastIndexOf("JsonParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("Parse Failure")) { int indexError = errorMessage.lastIndexOf("Parse Failure"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("SearchParseException")) { int indexError = errorMessage.lastIndexOf("SearchParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else { xMessage = result.getErrorMessage(); } throw new IllegalStateException(xMessage); } } return result; }
ElkConnectorImpl implements ElkConnector { @Override public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("ENTER: " + text); } if (text == null || text.isEmpty()) { throw new IllegalArgumentException("No search string provided"); } if (!isAlphaNumeric(text)) { throw new IllegalArgumentException("Search must be alpha numeric"); } QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*" + text + "*"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ); Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY) .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS); if (type == null || type == PolicyIndexType.all) { for (PolicyIndexType pT : PolicyIndexType.values()) { if (pT != PolicyIndexType.all) { searchBuilder.addType(pT.toString()); } } } else { searchBuilder.addType(type.toString()); } Search search = searchBuilder.build(); JestResult result; try { result = jestClient.execute(search); } catch (IOException ioe) { LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe); throw new IllegalStateException(ioe); } if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":" + System.lineSeparator() + result.getJsonString()); } } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": " + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":" + result.getErrorMessage()); } String errorMessage = result.getErrorMessage(); if (errorMessage != null && !errorMessage.isEmpty()) { String xMessage; if (errorMessage.contains("TokenMgrError")) { int indexError = errorMessage.lastIndexOf("TokenMgrError"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("QueryParsingException")) { int indexError = errorMessage.lastIndexOf("QueryParsingException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("JsonParseException")) { int indexError = errorMessage.lastIndexOf("JsonParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("Parse Failure")) { int indexError = errorMessage.lastIndexOf("Parse Failure"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("SearchParseException")) { int indexError = errorMessage.lastIndexOf("SearchParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else { xMessage = result.getErrorMessage(); } throw new IllegalStateException(xMessage); } } return result; } }
ElkConnectorImpl implements ElkConnector { @Override public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("ENTER: " + text); } if (text == null || text.isEmpty()) { throw new IllegalArgumentException("No search string provided"); } if (!isAlphaNumeric(text)) { throw new IllegalArgumentException("Search must be alpha numeric"); } QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*" + text + "*"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ); Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY) .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS); if (type == null || type == PolicyIndexType.all) { for (PolicyIndexType pT : PolicyIndexType.values()) { if (pT != PolicyIndexType.all) { searchBuilder.addType(pT.toString()); } } } else { searchBuilder.addType(type.toString()); } Search search = searchBuilder.build(); JestResult result; try { result = jestClient.execute(search); } catch (IOException ioe) { LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe); throw new IllegalStateException(ioe); } if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":" + System.lineSeparator() + result.getJsonString()); } } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": " + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":" + result.getErrorMessage()); } String errorMessage = result.getErrorMessage(); if (errorMessage != null && !errorMessage.isEmpty()) { String xMessage; if (errorMessage.contains("TokenMgrError")) { int indexError = errorMessage.lastIndexOf("TokenMgrError"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("QueryParsingException")) { int indexError = errorMessage.lastIndexOf("QueryParsingException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("JsonParseException")) { int indexError = errorMessage.lastIndexOf("JsonParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("Parse Failure")) { int indexError = errorMessage.lastIndexOf("Parse Failure"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("SearchParseException")) { int indexError = errorMessage.lastIndexOf("SearchParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else { xMessage = result.getErrorMessage(); } throw new IllegalStateException(xMessage); } } return result; } ElkConnectorImpl(); }
ElkConnectorImpl implements ElkConnector { @Override public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("ENTER: " + text); } if (text == null || text.isEmpty()) { throw new IllegalArgumentException("No search string provided"); } if (!isAlphaNumeric(text)) { throw new IllegalArgumentException("Search must be alpha numeric"); } QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*" + text + "*"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ); Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY) .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS); if (type == null || type == PolicyIndexType.all) { for (PolicyIndexType pT : PolicyIndexType.values()) { if (pT != PolicyIndexType.all) { searchBuilder.addType(pT.toString()); } } } else { searchBuilder.addType(type.toString()); } Search search = searchBuilder.build(); JestResult result; try { result = jestClient.execute(search); } catch (IOException ioe) { LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe); throw new IllegalStateException(ioe); } if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":" + System.lineSeparator() + result.getJsonString()); } } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": " + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":" + result.getErrorMessage()); } String errorMessage = result.getErrorMessage(); if (errorMessage != null && !errorMessage.isEmpty()) { String xMessage; if (errorMessage.contains("TokenMgrError")) { int indexError = errorMessage.lastIndexOf("TokenMgrError"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("QueryParsingException")) { int indexError = errorMessage.lastIndexOf("QueryParsingException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("JsonParseException")) { int indexError = errorMessage.lastIndexOf("JsonParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("Parse Failure")) { int indexError = errorMessage.lastIndexOf("Parse Failure"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("SearchParseException")) { int indexError = errorMessage.lastIndexOf("SearchParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else { xMessage = result.getErrorMessage(); } throw new IllegalStateException(xMessage); } } return result; } ElkConnectorImpl(); @Override JestResult search(PolicyIndexType type, String text); @Override JestResult search(PolicyIndexType type, String text, Map<String, String> filter_s); boolean put(PolicyRestAdapter policyData); @Override boolean delete(PolicyRestAdapter policyData); @Override boolean update(PolicyRestAdapter policyData); }
ElkConnectorImpl implements ElkConnector { @Override public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("ENTER: " + text); } if (text == null || text.isEmpty()) { throw new IllegalArgumentException("No search string provided"); } if (!isAlphaNumeric(text)) { throw new IllegalArgumentException("Search must be alpha numeric"); } QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*" + text + "*"); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(mQ); Builder searchBuilder = new Search.Builder(searchSourceBuilder.toString()).addIndex(ELK_INDEX_POLICY) .setParameter(Parameters.SIZE, ElkConnectorImpl.QUERY_MAXRECORDS); if (type == null || type == PolicyIndexType.all) { for (PolicyIndexType pT : PolicyIndexType.values()) { if (pT != PolicyIndexType.all) { searchBuilder.addType(pT.toString()); } } } else { searchBuilder.addType(type.toString()); } Search search = searchBuilder.build(); JestResult result; try { result = jestClient.execute(search); } catch (IOException ioe) { LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + ":" + search + ": " + ioe.getMessage(), ioe); throw new IllegalStateException(ioe); } if (result.isSucceeded()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("OK:" + result.getResponseCode() + ":" + search + ": " + result.getPathToResult() + ":" + System.lineSeparator() + result.getJsonString()); } } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn(XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + result.getResponseCode() + ": " + search.getURI() + ":" + result.getPathToResult() + ":" + result.getJsonString() + ":" + result.getErrorMessage()); } String errorMessage = result.getErrorMessage(); if (errorMessage != null && !errorMessage.isEmpty()) { String xMessage; if (errorMessage.contains("TokenMgrError")) { int indexError = errorMessage.lastIndexOf("TokenMgrError"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("QueryParsingException")) { int indexError = errorMessage.lastIndexOf("QueryParsingException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("JsonParseException")) { int indexError = errorMessage.lastIndexOf("JsonParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("Parse Failure")) { int indexError = errorMessage.lastIndexOf("Parse Failure"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else if (errorMessage.contains("SearchParseException")) { int indexError = errorMessage.lastIndexOf("SearchParseException"); xMessage = "Invalid Search Expression. Details: " + errorMessage.substring(indexError); } else { xMessage = result.getErrorMessage(); } throw new IllegalStateException(xMessage); } } return result; } ElkConnectorImpl(); @Override JestResult search(PolicyIndexType type, String text); @Override JestResult search(PolicyIndexType type, String text, Map<String, String> filter_s); boolean put(PolicyRestAdapter policyData); @Override boolean delete(PolicyRestAdapter policyData); @Override boolean update(PolicyRestAdapter policyData);  }