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 9cd447d SLING-10242 : Register web console plugin using DS
9cd447d is described below
commit 9cd447da084c491d25b19443093cbea5295b4f17
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri Mar 19 10:19:17 2021 +0100
SLING-10242 : Register web console plugin using DS
---
.../core/impl/AuthenticatorWebConsolePlugin.java | 32 +++++++++++++---------
.../sling/auth/core/impl/SlingAuthenticator.java | 28 ++-----------------
2 files changed, 21 insertions(+), 39 deletions(-)
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 8ae143b..f55f6c3 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
@@ -23,30 +23,36 @@ import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
+import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.sling.api.request.ResponseUtil;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.propertytypes.ServiceDescription;
+import org.osgi.service.component.propertytypes.ServiceVendor;
@SuppressWarnings("serial")
+@Component(service = Servlet.class,
+ property = {
+ "felix.webconsole.label=" + AuthenticatorWebConsolePlugin.LABEL,
+ "felix.webconsole.title=" + AuthenticatorWebConsolePlugin.TITLE,
+ "felix.webconsole.category=Sling"
+ })
+@ServiceDescription("Apache Sling Request Authenticator WebConsole Plugin")
+@ServiceVendor("The Apache Software Foundation")
public class AuthenticatorWebConsolePlugin extends HttpServlet {
- private final SlingAuthenticator slingAuthenticator;
+ /** The label for the web console */
+ public static final String LABEL = "slingauth";
+ /** The title for the web console */
+ public static final String TITLE = "Authenticator";
- String getLabel() {
- return "slingauth";
- }
-
- String getTitle() {
- return "Authenticator";
- }
-
- public AuthenticatorWebConsolePlugin(
- final SlingAuthenticator slingAuthenticator) {
- this.slingAuthenticator = slingAuthenticator;
- }
+ @Reference
+ private SlingAuthenticator slingAuthenticator;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
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 666d549..027315d 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
@@ -38,7 +38,6 @@ import javax.jcr.SimpleCredentials;
import javax.security.auth.login.AccountLockedException;
import javax.security.auth.login.AccountNotFoundException;
import javax.security.auth.login.CredentialExpiredException;
-import javax.servlet.Servlet;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
@@ -67,7 +66,6 @@ import org.apache.sling.commons.metrics.Timer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
@@ -108,7 +106,7 @@ import org.slf4j.LoggerFactory;
* URL.
*/
@Component(name = "org.apache.sling.engine.impl.auth.SlingAuthenticator",
- service = {Authenticator.class, AuthenticationSupport.class,
ServletRequestListener.class })
+ service = {Authenticator.class, AuthenticationSupport.class,
ServletRequestListener.class, SlingAuthenticator.class })
@HttpWhiteboardContextSelect("(" +
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=*)")
@HttpWhiteboardListener
@ServiceDescription("Apache Sling Request Authenticator")
@@ -305,9 +303,6 @@ public class SlingAuthenticator implements Authenticator,
/** HTTP Basic authentication handler */
private HttpBasicAuthenticationHandler httpBasicHandler;
- /** Web Console Plugin service registration */
- private ServiceRegistration<Servlet> webConsolePlugin;
-
/**
* The listener for services registered with "sling.auth.requirements" to
* update the internal authentication requirements
@@ -344,20 +339,6 @@ public class SlingAuthenticator implements Authenticator,
this.resourceResolverFactory = resourceResolverFactory;
modified(config);
- AuthenticatorWebConsolePlugin plugin = new
AuthenticatorWebConsolePlugin(
- this);
- Hashtable<String, Object> props = new Hashtable<String, Object>();
- props.put("felix.webconsole.label", plugin.getLabel());
- props.put("felix.webconsole.title", plugin.getTitle());
- props.put("felix.webconsole.category", "Sling");
- props.put(Constants.SERVICE_DESCRIPTION,
- "Sling Request Authenticator WebConsole Plugin");
- props.put(Constants.SERVICE_VENDOR,
- "The Apache Software Foundation");
-
- webConsolePlugin = bundleContext.registerService(
- Servlet.class, plugin, props);
-
serviceListener = SlingAuthenticatorServiceListener.createListener(
bundleContext, Executors.newSingleThreadExecutor(),
resourceResolverFactory, this.authRequiredCache);
}
@@ -445,12 +426,7 @@ public class SlingAuthenticator implements Authenticator,
private void deactivate(final BundleContext bundleContext) {
this.authRequiredCache.clear();
- serviceListener.stop(bundleContext);
-
- if (webConsolePlugin != null) {
- webConsolePlugin.unregister();
- webConsolePlugin = null;
- }
+ this.serviceListener.stop(bundleContext);
}
// --------- AuthenticationSupport interface