Ray Milkey
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
...@@ -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 {
284 states[currentState].start(); 283 states[currentState].start();
285 //move to the next state 284 //move to the next state
286 next(TRANSITION_START); 285 next(TRANSITION_START);
287 createIdentifier(); 286 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 {
301 states[currentState].requestAccess(); 296 states[currentState].requestAccess();
302 //move to the next state 297 //move to the next state
303 next(TRANSITION_REQUEST_ACCESS); 298 next(TRANSITION_REQUEST_ACCESS);
304 - } catch (StateMachineInvalidTransitionException e) {
305 - e.printStackTrace();
306 - }
307 } 299 }
308 300
309 /** 301 /**
...@@ -313,7 +305,6 @@ class StateMachine { ...@@ -313,7 +305,6 @@ 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 {
317 states[currentState].radiusAccepted(); 308 states[currentState].radiusAccepted();
318 //move to the next state 309 //move to the next state
319 next(TRANSITION_AUTHORIZE_ACCESS); 310 next(TRANSITION_AUTHORIZE_ACCESS);
...@@ -330,10 +321,6 @@ class StateMachine { ...@@ -330,10 +321,6 @@ class StateMachine {
330 } 321 }
331 322
332 deleteIdentifier(); 323 deleteIdentifier();
333 - } catch (StateMachineInvalidTransitionException e) {
334 - e.printStackTrace();
335 - }
336 -
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 {
347 states[currentState].radiusDenied(); 333 states[currentState].radiusDenied();
348 //move to the next state 334 //move to the next state
349 next(TRANSITION_DENY_ACCESS); 335 next(TRANSITION_DENY_ACCESS);
350 deleteIdentifier(); 336 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 {
364 states[currentState].logoff(); 346 states[currentState].logoff();
365 //move to the next state 347 //move to the next state
366 next(TRANSITION_LOGOFF); 348 next(TRANSITION_LOGOFF);
367 - } catch (StateMachineInvalidTransitionException e) {
368 - e.printStackTrace();
369 - }
370 } 349 }
371 350
372 /** 351 /**
...@@ -384,11 +363,8 @@ class StateMachine { ...@@ -384,11 +363,8 @@ 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 -
389 -// FIXME: A source file should contain no more than one top-level entity!
390 366
391 -abstract class State { 367 + abstract class State {
392 private final Logger log = getLogger(getClass()); 368 private final Logger log = getLogger(getClass());
393 369
394 private String name = "State"; 370 private String name = "State";
...@@ -412,36 +388,36 @@ abstract class State { ...@@ -412,36 +388,36 @@ abstract class State {
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.");
414 } 390 }
415 -} 391 + }
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.");
426 } 402 }
427 -} 403 + }
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.");
438 } 414 }
439 -} 415 + }
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
...@@ -452,12 +428,12 @@ class Pending extends State { ...@@ -452,12 +428,12 @@ class Pending extends State {
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.");
454 } 430 }
455 -} 431 + }
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
...@@ -465,36 +441,19 @@ class Authorized extends State { ...@@ -465,36 +441,19 @@ class Authorized extends State {
465 441
466 log.info("Moving from AUTHORIZED state to IDLE state."); 442 log.info("Moving from AUTHORIZED state to IDLE state.");
467 } 443 }
468 -} 444 + }
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.");
479 } 455 }
480 -}
481 -
482 -
483 -/**
484 - * Exception for the State Machine.
485 - */
486 -class StateMachineException extends Exception {
487 - public StateMachineException(String message) {
488 - super(message);
489 -
490 } 456 }
491 -}
492 457
493 -/** 458 +
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 +}