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