[ONOS-5688] Make LISP authKey and authKeyId be configurable

Change-Id: I8262cc1791e064547e79cb9a3cb58e99feec50b1
diff --git a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java
index f664c4c..ffabf79 100644
--- a/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java
+++ b/protocols/lisp/ctl/src/main/java/org/onosproject/lisp/ctl/LispMapServer.java
@@ -16,6 +16,7 @@
 package org.onosproject.lisp.ctl;
 
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.authentication.LispAuthenticationConfig;
 import org.onosproject.lisp.msg.protocols.DefaultLispInfoReply;
 import org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.DefaultNotifyBuilder;
 import org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.DefaultRegisterBuilder;
@@ -49,23 +50,22 @@
  * LISP map server class.
  * Handles map-register message and acknowledges with map-notify message.
  */
-public class LispMapServer {
+public final class LispMapServer {
 
     private static final int MAP_NOTIFY_PORT = 4342;
     private static final int INFO_REPLY_PORT = 4342;
 
-    // TODO: need to be configurable
-    private static final String AUTH_KEY = "onos";
-
-    // TODO: need to be configurable
-    private static final short AUTH_METHOD = 1;
-
     private static final Logger log = LoggerFactory.getLogger(LispMapServer.class);
 
-    private LispEidRlocMap mapInfo;
+    private LispEidRlocMap eidRlocMap = LispEidRlocMap.getInstance();
+    private LispAuthenticationConfig authConfig = LispAuthenticationConfig.getInstance();
 
-    public LispMapServer() {
-        mapInfo = LispEidRlocMap.getInstance();
+    public static LispMapServer getInstance() {
+        return SingletonHelper.INSTANCE;
+    }
+
+    // non-instantiable (except for our Singleton)
+    private LispMapServer() {
     }
 
     /**
@@ -84,9 +84,9 @@
         }
 
         NotifyBuilder notifyBuilder = new DefaultNotifyBuilder();
-        notifyBuilder.withKeyId(AUTH_METHOD);
-        notifyBuilder.withAuthDataLength(valueOf(AUTH_METHOD).getHashLength());
-        notifyBuilder.withAuthKey(AUTH_KEY);
+        notifyBuilder.withKeyId(authConfig.lispAuthKeyId());
+        notifyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength());
+        notifyBuilder.withAuthKey(authConfig.lispAuthKey());
         notifyBuilder.withNonce(register.getNonce());
         notifyBuilder.withMapRecords(register.getMapRecords());
 
@@ -99,7 +99,7 @@
         register.getMapRecords().forEach(record -> {
             LispEidRecord eidRecord =
                     new LispEidRecord(record.getMaskLength(), record.getEidPrefixAfi());
-            mapInfo.insertMapRecord(eidRecord, record);
+            eidRlocMap.insertMapRecord(eidRecord, record);
         });
 
         return notify;
@@ -146,8 +146,8 @@
 
         InfoReplyBuilder replyBuilder = new DefaultLispInfoReply.DefaultInfoReplyBuilder();
         replyBuilder.withKeyId(request.getKeyId());
-        replyBuilder.withAuthDataLength(valueOf(AUTH_METHOD).getHashLength());
-        replyBuilder.withAuthKey(AUTH_KEY);
+        replyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength());
+        replyBuilder.withAuthKey(authConfig.lispAuthKey());
         replyBuilder.withNonce(request.getNonce());
         replyBuilder.withEidPrefix(request.getPrefix());
         replyBuilder.withMaskLength(request.getMaskLength());
@@ -171,7 +171,7 @@
     private boolean checkMapRegisterAuthData(LispMapRegister register) {
         RegisterBuilder registerBuilder = new DefaultRegisterBuilder();
         registerBuilder.withKeyId(register.getKeyId());
-        registerBuilder.withAuthKey(AUTH_KEY);
+        registerBuilder.withAuthKey(authConfig.lispAuthKey());
         registerBuilder.withNonce(register.getNonce());
         registerBuilder.withIsProxyMapReply(register.isProxyMapReply());
         registerBuilder.withIsWantMapNotify(register.isWantMapNotify());
@@ -192,7 +192,7 @@
     private boolean checkInfoRequestAuthData(LispInfoRequest request) {
         InfoRequestBuilder requestBuilder = new DefaultInfoRequestBuilder();
         requestBuilder.withKeyId(request.getKeyId());
-        requestBuilder.withAuthKey(AUTH_KEY);
+        requestBuilder.withAuthKey(authConfig.lispAuthKey());
         requestBuilder.withNonce(request.getNonce());
         requestBuilder.withTtl(request.getTtl());
         requestBuilder.withEidPrefix(request.getPrefix());
@@ -203,4 +203,11 @@
 
         return Arrays.equals(authRequest.getAuthData(), request.getAuthData());
     }
+
+    /**
+     * Prevents object instantiation from external.
+     */
+    private static class SingletonHelper {
+        private static final LispMapServer INSTANCE = new LispMapServer();
+    }
 }