2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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====================================================
22 package org.onap.aaf.auth.cm.test;
24 import java.io.InputStream;
25 import java.net.HttpURLConnection;
26 import java.net.InetAddress;
28 import java.security.cert.CertificateException;
30 import javax.security.auth.x500.X500Principal;
32 import org.junit.After;
33 import org.junit.AfterClass;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import static org.junit.Assert.*;
38 import org.onap.aaf.auth.env.AuthzEnv;
39 import org.onap.aaf.cadi.CadiException;
40 import org.onap.aaf.cadi.Locator;
41 import org.onap.aaf.cadi.Locator.Item;
42 import org.onap.aaf.cadi.client.Future;
43 import org.onap.aaf.cadi.client.Rcli;
44 import org.onap.aaf.cadi.client.Retryable;
45 import org.onap.aaf.cadi.config.SecurityInfoC;
46 import org.onap.aaf.cadi.configure.Factory;
47 import org.onap.aaf.cadi.http.HBasicAuthSS;
48 import org.onap.aaf.cadi.http.HMangr;
49 import org.onap.aaf.cadi.locator.DNSLocator;
50 import org.onap.aaf.misc.env.APIException;
51 import org.onap.aaf.misc.env.Data;
52 import org.onap.aaf.misc.env.Data.TYPE;
53 import org.onap.aaf.misc.env.util.Chrono;
54 import org.onap.aaf.misc.rosetta.env.RosettaDF;
56 import certman.v1_0.CertInfo;
57 import certman.v1_0.CertificateRequest;
58 import junit.framework.Assert;
60 public class CertmanTest {
62 private static HMangr hman;
63 private static AuthzEnv env;
64 private static HBasicAuthSS ss;
65 private static RosettaDF<CertificateRequest> reqDF;
66 private static RosettaDF<CertInfo> certDF;
69 public static void setUpBeforeClass() throws Exception {
71 // InputStream ris = env.classLoader().getResource("certman.props").openStream();
78 // Locator<URI> loc = new DNSLocator(env, "https", "aaf.it.att.com", "8150");
79 // for (Item item = loc.first(); item!=null; item=loc.next(item)) {
80 // System.out.println(loc.get(item));
84 // SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(env, HttpURLConnection.class);
85 // ss = new HBasicAuthSS(si,"m12345@aaf.att.com",
86 // env.decrypt("enc:gvptdJyo0iKdVZw2rzMb0woxa7YKMdqLuhfQ4OQfZ8k",false));
87 // env.decrypt("enc:jFfAnO3mOKb9Gzm2OFysslmXpbnyuAxuoNJK",false), si);
88 // SecuritySetter<HttpURLConnection> ss = new X509SS(si, "aaf");
90 // hman = new HMangr(env,loc);
92 // reqDF = env.newDataFactory(CertificateRequest.class);
93 // reqDF.out(TYPE.JSON);
94 // certDF = env.newDataFactory(CertInfo.class);
98 // public static void tearDownAfterClass() throws Exception {
103 public void setUp() throws Exception {
108 public void tearDown() throws Exception {
112 // public void testX500Name() throws Exception {
114 // for ( InetAddress ia : InetAddress.getAllByName("aaf.dev.att.com")) {
115 // System.out.printf("%s - %s\n", ia.getHostName(), ia.getHostAddress());
116 // InetAddress ia1 = InetAddress.getByName(ia.getHostAddress());
117 // System.out.printf("%s - %s\n", ia1.getHostName(), ia1.getHostAddress());
120 // hman.best(ss, new Retryable<Void>() {
122 // public Void code(Rcli<?> client) throws APIException, CadiException {
123 // CertificateRequest cr = new CertificateRequest();
124 // cr.setMechid("a12345@org.osaaf.org");
125 // cr.setSponsor("something");
126 // cr.getFqdns().add("mithrilcsp.sbc.com");
127 // cr.getFqdns().add("zld01907.vci.att.com");
128 // cr.getFqdns().add("aaftest.test.att.com");
130 // String path = "/cert/local"; // Local Test
131 //// String path = "/cert/aaf"; // Official CA
132 // long end=0,start = System.nanoTime();
134 // System.out.println(reqDF.newData().option(Data.PRETTY).load(cr).asString());
135 // Future<String> f = client.updateRespondString(path, reqDF, cr);
136 // if (f.get(10000)) {
137 // end = System.nanoTime();
138 // System.out.println(f.body());
139 // CertInfo capi = certDF.newData().in(Data.TYPE.JSON).load(f.body()).asObject();
140 // for (String c :capi.getCerts()) {
141 // for ( java.security.cert.Certificate x509 : Factory.toX509Certificate(c)) {
142 // System.out.println(x509.toString());
146 // end = System.nanoTime();
147 // String msg = "Client returned " + f.code() + ": " + f.body();
148 // System.out.println(msg);
151 // } catch (CertificateException e) {
152 // throw new CadiException(e);
154 // System.out.println(Chrono.millisFromNanos(start,end) + " ms");
163 // public X500Principal ephemeral() {