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.net.HttpURLConnection;
34 import java.security.Principal;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Properties;
39 import org.onap.aaf.cadi.Permission;
40 import org.onap.aaf.cadi.PropAccess;
41 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
42 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
43 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
44 import org.onap.aaf.cadi.aaf.v2_0.AAFTaf;
45 import org.onap.aaf.cadi.config.Config;
46 import org.onap.aaf.cadi.locator.DNSLocator;
47 import org.onap.aaf.cadi.principal.CachedBasicPrincipal;
49 import junit.framework.Assert;
51 public class JU_JMeter {
52 private static AAFConHttp aaf;
53 private static AAFAuthn<HttpURLConnection> aafAuthn;
54 private static AAFLurPerm aafLur;
55 private static ArrayList<Principal> perfIDs;
57 private static AAFTaf<HttpURLConnection> aafTaf;
58 private static PropAccess access;
60 private static ByteArrayOutputStream outStream;
61 private static ByteArrayOutputStream errStream;
64 public static void before() throws Exception {
65 outStream = new ByteArrayOutputStream();
66 errStream = new ByteArrayOutputStream();
68 System.setOut(new PrintStream(outStream));
69 System.setErr(new PrintStream(errStream));
72 Properties props = System.getProperties();
73 props.setProperty("AFT_LATITUDE", "32.780140");
74 props.setProperty("AFT_LONGITUDE", "-96.800451");
75 props.setProperty("DME2_EP_REGISTRY_CLASS","DME2FS");
76 props.setProperty("AFT_DME2_EP_REGISTRY_FS_DIR","/Volumes/Data/src/authz/dme2reg");
77 props.setProperty("AFT_ENVIRONMENT", "AFTUAT");
78 props.setProperty("SCLD_PLATFORM", "NON-PROD");
79 props.setProperty(Config.AAF_URL,"https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
80 props.setProperty(Config.AAF_CALL_TIMEOUT, "2000");
81 int timeToLive = 3000;
82 props.setProperty(Config.AAF_CLEAN_INTERVAL, Integer.toString(timeToLive));
83 props.setProperty(Config.AAF_HIGH_COUNT, "4");
85 String aafPerfIDs = props.getProperty("AAF_PERF_IDS");
86 perfIDs = new ArrayList<Principal>();
88 if(aafPerfIDs!=null) {
89 perfFile = new File(aafPerfIDs);
92 access = new PropAccess();
93 aaf = new AAFConHttp(access, new DNSLocator(access,"https","localhost","8100"));
94 aafTaf = new AAFTaf<HttpURLConnection>(aaf,false);
95 aafLur = aaf.newLur(aafTaf);
96 aafAuthn = aaf.newAuthn(aafTaf);
97 aaf.basicAuth("testid@aaf.att.com", "whatever");
99 if(perfFile==null||!perfFile.exists()) {
100 perfIDs.add(new CachedBasicPrincipal(aafTaf,
101 "Basic dGVzdGlkOndoYXRldmVy",
102 "aaf.att.com",timeToLive));
103 perfIDs.add(new Princ("ab1234@aaf.att.com")); // Example of Local ID, which isn't looked up
105 BufferedReader ir = new BufferedReader(new FileReader(perfFile));
108 while((line = ir.readLine())!=null) {
109 if((line=line.trim()).length()>0)
110 perfIDs.add(new Princ(line));
116 Assert.assertNotNull(aafLur);
121 public void setup() {
122 outStream = new ByteArrayOutputStream();
123 errStream = new ByteArrayOutputStream();
125 System.setOut(new PrintStream(outStream));
126 System.setErr(new PrintStream(errStream));
130 public void tearDown() {
131 System.setOut(System.out);
132 System.setErr(System.err);
135 private static class Princ implements Principal {
137 public Princ(String name) {
140 public String getName() {
146 private static int index = -1;
148 private synchronized Principal getIndex() {
149 if(perfIDs.size()<=++index)index=0;
150 return perfIDs.get(index);
155 aafAuthn.validate("testid@aaf.att.com", "whatever");
156 List<Permission> perms = new ArrayList<Permission>();
157 aafLur.fishAll(getIndex(), perms);
158 // Assert.assertFalse(perms.isEmpty());
159 // for(Permission p : perms) {
160 // //access.log(Access.Level.AUDIT, p.permType());
162 } catch (Exception e) {
163 StringWriter sw = new StringWriter();
164 e.printStackTrace(new PrintWriter(sw));
165 Assert.fail(sw.toString());