Add Admin user/pass as arguments 93/90193/9
authorgvrangan <vgovindarajan@luminanetworks.com>
Mon, 1 Jun 2020 18:34:58 +0000 (00:04 +0530)
committergvrangan <vgovindarajan@luminanetworks.com>
Wed, 1 Jul 2020 17:51:46 +0000 (23:21 +0530)
- This Patch makes admin username and password as arguments
  with censor as true instead of challenging as input. This
  will print the string as wildcard in the command line as
  well as history file.

- eliminates the use of cache to avoid one session login to
  be used in another session.

- Deleted the aliases in the options with censor enabled due to the
  problem in karaf (https://issues.apache.org/jira/browse/KARAF-6769)

JIRA: AAA-189
Signed-off-by: gvrangan <vgovindarajan@luminanetworks.com>
Change-Id: Ief5b0177273baf39fc8afe248b8e5055f40cdc0e

19 files changed:
aaa-cli/src/main/java/org/opendaylight/aaa/cli/AaaCliAbstractCommand.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/SessionsManager.java [deleted file]
aaa-cli/src/main/java/org/opendaylight/aaa/cli/cert/GenerateCertReq.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/cert/GetODLSelfSignCert.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/cert/GetTrustStoreCert.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/AddDomain.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/AddGrant.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/AddRole.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/AddUser.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/ChangeUserPassword.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/ListODLDomains.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/ListODLRoles.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/ListODLUsers.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/RemoveDomain.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/RemoveGrant.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/RemoveRole.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/dmstore/RemoveUser.java
aaa-cli/src/main/java/org/opendaylight/aaa/cli/utils/CliUtils.java [deleted file]
aaa-cli/src/test/java/org/opendaylight/aaa/cli/test/SessionsManagerTest.java [deleted file]

index 628937c477b970d5b22254159f4282a41e1c36e3..d348e6feb1303e8475103f555edba6a32c1f1435 100644 (file)
@@ -10,11 +10,11 @@ package org.opendaylight.aaa.cli;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.opendaylight.aaa.api.IIDMStore;
 import org.opendaylight.aaa.api.model.User;
 import org.opendaylight.aaa.api.password.service.PasswordHashService;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -26,26 +26,29 @@ import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
 @SuppressWarnings("checkstyle:RegexpSingleLineJava")
 public abstract class AaaCliAbstractCommand implements Action {
+    public static final String LOGIN_FAILED_MESS = "User does not exist OR user name and passsword are not correct";
 
-    private static volatile String authUser = null;
+    @Option(name = "-aaaAdmin",
+            description = "AAA admin username",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String userName;
+
+    @Option(name = "-aaaAdminPass",
+            description = "AAA Admin password",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String passwd;
 
     @Reference protected IIDMStore identityStore;
     @Reference private PasswordHashService passwordService;
 
     @Override
     public Object execute() throws Exception {
-        final User currentUser = SessionsManager.getInstance().getCurrentUser(authUser);
-        if (currentUser == null) {
-            final String userName = CliUtils.readPassword("Enter Username:");
-            final String passwd = CliUtils.readPassword("Enter Password:");
-            final User usr = DataStoreUtils.isAdminUser(identityStore, passwordService, userName, passwd);
-            if (usr != null) {
-                authUser = userName;
-                SessionsManager.getInstance().addUserSession(userName, usr);
-            }
-            return usr;
-        }
-        return currentUser;
+        final User usr = DataStoreUtils.isAdminUser(identityStore, passwordService, userName, passwd);
+        return usr;
     }
 
     protected void list(String name, Collection<?> items) {
diff --git a/aaa-cli/src/main/java/org/opendaylight/aaa/cli/SessionsManager.java b/aaa-cli/src/main/java/org/opendaylight/aaa/cli/SessionsManager.java
deleted file mode 100644 (file)
index ca35b29..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2016, 2017 Inocybe Technologies. 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.cli;
-
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
-import net.sf.ehcache.config.CacheConfiguration;
-import net.sf.ehcache.config.Configuration;
-import net.sf.ehcache.config.ConfigurationFactory;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.aaa.api.model.User;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * The SessionsManager class will keep the admin user credential vaild at the
- * cache for certain time instead of required the admin user to enter the
- * username and pwd with each aaa-cli command.
- *
- * @author mserngawy
- *
- */
-public final class SessionsManager implements AutoCloseable {
-
-    private static final Logger LOG = LoggerFactory.getLogger(SessionsManager.class);
-
-    private static SessionsManager sessionMgr = new SessionsManager();
-    private final Cache authUsers;
-    private static final int MAX_CACHED_USERS_IN_MEMORY = 1;
-    private static final int MAX_CACHED_USERS_ON_DISK = 1;
-    private static final long SECONDS_TO_LIVE = 120;
-    private static final long SECONDS_TO_IDLE = 60;
-    private static final String CLI_CACHE_MANAGER = "org.opendaylight.aaa.cli";
-    private static final String CLI_CACHE = "users";
-
-    private SessionsManager() {
-        // When we restart, the cache manager and CLI cache are already there
-        CacheManager cm = CacheManager.getCacheManager(CLI_CACHE_MANAGER);
-        if (cm == null) {
-            Configuration configuration = ConfigurationFactory.parseConfiguration();
-            configuration.setName(CLI_CACHE_MANAGER);
-            cm = CacheManager.newInstance();
-        }
-        Cache existingCache = cm.getCache(CLI_CACHE);
-        if (existingCache != null) {
-            authUsers = existingCache;
-        } else {
-            authUsers = new Cache(new CacheConfiguration(CLI_CACHE, MAX_CACHED_USERS_IN_MEMORY)
-                    .maxEntriesLocalDisk(MAX_CACHED_USERS_ON_DISK).timeToLiveSeconds(SECONDS_TO_LIVE)
-                    .timeToIdleSeconds(SECONDS_TO_IDLE));
-            cm.addCache(authUsers);
-        }
-        LOG.info("Initialized cli authorized users cache manager");
-    }
-
-    public static SessionsManager getInstance() {
-        return sessionMgr;
-    }
-
-    @Override
-    public void close() {
-        LOG.info("Shutting down cli authorized users cache manager");
-        CacheManager.getInstance().shutdown();
-    }
-
-    public void addUserSession(final String userName, final User usr) {
-        authUsers.put(new Element(userName, usr));
-    }
-
-    /**
-     * Attempt to find the {@link User} associated with the given user name in the cache.
-     *
-     * @param userName The string to use for cache lookup
-     * @return The {@link User} associated with the given user name, if not cached return null.
-     */
-    public @Nullable User getCurrentUser(final String userName) {
-        Element elem = authUsers.get(userName);
-        if (elem != null) {
-            return (User) elem.getObjectValue();
-        }
-        return null;
-    }
-}
index 29ff2ef97a0994a22a341dcf04e584bf7bf21ea4..98d97e60967f7281f8ed74e34d96d019daad3575 100644 (file)
@@ -10,10 +10,10 @@ package org.opendaylight.aaa.cli.cert;
 
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.cert.api.ICertificateManager;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * GenerateCertReq from the ODL key store to be signed by the Certificate
@@ -28,10 +28,15 @@ import org.opendaylight.aaa.cli.utils.CliUtils;
 public class GenerateCertReq implements Action {
 
     @Reference private ICertificateManager certProvider;
+    @Option(name = "-keyStorePass",
+            description = "Keystore Password",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String pwd;
 
     @Override
     public Object execute() throws Exception {
-        final String pwd = CliUtils.readPassword("Enter Keystore Password:");
         return certProvider.genODLKeyStoreCertificateReq(pwd, true);
     }
 }
index abd6d86456a29fc68b8c12d0bceeacba9c33dc63..bc31f4e075736e5bea67efc682b68034c4b2771b 100644 (file)
@@ -10,10 +10,10 @@ package org.opendaylight.aaa.cli.cert;
 
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.cert.api.ICertificateManager;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * GetODLSelfSignCert get the ODL key store self sign certificate.
@@ -27,10 +27,15 @@ import org.opendaylight.aaa.cli.utils.CliUtils;
 public class GetODLSelfSignCert implements Action {
 
     @Reference private ICertificateManager certProvider;
+    @Option(name = "-keyStorePass",
+            description = "Keystore Password",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String pwd;
 
     @Override
     public Object execute() throws Exception {
-        final String pwd = CliUtils.readPassword("Enter Keystore Password:");
         return certProvider.getODLKeyStoreCertificate(pwd, true);
     }
 }
index ffcfac8e7a51d65edd8a5a91a06fc47eaa1a9d2a..40ca8810ea2498b07c088f94cbc5e56d021d9e09 100644 (file)
@@ -14,7 +14,6 @@ import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.cert.api.ICertificateManager;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * GetTrustStoreCert get a certain certificate stored in the trust key store
@@ -30,14 +29,22 @@ public class GetTrustStoreCert implements Action {
 
     @Reference private ICertificateManager certProvider;
 
-    @Option(name = "-alias", aliases = {"--alias" },
+    @Option(name = "-alias",
+            aliases = {"--alias" },
             description = "The alias.\n-alias / --should be the node certificate alias",
-            required = true, multiValued = false)
+            required = true,
+            multiValued = false)
     private String alias;
 
+    @Option(name = "-keyStorePass",
+            description = "Keystore Password",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String pwd;
+
     @Override
     public Object execute() throws Exception {
-        final String pwd = CliUtils.readPassword("Enter Keystore Password:");
         return certProvider.getCertificateTrustStore(pwd, alias, true);
     }
 }
index f09c844d936356c583c221eb3d70d0ce83d64408..d566bd993d406bfbd51493f317b87044ba26bf42 100644 (file)
@@ -13,7 +13,6 @@ import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.api.model.Domain;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * Adds a domain.
@@ -35,7 +34,7 @@ public class AddDomain extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         Domain domain = new Domain();
         domain.setDescription(domainDesc);
index a7384537f2b17541597688ed030eff6b712af719..da8ca018fc22f7328b0672d1874a7d794f604812 100644 (file)
@@ -13,7 +13,6 @@ import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.api.model.Grant;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -40,7 +39,7 @@ public class AddGrant extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
         if (domainId == null) {
index d771de62245eecec34fc0cf78b0e62e23c3a8b74..eb4d99b4873737d2807f1ff2e8e74a0619a34f61 100644 (file)
@@ -13,7 +13,6 @@ import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.api.model.Role;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -40,7 +39,7 @@ public class AddRole extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         Role role = new Role();
         role.setDescription(roleDesc);
index 0f29cea8707a617de304f3e81dcb7241f5b57231..72d32f301914fc8fb7357532d3476922931b89a3 100644 (file)
@@ -14,7 +14,6 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.api.model.Grant;
 import org.opendaylight.aaa.api.model.User;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -33,6 +32,13 @@ public class AddUser extends AaaCliAbstractCommand {
             multiValued = false)
     private String userName;
 
+    @Option(name = "-pass",
+            description = "Password for new User",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String passWord;
+
     @Option(name = "-dname",
             aliases = { "--domainName" },
             description = "The domain name",
@@ -64,7 +70,7 @@ public class AddUser extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
         if (domainId == null) {
@@ -75,11 +81,10 @@ public class AddUser extends AaaCliAbstractCommand {
         usr.setDomainid(domainId);
         usr.setEnabled(true);
         usr.setEmail(userEmail);
-        final String pwd = CliUtils.readPassword("Enter new user password: ");
-        if (pwd == null || pwd.isEmpty() || pwd.length() < 6) {
+        if (passWord.isEmpty() || passWord.length() < 6) {
             return "Password should be at least 6 characters";
         }
-        usr.setPassword(pwd);
+        usr.setPassword(passWord);
         usr.setName(userName);
         usr = identityStore.writeUser(usr);
         if (usr != null) {
index 22308e9ab2184c4fbd44737e91d4be74348cbb85..659287522ab3938cd506ca37d26c1c6dd00c268e 100644 (file)
@@ -13,12 +13,10 @@ import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.opendaylight.aaa.api.ClaimCache;
 import org.opendaylight.aaa.api.IIDMStore;
 import org.opendaylight.aaa.api.model.User;
 import org.opendaylight.aaa.api.model.Users;
 import org.opendaylight.aaa.api.password.service.PasswordHashService;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * ChangeUserPassword change the user password.
@@ -29,13 +27,27 @@ import org.opendaylight.aaa.cli.utils.CliUtils;
 @Command(name = "change-user-pwd", scope = "aaa", description = "Change the user password.")
 public class ChangeUserPassword implements Action {
 
+    public static final String CHANGE_PASSWORD_FAIL = "Wrong username or current password";
     @Reference private IIDMStore identityStore;
-    @Reference private ClaimCache claimCache;
 
     @Option(name = "-user", aliases = {
             "--userName" }, description = "The user name", required = true, multiValued = false)
     private String userName;
 
+    @Option(name = "-pass",
+            description = "User's Current Password",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String currentPwd;
+
+    @Option(name = "-newPass",
+            description = "New Password",
+            required = true,
+            censor = true,
+            multiValued = false)
+    private String newPwd;
+
     @Reference private PasswordHashService passwordService;
 
     @Override
@@ -43,18 +55,15 @@ public class ChangeUserPassword implements Action {
         if (identityStore == null) {
             return "Failed to access the users data store";
         }
-        final String currentPwd = CliUtils.readPassword("Enter current password:");
-        final String newPwd = CliUtils.readPassword("Enter new password:");
         final Users users = identityStore.getUsers();
         for (User usr : users.getUsers()) {
             if (usr.getName().equals(userName)
                     && passwordService.passwordsMatch(currentPwd, usr.getPassword(), usr.getSalt())) {
-                claimCache.clear();
                 usr.setPassword(newPwd);
                 identityStore.updateUser(usr);
                 return userName + "'s password has been changed";
             }
         }
-        return CliUtils.LOGIN_FAILED_MESS;
+        return CHANGE_PASSWORD_FAIL;
     }
 }
index 64fa29d14ba7e3d312223b590b251082d1b38773..76e7f77ad4a1c4cb692f7cddab887a34d1caa42a 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.aaa.cli.dmstore;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * ListODLDomains list the available domains at ODL aaa data store.
@@ -25,7 +24,7 @@ public class ListODLDomains extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         list("Domains: ", identityStore.getDomains().getDomains());
         return null;
index 502d3b7eff126c4496e6935a9c1f5ecf868fd5d1..1e78366a982ca2893f3b2270555b31d519a4d62c 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.aaa.cli.dmstore;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * ListODLDomains list the available roles at ODL aaa data store.
@@ -25,7 +24,7 @@ public class ListODLRoles extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         list("Roles: ", identityStore.getRoles().getRoles());
         return null;
index 0bd78e18cf878552f0a946412be3f253f8dd4aa5..76802ef30b03232ce1258da683c1f1ffad3ee579 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.aaa.cli.dmstore;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 
 /**
  * ListODLDomains list the available users at ODL aaa data store.
@@ -25,7 +24,7 @@ public class ListODLUsers extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         list("Users: ", identityStore.getUsers().getUsers());
         return null;
index 71f8b47ee30d8153e38315064d7d1a24a747c09a..9992af69fc4e191b3914d4ee1ab178fdef4991c8 100644 (file)
@@ -10,11 +10,8 @@ package org.opendaylight.aaa.cli.dmstore;
 
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.opendaylight.aaa.api.ClaimCache;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -26,7 +23,6 @@ import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 @Command(name = "remove-domain", scope = "aaa", description = "Remove domain.")
 public class RemoveDomain extends AaaCliAbstractCommand {
 
-    @Reference private ClaimCache claimCache;
 
     @Option(name = "-name", aliases = {
             "--domainName" }, description = "The domain name", required = true, multiValued = false)
@@ -35,7 +31,7 @@ public class RemoveDomain extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         final String domainId = DataStoreUtils.getDomainId(identityStore, domainName);
         if (domainId == null) {
@@ -44,7 +40,6 @@ public class RemoveDomain extends AaaCliAbstractCommand {
         if (identityStore.deleteDomain(domainId) == null) {
             return "Failed to delete domain " + domainName;
         }
-        claimCache.clear();
         return "Domain " + domainName + "has been deleted.";
     }
 }
index 67fff60955f0274bbcae769a923f41ccff567663..d54db5af6d51155b9216c2ee930c49c353bf332a 100644 (file)
@@ -10,11 +10,8 @@ package org.opendaylight.aaa.cli.dmstore;
 
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.opendaylight.aaa.api.ClaimCache;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -26,7 +23,6 @@ import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 @Command(name = "remove-grant", scope = "aaa", description = "Remove grant.")
 public class RemoveGrant extends AaaCliAbstractCommand {
 
-    @Reference private ClaimCache claimCache;
 
     @Option(name = "-uname", aliases = {
             "--userName" }, description = "The user name", required = true, multiValued = false)
@@ -43,7 +39,7 @@ public class RemoveGrant extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         final String grantid = DataStoreUtils.getGrantId(identityStore, domainName, roleName, userName);
         if (grantid == null) {
@@ -52,7 +48,6 @@ public class RemoveGrant extends AaaCliAbstractCommand {
         if (identityStore.deleteGrant(grantid) == null) {
             return "Failed to delete grant " + userName + " " + roleName + " " + domainName;
         }
-        claimCache.clear();
         return "Grant has been deleted.";
     }
 }
index 071309caa3089fe0814339a9847bf94fade11c9c..31a1374cdc8e718cab89fb1f9eaee20f8b5d219e 100644 (file)
@@ -10,11 +10,8 @@ package org.opendaylight.aaa.cli.dmstore;
 
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.opendaylight.aaa.api.ClaimCache;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -26,7 +23,6 @@ import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 @Command(name = "remove-role", scope = "aaa", description = "Remove role.")
 public class RemoveRole extends AaaCliAbstractCommand {
 
-    @Reference private ClaimCache claimCache;
 
     @Option(name = "-name", aliases = {
             "--roleName" }, description = "The role name", required = true, multiValued = false)
@@ -35,7 +31,7 @@ public class RemoveRole extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         final String roleId = DataStoreUtils.getRoleId(identityStore, roleName);
         if (roleId == null) {
@@ -44,7 +40,6 @@ public class RemoveRole extends AaaCliAbstractCommand {
         if (identityStore.deleteRole(roleId) == null) {
             return "Failed to delete role " + roleName;
         }
-        claimCache.clear();
         return "Role " + roleName + "has been deleted.";
     }
 }
index 97084f88488264b7c68258bbfd610f72dab4f9a5..b5f5b43ed70f5f1e25cf22d8a67cd9ec7c613ddc 100644 (file)
@@ -10,11 +10,8 @@ package org.opendaylight.aaa.cli.dmstore;
 
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.opendaylight.aaa.api.ClaimCache;
 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
-import org.opendaylight.aaa.cli.utils.CliUtils;
 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 
 /**
@@ -26,7 +23,6 @@ import org.opendaylight.aaa.cli.utils.DataStoreUtils;
 @Command(name = "remove-user", scope = "aaa", description = "Remove user.")
 public class RemoveUser extends AaaCliAbstractCommand {
 
-    @Reference private ClaimCache claimCache;
 
     @Option(name = "-name", aliases = {
             "--userName" }, description = "The user name", required = true, multiValued = false)
@@ -35,7 +31,7 @@ public class RemoveUser extends AaaCliAbstractCommand {
     @Override
     public Object execute() throws Exception {
         if (super.execute() == null) {
-            return CliUtils.LOGIN_FAILED_MESS;
+            return LOGIN_FAILED_MESS;
         }
         final String usrId = DataStoreUtils.getUserId(identityStore, userName);
         if (usrId == null) {
@@ -44,7 +40,6 @@ public class RemoveUser extends AaaCliAbstractCommand {
         if (identityStore.deleteUser(usrId) == null) {
             return "Failed to delete user " + userName;
         }
-        claimCache.clear();
         return "User " + userName + "has been deleted.";
     }
 }
diff --git a/aaa-cli/src/main/java/org/opendaylight/aaa/cli/utils/CliUtils.java b/aaa-cli/src/main/java/org/opendaylight/aaa/cli/utils/CliUtils.java
deleted file mode 100644 (file)
index 343cf7f..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2016, 2017 Inocybe Technologies. 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.cli.utils;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-
-/**
- * CliUtils has helper methods for CLI bundle.
- *
- * @author mserngawy
- *
- */
-@SuppressWarnings("checkstyle:RegexpSingleLineJava")
-public final class CliUtils {
-
-    public static final String LOGIN_FAILED_MESS = "User does not exist OR user name and passsword are not correct";
-
-    private CliUtils() {
-
-    }
-
-    /**
-     * Retrieve the password from the user.
-     *
-     * @param pwdPrintStr
-     *            label for enter password
-     * @return the new written password
-     * @throws Exception
-     *             exception reading the password
-     */
-    public static String readPassword(final String pwdPrintStr) throws Exception {
-        System.out.println(pwdPrintStr);
-        try (BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8))) {
-            return bReader.readLine();
-        }
-    }
-}
diff --git a/aaa-cli/src/test/java/org/opendaylight/aaa/cli/test/SessionsManagerTest.java b/aaa-cli/src/test/java/org/opendaylight/aaa/cli/test/SessionsManagerTest.java
deleted file mode 100644 (file)
index 0ed41c8..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2016, 2017 Inocybe Technologies. 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.cli.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.opendaylight.aaa.api.model.User;
-import org.opendaylight.aaa.cli.SessionsManager;
-
-/**
- * Test for Session Manager.
- *
- * @author mserngawy
- *
- */
-public class SessionsManagerTest {
-
-    @Test
-    public void testSessionManager() {
-        SessionsManager sessionMngr = SessionsManager.getInstance();
-        assertNotNull(sessionMngr);
-        final String usrName = "foo";
-        final User usr = new User();
-        usr.setName(usrName);
-        usr.setDomainid("fooDomain");
-        usr.setPassword("fooPwd");
-        sessionMngr.addUserSession(usrName, usr);
-        final User authUsr = sessionMngr.getCurrentUser(usrName);
-        assertNotNull(authUsr);
-        assertEquals(usr, authUsr);
-    }
-}