Refactoring of AAA app classes
- break up multi compilation unit class
- improve exception handling
- start on general clean up
Change-Id: Ic0b4e19a25c2fc1d64c73bfc4273c82cbcaf5d45
diff --git a/src/main/java/org/onosproject/aaa/StateMachine.java b/src/main/java/org/onosproject/aaa/StateMachine.java
index 60959ad..227f4e8 100644
--- a/src/main/java/org/onosproject/aaa/StateMachine.java
+++ b/src/main/java/org/onosproject/aaa/StateMachine.java
@@ -137,7 +137,7 @@
*/
private void createIdentifier() throws StateMachineException {
log.debug("Creating Identifier.");
- int index = -1;
+ int index;
try {
//find the first available spot for identifier assignment
@@ -267,7 +267,7 @@
/**
* Move to the next state.
*
- * @param msg
+ * @param msg message
*/
private void next(int msg) {
currentState = transition[currentState][msg];
@@ -280,14 +280,10 @@
* @throws StateMachineException if authentication protocol is violated
*/
public void start() throws StateMachineException {
- try {
- states[currentState].start();
- //move to the next state
- next(TRANSITION_START);
- createIdentifier();
- } catch (StateMachineInvalidTransitionException e) {
- e.printStackTrace();
- }
+ states[currentState].start();
+ //move to the next state
+ next(TRANSITION_START);
+ createIdentifier();
}
/**
@@ -297,13 +293,9 @@
* @throws StateMachineException if authentication protocol is violated
*/
public void requestAccess() throws StateMachineException {
- try {
- states[currentState].requestAccess();
- //move to the next state
- next(TRANSITION_REQUEST_ACCESS);
- } catch (StateMachineInvalidTransitionException e) {
- e.printStackTrace();
- }
+ states[currentState].requestAccess();
+ //move to the next state
+ next(TRANSITION_REQUEST_ACCESS);
}
/**
@@ -313,27 +305,22 @@
* @throws StateMachineException if authentication protocol is violated
*/
public void authorizeAccess() throws StateMachineException {
- try {
- states[currentState].radiusAccepted();
- //move to the next state
- next(TRANSITION_AUTHORIZE_ACCESS);
+ states[currentState].radiusAccepted();
+ //move to the next state
+ next(TRANSITION_AUTHORIZE_ACCESS);
- if (voltService != null) {
- voltService.addTenant(
- VoltTenant.builder()
- .withHumanReadableName("VCPE-" + this.identifier)
- .withId(this.identifier)
- .withProviderService(1)
- .withServiceSpecificId(String.valueOf(this.identifier))
- .withPort(this.supplicantConnectpoint)
- .withVlanId(String.valueOf(this.vlanId)).build());
- }
-
- deleteIdentifier();
- } catch (StateMachineInvalidTransitionException e) {
- e.printStackTrace();
+ if (voltService != null) {
+ voltService.addTenant(
+ VoltTenant.builder()
+ .withHumanReadableName("VCPE-" + this.identifier)
+ .withId(this.identifier)
+ .withProviderService(1)
+ .withServiceSpecificId(String.valueOf(this.identifier))
+ .withPort(this.supplicantConnectpoint)
+ .withVlanId(String.valueOf(this.vlanId)).build());
}
+ deleteIdentifier();
}
/**
@@ -343,14 +330,10 @@
* @throws StateMachineException if authentication protocol is violated
*/
public void denyAccess() throws StateMachineException {
- try {
- states[currentState].radiusDenied();
- //move to the next state
- next(TRANSITION_DENY_ACCESS);
- deleteIdentifier();
- } catch (StateMachineInvalidTransitionException e) {
- e.printStackTrace();
- }
+ states[currentState].radiusDenied();
+ //move to the next state
+ next(TRANSITION_DENY_ACCESS);
+ deleteIdentifier();
}
/**
@@ -360,13 +343,9 @@
* @throws StateMachineException if authentication protocol is violated
*/
public void logoff() throws StateMachineException {
- try {
- states[currentState].logoff();
- //move to the next state
- next(TRANSITION_LOGOFF);
- } catch (StateMachineInvalidTransitionException e) {
- e.printStackTrace();
- }
+ states[currentState].logoff();
+ //move to the next state
+ next(TRANSITION_LOGOFF);
}
/**
@@ -384,117 +363,97 @@
return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" +
("state: " + this.currentState);
}
-}
-// FIXME: A source file should contain no more than one top-level entity!
+ abstract class State {
+ private final Logger log = getLogger(getClass());
-abstract class State {
- private final Logger log = getLogger(getClass());
+ private String name = "State";
- private String name = "State";
+ public void start() throws StateMachineInvalidTransitionException {
+ log.warn("START transition from this state is not allowed.");
+ }
- public void start() throws StateMachineInvalidTransitionException {
- log.warn("START transition from this state is not allowed.");
+ public void requestAccess() throws StateMachineInvalidTransitionException {
+ log.warn("REQUEST ACCESS transition from this state is not allowed.");
+ }
+
+ public void radiusAccepted() throws StateMachineInvalidTransitionException {
+ log.warn("AUTHORIZE ACCESS transition from this state is not allowed.");
+ }
+
+ public void radiusDenied() throws StateMachineInvalidTransitionException {
+ log.warn("DENY ACCESS transition from this state is not allowed.");
+ }
+
+ public void logoff() throws StateMachineInvalidTransitionException {
+ log.warn("LOGOFF transition from this state is not allowed.");
+ }
}
- public void requestAccess() throws StateMachineInvalidTransitionException {
- log.warn("REQUEST ACCESS transition from this state is not allowed.");
+ /**
+ * Idle state: supplicant is logged of from the network.
+ */
+ class Idle extends State {
+ private final Logger log = getLogger(getClass());
+ private String name = "IDLE_STATE";
+
+ public void start() {
+ log.info("Moving from IDLE state to STARTED state.");
+ }
}
- public void radiusAccepted() throws StateMachineInvalidTransitionException {
- log.warn("AUTHORIZE ACCESS transition from this state is not allowed.");
+ /**
+ * Started state: supplicant has entered the network and informed the authenticator.
+ */
+ class Started extends State {
+ private final Logger log = getLogger(getClass());
+ private String name = "STARTED_STATE";
+
+ public void requestAccess() {
+ log.info("Moving from STARTED state to PENDING state.");
+ }
}
- public void radiusDenied() throws StateMachineInvalidTransitionException {
- log.warn("DENY ACCESS transition from this state is not allowed.");
+ /**
+ * Pending state: supplicant has been identified by the authenticator but has not access yet.
+ */
+ class Pending extends State {
+ private final Logger log = getLogger(getClass());
+ private String name = "PENDING_STATE";
+
+ public void radiusAccepted() {
+ log.info("Moving from PENDING state to AUTHORIZED state.");
+ }
+
+ public void radiusDenied() {
+ log.info("Moving from PENDING state to UNAUTHORIZED state.");
+ }
}
- public void logoff() throws StateMachineInvalidTransitionException {
- log.warn("LOGOFF transition from this state is not allowed.");
- }
-}
+ /**
+ * Authorized state: supplicant port has been accepted, access is granted.
+ */
+ class Authorized extends State {
+ private final Logger log = getLogger(getClass());
+ private String name = "AUTHORIZED_STATE";
-/**
- * Idle state: supplicant is logged of from the network.
- */
-class Idle extends State {
- private final Logger log = getLogger(getClass());
- private String name = "IDLE_STATE";
+ public void logoff() {
- public void start() {
- log.info("Moving from IDLE state to STARTED state.");
- }
-}
-
-/**
- * Started state: supplicant has entered the network and informed the authenticator.
- */
-class Started extends State {
- private final Logger log = getLogger(getClass());
- private String name = "STARTED_STATE";
-
- public void requestAccess() {
- log.info("Moving from STARTED state to PENDING state.");
- }
-}
-
-/**
- * Pending state: supplicant has been identified by the authenticator but has not access yet.
- */
-class Pending extends State {
- private final Logger log = getLogger(getClass());
- private String name = "PENDING_STATE";
-
- public void radiusAccepted() {
- log.info("Moving from PENDING state to AUTHORIZED state.");
+ log.info("Moving from AUTHORIZED state to IDLE state.");
+ }
}
- public void radiusDenied() {
- log.info("Moving from PENDING state to UNAUTHORIZED state.");
+ /**
+ * Unauthorized state: supplicant port has been rejected, access is denied.
+ */
+ class Unauthorized extends State {
+ private final Logger log = getLogger(getClass());
+ private String name = "UNAUTHORIZED_STATE";
+
+ public void logoff() {
+ log.info("Moving from UNAUTHORIZED state to IDLE state.");
+ }
}
-}
-
-/**
- * Authorized state: supplicant port has been accepted, access is granted.
- */
-class Authorized extends State {
- private final Logger log = getLogger(getClass());
- private String name = "AUTHORIZED_STATE";
-
- public void logoff() {
-
- log.info("Moving from AUTHORIZED state to IDLE state.");
- }
-}
-
-/**
- * Unauthorized state: supplicant port has been rejected, access is denied.
- */
-class Unauthorized extends State {
- private final Logger log = getLogger(getClass());
- private String name = "UNAUTHORIZED_STATE";
-
- public void logoff() {
- log.info("Moving from UNAUTHORIZED state to IDLE state.");
- }
-}
-/**
- * Exception for the State Machine.
- */
-class StateMachineException extends Exception {
- public StateMachineException(String message) {
- super(message);
-
- }
-}
-
-/**
- * Exception raised when the transition from one state to another is invalid.
- */
-class StateMachineInvalidTransitionException extends StateMachineException {
- public StateMachineInvalidTransitionException(String message) {
- super(message);
- }
}
diff --git a/src/main/java/org/onosproject/aaa/StateMachineException.java b/src/main/java/org/onosproject/aaa/StateMachineException.java
new file mode 100644
index 0000000..d4a4da7
--- /dev/null
+++ b/src/main/java/org/onosproject/aaa/StateMachineException.java
@@ -0,0 +1,28 @@
+/*
+ *
+ * Copyright 2015 AT&T Foundry
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.onosproject.aaa;
+
+/**
+ * Exception for the State Machine.
+ */
+class StateMachineException extends Exception {
+ public StateMachineException(String message) {
+ super(message);
+
+ }
+}
diff --git a/src/main/java/org/onosproject/aaa/StateMachineInvalidTransitionException.java b/src/main/java/org/onosproject/aaa/StateMachineInvalidTransitionException.java
new file mode 100644
index 0000000..9f41a34
--- /dev/null
+++ b/src/main/java/org/onosproject/aaa/StateMachineInvalidTransitionException.java
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright 2015 AT&T Foundry
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.onosproject.aaa;
+
+/**
+ * Exception raised when the transition from one state to another is invalid.
+ */
+class StateMachineInvalidTransitionException extends StateMachineException {
+ public StateMachineInvalidTransitionException(String message) {
+ super(message);
+ }
+}