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