[VOL-3672] Adding per device filter to aaa-users command

Change-Id: Ifa3d9b4b0db1e21b62a24eccca772514c9acb7cd
diff --git a/app/src/main/java/org/opencord/aaa/cli/AaaShowUsersCommand.java b/app/src/main/java/org/opencord/aaa/cli/AaaShowUsersCommand.java
index 0f066d3..2aff8e5 100644
--- a/app/src/main/java/org/opencord/aaa/cli/AaaShowUsersCommand.java
+++ b/app/src/main/java/org/opencord/aaa/cli/AaaShowUsersCommand.java
@@ -15,11 +15,15 @@
  */
 package org.opencord.aaa.cli;
 
+import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onlab.util.Tools;
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cli.net.DeviceIdCompleter;
 import org.onosproject.net.AnnotationKeys;
+import org.onosproject.net.DeviceId;
 import org.onosproject.net.Port;
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.utils.Comparators;
@@ -30,6 +34,7 @@
 
 import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static com.google.common.collect.Lists.newArrayList;
 
@@ -41,6 +46,10 @@
         description = "Shows the aaa users")
 public class AaaShowUsersCommand extends AbstractShellCommand {
 
+    @Argument(index = 0, name = "deviceId", description = "Access device ID")
+    @Completion(DeviceIdCompleter.class)
+    private String strDeviceId = null;
+
     static final String UNKNOWN = "UNKNOWN";
 
     @Override
@@ -58,6 +67,13 @@
 
         authentications.sort(authenticationRecordComparator);
 
+        if (strDeviceId != null && !strDeviceId.isEmpty()) {
+            DeviceId deviceId = DeviceId.deviceId(strDeviceId);
+            authentications = authentications.stream()
+                    .filter(a -> a.supplicantConnectPoint().deviceId().equals(deviceId))
+                    .collect(Collectors.toList());
+        }
+
         for (AuthenticationRecord auth : authentications) {
             String username = UNKNOWN;
             if (auth.username() != null) {
diff --git a/app/src/main/java/org/opencord/aaa/impl/AaaManager.java b/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
index d4f0fbb..56c3912 100644
--- a/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
+++ b/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
@@ -188,6 +188,8 @@
     private ConcurrentMap<String, StateMachine> stateMachines;
 
     private ConsistentMap<ConnectPoint, AuthenticationRecord> authenticationsConsistentMap;
+    // NOTE consider to change this map to be Map<DeviceId,Map<ConnectPoint, AuthenticationRecord>> so that
+    // we can iterate on smalled collection when dealing with authentications
     private Map<ConnectPoint, AuthenticationRecord> authentications;
 
     // NAS IP address
diff --git a/app/src/test/java/org/opencord/aaa/impl/AaaIntegrationTest.java b/app/src/test/java/org/opencord/aaa/impl/AaaIntegrationTest.java
index b6c9fe8..3a4d947 100644
--- a/app/src/test/java/org/opencord/aaa/impl/AaaIntegrationTest.java
+++ b/app/src/test/java/org/opencord/aaa/impl/AaaIntegrationTest.java
@@ -43,7 +43,7 @@
     /**
      * Mocks the network config registry.
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
     static final class TestNetworkConfigRegistry
             extends NetworkConfigRegistryAdapter {
         @Override
diff --git a/app/src/test/java/org/opencord/aaa/impl/AaaManagerTest.java b/app/src/test/java/org/opencord/aaa/impl/AaaManagerTest.java
index 394f86d..f0e93ef 100644
--- a/app/src/test/java/org/opencord/aaa/impl/AaaManagerTest.java
+++ b/app/src/test/java/org/opencord/aaa/impl/AaaManagerTest.java
@@ -107,7 +107,7 @@
     /**
      * Mocks the network config registry.
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
     private static final class TestNetworkConfigRegistry
             extends NetworkConfigRegistryAdapter {
         @Override
diff --git a/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java b/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
index bd68bfb..4442f65 100644
--- a/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
+++ b/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
@@ -115,7 +115,7 @@
     /**
      * Mocks the network config registry.
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
     private static final class TestNetworkConfigRegistry extends NetworkConfigRegistryAdapter {
         @Override
         public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {