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;
24 import java.io.BufferedReader;
26 import java.io.FileReader;
27 import java.io.PrintWriter;
28 import java.io.StringWriter;
29 import java.net.HttpURLConnection;
30 import java.security.Principal;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Properties;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.onap.aaf.cadi.Permission;
38 import org.onap.aaf.cadi.PropAccess;
39 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
40 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
41 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
42 import org.onap.aaf.cadi.aaf.v2_0.AAFTaf;
43 import org.onap.aaf.cadi.config.Config;
44 import org.onap.aaf.cadi.locator.DNSLocator;
45 import org.onap.aaf.cadi.principal.CachedBasicPrincipal;
47 import junit.framework.Assert;
49 public class JU_JMeter {
50 private static AAFConHttp aaf;
51 private static AAFAuthn<HttpURLConnection> aafAuthn;
52 private static AAFLurPerm aafLur;
53 private static ArrayList<Principal> perfIDs;
55 private static AAFTaf<HttpURLConnection> aafTaf;
56 private static PropAccess access;
59 public static void before() throws Exception {
61 Properties props = System.getProperties();
62 props.setProperty("AFT_LATITUDE", "32.780140");
63 props.setProperty("AFT_LONGITUDE", "-96.800451");
64 props.setProperty("DME2_EP_REGISTRY_CLASS","DME2FS");
65 props.setProperty("AFT_DME2_EP_REGISTRY_FS_DIR","/Volumes/Data/src/authz/dme2reg");
66 props.setProperty("AFT_ENVIRONMENT", "AFTUAT");
67 props.setProperty("SCLD_PLATFORM", "NON-PROD");
68 props.setProperty(Config.AAF_URL,"https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
69 props.setProperty(Config.AAF_CALL_TIMEOUT, "2000");
70 int timeToLive = 3000;
71 props.setProperty(Config.AAF_CLEAN_INTERVAL, Integer.toString(timeToLive));
72 props.setProperty(Config.AAF_HIGH_COUNT, "4");
74 String aafPerfIDs = props.getProperty("AAF_PERF_IDS");
75 perfIDs = new ArrayList<Principal>();
77 if(aafPerfIDs!=null) {
78 perfFile = new File(aafPerfIDs);
81 access = new PropAccess();
82 aaf = new AAFConHttp(access, new DNSLocator(access,"https","localhost","8100"));
83 aafTaf = new AAFTaf<HttpURLConnection>(aaf,false);
84 aafLur = aaf.newLur(aafTaf);
85 aafAuthn = aaf.newAuthn(aafTaf);
86 aaf.basicAuth("testid@aaf.att.com", "whatever");
88 if(perfFile==null||!perfFile.exists()) {
89 perfIDs.add(new CachedBasicPrincipal(aafTaf,
90 "Basic dGVzdGlkOndoYXRldmVy",
91 "aaf.att.com",timeToLive));
92 perfIDs.add(new Princ("ab1234@aaf.att.com")); // Example of Local ID, which isn't looked up
94 BufferedReader ir = new BufferedReader(new FileReader(perfFile));
97 while((line = ir.readLine())!=null) {
98 if((line=line.trim()).length()>0)
99 perfIDs.add(new Princ(line));
105 Assert.assertNotNull(aafLur);
109 private static class Princ implements Principal {
111 public Princ(String name) {
114 public String getName() {
120 private static int index = -1;
122 private synchronized Principal getIndex() {
123 if(perfIDs.size()<=++index)index=0;
124 return perfIDs.get(index);
129 aafAuthn.validate("testid@aaf.att.com", "whatever");
130 List<Permission> perms = new ArrayList<Permission>();
131 aafLur.fishAll(getIndex(), perms);
132 // Assert.assertFalse(perms.isEmpty());
133 // for(Permission p : perms) {
134 // //access.log(Access.Level.AUDIT, p.permType());
136 } catch (Exception e) {
137 StringWriter sw = new StringWriter();
138 e.printStackTrace(new PrintWriter(sw));
139 Assert.assertFalse(sw.toString(),true);