Add config subsystem binding to aaa-authn-odl-plugin 88/24188/2
authorMaros Marsalek <mmarsale@cisco.com>
Wed, 15 Jul 2015 13:20:54 +0000 (15:20 +0200)
committerMaros Marsalek <mmarsale@cisco.com>
Thu, 6 Aug 2015 08:01:55 +0000 (08:01 +0000)
AuthProvider is now a regular module instantiated automatically as a default
instance.

Change-Id: I3244242bfe3d1be1207ab077d4e5cc107a33ee4e
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
aaa-authn-odl-plugin/pom.xml
aaa-authn-odl-plugin/src/main/java/org/opendaylight/aaa/odl/AuthProviderActivator.java [deleted file]
aaa-authn-odl-plugin/src/main/java/org/opendaylight/aaa/odl/CredentialServiceAuthProvider.java
aaa-authn-odl-plugin/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/netconf/plugin/rev150715/AuthProviderModule.java [new file with mode: 0644]
aaa-authn-odl-plugin/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/netconf/plugin/rev150715/AuthProviderModuleFactory.java [new file with mode: 0644]
aaa-authn-odl-plugin/src/main/yang/aaa-authn-netconf-plugin.yang [new file with mode: 0644]

index f0271a224d9e13654e60c7b4cbefc627eaefc4dd..d8a7b87fc42226c44ea4adaee3f445841d6e909e 100644 (file)
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Bundle-Activator>org.opendaylight.aaa.odl.AuthProviderActivator</Bundle-Activator>
-                    </instructions>
-                    <manifestLocation>${project.basedir}/META-INF</manifestLocation>
-                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <version>${yangtools.version}</version>
+                <executions>
+                    <execution>
+                        <id>config</id>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+                                    <additionalConfiguration>
+                                        <namespaceToPackage1>
+                                            urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
+                                        </namespaceToPackage1>
+                                    </additionalConfiguration>
+                                </generator>
+                                <generator>
+                                    <codeGeneratorClass>org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass>
+                                    <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+                                </generator>
+                            </codeGenerators>
+                            <inspectDependencies>true</inspectDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-jmx-generator-plugin</artifactId>
+                        <version>${config.version}</version>
+                    </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.yangtools</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>${yangtools.version}</version>
+                    </dependency>
+                </dependencies>
             </plugin>
         </plugins>
     </build>
diff --git a/aaa-authn-odl-plugin/src/main/java/org/opendaylight/aaa/odl/AuthProviderActivator.java b/aaa-authn-odl-plugin/src/main/java/org/opendaylight/aaa/odl/AuthProviderActivator.java
deleted file mode 100644 (file)
index 735288e..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, 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.odl;
-
-import java.util.Hashtable;
-
-import org.opendaylight.controller.netconf.auth.AuthConstants;
-import org.opendaylight.controller.netconf.auth.AuthProvider;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-public class AuthProviderActivator implements BundleActivator {
-
-    public static final int PREFERENCE = 10;
-    private ServiceRegistration<AuthProvider> authProviderServiceRegistration;
-
-    @Override
-    public void start(final BundleContext context) throws Exception {
-        final AuthProvider authProvider = new CredentialServiceAuthProvider(context);
-        // Set preference of this service to 0
-        final Hashtable<String, Object> properties = new Hashtable<>(1);
-        properties.put(AuthConstants.SERVICE_PREFERENCE_KEY, PREFERENCE);
-
-        authProviderServiceRegistration = context.registerService(AuthProvider.class, authProvider, properties);
-    }
-
-    @Override
-    public void stop(final BundleContext context) throws Exception {
-        if(authProviderServiceRegistration != null) {
-            authProviderServiceRegistration.unregister();
-        }
-    }
-}
index 4ef93c755c2b3e8ffc6b87d93042bca056c0f471..1c47949c1eb161717671a585a6252febbeec5855 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.aaa.odl;
 
+import java.util.Map;
 import org.opendaylight.aaa.api.AuthenticationException;
 import org.opendaylight.aaa.api.Claim;
 import org.opendaylight.aaa.api.CredentialAuth;
@@ -21,17 +22,23 @@ import org.slf4j.LoggerFactory;
 
 
 /**
- * AuthProvider implementation delegating to AD-SAL UserManager instance.
+ * AuthProvider implementation delegating to AAA CredentialAuth&lt;PasswordCredentials&gt; instance.
  */
-public final class CredentialServiceAuthProvider implements AuthProvider {
+public final class CredentialServiceAuthProvider implements AuthProvider, AutoCloseable {
     private static final Logger logger = LoggerFactory.getLogger(CredentialServiceAuthProvider.class);
 
+    /**
+     * Singleton instance with delayed instantiation
+     */
+    public static volatile Map.Entry<BundleContext, CredentialServiceAuthProvider> INSTANCE;
+
     // TODO what domain should be used for this ? can we leave null ?
     public static final String DOMAIN = null;
 
     // FIXME CredentialAuth is generic and it causes warnings during compilation
     // Maybe there should be a PasswordCredentialAuth implements CredentialAuth<PasswordCredentials>
-    private CredentialAuth<PasswordCredentials> nullableCredService;
+    private volatile CredentialAuth<PasswordCredentials> nullableCredService;
+    private final ServiceTracker<CredentialAuth, CredentialAuth> listenerTracker;
 
     public CredentialServiceAuthProvider(final BundleContext bundleContext) {
 
@@ -57,12 +64,12 @@ public final class CredentialServiceAuthProvider implements AuthProvider {
                 }
             }
         };
-        final ServiceTracker<CredentialAuth, CredentialAuth> listenerTracker = new ServiceTracker<>(bundleContext, CredentialAuth.class, customizer);
+        listenerTracker = new ServiceTracker<>(bundleContext, CredentialAuth.class, customizer);
         listenerTracker.open();
     }
 
     /**
-     * Authenticate user. This implementation tracks IUserManager and delegates the decision to it. If the service is not
+     * Authenticate user. This implementation tracks CredentialAuth<PasswordCredentials> and delegates the decision to it. If the service is not
      * available, IllegalStateException is thrown.
      */
     @Override
@@ -84,6 +91,12 @@ public final class CredentialServiceAuthProvider implements AuthProvider {
         return true;
     }
 
+    @Override
+    public void close() throws Exception {
+        listenerTracker.close();
+        nullableCredService = null;
+    }
+
     private static final class PasswordCredentialsWrapper implements PasswordCredentials {
         private final String username;
         private final String password;
diff --git a/aaa-authn-odl-plugin/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/netconf/plugin/rev150715/AuthProviderModule.java b/aaa-authn-odl-plugin/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/netconf/plugin/rev150715/AuthProviderModule.java
new file mode 100644 (file)
index 0000000..cdf9eda
--- /dev/null
@@ -0,0 +1,41 @@
+package org.opendaylight.yang.gen.v1.config.aaa.authn.netconf.plugin.rev150715;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.aaa.odl.CredentialServiceAuthProvider;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.osgi.framework.BundleContext;
+
+public class AuthProviderModule extends org.opendaylight.yang.gen.v1.config.aaa.authn.netconf.plugin.rev150715.AbstractAuthProviderModule {
+
+    private BundleContext bundleContext;
+
+    public AuthProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public AuthProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.config.aaa.authn.netconf.plugin.rev150715.AuthProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    public AuthProviderModule(final ModuleIdentifier moduleIdentifier, final DependencyResolver dependencyResolver, final AuthProviderModule oldModule, final AutoCloseable oldInstance, final BundleContext bundleContext) {
+        this(moduleIdentifier, dependencyResolver, oldModule, oldInstance);
+        this.bundleContext = bundleContext;
+    }
+
+    public AuthProviderModule(final ModuleIdentifier moduleIdentifier, final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
+        this(moduleIdentifier, dependencyResolver);
+        this.bundleContext = bundleContext;
+    }
+
+    @Override
+    public void customValidation() {
+        Preconditions.checkNotNull(bundleContext, "BundleContext was not properly set up");
+    }
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+       return new CredentialServiceAuthProvider(bundleContext);
+    }
+
+}
diff --git a/aaa-authn-odl-plugin/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/netconf/plugin/rev150715/AuthProviderModuleFactory.java b/aaa-authn-odl-plugin/src/main/java/org/opendaylight/yang/gen/v1/config/aaa/authn/netconf/plugin/rev150715/AuthProviderModuleFactory.java
new file mode 100644 (file)
index 0000000..27bca44
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+* Generated file
+*
+* Generated from: yang module name: aaa-authn-netconf-plugin yang module local name: aaa-authn-netconf-plugin
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Wed Jul 15 15:16:51 CEST 2015
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.config.aaa.authn.netconf.plugin.rev150715;
+
+import java.util.Collections;
+import java.util.Set;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.DependencyResolverFactory;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.osgi.framework.BundleContext;
+
+public class AuthProviderModuleFactory extends org.opendaylight.yang.gen.v1.config.aaa.authn.netconf.plugin.rev150715.AbstractAuthProviderModuleFactory {
+
+    private static final ModuleIdentifier DEFAULT_INSTANCE_ID = new ModuleIdentifier(NAME, "default-auth-provider");
+
+    @Override
+    public AuthProviderModule instantiateModule(final String instanceName, final DependencyResolver dependencyResolver, final AuthProviderModule oldModule, final AutoCloseable oldInstance, final BundleContext bundleContext) {
+        return new AuthProviderModule(
+                new ModuleIdentifier(NAME, instanceName), dependencyResolver, oldModule, oldInstance, bundleContext);
+    }
+
+    @Override
+    public AuthProviderModule instantiateModule(final String instanceName, final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
+        return new AuthProviderModule(
+                new ModuleIdentifier(NAME, instanceName), dependencyResolver, bundleContext);
+    }
+
+    @Override
+    public Set<AuthProviderModule> getDefaultModules(final DependencyResolverFactory dependencyResolverFactory, final BundleContext bundleContext) {
+        // Config subsystem puts this instance into OSGi service registry automatically 
+        final DependencyResolver dependencyResolver = dependencyResolverFactory.createDependencyResolver(DEFAULT_INSTANCE_ID);
+        return Collections.singleton(new AuthProviderModule(DEFAULT_INSTANCE_ID, dependencyResolver, bundleContext));
+    }
+}
diff --git a/aaa-authn-odl-plugin/src/main/yang/aaa-authn-netconf-plugin.yang b/aaa-authn-odl-plugin/src/main/yang/aaa-authn-netconf-plugin.yang
new file mode 100644 (file)
index 0000000..ffa6d98
--- /dev/null
@@ -0,0 +1,27 @@
+module aaa-authn-netconf-plugin {
+
+    yang-version 1;
+    namespace "config:aaa:authn:netconf:plugin";
+    prefix "aaa-authn-store-cfg";
+
+    import config { prefix config; revision-date 2013-04-05; }
+    import netconf-auth { prefix na; revision-date 2015-07-15; }
+
+    revision "2015-07-15" {
+        description
+            "Initial revision.";
+    }
+
+    identity aaa-authn-netconf-plugin {
+            base config:module-type;
+            config:java-name-prefix AuthProvider;
+            config:provided-service na:netconf-auth-provider;
+    }
+
+    augment "/config:modules/config:module/config:configuration" {
+        case aaa-authn-netconf-plugin {
+            when "/config:modules/config:module/config:type = 'aaa-authn-netconf-plugin'";
+            // no config yet
+       }
+    }
+}