[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) {