Convert public services to OSGi DS 28/104328/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 20:12:13 +0000 (21:12 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 21:28:35 +0000 (22:28 +0100)
In order to unblock users, convert ODLAuthenticator and
ShiroWebContextSecurer into Declarative Services components.

Since we still rely on blueprint to pick up configuration and aaa-cert
services, bridge these two worlds by publishing WebEnvironment via an
implementation-specific AAAShiroWebEnvironment.

This also forces WebInitializer to be a proper component, as otherwise
we would have a circular dependency its WebContextSecurer dependency.

Since not all our services are SCR components, we need to explictly list
out our Provide-Capability entries.

JIRA: AAA-251
Change-Id: Ia5a0d28e10d7597a9c5fe90c3cf084c25da652a9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-shiro/impl/pom.xml
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/authenticator/ODLAuthenticator.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/web/env/AAAShiroWebEnvironment.java [new file with mode: 0644]
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/web/env/AAAWebEnvironment.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/web/env/ShiroWebContextSecurer.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/web/env/WebInitializer.java
aaa-shiro/impl/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml

index 5dd7596a85838c126e15021b9542bb838b6883b2..a351dc1cc19d09c2c6ecc229863c47eafa73edc5 100644 (file)
@@ -17,9 +17,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
         <relativePath>../../parent</relativePath>
     </parent>
 
-    <groupId>org.opendaylight.aaa</groupId>
     <artifactId>aaa-shiro</artifactId>
-    <version>0.17.5-SNAPSHOT</version>
     <name>ODL :: aaa :: ${project.artifactId}</name>
     <packaging>bundle</packaging>
 
@@ -165,6 +163,15 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                            !javax.annotation,
                            *
                         </Import-Package>
+
+                        <!-- FIXME: AAA-205: remove this block -->
+                        <Provide-Capability>
+                            osgi.service;objectClass:List&lt;String&gt;="javax.servlet.Servlet";uses:="javax.servlet",
+                            osgi.service;objectClass:List&lt;String&gt;="org.jolokia.osgi.security.Authenticator";uses:="org.jolokia.osgi.security",
+                            osgi.service;objectClass:List&lt;String&gt;="org.opendaylight.aaa.api.ClaimCache,org.opendaylight.aaa.api.CredentialAuth,org.opendaylight.aaa.api.IdMService,org.opendaylight.aaa.api.PasswordCredentialAuth";uses:="org.opendaylight.aaa.api,org.opendaylight.aaa.api,org.opendaylight.aaa.api,org.opendaylight.aaa.api",
+                            osgi.service;objectClass:List&lt;String&gt;="org.opendaylight.aaa.web.WebContextSecurer";uses:="org.opendaylight.aaa.web"
+                            osgi.service;objectClass:List&lt;String&gt;="org.opendaylight.aaa.shiro.web.env.AAAShiroWebEnvironment";uses:="org.opendaylight.aaa.shiro.web.env",
+                        </Provide-Capability>
                     </instructions>
                 </configuration>
             </plugin>
index b2a0934ea945be02895821a50d5004a9d85ca6a1..834fc12e78b29753e296a2bf38f69dd44e2864a4 100644 (file)
@@ -18,20 +18,25 @@ import org.apache.shiro.authc.UsernamePasswordToken;
 import org.apache.shiro.session.Session;
 import org.apache.shiro.session.UnknownSessionException;
 import org.apache.shiro.subject.Subject;
-import org.apache.shiro.web.env.WebEnvironment;
 import org.jolokia.osgi.security.Authenticator;
+import org.opendaylight.aaa.shiro.web.env.AAAShiroWebEnvironment;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * AAA hook for <code>odl-jolokia</code> configured w/ <code>org.jolokia.authMode=service-all</code>.
+ * AAA hook for @{code odl-jolokia} configured with {@code org.jolokia.authMode=service-all}.
  */
-public class ODLAuthenticator implements Authenticator {
+@Component(immediate = true)
+public final class ODLAuthenticator implements Authenticator {
     private static final Logger LOG = LoggerFactory.getLogger(ODLAuthenticator.class);
 
-    private final WebEnvironment env;
+    private final AAAShiroWebEnvironment env;
 
-    public ODLAuthenticator(final WebEnvironment env) {
+    @Activate
+    public ODLAuthenticator(@Reference final AAAShiroWebEnvironment env) {
         this.env = requireNonNull(env);
     }
 
diff --git a/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/web/env/AAAShiroWebEnvironment.java b/aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/web/env/AAAShiroWebEnvironment.java
new file mode 100644 (file)
index 0000000..4706ccd
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.aaa.shiro.web.env;
+
+import com.google.common.annotations.Beta;
+import org.apache.shiro.web.env.WebEnvironment;
+
+/**
+ * Implementation-internal interface for bridging {@link AAAWebEnvironment} through OSGi Service Registry.
+ */
+@Beta
+public interface AAAShiroWebEnvironment extends WebEnvironment {
+
+}
index 94d45aa561661f38d0634b283daa358a4de9ae7b..976c8a72345890c95c3d341e5fc87a677c987f66 100644 (file)
@@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
  * Initialization happens in the context of this class's ClassLoader, with dependencies being injected into their
  * thread-local variables.
  */
-public final class AAAWebEnvironment extends IniWebEnvironment {
+public final class AAAWebEnvironment extends IniWebEnvironment implements AAAShiroWebEnvironment {
     private static final Logger LOG = LoggerFactory.getLogger(AAAWebEnvironment.class);
 
     private AAAWebEnvironment(final Ini ini) {
index 7e8f14bd9e316f14d1c99f65fdbd19c61d68ef61..714ded36767e026caa04f4a896ce0f9cacd8970b 100644 (file)
@@ -10,21 +10,25 @@ package org.opendaylight.aaa.shiro.web.env;
 import static java.util.Objects.requireNonNull;
 
 import java.util.Arrays;
-import org.apache.shiro.web.env.WebEnvironment;
 import org.opendaylight.aaa.shiro.filters.AAAShiroFilter;
 import org.opendaylight.aaa.web.FilterDetails;
 import org.opendaylight.aaa.web.WebContext;
 import org.opendaylight.aaa.web.WebContextSecurer;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * Secures a {@link WebContext} using Shiro.
  *
  * @author Michael Vorburger.ch
  */
+@Component
 public class ShiroWebContextSecurer implements WebContextSecurer {
-    private final WebEnvironment webEnvironment;
+    private final AAAShiroWebEnvironment webEnvironment;
 
-    public ShiroWebContextSecurer(final WebEnvironment webEnvironment) {
+    @Activate
+    public ShiroWebContextSecurer(@Reference final AAAShiroWebEnvironment webEnvironment) {
         this.webEnvironment = requireNonNull(webEnvironment);
     }
 
index 51e71c72c9f253bc0cde5d3741a3554feb675ab0..48ad05810f3ad3054f8ade71631f088ee771ea5f 100644 (file)
@@ -23,6 +23,10 @@ import org.opendaylight.aaa.web.WebContextSecurer;
 import org.opendaylight.aaa.web.WebServer;
 import org.opendaylight.aaa.web.servlet.ServletSupport;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * Initializer for web components.
@@ -33,13 +37,16 @@ import org.opendaylight.yangtools.concepts.Registration;
  * @author Michael Vorburger.ch
  */
 @Singleton
-public class WebInitializer {
+@Component(service = { })
+public final class WebInitializer implements AutoCloseable {
     private final Registration registraton;
 
     @Inject
-    public WebInitializer(final WebServer webServer, final ClaimCache claimCache, final IIDMStore iidMStore,
-            final WebContextSecurer webContextSecurer, final ServletSupport servletSupport,
-            final CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException {
+    @Activate
+    public WebInitializer(final @Reference WebServer webServer, @Reference final ClaimCache claimCache,
+            final @Reference ServletSupport servletSupport, final @Reference WebContextSecurer webContextSecurer,
+            final @Reference IIDMStore iidMStore,
+            final @Reference CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException {
 
         final var webContextBuilder = WebContext.builder()
             .name("OpenDaylight IDM realm management")
@@ -64,6 +71,8 @@ public class WebInitializer {
     }
 
     @PreDestroy
+    @Deactivate
+    @Override
     public void close() {
         registraton.close();
     }
index c20dd4e515b9a47965d894e96c16c86ef922d8d6..0b69df3ce998084210ebbe62f59e21127cace1de 100644 (file)
@@ -8,7 +8,7 @@ terms of the Eclipse Public License v1.0 which accompanies this distribution,
 and is available at http://www.eclipse.org/legal/epl-v10.html
 -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-  xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
+           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
 
   <odl:clustered-app-config
           binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.aaa.app.config.rev170619.ShiroConfiguration"
@@ -22,13 +22,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <reference id="authService" interface="org.opendaylight.aaa.api.AuthenticationService"/>
   <reference id="passwordService" interface="org.opendaylight.aaa.api.password.service.PasswordHashService"/>
   <reference id="idmStore" interface ="org.opendaylight.aaa.api.IIDMStore"/>
-
   <reference id="passwordCredentialAuth" interface="org.opendaylight.aaa.api.PasswordCredentialAuth"/>
-  <reference id="claimCache" interface="org.opendaylight.aaa.api.ClaimCache"/>
-
   <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
-
   <reference id="certManager" interface="org.opendaylight.aaa.cert.api.ICertificateManager"/>
+  <reference id="servletSupport" interface="org.opendaylight.aaa.web.servlet.ServletSupport"/>
 
   <bean id="provider" class="org.opendaylight.aaa.AAAShiroProvider" init-method="init" destroy-method="close">
     <argument ref="passwordCredentialAuth"/>
@@ -36,8 +33,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <argument ref="idmStore"/>
   </bean>
 
-  <reference id="servletSupport" interface="org.opendaylight.aaa.web.servlet.ServletSupport"/>
-
   <bean id="webEnvironment" class="org.opendaylight.aaa.shiro.web.env.AAAWebEnvironment" factory-method="create">
     <argument ref="shiroConfiguration"/>
     <argument ref="dataBroker"/>
@@ -52,27 +47,5 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
     <argument ref="passwordService"/>
     <argument ref="servletSupport"/>
   </bean>
-
-  <bean id="webContextSecurer" class="org.opendaylight.aaa.shiro.web.env.ShiroWebContextSecurer">
-    <argument ref="webEnvironment"/>
-  </bean>
-  <service ref="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer" />
-
-  <bean id="jolokiaAuthenticator" class="org.opendaylight.aaa.authenticator.ODLAuthenticator">
-    <argument ref="webEnvironment"/>
-  </bean>
-  <service ref="jolokiaAuthenticator" interface="org.jolokia.osgi.security.Authenticator"/>
-
-  <reference id="customFilterAdapterConfig"
-      interface="org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration"/>
-  <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer" />
-
-  <bean id="webInitializer" class="org.opendaylight.aaa.shiro.web.env.WebInitializer" destroy-method="close">
-    <argument ref="webServer"/>
-    <argument ref="claimCache"/>
-    <argument ref="idmStore"/>
-    <argument ref="webContextSecurer"/>
-    <argument ref="servletSupport"/>
-    <argument ref="customFilterAdapterConfig"/>
-  </bean>
+  <service ref="webEnvironment" interface="org.opendaylight.aaa.shiro.web.env.AAAShiroWebEnvironment"/>
 </blueprint>