1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.cadi.lur.aaf.test;
\r
26 import java.io.BufferedReader;
\r
27 import java.io.File;
\r
28 import java.io.FileReader;
\r
29 import java.io.PrintWriter;
\r
30 import java.io.StringWriter;
\r
31 import java.net.HttpURLConnection;
\r
32 import java.security.Principal;
\r
33 import java.util.ArrayList;
\r
34 import java.util.List;
\r
35 import java.util.Properties;
\r
37 import org.junit.BeforeClass;
\r
38 import org.junit.Test;
\r
40 import com.att.cadi.Permission;
\r
41 import com.att.cadi.PropAccess;
\r
42 import com.att.cadi.aaf.v2_0.AAFAuthn;
\r
43 import com.att.cadi.aaf.v2_0.AAFConHttp;
\r
44 import com.att.cadi.aaf.v2_0.AAFLurPerm;
\r
45 import com.att.cadi.aaf.v2_0.AAFTaf;
\r
46 import com.att.cadi.config.Config;
\r
47 import com.att.cadi.locator.DNSLocator;
\r
48 import com.att.cadi.principal.CachedBasicPrincipal;
\r
50 import junit.framework.Assert;
\r
52 public class JU_JMeter {
\r
53 private static AAFConHttp aaf;
\r
54 private static AAFAuthn<HttpURLConnection> aafAuthn;
\r
55 private static AAFLurPerm aafLur;
\r
56 private static ArrayList<Principal> perfIDs;
\r
58 private static AAFTaf<HttpURLConnection> aafTaf;
\r
59 private static PropAccess access;
\r
62 public static void before() throws Exception {
\r
64 Properties props = System.getProperties();
\r
65 props.setProperty("AFT_LATITUDE", "32.780140");
\r
66 props.setProperty("AFT_LONGITUDE", "-96.800451");
\r
67 props.setProperty("DME2_EP_REGISTRY_CLASS","DME2FS");
\r
68 props.setProperty("AFT_DME2_EP_REGISTRY_FS_DIR","/Volumes/Data/src/authz/dme2reg");
\r
69 props.setProperty("AFT_ENVIRONMENT", "AFTUAT");
\r
70 props.setProperty("SCLD_PLATFORM", "NON-PROD");
\r
71 props.setProperty(Config.AAF_URL,"https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
\r
72 props.setProperty(Config.AAF_READ_TIMEOUT, "2000");
\r
73 int timeToLive = 3000;
\r
74 props.setProperty(Config.AAF_CLEAN_INTERVAL, Integer.toString(timeToLive));
\r
75 props.setProperty(Config.AAF_HIGH_COUNT, "4");
\r
77 String aafPerfIDs = props.getProperty("AAF_PERF_IDS");
\r
78 perfIDs = new ArrayList<Principal>();
\r
79 File perfFile = null;
\r
80 if(aafPerfIDs!=null) {
\r
81 perfFile = new File(aafPerfIDs);
\r
84 access = new PropAccess();
\r
85 aaf = new AAFConHttp(access, new DNSLocator(access,"https","localhost","8100"));
\r
86 aafTaf = new AAFTaf<HttpURLConnection>(aaf,false);
\r
87 aafLur = aaf.newLur(aafTaf);
\r
88 aafAuthn = aaf.newAuthn(aafTaf);
\r
89 aaf.basicAuth("testid@aaf.att.com", "whatever");
\r
91 if(perfFile==null||!perfFile.exists()) {
\r
92 perfIDs.add(new CachedBasicPrincipal(aafTaf,
\r
93 "Basic dGVzdGlkOndoYXRldmVy",
\r
94 "aaf.att.com",timeToLive));
\r
95 perfIDs.add(new Princ("ab1234@aaf.att.com")); // Example of Local ID, which isn't looked up
\r
97 BufferedReader ir = new BufferedReader(new FileReader(perfFile));
\r
100 while((line = ir.readLine())!=null) {
\r
101 if((line=line.trim()).length()>0)
\r
102 perfIDs.add(new Princ(line));
\r
108 Assert.assertNotNull(aafLur);
\r
112 private static class Princ implements Principal {
\r
113 private String name;
\r
114 public Princ(String name) {
\r
117 public String getName() {
\r
123 private static int index = -1;
\r
125 private synchronized Principal getIndex() {
\r
126 if(perfIDs.size()<=++index)index=0;
\r
127 return perfIDs.get(index);
\r
130 public void test() {
\r
132 aafAuthn.validate("testid@aaf.att.com", "whatever");
\r
133 List<Permission> perms = new ArrayList<Permission>();
\r
134 aafLur.fishAll(getIndex(), perms);
\r
135 // Assert.assertFalse(perms.isEmpty());
\r
136 // for(Permission p : perms) {
\r
137 // //access.log(Access.Level.AUDIT, p.permType());
\r
139 } catch (Exception e) {
\r
140 StringWriter sw = new StringWriter();
\r
141 e.printStackTrace(new PrintWriter(sw));
\r
142 Assert.assertFalse(sw.toString(),true);
\r