X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fcore%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2FAccess.java;h=76d9bb2a9af8784694abb6536559afb11047f3c5;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=83127238fc0c1a70bdbe47a1b6862b9dcf175645;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java index 83127238..76d9bb2a 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java @@ -35,146 +35,146 @@ import java.util.Properties; * */ public interface Access { - // levels to use - public enum Level { - DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),TRACE(0x10000),NONE(0XFFFF); - private final int bit; - - Level(int ord) { - bit = ord; - } - - public boolean inMask(int mask) { - return (mask & bit) == bit; - } - - public int addToMask(int mask) { - return mask | bit; - } - - public int delFromMask(int mask) { - return mask & ~bit; - } - - public int toggle(int mask) { - if(inMask(mask)) { - return delFromMask(mask); - } else { - return addToMask(mask); - } - } - - - public int maskOf() { - int mask=0; - for(Level l : values()) { - if(ordinal()<=l.ordinal() && l!=NONE) { - mask|=l.bit; - } - } - return mask; - } - } - - /** - * Write a variable list of Object's text via the toString() method with appropriate space, etc. - * @param elements - */ - public void log(Level level, Object ... elements); - - /** - * Printf mechanism for Access - * @param level - * @param fmt - * @param elements - */ - public void printf(Level level, String fmt, Object ... elements); - - /** - * Check if message will log before constructing - * @param level - * @return - */ - public boolean willLog(Level level); - - /** - * Write the contents of an exception, followed by a variable list of Object's text via the - * toString() method with appropriate space, etc. - * - * The Loglevel is always "ERROR" - * - * @param elements - */ - public void log(Exception e, Object ... elements); - - /** - * Set the Level to compare logging too - */ - public void setLogLevel(Level level); - - /** - * It is important in some cases to create a class from within the same Classloader that created - * Security Objects. Specifically, it's pretty typical for Web Containers to separate classloaders - * so as to allow Apps with different dependencies. - * @return - */ - public ClassLoader classLoader(); - - public String getProperty(String string, String def); - - public Properties getProperties(); - - public void load(InputStream is) throws IOException; - - /** - * if "anytext" is true, then decryption will always be attempted. Otherwise, only if starts with - * Symm.ENC - * @param encrypted - * @param anytext - * @return - * @throws IOException - */ - public String decrypt(String encrypted, boolean anytext) throws IOException; - - public static final Access NULL = new Access() { - public void log(Level level, Object... elements) { - } - - @Override - public void printf(Level level, String fmt, Object... elements) { - } - - public void log(Exception e, Object... elements) { - } - - public ClassLoader classLoader() { - return ClassLoader.getSystemClassLoader(); - } - - public String getProperty(String string, String def) { - return null; - } - - public void load(InputStream is) throws IOException { - } - - public void setLogLevel(Level level) { - } - - public String decrypt(String encrypted, boolean anytext) throws IOException { - return encrypted; - } - - @Override - public boolean willLog(Level level) { - return false; - } - - @Override - public Properties getProperties() { - return new Properties(); - } - }; + // levels to use + public enum Level { + DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),TRACE(0x10000),NONE(0XFFFF); + private final int bit; + + Level(int ord) { + bit = ord; + } + + public boolean inMask(int mask) { + return (mask & bit) == bit; + } + + public int addToMask(int mask) { + return mask | bit; + } + + public int delFromMask(int mask) { + return mask & ~bit; + } + + public int toggle(int mask) { + if(inMask(mask)) { + return delFromMask(mask); + } else { + return addToMask(mask); + } + } + + + public int maskOf() { + int mask=0; + for(Level l : values()) { + if(ordinal()<=l.ordinal() && l!=NONE) { + mask|=l.bit; + } + } + return mask; + } + } + + /** + * Write a variable list of Object's text via the toString() method with appropriate space, etc. + * @param elements + */ + public void log(Level level, Object ... elements); + + /** + * Printf mechanism for Access + * @param level + * @param fmt + * @param elements + */ + public void printf(Level level, String fmt, Object ... elements); + + /** + * Check if message will log before constructing + * @param level + * @return + */ + public boolean willLog(Level level); + + /** + * Write the contents of an exception, followed by a variable list of Object's text via the + * toString() method with appropriate space, etc. + * + * The Loglevel is always "ERROR" + * + * @param elements + */ + public void log(Exception e, Object ... elements); + + /** + * Set the Level to compare logging too + */ + public void setLogLevel(Level level); + + /** + * It is important in some cases to create a class from within the same Classloader that created + * Security Objects. Specifically, it's pretty typical for Web Containers to separate classloaders + * so as to allow Apps with different dependencies. + * @return + */ + public ClassLoader classLoader(); + + public String getProperty(String string, String def); + + public Properties getProperties(); + + public void load(InputStream is) throws IOException; + + /** + * if "anytext" is true, then decryption will always be attempted. Otherwise, only if starts with + * Symm.ENC + * @param encrypted + * @param anytext + * @return + * @throws IOException + */ + public String decrypt(String encrypted, boolean anytext) throws IOException; + + public static final Access NULL = new Access() { + public void log(Level level, Object... elements) { + } + + @Override + public void printf(Level level, String fmt, Object... elements) { + } + + public void log(Exception e, Object... elements) { + } + + public ClassLoader classLoader() { + return ClassLoader.getSystemClassLoader(); + } + + public String getProperty(String string, String def) { + return null; + } + + public void load(InputStream is) throws IOException { + } + + public void setLogLevel(Level level) { + } + + public String decrypt(String encrypted, boolean anytext) throws IOException { + return encrypted; + } + + @Override + public boolean willLog(Level level) { + return false; + } + + @Override + public Properties getProperties() { + return new Properties(); + } + }; }