blob: 11958a6d93c0338b652e17f42415b96ca3d9b6fa [file] [log] [blame]
Qianqian Hu61a6a402016-02-16 15:18:05 +08001/*
Brian O'Connor4e33be22017-08-03 22:45:46 -07002 * Copyright 2016-present Open Networking Foundation
Qianqian Hu61a6a402016-02-16 15:18:05 +08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carmelo Cascone58b53292019-09-30 12:35:31 -070016package org.opencord.aaa.cli;
Qianqian Hu61a6a402016-02-16 15:18:05 +080017
Carmelo Cascone58b53292019-09-30 12:35:31 -070018import org.apache.karaf.shell.api.action.Command;
19import org.apache.karaf.shell.api.action.lifecycle.Service;
Jonathan Hart9d1ce802020-01-28 10:45:08 -080020import org.onlab.util.Tools;
Qianqian Hu61a6a402016-02-16 15:18:05 +080021import org.onosproject.cli.AbstractShellCommand;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010022import org.onosproject.net.AnnotationKeys;
23import org.onosproject.net.device.DeviceService;
Jonathan Hart612651f2019-11-25 09:21:43 -080024import org.opencord.aaa.AuthenticationRecord;
25import org.opencord.aaa.AuthenticationService;
Gamze Abaka1cfdb192018-10-25 11:39:19 +000026import org.opencord.sadis.SadisService;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010027import org.opencord.sadis.SubscriberAndDeviceInformation;
Qianqian Hu61a6a402016-02-16 15:18:05 +080028
29/**
30 * Shows the users in the aaa.
31 */
Carmelo Cascone58b53292019-09-30 12:35:31 -070032@Service
Qianqian Hu61a6a402016-02-16 15:18:05 +080033@Command(scope = "onos", name = "aaa-users",
34 description = "Shows the aaa users")
35public class AaaShowUsersCommand extends AbstractShellCommand {
36 @Override
Carmelo Cascone58b53292019-09-30 12:35:31 -070037 protected void doExecute() {
Amit Ghosh6bf21a22017-08-23 12:45:09 +010038
Jonathan Hart612651f2019-11-25 09:21:43 -080039 DeviceService devService = get(DeviceService.class);
40 SadisService sadisService = get(SadisService.class);
41 AuthenticationService authService = get(AuthenticationService.class);
Amit Ghosh6bf21a22017-08-23 12:45:09 +010042
Jonathan Hart612651f2019-11-25 09:21:43 -080043 for (AuthenticationRecord auth : authService.getAuthenticationRecords()) {
Amit Ghoshf739be52017-09-21 15:49:37 +010044 String username = "UNKNOWN";
Jonathan Hart612651f2019-11-25 09:21:43 -080045 if (auth.username() != null) {
46 username = new String(auth.username());
Amit Ghoshf739be52017-09-21 15:49:37 +010047 }
48 String mac = "UNKNOWN";
Jonathan Hart612651f2019-11-25 09:21:43 -080049 if (auth.supplicantAddress() != null) {
50 mac = auth.supplicantAddress().toString();
Amit Ghoshf739be52017-09-21 15:49:37 +010051 }
Amit Ghosh6bf21a22017-08-23 12:45:09 +010052
Jonathan Hart612651f2019-11-25 09:21:43 -080053 String nasPortId = devService.getPort(auth.supplicantConnectPoint()).
Amit Ghosh6bf21a22017-08-23 12:45:09 +010054 annotations().value(AnnotationKeys.PORT_NAME);
55
Amit Ghoshf739be52017-09-21 15:49:37 +010056 String subsId = "UNKNOWN";
Gamze Abaka1cfdb192018-10-25 11:39:19 +000057 SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId);
Amit Ghosh6bf21a22017-08-23 12:45:09 +010058 if (subscriber != null) {
59 subsId = subscriber.nasPortId();
60 }
61
Jonathan Hart9d1ce802020-01-28 10:45:08 -080062 print("%s: %s, last-changed=%s, mac=%s, subid=%s, username=%s",
63 auth.supplicantConnectPoint(), auth.state(), Tools.timeAgo(auth.lastChanged()),
64 mac, subsId, username);
Qianqian Hu61a6a402016-02-16 15:18:05 +080065 }
66 }
67}