This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git
The following commit(s) were added to refs/heads/master by this push:
new 9c42ec0 SLING-10255 : Refactor: Move auth handlers management into
separate component
9c42ec0 is described below
commit 9c42ec0ed84607c762ba382f9a9adafd811ca2e7
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Mar 24 12:10:53 2021 +0100
SLING-10255 : Refactor: Move auth handlers management into separate
component
---
.../core/impl/AuthenticationHandlersManager.java | 187 +++++++++++++++++++++
.../core/impl/AuthenticatorWebConsolePlugin.java | 21 ++-
.../sling/auth/core/impl/SlingAuthenticator.java | 181 ++++----------------
.../AuthenticationRequirementsManagerTest.java | 33 ++--
.../auth/core/impl/SlingAuthenticatorOsgiTest.java | 1 +
.../auth/core/impl/SlingAuthenticatorTest.java | 155 +++++++----------
6 files changed, 302 insertions(+), 276 deletions(-)
diff --git
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
new file mode 100644
index 0000000..dbfb103
--- /dev/null
+++
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlersManager.java
@@ -0,0 +1,187 @@
+/*
+ * 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.auth.core.impl;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+
+import
org.apache.sling.auth.core.impl.engine.EngineAuthenticationHandlerHolder;
+import org.apache.sling.auth.core.spi.AuthenticationHandler;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.util.converter.Converters;
+
+@Component(service = {AuthenticationHandlersManager.class},
+ configurationPid = SlingAuthenticator.PID)
+public class AuthenticationHandlersManager extends
PathBasedHolderCache<AbstractAuthenticationHandlerHolder> {
+
+ /** Handler map for authentication handlers */
+ private final Map<String, List<AbstractAuthenticationHandlerHolder>>
handlerMap = new ConcurrentHashMap<>();
+
+ private final Boolean httpSupport;
+
+ @Activate
+ public AuthenticationHandlersManager(final SlingAuthenticator.Config
config) {
+ final String http = SlingAuthenticator.getHttpAuth(config);
+ if (SlingAuthenticator.HTTP_AUTH_DISABLED.equals(http)) {
+ this.httpSupport = null;
+ } else {
+ this.httpSupport =
SlingAuthenticator.HTTP_AUTH_ENABLED.equals(http);
+ }
+ }
+
+ /**
+ * Returns the list of registered authentication handlers as a map for the
web console
+ */
+ Map<String, List<String>> getAuthenticationHandlerMap() {
+ final List<AbstractAuthenticationHandlerHolder> registeredHolders =
this.getHolders();
+ final LinkedHashMap<String, List<String>> handlerMap = new
LinkedHashMap<String, List<String>>();
+ for (final AbstractAuthenticationHandlerHolder holder :
registeredHolders) {
+ final List<String> provider =
handlerMap.computeIfAbsent(holder.fullPath, key -> new ArrayList<>());
+ provider.add(holder.getProvider());
+ }
+ if (httpSupport != null) {
+ final List<String> provider = handlerMap.computeIfAbsent("/", key
-> new ArrayList<>());
+ provider.add("HTTP Basic Authentication Handler ("
+ + (httpSupport ? "enabled" : "preemptive") + ")");
+ }
+ return handlerMap;
+ }
+
+ /**
+ * Bind authentication handler
+ * @param ref Service reference
+ * @param handler The handler
+ */
+ @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy =
ReferencePolicy.DYNAMIC)
+ private void bindAuthHandler(final AuthenticationHandler handler, final
ServiceReference<Object> ref) {
+ final String id =
"A".concat(ref.getProperty(Constants.SERVICE_ID).toString());
+ final String[] paths =
Converters.standardConverter().convert(ref.getProperty(AuthenticationHandler.PATH_PROPERTY)).to(String[].class);
+ internalBindAuthHandler(paths, id, path -> {
+ return new AuthenticationHandlerHolder(path,
+ handler,
+ ref);
+ });
+ }
+
+ /**
+ * Update authentication handler
+ * @param ref Service reference
+ * @param handler The handler
+ */
+ private void updatedAuthHandler(final AuthenticationHandler handler, final
ServiceReference<Object> ref) {
+ unbindAuthHandler(ref);
+ bindAuthHandler(handler, ref);
+ }
+
+ /**
+ * Unbind authentication handler
+ * @param ref Service Reference
+ */
+ private void unbindAuthHandler(final ServiceReference<Object> ref) {
+ final String id =
"A".concat(ref.getProperty(Constants.SERVICE_ID).toString());
+ internalUnbindAuthHandler(id);
+ }
+
+ /**
+ * Bind old engine authentication handler
+ * @param ref Service reference
+ * @param handler The handler
+ */
+ @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy =
ReferencePolicy.DYNAMIC)
+ private void bindEngineAuthHandler(final
org.apache.sling.engine.auth.AuthenticationHandler handler, final
ServiceReference<Object> ref) {
+ final String id =
"E".concat(ref.getProperty(Constants.SERVICE_ID).toString());
+ final String[] paths =
Converters.standardConverter().convert(ref.getProperty(AuthenticationHandler.PATH_PROPERTY)).to(String[].class);
+ internalBindAuthHandler(paths, id, path -> {
+ return new EngineAuthenticationHandlerHolder(path,
+ handler,
+ ref);
+ });
+ }
+
+ /**
+ * Update old engine authentication handler
+ * @param ref Service reference
+ * @param handler The handler
+ */
+ private void updatedEngineAuthHandler(final
org.apache.sling.engine.auth.AuthenticationHandler handler, final
ServiceReference<Object> ref) {
+ unbindEngineAuthHandler(ref);
+ bindEngineAuthHandler(handler, ref);
+ }
+
+ /**
+ * Unbind old engine authentication handler
+ * @param ref Service Reference
+ */
+ private void unbindEngineAuthHandler(final ServiceReference<Object> ref) {
+ final String id =
"E".concat(ref.getProperty(Constants.SERVICE_ID).toString());
+ internalUnbindAuthHandler(id);
+ }
+
+ /**
+ * Bind an authentication handler
+ * @param paths The paths
+ * @param id Unique id
+ * @param createFunction Creation callback
+ */
+ private void internalBindAuthHandler(final String[] paths, final String
id, final Function<String, AbstractAuthenticationHandlerHolder> createFunction)
{
+ if (paths != null && paths.length > 0) {
+
+ // generate the holders
+ ArrayList<AbstractAuthenticationHandlerHolder> holderList = new
ArrayList<AbstractAuthenticationHandlerHolder>();
+ for (String path : paths) {
+ if (path != null && path.length() > 0) {
+ holderList.add(createFunction.apply(path));
+ }
+ }
+ // register the holders
+ if ( !holderList.isEmpty() ) {
+ for(final AbstractAuthenticationHandlerHolder holder :
holderList) {
+ this.addHolder(holder);
+ }
+ }
+
+ // keep a copy of them for unregistration later
+ handlerMap.put(id, holderList);
+ }
+ }
+
+ /**
+ * Unbind authentication handler
+ * @param id Unqiue id
+ */
+ private void internalUnbindAuthHandler(final String id) {
+ final List<AbstractAuthenticationHandlerHolder> holders =
handlerMap.remove(id);
+
+ if (holders != null) {
+ for (AbstractAuthenticationHandlerHolder holder : holders) {
+ this.removeHolder(holder);
+ }
+ }
+ }
+}
diff --git
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java
index bc5702c..b01a85f 100644
---
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java
+++
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticatorWebConsolePlugin.java
@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.sling.api.request.ResponseUtil;
+import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.propertytypes.ServiceDescription;
@@ -37,6 +38,7 @@ import org.osgi.service.component.propertytypes.ServiceVendor;
@SuppressWarnings("serial")
@Component(service = Servlet.class,
+ configurationPid = SlingAuthenticator.PID,
property = {
"felix.webconsole.label=" + AuthenticatorWebConsolePlugin.LABEL,
"felix.webconsole.title=" + AuthenticatorWebConsolePlugin.TITLE,
@@ -55,8 +57,15 @@ public class AuthenticatorWebConsolePlugin extends
HttpServlet {
private PathBasedHolderCache<AuthenticationRequirementHolder>
authenticationRequirementsManager;
@Reference
- private SlingAuthenticator slingAuthenticator;
+ private AuthenticationHandlersManager authenticationHoldersManager;
+ private final SlingAuthenticator.Config config;
+
+ @Activate
+ public AuthenticatorWebConsolePlugin(final SlingAuthenticator.Config
config) {
+ this.config = config;
+ }
+
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -96,7 +105,7 @@ public class AuthenticatorWebConsolePlugin extends
HttpServlet {
pw.println("<th class='content' colspan='2'>Handler</td>");
pw.println("</tr>");
- final Map<String, List<String>> handlerMap =
slingAuthenticator.getAuthenticationHandler();
+ final Map<String, List<String>> handlerMap =
authenticationHoldersManager.getAuthenticationHandlerMap();
for (final Map.Entry<String, List<String>> handler :
handlerMap.entrySet()) {
final String path = handler.getKey();
for (final String name : handler.getValue()) {
@@ -131,9 +140,9 @@ public class AuthenticatorWebConsolePlugin extends
HttpServlet {
}
private void printAuthenticationConfiguration(final PrintWriter pw) {
- final String anonUser = slingAuthenticator.getAnonUserName();
- final String sudoCookie = slingAuthenticator.getSudoCookieName();
- final String sudoParam = slingAuthenticator.getSudoParameterName();
+ final String anonUser = (this.config.sling_auth_anonymous_user() !=
null && this.config.sling_auth_anonymous_user().isEmpty()) ?
this.config.sling_auth_anonymous_user() : "(default)";
+ final String sudoCookie = this.config.auth_sudo_cookie();
+ final String sudoParam = this.config.auth_sudo_parameter();
pw.println("<tr>");
pw.println("<th class='content container' colspan='3'>Miscellaneous
Configuration</td>");
@@ -149,7 +158,7 @@ public class AuthenticatorWebConsolePlugin extends
HttpServlet {
pw.println("</tr>");
pw.println("<tr>");
pw.println("<td class='content'>Anonymous User Name</td>");
- pw.printf("<td class='content' colspan='2'>%s</td>%n", (anonUser ==
null) ? "(default)" : ResponseUtil.escapeXml(anonUser));
+ pw.printf("<td class='content' colspan='2'>%s</td>%n",
ResponseUtil.escapeXml(anonUser));
pw.println("</tr>");
}
}
diff --git
a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
index 6f03a97..5c5ebef 100644
--- a/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
+++ b/src/main/java/org/apache/sling/auth/core/impl/SlingAuthenticator.java
@@ -104,7 +104,7 @@ import org.slf4j.LoggerFactory;
* URL.
*/
@Component(name = SlingAuthenticator.PID,
- service = {Authenticator.class, AuthenticationSupport.class,
ServletRequestListener.class, SlingAuthenticator.class })
+ service = {Authenticator.class, AuthenticationSupport.class,
ServletRequestListener.class})
@HttpWhiteboardContextSelect("(" +
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)")
@HttpWhiteboardListener
@ServiceDescription("Apache Sling Request Authenticator")
@@ -215,21 +215,20 @@ public class SlingAuthenticator implements Authenticator,
String[] auth_uri_suffix() default DEFAULT_AUTH_URI_SUFFIX;
}
- /** default log */
+ /** default logger */
private final Logger log =
LoggerFactory.getLogger(SlingAuthenticator.class);
-
/**
* Value of the {@link Config#auth_http()} property to fully enable the
built-in
* HTTP Authentication Handler (value is "enabled").
*/
- private static final String HTTP_AUTH_ENABLED = "enabled";
+ static final String HTTP_AUTH_ENABLED = "enabled";
/**
* Value of the {@link Config#auth_http()} property to completely disable
the
* built-in HTTP Authentication Handler (value is "disabled").
*/
- private static final String HTTP_AUTH_DISABLED = "disabled";
+ static final String HTTP_AUTH_DISABLED = "disabled";
/**
* Value of the {@link Config#auth_http()} property to enable extracting
the
@@ -261,8 +260,6 @@ public class SlingAuthenticator implements Authenticator,
*/
private static final String AUTH_INFO_PROP_FEEDBACK_HANDLER =
"$$sling.auth.AuthenticationFeedbackHandler$$";
- private final PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authHandlerCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
/** The name of the impersonation parameter */
private volatile String sudoParameterName;
@@ -299,20 +296,22 @@ public class SlingAuthenticator implements Authenticator,
private volatile HttpBasicAuthenticationHandler httpBasicHandler;
/**
- * The listener for services registered with "sling.auth.requirements" to
+ * The manager for services registered with "sling.auth.requirements" to
* update the internal authentication requirements
*/
private final PathBasedHolderCache<AuthenticationRequirementHolder>
authenticationRequirementsManager;
/**
+ * Manager for authentication handlers.
+ */
+ private final PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authHandlersManager;
+
+ /**
* AuthenticationInfoPostProcessor services
*/
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service =
AuthenticationInfoPostProcessor.class, fieldOption = FieldOption.REPLACE)
private volatile List<AuthenticationInfoPostProcessor>
authInfoPostProcessors = Collections.emptyList();
- /** Handler map for authentication handlers */
- private final Map<String, List<AbstractAuthenticationHandlerHolder>>
handlerMap = new ConcurrentHashMap<>();
-
/**
* The event admin service.
*/
@@ -328,6 +327,7 @@ public class SlingAuthenticator implements Authenticator,
@Activate
public SlingAuthenticator(@Reference(policyOption =
ReferencePolicyOption.GREEDY) final MetricsService metricsService,
@Reference AuthenticationRequirementsManager authReqManager,
+ @Reference AuthenticationHandlersManager authHandlerManager,
@Reference(policyOption = ReferencePolicyOption.GREEDY) final
ResourceResolverFactory resourceResolverFactory,
final BundleContext bundleContext,
final Config config) {
@@ -335,7 +335,7 @@ public class SlingAuthenticator implements Authenticator,
this.resourceResolverFactory = resourceResolverFactory;
this.authenticationRequirementsManager = authReqManager;
-
+ this.authHandlersManager = authHandlerManager;
this.modified(config);
}
@@ -365,14 +365,11 @@ public class SlingAuthenticator implements Authenticator,
this.authUriSuffices = config.auth_uri_suffix();
- final String http;
- if (config.auth_annonymous()) {
- http = config.auth_http();
- } else {
- http = HTTP_AUTH_ENABLED;
+ if (!config.auth_annonymous()) {
log.debug("modified: Anonymous Access is denied thus HTTP Basic
Authentication is fully enabled");
}
+ final String http = getHttpAuth(config);
if (HTTP_AUTH_DISABLED.equals(http)) {
this.httpBasicHandler = null;
} else {
@@ -380,6 +377,17 @@ public class SlingAuthenticator implements Authenticator,
}
}
+ public static String getHttpAuth(final Config config) {
+ final String http;
+ if (config.auth_annonymous()) {
+ http = config.auth_http();
+ } else {
+ http = HTTP_AUTH_ENABLED;
+ }
+
+ return http;
+ }
+
// --------- AuthenticationSupport interface
/**
@@ -507,7 +515,7 @@ public class SlingAuthenticator implements Authenticator,
}
// select path used for authentication handler selection
- final Collection<AbstractAuthenticationHandlerHolder>[] holdersArray =
this.authHandlerCache
+ final Collection<AbstractAuthenticationHandlerHolder>[] holdersArray =
this.authHandlersManager
.findApplicableHolders(request);
final String path = getHandlerSelectionPath(request);
boolean done = false;
@@ -570,7 +578,7 @@ public class SlingAuthenticator implements Authenticator,
setSudoCookie(request, response, new AuthenticationInfo("dummy",
request.getRemoteUser()));
final String path = getHandlerSelectionPath(request);
- final Collection<AbstractAuthenticationHandlerHolder>[] holdersArray =
this.authHandlerCache
+ final Collection<AbstractAuthenticationHandlerHolder>[] holdersArray =
this.authHandlersManager
.findApplicableHolders(request);
for (int m = 0; m < holdersArray.length; m++) {
final Collection<AbstractAuthenticationHandlerHolder> holderSet =
holdersArray[m];
@@ -622,7 +630,7 @@ public class SlingAuthenticator implements Authenticator,
* Returns the list of registered authentication handlers as a map
*/
Map<String, List<String>> getAuthenticationHandler() {
- List<AbstractAuthenticationHandlerHolder> registeredHolders =
authHandlerCache.getHolders();
+ List<AbstractAuthenticationHandlerHolder> registeredHolders =
this.authHandlersManager.getHolders();
LinkedHashMap<String, List<String>> handlerMap = new
LinkedHashMap<String, List<String>>();
for (AbstractAuthenticationHandlerHolder holder : registeredHolders) {
List<String> provider = handlerMap.get(holder.fullPath);
@@ -643,25 +651,6 @@ public class SlingAuthenticator implements Authenticator,
return handlerMap;
}
- /**
- * Returns the name of the user to assume for requests without credentials.
- * This may be <code>null</code> if not configured and the default
anonymous
- * user is to be used.
- * <p>
- * The configured password cannot be requested.
- */
- String getAnonUserName() {
- return anonUser;
- }
-
- String getSudoCookieName() {
- return sudoCookieName;
- }
-
- String getSudoParameterName() {
- return sudoParameterName;
- }
-
// ---------- internal
/**
@@ -692,7 +681,7 @@ public class SlingAuthenticator implements Authenticator,
String path = getPath(request);
- final Collection<AbstractAuthenticationHandlerHolder>[] localArray =
this.authHandlerCache
+ final Collection<AbstractAuthenticationHandlerHolder>[] localArray =
this.authHandlersManager
.findApplicableHolders(request);
for (int m = 0; m < localArray.length; m++) {
final Collection<AbstractAuthenticationHandlerHolder> local =
localArray[m];
@@ -1582,116 +1571,4 @@ public class SlingAuthenticator implements
Authenticator,
}
return builder.toString();
}
-
- /**
- * Bind authentication handler
- * @param ref Service reference
- * @param handler The handler
- */
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy =
ReferencePolicy.DYNAMIC)
- private void bindAuthHandler(final AuthenticationHandler handler, final
ServiceReference<Object> ref) {
- final String id =
"A".concat(ref.getProperty(Constants.SERVICE_ID).toString());
- final String[] paths =
Converters.standardConverter().convert(ref.getProperty(AuthenticationHandler.PATH_PROPERTY)).to(String[].class);
- internalBindAuthHandler(paths, id, path -> {
- return new AuthenticationHandlerHolder(path,
- handler,
- ref);
- });
- }
-
- /**
- * Update authentication handler
- * @param ref Service reference
- * @param handler The handler
- */
- private void updatedAuthHandler(final AuthenticationHandler handler, final
ServiceReference<Object> ref) {
- unbindAuthHandler(ref);
- bindAuthHandler(handler, ref);
- }
-
- /**
- * Unbind authentication handler
- * @param ref Service Reference
- */
- private void unbindAuthHandler(final ServiceReference<Object> ref) {
- final String id =
"A".concat(ref.getProperty(Constants.SERVICE_ID).toString());
- internalUnbindAuthHandler(id);
- }
-
- /**
- * Bind old engine authentication handler
- * @param ref Service reference
- * @param handler The handler
- */
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy =
ReferencePolicy.DYNAMIC)
- private void bindEngineAuthHandler(final
org.apache.sling.engine.auth.AuthenticationHandler handler, final
ServiceReference<Object> ref) {
- final String id =
"E".concat(ref.getProperty(Constants.SERVICE_ID).toString());
- final String[] paths =
Converters.standardConverter().convert(ref.getProperty(AuthenticationHandler.PATH_PROPERTY)).to(String[].class);
- internalBindAuthHandler(paths, id, path -> {
- return new EngineAuthenticationHandlerHolder(path,
- handler,
- ref);
- });
- }
-
- /**
- * Update old engine authentication handler
- * @param ref Service reference
- * @param handler The handler
- */
- private void updatedEngineAuthHandler(final
org.apache.sling.engine.auth.AuthenticationHandler handler, final
ServiceReference<Object> ref) {
- unbindEngineAuthHandler(ref);
- bindEngineAuthHandler(handler, ref);
- }
-
- /**
- * Unbind old engine authentication handler
- * @param ref Service Reference
- */
- private void unbindEngineAuthHandler(final ServiceReference<Object> ref) {
- final String id =
"E".concat(ref.getProperty(Constants.SERVICE_ID).toString());
- internalUnbindAuthHandler(id);
- }
-
- /**
- * Bind an authentication handler
- * @param paths The paths
- * @param id Unique id
- * @param createFunction Creation callback
- */
- private void internalBindAuthHandler(final String[] paths, final String
id, final Function<String, AbstractAuthenticationHandlerHolder> createFunction)
{
- if (paths != null && paths.length > 0) {
-
- // generate the holders
- ArrayList<AbstractAuthenticationHandlerHolder> holderList = new
ArrayList<AbstractAuthenticationHandlerHolder>();
- for (String path : paths) {
- if (path != null && path.length() > 0) {
- holderList.add(createFunction.apply(path));
- }
- }
- // register the holders
- if ( !holderList.isEmpty() ) {
- for(final AbstractAuthenticationHandlerHolder holder :
holderList) {
- authHandlerCache.addHolder(holder);
- }
- }
-
- // keep a copy of them for unregistration later
- handlerMap.put(id, holderList);
- }
- }
-
- /**
- * Unbind authentication handler
- * @param id Unqiue id
- */
- private void internalUnbindAuthHandler(final String id) {
- final List<AbstractAuthenticationHandlerHolder> holders =
handlerMap.remove(id);
-
- if (holders != null) {
- for (AbstractAuthenticationHandlerHolder holder : holders) {
- authHandlerCache.removeHolder(holder);
- }
- }
- }
}
diff --git
a/src/test/java/org/apache/sling/auth/core/impl/AuthenticationRequirementsManagerTest.java
b/src/test/java/org/apache/sling/auth/core/impl/AuthenticationRequirementsManagerTest.java
index 115c961..2cf1945 100644
---
a/src/test/java/org/apache/sling/auth/core/impl/AuthenticationRequirementsManagerTest.java
+++
b/src/test/java/org/apache/sling/auth/core/impl/AuthenticationRequirementsManagerTest.java
@@ -41,19 +41,6 @@ import org.osgi.framework.ServiceReference;
public class AuthenticationRequirementsManagerTest {
- private SlingAuthenticator.Config createDefaultConfig() {
- final SlingAuthenticator.Config config =
mock(SlingAuthenticator.Config.class);
-
- when(config.auth_sudo_cookie()).thenReturn("sling.sudo");
- when(config.auth_sudo_parameter()).thenReturn("sudo");
- when(config.auth_annonymous()).thenReturn(true);
-
when(config.auth_http()).thenReturn(SlingAuthenticator.HTTP_AUTH_PREEMPTIVE);
- when(config.auth_http_realm()).thenReturn("Sling (Development)");
- when(config.auth_uri_suffix()).thenReturn(new String[]
{SlingAuthenticator.DEFAULT_AUTH_URI_SUFFIX});
-
- return config;
- }
-
private void assertPaths(final
PathBasedHolderCache<AuthenticationRequirementHolder> cache,
final String[] paths,
final ServiceReference<?>[] refs) {
@@ -128,7 +115,7 @@ public class AuthenticationRequirementsManagerTest {
final ResourceMapper mapper = mock(ResourceMapper.class);
when(mapper.getAllMappings("/path1")).thenReturn(Collections.singleton("/path1"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
assertEquals(3, manager.getHolders().size());
@@ -151,7 +138,7 @@ public class AuthenticationRequirementsManagerTest {
when(mapper.getAllMappings("/path3")).thenReturn(Arrays.asList("/path3",
"/path3a"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
// add
final ServiceReference<?> ref = createServiceReference(new String[]
{"/path1", "/path2"});
@@ -182,7 +169,7 @@ public class AuthenticationRequirementsManagerTest {
when(mapper.getAllMappings("/path2")).thenReturn(Collections.singleton("/path2"));
when(mapper.getAllMappings("/path3")).thenReturn(Collections.singleton("/path3"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref1 = createServiceReference(new String[]
{"/path1", "/path1", "/path2"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,
ref1));
@@ -210,7 +197,7 @@ public class AuthenticationRequirementsManagerTest {
when(mapper.getAllMappings("/path4")).thenReturn(Collections.singleton("/path4"));
when(mapper.getAllMappings("/path5")).thenReturn(Collections.singleton("/path5"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref1 = createServiceReference(new String[]
{"/path1"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,
ref1));
@@ -246,7 +233,7 @@ public class AuthenticationRequirementsManagerTest {
when(mapper.getAllMappings("/path4")).thenReturn(Collections.singleton("/path4"));
when(mapper.getAllMappings("/path5")).thenReturn(Collections.singleton("/path5"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref1 = createServiceReference(new String[]
{"/path1", "/path2", "/path3"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED,
ref1));
@@ -270,7 +257,7 @@ public class AuthenticationRequirementsManagerTest {
final ResourceMapper mapper = mock(ResourceMapper.class);
when(mapper.getAllMappings("/path1")).thenReturn(Arrays.asList("/path1",
"/path2", "/path3"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref = createServiceReference(new String[]
{"/path1"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref));
@@ -288,7 +275,7 @@ public class AuthenticationRequirementsManagerTest {
final ResourceMapper mapper = mock(ResourceMapper.class);
when(mapper.getAllMappings("/path1")).thenReturn(Arrays.asList("/path1",
"/path2", "/path3"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref = createServiceReference(new String[]
{"/path1"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref));
@@ -312,7 +299,7 @@ public class AuthenticationRequirementsManagerTest {
final BundleContext context = mock(BundleContext.class);
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(null),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref = createServiceReference(new String[]
{"-/path1", "+/path2", "/path3"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref));
@@ -330,7 +317,7 @@ public class AuthenticationRequirementsManagerTest {
when(mapper.getAllMappings("/path2")).thenReturn(Arrays.asList("/path2",
"/path2a", "/path2b"));
when(mapper.getAllMappings("/path3")).thenReturn(Arrays.asList("/path3",
"/path3a", "/path3b"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
final ServiceReference<?> ref = createServiceReference(new String[]
{"-/path1", "+/path2", "/path3"});
manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref));
@@ -357,7 +344,7 @@ public class AuthenticationRequirementsManagerTest {
when(mapper.getAllMappings("/path2")).thenReturn(Arrays.asList("/path2",
"/path2a"));
final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(context, createFactoryForMapper(mapper),
- createDefaultConfig(), callable -> callable.run());
+ SlingAuthenticatorTest.createDefaultConfig(), callable ->
callable.run());
// add
final ServiceReference<?> ref = createServiceReference(new String[]
{"+/path1", "-/path2"});
diff --git
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
index a6ce7d8..5d9bf6e 100644
---
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
+++
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
@@ -68,6 +68,7 @@ public class SlingAuthenticatorOsgiTest {
context.registerService(ResourceResolverFactory.class,
resourceResolverFactory);
context.registerService(MetricsService.class, metricsService);
context.registerInjectActivateService(AuthenticationRequirementsManager.class);
+
context.registerInjectActivateService(AuthenticationHandlersManager.class);
authenticator =
context.registerInjectActivateService(SlingAuthenticator.class);
}
diff --git
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
index 84c6efc..2954e4e 100644
--- a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
+++ b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorTest.java
@@ -36,6 +36,48 @@ import junitx.util.PrivateAccessor;
public class SlingAuthenticatorTest {
+ /**
+ * Helper method to create a default configuration
+ */
+ public static SlingAuthenticator.Config createDefaultConfig() {
+ final SlingAuthenticator.Config config =
Mockito.mock(SlingAuthenticator.Config.class);
+
+ Mockito.when(config.auth_sudo_cookie()).thenReturn("sling.sudo");
+ Mockito.when(config.auth_sudo_parameter()).thenReturn("sudo");
+ Mockito.when(config.auth_annonymous()).thenReturn(true);
+
Mockito.when(config.auth_http()).thenReturn(SlingAuthenticator.HTTP_AUTH_PREEMPTIVE);
+ Mockito.when(config.auth_http_realm()).thenReturn("Sling
(Development)");
+ Mockito.when(config.auth_uri_suffix()).thenReturn(new String[]
{SlingAuthenticator.DEFAULT_AUTH_URI_SUFFIX});
+
+ return config;
+ }
+
+ private SlingAuthenticator createSlingAuthenticator() {
+ return createSlingAuthenticator(createDefaultConfig());
+ }
+
+ public SlingAuthenticator createSlingAuthenticator(final String...
typeAndPathPairs) {
+ return createSlingAuthenticator(createDefaultConfig(),
typeAndPathPairs);
+ }
+
+ private SlingAuthenticator createSlingAuthenticator(final
SlingAuthenticator.Config config,
+ final String... typeAndPathPairs) {
+ final AuthenticationRequirementsManager requirements = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
config, callable -> callable.run());
+ final AuthenticationHandlersManager handlers = new
AuthenticationHandlersManager(config);
+ if ( typeAndPathPairs != null ) {
+ int i=0;
+ while ( i < typeAndPathPairs.length ) {
+
handlers.addHolder(buildAuthHolderForAuthTypeAndPath(typeAndPathPairs[i],
typeAndPathPairs[i+1]));
+ i += 2;
+ }
+ }
+ final SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), requirements,
+ handlers,
+ null, Mockito.mock(BundleContext.class), config);
+
+ return slingAuthenticator;
+ }
+
@Test
public void test_quoteCookieValue() throws UnsupportedEncodingException {
@@ -81,28 +123,11 @@ public class SlingAuthenticatorTest {
checkUnQuote("\"string\ttab\"", "string\ttab");
}
- private SlingAuthenticator.Config createDefaultConfig() {
- final SlingAuthenticator.Config config =
Mockito.mock(SlingAuthenticator.Config.class);
-
- Mockito.when(config.auth_sudo_cookie()).thenReturn("sling.sudo");
- Mockito.when(config.auth_sudo_parameter()).thenReturn("sudo");
- Mockito.when(config.auth_annonymous()).thenReturn(true);
-
Mockito.when(config.auth_http()).thenReturn(SlingAuthenticator.HTTP_AUTH_PREEMPTIVE);
- Mockito.when(config.auth_http_realm()).thenReturn("Sling
(Development)");
- Mockito.when(config.auth_uri_suffix()).thenReturn(new String[]
{SlingAuthenticator.DEFAULT_AUTH_URI_SUFFIX});
-
- return config;
- }
-
//SLING-4864
@Test
public void test_isAnonAllowed() throws Throwable {
// anon is allowed by default
- final SlingAuthenticator.Config config = createDefaultConfig();
-
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
config, callable -> callable.run());
- final SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), config);
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getServerName()).thenReturn("localhost");
@@ -118,9 +143,7 @@ public class SlingAuthenticatorTest {
final SlingAuthenticator.Config config = createDefaultConfig();
Mockito.when(config.auth_annonymous()).thenReturn(false);
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
config, callable -> callable.run());
- final SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), config);
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(config);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getServerName()).thenReturn("localhost");
@@ -136,18 +159,13 @@ public class SlingAuthenticatorTest {
*/
@Test
public void test_childNodeShouldHaveAuthenticationInfo() throws Throwable {
+
final String AUTH_TYPE = "AUTH_TYPE_TEST";
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test/childnodetest";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
-
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH);
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
@@ -169,14 +187,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
-
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH);
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
@@ -198,14 +210,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test/";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH);
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
-
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
@@ -227,14 +233,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_CHILD_NODE = "/content/en/test.html";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
-
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH);
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
@@ -252,14 +252,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/";
final String REQUEST_CHILD_NODE = "/content/en/test";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
-
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH);
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
@@ -279,15 +273,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH_LONGER = "/resource1.test2";
final String REQUEST_CHILD_NODE = "/resource1.test2";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH, AUTH_TYPE_LONGER,
PROTECTED_PATH_LONGER);
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE_LONGER,
PROTECTED_PATH_LONGER));
-
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_CHILD_NODE);
@@ -322,14 +309,8 @@ public class SlingAuthenticatorTest {
final String PROTECTED_PATH = "/content/en/test";
final String REQUEST_NOT_PROTECTED_PATH = "/content/en/test2";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
-
- PathBasedHolderCache<AbstractAuthenticationHandlerHolder>
authRequiredCache = new
PathBasedHolderCache<AbstractAuthenticationHandlerHolder>();
-
authRequiredCache.addHolder(buildAuthHolderForAuthTypeAndPath(AUTH_TYPE,
PROTECTED_PATH));
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator(AUTH_TYPE, PROTECTED_PATH);
- PrivateAccessor.setField(slingAuthenticator, "authHandlerCache",
authRequiredCache);
final HttpServletRequest request =
Mockito.mock(HttpServletRequest.class);
buildExpectationsForRequest(request, REQUEST_NOT_PROTECTED_PATH);
@@ -345,9 +326,7 @@ public class SlingAuthenticatorTest {
public void test_childNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test/test2";
final String handlerPath = "/content/test";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -356,9 +335,7 @@ public class SlingAuthenticatorTest {
public void test_siblingNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath =
"/content/test2.html/en/2016/09/19/test.html";
final String handlerPath = "/content/test";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertFalse(
(boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -367,9 +344,7 @@ public class SlingAuthenticatorTest {
public void test_actualNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test";
final String handlerPath = "/content/test";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -378,9 +353,7 @@ public class SlingAuthenticatorTest {
public void test_rootNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test";
final String handlerPath = "/";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -389,9 +362,7 @@ public class SlingAuthenticatorTest {
public void test_requestPathSelectorsAreTakenInConsideration() throws
Throwable {
final String requestPath =
"/content/test.selector1.selector2.html/en/2016/test.html";
final String handlerPath = "/content/test";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -400,9 +371,7 @@ public class SlingAuthenticatorTest {
public void test_requestPathSelectorsSiblingAreTakenInConsideration()
throws Throwable {
final String requestPath =
"/content/test.selector1.selector2.html/en/2016/09/19/test.html";
final String handlerPath = "/content/test2";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertFalse(
(boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -411,9 +380,7 @@ public class SlingAuthenticatorTest {
public void test_requestPathBackSlash() throws Throwable {
final String requestPath = "/page1\\somesubepage";
final String handlerPath = "/page";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertFalse(
(boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}
@@ -422,9 +389,7 @@ public class SlingAuthenticatorTest {
public void test_emptyNodeAuthenticationHandlerPath() throws Throwable {
final String requestPath = "/content/test";
final String handlerPath = "";
- final AuthenticationRequirementsManager manager = new
AuthenticationRequirementsManager(Mockito.mock(BundleContext.class), null,
createDefaultConfig(), callable -> callable.run());
- SlingAuthenticator slingAuthenticator = new
SlingAuthenticator(Mockito.mock(MetricsService.class), manager,
- null, Mockito.mock(BundleContext.class), createDefaultConfig());
+ final SlingAuthenticator slingAuthenticator =
this.createSlingAuthenticator();
Assert.assertTrue( (boolean)PrivateAccessor.invoke(slingAuthenticator,
"isNodeRequiresAuthHandler", new Class[] {String.class, String.class}, new
Object[] {requestPath, handlerPath}));
}