<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>
+++ /dev/null
-/*
- * 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();
- }
- }
-}
*/
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;
/**
- * AuthProvider implementation delegating to AD-SAL UserManager instance.
+ * AuthProvider implementation delegating to AAA CredentialAuth<PasswordCredentials> 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) {
}
}
};
- 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
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;
--- /dev/null
+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);
+ }
+
+}
--- /dev/null
+/*
+* 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));
+ }
+}
--- /dev/null
+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
+ }
+ }
+}