jsedding commented on code in PR #11:
URL:
https://github.com/apache/sling-org-apache-sling-jcr-base/pull/11#discussion_r1334302571
##########
src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java:
##########
@@ -47,34 +45,28 @@
* use the loginAdministrative method.
*/
@Component(service = LoginAdminAllowList.class,
- configurationPid = LoginAdminAllowList.PID,
- reference = {
- // ConfigurationUpdater is a required dependency to make sure that
configurations are
- // updated before this component is activated
- @Reference(
- name = "ConfigurationUpdater",
- service = ConfigurationUpdater.class,
- cardinality = ReferenceCardinality.MANDATORY
- )
- }
-)
-@Designate(
- ocd = LoginAdminAllowListConfiguration.class
+ configurationPid = {LoginAdminAllowList.PID,
LoginAdminAllowList.LEGACY_PID}
Review Comment:
I think the two PIDs should be swapped around. The later PID has higher
precedence.
##########
src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java:
##########
@@ -83,23 +75,22 @@ public class LoginAdminAllowList {
cardinality = ReferenceCardinality.MULTIPLE,
policy = ReferencePolicy.DYNAMIC,
policyOption = ReferencePolicyOption.GREEDY
- ) @SuppressWarnings("unused")
+ )
void bindAllowListFragment(AllowListFragment fragment) {
allowListFragments.add(fragment);
LOG.info("AllowListFragment added '{}'", fragment);
}
- @SuppressWarnings("unused")
void unbindAllowListFragment(AllowListFragment fragment) {
allowListFragments.remove(fragment);
LOG.info("AllowListFragment removed '{}'", fragment);
}
- @Activate @Modified @SuppressWarnings("unused")
- void configure(LoginAdminAllowListConfiguration configuration, Map<String,
Object> properties) {
- this.config = new ConfigurationState(configuration);
- ensureBackwardsCompatibility(properties,
PROP_WHITELIST_BUNDLES_DEFAULT);
- ensureBackwardsCompatibility(properties,
PROP_WHITELIST_BUNDLES_ADDITIONAL);
+ @Activate @Modified
+ void configure(final LoginAdminAllowListConfiguration configuration, final
Map<String, Object> properties) {
Review Comment:
What about using a second annotation, without metatype, like you did with
the
[`VanityPathConfigurer.DeprecatedVanityConfig`](https://github.com/apache/sling-org-apache-sling-resourceresolver/blob/a24a17467b334f9076f91c2dccd2491dfc9ae96b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java#L221)?
##########
src/main/java/org/apache/sling/jcr/base/internal/LegacyFragment.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.base.internal;
+
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.util.converter.Converters;
+
+import java.util.Map;
+
+/**
+ * Legacy fragment configuration. Use {@link AllowListFragment} instead.
+ */
+@Component(
+ configurationPid = LegacyFragment.LEGACY_FACTORY_PID,
+ configurationPolicy = ConfigurationPolicy.REQUIRE,
+ service = LegacyFragment.class
+)
+public class LegacyFragment {
+
+ public static final String LEGACY_FACTORY_PID =
"org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment";
+
+ private static final String LEGACY_NAME = "whitelist.name";
+ private static final String LEGACY_BUNDLES = "whitelist.bundles";
+
+ private final AllowListFragment fragment;
+
+ private final LoginAdminAllowList allowList;
+
+ @Activate
+ public LegacyFragment(final @Reference LoginAdminAllowList allowList,
final Map<String, Object> config) {
+ LoginAdminAllowList.LOG.warn("Using deprecated factory configuration
'{}'. " +
+ "Update your configuration to use configuration '{}' instead.",
+ LEGACY_FACTORY_PID, AllowListFragment.FACTORY_PID);
+ this.allowList = allowList;
+ final String name =
Converters.standardConverter().convert(config.get(LEGACY_NAME)).to(String.class);
+ final String[] bundles =
Converters.standardConverter().convert(config.get(LEGACY_BUNDLES)).to(String[].class);
+ this.fragment = new AllowListFragment(name, bundles);
+ this.allowList.bindAllowListFragment(fragment);
Review Comment:
As an alternative to manual binding/unbinding, we could extend
`LegacyFragment` from `AllowListFragment`, registering it as an
`AllowListFragment` service. The configuration could be injected via annotation
object, but without metatype, and the values passed to the
`AllowListFragment(String name, String[] bundles)` constructor. I think this
would simplify the code further.
##########
src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java:
##########
@@ -133,24 +124,47 @@ public boolean allowLoginAdministrative(Bundle b) {
}
// encapsulate configuration state for atomic configuration updates
- private static class ConfigurationState {
+ static class ConfigurationState {
+
+ public final boolean bypassAllowList;
- private final boolean bypassAllowList;
+ public final Pattern allowListRegexp;
- private final Pattern allowListRegexp;
+ ConfigurationState(final LoginAdminAllowListConfiguration config,
final Map<String, Object> properties) {
+ // first check for legacy properties
+ boolean bypass = config.allowlist_bypass();
+ final Object legacyBypassObject =
properties.get(LEGACY_BYPASS_PROPERTY);
+ if (legacyBypassObject != null) {
+ LOG.warn("Using deprecated configuration property '{}' from
configuration '{}'. " +
+ "Update your configuration to use configuration '{}' and
property '{}' instead.",
+ LEGACY_BYPASS_PROPERTY, LEGACY_PID, PID,
"allowlist.bypass");
+ bypass =
Converters.standardConverter().convert(legacyBypassObject).defaultValue(false).to(Boolean.class);
+ }
+ String legacyRegexp = null;
+ final Object legacyBundlesObject =
properties.get(LEGACY_BUNDLES_PROPERTY);
+ if (legacyBypassObject != null) {
+ LOG.warn("Using deprecated configuration property '{}' from
configuration '{}'. " +
+ "Update your configuration to use configuration '{}' and
property '{}' instead.",
+ LEGACY_BUNDLES_PROPERTY, LEGACY_PID, PID,
"allowlist.bundles.regexp");
+ legacyRegexp =
Converters.standardConverter().convert(legacyBundlesObject).to(String.class);
+ }
- private ConfigurationState(final LoginAdminAllowListConfiguration
config) {
final String regexp = config.allowlist_bundles_regexp();
- if(regexp.trim().length() > 0) {
- allowListRegexp = Pattern.compile(regexp);
- LOG.warn("A 'allowlist.bundles.regexp' is configured, this is
NOT RECOMMENDED for production: {}",
- allowListRegexp);
+ if (regexp.trim().length() > 0) {
+ if (legacyRegexp != null) {
+ LOG.warn("Both deprecated configuration property '{}' and
configuration property '{}' are set. " +
Review Comment:
IMHO it could be clearer that the second property name is not deprecated.
Maybe reword to something like "... and its non-deprecated equivalent '{}' are
set.". WDYT?
##########
src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java:
##########
@@ -133,24 +124,47 @@ public boolean allowLoginAdministrative(Bundle b) {
}
// encapsulate configuration state for atomic configuration updates
- private static class ConfigurationState {
+ static class ConfigurationState {
+
+ public final boolean bypassAllowList;
- private final boolean bypassAllowList;
+ public final Pattern allowListRegexp;
- private final Pattern allowListRegexp;
+ ConfigurationState(final LoginAdminAllowListConfiguration config,
final Map<String, Object> properties) {
+ // first check for legacy properties
+ boolean bypass = config.allowlist_bypass();
+ final Object legacyBypassObject =
properties.get(LEGACY_BYPASS_PROPERTY);
+ if (legacyBypassObject != null) {
+ LOG.warn("Using deprecated configuration property '{}' from
configuration '{}'. " +
+ "Update your configuration to use configuration '{}' and
property '{}' instead.",
+ LEGACY_BYPASS_PROPERTY, LEGACY_PID, PID,
"allowlist.bypass");
+ bypass =
Converters.standardConverter().convert(legacyBypassObject).defaultValue(false).to(Boolean.class);
+ }
+ String legacyRegexp = null;
+ final Object legacyBundlesObject =
properties.get(LEGACY_BUNDLES_PROPERTY);
+ if (legacyBypassObject != null) {
+ LOG.warn("Using deprecated configuration property '{}' from
configuration '{}'. " +
+ "Update your configuration to use configuration '{}' and
property '{}' instead.",
+ LEGACY_BUNDLES_PROPERTY, LEGACY_PID, PID,
"allowlist.bundles.regexp");
+ legacyRegexp =
Converters.standardConverter().convert(legacyBundlesObject).to(String.class);
+ }
- private ConfigurationState(final LoginAdminAllowListConfiguration
config) {
final String regexp = config.allowlist_bundles_regexp();
- if(regexp.trim().length() > 0) {
- allowListRegexp = Pattern.compile(regexp);
- LOG.warn("A 'allowlist.bundles.regexp' is configured, this is
NOT RECOMMENDED for production: {}",
- allowListRegexp);
+ if (regexp.trim().length() > 0) {
+ if (legacyRegexp != null) {
+ LOG.warn("Both deprecated configuration property '{}' and
configuration property '{}' are set. " +
+ "The deprecated property '{}' is ignored.",
+ LEGACY_BUNDLES_PROPERTY, "allowlist.bundles.regexp",
LEGACY_BUNDLES_PROPERTY);
+ }
+ this.allowListRegexp = Pattern.compile(regexp);
} else {
- allowListRegexp = null;
+ this.allowListRegexp = legacyRegexp != null ?
Pattern.compile(legacyRegexp) : null;
}
-
- bypassAllowList = config.allowlist_bypass();
- if(bypassAllowList) {
+ if (this.allowListRegexp != null) {
+ LOG.warn("A 'allowlist.bundles.regexp' is configured, this is
NOT RECOMMENDED for production: {}", allowListRegexp);
Review Comment:
Should we deprecate the regexp for removal? And only leave support for
"whitelist.bundles.regexp"?
##########
src/main/java/org/apache/sling/jcr/base/internal/LoginAdminAllowList.java:
##########
@@ -133,24 +124,47 @@ public boolean allowLoginAdministrative(Bundle b) {
}
// encapsulate configuration state for atomic configuration updates
- private static class ConfigurationState {
+ static class ConfigurationState {
+
+ public final boolean bypassAllowList;
- private final boolean bypassAllowList;
+ public final Pattern allowListRegexp;
- private final Pattern allowListRegexp;
+ ConfigurationState(final LoginAdminAllowListConfiguration config,
final Map<String, Object> properties) {
+ // first check for legacy properties
+ boolean bypass = config.allowlist_bypass();
+ final Object legacyBypassObject =
properties.get(LEGACY_BYPASS_PROPERTY);
+ if (legacyBypassObject != null) {
+ LOG.warn("Using deprecated configuration property '{}' from
configuration '{}'. " +
+ "Update your configuration to use configuration '{}' and
property '{}' instead.",
+ LEGACY_BYPASS_PROPERTY, LEGACY_PID, PID,
"allowlist.bypass");
+ bypass =
Converters.standardConverter().convert(legacyBypassObject).defaultValue(false).to(Boolean.class);
+ }
+ String legacyRegexp = null;
+ final Object legacyBundlesObject =
properties.get(LEGACY_BUNDLES_PROPERTY);
+ if (legacyBypassObject != null) {
+ LOG.warn("Using deprecated configuration property '{}' from
configuration '{}'. " +
+ "Update your configuration to use configuration '{}' and
property '{}' instead.",
+ LEGACY_BUNDLES_PROPERTY, LEGACY_PID, PID,
"allowlist.bundles.regexp");
+ legacyRegexp =
Converters.standardConverter().convert(legacyBundlesObject).to(String.class);
+ }
- private ConfigurationState(final LoginAdminAllowListConfiguration
config) {
final String regexp = config.allowlist_bundles_regexp();
- if(regexp.trim().length() > 0) {
- allowListRegexp = Pattern.compile(regexp);
- LOG.warn("A 'allowlist.bundles.regexp' is configured, this is
NOT RECOMMENDED for production: {}",
- allowListRegexp);
+ if (regexp.trim().length() > 0) {
+ if (legacyRegexp != null) {
+ LOG.warn("Both deprecated configuration property '{}' and
configuration property '{}' are set. " +
+ "The deprecated property '{}' is ignored.",
+ LEGACY_BUNDLES_PROPERTY, "allowlist.bundles.regexp",
LEGACY_BUNDLES_PROPERTY);
+ }
+ this.allowListRegexp = Pattern.compile(regexp);
} else {
- allowListRegexp = null;
+ this.allowListRegexp = legacyRegexp != null ?
Pattern.compile(legacyRegexp) : null;
}
-
- bypassAllowList = config.allowlist_bypass();
- if(bypassAllowList) {
+ if (this.allowListRegexp != null) {
+ LOG.warn("A 'allowlist.bundles.regexp' is configured, this is
NOT RECOMMENDED for production: {}", allowListRegexp);
+ }
+ this.bypassAllowList = bypass;
+ if (this.bypassAllowList) {
LOG.info("bypassAllowlist=true, allowlisted BSNs=<ALL>");
LOG.warn("All bundles are allowed to use loginAdministrative
due to the 'allowlist.bypass' " +
Review Comment:
Deprecate for removal? Or is it too useful for development?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]