SEBA-75: AAA app exposes authentication state machine events.

Change-Id: I9a1fbc0c28579f6b347322d6f7fc58635c1a9c8a
diff --git a/src/main/java/org/opencord/aaa/StateMachine.java b/src/main/java/org/opencord/aaa/StateMachine.java
index e2a24bc..d888c98 100644
--- a/src/main/java/org/opencord/aaa/StateMachine.java
+++ b/src/main/java/org/opencord/aaa/StateMachine.java
@@ -109,6 +109,8 @@
     private static Map<String, StateMachine> sessionIdMap;
     private static Map<Integer, StateMachine> identifierMap;
 
+    private static StateMachineDelegate delegate;
+
     public static void initializeMaps() {
         sessionIdMap = Maps.newConcurrentMap();
         identifierMap = Maps.newConcurrentMap();
@@ -120,6 +122,16 @@
         identifierMap = null;
     }
 
+    public static void setDelegate(StateMachineDelegate delagate) {
+        StateMachine.delegate = delagate;
+    }
+
+    public static void unsetDelegate(StateMachineDelegate delegate) {
+        if (StateMachine.delegate == delegate) {
+            StateMachine.delegate = null;
+        }
+    }
+
     public static Map<String, StateMachine> sessionIdMap() {
         return sessionIdMap;
     }
@@ -366,6 +378,10 @@
      */
     public void start() throws StateMachineException {
         states[currentState].start();
+
+        delegate.notify(new AuthenticationEvent(
+                AuthenticationEvent.Type.STARTED, supplicantConnectpoint));
+
         //move to the next state
         next(TRANSITION_START);
         identifier = this.identifier();
@@ -379,6 +395,10 @@
      */
     public void requestAccess() throws StateMachineException {
         states[currentState].requestAccess();
+
+        delegate.notify(new AuthenticationEvent(
+                AuthenticationEvent.Type.REQUESTED, supplicantConnectpoint));
+
         //move to the next state
         next(TRANSITION_REQUEST_ACCESS);
     }
@@ -394,7 +414,8 @@
         //move to the next state
         next(TRANSITION_AUTHORIZE_ACCESS);
 
-        // TODO send state machine change event
+        delegate.notify(new AuthenticationEvent(
+                AuthenticationEvent.Type.APPROVED, supplicantConnectpoint));
 
         // Clear mapping
         deleteStateMachineMapping(this);
@@ -410,6 +431,10 @@
         states[currentState].radiusDenied();
         //move to the next state
         next(TRANSITION_DENY_ACCESS);
+
+        delegate.notify(new AuthenticationEvent(
+                AuthenticationEvent.Type.DENIED, supplicantConnectpoint));
+
         // Clear mappings
         deleteStateMachineMapping(this);
     }