Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015 AT&T Foundry |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | package org.onosproject.aaa; |
| 20 | |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 21 | import java.util.BitSet; |
| 22 | import java.util.Map; |
| 23 | |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onosproject.net.ConnectPoint; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 26 | import org.slf4j.Logger; |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 27 | |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 28 | import com.google.common.collect.Maps; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 29 | |
| 30 | import static org.slf4j.LoggerFactory.getLogger; |
| 31 | |
| 32 | /** |
| 33 | * AAA Finite State Machine. |
| 34 | */ |
| 35 | |
| 36 | class StateMachine { |
| 37 | //INDEX to identify the state in the transition table |
| 38 | static final int STATE_IDLE = 0; |
| 39 | static final int STATE_STARTED = 1; |
| 40 | static final int STATE_PENDING = 2; |
| 41 | static final int STATE_AUTHORIZED = 3; |
| 42 | static final int STATE_UNAUTHORIZED = 4; |
| 43 | |
| 44 | //INDEX to identify the transition in the transition table |
| 45 | static final int TRANSITION_START = 0; // --> started |
| 46 | static final int TRANSITION_REQUEST_ACCESS = 1; |
| 47 | static final int TRANSITION_AUTHORIZE_ACCESS = 2; |
| 48 | static final int TRANSITION_DENY_ACCESS = 3; |
| 49 | static final int TRANSITION_LOGOFF = 4; |
| 50 | |
| 51 | //map of access identifiers (issued at EAPOL START) |
| 52 | static BitSet bitSet = new BitSet(); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 53 | |
| 54 | private int identifier = -1; |
| 55 | private byte challengeIdentifier; |
| 56 | private byte[] challengeState; |
| 57 | private byte[] username; |
| 58 | private byte[] requestAuthenticator; |
| 59 | |
| 60 | // Supplicant connectivity info |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 61 | private ConnectPoint supplicantConnectpoint; |
| 62 | private MacAddress supplicantAddress; |
| 63 | private short vlanId; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 64 | |
| 65 | private String sessionId = null; |
| 66 | |
| 67 | private final Logger log = getLogger(getClass()); |
| 68 | |
| 69 | |
| 70 | private State[] states = { |
| 71 | new Idle(), new Started(), new Pending(), new Authorized(), new Unauthorized() |
| 72 | }; |
| 73 | |
| 74 | |
| 75 | //State transition table |
| 76 | /* |
| 77 | |
| 78 | state IDLE | STARTED | PENDING | AUTHORIZED | UNAUTHORIZED |
| 79 | //// |
| 80 | input |
| 81 | ---------------------------------------------------------------------------------------------------- |
| 82 | |
Qianqian Hu | 5f374cd | 2016-02-15 17:25:22 +0800 | [diff] [blame] | 83 | START STARTED | _ | _ | STARTED | _ |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 84 | |
| 85 | REQUEST_ACCESS _ | PENDING | _ | _ | _ |
| 86 | |
| 87 | AUTHORIZE_ACCESS _ | _ | AUTHORIZED | _ | _ |
| 88 | |
| 89 | DENY_ACCESS _ | - | UNAUTHORIZED | _ | _ |
| 90 | |
| 91 | LOGOFF _ | _ | _ | IDLE | IDLE |
| 92 | */ |
| 93 | |
| 94 | private int[] idleTransition = |
| 95 | {STATE_STARTED, STATE_IDLE, STATE_IDLE, STATE_IDLE, STATE_IDLE}; |
| 96 | private int[] startedTransition = |
| 97 | {STATE_STARTED, STATE_PENDING, STATE_STARTED, STATE_STARTED, STATE_STARTED}; |
| 98 | private int[] pendingTransition = |
| 99 | {STATE_PENDING, STATE_PENDING, STATE_AUTHORIZED, STATE_UNAUTHORIZED, STATE_PENDING}; |
| 100 | private int[] authorizedTransition = |
Qianqian Hu | 5f374cd | 2016-02-15 17:25:22 +0800 | [diff] [blame] | 101 | {STATE_STARTED, STATE_AUTHORIZED, STATE_AUTHORIZED, STATE_AUTHORIZED, STATE_IDLE}; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 102 | private int[] unauthorizedTransition = |
| 103 | {STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, STATE_UNAUTHORIZED, STATE_IDLE}; |
| 104 | |
| 105 | //THE TRANSITION TABLE |
| 106 | private int[][] transition = |
| 107 | {idleTransition, startedTransition, pendingTransition, authorizedTransition, |
| 108 | unauthorizedTransition}; |
| 109 | |
| 110 | private int currentState = STATE_IDLE; |
| 111 | |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 112 | // Maps of state machines. Each state machine is represented by an |
| 113 | // unique identifier on the switch: dpid + port number |
| 114 | private static Map<String, StateMachine> sessionIdMap; |
| 115 | private static Map<Integer, StateMachine> identifierMap; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 116 | |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 117 | public static void initializeMaps() { |
| 118 | sessionIdMap = Maps.newConcurrentMap(); |
| 119 | identifierMap = Maps.newConcurrentMap(); |
| 120 | } |
| 121 | |
| 122 | public static void destroyMaps() { |
| 123 | sessionIdMap = null; |
| 124 | identifierMap = null; |
| 125 | } |
| 126 | |
| 127 | public static StateMachine lookupStateMachineById(byte identifier) { |
| 128 | return identifierMap.get((int) identifier); |
| 129 | } |
| 130 | |
| 131 | public static StateMachine lookupStateMachineBySessionId(String sessionId) { |
| 132 | return sessionIdMap.get(sessionId); |
| 133 | } /** |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 134 | * State Machine Constructor. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 135 | * |
| 136 | * @param sessionId session Id represented by the switch dpid + port number |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 137 | */ |
Ray Milkey | 3c6c2f9 | 2016-02-16 14:23:26 -0800 | [diff] [blame] | 138 | public StateMachine(String sessionId) { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 139 | log.info("Creating a new state machine for {}", sessionId); |
| 140 | this.sessionId = sessionId; |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 141 | sessionIdMap.put(sessionId, this); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 145 | * Gets the connect point for the supplicant side. |
| 146 | * |
| 147 | * @return supplicant connect point |
| 148 | */ |
| 149 | public ConnectPoint supplicantConnectpoint() { |
| 150 | return supplicantConnectpoint; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Sets the supplicant side connect point. |
| 155 | * |
| 156 | * @param supplicantConnectpoint supplicant select point. |
| 157 | */ |
| 158 | public void setSupplicantConnectpoint(ConnectPoint supplicantConnectpoint) { |
| 159 | this.supplicantConnectpoint = supplicantConnectpoint; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Gets the MAC address of the supplicant. |
| 164 | * |
| 165 | * @return supplicant MAC address |
| 166 | */ |
| 167 | public MacAddress supplicantAddress() { |
| 168 | return supplicantAddress; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Sets the supplicant MAC address. |
| 173 | * |
| 174 | * @param supplicantAddress new supplicant MAC address |
| 175 | */ |
| 176 | public void setSupplicantAddress(MacAddress supplicantAddress) { |
| 177 | this.supplicantAddress = supplicantAddress; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Gets the client's Vlan ID. |
| 182 | * |
| 183 | * @return client vlan ID |
| 184 | */ |
| 185 | public short vlanId() { |
| 186 | return vlanId; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Sets the client's vlan ID. |
| 191 | * |
| 192 | * @param vlanId new client vlan ID |
| 193 | */ |
| 194 | public void setVlanId(short vlanId) { |
| 195 | this.vlanId = vlanId; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Gets the client id that is requesting for access. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 200 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 201 | * @return The client id. |
| 202 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 203 | public String sessionId() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 204 | return this.sessionId; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Create the identifier for the state machine (happens when goes to STARTED state). |
| 209 | */ |
| 210 | private void createIdentifier() throws StateMachineException { |
| 211 | log.debug("Creating Identifier."); |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 212 | int index; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 213 | |
| 214 | try { |
| 215 | //find the first available spot for identifier assignment |
| 216 | index = StateMachine.bitSet.nextClearBit(0); |
| 217 | |
| 218 | //there is a limit of 256 identifiers |
| 219 | if (index == 256) { |
| 220 | throw new StateMachineException("Cannot handle any new identifier. Limit is 256."); |
| 221 | } |
| 222 | } catch (IndexOutOfBoundsException e) { |
| 223 | throw new StateMachineException(e.getMessage()); |
| 224 | } |
| 225 | |
| 226 | log.info("Assigning identifier {}", index); |
| 227 | StateMachine.bitSet.set(index); |
| 228 | this.identifier = index; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Set the challenge identifier and the state issued by the RADIUS. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 233 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 234 | * @param challengeIdentifier The challenge identifier set into the EAP packet from the RADIUS message. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 235 | * @param challengeState The challenge state from the RADIUS. |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 236 | */ |
| 237 | protected void setChallengeInfo(byte challengeIdentifier, byte[] challengeState) { |
| 238 | this.challengeIdentifier = challengeIdentifier; |
| 239 | this.challengeState = challengeState; |
| 240 | } |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 241 | |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Set the challenge identifier issued by the RADIUS on the access challenge request. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 244 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 245 | * @param challengeIdentifier The challenge identifier set into the EAP packet from the RADIUS message. |
| 246 | */ |
| 247 | protected void setChallengeIdentifier(byte challengeIdentifier) { |
| 248 | log.info("Set Challenge Identifier to {}", challengeIdentifier); |
| 249 | this.challengeIdentifier = challengeIdentifier; |
| 250 | } |
| 251 | |
| 252 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 253 | * Gets the challenge EAP identifier set by the RADIUS. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 254 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 255 | * @return The challenge EAP identifier. |
| 256 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 257 | protected byte challengeIdentifier() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 258 | return this.challengeIdentifier; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | /** |
| 263 | * Set the challenge state info issued by the RADIUS. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 264 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 265 | * @param challengeState The challenge state from the RADIUS. |
| 266 | */ |
| 267 | protected void setChallengeState(byte[] challengeState) { |
| 268 | log.info("Set Challenge State"); |
| 269 | this.challengeState = challengeState; |
| 270 | } |
| 271 | |
| 272 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 273 | * Gets the challenge state set by the RADIUS. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 274 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 275 | * @return The challenge state. |
| 276 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 277 | protected byte[] challengeState() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 278 | return this.challengeState; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Set the username. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 283 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 284 | * @param username The username sent to the RADIUS upon access request. |
| 285 | */ |
| 286 | protected void setUsername(byte[] username) { |
| 287 | this.username = username; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 292 | * Gets the username. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 293 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 294 | * @return The requestAuthenticator. |
| 295 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 296 | protected byte[] requestAuthenticator() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 297 | return this.requestAuthenticator; |
| 298 | } |
| 299 | |
| 300 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 301 | * Sets the authenticator. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 302 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 303 | * @param authenticator The username sent to the RADIUS upon access request. |
| 304 | */ |
| 305 | protected void setRequestAuthenticator(byte[] authenticator) { |
| 306 | this.requestAuthenticator = authenticator; |
| 307 | } |
| 308 | |
| 309 | |
| 310 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 311 | * Gets the username. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 312 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 313 | * @return The username. |
| 314 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 315 | protected byte[] username() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 316 | return this.username; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Return the identifier of the state machine. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 321 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 322 | * @return The state machine identifier. |
| 323 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 324 | public byte identifier() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 325 | return (byte) this.identifier; |
| 326 | } |
| 327 | |
| 328 | |
| 329 | protected void deleteIdentifier() { |
| 330 | if (this.identifier != -1) { |
| 331 | log.info("Freeing up " + this.identifier); |
| 332 | //this state machine should be deleted and free up the identifier |
| 333 | StateMachine.bitSet.clear(this.identifier); |
| 334 | this.identifier = -1; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /** |
| 340 | * Move to the next state. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 341 | * |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 342 | * @param msg message |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 343 | */ |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 344 | private void next(int msg) { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 345 | currentState = transition[currentState][msg]; |
| 346 | log.info("Current State " + currentState); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Client has requested the start action to allow network access. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 351 | * |
| 352 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 353 | */ |
| 354 | public void start() throws StateMachineException { |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 355 | states[currentState].start(); |
| 356 | //move to the next state |
| 357 | next(TRANSITION_START); |
| 358 | createIdentifier(); |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 359 | identifierMap.put(identifier, this); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
| 363 | * An Identification information has been sent by the supplicant. |
| 364 | * Move to the next state if possible. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 365 | * |
| 366 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 367 | */ |
| 368 | public void requestAccess() throws StateMachineException { |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 369 | states[currentState].requestAccess(); |
| 370 | //move to the next state |
| 371 | next(TRANSITION_REQUEST_ACCESS); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /** |
| 375 | * RADIUS has accepted the identification. |
| 376 | * Move to the next state if possible. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 377 | * |
| 378 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 379 | */ |
| 380 | public void authorizeAccess() throws StateMachineException { |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 381 | states[currentState].radiusAccepted(); |
| 382 | //move to the next state |
| 383 | next(TRANSITION_AUTHORIZE_ACCESS); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 384 | |
Ray Milkey | 3c6c2f9 | 2016-02-16 14:23:26 -0800 | [diff] [blame] | 385 | // TODO: put in calls to launch vSG here |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 386 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 387 | deleteIdentifier(); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /** |
| 391 | * RADIUS has denied the identification. |
| 392 | * Move to the next state if possible. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 393 | * |
| 394 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 395 | */ |
| 396 | public void denyAccess() throws StateMachineException { |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 397 | states[currentState].radiusDenied(); |
| 398 | //move to the next state |
| 399 | next(TRANSITION_DENY_ACCESS); |
| 400 | deleteIdentifier(); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Logoff request has been requested. |
| 405 | * Move to the next state if possible. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 406 | * |
| 407 | * @throws StateMachineException if authentication protocol is violated |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 408 | */ |
| 409 | public void logoff() throws StateMachineException { |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 410 | states[currentState].logoff(); |
| 411 | //move to the next state |
| 412 | next(TRANSITION_LOGOFF); |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /** |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 416 | * Gets the current state. |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 417 | * |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 418 | * @return The current state. Could be STATE_IDLE, STATE_STARTED, STATE_PENDING, STATE_AUTHORIZED, |
| 419 | * STATE_UNAUTHORIZED. |
| 420 | */ |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 421 | public int state() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 422 | return currentState; |
| 423 | } |
| 424 | |
Ray Milkey | 75879ef | 2015-09-24 16:34:02 -0700 | [diff] [blame] | 425 | @Override |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 426 | public String toString() { |
| 427 | return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" + |
| 428 | ("state: " + this.currentState); |
| 429 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 430 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 431 | abstract class State { |
| 432 | private final Logger log = getLogger(getClass()); |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 433 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 434 | private String name = "State"; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 435 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 436 | public void start() throws StateMachineInvalidTransitionException { |
| 437 | log.warn("START transition from this state is not allowed."); |
| 438 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 439 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 440 | public void requestAccess() throws StateMachineInvalidTransitionException { |
| 441 | log.warn("REQUEST ACCESS transition from this state is not allowed."); |
| 442 | } |
| 443 | |
| 444 | public void radiusAccepted() throws StateMachineInvalidTransitionException { |
| 445 | log.warn("AUTHORIZE ACCESS transition from this state is not allowed."); |
| 446 | } |
| 447 | |
| 448 | public void radiusDenied() throws StateMachineInvalidTransitionException { |
| 449 | log.warn("DENY ACCESS transition from this state is not allowed."); |
| 450 | } |
| 451 | |
| 452 | public void logoff() throws StateMachineInvalidTransitionException { |
| 453 | log.warn("LOGOFF transition from this state is not allowed."); |
| 454 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 455 | } |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 456 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 457 | /** |
| 458 | * Idle state: supplicant is logged of from the network. |
| 459 | */ |
| 460 | class Idle extends State { |
| 461 | private final Logger log = getLogger(getClass()); |
| 462 | private String name = "IDLE_STATE"; |
| 463 | |
| 464 | public void start() { |
| 465 | log.info("Moving from IDLE state to STARTED state."); |
| 466 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 467 | } |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 468 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 469 | /** |
| 470 | * Started state: supplicant has entered the network and informed the authenticator. |
| 471 | */ |
| 472 | class Started extends State { |
| 473 | private final Logger log = getLogger(getClass()); |
| 474 | private String name = "STARTED_STATE"; |
| 475 | |
| 476 | public void requestAccess() { |
| 477 | log.info("Moving from STARTED state to PENDING state."); |
| 478 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 479 | } |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 480 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 481 | /** |
| 482 | * Pending state: supplicant has been identified by the authenticator but has not access yet. |
| 483 | */ |
| 484 | class Pending extends State { |
| 485 | private final Logger log = getLogger(getClass()); |
| 486 | private String name = "PENDING_STATE"; |
| 487 | |
| 488 | public void radiusAccepted() { |
| 489 | log.info("Moving from PENDING state to AUTHORIZED state."); |
| 490 | } |
| 491 | |
| 492 | public void radiusDenied() { |
| 493 | log.info("Moving from PENDING state to UNAUTHORIZED state."); |
| 494 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 495 | } |
Thomas Vachuska | d894b5d | 2015-07-30 11:59:07 -0700 | [diff] [blame] | 496 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 497 | /** |
| 498 | * Authorized state: supplicant port has been accepted, access is granted. |
| 499 | */ |
| 500 | class Authorized extends State { |
| 501 | private final Logger log = getLogger(getClass()); |
| 502 | private String name = "AUTHORIZED_STATE"; |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 503 | |
Qianqian Hu | 5f374cd | 2016-02-15 17:25:22 +0800 | [diff] [blame] | 504 | public void start() { |
| 505 | log.info("Moving from AUTHORIZED state to STARTED state."); |
| 506 | } |
| 507 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 508 | public void logoff() { |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 509 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 510 | log.info("Moving from AUTHORIZED state to IDLE state."); |
| 511 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Ray Milkey | c3fca7f | 2015-09-24 08:36:45 -0700 | [diff] [blame] | 514 | /** |
| 515 | * Unauthorized state: supplicant port has been rejected, access is denied. |
| 516 | */ |
| 517 | class Unauthorized extends State { |
| 518 | private final Logger log = getLogger(getClass()); |
| 519 | private String name = "UNAUTHORIZED_STATE"; |
| 520 | |
| 521 | public void logoff() { |
| 522 | log.info("Moving from UNAUTHORIZED state to IDLE state."); |
| 523 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 524 | } |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 525 | |
| 526 | |
Ari Saha | 79d7c25 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 527 | } |