10. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/5/2018 10:24:07 AM Central Daylight 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.

10.1 Files compared

# Location File Last Modified
1 patch_205_build_9.zip\Java\BaseWebFacade\main\src\java\gov\va\med\imaging SecurityFilter.java Wed May 30 14:35:20 2018 UTC
2 patch_205_build_9.zip\Java\BaseWebFacade\main\src\java\gov\va\med\imaging SecurityFilter.java Fri Jun 1 17:57:34 2018 UTC

10.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 600
Changed 1 2
Inserted 0 0
Removed 0 0

10.3 Comparison options

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

10.4 Active regular expressions

No regular expressions were active.

10.5 Comparison detail

  1   /**
  2    * 
  3    */
  4   package go v.va.med.i maging;
  5  
  6   import gov .va.med.Ro utingToken ;
  7   import gov .va.med.Ro utingToken Impl;
  8   import gov .va.med.ex ceptions.R outingToke nFormatExc eption;
  9   import gov .va.med.im aging.tran sactioncon text.Trans actionCont ext;
  10   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extFactory ;
  11   import gov .va.med.im aging.tran sactioncon text.Trans actionCont extHttpHea ders;
  12  
  13   import gov .va.med.im aging.core .FacadeRou terUtility ;
  14   import gov .va.med.im aging.exch ange.busin ess.Transa ctionConte xtLogEntry Snapshot;
  15  
  16   import jav a.io.IOExc eption;
  17   import jav ax.servlet .Filter;
  18   import jav ax.servlet .FilterCha in;
  19   import jav ax.servlet .FilterCon fig;
  20   //import j avax.servl et.Servlet Context;
  21   import jav ax.servlet .ServletEx ception;
  22   import jav ax.servlet .ServletRe quest;
  23   import jav ax.servlet .ServletRe sponse;
  24   import jav ax.servlet .http.Http ServletReq uest;
  25  
  26   import org .apache.lo gging.log4 j.Logger;
  27   import org .apache.lo gging.log4 j.LogManag er;
  28  
  29   /**
  30    * The Sec urityFilte r sets som e properti es of the  transactio n context  based
  31    * on init ialization  parameter s in the w eb configu ration fil e.  
  32    * This cl ass also c opies HTTP  headers i nto the tr ansaction  context.
  33    * 
  34    * @author   PII
  35    *
  36    */
  37   public cla ss Securit yFilter 
  38   implements  Filter
  39   {
  40           pr ivate Logg er logger  = LogManag er.getLogg er(this.ge tClass());
  41           pr ivate bool ean genera teTransact ionId = fa lse;           // for  a web app  where the  transacti on initiat es this ma y be true
  42           pr ivate bool ean enable ProtocolOv erride = f alse;          // for  test driv ers, enabl e this in  the web.xm l to allow  
  43                                                                                                                              // proto colOverrid e and targ etSite que ry paramet er
  44           
  45           pr ivate Stri ng machine Name = nul l;
  46           
  47           /*  (non-Java doc)
  48            *  @see java x.servlet. Filter#ini t(javax.se rvlet.Filt erConfig)
  49            * /
  50           pu blic void  init(Filte rConfig co nfig) 
  51           th rows Servl etExceptio n
  52           {
  53                    gene rateTransa ctionId =  Boolean.pa rseBoolean ( config.g etInitPara meter("gen erateTrans actionId")  );
  54                    enab leProtocol Override =  Boolean.p arseBoolea n( config. getInitPar ameter("en ableProtoc olOverride ") );
  55                    
  56                    logg er.info("S ecurityFil ter for "  + config.g etServletC ontext().g etServletC ontextName () + 
  57                                      (generat eTransacti onId ? " w ill" : " w ill not")  + " genera te transac tion IDs i f they do  not exist. ");
  58                    logg er.info("S ecurityFil ter for "  + config.g etServletC ontext().g etServletC ontextName () + 
  59                                      (enableP rotocolOve rride ? "  will" : "  will not")  + " allow  protocol  and target  site ovve ride.");
  60                    
  61                    // D etermine t he hostnam e for late r logging.
  62                    try
  63                    {
  64                       m achineName  = java.ne t.InetAddr ess.getLoc alHost (). getHostNam e ();
  65                       i f (machine Name == nu ll) machin eName = ja va.net.Ine tAddress.g etLocalHos t ().getHo stAddress  ();
  66                       / /if ("loca lhost".equ alsIgnoreC ase (machi neName) ||  "127.0.0. 1".equals  (machineNa me)) machi neName = n ull;
  67                    }
  68                    catc h (java.ne t.UnknownH ostExcepti on uhx)
  69                    {
  70                       m achineName  = "<unkno wn>";
  71                    }
  72           }
  73  
  74           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ====
  75           //  Accessors  so that S pring can  initialize  
  76           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ====
  77           pu blic boole an isGener ateTransac tionId()
  78       {
  79           re turn gener ateTransac tionId;
  80       }
  81           pu blic void  setGenerat eTransacti onId(boole an generat eTransacti onId)
  82       {
  83           th is.generat eTransacti onId = gen erateTrans actionId;
  84       }
  85  
  86           pu blic boole an isEnabl eProtocolO verride()
  87       {
  88           re turn enabl eProtocolO verride;
  89       }
  90           pu blic void  setEnableP rotocolOve rride(bool ean enable ProtocolOv erride)
  91       {
  92           th is.enableP rotocolOve rride = en ableProtoc olOverride ;
  93       }
  94  
  95           /*  (non-Java doc)
  96            *  @see java x.servlet. Filter#doF ilter(java x.servlet. ServletReq uest, java x.servlet. ServletRes ponse, jav ax.servlet .FilterCha in)
  97            * /
  98           pu blic void  doFilter(
  99                    Serv letRequest  request, 
  100                    Serv letRespons e response ,
  101                    Filt erChain ch ain) 
  102           th rows IOExc eption, Se rvletExcep tion
  103           {
  104           Lo ng startTi me = Syste m.currentT imeMillis( );
  105                    // T he princip al should  be accessi ble in the  request a nd would b e accessib le if we k new this w as
  106                    // a n HTTP req uest.
  107                    Tran sactionCon text trans actionCont ext = Tran sactionCon textFactor y.get();
  108                    tran sactionCon text.setSt artTime(st artTime);
  109                    
  110                    // D etermine t he hostnam e for logg ing.
  111                    // T he init me thod never  seems to  get called .  Spring  vs. Contai ner loadin g?
  112                    try
  113                    {
  114                       m achineName  = java.ne t.InetAddr ess.getLoc alHost (). getHostNam e ();
  115                       i f (machine Name == nu ll) machin eName = ja va.net.Ine tAddress.g etLocalHos t ().getHo stAddress  ();
  116                       / /if ("loca lhost".equ alsIgnoreC ase (machi neName) ||  "127.0.0. 1".equals  (machineNa me)) machi neName = n ull;
  117                    }
  118                    catc h (java.ne t.UnknownH ostExcepti on uhx)
  119                    {
  120                       m achineName  = "<unkno wn>";
  121                    }
  122                    
  123                    // R ecord the  hostname.
  124                    tran sactionCon text.setMa chineName  (machineNa me);
  125                    
  126                    if(r equest ins tanceof Ht tpServletR equest)
  127                    {
  128                             HttpSe rvletReque st httpReq uest = (Ht tpServletR equest)req uest;
  129                             logger .info(
  130                                      "Transac tionContex t " + 
  131                                      (Boolean .valueOf(t ransaction Context.is Authentica tedByDeleg ate()) ? " is authent icated by  delegate"  : "is auth enticated  by VistA")  + 
  132                                      ".  Vist aRealmSecu rityContex t, getting  credentia ls from HT TP header  informatio n..." );
  133                             
  134                             transa ctionConte xt.setOrig inatingAdd ress(httpR equest.get RemoteAddr () + ":" +  httpReque st.getRemo tePort());
  135                             
  136                             logger .debug("Ch ecking htt p header f or credent ials in "  + this.get Class().ge tName());
  137                             logger .debug("DU Z: "+httpR equest.get Header(Tra nsactionCo ntextHttpH eaders.htt pHeaderDuz ));
  138                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderD uz) != nul l)
  139                                      transact ionContext .setDuz(ht tpRequest. getHeader( Transactio nContextHt tpHeaders. httpHeader Duz));
  140                             logger .debug("Fu ll Name: " +httpReque st.getHead er(Transac tionContex tHttpHeade rs.httpHea derFullNam e));
  141                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderF ullName) ! = null)
  142                                      transact ionContext .setFullNa me(httpReq uest.getHe ader(Trans actionCont extHttpHea ders.httpH eaderFullN ame));
  143                             logger .debug("Si te Name: " +httpReque st.getHead er(Transac tionContex tHttpHeade rs.httpHea derSiteNam e));
  144                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderS iteName) ! = null)
  145                                      transact ionContext .setSiteNa me(httpReq uest.getHe ader(Trans actionCont extHttpHea ders.httpH eaderSiteN ame));
  146                             logger .debug("Si te Number:  "+httpReq uest.getHe ader(Trans actionCont extHttpHea ders.httpH eaderSiteN umber));
  147                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderS iteNumber)  != null)
  148                                      transact ionContext .setSiteNu mber(httpR equest.get Header(Tra nsactionCo ntextHttpH eaders.htt pHeaderSit eNumber));
  149                             logger .debug("SS N: "+httpR equest.get Header(Tra nsactionCo ntextHttpH eaders.htt pHeaderSSN ));
  150                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderS SN) != nul l)
  151                                      transact ionContext .setSsn(ht tpRequest. getHeader( Transactio nContextHt tpHeaders. httpHeader SSN));
  152                             logger .debug("Tr ansaction  ID: "+http Request.ge tHeader(Tr ansactionC ontextHttp Headers.ht tpHeaderTr ansactionI d));
  153                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderT ransaction Id) != nul l)
  154                                      transact ionContext .setTransa ctionId(ht tpRequest. getHeader( Transactio nContextHt tpHeaders. httpHeader Transactio nId));
  155                             logger .debug("Pu rpose of U se: "+http Request.ge tHeader(Tr ansactionC ontextHttp Headers.ht tpHeaderPu rposeOfUse ));
  156                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderP urposeOfUs e) != null )
  157                                      transact ionContext .setPurpos eOfUse(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderP urposeOfUs e));
  158                             logger .debug("Br oker Secur ity Token  ID: "+http Request.ge tHeader(Tr ansactionC ontextHttp Headers.ht tpHeaderBr okerSecuri tyTokenId) );
  159                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderB rokerSecur ityTokenId ) != null)
  160                                      transact ionContext .setBroker SecurityTo ken(httpRe quest.getH eader(Tran sactionCon textHttpHe aders.http HeaderBrok erSecurity TokenId));
  161                             logger .debug("Ca che Locati on ID: "+h ttpRequest .getHeader (Transacti onContextH ttpHeaders .httpHeade rCacheLoca tionId));
  162                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderC acheLocati onId) != n ull)
  163                                      transact ionContext .setCacheL ocationId( httpReques t.getHeade r(Transact ionContext HttpHeader s.httpHead erCacheLoc ationId));
  164                             logger .debug("Us er Divisio n: "+httpR equest.get Header(Tra nsactionCo ntextHttpH eaders.htt pHeaderUse rDivision) );
  165                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderU serDivisio n) != null )
  166                                      transact ionContext .setUserDi vision(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderU serDivisio n));
  167                             logger .debug("Cl ient Versi on: "+http Request.ge tHeader(Tr ansactionC ontextHttp Headers.ht tpHeaderCl ientVersio n));
  168                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderC lientVersi on) != nul l)
  169                                      transact ionContext .setClient Version(ht tpRequest. getHeader( Transactio nContextHt tpHeaders. httpHeader ClientVers ion));
  170                             logger .debug("Re questing V ix Site Nu mber: "+ht tpRequest. getHeader( Transactio nContextHt tpHeaders. httpHeader Requesting VixSiteNum ber));
  171                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderR equestingV ixSiteNumb er) != nul l)
  172                                      transact ionContext .setReques tingVixSit eNumber(ht tpRequest. getHeader( Transactio nContextHt tpHeaders. httpHeader Requesting VixSiteNum ber));
  173                             logger .debug("Op tion Conte xt: "+http Request.ge tHeader(Tr ansactionC ontextHttp Headers.ht tpHeaderOp tionContex t));
  174                             if(htt pRequest.g etHeader(T ransaction ContextHtt pHeaders.h ttpHeaderO ptionConte xt) != nul l)
  175                                      transact ionContext .setImagin gSecurityC ontextType (httpReque st.getHead er(Transac tionContex tHttpHeade rs.httpHea derOptionC ontext));
  176                             String  httpHeade rAllowAddF ederationC ompression  = httpReq uest.getHe ader(Trans actionCont extHttpHea ders.httpH eaderAllow AddFederat ionCompres sion);
  177  
  178                             //WFP- This made  it work. B ut I have  to confirm  this is t he correct  location.
  179                             //       My inten t was to p lace it wi thin the I mporter we b service  calls.
  180                             transa ctionConte xt.setBrok erSecurity Applicatio nName("VIS TA IMAGING  VIX");                         
  181  
  182                             if(htt pHeaderAll owAddFeder ationCompr ession !=  null && ht tpHeaderAl lowAddFede rationComp ression.le ngth() > 0 )
  183                             {
  184                                      transact ionContext .setAllowA ddFederati onCompress ion(Boolea n.parseBoo lean(httpH eaderAllow AddFederat ionCompres sion));
  185                             }
  186                             
  187                             if(tra nsactionCo ntext.getT ransaction Id() == nu ll && gene rateTransa ctionId)
  188                             {
  189                                      logger.i nfo("Gener ated trans action ID. ");
  190                                      transact ionContext .setTransa ctionId( ( new GUID() ).toLongSt ring() );
  191                             }
  192                             
  193                             // If  protocol o verride is  enabled,  and it sho uld not be  in a prod uction
  194                             // set ting, then  copy the  protocol a nd target  server int o the tran saction
  195                             // con text.
  196                             if(ena bleProtoco lOverride)
  197                             {
  198                                      // "secr et" reques t paramete rs that al low some c ontrol of  the router
  199                                      String p rotocolOve rride = re quest.getP arameter(" protocolOv erride");
  200                                      String t argetSite  = request. getParamet er("target Site");
  201                                      
  202                                      if(targe tSite != n ull && tar getSite.le ngth() > 0  && protoc olOverride  != null & & protocol Override.l ength() >  0)
  203                                      {
  204                                               logger.war n("Preferr ed protoco ls for tra nsaction [ " + transa ctionConte xt.getTran sactionId( ) + 
  205                                                       "]  explicitl y set to ' " + protoc olOverride  + 
  206                                                       "' , and targ et server  '" + targe tSite + "' .");
  207                                              
  208                                               RoutingTok en routing Token;
  209                                               try
  210                                               {
  211                                                       ro utingToken  = Routing TokenImpl. createVARa diologySit e(targetSi te);
  212                                                       tr ansactionC ontext.set OverridePr otocol(pro tocolOverr ide);
  213                                                       tr ansactionC ontext.set OverrideRo utingToken (routingTo ken);
  214                                               }
  215                                               catch (Rou tingTokenF ormatExcep tion x)
  216                                               {
  217                                                       th row new Se rvletExcep tion(x);
  218                                               }
  219                                      }
  220                                      
  221                             }
  222                    }        
  223                    else
  224                             logger .error("Se curityFilt er servlet  filter pa ssed non-H TTP reques t, unable  to provide  security  informatio n.");
  225                             
  226                    logg er.info("T ransaction  ID [" + t ransaction Context.ge tTransacti onId() + " ]");
  227                    
  228                    try
  229                    {
  230                             chain. doFilter(r equest, re sponse);                // the r emainder o f the serv let chain  and the se rvlet get  called wit hin here
  231                    }
  232                    catc h(Exceptio n ex)
  233                    {
  234                             // JMW  7/8/08 -  we want to  catch the  exception  so we can  put
  235                             // it  into the t ransaction  context ( if there i s no previ ous messag e).
  236                             if((tr ansactionC ontext.get ErrorMessa ge() == nu ll) ||
  237                                      (transac tionContex t.getError Message(). length() < = 0))
  238                             {
  239                                      // CPT 8 /14/08 - h andle "exc eption_cau se_message  == null"  case (e.g.  NullPoint erExceptio n)
  240                                      String m sg=null;
  241                                      try 
  242                                      {
  243                                               if(ex.getC ause() !=  null)
  244                                                       ms g = ex.get Cause().ge tMessage() ;
  245                                               else
  246                                                       ms g = ex.toS tring();
  247                                      }
  248                                      catch (E xception e
  249                                      {
  250                                               msg = "Und elegated E xception";
  251                                      }
  252                                      logger.i nfo("Caugh t exceptio n [" + msg  + "] in S ecurityFil ter and pu tting into  transacti on context ");
  253                                      transact ionContext .setErrorM essage(msg );
  254                                      transact ionContext .setExcept ionClassNa me(ex.getC lass().get SimpleName ());
  255                             }
  256                             if(ex. getClass()  == IOExce ption.clas s)
  257                             {
  258                                      throw (I OException )ex;
  259                             }
  260                             else 
  261                             {
  262                                      throw ne w ServletE xception(e x);
  263                             }
  264                    }
  265                    fina lly
  266                    {
  267                             //writ e the curr ent thread 's Transac tionContex t to the T ransaction  Log
  268                             logger .info("Wri ting entry  to transa ction log  for transa ction '" +  transacti onContext. getTransac tionId() +  "'");
  269                             
  270                             try 
  271                             {
  272                                      BaseWebF acadeRoute r router =  FacadeRou terUtility
  273                                                       .g etFacadeRo uter(BaseW ebFacadeRo uter.class );
  274                                      router.p ostTransac tionLogEnt ryImmediat e(new Tran sactionCon textLogEnt rySnapshot (transacti onContext) );
  275                             } catc h (Excepti on xAny) 
  276                             {
  277                                      logger.e rror("post Transactio nLogEntryI mmediate F ailed: "
  278                                                       +  xAny.getMe ssage());
  279                                      // don't  throw the  exception  so the cl ient doesn 't see it,  this tran saction wi ll just be  dropped
  280                                      //throw  new Servle tException (xAny);
  281                             }
  282  
  283                             // Cle ar the sec urity cont ext so tha t the thre ad has no  remaining
  284                             // ref erences an d has no
  285                             // est ablished s ecurity co ntext when  it is reu sed.
  286                             // Onc e the tran saction co ntext is c leared, ca lled to it  will do
  287                             // not hing but l og a warni ng (and re turn null)
  288                             transa ctionConte xt.clear() ;
  289                    }
  290           }
  291  
  292           /*
  293            *  (non-Java doc)
  294            *  
  295            *  @see java x.servlet. Filter#des troy()
  296            * /
  297           pu blic void  destroy()
  298           {
  299           }
  300  
  301   }