blob: cd1cea556777b86a7fdb47c07c3b583f6fefd48f [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;
Qianqian Hu61a6a402016-02-16 15:18:05 +080020import org.onosproject.cli.AbstractShellCommand;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010021import org.onosproject.net.AnnotationKeys;
22import org.onosproject.net.device.DeviceService;
Jonathan Hart612651f2019-11-25 09:21:43 -080023import org.opencord.aaa.AuthenticationRecord;
24import org.opencord.aaa.AuthenticationService;
Gamze Abaka1cfdb192018-10-25 11:39:19 +000025import org.opencord.sadis.SadisService;
Amit Ghosh6bf21a22017-08-23 12:45:09 +010026import org.opencord.sadis.SubscriberAndDeviceInformation;
Qianqian Hu61a6a402016-02-16 15:18:05 +080027
28/**
29 * Shows the users in the aaa.
30 */
Carmelo Cascone58b53292019-09-30 12:35:31 -070031@Service
Qianqian Hu61a6a402016-02-16 15:18:05 +080032@Command(scope = "onos", name = "aaa-users",
33 description = "Shows the aaa users")
34public class AaaShowUsersCommand extends AbstractShellCommand {
35 @Override
Carmelo Cascone58b53292019-09-30 12:35:31 -070036 protected void doExecute() {
Amit Ghosh6bf21a22017-08-23 12:45:09 +010037
Jonathan Hart612651f2019-11-25 09:21:43 -080038 DeviceService devService = get(DeviceService.class);
39 SadisService sadisService = get(SadisService.class);
40 AuthenticationService authService = get(AuthenticationService.class);
Amit Ghosh6bf21a22017-08-23 12:45:09 +010041
Jonathan Hart612651f2019-11-25 09:21:43 -080042 for (AuthenticationRecord auth : authService.getAuthenticationRecords()) {
43 String deviceId = auth.supplicantConnectPoint().deviceId().toString();
44 String portNum = auth.supplicantConnectPoint().port().toString();
Amit Ghoshf739be52017-09-21 15:49:37 +010045
46 String username = "UNKNOWN";
Jonathan Hart612651f2019-11-25 09:21:43 -080047 if (auth.username() != null) {
48 username = new String(auth.username());
Amit Ghoshf739be52017-09-21 15:49:37 +010049 }
50 String mac = "UNKNOWN";
Jonathan Hart612651f2019-11-25 09:21:43 -080051 if (auth.supplicantAddress() != null) {
52 mac = auth.supplicantAddress().toString();
Amit Ghoshf739be52017-09-21 15:49:37 +010053 }
Amit Ghosh6bf21a22017-08-23 12:45:09 +010054
Jonathan Hart612651f2019-11-25 09:21:43 -080055 String nasPortId = devService.getPort(auth.supplicantConnectPoint()).
Amit Ghosh6bf21a22017-08-23 12:45:09 +010056 annotations().value(AnnotationKeys.PORT_NAME);
57
Amit Ghoshf739be52017-09-21 15:49:37 +010058 String subsId = "UNKNOWN";
Gamze Abaka1cfdb192018-10-25 11:39:19 +000059 SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId);
Amit Ghosh6bf21a22017-08-23 12:45:09 +010060 if (subscriber != null) {
61 subsId = subscriber.nasPortId();
62 }
63
64 print("UserName=%s,CurrentState=%s,DeviceId=%s,MAC=%s,PortNumber=%s,SubscriberId=%s",
Jonathan Hart612651f2019-11-25 09:21:43 -080065 username, auth.state(), deviceId, mac, portNum, subsId);
Qianqian Hu61a6a402016-02-16 15:18:05 +080066 }
67 }
68}