Sonar Fixes: Variable name changes
[aaf/authz.git] / auth / auth-core / src / main / java / org / onap / aaf / auth / env / AuthzEnv.java
index 70cee5c..0e2d414 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -39,10 +39,10 @@ import org.onap.aaf.misc.rosetta.env.RosettaEnv;
 
 /**
  * AuthzEnv is the Env tailored to Authz Service
- * 
+ *
  * Most of it is derived from RosettaEnv, but it also implements Access, which
  * is an Interface that Allows CADI to interact with Container Logging
- * 
+ *
  * @author Jonathan
  *
  */
@@ -65,14 +65,14 @@ public class AuthzEnv extends RosettaEnv implements Access {
         super();
         _init(new PropAccess(props));
     }
-    
+
 
     public AuthzEnv(PropAccess pa) {
         super();
         _init(pa);
     }
-    
-    private final void _init(PropAccess pa) { 
+
+    private final void _init(PropAccess pa) {
         access = pa;
         times = new long[20];
         idx = 0;
@@ -85,16 +85,16 @@ public class AuthzEnv extends RosettaEnv implements Access {
         debug = new AccessLogTarget(access, Level.DEBUG);
         trace = new AccessLogTarget(access, Level.TRACE);
     }
-    
+
     private class AccessLogTarget implements LogTarget {
         private final Level level;
         private final Access access;
-        
+
         public AccessLogTarget(final Access access, final Level level) {
             this.level = level;
             this.access = access;
         }
-        
+
         @Override
         public void log(Object... msgs) {
             access.log(level, msgs);
@@ -102,7 +102,10 @@ public class AuthzEnv extends RosettaEnv implements Access {
 
         @Override
         public void log(Throwable e, Object... msgs) {
-            access.log(Level.ERROR, msgs);
+            Object[] nm = new Object[msgs.length+1];
+            System.arraycopy(msgs, 0, nm, 1, msgs.length);
+            nm[0]=e;
+            access.log(Level.ERROR, nm);
         }
 
         @Override
@@ -114,13 +117,13 @@ public class AuthzEnv extends RosettaEnv implements Access {
         public void printf(String fmt, Object... vars) {
             access.printf(level, fmt, vars);
         }
-        
+
     }
     @Override
     public AuthzTransImpl newTrans() {
         synchronized(this) {
             times[idx]=System.currentTimeMillis();
-            if(++idx>=times.length)idx=0;
+            if (++idx>=times.length)idx=0;
         }
         return new AuthzTransImpl(this);
     }
@@ -137,28 +140,28 @@ public class AuthzEnv extends RosettaEnv implements Access {
         int count = 0;
         long pot = 0;
         long prev = 0;
-        for(int i=idx;i<times.length;++i) {
-            if(times[i]>0) {
-                if(prev>0) {
+        for (int i=idx;i<times.length;++i) {
+            if (times[i]>0) {
+                if (prev>0) {
                     ++count;
         pot += times[i]-prev;
                 }
-                prev = times[i]; 
+                prev = times[i];
             }
         }
-        for(int i=0;i<idx;++i) {
-            if(times[i]>0) {
-                if(prev>0) {
+        for (int i=0;i<idx;++i) {
+            if (times[i]>0) {
+                if (prev>0) {
                     ++count;
                     pot += times[i]-prev;
                 }
-                prev = times[i]; 
+                prev = times[i];
             }
         }
 
         return count==0?300000L:pot/count; // Return Weighted Avg, or 5 mins, if none avail.
     }
-    
+
     @Override
     public ClassLoader classLoader() {
         return getClass().getClassLoader();
@@ -196,14 +199,14 @@ public class AuthzEnv extends RosettaEnv implements Access {
     public void setLogLevel(Level level) {
         access.setLogLevel(level);
     }
-    
+
     private static final byte[] ENC="enc:".getBytes();
     public String decrypt(String encrypted, final boolean anytext) throws IOException {
-        if(encrypted==null) {
+        if (encrypted==null) {
             throw new IOException("Password to be decrypted is null");
         }
-        if(anytext || encrypted.startsWith("enc:")) {
-            if(decryptor.equals(Decryptor.NULL) && getProperty(Config.CADI_KEYFILE)!=null) {
+        if (anytext || encrypted.startsWith("enc:")) {
+            if (decryptor.equals(Decryptor.NULL) && getProperty(Config.CADI_KEYFILE)!=null) {
                 final Symm s;
                 try {
                     s = Symm.obtain(this);
@@ -234,7 +237,7 @@ public class AuthzEnv extends RosettaEnv implements Access {
                             return "";
                         }
                     }
-    
+
                 };
             }
             return decryptor.decrypt(encrypted);
@@ -287,5 +290,5 @@ public class AuthzEnv extends RosettaEnv implements Access {
     public Properties getProperties() {
         return access.getProperties();
     };
-    
+
 }