bind AAA Encrypt & Cert services (requires by upcoming OVSDB)
authorMichael Vorburger <mike@vorburger.ch>
Sat, 22 Dec 2018 00:46:23 +0000 (01:46 +0100)
committerMichael Vorburger <mike@vorburger.ch>
Wed, 1 Jul 2020 23:38:10 +0000 (01:38 +0200)
Signed-off-by: Michael Vorburger <mike@vorburger.ch>
src/main/java/org/opendaylight/aaa/simple/AAAModule.java
src/main/java/org/opendaylight/aaa/simple/CertModule.java
src/main/java/org/opendaylight/aaa/simple/EncryptModule.java
src/test/java/org/opendaylight/aaa/simple/test/CertModuleTest.java [new file with mode: 0644]
src/test/java/org/opendaylight/aaa/simple/test/EncryptModuleTest.java [new file with mode: 0644]

index 849f0de3742ca14e1b2f0766820abc36951a6b58..8f0d18bdafe63c694058f485657aea113d0975ac 100644 (file)
@@ -13,7 +13,6 @@ public class AAAModule extends AbstractModule {
 
     @Override
     protected void configure() {
-        install(new EncryptModule());
         install(new CertModule());
         install(new ShiroModule());
     }
index 3c58ed84d3d5b9c4e3d78c26f5a8c5d363c211f1..dbdc122644ebc5c3bdd499351a6a13dd5f73b255 100644 (file)
@@ -8,6 +8,19 @@
 package org.opendaylight.aaa.simple;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import java.io.IOException;
+import java.security.Security;
+import javax.inject.Singleton;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.opendaylight.aaa.cert.api.ICertificateManager;
+import org.opendaylight.aaa.cert.impl.AaaCertRpcServiceImpl;
+import org.opendaylight.aaa.cert.impl.CertificateManagerService;
+import org.opendaylight.aaa.encrypt.AAAEncryptionService;
+import org.opendaylight.controller.simple.ConfigReader;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.aaa.cert.rev151126.AaaCertServiceConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.aaa.cert.rpc.rev151215.AaaCertRpcService;
 
 /**
  * Guice wiring equivalent of AAA Cert BP XML in
@@ -17,30 +30,38 @@ import com.google.inject.AbstractModule;
  */
 public class CertModule extends AbstractModule {
 
-    @Override
-    protected void configure() {
+    static {
+        Security.addProvider(new BouncyCastleProvider());
     }
 
-/*
     @Override
     protected void configure() {
-        // as per aaa-cert-config.xml
-        // TODO read this from XML with that helper I once wrote somewhere for tests instead of duplicating here..
-        bind(AaaCertServiceConfig.class).toInstance(new AaaCertServiceConfigBuilder().setUseConfig(true)
-                .setUseMdsal(true).setBundleName("opendaylight").build());
-        // TODO ctlKeystore & trustKeystore, but what are those, where are the stores, and needed for what?
+        install(new EncryptModule());
     }
 
     @Provides
-    @Singleton public ICertificateManager certificateManagerService(AaaCertServiceConfig config, DataBroker db,
+    @Singleton ICertificateManager certificateManagerService(AaaCertServiceConfig config, DataBroker db,
             AAAEncryptionService crypto) {
         return new CertificateManagerService(config, db, crypto);
     }
 
+    @Provides
+    @Singleton AaaCertServiceConfig getAaaCertServiceConfig(ConfigReader configReader) throws IOException {
+        // TODO Urgh, CertificateManagerService is hard-coded to expect aaa-cert-config.xml to be in
+        // etc/opendaylight/datastore/initial/config/aaa-cert-config.xml instead of in initial/aaa-cert-config.xml
+        // and -more importantly- it *WRITES INTO IT* - OMG, what is that?!
+        //
+        // This _HACK_ prevents the WARN, but it should be changed in AAA:
+//        File file = new File("etc/opendaylight/datastore/initial/config/aaa-cert-config.xml");
+//        file.getParentFile().mkdirs();
+//        Resources.asByteSource(Resources.getResource("initial/aaa-cert-config.xml")).copyTo(Files.asByteSink(file));
+
+        return configReader.read("/initial/aaa-cert-config", AaaCertServiceConfig.class);
+    }
+
     @Provides
     @Singleton
-    public AaaCertRpcService aaaCertRpcService(AaaCertServiceConfig config, DataBroker db, AAAEncryptionService crypt) {
+    AaaCertRpcService aaaCertRpcService(AaaCertServiceConfig config, DataBroker db, AAAEncryptionService crypt) {
         return new AaaCertRpcServiceImpl(config, db, crypt);
     }
-*/
 }
index 81780b859ed7f5ca01958bb2cf9f7279ee6084f1..e96ab73fbe18b3ebb155a64f4626a82b59fb0490 100644 (file)
@@ -8,22 +8,19 @@
 package org.opendaylight.aaa.simple;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import javax.inject.Singleton;
+import org.opendaylight.aaa.encrypt.AAAEncryptionService;
+import org.opendaylight.aaa.encrypt.impl.AAAEncryptionServiceImpl;
+import org.opendaylight.controller.simple.ConfigReader;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.yang.gen.v1.config.aaa.authn.encrypt.service.config.rev160915.AaaEncryptServiceConfig;
 
 public class EncryptModule extends AbstractModule {
 
-    @Override
-    protected void configure() {
-    }
-
-/*
-    @Override
-    protected void configure() {
-        // as per aaa-encrypt-service-config.xml
-        // TODO read this from XML with that helper I once wrote somewhere for tests instead of duplicating here..
-        bind(AaaEncryptServiceConfig.class).toInstance(new AaaEncryptServiceConfigBuilder()
-                .setEncryptKey("V1S1ED4OMeEh").setPasswordLength(12).setEncryptSalt("TdtWeHbch/7xP52/rp3Usw==")
-                .setEncryptMethod("PBKDF2WithHmacSHA1").setEncryptType("AES").setEncryptIterationCount(32768)
-                .setEncryptKeyLength(128).setCipherTransforms("AES/CBC/PKCS5Padding").build());
+    @Provides
+    @Singleton AaaEncryptServiceConfig getEncryptServiceConfig(ConfigReader configReader) {
+        return configReader.read("/initial/aaa-encrypt-service-config", AaaEncryptServiceConfig.class);
     }
 
     @Provides
@@ -31,5 +28,8 @@ public class EncryptModule extends AbstractModule {
     public AAAEncryptionService aaaEncryptionService(AaaEncryptServiceConfig config, DataBroker db) {
         return new AAAEncryptionServiceImpl(config, db);
     }
-*/
+
+    @Override
+    protected void configure() {
+    }
 }
diff --git a/src/test/java/org/opendaylight/aaa/simple/test/CertModuleTest.java b/src/test/java/org/opendaylight/aaa/simple/test/CertModuleTest.java
new file mode 100644 (file)
index 0000000..5bc9bce
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Red Hat, Inc. 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.simple.test;
+
+import javax.inject.Inject;
+import org.junit.Rule;
+import org.opendaylight.aaa.cert.api.ICertificateManager;
+import org.opendaylight.aaa.simple.CertModule;
+import org.opendaylight.controller.simple.InMemoryControllerModule;
+import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
+import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule2;
+import org.opendaylight.infrautils.simple.testutils.AbstractSimpleDistributionTest;
+
+public class CertModuleTest extends AbstractSimpleDistributionTest {
+
+    public @Rule GuiceRule2 guice = new GuiceRule2(
+            new CertModule(), new InMemoryControllerModule(), new AnnotationsModule());
+
+    @Inject ICertificateManager certificateManager;
+
+}
diff --git a/src/test/java/org/opendaylight/aaa/simple/test/EncryptModuleTest.java b/src/test/java/org/opendaylight/aaa/simple/test/EncryptModuleTest.java
new file mode 100644 (file)
index 0000000..00a3716
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2017 Red Hat, Inc. 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.simple.test;
+
+import javax.inject.Inject;
+import org.junit.Rule;
+import org.opendaylight.aaa.encrypt.AAAEncryptionService;
+import org.opendaylight.aaa.simple.EncryptModule;
+import org.opendaylight.controller.simple.InMemoryControllerModule;
+import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
+import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule2;
+import org.opendaylight.infrautils.simple.testutils.AbstractSimpleDistributionTest;
+
+public class EncryptModuleTest extends AbstractSimpleDistributionTest {
+
+    public @Rule GuiceRule2 guice = new GuiceRule2(
+            new EncryptModule(), new InMemoryControllerModule(), new AnnotationsModule());
+
+    @Inject AAAEncryptionService encryptionService;
+
+}