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.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.Access;
\r
37 import com.att.cadi.CadiException;
\r
38 import com.att.cadi.LocatorException;
\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.SecurityInfo;
\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
54 public AAFConDME2(Access access) throws CadiException, GeneralSecurityException, IOException{
\r
55 super(access,Config.AAF_URL,new SecurityInfo<DME2Client> (access));
\r
56 manager = newManager(access);
\r
59 public AAFConDME2(Access access, String url) throws CadiException, GeneralSecurityException, IOException{
\r
60 super(access,url,new SecurityInfo<DME2Client> (access));
\r
61 manager = newManager(access);
\r
64 public AAFConDME2(Access access, SecurityInfo<DME2Client> si) throws CadiException {
\r
65 super(access,Config.AAF_URL,si);
\r
66 manager = newManager(access);
\r
69 public AAFConDME2(Access access, String url, SecurityInfo<DME2Client> si) throws CadiException {
\r
70 super(access,url,si);
\r
71 manager = newManager(access);
\r
74 private DME2Manager newManager(Access access) throws CadiException {
\r
75 Properties props = new Properties();
\r
76 Config.cadiToDME2(access, props);
\r
78 return new DME2Manager("AAFCon",props);
\r
79 } catch (DME2Exception e) {
\r
80 throw new CadiException(e);
\r
86 * @see com.att.cadi.aaf.v2_0.AAFCon#basicAuth(java.lang.String, java.lang.String)
\r
89 public SecuritySetter<DME2Client> basicAuth(String user, String password) throws CadiException {
\r
90 if(password.startsWith("enc:???")) {
\r
92 password = access.decrypt(password, true);
\r
93 } catch (IOException e) {
\r
94 throw new CadiException("Error Decrypting Password",e);
\r
99 return set(new DME2BasicAuth(user,password,si));
\r
100 } catch (IOException e) {
\r
101 throw new CadiException("Error setting up DME2BasicAuth",e);
\r
106 * @see com.att.cadi.aaf.v2_0.AAFCon#rclient(java.net.URI, com.att.cadi.SecuritySetter)
\r
109 protected Rcli<DME2Client> rclient(URI uri, SecuritySetter<DME2Client> ss) {
\r
110 DRcli dc = new DRcli(uri, ss);
\r
111 dc.setManager(manager);
\r
116 public SecuritySetter<DME2Client> transferSS(Principal principal) throws CadiException {
\r
118 return principal==null?ss:new DME2TransferSS(principal, app);
\r
119 } catch (IOException e) {
\r
120 throw new CadiException("Error creating DME2TransferSS",e);
\r
125 public SecuritySetter<DME2Client> basicAuthSS(BasicPrincipal principal) throws CadiException {
\r
127 return new DME2BasicAuth(principal,si);
\r
128 } catch (IOException e) {
\r
129 throw new CadiException("Error creating DME2BasicAuth",e);
\r
135 public SecuritySetter<DME2Client> x509Alias(String alias) throws CadiException {
\r
137 return new DME2x509SS(alias,si);
\r
138 } catch (Exception e) {
\r
139 throw new CadiException("Error creating DME2x509SS",e);
\r
144 public <RET> RET best(Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
\r
145 // NOTE: DME2 had Retry Logic embedded lower.
\r
147 return (retryable.code(rclient(initURI,ss)));
\r
148 } catch (ConnectException e) {
\r
149 // DME2 should catch
\r
152 } catch (Exception e1) {
\r
153 throw new CadiException(e1);
\r
155 throw new CadiException(e);
\r