Eliminate AAAShiroProvider.init() 32/104332/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 21:54:30 +0000 (22:54 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 8 Feb 2023 21:55:53 +0000 (22:55 +0100)
The init method is used only to log information, integrate it into the
constructor, differentiating successful and empty startup.

Also implement AutoCloseable to specify close() method, which does only
logging, but perhaps will do more in the future.

JIRA: AAA-205
Change-Id: Ice5c0a150e4b361fc39ddca54f999a8d2e04c5d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/AAAShiroProvider.java
aaa-shiro/impl/src/main/resources/OSGI-INF/blueprint/impl-blueprint.xml

index f132c6d9bb12bef82edd652198ec0c9b96e6169c..2a8c7bdf2ebf37594c3e8cd74fc7b222b357f544 100644 (file)
@@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
 /**
  * Provider for AAA shiro implementation.
  */
-public final class AAAShiroProvider {
+public final class AAAShiroProvider implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(AAAShiroProvider.class);
 
     private final TokenStore tokenStore;
@@ -34,19 +34,27 @@ public final class AAAShiroProvider {
     public AAAShiroProvider(final PasswordCredentialAuth credentialAuth,
                             final DatastoreConfig datastoreConfig,
                             final IIDMStore iidmStore) {
-        if (datastoreConfig == null || !datastoreConfig.getStore().equals(DatastoreConfig.Store.H2DataStore)) {
-            LOG.info("AAA Datastore has not been initialized");
+        if (datastoreConfig != null && datastoreConfig.getStore() == DatastoreConfig.Store.H2DataStore) {
+            tokenStore = new H2TokenStore(datastoreConfig.getTimeToLive().longValue(),
+                datastoreConfig.getTimeToWait().longValue());
+
+            initializeIIDMStore(iidmStore);
+
+            tokenAuthenticators = new TokenAuthenticators(new HttpBasicAuth(credentialAuth));
+            LOG.info("AAAShiroProvider Session Initiated");
+        } else {
             tokenStore = null;
             tokenAuthenticators = new TokenAuthenticators();
-            return;
+            LOG.info("AAA Datastore has not been initialized");
         }
+    }
 
-        tokenStore = new H2TokenStore(datastoreConfig.getTimeToLive().longValue(),
-                datastoreConfig.getTimeToWait().longValue());
-
-        initializeIIDMStore(iidmStore);
-
-        tokenAuthenticators = new TokenAuthenticators(new HttpBasicAuth(credentialAuth));
+    /**
+     * Method called when the blueprint container is destroyed.
+     */
+    @Override
+    public void close() {
+        LOG.info("AAAShiroProvider Closed");
     }
 
     private static void initializeIIDMStore(final IIDMStore iidmStore) {
@@ -57,20 +65,6 @@ public final class AAAShiroProvider {
         }
     }
 
-    /**
-     * Method called when the blueprint container is created.
-     */
-    public void init() {
-        LOG.info("AAAShiroProvider Session Initiated");
-    }
-
-    /**
-     * Method called when the blueprint container is destroyed.
-     */
-    public void close() {
-        LOG.info("AAAShiroProvider Closed");
-    }
-
     public TokenStore getTokenStore() {
         return tokenStore;
     }
index 0b69df3ce998084210ebbe62f59e21127cace1de..0c6e0d7b47edb5eda9fa2de36515042e5b24eda7 100644 (file)
@@ -27,7 +27,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <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">
+  <bean id="provider" class="org.opendaylight.aaa.AAAShiroProvider" destroy-method="close">
     <argument ref="passwordCredentialAuth"/>
     <argument ref="datastoreConfig"/>
     <argument ref="idmStore"/>