Produced by Araxis Merge on 12/5/2017 12:06:39 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\DxDataSourceProvider\main\src\java\gov\va\med\imaging\dx\rest\proxy | DxBasicAuthRestClient.java | Mon Dec 4 21:35:24 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\DxDataSourceProvider\main\src\java\gov\va\med\imaging\dx\rest\proxy | DxBasicAuthRestClient.java | Tue Dec 5 12:45:45 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 652 |
| Changed | 1 | 4 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.med.i maging.dx. rest.proxy ; | |
| 2 | ||
| 3 | import org .apache.lo gging.log4 j.LogManag er; | |
| 4 | import org .apache.lo gging.log4 j.Logger; | |
| 5 | ||
| 6 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont ext; | |
| 7 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ; | |
| 8 | import gov .va.med.im aging.tran sactioncon text.Trans actionCont extHttpHea ders; | |
| 9 | ||
| 10 | import com .sun.jerse y.api.clie nt.Client; | |
| 11 | import com .sun.jerse y.api.clie nt.WebReso urce; | |
| 12 | import com .sun.jerse y.api.clie nt.config. ClientConf ig; | |
| 13 | import com .sun.jerse y.api.clie nt.config. DefaultCli entConfig; | |
| 14 | import com .sun.jerse y.api.clie nt.filter. HTTPBasicA uthFilter; | |
| 15 | //import c om.sun.jer sey.client .apache.Ap acheHttpCl ient; | |
| 16 | import com .sun.jerse y.client.u rlconnecti on.HTTPSPr operties; | |
| 17 | ||
| 18 | import jav a.io.IOExc eption; | |
| 19 | import jav a.io.Input Stream; | |
| 20 | import jav a.io.Print Writer; | |
| 21 | import jav a.io.Strin gWriter; | |
| 22 | import jav a.net.URL; | |
| 23 | import jav a.security .GeneralSe curityExce ption; | |
| 24 | import jav a.security .KeyStore; | |
| 25 | import jav a.security .KeyStoreE xception; | |
| 26 | import jav a.security .NoSuchAlg orithmExce ption; | |
| 27 | import jav a.security .Unrecover ableKeyExc eption; | |
| 28 | import jav a.security .cert.Cert ificateExc eption; | |
| 29 | ||
| 30 | //import j avax.ws.rs .core.Http Headers; | |
| 31 | import jav ax.ws.rs.c ore.MediaT ype; | |
| 32 | ||
| 33 | import jav ax.net.ssl .HostnameV erifier; | |
| 34 | //import j avax.net.s sl.HttpsUR LConnectio n; | |
| 35 | import jav ax.net.ssl .KeyManage r; | |
| 36 | import jav ax.net.ssl .KeyManage rFactory; | |
| 37 | import jav ax.net.ssl .SSLContex t; | |
| 38 | import jav ax.net.ssl .SSLSessio n; | |
| 39 | import jav ax.net.ssl .TrustMana ger; | |
| 40 | import jav ax.net.ssl .TrustMana gerFactory ; | |
| 41 | //import c om.sun.jer sey.api.cl ient.Clien tResponse; | |
| 42 | ||
| 43 | /** | |
| 44 | * @author vhaisltjah jb | |
| 45 | * | |
| 46 | */ | |
| 47 | ||
| 48 | public cla ss DxBasic AuthRestCl ient { | |
| 49 | privat e final st atic Logge r logger = LogManage r.getLogge r(DxBasicA uthRestCli ent.class) ; | |
| 50 | privat e String b asicAuthUr l = null; | |
| 51 | privat e String a lexdelarge Password = null; | |
| 52 | privat e Transact ionContext transacti onContext = null; | |
| 53 | ||
| 54 | public DxBasicAu thRestClie nt(String url, Strin g alexdela rgePasswor d) | |
| 55 | { | |
| 56 | th is.basicAu thUrl = ur l; | |
| 57 | th is.alexdel argePasswo rd = alexd elargePass word; | |
| 58 | tr ansactionC ontext = T ransaction ContextFac tory.get() ; | |
| 59 | } | |
| 60 | ||
| 61 | public String ge tDataFromS erver(Stri ng keystor eUrl, Stri ng keystor ePassword) | |
| 62 | { | |
| 63 | St ring resul t = null; | |
| 64 | ||
| 65 | //Hostnam eVerifier hostnameVe rifier = H ttpsURLCon nection.ge tDefaultHo stnameVeri fier(); | |
| 66 | Ho stnameVeri fier hostn ameVerifie r = new Ho stnameVeri fier() { | |
| 67 | @ Override | |
| 68 | p ublic bool ean verify (String ho stname, SS LSession s ession) | |
| 69 | { | |
| 70 | ret urn true; | |
| 71 | } | |
| 72 | }; | |
| 73 | ||
| 74 | SS LContext s slContext = createSS LContext(k eystoreUrl , keystore Password, keystoreUr l, keystor ePassword) ; | |
| 75 | logg er.debug(" DX createS SLContext done."); | |
| 76 | ||
| 77 | Cl ientConfig config = new Defaul tClientCon fig(); | |
| 78 | c onfig.getP roperties( ).put( | |
| 79 | HTT PSProperti es.PROPERT Y_HTTPS_PR OPERTIES, new HTTPSP roperties( hostnameVe rifier, ss lContext)) ; | |
| 80 | config. getPropert ies().put( | |
| 81 | Cli entConfig. PROPERTY_C ONNECT_TIM EOUT, 3000 0); | |
| 82 | c onfig.getP roperties( ).put( | |
| 83 | Cli entConfig. PROPERTY_R EAD_TIMEOU T, 60000); | |
| 84 | ||
| 85 | Cl ient clien t = Client .create(co nfig); | |
| 86 | logg er.debug(" DX Client. reate(conf ig) done." ); | |
| 87 | ||
| 88 | tr y | |
| 89 | { | |
| 90 | client.add Filter(new HTTPBasic AuthFilter ("alexdela rge", alex delargePas sword)); | |
| 91 | ||
| 92 | WebR esource re source = c lient.reso urce(basic AuthUrl); | |
| 93 | logg er.debug(" DX client resource d one."); | |
| 94 | addTransac tionHeader s(resource ); | |
| 95 | ||
| 96 | resu lt = resou rce.accept (MediaType .TEXT_PLAI N_TYPE).ge t(String.c lass); | |
| 97 | logg er.debug(" DX got res ult:" + re sult); | |
| 98 | } | |
| 99 | ca tch (Excep tion e) { | |
| 100 | logg er.debug(" DX getData FromServer exception : " + e.ge tMessage() ); | |
| 101 | ||
| 102 | } | |
| 103 | fi nally | |
| 104 | { | |
| 105 | clie nt.destroy (); | |
| 106 | } | |
| 107 | ||
| 108 | re turn resul t; | |
| 109 | ||
| 110 | } | |
| 111 | ||
| 112 | privat e static S SLContext createSSLC ontext( | |
| 113 | Stri ng keystor efile, Str ing keysto rePassword , | |
| 114 | Stri ng trustst orefile, S tring trus tstorepwd) | |
| 115 | { | |
| 116 | logg er.debug(" keystoreur l=" + keys torefile); | |
| 117 | ||
| 118 | try | |
| 119 | { | |
| 120 | KeyMan ager[] key managers = null; | |
| 121 | if (ke ystorefile != null) | |
| 122 | { | |
| 123 | URL keys toreUrl = new URL(ke ystorefile ); | |
| 124 | KeyStore keystore = createKe yStore(key storeUrl, keystorePa ssword); | |
| 125 | keymanag ers = crea teKeyManag ers(keysto re, keysto rePassword ); | |
| 126 | } | |
| 127 | ||
| 128 | TrustM anager[] t rustmanage rs = null; | |
| 129 | if (tr uststorefi le != null ) | |
| 130 | { | |
| 131 | URL trus tstoreUrl = new URL( truststore file); | |
| 132 | KeyStore truststor e = create KeyStore(t ruststoreU rl, trusts torepwd); | |
| 133 | trustman agers = cr eateTrustM anagers(tr uststore); | |
| 134 | } | |
| 135 | ||
| 136 | SSLCon text sslco ntext = SS LContext.g etInstance ("SSL"); | |
| 137 | sslcon text.init( keymanager s, trustma nagers, nu ll); | |
| 138 | return sslcontex t; | |
| 139 | } | |
| 140 | catc h (NoSuchA lgorithmEx ception e) | |
| 141 | { | |
| 142 | String Writer sw = new Stri ngWriter() ; | |
| 143 | e.prin tStackTrac e(new Prin tWriter(sw )); | |
| 144 | logger .debug("Cr eate SSL C ontext Err or: " + sw .toString( )); | |
| 145 | } | |
| 146 | catc h (KeyStor eException e) | |
| 147 | { | |
| 148 | String Writer sw = new Stri ngWriter() ; | |
| 149 | e.prin tStackTrac e(new Prin tWriter(sw )); | |
| 150 | logger .debug("Cr eate SSL C ontext Err or: " + sw .toString( )); | |
| 151 | } | |
| 152 | catc h (General SecurityEx ception e) | |
| 153 | { | |
| 154 | String Writer sw = new Stri ngWriter() ; | |
| 155 | e.prin tStackTrac e(new Prin tWriter(sw )); | |
| 156 | logger .debug("Cr eate SSL C ontext Err or: " + sw .toString( )); | |
| 157 | } | |
| 158 | catc h (IOExcep tion e) | |
| 159 | { | |
| 160 | String Writer sw = new Stri ngWriter() ; | |
| 161 | e.prin tStackTrac e(new Prin tWriter(sw )); | |
| 162 | logger .debug("Cr eate SSL C ontext Err or: " + sw .toString( )); | |
| 163 | } | |
| 164 | ||
| 165 | retu rn null; | |
| 166 | } | |
| 167 | ||
| 168 | ||
| 169 | privat e static K eyStore cr eateKeySto re(final U RL url, fi nal String password) | |
| 170 | th rows KeySt oreExcepti on, NoSuch AlgorithmE xception, Certificat eException , IOExcept ion | |
| 171 | { | |
| 172 | if ( url == nul l) | |
| 173 | throw new Illega lArgumentE xception(" Keystore u rl may not be null") ; | |
| 174 | ||
| 175 | KeyS tore keyst ore = KeyS tore.getIn stance("jk s"); | |
| 176 | Inpu tStream is = null; | |
| 177 | try | |
| 178 | { | |
| 179 | is = u rl.openStr eam(); | |
| 180 | keysto re.load(is , password != null ? password. toCharArra y() : null ); | |
| 181 | } | |
| 182 | fina lly | |
| 183 | { | |
| 184 | if (is != null) | |
| 185 | is.close (); | |
| 186 | } | |
| 187 | retu rn keystor e; | |
| 188 | } | |
| 189 | ||
| 190 | privat e static K eyManager[ ] createKe yManagers( final KeyS tore keyst ore, final String pa ssword) | |
| 191 | thro ws KeyStor eException , NoSuchAl gorithmExc eption, Un recoverabl eKeyExcept ion | |
| 192 | { | |
| 193 | if ( keystore = = null) | |
| 194 | throw new Illega lArgumentE xception(" Keystore m ay not be null"); | |
| 195 | ||
| 196 | KeyM anagerFact ory kmfact ory = KeyM anagerFact ory.getIns tance(KeyM anagerFact ory.getDef aultAlgori thm()); | |
| 197 | kmfa ctory.init (keystore, password != null ? password.t oCharArray () : null) ; | |
| 198 | retu rn kmfacto ry.getKeyM anagers(); | |
| 199 | } | |
| 200 | ||
| 201 | pr ivate stat ic TrustMa nager[] cr eateTrustM anagers(fi nal KeySto re keystor e) | |
| 202 | th rows KeySt oreExcepti on, NoSuch AlgorithmE xception | |
| 203 | { | |
| 204 | if ( keystore = = null) | |
| 205 | throw new Illega lArgumentE xception(" Keystore m ay not be null"); | |
| 206 | ||
| 207 | Trus tManagerFa ctory tmfa ctory = Tr ustManager Factory.ge tInstance( TrustManag erFactory. getDefault Algorithm( )); | |
| 208 | tmfa ctory.init (keystore) ; | |
| 209 | tmfa ctory.getT rustManage rs(); | |
| 210 | retu rn tmfacto ry.getTrus tManagers( ); | |
| 211 | } | |
| 212 | ||
| 213 | pr ivate void addTransa ctionHeade rs(WebReso urce reque st) | |
| 214 | { | |
| 215 | Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get(); | |
| 216 | ||
| 217 | Stri ng duz = t ransaction Context.ge tDuz(); | |
| 218 | if(d uz != null && duz.le ngth() > 0 ) | |
| 219 | req uest.heade r( Transac tionContex tHttpHeade rs.httpHea derDuz, du z); | |
| 220 | ||
| 221 | Stri ng fullnam e = transa ctionConte xt.getFull Name(); | |
| 222 | if(f ullname != null && f ullname.le ngth() > 0 ) | |
| 223 | req uest.heade r( Transac tionContex tHttpHeade rs.httpHea derFullNam e, fullnam e); | |
| 224 | ||
| 225 | Stri ng sitenam e = transa ctionConte xt.getSite Name(); | |
| 226 | if(s itename != null && s itename.le ngth() > 0 ) | |
| 227 | req uest.heade r( Transac tionContex tHttpHeade rs.httpHea derSiteNam e, sitenam e); | |
| 228 | ||
| 229 | Stri ng sitenum ber = tran sactionCon text.getSi teNumber() ; | |
| 230 | if(s itenumber != null && sitenumbe r.length() > 0) | |
| 231 | req uest.heade r( Transac tionContex tHttpHeade rs.httpHea derSiteNum ber, siten umber); | |
| 232 | ||
| 233 | Stri ng ssn = t ransaction Context.ge tSsn(); | |
| 234 | if(s sn != null && ssn.le ngth() > 0 ) | |
| 235 | req uest.heade r( Transac tionContex tHttpHeade rs.httpHea derSSN, ss n); | |
| 236 | ||
| 237 | Stri ng securit yToken = t ransaction Context.ge tBrokerSec urityToken (); | |
| 238 | if(s ecurityTok en != null && securi tyToken.le ngth() > 0 ) | |
| 239 | req uest.heade r(Transact ionContext HttpHeader s.httpHead erBrokerSe curityToke nId, secur ityToken); | |
| 240 | ||
| 241 | Stri ng cacheLo cationId = transacti onContext. getCacheLo cationId() ; | |
| 242 | if(c acheLocati onId != nu ll && cach eLocationI d.length() > 0) | |
| 243 | req uest.heade r(Transact ionContext HttpHeader s.httpHead erCacheLoc ationId, c acheLocati onId); | |
| 244 | ||
| 245 | Stri ng userDiv ision = tr ansactionC ontext.get UserDivisi on(); | |
| 246 | if(u serDivisio n != null && userDiv ision.leng th() > 0) | |
| 247 | req uest.heade r(Transact ionContext HttpHeader s.httpHead erUserDivi sion, user Division); | |
| 248 | ||
| 249 | Stri ng transac tionId = t ransaction Context.ge tTransacti onId(); | |
| 250 | if(t ransaction Id != null && transa ctionId.le ngth() > 0 ) | |
| 251 | req uest.heade r(Transact ionContext HttpHeader s.httpHead erTransact ionId, tra nsactionId ); | |
| 252 | ||
| 253 | Stri ng request ingVixSite Number = t ransaction Context.ge tVixSiteNu mber(); | |
| 254 | if(r equestingV ixSiteNumb er != null && reques tingVixSit eNumber.le ngth() > 0 ) | |
| 255 | req uest.heade r(Transact ionContext HttpHeader s.httpHead erRequesti ngVixSiteN umber, req uestingVix SiteNumber ); | |
| 256 | ||
| 257 | Stri ng imaging SecurityCo ntextType = transact ionContext .getImagin gSecurityC ontextType (); | |
| 258 | if(i magingSecu rityContex tType != n ull && ima gingSecuri tyContextT ype.length () > 0) | |
| 259 | req uest.heade r(Transact ionContext HttpHeader s.httpHead erOptionCo ntext, ima gingSecuri tyContextT ype); | |
| 260 | ||
| 261 | debu gHeaders() ; | |
| 262 | } | |
| 263 | ||
| 264 | pr ivate void debugHead ers() | |
| 265 | { | |
| 266 | Stri ng duz = t ransaction Context.ge tDuz(); | |
| 267 | if(d uz != null && duz.le ngth() > 0 ) | |
| 268 | logger.deb ug("Header Duz: " + duz); | |
| 269 | ||
| 270 | Stri ng fullnam e = transa ctionConte xt.getFull Name(); | |
| 271 | if(f ullname != null && f ullname.le ngth() > 0 ) | |
| 272 | logg er.debug(" Header ful lname: " + fullname) ; | |
| 273 | ||
| 274 | Stri ng sitenam e = transa ctionConte xt.getSite Name(); | |
| 275 | if(s itename != null && s itename.le ngth() > 0 ) | |
| 276 | logg er.debug(" Header sit ename: " + sitename) ; | |
| 277 | ||
| 278 | Stri ng sitenum ber = tran sactionCon text.getSi teNumber() ; | |
| 279 | if(s itenumber != null && sitenumbe r.length() > 0) | |
| 280 | logg er.debug(" Header sit enumber: " + sitenum ber); | |
| 281 | ||
| 282 | Stri ng ssn = t ransaction Context.ge tSsn(); | |
| 283 | if(s sn != null && ssn.le ngth() > 0 ) | |
| 284 | logg er.debug(" Header ssn : " + ssn) ; | |
| 285 | ||
| 286 | Stri ng securit yToken = t ransaction Context.ge tBrokerSec urityToken (); | |
| 287 | if(s ecurityTok en != null && securi tyToken.le ngth() > 0 ) | |
| 288 | logg er.debug(" Header sec urityToken : " + secu rityToken) ; | |
| 289 | ||
| 290 | Stri ng cacheLo cationId = transacti onContext. getCacheLo cationId() ; | |
| 291 | if(c acheLocati onId != nu ll && cach eLocationI d.length() > 0) | |
| 292 | logg er.debug(" Header cac heLocation Id: " + ca cheLocatio nId); | |
| 293 | ||
| 294 | Stri ng userDiv ision = tr ansactionC ontext.get UserDivisi on(); | |
| 295 | if(u serDivisio n != null && userDiv ision.leng th() > 0) | |
| 296 | logg er.debug(" Header use rDivision: " + userD ivision); | |
| 297 | ||
| 298 | Stri ng transac tionId = t ransaction Context.ge tTransacti onId(); | |
| 299 | if(t ransaction Id != null && transa ctionId.le ngth() > 0 ) | |
| 300 | logg er.debug(" Header tra nsactionId : " + tran sactionId) ; | |
| 301 | ||
| 302 | Stri ng request ingVixSite Number = t ransaction Context.ge tVixSiteNu mber(); | |
| 303 | if(r equestingV ixSiteNumb er != null && reques tingVixSit eNumber.le ngth() > 0 ) | |
| 304 | logg er.debug(" Header req uestingVix SiteNumber : " + requ estingVixS iteNumber) ; | |
| 305 | ||
| 306 | Stri ng imaging SecurityCo ntextType = transact ionContext .getImagin gSecurityC ontextType (); | |
| 307 | if(i magingSecu rityContex tType != n ull && ima gingSecuri tyContextT ype.length () > 0) | |
| 308 | logg er.debug(" Header ima gingSecuri tyContextT ype: " + i magingSecu rityContex tType); | |
| 309 | ||
| 310 | } | |
| 311 | ||
| 312 | // java.exe | |
| 313 | // -Dlo g4j.config uration=fi le:/C:/Vix Config/log 4j.propert ies | |
| 314 | // -cp ./*;DxData SourceProv ider-0.1.j ar | |
| 315 | // gov. va.med.ima ging.dx.re st.proxy.D xBasicAuth RestClient <params> | |
| 316 | // pu blic stati c void mai n(String[] argv) | |
| 317 | // { | |
| 318 | // Stri ng keystor eUrl = "fi le:///C:/V ixCertStor e/cvix.jks "; | |
| 319 | // String key storePassw ord = " RE DA CTED "; | |
| 320 | // String url = "https: // IP /MIXWebApp /restservi ces/mix/Da sCachedDoc umentId?re poId=centr al&docId=h 0103d64813 f486400db7 5d39430b80 5f110111- IP "; | |
| 321 | // | |
| 322 | // DxBa sicAuthRes tClient ba sicClient = new DxBa sicAuthRes tClient(ur l); | |
| 323 | // Stri ng result = basicCli ent.getDat aFromServe r(keystore Url, keyst orePasswor d); | |
| 324 | // Syst em.out.pri ntln(resul t); | |
| 325 | // } | |
| 326 | ||
| 327 | } | |
| 328 |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.