1 /*******************************************************************************
2 * ============LICENSE_START====================================================
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
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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.cadi.lur.aaf.test;
26 import java.io.BufferedReader;
27 import java.io.ByteArrayOutputStream;
29 import java.io.FileReader;
30 import java.io.PrintStream;
31 import java.io.PrintWriter;
32 import java.io.StringWriter;
33 import java.lang.reflect.Field;
34 import java.net.HttpURLConnection;
35 import java.security.Principal;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Properties;
41 import org.onap.aaf.cadi.Permission;
42 import org.onap.aaf.cadi.PropAccess;
43 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
44 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
45 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
46 import org.onap.aaf.cadi.aaf.v2_0.AAFTaf;
47 import org.onap.aaf.cadi.config.Config;
48 import org.onap.aaf.cadi.config.SecurityInfoC;
49 import org.onap.aaf.cadi.locator.DNSLocator;
50 import org.onap.aaf.cadi.principal.CachedBasicPrincipal;
52 import junit.framework.Assert;
54 public class JU_JMeter {
55 private static AAFConHttp aaf;
56 private static AAFAuthn<HttpURLConnection> aafAuthn;
57 private static AAFLurPerm aafLur;
58 private static ArrayList<Principal> perfIDs;
60 private static AAFTaf<HttpURLConnection> aafTaf;
61 private static PropAccess access;
63 private static ByteArrayOutputStream outStream;
64 private static ByteArrayOutputStream errStream;
67 public static void before() throws Exception {
68 outStream = new ByteArrayOutputStream();
69 errStream = new ByteArrayOutputStream();
71 System.setOut(new PrintStream(outStream));
72 System.setErr(new PrintStream(errStream));
75 Properties props = System.getProperties();
76 props.setProperty("AFT_LATITUDE", "32.780140");
77 props.setProperty("AFT_LONGITUDE", "-96.800451");
78 props.setProperty("DME2_EP_REGISTRY_CLASS","DME2FS");
79 props.setProperty("AFT_DME2_EP_REGISTRY_FS_DIR","/Volumes/Data/src/authz/dme2reg");
80 props.setProperty("AFT_ENVIRONMENT", "AFTUAT");
81 props.setProperty("SCLD_PLATFORM", "NON-PROD");
82 props.setProperty(Config.AAF_URL,"https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
83 props.setProperty(Config.AAF_CALL_TIMEOUT, "2000");
84 int timeToLive = 3000;
85 props.setProperty(Config.AAF_CLEAN_INTERVAL, Integer.toString(timeToLive));
86 props.setProperty(Config.AAF_HIGH_COUNT, "4");
88 String aafPerfIDs = props.getProperty("AAF_PERF_IDS");
89 perfIDs = new ArrayList<Principal>();
91 if(aafPerfIDs!=null) {
92 perfFile = new File(aafPerfIDs);
95 access = new PropAccess();
96 aaf = new AAFConHttp(access, new DNSLocator(access,"https","localhost","8100"));
97 aafTaf = new AAFTaf<HttpURLConnection>(aaf,false);
98 aafLur = aaf.newLur(aafTaf);
99 aafAuthn = aaf.newAuthn(aafTaf);
100 aaf.basicAuth("testid@aaf.att.com", "whatever");
102 if(perfFile==null||!perfFile.exists()) {
103 perfIDs.add(new CachedBasicPrincipal(aafTaf,
104 "Basic dGVzdGlkOndoYXRldmVy",
105 "aaf.att.com",timeToLive));
106 perfIDs.add(new Princ("ab1234@aaf.att.com")); // Example of Local ID, which isn't looked up
108 BufferedReader ir = new BufferedReader(new FileReader(perfFile));
111 while((line = ir.readLine())!=null) {
112 if((line=line.trim()).length()>0)
113 perfIDs.add(new Princ(line));
119 Assert.assertNotNull(aafLur);
124 public void setup() {
125 outStream = new ByteArrayOutputStream();
126 errStream = new ByteArrayOutputStream();
128 System.setOut(new PrintStream(outStream));
129 System.setErr(new PrintStream(errStream));
133 public void tearDown() {
134 System.setOut(System.out);
135 System.setErr(System.err);
138 private static class Princ implements Principal {
140 public Princ(String name) {
143 public String getName() {
150 public static void tearDownAfterClass() throws Exception {
151 Field field = SecurityInfoC.class.getDeclaredField("sicMap");
152 field.setAccessible(true);
153 field.set(null, new HashMap<Class<?>,SecurityInfoC<?>>());
156 private static int index = -1;
158 private synchronized Principal getIndex() {
159 if(perfIDs.size()<=++index)index=0;
160 return perfIDs.get(index);
165 aafAuthn.validate("testid@aaf.att.com", "whatever");
166 List<Permission> perms = new ArrayList<Permission>();
167 aafLur.fishAll(getIndex(), perms);
168 // Assert.assertFalse(perms.isEmpty());
169 // for(Permission p : perms) {
170 // //access.log(Access.Level.AUDIT, p.permType());
172 } catch (Exception e) {
173 StringWriter sw = new StringWriter();
174 e.printStackTrace(new PrintWriter(sw));
175 Assert.fail(sw.toString());