1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.cadi.client;
\r
26 import java.io.IOException;
\r
27 import java.io.InputStream;
\r
28 import java.util.Map.Entry;
\r
29 import java.util.Properties;
\r
31 import com.att.cadi.Access;
\r
32 import com.att.cadi.Symm;
\r
33 import com.att.inno.env.Decryptor;
\r
34 import com.att.inno.env.Env;
\r
35 import com.att.inno.env.impl.BasicEnv;
\r
37 public class EnvAccess implements Access {
\r
41 * String Property tag for files/resources that may contain properties. Can be null.
\r
42 * Resources of ClassLoader will be checked first, if exist. Can be null.
\r
46 * @throws IOException
\r
48 public EnvAccess(BasicEnv env, ClassLoader cl) throws IOException {
\r
50 final Symm s = Symm.obtain(this);
\r
51 env.set(new Decryptor() {
\r
52 private Symm symm = s;
\r
54 public String decrypt(String encrypted) {
\r
56 return (encrypted!=null && (encrypted.startsWith(Symm.ENC)))
\r
57 ? symm.depass(encrypted)
\r
59 } catch (IOException e) {
\r
69 * Construct with the Classloader of Env and CADI_PROP_FILES, if possible
\r
72 * @throws IOException
\r
74 public EnvAccess(BasicEnv env) throws IOException {
\r
75 this(env, env.getClass().getClassLoader());
\r
79 public void log(Level level, Object... elements) {
\r
82 env.audit().log(elements);
\r
85 env.debug().log(elements);
\r
88 env.error().log(elements);
\r
91 env.info().log(elements);
\r
94 env.init().log(elements);
\r
97 env.warn().log(elements);
\r
106 public void log(Exception e, Object... elements) {
\r
107 env.error().log(e,elements);
\r
111 public void printf(Level level, String fmt, Object... elements) {
\r
112 if(willLog(level)) {
\r
113 log(level,String.format(fmt, elements));
\r
119 public boolean willLog(Level level) {
\r
122 return env.audit().isLoggable();
\r
124 return env.debug().isLoggable();
\r
126 return env.error().isLoggable();
\r
128 return env.info().isLoggable();
\r
130 return env.init().isLoggable();
\r
132 return env.warn().isLoggable();
\r
140 public void setLogLevel(Level level) {
\r
145 public ClassLoader classLoader() {
\r
146 return env.getClass().getClassLoader();
\r
150 public String getProperty(String string, String def) {
\r
151 return env.getProperty(string, def);
\r
155 public void load(InputStream is) throws IOException {
\r
156 Properties props = new Properties();
\r
158 for(Entry<Object, Object> es :props.entrySet()) {
\r
159 env.setProperty(es.getKey().toString(), es.getValue().toString());
\r
164 public String decrypt(String encrypted, boolean anytext) throws IOException {
\r
165 return env.decryptor().decrypt(encrypted);
\r