From c435bd9dd87c7d4372997eef57691ee67cc76f2b Mon Sep 17 00:00:00 2001 From: VenkataSatya Jonnadula Date: Thu, 10 Sep 2020 16:51:25 +0530 Subject: [PATCH] Missing Yang-tools Binding and AAA binding in Netconf Module. There some yang-tools binding in the latest Aluminium. The Netconf module was failing to start as these bindings were missing in ODLMicro JIRA: ODLMICRO-37 Signed-off-by: VenkataSatya Jonnadula Change-Id: I9b46f7e3eb3bdef3128587c0cda490aeda64054d --- micro-core/pom.xml | 5 ++ .../org/opendaylight/aaa/micro/AAAModule.java | 50 +++++++------------ .../micro/InMemoryControllerModule.java | 7 +++ micro-netconf/pom.xml | 13 +++++ .../netconf/micro/NetconfModule.java | 6 +-- .../AbstractSimpleDistributionTest.java | 35 +++++++++++++ .../netconf/micro/test/NetconfModuleTest.java | 22 ++++++++ 7 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 micro-netconf/src/test/java/org/opendaylight/infrautils/micro/testutils/AbstractSimpleDistributionTest.java create mode 100644 micro-netconf/src/test/java/org/opendaylight/netconf/micro/test/NetconfModuleTest.java diff --git a/micro-core/pom.xml b/micro-core/pom.xml index 9b1b1bb..3e6c6b6 100644 --- a/micro-core/pom.xml +++ b/micro-core/pom.xml @@ -302,6 +302,11 @@ util + + org.opendaylight.yangtools + yang-xpath-impl + + org.slf4j diff --git a/micro-core/src/main/java/org/opendaylight/aaa/micro/AAAModule.java b/micro-core/src/main/java/org/opendaylight/aaa/micro/AAAModule.java index 9fae814..d8f6a96 100644 --- a/micro-core/src/main/java/org/opendaylight/aaa/micro/AAAModule.java +++ b/micro-core/src/main/java/org/opendaylight/aaa/micro/AAAModule.java @@ -8,14 +8,12 @@ package org.opendaylight.aaa.micro; import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import javax.inject.Singleton; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.aaa.api.AuthenticationException; import org.opendaylight.aaa.api.Claim; -import org.opendaylight.aaa.api.CredentialAuth; +import org.opendaylight.aaa.api.PasswordCredentialAuth; import org.opendaylight.aaa.api.PasswordCredentials; +import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration; +import org.opendaylight.aaa.filterchain.configuration.impl.CustomFilterAdapterConfigurationImpl; import org.opendaylight.aaa.shiro.tokenauthrealm.auth.ClaimBuilder; import org.opendaylight.aaa.shiro.tokenauthrealm.auth.PasswordCredentialBuilder; @@ -26,34 +24,24 @@ public class AAAModule extends AbstractModule { protected void configure() { install(new CertModule()); install(new ShiroModule()); + bind(PasswordCredentialAuth.class).toInstance(new SimplePasswordCredentialAuth()); + bind(CustomFilterAdapterConfiguration.class).toInstance(new CustomFilterAdapterConfigurationImpl()); } - @Provides - @Singleton - CredentialAuth getPasswordCredentialAuth() { - PasswordCredentials passwordCredentials = new PasswordCredentialBuilder() - .setUserName("admin") - .setPassword("admin") - .setDomain("") - .build(); - return new CredentialAuth() { - - @Nullable - @Override - public Claim authenticate(PasswordCredentials cred) throws AuthenticationException { - if (cred.equals(passwordCredentials)) { - return new ClaimBuilder() - .setUser("admin") - .build(); - } - return null; - } - - @Override - public @NonNull Class credentialClass() { - // TODO Auto-generated method stub - return PasswordCredentials.class; + public static class SimplePasswordCredentialAuth implements PasswordCredentialAuth { + @Override + public Claim authenticate(PasswordCredentials cred) throws AuthenticationException { + PasswordCredentials passwordCredentials = new PasswordCredentialBuilder() + .setUserName("admin") + .setPassword("admin") + .setDomain("") + .build(); + if (cred.equals(passwordCredentials)) { + return new ClaimBuilder() + .setUser("admin") + .build(); } - }; + return null; + } } } diff --git a/micro-core/src/main/java/org/opendaylight/controller/micro/InMemoryControllerModule.java b/micro-core/src/main/java/org/opendaylight/controller/micro/InMemoryControllerModule.java index f1eea80..830cec9 100644 --- a/micro-core/src/main/java/org/opendaylight/controller/micro/InMemoryControllerModule.java +++ b/micro-core/src/main/java/org/opendaylight/controller/micro/InMemoryControllerModule.java @@ -46,6 +46,10 @@ import org.opendaylight.mdsal.eos.dom.simple.SimpleDOMEntityOwnershipService; import org.opendaylight.mdsal.micro.MdsalModule; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.dom.impl.DOMClusterSingletonServiceProviderImpl; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; +import org.opendaylight.yangtools.yang.parser.impl.YangParserFactoryImpl; +import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory; +import org.opendaylight.yangtools.yang.xpath.impl.AntlrXPathParserFactory; @SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") @@ -123,6 +127,9 @@ public class InMemoryControllerModule extends AbstractCloseableModule { bind(EntityOwnershipService.class).toInstance(new BindingDOMEntityOwnershipServiceAdapter(eos, adapterContext)); bind(ClusterSingletonServiceProvider.class).toInstance(new DOMClusterSingletonServiceProviderImpl(eos)); + bind(YangXPathParserFactory.class).to(AntlrXPathParserFactory.class); + bind(YangParserFactory.class).to(YangParserFactoryImpl.class); + } // NETCONF diff --git a/micro-netconf/pom.xml b/micro-netconf/pom.xml index c7e2cbb..8f05fd9 100644 --- a/micro-netconf/pom.xml +++ b/micro-netconf/pom.xml @@ -101,6 +101,19 @@ aaa-cert compile + + + junit + junit + compile + + + + org.opendaylight.infrautils + infrautils-testutils + test + + diff --git a/micro-netconf/src/main/java/org/opendaylight/netconf/micro/NetconfModule.java b/micro-netconf/src/main/java/org/opendaylight/netconf/micro/NetconfModule.java index 849a740..1bde7fd 100644 --- a/micro-netconf/src/main/java/org/opendaylight/netconf/micro/NetconfModule.java +++ b/micro-netconf/src/main/java/org/opendaylight/netconf/micro/NetconfModule.java @@ -14,9 +14,7 @@ import io.netty.util.concurrent.EventExecutor; import java.util.Arrays; import java.util.concurrent.TimeUnit; import javax.inject.Singleton; -import org.opendaylight.aaa.api.CredentialAuth; import org.opendaylight.aaa.api.PasswordCredentialAuth; -import org.opendaylight.aaa.api.PasswordCredentials; import org.opendaylight.aaa.encrypt.AAAEncryptionService; import org.opendaylight.aaa.micro.AAAModule; import org.opendaylight.controller.config.threadpool.ScheduledThreadPool; @@ -314,8 +312,8 @@ public class NetconfModule extends AutoWiringModule { @Provides @Singleton @NetconfAuthProvider - CredentialServiceAuthProvider getNetconfAuthProvider(CredentialAuth credService) { - return new CredentialServiceAuthProvider((PasswordCredentialAuth) credService); + CredentialServiceAuthProvider getNetconfAuthProvider(PasswordCredentialAuth passwordCredentialAuth) { + return new CredentialServiceAuthProvider(passwordCredentialAuth); } // Converted here from netconf/aaa-authn-odl-plugin/src/main/resources/OSGI-INF/blueprint/aaa-authn-netconf.xml // END diff --git a/micro-netconf/src/test/java/org/opendaylight/infrautils/micro/testutils/AbstractSimpleDistributionTest.java b/micro-netconf/src/test/java/org/opendaylight/infrautils/micro/testutils/AbstractSimpleDistributionTest.java new file mode 100644 index 0000000..f49fdc6 --- /dev/null +++ b/micro-netconf/src/test/java/org/opendaylight/infrautils/micro/testutils/AbstractSimpleDistributionTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 OpendayLight. 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.infrautils.micro.testutils; + +import static com.google.common.truth.Truth.assertThat; + +import javax.inject.Inject; +import org.junit.Rule; +import org.junit.Test; +import org.opendaylight.infrautils.testutils.LogRule; +import org.opendaylight.odlguice.inject.guice.extensions.closeable.CloseableInjector; + +/** + * Abstract base class for micro distribution component tests. + */ +public abstract class AbstractSimpleDistributionTest { + + // TODO public static @ClassRule ClasspathHellDuplicatesCheckRule jHades = new ClasspathHellDuplicatesCheckRule(); + + public @Rule LogRule logRule = new LogRule(); + // TODO NOK together with Log4j on CP, re-enable when split into separate modules: + // public @Rule LogCaptureRule logCaptureRule = new LogCaptureRule(); + + // The point of this is really just to make sure that subclasses have a @Rule GuiceRule + private @Inject CloseableInjector closeableInjector; + + @Test public void testDistribution() { + assertThat(closeableInjector).isNotNull(); + } +} diff --git a/micro-netconf/src/test/java/org/opendaylight/netconf/micro/test/NetconfModuleTest.java b/micro-netconf/src/test/java/org/opendaylight/netconf/micro/test/NetconfModuleTest.java new file mode 100644 index 0000000..eb80e23 --- /dev/null +++ b/micro-netconf/src/test/java/org/opendaylight/netconf/micro/test/NetconfModuleTest.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2020 OpendayLight. 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.netconf.micro.test; + +import org.junit.Rule; +import org.opendaylight.infrautils.micro.testutils.AbstractSimpleDistributionTest; +import org.opendaylight.netconf.micro.NetconfModule; +import org.opendaylight.odlguice.inject.guice.GuiceClassPathBinder; +import org.opendaylight.odlguice.inject.guice.testutils.GuiceRule; + +public class NetconfModuleTest extends AbstractSimpleDistributionTest { + + private static final GuiceClassPathBinder CLASS_PATH_BINDER = new GuiceClassPathBinder("org.opendaylight"); + + public @Rule GuiceRule guice = new GuiceRule(new NetconfModule(CLASS_PATH_BINDER)); + +} -- 2.36.6