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.aaf.v2_0;
\r
26 import java.io.IOException;
\r
27 import java.net.HttpURLConnection;
\r
28 import java.net.URI;
\r
29 import java.security.GeneralSecurityException;
\r
30 import java.security.Principal;
\r
32 import com.att.cadi.Access;
\r
33 import com.att.cadi.CadiException;
\r
34 import com.att.cadi.Locator;
\r
35 import com.att.cadi.LocatorException;
\r
36 import com.att.cadi.SecuritySetter;
\r
37 import com.att.cadi.client.AbsTransferSS;
\r
38 import com.att.cadi.client.Rcli;
\r
39 import com.att.cadi.client.Retryable;
\r
40 import com.att.cadi.config.Config;
\r
41 import com.att.cadi.config.SecurityInfo;
\r
42 import com.att.cadi.http.HBasicAuthSS;
\r
43 import com.att.cadi.http.HMangr;
\r
44 import com.att.cadi.http.HRcli;
\r
45 import com.att.cadi.http.HTransferSS;
\r
46 import com.att.cadi.http.HX509SS;
\r
47 import com.att.cadi.principal.BasicPrincipal;
\r
48 import com.att.inno.env.APIException;
\r
50 public class AAFConHttp extends AAFCon<HttpURLConnection> {
\r
51 private final HMangr hman;
\r
53 public AAFConHttp(Access access) throws CadiException, GeneralSecurityException, IOException {
\r
54 super(access,Config.AAF_URL,new SecurityInfo<HttpURLConnection>(access));
\r
55 hman = new HMangr(access,Config.loadLocator(access, access.getProperty(Config.AAF_URL,null)));
\r
58 public AAFConHttp(Access access, String tag) throws CadiException, GeneralSecurityException, IOException {
\r
59 super(access,tag,new SecurityInfo<HttpURLConnection>(access));
\r
60 hman = new HMangr(access,Config.loadLocator(access, access.getProperty(tag,null)));
\r
63 public AAFConHttp(Access access, String urlTag, SecurityInfo<HttpURLConnection> si) throws CadiException {
\r
64 super(access,urlTag,si);
\r
65 hman = new HMangr(access,Config.loadLocator(access, access.getProperty(urlTag,null)));
\r
68 public AAFConHttp(Access access, Locator locator) throws CadiException, GeneralSecurityException, IOException {
\r
69 super(access,Config.AAF_URL,new SecurityInfo<HttpURLConnection>(access));
\r
70 hman = new HMangr(access,locator);
\r
73 public AAFConHttp(Access access, Locator locator, SecurityInfo<HttpURLConnection> si) throws CadiException {
\r
74 super(access,Config.AAF_URL,si);
\r
75 hman = new HMangr(access,locator);
\r
78 public AAFConHttp(Access access, Locator locator, SecurityInfo<HttpURLConnection> si, String tag) throws CadiException {
\r
79 super(access,tag,si);
\r
80 hman = new HMangr(access, locator);
\r
84 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuth(java.lang.String, java.lang.String)
\r
87 public SecuritySetter<HttpURLConnection> basicAuth(String user, String password) throws CadiException {
\r
88 if(password.startsWith("enc:???")) {
\r
90 password = access.decrypt(password, true);
\r
91 } catch (IOException e) {
\r
92 throw new CadiException("Error decrypting password",e);
\r
96 return set(new HBasicAuthSS(user,password,si));
\r
97 } catch (IOException e) {
\r
98 throw new CadiException("Error creating HBasicAuthSS",e);
\r
102 public SecuritySetter<HttpURLConnection> x509Alias(String alias) throws APIException, CadiException {
\r
104 return set(new HX509SS(alias,si));
\r
105 } catch (Exception e) {
\r
106 throw new CadiException("Error creating X509SS",e);
\r
111 * @see com.att.cadi.aaf.v2_0.AAFCon#rclient(java.net.URI, com.att.cadi.SecuritySetter)
\r
114 protected Rcli<HttpURLConnection> rclient(URI ignoredURI, SecuritySetter<HttpURLConnection> ss) throws CadiException {
\r
116 return new HRcli(hman, hman.loc.best() ,ss);
\r
117 } catch (Exception e) {
\r
118 throw new CadiException(e);
\r
123 public AbsTransferSS<HttpURLConnection> transferSS(Principal principal) throws CadiException {
\r
124 return new HTransferSS(principal, app,si);
\r
128 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuthSS(java.security.Principal)
\r
131 public SecuritySetter<HttpURLConnection> basicAuthSS(BasicPrincipal principal) throws CadiException {
\r
133 return new HBasicAuthSS(principal,si);
\r
134 } catch (IOException e) {
\r
135 throw new CadiException("Error creating HBasicAuthSS",e);
\r
139 public HMangr hman() {
\r
144 public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
\r
145 return hman.best(ss, (Retryable<RET>)retryable);
\r