Repository: ranger Updated Branches: refs/heads/master e52e2b271 -> 11bcd728e
RANGER-1658:Solr gives NPE while printing the AuthorizationContext in INFO and DEBUG log Signed-off-by: rmani <rm...@hortonworks.com> Project: http://git-wip-us.apache.org/repos/asf/ranger/repo Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/11bcd728 Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/11bcd728 Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/11bcd728 Branch: refs/heads/master Commit: 11bcd728ef103a1dd34a6d3f2b386bbaaa9ba550 Parents: e52e2b2 Author: rmani <rm...@hortonworks.com> Authored: Tue Jun 20 16:45:00 2017 -0700 Committer: rmani <rm...@hortonworks.com> Committed: Mon Jun 26 13:32:16 2017 -0700 ---------------------------------------------------------------------- .../solr/authorizer/RangerSolrAuthorizer.java | 40 +++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ranger/blob/11bcd728/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java ---------------------------------------------------------------------- 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 bf22b47..0cc9de9 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 @@ -162,6 +162,7 @@ public class RangerSolrAuthorizer implements AuthorizationPlugin { try { if (logger.isDebugEnabled()) { + logger.debug("==> RangerSolrAuthorizer.authorize()"); logAuthorizationConext(context); } @@ -228,7 +229,7 @@ public class RangerSolrAuthorizer implements AuthorizationPlugin { response = new AuthorizationResponse(200); } if (logger.isDebugEnabled()) { - logger.debug("context=" + context + ": returning: " + isDenied); + logger.debug( "<== RangerSolrAuthorizer.authorize() result: " + isDenied + "Response : " + response.getMessage()); } return response; } @@ -238,9 +239,7 @@ public class RangerSolrAuthorizer implements AuthorizationPlugin { */ private void logAuthorizationConext(AuthorizationContext context) { try { - // Note: This method should be called with isDebugEnabled() or - // isInfoEnabled() scope - + // Note: This method should be called with isDebugEnabled() String collections = ""; int i = -1; for (CollectionRequest collectionRequest : context @@ -280,15 +279,30 @@ public class RangerSolrAuthorizer implements AuthorizationPlugin { String userName = getUserName(context); Set<String> groups = getGroupsForUser(userName); - - logger.info("AuthorizationContext: context.getResource()=" - + context.getResource() + ", solarParams=" - + context.getParams() + ", requestType=" - + context.getRequestType() + ", ranger.requestType=" - + mapToRangerAccessType(context) + ", userPrincipal=" - + context.getUserPrincipal() + ", userName=" + userName - + ", groups=" + groups + ", ipAddress=" + ipAddress - + ", collections=" + collections + ", headers=" + headers); + String resource = context.getResource(); + String solrParams = ""; + try { + solrParams = context.getParams().toQueryString(); + } catch (Throwable t) { + //Exception ignored + } + RequestType requestType = context.getRequestType(); + String accessType = mapToRangerAccessType(context); + Principal principal = context.getUserPrincipal(); + + String contextString = new String("AuthorizationContext: "); + contextString = contextString + "context.getResource()= " + ((resource != null ) ? resource : ""); + contextString = contextString + ", solarParams= " + (( solrParams != null ) ? solrParams : ""); + contextString = contextString + ", requestType= " + (( requestType != null ) ? requestType : ""); + contextString = contextString + ", ranger.requestType= " + ((accessType != null ) ? accessType : ""); + contextString = contextString + ", userPrincipal= " + ((principal != null ) ? principal : ""); + contextString = contextString + ", userName= " + userName; + contextString = contextString + ", groups= " + groups; + contextString = contextString + ", ipAddress= " + ipAddress; + contextString = contextString + ", collections= " + collections; + contextString = contextString + ", headers= " + headers; + + logger.debug(contextString); } catch (Throwable t) { logger.error("Error getting request context!!!", t); }