Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 4e33be2 | 2017-08-03 22:45:46 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 3 | * |
| 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 Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 16 | package org.opencord.aaa.cli; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 17 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 20 | import org.onosproject.cli.AbstractShellCommand; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 21 | import org.onosproject.net.AnnotationKeys; |
| 22 | import org.onosproject.net.device.DeviceService; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 23 | import org.opencord.aaa.AuthenticationRecord; |
| 24 | import org.opencord.aaa.AuthenticationService; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 25 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 26 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Shows the users in the aaa. |
| 30 | */ |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 31 | @Service |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 32 | @Command(scope = "onos", name = "aaa-users", |
| 33 | description = "Shows the aaa users") |
| 34 | public class AaaShowUsersCommand extends AbstractShellCommand { |
| 35 | @Override |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 36 | protected void doExecute() { |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 37 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 38 | DeviceService devService = get(DeviceService.class); |
| 39 | SadisService sadisService = get(SadisService.class); |
| 40 | AuthenticationService authService = get(AuthenticationService.class); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 41 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 42 | for (AuthenticationRecord auth : authService.getAuthenticationRecords()) { |
| 43 | String deviceId = auth.supplicantConnectPoint().deviceId().toString(); |
| 44 | String portNum = auth.supplicantConnectPoint().port().toString(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 45 | |
| 46 | String username = "UNKNOWN"; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 47 | if (auth.username() != null) { |
| 48 | username = new String(auth.username()); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 49 | } |
| 50 | String mac = "UNKNOWN"; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 51 | if (auth.supplicantAddress() != null) { |
| 52 | mac = auth.supplicantAddress().toString(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 53 | } |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 54 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 55 | String nasPortId = devService.getPort(auth.supplicantConnectPoint()). |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 56 | annotations().value(AnnotationKeys.PORT_NAME); |
| 57 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 58 | String subsId = "UNKNOWN"; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 59 | SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 60 | if (subscriber != null) { |
| 61 | subsId = subscriber.nasPortId(); |
| 62 | } |
| 63 | |
| 64 | print("UserName=%s,CurrentState=%s,DeviceId=%s,MAC=%s,PortNumber=%s,SubscriberId=%s", |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame^] | 65 | username, auth.state(), deviceId, mac, portNum, subsId); |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |