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.dao.aaf.test;
\r
26 import java.io.File;
\r
27 import java.io.FileInputStream;
\r
28 import java.io.IOException;
\r
29 import java.io.InputStream;
\r
30 import java.net.URL;
\r
31 import java.security.NoSuchAlgorithmException;
\r
32 import java.util.Properties;
\r
34 import org.junit.After;
\r
35 import org.junit.AfterClass;
\r
36 import org.junit.Before;
\r
37 import org.junit.BeforeClass;
\r
39 import com.att.authz.env.AuthzEnv;
\r
40 import com.att.authz.env.AuthzTrans;
\r
41 import com.att.cadi.Hash;
\r
42 import com.att.cadi.Symm;
\r
43 import com.att.dao.CassAccess;
\r
44 import com.att.dao.CassDAOImpl;
\r
45 import com.att.inno.env.APIException;
\r
46 import com.att.inno.env.Env;
\r
47 import com.att.inno.env.Trans.Metric;
\r
48 import com.datastax.driver.core.Cluster;
\r
50 import junit.framework.Assert;
\r
53 * Do Setup of Cassandra for Cassandra JUnit Testing
\r
57 public class AbsJUCass {
\r
58 protected static final String AUTHZ = "authz";
\r
59 protected static Cluster cluster;
\r
60 protected static AuthzEnv env;
\r
61 protected static int iterations = 0;
\r
62 protected static float totals=0.0f;
\r
63 protected static float remote = 0.0f;
\r
64 protected static float json = 0.0f;
\r
65 protected static AuthzTrans trans;
\r
66 protected static boolean details = true;
\r
69 public static void startup() throws APIException, IOException {
\r
70 synchronized(AUTHZ) {
\r
72 final String resource = "cadi.properties";
\r
73 File f = new File("etc" + resource);
\r
74 InputStream is=null;
\r
75 Properties props = new Properties();
\r
78 is = new FileInputStream(f);
\r
80 URL rsrc = ClassLoader.getSystemResource(resource);
\r
81 is = rsrc.openStream();
\r
86 env= new AuthzEnv();
\r
87 Assert.fail(resource + " must exist in etc dir, or in Classpath");
\r
91 env = new AuthzEnv(props);
\r
94 cluster = CassAccess.cluster(env,"LOCAL");
\r
96 env.info().log("Connecting to Cluster");
\r
98 cluster.connect(AUTHZ);
\r
99 } catch(Exception e) {
\r
101 env.error().log(e);
\r
102 Assert.fail("Not able to connect to DB: " + e.getLocalizedMessage());
\r
104 env.info().log("Connected");
\r
106 // Load special data here
\r
109 env.setProperty("java.naming.provider.url","ldap://ldap.webphone.att.com:389");
\r
110 env.setProperty("com.sun.jndi.ldap.connect.pool","true");
\r
117 public static void shutdown() {
\r
118 if(cluster!=null) {
\r
125 public void newTrans() {
\r
126 trans = env.newTrans();
\r
128 trans.setProperty(CassDAOImpl.USER_NAME, System.getProperty("user.name"));
\r
132 public void auditTrail() {
\r
133 if(totals==0) { // "updateTotals()" was not called... just do one Trans
\r
134 StringBuilder sb = new StringBuilder();
\r
135 Metric metric = trans.auditTrail(4, sb, Env.JSON, Env.REMOTE);
\r
140 totals += metric.total,
\r
147 totals += metric.total;
\r
152 protected void updateTotals() {
\r
153 Metric metric = trans.auditTrail(0, null, Env.JSON, Env.REMOTE);
\r
154 totals+=metric.total;
\r
155 json +=metric.buckets[0];
\r
156 remote+=metric.buckets[1];
\r
161 public static void print() {
\r
163 if(iterations==0) {
\r
166 transTime=totals/iterations;
\r
177 "Transaction time:",
\r
183 * Take a User/Pass and turn into an MD5 Hashed BasicAuth
\r
188 * @throws IOException
\r
189 * @throws NoSuchAlgorithmException
\r
191 public static byte[] userPassToBytes(String user, String pass)
\r
192 throws IOException, NoSuchAlgorithmException {
\r
193 // Take the form of BasicAuth, so as to allow any character in Password
\r
194 // (this is an issue in 1.0)
\r
195 // Also, it makes it quicker to evaluate Basic Auth direct questions
\r
196 String ba = Symm.base64url.encode(user + ':' + pass);
\r
197 // Take MD5 Hash, so that data in DB can't be reversed out.
\r
198 return Hash.encryptMD5(ba.getBytes());
\r