* 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.
/**
* 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
*
*/
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;
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);
@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
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);
}
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();
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);
return "";
}
}
-
+
};
}
return decryptor.decrypt(encrypted);
public Properties getProperties() {
return access.getProperties();
};
-
+
}