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; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame^] | 20 | import org.onlab.util.Tools; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 21 | import org.onosproject.cli.AbstractShellCommand; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 22 | import org.onosproject.net.AnnotationKeys; |
| 23 | import org.onosproject.net.device.DeviceService; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 24 | import org.opencord.aaa.AuthenticationRecord; |
| 25 | import org.opencord.aaa.AuthenticationService; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 26 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 27 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Shows the users in the aaa. |
| 31 | */ |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 32 | @Service |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 33 | @Command(scope = "onos", name = "aaa-users", |
| 34 | description = "Shows the aaa users") |
| 35 | public class AaaShowUsersCommand extends AbstractShellCommand { |
| 36 | @Override |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 37 | protected void doExecute() { |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 38 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 39 | DeviceService devService = get(DeviceService.class); |
| 40 | SadisService sadisService = get(SadisService.class); |
| 41 | AuthenticationService authService = get(AuthenticationService.class); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 42 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 43 | for (AuthenticationRecord auth : authService.getAuthenticationRecords()) { |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 44 | String username = "UNKNOWN"; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 45 | if (auth.username() != null) { |
| 46 | username = new String(auth.username()); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 47 | } |
| 48 | String mac = "UNKNOWN"; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 49 | if (auth.supplicantAddress() != null) { |
| 50 | mac = auth.supplicantAddress().toString(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 51 | } |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 52 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 53 | String nasPortId = devService.getPort(auth.supplicantConnectPoint()). |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 54 | annotations().value(AnnotationKeys.PORT_NAME); |
| 55 | |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 56 | String subsId = "UNKNOWN"; |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 57 | SubscriberAndDeviceInformation subscriber = sadisService.getSubscriberInfoService().get(nasPortId); |
Amit Ghosh | 6bf21a2 | 2017-08-23 12:45:09 +0100 | [diff] [blame] | 58 | if (subscriber != null) { |
| 59 | subsId = subscriber.nasPortId(); |
| 60 | } |
| 61 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame^] | 62 | 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 Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | } |