Sonar: Exception handler should preserve exception
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / authentication / LispMACAuthentication.java
index 0a4ec7e86a4ffaac587109ddb79c774c70a7fa20..ed92ec9aa792dd0f18971b295fff971cd8b022cd 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.lispflowmapping.implementation.authentication;
 
 import java.nio.ByteBuffer;
@@ -8,16 +15,17 @@ import java.util.Arrays;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 
-import org.opendaylight.lispflowmapping.implementation.serializer.MapNotifySerializer;
-import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
-import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
-import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+import org.opendaylight.lispflowmapping.interfaces.lisp.ILispAuthentication;
+import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class LispMACAuthentication implements ILispAuthentication {
 
-    protected static final Logger logger = LoggerFactory.getLogger(LispMACAuthentication.class);
+    protected static final Logger LOG = LoggerFactory.getLogger(LispMACAuthentication.class);
 
     protected String algorithm;
     private byte[] tempAuthenticationData;
@@ -29,12 +37,13 @@ public class LispMACAuthentication implements ILispAuthentication {
             authenticationLength = Mac.getInstance(algorithm).getMacLength();
             tempAuthenticationData = new byte[authenticationLength];
         } catch (NoSuchAlgorithmException e) {
-            logger.error("No such MAC algorithm" + algorithm);
+            LOG.warn("No such MAC algorithm {}", algorithm, e);
         }
     }
 
     public boolean validate(MapRegister mapRegister, String key) {
         if (key == null) {
+            LOG.warn("The authentication key is null!");
             return false;
         }
         ByteBuffer mapRegisterBuffer = MapRegisterSerializer.getInstance().serialize(mapRegister);
@@ -57,9 +66,9 @@ public class LispMACAuthentication implements ILispAuthentication {
 
             return mac.doFinal(data);
         } catch (InvalidKeyException e) {
-            logger.error("Invalid password" + key);
+            LOG.warn("Invalid password {}", key, e);
         } catch (NoSuchAlgorithmException e) {
-            logger.error("No such MAC algorithm" + algorithm);
+            LOG.warn("No such MAC algorithm {}", algorithm, e);
         }
         return null;
     }