Committed by
Gerrit Code Review
Refactoring of AAA app classes
- break up multi compilation unit class - improve exception handling - start on general clean up Change-Id: Ic0b4e19a25c2fc1d64c73bfc4273c82cbcaf5d45
Showing
3 changed files
with
151 additions
and
137 deletions
... | @@ -137,7 +137,7 @@ class StateMachine { | ... | @@ -137,7 +137,7 @@ class StateMachine { |
137 | */ | 137 | */ |
138 | private void createIdentifier() throws StateMachineException { | 138 | private void createIdentifier() throws StateMachineException { |
139 | log.debug("Creating Identifier."); | 139 | log.debug("Creating Identifier."); |
140 | - int index = -1; | 140 | + int index; |
141 | 141 | ||
142 | try { | 142 | try { |
143 | //find the first available spot for identifier assignment | 143 | //find the first available spot for identifier assignment |
... | @@ -267,7 +267,7 @@ class StateMachine { | ... | @@ -267,7 +267,7 @@ class StateMachine { |
267 | /** | 267 | /** |
268 | * Move to the next state. | 268 | * Move to the next state. |
269 | * | 269 | * |
270 | - * @param msg | 270 | + * @param msg message |
271 | */ | 271 | */ |
272 | private void next(int msg) { | 272 | private void next(int msg) { |
273 | currentState = transition[currentState][msg]; | 273 | currentState = transition[currentState][msg]; |
... | @@ -280,14 +280,10 @@ class StateMachine { | ... | @@ -280,14 +280,10 @@ class StateMachine { |
280 | * @throws StateMachineException if authentication protocol is violated | 280 | * @throws StateMachineException if authentication protocol is violated |
281 | */ | 281 | */ |
282 | public void start() throws StateMachineException { | 282 | public void start() throws StateMachineException { |
283 | - try { | 283 | + states[currentState].start(); |
284 | - states[currentState].start(); | 284 | + //move to the next state |
285 | - //move to the next state | 285 | + next(TRANSITION_START); |
286 | - next(TRANSITION_START); | 286 | + createIdentifier(); |
287 | - createIdentifier(); | ||
288 | - } catch (StateMachineInvalidTransitionException e) { | ||
289 | - e.printStackTrace(); | ||
290 | - } | ||
291 | } | 287 | } |
292 | 288 | ||
293 | /** | 289 | /** |
... | @@ -297,13 +293,9 @@ class StateMachine { | ... | @@ -297,13 +293,9 @@ class StateMachine { |
297 | * @throws StateMachineException if authentication protocol is violated | 293 | * @throws StateMachineException if authentication protocol is violated |
298 | */ | 294 | */ |
299 | public void requestAccess() throws StateMachineException { | 295 | public void requestAccess() throws StateMachineException { |
300 | - try { | 296 | + states[currentState].requestAccess(); |
301 | - states[currentState].requestAccess(); | 297 | + //move to the next state |
302 | - //move to the next state | 298 | + next(TRANSITION_REQUEST_ACCESS); |
303 | - next(TRANSITION_REQUEST_ACCESS); | ||
304 | - } catch (StateMachineInvalidTransitionException e) { | ||
305 | - e.printStackTrace(); | ||
306 | - } | ||
307 | } | 299 | } |
308 | 300 | ||
309 | /** | 301 | /** |
... | @@ -313,27 +305,22 @@ class StateMachine { | ... | @@ -313,27 +305,22 @@ class StateMachine { |
313 | * @throws StateMachineException if authentication protocol is violated | 305 | * @throws StateMachineException if authentication protocol is violated |
314 | */ | 306 | */ |
315 | public void authorizeAccess() throws StateMachineException { | 307 | public void authorizeAccess() throws StateMachineException { |
316 | - try { | 308 | + states[currentState].radiusAccepted(); |
317 | - states[currentState].radiusAccepted(); | 309 | + //move to the next state |
318 | - //move to the next state | 310 | + next(TRANSITION_AUTHORIZE_ACCESS); |
319 | - next(TRANSITION_AUTHORIZE_ACCESS); | 311 | + |
320 | - | 312 | + if (voltService != null) { |
321 | - if (voltService != null) { | 313 | + voltService.addTenant( |
322 | - voltService.addTenant( | 314 | + VoltTenant.builder() |
323 | - VoltTenant.builder() | 315 | + .withHumanReadableName("VCPE-" + this.identifier) |
324 | - .withHumanReadableName("VCPE-" + this.identifier) | 316 | + .withId(this.identifier) |
325 | - .withId(this.identifier) | 317 | + .withProviderService(1) |
326 | - .withProviderService(1) | 318 | + .withServiceSpecificId(String.valueOf(this.identifier)) |
327 | - .withServiceSpecificId(String.valueOf(this.identifier)) | 319 | + .withPort(this.supplicantConnectpoint) |
328 | - .withPort(this.supplicantConnectpoint) | 320 | + .withVlanId(String.valueOf(this.vlanId)).build()); |
329 | - .withVlanId(String.valueOf(this.vlanId)).build()); | ||
330 | - } | ||
331 | - | ||
332 | - deleteIdentifier(); | ||
333 | - } catch (StateMachineInvalidTransitionException e) { | ||
334 | - e.printStackTrace(); | ||
335 | } | 321 | } |
336 | 322 | ||
323 | + deleteIdentifier(); | ||
337 | } | 324 | } |
338 | 325 | ||
339 | /** | 326 | /** |
... | @@ -343,14 +330,10 @@ class StateMachine { | ... | @@ -343,14 +330,10 @@ class StateMachine { |
343 | * @throws StateMachineException if authentication protocol is violated | 330 | * @throws StateMachineException if authentication protocol is violated |
344 | */ | 331 | */ |
345 | public void denyAccess() throws StateMachineException { | 332 | public void denyAccess() throws StateMachineException { |
346 | - try { | 333 | + states[currentState].radiusDenied(); |
347 | - states[currentState].radiusDenied(); | 334 | + //move to the next state |
348 | - //move to the next state | 335 | + next(TRANSITION_DENY_ACCESS); |
349 | - next(TRANSITION_DENY_ACCESS); | 336 | + deleteIdentifier(); |
350 | - deleteIdentifier(); | ||
351 | - } catch (StateMachineInvalidTransitionException e) { | ||
352 | - e.printStackTrace(); | ||
353 | - } | ||
354 | } | 337 | } |
355 | 338 | ||
356 | /** | 339 | /** |
... | @@ -360,13 +343,9 @@ class StateMachine { | ... | @@ -360,13 +343,9 @@ class StateMachine { |
360 | * @throws StateMachineException if authentication protocol is violated | 343 | * @throws StateMachineException if authentication protocol is violated |
361 | */ | 344 | */ |
362 | public void logoff() throws StateMachineException { | 345 | public void logoff() throws StateMachineException { |
363 | - try { | 346 | + states[currentState].logoff(); |
364 | - states[currentState].logoff(); | 347 | + //move to the next state |
365 | - //move to the next state | 348 | + next(TRANSITION_LOGOFF); |
366 | - next(TRANSITION_LOGOFF); | ||
367 | - } catch (StateMachineInvalidTransitionException e) { | ||
368 | - e.printStackTrace(); | ||
369 | - } | ||
370 | } | 349 | } |
371 | 350 | ||
372 | /** | 351 | /** |
... | @@ -384,117 +363,97 @@ class StateMachine { | ... | @@ -384,117 +363,97 @@ class StateMachine { |
384 | return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" + | 363 | return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" + |
385 | ("state: " + this.currentState); | 364 | ("state: " + this.currentState); |
386 | } | 365 | } |
387 | -} | ||
388 | 366 | ||
389 | -// FIXME: A source file should contain no more than one top-level entity! | 367 | + abstract class State { |
390 | - | 368 | + private final Logger log = getLogger(getClass()); |
391 | -abstract class State { | ||
392 | - private final Logger log = getLogger(getClass()); | ||
393 | 369 | ||
394 | - private String name = "State"; | 370 | + private String name = "State"; |
395 | 371 | ||
396 | - public void start() throws StateMachineInvalidTransitionException { | 372 | + public void start() throws StateMachineInvalidTransitionException { |
397 | - log.warn("START transition from this state is not allowed."); | 373 | + log.warn("START transition from this state is not allowed."); |
398 | - } | 374 | + } |
399 | 375 | ||
400 | - public void requestAccess() throws StateMachineInvalidTransitionException { | 376 | + public void requestAccess() throws StateMachineInvalidTransitionException { |
401 | - log.warn("REQUEST ACCESS transition from this state is not allowed."); | 377 | + log.warn("REQUEST ACCESS transition from this state is not allowed."); |
402 | - } | 378 | + } |
403 | 379 | ||
404 | - public void radiusAccepted() throws StateMachineInvalidTransitionException { | 380 | + public void radiusAccepted() throws StateMachineInvalidTransitionException { |
405 | - log.warn("AUTHORIZE ACCESS transition from this state is not allowed."); | 381 | + log.warn("AUTHORIZE ACCESS transition from this state is not allowed."); |
406 | - } | 382 | + } |
407 | 383 | ||
408 | - public void radiusDenied() throws StateMachineInvalidTransitionException { | 384 | + public void radiusDenied() throws StateMachineInvalidTransitionException { |
409 | - log.warn("DENY ACCESS transition from this state is not allowed."); | 385 | + log.warn("DENY ACCESS transition from this state is not allowed."); |
410 | - } | 386 | + } |
411 | 387 | ||
412 | - public void logoff() throws StateMachineInvalidTransitionException { | 388 | + public void logoff() throws StateMachineInvalidTransitionException { |
413 | - log.warn("LOGOFF transition from this state is not allowed."); | 389 | + log.warn("LOGOFF transition from this state is not allowed."); |
390 | + } | ||
414 | } | 391 | } |
415 | -} | ||
416 | 392 | ||
417 | -/** | 393 | + /** |
418 | - * Idle state: supplicant is logged of from the network. | 394 | + * Idle state: supplicant is logged of from the network. |
419 | - */ | 395 | + */ |
420 | -class Idle extends State { | 396 | + class Idle extends State { |
421 | - private final Logger log = getLogger(getClass()); | 397 | + private final Logger log = getLogger(getClass()); |
422 | - private String name = "IDLE_STATE"; | 398 | + private String name = "IDLE_STATE"; |
423 | 399 | ||
424 | - public void start() { | 400 | + public void start() { |
425 | - log.info("Moving from IDLE state to STARTED state."); | 401 | + log.info("Moving from IDLE state to STARTED state."); |
402 | + } | ||
426 | } | 403 | } |
427 | -} | ||
428 | 404 | ||
429 | -/** | 405 | + /** |
430 | - * Started state: supplicant has entered the network and informed the authenticator. | 406 | + * Started state: supplicant has entered the network and informed the authenticator. |
431 | - */ | 407 | + */ |
432 | -class Started extends State { | 408 | + class Started extends State { |
433 | - private final Logger log = getLogger(getClass()); | 409 | + private final Logger log = getLogger(getClass()); |
434 | - private String name = "STARTED_STATE"; | 410 | + private String name = "STARTED_STATE"; |
435 | 411 | ||
436 | - public void requestAccess() { | 412 | + public void requestAccess() { |
437 | - log.info("Moving from STARTED state to PENDING state."); | 413 | + log.info("Moving from STARTED state to PENDING state."); |
414 | + } | ||
438 | } | 415 | } |
439 | -} | ||
440 | 416 | ||
441 | -/** | 417 | + /** |
442 | - * Pending state: supplicant has been identified by the authenticator but has not access yet. | 418 | + * Pending state: supplicant has been identified by the authenticator but has not access yet. |
443 | - */ | 419 | + */ |
444 | -class Pending extends State { | 420 | + class Pending extends State { |
445 | - private final Logger log = getLogger(getClass()); | 421 | + private final Logger log = getLogger(getClass()); |
446 | - private String name = "PENDING_STATE"; | 422 | + private String name = "PENDING_STATE"; |
447 | 423 | ||
448 | - public void radiusAccepted() { | 424 | + public void radiusAccepted() { |
449 | - log.info("Moving from PENDING state to AUTHORIZED state."); | 425 | + log.info("Moving from PENDING state to AUTHORIZED state."); |
450 | - } | 426 | + } |
451 | 427 | ||
452 | - public void radiusDenied() { | 428 | + public void radiusDenied() { |
453 | - log.info("Moving from PENDING state to UNAUTHORIZED state."); | 429 | + log.info("Moving from PENDING state to UNAUTHORIZED state."); |
430 | + } | ||
454 | } | 431 | } |
455 | -} | ||
456 | 432 | ||
457 | -/** | 433 | + /** |
458 | - * Authorized state: supplicant port has been accepted, access is granted. | 434 | + * Authorized state: supplicant port has been accepted, access is granted. |
459 | - */ | 435 | + */ |
460 | -class Authorized extends State { | 436 | + class Authorized extends State { |
461 | - private final Logger log = getLogger(getClass()); | 437 | + private final Logger log = getLogger(getClass()); |
462 | - private String name = "AUTHORIZED_STATE"; | 438 | + private String name = "AUTHORIZED_STATE"; |
463 | 439 | ||
464 | - public void logoff() { | 440 | + public void logoff() { |
465 | 441 | ||
466 | - log.info("Moving from AUTHORIZED state to IDLE state."); | 442 | + log.info("Moving from AUTHORIZED state to IDLE state."); |
443 | + } | ||
467 | } | 444 | } |
468 | -} | ||
469 | 445 | ||
470 | -/** | 446 | + /** |
471 | - * Unauthorized state: supplicant port has been rejected, access is denied. | 447 | + * Unauthorized state: supplicant port has been rejected, access is denied. |
472 | - */ | 448 | + */ |
473 | -class Unauthorized extends State { | 449 | + class Unauthorized extends State { |
474 | - private final Logger log = getLogger(getClass()); | 450 | + private final Logger log = getLogger(getClass()); |
475 | - private String name = "UNAUTHORIZED_STATE"; | 451 | + private String name = "UNAUTHORIZED_STATE"; |
476 | 452 | ||
477 | - public void logoff() { | 453 | + public void logoff() { |
478 | - log.info("Moving from UNAUTHORIZED state to IDLE state."); | 454 | + log.info("Moving from UNAUTHORIZED state to IDLE state."); |
455 | + } | ||
479 | } | 456 | } |
480 | -} | ||
481 | 457 | ||
482 | 458 | ||
483 | -/** | ||
484 | - * Exception for the State Machine. | ||
485 | - */ | ||
486 | -class StateMachineException extends Exception { | ||
487 | - public StateMachineException(String message) { | ||
488 | - super(message); | ||
489 | - | ||
490 | - } | ||
491 | -} | ||
492 | - | ||
493 | -/** | ||
494 | - * Exception raised when the transition from one state to another is invalid. | ||
495 | - */ | ||
496 | -class StateMachineInvalidTransitionException extends StateMachineException { | ||
497 | - public StateMachineInvalidTransitionException(String message) { | ||
498 | - super(message); | ||
499 | - } | ||
500 | } | 459 | } | ... | ... |
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 | +package org.onosproject.aaa; | ||
19 | + | ||
20 | +/** | ||
21 | + * Exception for the State Machine. | ||
22 | + */ | ||
23 | +class StateMachineException extends Exception { | ||
24 | + public StateMachineException(String message) { | ||
25 | + super(message); | ||
26 | + | ||
27 | + } | ||
28 | +} |
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 | +package org.onosproject.aaa; | ||
19 | + | ||
20 | +/** | ||
21 | + * Exception raised when the transition from one state to another is invalid. | ||
22 | + */ | ||
23 | +class StateMachineInvalidTransitionException extends StateMachineException { | ||
24 | + public StateMachineInvalidTransitionException(String message) { | ||
25 | + super(message); | ||
26 | + } | ||
27 | +} |
-
Please register or login to post a comment