sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1765978 - in /sling/trunk/bundles/jcr/base/src: main/java/org/apache/sling/jcr/base/internal/ test/java/org/apache/sling/jcr/base/internal/
Date Fri, 21 Oct 2016 10:05:23 GMT
Author: bdelacretaz
Date: Fri Oct 21 10:05:23 2016
New Revision: 1765978

URL: http://svn.apache.org/viewvc?rev=1765978&view=rev
Log:
SLING-5135 - move default whitelist to its own class to better keep track of it

Added:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/DefaultWhitelist.java
      - copied, changed from r1765976, sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java
Modified:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java
    sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImplTest.java

Copied: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/DefaultWhitelist.java
(from r1765976, sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/DefaultWhitelist.java?p2=sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/DefaultWhitelist.java&p1=sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java&r1=1765976&r2=1765978&rev=1765978&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java
(original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/DefaultWhitelist.java
Fri Oct 21 10:05:23 2016
@@ -35,52 +35,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Whitelist that defines which bundles can use the
- * {@link SlingRepository#loginAdministrative} method.
- *
- * The default configuration lets a few trusted Sling bundles
- * use the loginAdministrative method.
+ * Define the default whitelist in its own class to better
+ * keep track of it. The goal is to reduce it to the bare
+ * minimum over time.
  */
-@Service(value=LoginAdminWhitelist.class)
-@Component(
-        label="Login Admin Whitelist",
-        description="Defines which bundles can use SlingRepository.loginAdministrative()",
-        metatype=true)
-public class LoginAdminWhitelistImpl implements LoginAdminWhitelist {
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    /** Need to allow for bypassing the whitelist, for backwards
-     *  compatibility with previous Sling versions which didn't
-     *  implement it. Setting this to true is not recommended
-     *  and logged as a warning.
-     */
-    @Property(
-            label="Bypass the whitelist",
-            description=
-                "Allow all bundles to use loginAdministrative(). "
-                + "Should ONLY be used for backwards compatiblity reasons and "
-                + "if you are aware of the related security risks.",
-            boolValue=false)
-    public static final String PROP_BYPASS_WHITELIST = "whitelist.bypass";
-    public static final boolean DEFAULT_BYPASS = false;
-    private boolean bypassWhitelist = DEFAULT_BYPASS;
-
-    @Property(
-            label="Whitelist regexp",
-            description="Regular expression for bundle symbolic names for which loginAdministrative()
is allowed. "
-                + " NOT recommended for production use, but useful for testing with generated
bundles.",
-            value = "")
-    public static final String PROP_WHITELIST_REGEXP = "whitelist.regexp";
-    private Pattern whitelistRegexp;
-
-    @Property(
-            label="Whitelisted BSNs",
-            description="List of bundle symbolic names for which loginAdministrative() is
allowed",
-            value = {})
-    public static final String PROP_WHITELISTED_BSN = "whitelisted.bundle.symbolic.names";
-    private Set<String> whitelistedBsn;
-
-    static final String [] DEFAULT_WHITELISTED_BSN = {
+class DefaultWhitelist {
+    static final String [] WHITELISTED_BSN = {
             "org.apache.sling.discovery.commons",
             "org.apache.sling.discovery.base",
             "org.apache.sling.discovery.oak",
@@ -103,53 +63,4 @@ public class LoginAdminWhitelistImpl imp
             "org.apache.sling.servlets.resolver",
             "org.apache.sling.xss"
     };
-
-    public void activate(Map<String, Object> config) {
-        bypassWhitelist = PropertiesUtil.toBoolean(config.get(PROP_BYPASS_WHITELIST), DEFAULT_BYPASS);
-        whitelistedBsn = new TreeSet<String>();
-        final Object bsns = config.get(PROP_WHITELISTED_BSN);
-        if(bsns == null) {
-            whitelistedBsn.addAll(Arrays.asList(DEFAULT_WHITELISTED_BSN));
-        } else {
-            whitelistedBsn.addAll(Arrays.asList(PropertiesUtil.toStringArray(bsns)));
-        }
-
-        final String regexp = PropertiesUtil.toString(config.get(PROP_WHITELIST_REGEXP),
"");
-        if(regexp.trim().length() > 0) {
-            whitelistRegexp = Pattern.compile(regexp);
-            log.warn("A {} is configured, this is NOT RECOMMENDED for production: {}", PROP_WHITELIST_REGEXP,
whitelistRegexp);
-        } else {
-            whitelistRegexp = null;
-        }
-
-        if(bypassWhitelist) {
-            log.info("bypassWhitelist={}, whitelisted BSNs=<ALL>", bypassWhitelist);
-            log.warn(
-                "All bundles are allowed to use loginAdministrative due to the 'bypass whitelist'
configuration"
-                + " of this service. This is NOT RECOMMENDED, for security reasons."
-            );
-        } else {
-            log.info("bypassWhitelist={}, whitelisted BSNs({})={}",
-                    new Object[] { bypassWhitelist, whitelistedBsn.size(), whitelistedBsn
});
-        }
-    }
-
-    @Override
-    public boolean allowLoginAdministrative(Bundle b) {
-        if(bypassWhitelist) {
-            log.debug("Whitelist is bypassed, all bundles allowed to use loginAdministrative");
-            return true;
-        }
-
-        final String bsn = b.getSymbolicName();
-        if(whitelistRegexp != null && whitelistRegexp.matcher(bsn).matches()) {
-            log.debug("{} is whitelisted to use loginAdministrative, by regexp", bsn);
-            return true;
-        } else if(whitelistedBsn.contains(bsn)) {
-            log.debug("{} is whitelisted to use loginAdministrative, by explicit whitelist",
bsn);
-            return true;
-        }
-        log.debug("{} is not whitelisted to use loginAdministrative", bsn);
-        return false;
-    }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java?rev=1765978&r1=1765977&r2=1765978&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java
(original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImpl.java
Fri Oct 21 10:05:23 2016
@@ -80,36 +80,12 @@ public class LoginAdminWhitelistImpl imp
     public static final String PROP_WHITELISTED_BSN = "whitelisted.bundle.symbolic.names";
     private Set<String> whitelistedBsn;
 
-    static final String [] DEFAULT_WHITELISTED_BSN = {
-            "org.apache.sling.discovery.commons",
-            "org.apache.sling.discovery.base",
-            "org.apache.sling.discovery.oak",
-            "org.apache.sling.extensions.webconsolesecurityprovider",
-            "org.apache.sling.i18n",
-            "org.apache.sling.installer.provider.jcr",
-            "org.apache.sling.jcr.base",
-            "org.apache.sling.jcr.contentloader",
-            "org.apache.sling.jcr.davex",
-            "org.apache.sling.jcr.jackrabbit.usermanager",
-            "org.apache.sling.jcr.oak.server",
-            "org.apache.sling.jcr.resource",
-            "org.apache.sling.jcr.webconsole",
-            "org.apache.sling.jcr.webdav",
-            "org.apache.sling.junit.core",
-            "org.apache.sling.resourceresolver",
-            "org.apache.sling.scripting.core",
-            "org.apache.sling.scripting.sightly",
-            "org.apache.sling.servlets.post",
-            "org.apache.sling.servlets.resolver",
-            "org.apache.sling.xss"
-    };
-
     public void activate(Map<String, Object> config) {
         bypassWhitelist = PropertiesUtil.toBoolean(config.get(PROP_BYPASS_WHITELIST), DEFAULT_BYPASS);
         whitelistedBsn = new TreeSet<String>();
         final Object bsns = config.get(PROP_WHITELISTED_BSN);
         if(bsns == null) {
-            whitelistedBsn.addAll(Arrays.asList(DEFAULT_WHITELISTED_BSN));
+            whitelistedBsn.addAll(Arrays.asList(DefaultWhitelist.WHITELISTED_BSN));
         } else {
             whitelistedBsn.addAll(Arrays.asList(PropertiesUtil.toStringArray(bsns)));
         }

Modified: sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImplTest.java?rev=1765978&r1=1765977&r2=1765978&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImplTest.java
(original)
+++ sling/trunk/bundles/jcr/base/src/test/java/org/apache/sling/jcr/base/internal/LoginAdminWhitelistImplTest.java
Fri Oct 21 10:05:23 2016
@@ -62,7 +62,7 @@ public class LoginAdminWhitelistImplTest
     public void testDefaultConfig() {
         whitelist.activate(config);
         
-        for(String bsn : LoginAdminWhitelistImpl.DEFAULT_WHITELISTED_BSN) {
+        for(String bsn : DefaultWhitelist.WHITELISTED_BSN) {
             assertAdminLogin(bsn, true);
         }
         



Mime
View raw message