AT&T 2.0.19 Code drop, stage 2
[aaf/authz.git] / cadi / client / src / test / java / org / onap / aaf / client / test / JU_TestAccess.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
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====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.client.test;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Properties;
27
28 import org.onap.aaf.cadi.Access;
29 import org.onap.aaf.cadi.CadiException;
30 import org.onap.aaf.cadi.Symm;
31
32 // TODO: Ian [JUnit] JU_TestAccess isn't implementing all abstract methdods of Access
33 public class JU_TestAccess implements Access {
34         private Symm symm;
35
36         public JU_TestAccess() throws CadiException {
37                 symm = Symm.obtain(this);
38         }
39         
40         public void log(Level level, Object... elements) {
41                 boolean first = true;
42                 for(int i=0;i<elements.length;++i) {
43                         if(first)first = false;
44                         else System.out.print(' ');
45                         System.out.print(elements[i].toString());
46                 }
47                 System.out.println();
48         }
49
50         public void log(Exception e, Object... elements) {
51                 e.printStackTrace();
52                 log(Level.ERROR,elements);
53         }
54
55         @Override
56         public void printf(Level level, String fmt, Object... elements) {
57                 if(willLog(level)) {
58                         System.out.printf(fmt, elements);
59                 }
60         }
61
62         public void setLogLevel(Level level) {
63                 
64         }
65
66         public ClassLoader classLoader() {
67                 return ClassLoader.getSystemClassLoader();
68         }
69
70         public String getProperty(String string, String def) {
71                 String rv = System.getProperty(string);
72                 return rv==null?def:rv;
73         }
74
75         public void load(InputStream is) throws IOException {
76                 
77         }
78
79         public String decrypt(String encrypted, boolean anytext) throws IOException {
80                 return (encrypted!=null && (anytext==true || encrypted.startsWith(Symm.ENC)))
81                         ? symm.depass(encrypted)
82                         : encrypted;
83         }
84
85         /* (non-Javadoc)
86          * @see org.onap.aaf.cadi.Access#willLog(org.onap.aaf.cadi.Access.Level)
87          */
88         @Override
89         public boolean willLog(Level level) {
90                 return true;
91         }
92
93         @Override
94         public Properties getProperties() {
95                 return System.getProperties();
96         }
97
98 }