1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.lur.aaf.test;
\r
25 import java.io.FileInputStream;
\r
26 import java.io.IOException;
\r
27 import java.io.InputStream;
\r
28 import java.io.PrintStream;
\r
30 import org.onap.aaf.cadi.Access;
\r
31 import org.onap.aaf.cadi.Symm;
\r
32 import org.onap.aaf.cadi.config.Config;
\r
34 public class TestAccess implements Access {
\r
36 private PrintStream out;
\r
38 public TestAccess(PrintStream out) {
\r
40 InputStream is = ClassLoader.getSystemResourceAsStream("cadi.properties");
\r
42 System.getProperties().load(is);
\r
43 } catch (IOException e) {
\r
44 e.printStackTrace(out);
\r
48 } catch (IOException e) {
\r
49 e.printStackTrace(out);
\r
53 String keyfile = System.getProperty(Config.CADI_KEYFILE);
\r
55 System.err.println("No " + Config.CADI_KEYFILE + " in Classpath");
\r
58 is = new FileInputStream(keyfile);
\r
60 symm = Symm.obtain(is);
\r
64 } catch (IOException e) {
\r
65 e.printStackTrace(out);
\r
73 public void log(Level level, Object... elements) {
\r
74 boolean first = true;
\r
75 for(int i=0;i<elements.length;++i) {
\r
76 if(first)first = false;
\r
77 else out.print(' ');
\r
78 out.print(elements[i].toString());
\r
83 public void log(Exception e, Object... elements) {
\r
84 e.printStackTrace(out);
\r
85 log(Level.ERROR,elements);
\r
88 public void setLogLevel(Level level) {
\r
93 public boolean willLog(Level level) {
\r
97 public ClassLoader classLoader() {
\r
98 return ClassLoader.getSystemClassLoader();
\r
101 public String getProperty(String string, String def) {
\r
102 String rv = System.getProperty(string);
\r
103 return rv==null?def:rv;
\r
106 public void load(InputStream is) throws IOException {
\r
110 public String decrypt(String encrypted, boolean anytext) throws IOException {
\r
111 return (encrypted!=null && (anytext==true || encrypted.startsWith(Symm.ENC)))
\r
112 ? symm.depass(encrypted)
\r
117 public void printf(Level level, String fmt, Object... elements) {
\r
118 // TODO Auto-generated method stub
\r