1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.aaf.v2_0;
\r
25 import java.io.IOException;
\r
26 import java.net.HttpURLConnection;
\r
27 import java.net.URI;
\r
28 import java.security.GeneralSecurityException;
\r
29 import java.security.Principal;
\r
31 import org.onap.aaf.cadi.CadiException;
\r
32 import org.onap.aaf.cadi.Locator;
\r
33 import org.onap.aaf.cadi.LocatorException;
\r
34 import org.onap.aaf.cadi.PropAccess;
\r
35 import org.onap.aaf.cadi.SecuritySetter;
\r
36 import org.onap.aaf.cadi.Locator.Item;
\r
37 import org.onap.aaf.cadi.client.AbsTransferSS;
\r
38 import org.onap.aaf.cadi.client.Rcli;
\r
39 import org.onap.aaf.cadi.client.Retryable;
\r
40 import org.onap.aaf.cadi.config.Config;
\r
41 import org.onap.aaf.cadi.config.SecurityInfoC;
\r
42 import org.onap.aaf.cadi.http.HBasicAuthSS;
\r
43 import org.onap.aaf.cadi.http.HMangr;
\r
44 import org.onap.aaf.cadi.http.HRcli;
\r
45 import org.onap.aaf.cadi.http.HTransferSS;
\r
46 import org.onap.aaf.cadi.http.HX509SS;
\r
47 import org.onap.aaf.cadi.principal.BasicPrincipal;
\r
49 import org.onap.aaf.inno.env.APIException;
\r
51 public class AAFConHttp extends AAFCon<HttpURLConnection> {
\r
52 private final HMangr hman;
\r
54 public AAFConHttp(PropAccess access) throws CadiException, GeneralSecurityException, IOException {
\r
55 super(access,Config.AAF_URL,new SecurityInfoC<HttpURLConnection>(access));
\r
56 hman = new HMangr(access,Config.loadLocator(access, access.getProperty(Config.AAF_URL,null)));
\r
59 public AAFConHttp(PropAccess access, String tag) throws CadiException, GeneralSecurityException, IOException {
\r
60 super(access,tag,new SecurityInfoC<HttpURLConnection>(access));
\r
61 hman = new HMangr(access,Config.loadLocator(access, access.getProperty(tag,null)));
\r
64 public AAFConHttp(PropAccess access, String urlTag, SecurityInfoC<HttpURLConnection> si) throws CadiException {
\r
65 super(access,urlTag,si);
\r
66 hman = new HMangr(access,Config.loadLocator(access, access.getProperty(urlTag,null)));
\r
69 public AAFConHttp(PropAccess access, Locator<URI> locator) throws CadiException, GeneralSecurityException, IOException {
\r
70 super(access,Config.AAF_URL,new SecurityInfoC<HttpURLConnection>(access));
\r
71 hman = new HMangr(access,locator);
\r
74 public AAFConHttp(PropAccess access, Locator<URI> locator, SecurityInfoC<HttpURLConnection> si) throws CadiException {
\r
75 super(access,Config.AAF_URL,si);
\r
76 hman = new HMangr(access,locator);
\r
79 public AAFConHttp(PropAccess access, Locator<URI> locator, SecurityInfoC<HttpURLConnection> si, String tag) throws CadiException {
\r
80 super(access,tag,si);
\r
81 hman = new HMangr(access, locator);
\r
84 private AAFConHttp(AAFCon<HttpURLConnection> aafcon, String url) {
\r
86 hman = new HMangr(aafcon.access,Config.loadLocator(access, url));
\r
90 public AAFCon<HttpURLConnection> clone(String url) {
\r
91 return new AAFConHttp(this,url);
\r
95 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuth(java.lang.String, java.lang.String)
\r
98 public SecuritySetter<HttpURLConnection> basicAuth(String user, String password) throws CadiException {
\r
99 if(password.startsWith("enc:???")) {
\r
101 password = access.decrypt(password, true);
\r
102 } catch (IOException e) {
\r
103 throw new CadiException("Error decrypting password",e);
\r
107 return new HBasicAuthSS(user,password,si);
\r
108 } catch (IOException e) {
\r
109 throw new CadiException("Error creating HBasicAuthSS",e);
\r
113 public SecuritySetter<HttpURLConnection> x509Alias(String alias) throws APIException, CadiException {
\r
115 return set(new HX509SS(alias,si));
\r
116 } catch (Exception e) {
\r
117 throw new CadiException("Error creating X509SS",e);
\r
122 * @see com.att.cadi.aaf.v2_0.AAFCon#rclient(java.net.URI, com.att.cadi.SecuritySetter)
\r
125 protected Rcli<HttpURLConnection> rclient(URI ignoredURI, SecuritySetter<HttpURLConnection> ss) throws CadiException {
\r
126 if(hman.loc==null) {
\r
127 throw new CadiException("No Locator set in AAFConHttp");
\r
130 return new HRcli(hman, hman.loc.best() ,ss);
\r
131 } catch (Exception e) {
\r
132 throw new CadiException(e);
\r
137 public AbsTransferSS<HttpURLConnection> transferSS(Principal principal) throws CadiException {
\r
138 return new HTransferSS(principal, app,si);
\r
142 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuthSS(java.security.Principal)
\r
145 public SecuritySetter<HttpURLConnection> basicAuthSS(BasicPrincipal principal) throws CadiException {
\r
147 return new HBasicAuthSS(principal,si);
\r
148 } catch (IOException e) {
\r
149 throw new CadiException("Error creating HBasicAuthSS",e);
\r
153 public HMangr hman() {
\r
158 public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
\r
159 return hman.best(ss, (Retryable<RET>)retryable);
\r
163 * @see com.att.cadi.aaf.v2_0.AAFCon#initURI()
\r
166 protected URI initURI() {
\r
168 Item item = hman.loc.best();
\r
170 return hman.loc.get(item);
\r
172 } catch (LocatorException e) {
\r
173 access.log(e, "Error in AAFConHttp obtaining initial URI");
\r
179 * @see com.att.cadi.aaf.v2_0.AAFCon#setInitURI(java.lang.String)
\r
182 protected void setInitURI(String uriString) throws CadiException {
\r
183 // TODO Auto-generated method stub
\r