Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [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 | * |
| 16 | */ |
| 17 | |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 18 | package org.opencord.aaa.impl; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 19 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame^] | 20 | import com.google.common.collect.Maps; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onosproject.net.ConnectPoint; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 23 | import org.opencord.aaa.AuthenticationEvent; |
| 24 | import org.opencord.aaa.StateMachineDelegate; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 25 | import org.slf4j.Logger; |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 26 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame^] | 27 | import java.util.HashSet; |
| 28 | import java.util.Map; |
| 29 | import java.util.Set; |
| 30 | |
| 31 | import static org.slf4j.LoggerFactory.getLogger; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * AAA Finite State Machine. |
| 35 | */ |
| 36 | |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 37 | public class StateMachine { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 38 | //INDEX to identify the state in the transition table |
| 39 | static final int STATE_IDLE = 0; |
| 40 | static final int STATE_STARTED = 1; |
| 41 | static final int STATE_PENDING = 2; |
| 42 | static final int STATE_AUTHORIZED = 3; |
| 43 | static final int STATE_UNAUTHORIZED = 4; |
| 44 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 45 | // Defining the states where timeout can happen |
| 46 | static final Set<Integer> TIMEOUT_ELIGIBLE_STATES = new HashSet(); |
| 47 | static { |
| 48 | TIMEOUT_ELIGIBLE_STATES.add(STATE_STARTED); |
| 49 | TIMEOUT_ELIGIBLE_STATES.add(STATE_PENDING); |
| 50 | } |
| 51 | // INDEX to identify the transition in the transition table |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 52 | static final int TRANSITION_START = 0; // --> started |
| 53 | static final int TRANSITION_REQUEST_ACCESS = 1; |
| 54 | static final int TRANSITION_AUTHORIZE_ACCESS = 2; |
| 55 | static final int TRANSITION_DENY_ACCESS = 3; |
| 56 | static final int TRANSITION_LOGOFF = 4; |
| 57 | |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame^] | 58 | private static int identifier = 1; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 59 | private byte challengeIdentifier; |
| 60 | private byte[] challengeState; |
| 61 | private byte[] username; |
| 62 | private byte[] requestAuthenticator; |
| 63 | |
| 64 | // Supplicant connectivity info |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 65 | private ConnectPoint supplicantConnectpoint; |
| 66 | private MacAddress supplicantAddress; |
| 67 | private short vlanId; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 68 | private byte priorityCode; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 69 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 70 | // Boolean flag indicating whether response is pending from AAA Server. |
| 71 | // Used for counting timeout happening for AAA Sessions due to no response. |
| 72 | private boolean waitingForRadiusResponse; |
| 73 | |
| 74 | private static int cleanupTimerTimeOutInMins; |
| 75 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 76 | private String sessionId = null; |
| 77 | |
| 78 | private final Logger log = getLogger(getClass()); |
| 79 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 80 | private State[] states = {new Idle(), new Started(), new Pending(), new Authorized(), new Unauthorized() }; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 81 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 82 | // Cleanup Timer instance created for this session |
| 83 | private java.util.concurrent.ScheduledFuture<?> cleanupTimer = null; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 84 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 85 | // TimeStamp of last EAPOL or RADIUS message received. |
| 86 | private long lastPacketReceivedTime = 0; |
| 87 | |
| 88 | // State transition table |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 89 | /* |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 90 | * |
| 91 | * state IDLE | STARTED | PENDING | AUTHORIZED | UNAUTHORIZED //// input |
| 92 | * ----------------------------------------------------------------------------- |
| 93 | * ----------------------- |
| 94 | * |
| 95 | * START STARTED | _ | _ | STARTED | STARTED |
| 96 | * |
| 97 | * REQUEST_ACCESS _ | PENDING | _ | _ | _ |
| 98 | * |
| 99 | * AUTHORIZE_ACCESS _ | _ | AUTHORIZED | _ | _ |
| 100 | * |
| 101 | * DENY_ACCESS _ | - | UNAUTHORIZED | _ | _ |
| 102 | * |
| 103 | * LOGOFF _ | _ | _ | IDLE | IDLE |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 104 | */ |
| 105 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 106 | private int[] idleTransition = {STATE_STARTED, STATE_IDLE, STATE_IDLE, STATE_IDLE, STATE_IDLE }; |
| 107 | private int[] startedTransition = {STATE_STARTED, STATE_PENDING, STATE_STARTED, STATE_STARTED, STATE_STARTED }; |
| 108 | private int[] pendingTransition = {STATE_PENDING, STATE_PENDING, STATE_AUTHORIZED, STATE_UNAUTHORIZED, |
| 109 | STATE_PENDING }; |
| 110 | private int[] authorizedTransition = {STATE_STARTED, STATE_AUTHORIZED, STATE_AUTHORIZED, STATE_AUTHORIZED, |
| 111 | STATE_IDLE }; |
| 112 | private int[] unauthorizedTransition = {STATE_STARTED, STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, |
| 113 | STATE_IDLE }; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 114 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 115 | // THE TRANSITION TABLE |
| 116 | private int[][] transition = {idleTransition, startedTransition, pendingTransition, authorizedTransition, |
| 117 | unauthorizedTransition }; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 118 | |
| 119 | private int currentState = STATE_IDLE; |
| 120 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 121 | // Maps of state machines. Each state machine is represented by an |
| 122 | // unique identifier on the switch: dpid + port number |
| 123 | private static Map<String, StateMachine> sessionIdMap; |
| 124 | private static Map<Integer, StateMachine> identifierMap; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 125 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 126 | private static StateMachineDelegate delegate; |
| 127 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 128 | public static void initializeMaps() { |
| 129 | sessionIdMap = Maps.newConcurrentMap(); |
| 130 | identifierMap = Maps.newConcurrentMap(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame^] | 131 | identifier = 1; |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | public static void destroyMaps() { |
| 135 | sessionIdMap = null; |
| 136 | identifierMap = null; |
| 137 | } |
| 138 | |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 139 | public static void setDelegate(StateMachineDelegate delegate) { |
| 140 | StateMachine.delegate = delegate; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 143 | public static void setcleanupTimerTimeOutInMins(int cleanupTimerTimeoutInMins) { |
| 144 | cleanupTimerTimeOutInMins = cleanupTimerTimeoutInMins; |
| 145 | } |
| 146 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 147 | public static void unsetDelegate(StateMachineDelegate delegate) { |
| 148 | if (StateMachine.delegate == delegate) { |
| 149 | StateMachine.delegate = null; |
| 150 | } |
| 151 | } |
| 152 | |
Qianqian Hu | 61a6a40 | 2016-02-16 15:18:05 +0800 | [diff] [blame] | 153 | public static Map<String, StateMachine> sessionIdMap() { |
| 154 | return sessionIdMap; |
| 155 | } |
| 156 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 157 | public static StateMachine lookupStateMachineById(byte identifier) { |
| 158 | return identifierMap.get((int) identifier); |
| 159 | } |
| 160 | |
| 161 | public static StateMachine lookupStateMachineBySessionId(String sessionId) { |
| 162 | return sessionIdMap.get(sessionId); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 165 | public static void deleteStateMachineId(String sessionId) { |
| 166 | sessionIdMap.remove(sessionId); |
| 167 | } |
| 168 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 169 | public static void deleteStateMachineMapping(StateMachine machine) { |
| 170 | identifierMap.entrySet().removeIf(e -> e.getValue().equals(machine)); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 171 | if (machine.cleanupTimer != null) { |
| 172 | machine.cleanupTimer.cancel(false); |
| 173 | machine.cleanupTimer = null; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | public java.util.concurrent.ScheduledFuture<?> getCleanupTimer() { |
| 178 | return cleanupTimer; |
| 179 | } |
| 180 | |
| 181 | public boolean isWaitingForRadiusResponse() { |
| 182 | return waitingForRadiusResponse; |
| 183 | } |
| 184 | |
| 185 | public void setWaitingForRadiusResponse(boolean waitingForRadiusResponse) { |
| 186 | this.waitingForRadiusResponse = waitingForRadiusResponse; |
| 187 | } |
| 188 | |
| 189 | public void setCleanupTimer(java.util.concurrent.ScheduledFuture<?> cleanupTimer) { |
| 190 | this.cleanupTimer = cleanupTimer; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
David K. Bainbridge | 6201949 | 2017-07-28 17:02:10 -0700 | [diff] [blame] | 194 | * Deletes authentication state machine records for a given MAC address. |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 195 | * |
David K. Bainbridge | 6201949 | 2017-07-28 17:02:10 -0700 | [diff] [blame] | 196 | * @param mac mac address of the suppliant who's state machine should be removed |
| 197 | */ |
| 198 | public static void deleteByMac(MacAddress mac) { |
| 199 | |
| 200 | // Walk the map from session IDs to state machines looking for a MAC match |
| 201 | for (Map.Entry<String, StateMachine> e : sessionIdMap.entrySet()) { |
| 202 | |
| 203 | // If a MAC match is found then delete the entry from the session ID |
| 204 | // and identifier map as well as call delete identifier to clean up |
| 205 | // the identifier bit set. |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 206 | if (e.getValue() != null && e.getValue().supplicantAddress != null |
| 207 | && e.getValue().supplicantAddress.equals(mac)) { |
David K. Bainbridge | 6201949 | 2017-07-28 17:02:10 -0700 | [diff] [blame] | 208 | sessionIdMap.remove(e.getValue().sessionId); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame^] | 209 | if (e.getValue().identifier != 1) { |
David K. Bainbridge | 6201949 | 2017-07-28 17:02:10 -0700 | [diff] [blame] | 210 | deleteStateMachineMapping(e.getValue()); |
| 211 | } |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /** |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 218 | * Creates a new StateMachine with the given session ID. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 219 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 220 | * @param sessionId session Id represented by the switch dpid + port number |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 221 | */ |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 222 | public StateMachine(String sessionId) { |
| 223 | log.info("Creating a new state machine for {}", sessionId); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 224 | this.sessionId = sessionId; |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 225 | sessionIdMap.put(sessionId, this); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 229 | * Gets the connect point for the supplicant side. |
| 230 | * |
| 231 | * @return supplicant connect point |
| 232 | */ |
| 233 | public ConnectPoint supplicantConnectpoint() { |
| 234 | return supplicantConnectpoint; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Sets the supplicant side connect point. |
| 239 | * |
| 240 | * @param supplicantConnectpoint supplicant select point. |
| 241 | */ |
| 242 | public void setSupplicantConnectpoint(ConnectPoint supplicantConnectpoint) { |
| 243 | this.supplicantConnectpoint = supplicantConnectpoint; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Gets the MAC address of the supplicant. |
| 248 | * |
| 249 | * @return supplicant MAC address |
| 250 | */ |
| 251 | public MacAddress supplicantAddress() { |
| 252 | return supplicantAddress; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Sets the supplicant MAC address. |
| 257 | * |
| 258 | * @param supplicantAddress new supplicant MAC address |
| 259 | */ |
| 260 | public void setSupplicantAddress(MacAddress supplicantAddress) { |
| 261 | this.supplicantAddress = supplicantAddress; |
| 262 | } |
| 263 | |
| 264 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 265 | * Sets the lastPacketReceivedTime. |
| 266 | * |
| 267 | * @param lastPacketReceivedTime timelastPacket was received |
| 268 | */ |
| 269 | public void setLastPacketReceivedTime(long lastPacketReceivedTime) { |
| 270 | this.lastPacketReceivedTime = lastPacketReceivedTime; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Gets the lastPacketReceivedTime. |
| 275 | * |
| 276 | * @return lastPacketReceivedTime |
| 277 | */ |
| 278 | public long getLastPacketReceivedTime() { |
| 279 | return lastPacketReceivedTime; |
| 280 | } |
| 281 | |
| 282 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 283 | * Gets the client's Vlan ID. |
| 284 | * |
| 285 | * @return client vlan ID |
| 286 | */ |
| 287 | public short vlanId() { |
| 288 | return vlanId; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Sets the client's vlan ID. |
| 293 | * |
| 294 | * @param vlanId new client vlan ID |
| 295 | */ |
| 296 | public void setVlanId(short vlanId) { |
| 297 | this.vlanId = vlanId; |
| 298 | } |
| 299 | |
| 300 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 301 | * Gets the client's priority Code. |
| 302 | * |
| 303 | * @return client Priority code |
| 304 | */ |
| 305 | public byte priorityCode() { |
| 306 | return priorityCode; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Sets the client's priority Code. |
| 311 | * |
| 312 | * @param priorityCode new client priority Code |
| 313 | */ |
| 314 | public void setPriorityCode(byte priorityCode) { |
| 315 | this.priorityCode = priorityCode; |
| 316 | } |
| 317 | |
| 318 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 319 | * Gets the client id that is requesting for access. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 320 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 321 | * @return The client id. |
| 322 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 323 | public String sessionId() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 324 | return this.sessionId; |
| 325 | } |
| 326 | |
| 327 | /** |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 328 | * Set the challenge identifier and the state issued by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 329 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 330 | * @param challengeIdentifier The challenge identifier set into the EAP packet |
| 331 | * from the RADIUS message. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 332 | * @param challengeState The challenge state from the RADIUS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 333 | */ |
| 334 | protected void setChallengeInfo(byte challengeIdentifier, byte[] challengeState) { |
| 335 | this.challengeIdentifier = challengeIdentifier; |
| 336 | this.challengeState = challengeState; |
| 337 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 338 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 339 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 340 | * Set the challenge identifier issued by the RADIUS on the access challenge |
| 341 | * request. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 342 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 343 | * @param challengeIdentifier The challenge identifier set into the EAP packet |
| 344 | * from the RADIUS message. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 345 | */ |
| 346 | protected void setChallengeIdentifier(byte challengeIdentifier) { |
| 347 | log.info("Set Challenge Identifier to {}", challengeIdentifier); |
| 348 | this.challengeIdentifier = challengeIdentifier; |
| 349 | } |
| 350 | |
| 351 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 352 | * Gets the challenge EAP identifier set by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 353 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 354 | * @return The challenge EAP identifier. |
| 355 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 356 | protected byte challengeIdentifier() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 357 | return this.challengeIdentifier; |
| 358 | } |
| 359 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 360 | /** |
| 361 | * Set the challenge state info issued by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 362 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 363 | * @param challengeState The challenge state from the RADIUS. |
| 364 | */ |
| 365 | protected void setChallengeState(byte[] challengeState) { |
| 366 | log.info("Set Challenge State"); |
| 367 | this.challengeState = challengeState; |
| 368 | } |
| 369 | |
| 370 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 371 | * Gets the challenge state set by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 372 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 373 | * @return The challenge state. |
| 374 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 375 | protected byte[] challengeState() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 376 | return this.challengeState; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Set the username. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 381 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 382 | * @param username The username sent to the RADIUS upon access request. |
| 383 | */ |
| 384 | protected void setUsername(byte[] username) { |
| 385 | this.username = username; |
| 386 | } |
| 387 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 388 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 389 | * Gets the username. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 390 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 391 | * @return The requestAuthenticator. |
| 392 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 393 | protected byte[] requestAuthenticator() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 394 | return this.requestAuthenticator; |
| 395 | } |
| 396 | |
| 397 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 398 | * Sets the authenticator. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 399 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 400 | * @param authenticator The username sent to the RADIUS upon access request. |
| 401 | */ |
| 402 | protected void setRequestAuthenticator(byte[] authenticator) { |
| 403 | this.requestAuthenticator = authenticator; |
| 404 | } |
| 405 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 406 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 407 | * Gets the username. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 408 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 409 | * @return The username. |
| 410 | */ |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 411 | public byte[] username() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 412 | return this.username; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Return the identifier of the state machine. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 417 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 418 | * @return The state machine identifier. |
| 419 | */ |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 420 | public synchronized byte identifier() { |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame^] | 421 | //identifier 0 is for statusServerrequest |
| 422 | //identifier 1 is for fake accessRequest |
| 423 | identifier = (identifier + 1) % 253; |
| 424 | identifierMap.put((identifier + 2), this); |
| 425 | return (byte) (identifier + 2); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 428 | /** |
| 429 | * Move to the next state. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 430 | * |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 431 | * @param msg message |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 432 | */ |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 433 | private void next(int msg) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 434 | currentState = transition[currentState][msg]; |
| 435 | log.info("Current State " + currentState); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Client has requested the start action to allow network access. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 440 | * |
| 441 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 442 | */ |
| 443 | public void start() throws StateMachineException { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 444 | states[currentState].start(); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 445 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 446 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.STARTED, supplicantConnectpoint)); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 447 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 448 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 449 | next(TRANSITION_START); |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 450 | identifier = this.identifier(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 454 | * An Identification information has been sent by the supplicant. Move to the |
| 455 | * next state if possible. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 456 | * |
| 457 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 458 | */ |
| 459 | public void requestAccess() throws StateMachineException { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 460 | states[currentState].requestAccess(); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 461 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 462 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.REQUESTED, supplicantConnectpoint)); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 463 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 464 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 465 | next(TRANSITION_REQUEST_ACCESS); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 469 | * RADIUS has accepted the identification. Move to the next state if possible. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 470 | * |
| 471 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 472 | */ |
| 473 | public void authorizeAccess() throws StateMachineException { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 474 | states[currentState].radiusAccepted(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 475 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 476 | next(TRANSITION_AUTHORIZE_ACCESS); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 477 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 478 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.APPROVED, supplicantConnectpoint)); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 479 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 480 | // Clear mapping |
| 481 | deleteStateMachineMapping(this); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 485 | * RADIUS has denied the identification. Move to the next state if possible. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 486 | * |
| 487 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 488 | */ |
| 489 | public void denyAccess() throws StateMachineException { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 490 | states[currentState].radiusDenied(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 491 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 492 | next(TRANSITION_DENY_ACCESS); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 493 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 494 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.DENIED, supplicantConnectpoint)); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 495 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 496 | // Clear mappings |
| 497 | deleteStateMachineMapping(this); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 501 | * Logoff request has been requested. Move to the next state if possible. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 502 | * |
| 503 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 504 | */ |
| 505 | public void logoff() throws StateMachineException { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 506 | states[currentState].logoff(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 507 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 508 | next(TRANSITION_LOGOFF); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 512 | * Gets the current state. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 513 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 514 | * @return The current state. Could be STATE_IDLE, STATE_STARTED, STATE_PENDING, |
| 515 | * STATE_AUTHORIZED, STATE_UNAUTHORIZED. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 516 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 517 | public int state() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 518 | return currentState; |
| 519 | } |
| 520 | |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 521 | @Override |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 522 | public String toString() { |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 523 | return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" |
| 524 | + ("state: " + this.currentState); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 525 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 526 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 527 | abstract class State { |
| 528 | private final Logger log = getLogger(getClass()); |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 529 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 530 | private String name = "State"; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 531 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 532 | public void start() throws StateMachineInvalidTransitionException { |
| 533 | log.warn("START transition from this state is not allowed."); |
| 534 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 535 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 536 | public void requestAccess() throws StateMachineInvalidTransitionException { |
| 537 | log.warn("REQUEST ACCESS transition from this state is not allowed."); |
| 538 | } |
| 539 | |
| 540 | public void radiusAccepted() throws StateMachineInvalidTransitionException { |
| 541 | log.warn("AUTHORIZE ACCESS transition from this state is not allowed."); |
| 542 | } |
| 543 | |
| 544 | public void radiusDenied() throws StateMachineInvalidTransitionException { |
| 545 | log.warn("DENY ACCESS transition from this state is not allowed."); |
| 546 | } |
| 547 | |
| 548 | public void logoff() throws StateMachineInvalidTransitionException { |
| 549 | log.warn("LOGOFF transition from this state is not allowed."); |
| 550 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 551 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 552 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 553 | /** |
| 554 | * Idle state: supplicant is logged of from the network. |
| 555 | */ |
| 556 | class Idle extends State { |
| 557 | private final Logger log = getLogger(getClass()); |
| 558 | private String name = "IDLE_STATE"; |
| 559 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 560 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 561 | public void start() { |
| 562 | log.info("Moving from IDLE state to STARTED state."); |
| 563 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 564 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 565 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 566 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 567 | * Started state: supplicant has entered the network and informed the |
| 568 | * authenticator. |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 569 | */ |
| 570 | class Started extends State { |
| 571 | private final Logger log = getLogger(getClass()); |
| 572 | private String name = "STARTED_STATE"; |
| 573 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 574 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 575 | public void requestAccess() { |
| 576 | log.info("Moving from STARTED state to PENDING state."); |
| 577 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 578 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 579 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 580 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 581 | * Pending state: supplicant has been identified by the authenticator but has |
| 582 | * not access yet. |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 583 | */ |
| 584 | class Pending extends State { |
| 585 | private final Logger log = getLogger(getClass()); |
| 586 | private String name = "PENDING_STATE"; |
| 587 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 588 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 589 | public void radiusAccepted() { |
| 590 | log.info("Moving from PENDING state to AUTHORIZED state."); |
| 591 | } |
| 592 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 593 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 594 | public void radiusDenied() { |
| 595 | log.info("Moving from PENDING state to UNAUTHORIZED state."); |
| 596 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 597 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 598 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 599 | /** |
| 600 | * Authorized state: supplicant port has been accepted, access is granted. |
| 601 | */ |
| 602 | class Authorized extends State { |
| 603 | private final Logger log = getLogger(getClass()); |
| 604 | private String name = "AUTHORIZED_STATE"; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 605 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 606 | @Override |
Qianqian Hu | 0c34981 | 2016-02-15 17:25:22 +0800 | [diff] [blame] | 607 | public void start() { |
| 608 | log.info("Moving from AUTHORIZED state to STARTED state."); |
| 609 | } |
| 610 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 611 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 612 | public void logoff() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 613 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 614 | log.info("Moving from AUTHORIZED state to IDLE state."); |
| 615 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 618 | /** |
| 619 | * Unauthorized state: supplicant port has been rejected, access is denied. |
| 620 | */ |
| 621 | class Unauthorized extends State { |
| 622 | private final Logger log = getLogger(getClass()); |
| 623 | private String name = "UNAUTHORIZED_STATE"; |
| 624 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 625 | @Override |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 626 | public void start() { |
| 627 | log.info("Moving from UNAUTHORIZED state to STARTED state."); |
| 628 | } |
| 629 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 630 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 631 | public void logoff() { |
| 632 | log.info("Moving from UNAUTHORIZED state to IDLE state."); |
| 633 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 634 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 635 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 636 | /** |
| 637 | * Class for cleaning the StateMachine for those session for which no response |
| 638 | * is coming--implementing timeout. |
| 639 | */ |
| 640 | class CleanupTimerTask implements Runnable { |
| 641 | private final Logger log = getLogger(getClass()); |
| 642 | private String sessionId; |
| 643 | private AaaManager aaaManager; |
| 644 | |
| 645 | CleanupTimerTask(String sessionId, AaaManager aaaManager) { |
| 646 | this.sessionId = sessionId; |
| 647 | this.aaaManager = aaaManager; |
| 648 | } |
| 649 | |
| 650 | @Override |
| 651 | public void run() { |
| 652 | StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId); |
| 653 | if (null != stateMachine) { |
| 654 | // Asserting if last packet received for this stateMachine session was beyond half of timeout period. |
| 655 | // StateMachine is considered eligible for cleanup when no packets has been exchanged by it with AAA |
| 656 | // Server or RG during a long period (half of timeout period). For example, when cleanup timer has |
| 657 | // been configured as 10 minutes, StateMachine would be cleaned up at the end of 10 minutes if |
| 658 | // the authentication is still pending and no packet was exchanged for this session during last 5 |
| 659 | // minutes. |
| 660 | |
| 661 | boolean noTrafficWithinThreshold = (System.currentTimeMillis() |
| 662 | - stateMachine.getLastPacketReceivedTime()) > ((cleanupTimerTimeOutInMins * 60 * 1000) / 2); |
| 663 | |
| 664 | if ((TIMEOUT_ELIGIBLE_STATES.contains(stateMachine.state())) && noTrafficWithinThreshold) { |
| 665 | log.info("Deleting StateMachineMapping for sessionId: {}", sessionId); |
| 666 | cleanupTimer = null; |
| 667 | if (stateMachine.state() == STATE_PENDING && stateMachine.isWaitingForRadiusResponse()) { |
| 668 | aaaManager.aaaStatisticsManager.getAaaStats().increaseTimedOutPackets(); |
| 669 | } |
| 670 | deleteStateMachineId(sessionId); |
| 671 | deleteStateMachineMapping(stateMachine); |
| 672 | |
| 673 | // If StateMachine is not eligible for cleanup yet, reschedule cleanupTimer further. |
| 674 | } else { |
| 675 | aaaManager.scheduleStateMachineCleanupTimer(sessionId, stateMachine); |
| 676 | } |
| 677 | } else { |
| 678 | // This statement should not be logged; cleanupTimer should be cancelled for stateMachine |
| 679 | // instances which have been authenticated successfully. |
| 680 | log.warn("state-machine not found for sessionId: {}", sessionId); |
| 681 | } |
| 682 | |
| 683 | } |
| 684 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 685 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 686 | } |