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 | |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onosproject.net.ConnectPoint; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 22 | import org.opencord.aaa.AuthenticationEvent; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 23 | import org.opencord.aaa.AuthenticationRecord; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 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; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 28 | import java.util.Set; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 29 | import java.util.concurrent.ScheduledExecutorService; |
| 30 | import java.util.concurrent.TimeUnit; |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 31 | |
| 32 | import static org.slf4j.LoggerFactory.getLogger; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * AAA Finite State Machine. |
| 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 |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 46 | static final Set<Integer> TIMEOUT_ELIGIBLE_STATES = new HashSet<>(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 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 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [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; |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 69 | private long sessionStartTime; |
| 70 | private String eapolTypeVal; |
| 71 | |
| 72 | public enum EapolType { |
| 73 | EAPOL_PACKET("EAPOL_PACKET"), |
| 74 | EAPOL_START("EAPOL_START"), |
| 75 | EAPOL_LOGOFF("EAPOL_LOGOFF"), |
| 76 | EAPOL_KEY("EAPOL_KEY"), |
| 77 | EAPOL_ASF("EAPOL_ASF"); |
| 78 | |
| 79 | private final String eaptype; |
| 80 | |
| 81 | private EapolType(String value) { |
| 82 | this.eaptype = value; |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | private String sessionTerminateReason; |
| 87 | |
| 88 | public enum SessionTerminationReasons { |
| 89 | SUPPLICANT_LOGOFF("SUPPLICANT_LOGOFF"), |
| 90 | TIME_OUT("TIME_OUT"), |
Girish Kumar | 064084c | 2020-02-04 08:32:46 +0000 | [diff] [blame] | 91 | PORT_REMOVED("PORT_REMOVED"), |
| 92 | DEVICE_REMOVED("DEVICE_REMOVED"); |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 93 | |
| 94 | private final String reason; |
| 95 | |
| 96 | private SessionTerminationReasons(String value) { |
| 97 | this.reason = value; |
| 98 | } |
| 99 | |
| 100 | public String getReason() { |
| 101 | return this.reason; |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | // Supplicant packet count |
| 106 | private int totalPacketsSent; |
| 107 | private int totalPacketsReceived; |
| 108 | private int totalOctetSent; |
| 109 | private int totalOctetReceived; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 110 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 111 | // Boolean flag indicating whether response is pending from AAA Server. |
| 112 | // Used for counting timeout happening for AAA Sessions due to no response. |
| 113 | private boolean waitingForRadiusResponse; |
| 114 | |
| 115 | private static int cleanupTimerTimeOutInMins; |
| 116 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 117 | private String sessionId = null; |
| 118 | |
| 119 | private final Logger log = getLogger(getClass()); |
| 120 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 121 | 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] | 122 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 123 | // Cleanup Timer instance created for this session |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 124 | private ScheduledExecutorService timeoutExecutor; |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 125 | private java.util.concurrent.ScheduledFuture<?> cleanupTimer = null; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 126 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 127 | // TimeStamp of last EAPOL or RADIUS message received. |
| 128 | private long lastPacketReceivedTime = 0; |
| 129 | |
| 130 | // State transition table |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 131 | /* |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 132 | * |
| 133 | * state IDLE | STARTED | PENDING | AUTHORIZED | UNAUTHORIZED //// input |
| 134 | * ----------------------------------------------------------------------------- |
| 135 | * ----------------------- |
| 136 | * |
| 137 | * START STARTED | _ | _ | STARTED | STARTED |
| 138 | * |
| 139 | * REQUEST_ACCESS _ | PENDING | _ | _ | _ |
| 140 | * |
| 141 | * AUTHORIZE_ACCESS _ | _ | AUTHORIZED | _ | _ |
| 142 | * |
| 143 | * DENY_ACCESS _ | - | UNAUTHORIZED | _ | _ |
| 144 | * |
| 145 | * LOGOFF _ | _ | _ | IDLE | IDLE |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 146 | */ |
| 147 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 148 | private int[] idleTransition = {STATE_STARTED, STATE_IDLE, STATE_IDLE, STATE_IDLE, STATE_IDLE }; |
| 149 | private int[] startedTransition = {STATE_STARTED, STATE_PENDING, STATE_STARTED, STATE_STARTED, STATE_STARTED }; |
| 150 | private int[] pendingTransition = {STATE_PENDING, STATE_PENDING, STATE_AUTHORIZED, STATE_UNAUTHORIZED, |
| 151 | STATE_PENDING }; |
| 152 | private int[] authorizedTransition = {STATE_STARTED, STATE_AUTHORIZED, STATE_AUTHORIZED, STATE_AUTHORIZED, |
| 153 | STATE_IDLE }; |
| 154 | private int[] unauthorizedTransition = {STATE_STARTED, STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, |
| 155 | STATE_IDLE }; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 156 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 157 | // THE TRANSITION TABLE |
| 158 | private int[][] transition = {idleTransition, startedTransition, pendingTransition, authorizedTransition, |
| 159 | unauthorizedTransition }; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 160 | |
| 161 | private int currentState = STATE_IDLE; |
| 162 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 163 | private static StateMachineDelegate delegate; |
| 164 | |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 165 | public static void setDelegate(StateMachineDelegate delegate) { |
| 166 | StateMachine.delegate = delegate; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 169 | public static void setcleanupTimerTimeOutInMins(int cleanupTimerTimeoutInMins) { |
| 170 | cleanupTimerTimeOutInMins = cleanupTimerTimeoutInMins; |
| 171 | } |
| 172 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 173 | private void scheduleTimeout() { |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 174 | cleanupTimer = timeoutExecutor.schedule(this::timeout, cleanupTimerTimeOutInMins, TimeUnit.MINUTES); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 177 | public static void unsetDelegate(StateMachineDelegate delegate) { |
| 178 | if (StateMachine.delegate == delegate) { |
| 179 | StateMachine.delegate = null; |
| 180 | } |
| 181 | } |
| 182 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 183 | public static void deleteStateMachineMapping(StateMachine machine) { |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 184 | if (machine.cleanupTimer != null) { |
| 185 | machine.cleanupTimer.cancel(false); |
| 186 | machine.cleanupTimer = null; |
| 187 | } |
| 188 | } |
| 189 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 190 | public void stop() { |
| 191 | if (cleanupTimer != null) { |
| 192 | cleanupTimer.cancel(false); |
| 193 | } |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | public boolean isWaitingForRadiusResponse() { |
| 197 | return waitingForRadiusResponse; |
| 198 | } |
| 199 | |
| 200 | public void setWaitingForRadiusResponse(boolean waitingForRadiusResponse) { |
| 201 | this.waitingForRadiusResponse = waitingForRadiusResponse; |
| 202 | } |
| 203 | |
David K. Bainbridge | 6201949 | 2017-07-28 17:02:10 -0700 | [diff] [blame] | 204 | /** |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 205 | * Creates a new StateMachine with the given session ID. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 206 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 207 | * @param sessionId session Id represented by the switch dpid + port number |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 208 | * @param executor executor to run background tasks on |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 209 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 210 | public StateMachine(String sessionId, ScheduledExecutorService executor) { |
Jonathan Hart | 932bedc | 2018-07-12 13:46:09 -0700 | [diff] [blame] | 211 | log.info("Creating a new state machine for {}", sessionId); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 212 | this.sessionId = sessionId; |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 213 | this.timeoutExecutor = executor; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 217 | * Gets the connect point for the supplicant side. |
| 218 | * |
| 219 | * @return supplicant connect point |
| 220 | */ |
| 221 | public ConnectPoint supplicantConnectpoint() { |
| 222 | return supplicantConnectpoint; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Sets the supplicant side connect point. |
| 227 | * |
| 228 | * @param supplicantConnectpoint supplicant select point. |
| 229 | */ |
| 230 | public void setSupplicantConnectpoint(ConnectPoint supplicantConnectpoint) { |
| 231 | this.supplicantConnectpoint = supplicantConnectpoint; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Gets the MAC address of the supplicant. |
| 236 | * |
| 237 | * @return supplicant MAC address |
| 238 | */ |
| 239 | public MacAddress supplicantAddress() { |
| 240 | return supplicantAddress; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Sets the supplicant MAC address. |
| 245 | * |
| 246 | * @param supplicantAddress new supplicant MAC address |
| 247 | */ |
| 248 | public void setSupplicantAddress(MacAddress supplicantAddress) { |
| 249 | this.supplicantAddress = supplicantAddress; |
| 250 | } |
| 251 | |
| 252 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 253 | * Sets the lastPacketReceivedTime. |
| 254 | * |
| 255 | * @param lastPacketReceivedTime timelastPacket was received |
| 256 | */ |
| 257 | public void setLastPacketReceivedTime(long lastPacketReceivedTime) { |
| 258 | this.lastPacketReceivedTime = lastPacketReceivedTime; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Gets the lastPacketReceivedTime. |
| 263 | * |
| 264 | * @return lastPacketReceivedTime |
| 265 | */ |
| 266 | public long getLastPacketReceivedTime() { |
| 267 | return lastPacketReceivedTime; |
| 268 | } |
| 269 | |
| 270 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 271 | * Gets the client's Vlan ID. |
| 272 | * |
| 273 | * @return client vlan ID |
| 274 | */ |
| 275 | public short vlanId() { |
| 276 | return vlanId; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Sets the client's vlan ID. |
| 281 | * |
| 282 | * @param vlanId new client vlan ID |
| 283 | */ |
| 284 | public void setVlanId(short vlanId) { |
| 285 | this.vlanId = vlanId; |
| 286 | } |
| 287 | |
| 288 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 289 | * Gets the client's priority Code. |
| 290 | * |
| 291 | * @return client Priority code |
| 292 | */ |
| 293 | public byte priorityCode() { |
| 294 | return priorityCode; |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Sets the client's priority Code. |
| 299 | * |
| 300 | * @param priorityCode new client priority Code |
| 301 | */ |
| 302 | public void setPriorityCode(byte priorityCode) { |
| 303 | this.priorityCode = priorityCode; |
| 304 | } |
| 305 | |
| 306 | /** |
Kartikey Dubey | adeb26e | 2019-10-01 12:18:35 +0000 | [diff] [blame] | 307 | * Gets the session start time. |
| 308 | * |
| 309 | * @return session start time |
| 310 | */ |
| 311 | public long sessionStartTime() { |
| 312 | return sessionStartTime; |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Sets the session start time. |
| 317 | * |
| 318 | * @param sessionStartTime new session start time |
| 319 | */ |
| 320 | public void setSessionStartTime(long sessionStartTime) { |
| 321 | this.sessionStartTime = sessionStartTime; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * returns eapol Type. |
| 326 | * |
| 327 | * @return eapolTypeVal. |
| 328 | */ |
| 329 | public String eapolType() { |
| 330 | return this.eapolTypeVal; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Sets eapol Type name from eapol value. |
| 335 | * |
| 336 | * @param value eapol type as byte. |
| 337 | */ |
| 338 | public void setEapolTypeVal(byte value) { |
| 339 | switch (value) { |
| 340 | case (byte) 0: this.eapolTypeVal = EapolType.EAPOL_PACKET.eaptype; |
| 341 | break; |
| 342 | case (byte) 1: this.eapolTypeVal = EapolType.EAPOL_START.eaptype; |
| 343 | break; |
| 344 | case (byte) 2: this.eapolTypeVal = EapolType.EAPOL_LOGOFF.eaptype; |
| 345 | break; |
| 346 | case (byte) 3: this.eapolTypeVal = EapolType.EAPOL_KEY.eaptype; |
| 347 | break; |
| 348 | case (byte) 4: this.eapolTypeVal = EapolType.EAPOL_ASF.eaptype; |
| 349 | break; |
| 350 | default : this.eapolTypeVal = "INVALID TYPE"; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | public String getSessionTerminateReason() { |
| 355 | return sessionTerminateReason; |
| 356 | } |
| 357 | |
| 358 | public void setSessionTerminateReason(String sessionTerminateReason) { |
| 359 | this.sessionTerminateReason = sessionTerminateReason; |
| 360 | } |
| 361 | |
| 362 | public int totalPacketsReceived() { |
| 363 | return this.totalPacketsReceived; |
| 364 | } |
| 365 | |
| 366 | public void incrementTotalPacketsReceived() { |
| 367 | this.totalPacketsReceived = this.totalPacketsReceived + 1; |
| 368 | } |
| 369 | |
| 370 | public int totalPacketsSent() { |
| 371 | return this.totalPacketsSent; |
| 372 | } |
| 373 | |
| 374 | public void incrementTotalPacketsSent() { |
| 375 | this.totalPacketsSent = this.totalPacketsSent + 1; |
| 376 | } |
| 377 | |
| 378 | public void incrementTotalOctetReceived(short packetLen) { |
| 379 | this.totalOctetReceived = this.totalOctetReceived + packetLen; |
| 380 | } |
| 381 | |
| 382 | public void incrementTotalOctetSent(short packetLen) { |
| 383 | this.totalOctetSent = this.totalOctetSent + packetLen; |
| 384 | } |
| 385 | |
| 386 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 387 | * Gets the client id that is requesting for access. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 388 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 389 | * @return The client id. |
| 390 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 391 | public String sessionId() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 392 | return this.sessionId; |
| 393 | } |
| 394 | |
| 395 | /** |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 396 | * Set the challenge identifier and the state issued by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 397 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 398 | * @param challengeIdentifier The challenge identifier set into the EAP packet |
| 399 | * from the RADIUS message. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 400 | * @param challengeState The challenge state from the RADIUS. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 401 | */ |
| 402 | protected void setChallengeInfo(byte challengeIdentifier, byte[] challengeState) { |
| 403 | this.challengeIdentifier = challengeIdentifier; |
| 404 | this.challengeState = challengeState; |
| 405 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 406 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 407 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 408 | * Set the challenge identifier issued by the RADIUS on the access challenge |
| 409 | * request. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 410 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 411 | * @param challengeIdentifier The challenge identifier set into the EAP packet |
| 412 | * from the RADIUS message. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 413 | */ |
| 414 | protected void setChallengeIdentifier(byte challengeIdentifier) { |
| 415 | log.info("Set Challenge Identifier to {}", challengeIdentifier); |
| 416 | this.challengeIdentifier = challengeIdentifier; |
| 417 | } |
| 418 | |
| 419 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 420 | * Gets the challenge EAP identifier set by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 421 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 422 | * @return The challenge EAP identifier. |
| 423 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 424 | protected byte challengeIdentifier() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 425 | return this.challengeIdentifier; |
| 426 | } |
| 427 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 428 | /** |
| 429 | * Set the challenge state info issued by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 430 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 431 | * @param challengeState The challenge state from the RADIUS. |
| 432 | */ |
| 433 | protected void setChallengeState(byte[] challengeState) { |
| 434 | log.info("Set Challenge State"); |
| 435 | this.challengeState = challengeState; |
| 436 | } |
| 437 | |
| 438 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 439 | * Gets the challenge state set by the RADIUS. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 440 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 441 | * @return The challenge state. |
| 442 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 443 | protected byte[] challengeState() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 444 | return this.challengeState; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Set the username. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 449 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 450 | * @param username The username sent to the RADIUS upon access request. |
| 451 | */ |
| 452 | protected void setUsername(byte[] username) { |
| 453 | this.username = username; |
| 454 | } |
| 455 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 456 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 457 | * Gets the username. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 458 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 459 | * @return The requestAuthenticator. |
| 460 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 461 | protected byte[] requestAuthenticator() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 462 | return this.requestAuthenticator; |
| 463 | } |
| 464 | |
| 465 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 466 | * Sets the authenticator. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 467 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 468 | * @param authenticator The username sent to the RADIUS upon access request. |
| 469 | */ |
| 470 | protected void setRequestAuthenticator(byte[] authenticator) { |
| 471 | this.requestAuthenticator = authenticator; |
| 472 | } |
| 473 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 474 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 475 | * Gets the username. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 476 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 477 | * @return The username. |
| 478 | */ |
Carmelo Cascone | 58b5329 | 2019-09-30 12:35:31 -0700 | [diff] [blame] | 479 | public byte[] username() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 480 | return this.username; |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Return the identifier of the state machine. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 485 | * |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 486 | * @return The state machine identifier. |
| 487 | */ |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 488 | public synchronized byte identifier() { |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 489 | identifier = (identifier + 1) % 255; |
| 490 | return (byte) identifier; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 493 | /** |
| 494 | * Move to the next state. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 495 | * |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 496 | * @param msg message |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 497 | */ |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 498 | private void next(int msg) { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 499 | currentState = transition[currentState][msg]; |
| 500 | log.info("Current State " + currentState); |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Client has requested the start action to allow network access. |
| 505 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 506 | public void start() { |
| 507 | this.scheduleTimeout(); |
| 508 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 509 | states[currentState].start(); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 510 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 511 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.STARTED, |
| 512 | supplicantConnectpoint, toAuthRecord())); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 513 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 514 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 515 | next(TRANSITION_START); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 519 | * An Identification information has been sent by the supplicant. Move to the |
| 520 | * next state if possible. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 521 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 522 | public void requestAccess() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 523 | states[currentState].requestAccess(); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 524 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 525 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.REQUESTED, |
| 526 | supplicantConnectpoint, toAuthRecord())); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 527 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 528 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 529 | next(TRANSITION_REQUEST_ACCESS); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 533 | * RADIUS has accepted the identification. Move to the next state if possible. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 534 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 535 | public void authorizeAccess() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 536 | states[currentState].radiusAccepted(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 537 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 538 | next(TRANSITION_AUTHORIZE_ACCESS); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 539 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 540 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.APPROVED, |
| 541 | supplicantConnectpoint, toAuthRecord())); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 542 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 543 | // Clear mapping |
| 544 | deleteStateMachineMapping(this); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 548 | * RADIUS has denied the identification. Move to the next state if possible. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 549 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 550 | public void denyAccess() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 551 | states[currentState].radiusDenied(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 552 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 553 | next(TRANSITION_DENY_ACCESS); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 554 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 555 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.DENIED, |
| 556 | supplicantConnectpoint, toAuthRecord())); |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 557 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 558 | // Clear mappings |
| 559 | deleteStateMachineMapping(this); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 563 | * Logoff request has been requested. Move to the next state if possible. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 564 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 565 | public void logoff() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 566 | states[currentState].logoff(); |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 567 | |
| 568 | // TODO event here? |
| 569 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 570 | // move to the next state |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 571 | next(TRANSITION_LOGOFF); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 574 | private AuthenticationRecord toAuthRecord() { |
| 575 | return new AuthenticationRecord(this.supplicantConnectpoint(), |
| 576 | this.username(), this.supplicantAddress(), this.stateString(), |
| 577 | this.getLastPacketReceivedTime()); |
| 578 | } |
| 579 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 580 | /** |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 581 | * Gets the current state. |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 582 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 583 | * @return The current state. Could be STATE_IDLE, STATE_STARTED, STATE_PENDING, |
| 584 | * STATE_AUTHORIZED, STATE_UNAUTHORIZED. |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 585 | */ |
Ray Milkey | f61a24e | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 586 | public int state() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 587 | return currentState; |
| 588 | } |
| 589 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 590 | public String stateString() { |
| 591 | return states[currentState].name(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 592 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 593 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 594 | @Override |
| 595 | public String toString() { |
| 596 | return ("sessionId: " + this.sessionId) + "\t" + ("state: " + this.currentState); |
| 597 | } |
| 598 | |
| 599 | abstract static class State { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 600 | private final Logger log = getLogger(getClass()); |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 601 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 602 | abstract String name(); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 603 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 604 | public void start() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 605 | log.warn("START transition from this state is not allowed."); |
| 606 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 607 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 608 | public void requestAccess() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 609 | log.warn("REQUEST ACCESS transition from this state is not allowed."); |
| 610 | } |
| 611 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 612 | public void radiusAccepted() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 613 | log.warn("AUTHORIZE ACCESS transition from this state is not allowed."); |
| 614 | } |
| 615 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 616 | public void radiusDenied() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 617 | log.warn("DENY ACCESS transition from this state is not allowed."); |
| 618 | } |
| 619 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 620 | public void logoff() { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 621 | log.warn("LOGOFF transition from this state is not allowed."); |
| 622 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 623 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 624 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 625 | /** |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 626 | * Idle state: supplicant is logged off from the network. |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 627 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 628 | static class Idle extends State { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 629 | private final Logger log = getLogger(getClass()); |
| 630 | private String name = "IDLE_STATE"; |
| 631 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 632 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 633 | String name() { |
| 634 | return this.name; |
| 635 | } |
| 636 | |
| 637 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 638 | public void start() { |
| 639 | log.info("Moving from IDLE state to STARTED state."); |
| 640 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 641 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 642 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 643 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 644 | * Started state: supplicant has entered the network and informed the |
| 645 | * authenticator. |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 646 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 647 | static class Started extends State { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 648 | private final Logger log = getLogger(getClass()); |
| 649 | private String name = "STARTED_STATE"; |
| 650 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 651 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 652 | String name() { |
| 653 | return this.name; |
| 654 | } |
| 655 | |
| 656 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 657 | public void requestAccess() { |
| 658 | log.info("Moving from STARTED state to PENDING state."); |
| 659 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 660 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 661 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 662 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 663 | * Pending state: supplicant has been identified by the authenticator but has |
| 664 | * not access yet. |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 665 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 666 | static class Pending extends State { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 667 | private final Logger log = getLogger(getClass()); |
| 668 | private String name = "PENDING_STATE"; |
| 669 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 670 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 671 | String name() { |
| 672 | return this.name; |
| 673 | } |
| 674 | |
| 675 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 676 | public void radiusAccepted() { |
| 677 | log.info("Moving from PENDING state to AUTHORIZED state."); |
| 678 | } |
| 679 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 680 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 681 | public void radiusDenied() { |
| 682 | log.info("Moving from PENDING state to UNAUTHORIZED state."); |
| 683 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 684 | } |
Thomas Vachuska | e989420 | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 685 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 686 | /** |
| 687 | * Authorized state: supplicant port has been accepted, access is granted. |
| 688 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 689 | static class Authorized extends State { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 690 | private final Logger log = getLogger(getClass()); |
| 691 | private String name = "AUTHORIZED_STATE"; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 692 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 693 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 694 | String name() { |
| 695 | return this.name; |
| 696 | } |
| 697 | |
| 698 | @Override |
Qianqian Hu | 0c34981 | 2016-02-15 17:25:22 +0800 | [diff] [blame] | 699 | public void start() { |
| 700 | log.info("Moving from AUTHORIZED state to STARTED state."); |
| 701 | } |
| 702 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 703 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 704 | public void logoff() { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 705 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 706 | log.info("Moving from AUTHORIZED state to IDLE state."); |
| 707 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 710 | /** |
| 711 | * Unauthorized state: supplicant port has been rejected, access is denied. |
| 712 | */ |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 713 | static class Unauthorized extends State { |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 714 | private final Logger log = getLogger(getClass()); |
| 715 | private String name = "UNAUTHORIZED_STATE"; |
| 716 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 717 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 718 | String name() { |
| 719 | return this.name; |
| 720 | } |
| 721 | |
| 722 | @Override |
ke han | 04e47f3 | 2016-10-28 14:15:43 +0800 | [diff] [blame] | 723 | public void start() { |
| 724 | log.info("Moving from UNAUTHORIZED state to STARTED state."); |
| 725 | } |
| 726 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 727 | @Override |
Ray Milkey | 78e95a4 | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 728 | public void logoff() { |
| 729 | log.info("Moving from UNAUTHORIZED state to IDLE state."); |
| 730 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 731 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 732 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 733 | private void timeout() { |
| 734 | boolean noTrafficWithinThreshold = |
| 735 | (System.currentTimeMillis() - lastPacketReceivedTime) > ((cleanupTimerTimeOutInMins * 60 * 1000) / 2); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 736 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 737 | if (TIMEOUT_ELIGIBLE_STATES.contains(currentState) && noTrafficWithinThreshold) { |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 738 | this.setSessionTerminateReason(SessionTerminationReasons.TIME_OUT.reason); |
| 739 | |
| 740 | delegate.notify(new AuthenticationEvent(AuthenticationEvent.Type.TIMEOUT, |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame^] | 741 | this.supplicantConnectpoint, toAuthRecord())); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 742 | // If StateMachine is not eligible for cleanup yet, reschedule cleanupTimer further. |
| 743 | } else { |
| 744 | this.scheduleTimeout(); |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 747 | |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 748 | } |