You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2017/09/19 13:08:55 UTC

svn commit: r1808876 - /sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java

Author: sseifert
Date: Tue Sep 19 13:08:55 2017
New Revision: 1808876

URL: http://svn.apache.org/viewvc?rev=1808876&view=rev
Log:
SLING-6935 fix NPE when no config name is given
default content path to /content
fallback to web console resource resolver if no valid system user mapping is configured

Modified:
    sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java

Modified: sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java?rev=1808876&r1=1808875&r2=1808876&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java (original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/management/impl/console/ConfigurationWebConsolePlugin.java Tue Sep 19 13:08:55 2017
@@ -112,7 +112,7 @@ public class ConfigurationWebConsolePlug
     }
 
     private void printResolutionTestTool(HttpServletRequest request, PrintWriter pw) {
-        final String path = this.getParameter(request, "path", null);
+        final String path = this.getParameter(request, "path", "/content");
         String configNameOther = this.getParameter(request, "configNameOther", null);
         String configName = this.getParameter(request, "configName", null);
         if (configName == null) {
@@ -127,7 +127,7 @@ public class ConfigurationWebConsolePlug
         try {
             Resource contentResource = null;
             if (path != null) {
-                resolver = getResolver();
+                resolver = getResolver(request);
                 if (resolver != null) {
                     contentResource = resolver.getResource(path);
                 }
@@ -166,7 +166,7 @@ public class ConfigurationWebConsolePlug
 
             pw.println("<br/>");
 
-            if (contentResource != null) {
+            if (contentResource != null && configName != null) {
                 
                 // context paths
                 Iterator<ContextResource> contextResources = contextPathStrategyMultiplexer.findContextResources(contentResource);
@@ -375,14 +375,22 @@ public class ConfigurationWebConsolePlug
         pw.print("</td>");
     }
 
-    private ResourceResolver getResolver() {
+    private ResourceResolver getResolver(HttpServletRequest request) {
+        ResourceResolver resolver = null;
         try {
-            return resolverFactory.getServiceResourceResolver(null);
+            resolver = resolverFactory.getServiceResourceResolver(null);
         }
         catch (final LoginException ex) {
-            log.warn("Unable to get resource resolver - please ensure a system user is configured: {}", ex.getMessage());
-            return null;
+            // fallback if no service user is registered - try to get current web console resource resolver
+            resolver = (ResourceResolver)request.getAttribute("org.apache.sling.auth.core.ResourceResolver");
+            if (resolver == null) {
+                log.warn("Unable to get resource resolver - please ensure a system user is configured: {}", ex.getMessage());
+            }
+            else {
+                log.debug("No system user configured, use resource resolver from web console.");
+            }
         }
+        return resolver;
     }
 
 }