From a6f7b58d0d1776a3cdb5d3c7c9961e0103719e6a Mon Sep 17 00:00:00 2001 From: Madhan Neethiraj Date: Thu, 6 Mar 2025 15:42:55 -0800 Subject: [PATCH] RANGER-5049: checkstyle compliance updates - plugin-solr module - #2 (#539) --- .../solr/authorizer/RangerSolrAuthorizer.java | 16 +- .../solr/client/ServiceSolrClient.java | 142 +++++++++--------- 2 files changed, 77 insertions(+), 81 deletions(-) diff --git a/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java b/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java index 7f1809a944..58c26f38a5 100644 --- a/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java +++ b/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java @@ -327,7 +327,7 @@ public void init(Map initInfo) { logger.info("Calling solrPlugin.init()"); me.init(); - me.setResultProcessor(new RangerSolrAuditHandler(solrPlugin.getConfig())); + me.setResultProcessor(new RangerSolrAuditHandler(me.getConfig())); solrPlugin = me; } @@ -736,7 +736,7 @@ private String getConjunctiveFilterQueryStr(Set roles) { .append(" set_value=\"").append(Joiner.on(',').join(roles.iterator())).append("\"") .append(" count_field=\"").append(tokenCountField).append("\""); - if (allRolesToken != null && !allRolesToken.equals("")) { + if (allRolesToken != null && !allRolesToken.isEmpty()) { filterQuery.append(" wildcard_token=\"").append(allRolesToken).append("\""); } @@ -878,7 +878,7 @@ private String buildSimpleORFilterQuery(String fieldName, Collection att } if (extraOpts != null && !extraOpts.isEmpty()) { - s.append(extraOpts + " "); + s.append(extraOpts).append(" "); } s.deleteCharAt(s.length() - 1); @@ -904,7 +904,7 @@ private String buildSubsetFilterQuery(String fieldName, Collection attri } if (extraOpts != null && !extraOpts.isEmpty()) { - s.append(" " + extraOpts); + s.append(" ").append(extraOpts); } s.append("}"); @@ -917,7 +917,7 @@ private String buildGreaterThanFilterQuery(String fieldName, Collection if (attributeValues.size() == 1) { value = attributeValues.iterator().next(); - } else if (allUsersValue != null && !allUsersValue.equals("")) { + } else if (allUsersValue != null && !allUsersValue.isEmpty()) { value = allUsersValue; } else { throw new IllegalArgumentException("Greater Than Filter Query cannot be built for field " + fieldName); @@ -929,7 +929,7 @@ private String buildGreaterThanFilterQuery(String fieldName, Collection extraClause.append(" (*:* AND -").append(fieldName).append(":*)"); } - if (extraOpts != null && !extraOpts.equals("")) { + if (extraOpts != null && !extraOpts.isEmpty()) { extraClause.append(" ").append(extraOpts); } @@ -941,7 +941,7 @@ private String buildLessThanFilterQuery(String fieldName, Collection att if (attributeValues.size() == 1) { value = attributeValues.iterator().next(); - } else if (allUsersValue != null && !allUsersValue.equals("")) { + } else if (allUsersValue != null && !allUsersValue.isEmpty()) { value = allUsersValue; } else { throw new IllegalArgumentException("Less Than Filter Query cannot be built for field " + fieldName); @@ -953,7 +953,7 @@ private String buildLessThanFilterQuery(String fieldName, Collection att extraClause.append(" (*:* AND -").append(fieldName).append(":*)"); } - if (extraOpts != null && !extraOpts.equals("")) { + if (extraOpts != null && !extraOpts.isEmpty()) { extraClause.append(" ").append(extraOpts); } diff --git a/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java b/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java index 76cd12c5ad..44033b97e5 100644 --- a/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java +++ b/plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java @@ -66,14 +66,14 @@ public class ServiceSolrClient { private static final Logger LOG = LoggerFactory.getLogger(ServiceSolrClient.class); - private final String url; - private final String username; - private final String password; - private final String serviceName; - private final String authType; - private final boolean isKerberosAuth; - - private boolean isSolrCloud; + private final String url; + private final String username; + private final String password; + private final String serviceName; + private final String authType; + private final boolean isKerberosAuth; + private final boolean isSolrCloud; + private Subject loginSubject; private SolrClient solrClient; @@ -161,44 +161,41 @@ public List getResources(ResourceLookupContext context) { if (lookupResource == RangerSolrConstants.ResourceType.COLLECTION) { // get the collection list for given Input - callableObj = new Callable>() { - @Override - public List call() { - List retList = new ArrayList<>(); - - try { - List list = null; - - if (isKerberosAuth) { - list = Subject.doAs(loginSubject, (PrivilegedAction>) () -> { - List ret = null; - - try { - ret = getCollectionList(finalCollectionList); - } catch (Exception e) { - LOG.error("Unable to get collections, Error : {}", e.getMessage(), new Throwable(e)); - } - return ret; - }); - } else { - list = getCollectionList(finalCollectionList); - } + callableObj = () -> { + List retList = new ArrayList<>(); - if (userInputFinal != null && !userInputFinal.isEmpty()) { - for (String value : list) { - if (value.startsWith(userInputFinal)) { - retList.add(value); - } + try { + List list; + + if (isKerberosAuth) { + list = Subject.doAs(loginSubject, (PrivilegedAction>) () -> { + List ret = null; + + try { + ret = getCollectionList(finalCollectionList); + } catch (Exception e) { + LOG.error("Unable to get collections, Error : {}", e.getMessage(), new Throwable(e)); } - } else { - retList.addAll(list); - } - } catch (Exception ex) { - LOG.error("Error getting collections.", ex); + return ret; + }); + } else { + list = getCollectionList(finalCollectionList); } - return retList; + if (userInputFinal != null && !userInputFinal.isEmpty()) { + for (String value : list) { + if (value.startsWith(userInputFinal)) { + retList.add(value); + } + } + } else { + retList.addAll(list); + } + } catch (Exception ex) { + LOG.error("Error getting collections.", ex); } + + return retList; }; } else if (lookupResource == RangerSolrConstants.ResourceType.FIELD) { callableObj = () -> { @@ -221,6 +218,7 @@ public List call() { } else { list = getFieldList(finalCollectionList, finalFieldList); } + if (userInputFinal != null && !userInputFinal.isEmpty()) { for (String value : list) { if (value.startsWith(userInputFinal)) { @@ -295,42 +293,40 @@ public List call() { resultList = retList; } else if (lookupResource == RangerSolrConstants.ResourceType.SCHEMA) { // get the collection list for given Input, since there is no way of getting a list of the available schemas - callableObj = new Callable>() { - @Override - public List call() { - List retList = new ArrayList<>(); - - try { - List list; - - if (isKerberosAuth) { - list = Subject.doAs(loginSubject, (PrivilegedAction>) () -> { - List ret = null; - - try { - ret = getSchemaList(finalSchemaList); - } catch (Exception e) { - LOG.error("Unable to get collections for schema listing, Error : {}", e.getMessage(), new Throwable(e)); - } - return ret; - }); - } else { - list = getSchemaList(finalSchemaList); - } - if (userInputFinal != null && !userInputFinal.isEmpty()) { - for (String value : list) { - if (value.startsWith(userInputFinal)) { - retList.add(value); - } + callableObj = () -> { + List retList = new ArrayList<>(); + + try { + List list; + + if (isKerberosAuth) { + list = Subject.doAs(loginSubject, (PrivilegedAction>) () -> { + List ret = null; + + try { + ret = getSchemaList(finalSchemaList); + } catch (Exception e) { + LOG.error("Unable to get collections for schema listing, Error : {}", e.getMessage(), new Throwable(e)); + } + return ret; + }); + } else { + list = getSchemaList(finalSchemaList); + } + if (userInputFinal != null && !userInputFinal.isEmpty()) { + for (String value : list) { + if (value.startsWith(userInputFinal)) { + retList.add(value); } - } else { - retList.addAll(list); } - } catch (Exception ex) { - LOG.error("Error getting collections for schema listing.", ex); + } else { + retList.addAll(list); } - return retList; + } catch (Exception ex) { + LOG.error("Error getting collections for schema listing.", ex); } + + return retList; }; }