2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.cadi;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Properties;
29 * Various Environments require different logging mechanisms, or at least allow
30 * for different ones. We need the Framework to be able to hook into any particular instance of logging
31 * mechanism, whether it be a Logging Object within a Servlet Context, or a direct library like log4j.
32 * This interface, therefore, allows maximum pluggability in a variety of different app styles.
37 public interface Access {
40 DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),TRACE(0x10000),NONE(0XFFFF);
41 private final int bit;
47 public boolean inMask(int mask) {
48 return (mask & bit) == bit;
51 public int addToMask(int mask) {
55 public int delFromMask(int mask) {
59 public int toggle(int mask) {
61 return delFromMask(mask);
63 return addToMask(mask);
70 for (Level l : values()) {
71 if (ordinal()<=l.ordinal() && l!=NONE) {
80 * Write a variable list of Object's text via the toString() method with appropriate space, etc.
83 public void log(Level level, Object ... elements);
86 * Printf mechanism for Access
91 public void printf(Level level, String fmt, Object ... elements);
94 * Check if message will log before constructing
98 public boolean willLog(Level level);
101 * Write the contents of an exception, followed by a variable list of Object's text via the
102 * toString() method with appropriate space, etc.
104 * The Loglevel is always "ERROR"
108 public void log(Exception e, Object ... elements);
111 * Set the Level to compare logging too
113 public void setLogLevel(Level level);
116 * It is important in some cases to create a class from within the same Classloader that created
117 * Security Objects. Specifically, it's pretty typical for Web Containers to separate classloaders
118 * so as to allow Apps with different dependencies.
121 public ClassLoader classLoader();
123 public String getProperty(String string, String def);
125 public Properties getProperties();
127 public void load(InputStream is) throws IOException;
130 * if "anytext" is true, then decryption will always be attempted. Otherwise, only if starts with
135 * @throws IOException
137 public String decrypt(String encrypted, boolean anytext) throws IOException;
139 public static final Access NULL = new Access() {
140 public void log(Level level, Object... elements) {
144 public void printf(Level level, String fmt, Object... elements) {
147 public void log(Exception e, Object... elements) {
150 public ClassLoader classLoader() {
151 return ClassLoader.getSystemClassLoader();
154 public String getProperty(String string, String def) {
158 public void load(InputStream is) throws IOException {
161 public void setLogLevel(Level level) {
164 public String decrypt(String encrypted, boolean anytext) throws IOException {
169 public boolean willLog(Level level) {
174 public Properties getProperties() {
175 return new Properties();