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 com.att.cadi.aaf.v2_0;
\r
25 import java.io.IOException;
\r
26 import java.net.ConnectException;
\r
27 import java.net.URI;
\r
28 import java.net.URISyntaxException;
\r
29 import java.security.GeneralSecurityException;
\r
30 import java.security.Principal;
\r
31 import java.util.Properties;
\r
33 import com.att.aft.dme2.api.DME2Client;
\r
34 import com.att.aft.dme2.api.DME2Exception;
\r
35 import com.att.aft.dme2.api.DME2Manager;
\r
36 import com.att.cadi.CadiException;
\r
37 import com.att.cadi.LocatorException;
\r
38 import com.att.cadi.PropAccess;
\r
39 import com.att.cadi.SecuritySetter;
\r
40 import com.att.cadi.client.Rcli;
\r
41 import com.att.cadi.client.Retryable;
\r
42 import com.att.cadi.config.Config;
\r
43 import com.att.cadi.config.SecurityInfoC;
\r
44 import com.att.cadi.dme2.DME2BasicAuth;
\r
45 import com.att.cadi.dme2.DME2TransferSS;
\r
46 import com.att.cadi.dme2.DME2x509SS;
\r
47 import com.att.cadi.dme2.DRcli;
\r
48 import com.att.cadi.principal.BasicPrincipal;
\r
49 import com.att.inno.env.APIException;
\r
51 public class AAFConDME2 extends AAFCon<DME2Client>{
\r
52 private DME2Manager manager;
\r
53 private boolean isProxy;
\r
54 private URI initURI;
\r
56 public AAFConDME2(PropAccess access) throws CadiException, GeneralSecurityException, IOException{
\r
57 super(access,Config.AAF_URL,new SecurityInfoC<DME2Client> (access));
\r
58 manager = newManager(access);
\r
62 public AAFConDME2(PropAccess access, String url) throws CadiException, GeneralSecurityException, IOException{
\r
63 super(access,url,new SecurityInfoC<DME2Client> (access));
\r
64 manager = newManager(access);
\r
68 public AAFConDME2(PropAccess access, SecurityInfoC<DME2Client> si) throws CadiException {
\r
69 super(access,Config.AAF_URL,si);
\r
70 manager = newManager(access);
\r
74 public AAFConDME2(PropAccess access, String url, SecurityInfoC<DME2Client> si) throws CadiException {
\r
75 super(access,url,si);
\r
76 manager = newManager(access);
\r
81 * Construct a Connector based on the AAF one. This is for remote access to OTHER than AAF,
\r
82 * but using Credentials, etc
\r
84 private AAFConDME2(AAFCon<DME2Client> aafcon, String url) throws CadiException {
\r
87 initURI = new URI(url);
\r
88 } catch (URISyntaxException e) {
\r
89 throw new CadiException(e);
\r
91 manager = newManager(access);
\r
95 * Create a Connector based on the AAF one. This is for remote access to OTHER than AAF,
\r
96 * but using Credentials, etc
\r
98 public AAFCon<DME2Client> clone(String url) throws CadiException {
\r
99 return new AAFConDME2(this,url);
\r
102 private void setIsProxy() {
\r
104 if((str=access.getProperty(Config.AAF_URL, null))!=null) {
\r
105 isProxy = str.contains("service=com.att.authz.authz-gw/version=");
\r
109 private DME2Manager newManager(PropAccess access) throws CadiException {
\r
110 Properties props = access.getDME2Properties();
\r
111 // Critical that TLS Settings not ignored
\r
113 return new DME2Manager("AAFCon",props);
\r
114 } catch (DME2Exception e) {
\r
115 throw new CadiException(e);
\r
121 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuth(java.lang.String, java.lang.String)
\r
124 public SecuritySetter<DME2Client> basicAuth(String user, String password) throws CadiException {
\r
125 if(password.startsWith("enc:???")) {
\r
127 password = access.decrypt(password, true);
\r
128 } catch (IOException e) {
\r
129 throw new CadiException("Error Decrypting Password",e);
\r
134 return set(new DME2BasicAuth(user,password,si));
\r
135 } catch (IOException e) {
\r
136 throw new CadiException("Error setting up DME2BasicAuth",e);
\r
141 * @see com.att.cadi.aaf.v2_0.AAFCon#rclient(java.net.URI, com.att.cadi.SecuritySetter)
\r
144 protected Rcli<DME2Client> rclient(URI uri, SecuritySetter<DME2Client> ss) {
\r
145 DRcli dc = new DRcli(uri, ss);
\r
146 dc.setProxy(isProxy);
\r
147 dc.setManager(manager);
\r
152 public SecuritySetter<DME2Client> transferSS(Principal principal) throws CadiException {
\r
154 return principal==null?ss:new DME2TransferSS(principal, app, si);
\r
155 } catch (IOException e) {
\r
156 throw new CadiException("Error creating DME2TransferSS",e);
\r
161 public SecuritySetter<DME2Client> basicAuthSS(BasicPrincipal principal) throws CadiException {
\r
163 return new DME2BasicAuth(principal,si);
\r
164 } catch (IOException e) {
\r
165 throw new CadiException("Error creating DME2BasicAuth",e);
\r
171 public SecuritySetter<DME2Client> x509Alias(String alias) throws CadiException {
\r
173 presetProps(access, alias);
\r
174 return new DME2x509SS(alias,si);
\r
175 } catch (Exception e) {
\r
176 throw new CadiException("Error creating DME2x509SS",e);
\r
181 public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
\r
182 // NOTE: DME2 had Retry Logic embedded lower.
\r
184 return (retryable.code(rclient(initURI,ss)));
\r
185 } catch (ConnectException e) {
\r
186 // DME2 should catch
\r
189 } catch (Exception e1) {
\r
190 throw new CadiException(e1);
\r
192 throw new CadiException(e);
\r
196 public static void presetProps(PropAccess access, String alias) throws IOException {
\r
197 System.setProperty(Config.AFT_DME2_CLIENT_SSL_CERT_ALIAS, alias);
\r
198 if(System.getProperty(Config.AFT_DME2_CLIENT_IGNORE_SSL_CONFIG)==null) {
\r
199 access.getDME2Properties();
\r
205 * @see com.att.cadi.aaf.v2_0.AAFCon#initURI()
\r
208 protected URI initURI() {
\r
213 * @see com.att.cadi.aaf.v2_0.AAFCon#setInitURI(java.lang.String)
\r
216 protected void setInitURI(String uriString) throws CadiException {
\r
218 initURI = new URI(uriString);
\r
219 } catch (URISyntaxException e) {
\r
220 throw new CadiException(e);
\r