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.ConnectException;
\r
28 import java.net.URI;
\r
29 import java.net.URISyntaxException;
\r
30 import java.security.GeneralSecurityException;
\r
31 import java.security.Principal;
\r
32 import java.util.Properties;
\r
34 import com.att.aft.dme2.api.DME2Client;
\r
35 import com.att.aft.dme2.api.DME2Exception;
\r
36 import com.att.aft.dme2.api.DME2Manager;
\r
37 import com.att.cadi.CadiException;
\r
38 import com.att.cadi.LocatorException;
\r
39 import com.att.cadi.PropAccess;
\r
40 import com.att.cadi.SecuritySetter;
\r
41 import com.att.cadi.client.Rcli;
\r
42 import com.att.cadi.client.Retryable;
\r
43 import com.att.cadi.config.Config;
\r
44 import com.att.cadi.config.SecurityInfoC;
\r
45 import com.att.cadi.dme2.DME2BasicAuth;
\r
46 import com.att.cadi.dme2.DME2TransferSS;
\r
47 import com.att.cadi.dme2.DME2x509SS;
\r
48 import com.att.cadi.dme2.DRcli;
\r
49 import com.att.cadi.principal.BasicPrincipal;
\r
50 import com.att.inno.env.APIException;
\r
52 public class AAFConDME2 extends AAFCon<DME2Client>{
\r
53 private DME2Manager manager;
\r
54 private boolean isProxy;
\r
55 private URI initURI;
\r
57 public AAFConDME2(PropAccess access) throws CadiException, GeneralSecurityException, IOException{
\r
58 super(access,Config.AAF_URL,new SecurityInfoC<DME2Client> (access));
\r
59 manager = newManager(access);
\r
63 public AAFConDME2(PropAccess access, String url) throws CadiException, GeneralSecurityException, IOException{
\r
64 super(access,url,new SecurityInfoC<DME2Client> (access));
\r
65 manager = newManager(access);
\r
69 public AAFConDME2(PropAccess access, SecurityInfoC<DME2Client> si) throws CadiException {
\r
70 super(access,Config.AAF_URL,si);
\r
71 manager = newManager(access);
\r
75 public AAFConDME2(PropAccess access, String url, SecurityInfoC<DME2Client> si) throws CadiException {
\r
76 super(access,url,si);
\r
77 manager = newManager(access);
\r
82 * Construct a Connector based on the AAF one. This is for remote access to OTHER than AAF,
\r
83 * but using Credentials, etc
\r
85 private AAFConDME2(AAFCon<DME2Client> aafcon, String url) throws CadiException {
\r
88 initURI = new URI(url);
\r
89 } catch (URISyntaxException e) {
\r
90 throw new CadiException(e);
\r
92 manager = newManager(access);
\r
96 * Create a Connector based on the AAF one. This is for remote access to OTHER than AAF,
\r
97 * but using Credentials, etc
\r
99 public AAFCon<DME2Client> clone(String url) throws CadiException {
\r
100 return new AAFConDME2(this,url);
\r
103 private void setIsProxy() {
\r
105 if((str=access.getProperty(Config.AAF_URL, null))!=null) {
\r
106 isProxy = str.contains("service=com.att.authz.authz-gw/version=");
\r
110 private DME2Manager newManager(PropAccess access) throws CadiException {
\r
111 Properties props = access.getDME2Properties();
\r
112 // Critical that TLS Settings not ignored
\r
114 return new DME2Manager("AAFCon",props);
\r
115 } catch (DME2Exception e) {
\r
116 throw new CadiException(e);
\r
122 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuth(java.lang.String, java.lang.String)
\r
125 public SecuritySetter<DME2Client> basicAuth(String user, String password) throws CadiException {
\r
126 if(password.startsWith("enc:???")) {
\r
128 password = access.decrypt(password, true);
\r
129 } catch (IOException e) {
\r
130 throw new CadiException("Error Decrypting Password",e);
\r
135 return set(new DME2BasicAuth(user,password,si));
\r
136 } catch (IOException e) {
\r
137 throw new CadiException("Error setting up DME2BasicAuth",e);
\r
142 * @see com.att.cadi.aaf.v2_0.AAFCon#rclient(java.net.URI, com.att.cadi.SecuritySetter)
\r
145 protected Rcli<DME2Client> rclient(URI uri, SecuritySetter<DME2Client> ss) {
\r
146 DRcli dc = new DRcli(uri, ss);
\r
147 dc.setProxy(isProxy);
\r
148 dc.setManager(manager);
\r
153 public SecuritySetter<DME2Client> transferSS(Principal principal) throws CadiException {
\r
155 return principal==null?ss:new DME2TransferSS(principal, app, si);
\r
156 } catch (IOException e) {
\r
157 throw new CadiException("Error creating DME2TransferSS",e);
\r
162 public SecuritySetter<DME2Client> basicAuthSS(BasicPrincipal principal) throws CadiException {
\r
164 return new DME2BasicAuth(principal,si);
\r
165 } catch (IOException e) {
\r
166 throw new CadiException("Error creating DME2BasicAuth",e);
\r
172 public SecuritySetter<DME2Client> x509Alias(String alias) throws CadiException {
\r
174 presetProps(access, alias);
\r
175 return new DME2x509SS(alias,si);
\r
176 } catch (Exception e) {
\r
177 throw new CadiException("Error creating DME2x509SS",e);
\r
182 public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
\r
183 // NOTE: DME2 had Retry Logic embedded lower.
\r
185 return (retryable.code(rclient(initURI,ss)));
\r
186 } catch (ConnectException e) {
\r
187 // DME2 should catch
\r
190 } catch (Exception e1) {
\r
191 throw new CadiException(e1);
\r
193 throw new CadiException(e);
\r
197 public static void presetProps(PropAccess access, String alias) throws IOException {
\r
198 System.setProperty(Config.AFT_DME2_CLIENT_SSL_CERT_ALIAS, alias);
\r
199 if(System.getProperty(Config.AFT_DME2_CLIENT_IGNORE_SSL_CONFIG)==null) {
\r
200 access.getDME2Properties();
\r
206 * @see com.att.cadi.aaf.v2_0.AAFCon#initURI()
\r
209 protected URI initURI() {
\r
214 * @see com.att.cadi.aaf.v2_0.AAFCon#setInitURI(java.lang.String)
\r
217 protected void setInitURI(String uriString) throws CadiException {
\r
219 initURI = new URI(uriString);
\r
220 } catch (URISyntaxException e) {
\r
221 throw new CadiException(e);
\r