4259. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/9/2017 3:51:24 PM Eastern 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.

4259.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:51:24 2017 UTC
2 eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-web\src\main\java\gov\va\nvap\web\app PermissionAppFilter.java Fri Apr 21 20:15:58 2017 UTC

4259.2 Comparison summary

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

4259.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

4259.4 Active regular expressions

No regular expressions were active.

4259.5 Comparison detail

        1   /*
        2    * To chan ge this te mplate, ch oose Tools  | Templat es
        3    * and ope n the temp late in th e editor.
        4    */
        5  
        6   package go v.va.nvap. web.app;
        7  
        8   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        9   import gov .va.nvap.s vc.consent mgmt.stub. dao.Descri ptorDAO;
        10   import gov .va.nvap.s vc.consent mgmt.stub. data.Descr iptor;
        11   import gov .va.nvap.s vc.facilit y.data.Fac ility;
        12   import gov .va.nvap.w eb.dao.All owedRoleDA O;
        13   import gov .va.nvap.w eb.dao.Use rRoleDAO;
        14   import gov .va.nvap.w eb.helper. facility.F acilityHel per;
        15   import gov .va.nvap.w eb.user.Us er;
        16   import gov .va.nvap.w eb.user.ro le.UserNam eException ;
        17   import gov .va.nvap.w eb.user.ro le.UserRol eException ;
        18  
        19   import jav a.io.IOExc eption;
        20   import jav a.io.Print Stream;
        21   import jav a.io.Print Writer;
        22   import jav a.io.Strin gWriter;
        23   import jav a.util.Has hMap;
        24   import jav a.util.Lis t;
        25  
        26   import jav ax.servlet .Filter;
        27   import jav ax.servlet .FilterCha in;
        28   import jav ax.servlet .FilterCon fig;
        29   import jav ax.servlet .ServletEx ception;
        30   import jav ax.servlet .ServletRe quest;
        31   import jav ax.servlet .ServletRe sponse;
        32   import jav ax.servlet .http.Http ServletRes ponse;
        33   import jav a.util.log ging.Level ;
        34   import jav a.util.log ging.Logge r;
        35   import jav ax.servlet .http.Cook ie;
        36   import jav ax.servlet .http.Http ServletReq uest;
        37   import jav ax.servlet .http.Http Session;
        38   import org .apache.co mmons.logg ing.Log;
        39   import org .apache.co mmons.logg ing.LogFac tory;
        40   import org .springfra mework.web .context.W ebApplicat ionContext ;
        41   import org .springfra mework.web .context.s upport.Web Applicatio nContextUt ils;
        42  
        43   /**
        44    * A filte r to proce ss errors.
        45    *
        46    * @author  David Vaz quez
        47    */
        48   public cla ss Permiss ionAppFilt er impleme nts Filter  {
        49       privat e static f inal Log L OG = LogFa ctory.getL og(Permiss ionAppFilt er.class);
        50       privat e static f inal Strin g VA_USERN AME = "adS amAccountN ame";
        51       privat e static f inal Strin g LOGOUT_P ATH = "Log out.do_sec ";
        52  
        53       protec ted WebApp licationCo ntext webA pplication Context;
        54  
        55           pu blic stati c String g etStackTra ce(final T hrowable t ) {
        56                    Stri ng stackTr ace = null ;
        57                    try  {
        58                             final  StringWrit er sw = ne w StringWr iter();
        59                             final  PrintWrite r pw = new  PrintWrit er(sw);
        60                             t.prin tStackTrac e(pw);
        61                             pw.clo se();
        62                             sw.clo se();
        63                             stackT race = sw. getBuffer( ).toString ();
        64                    } ca tch (final  Exception  ex) {
        65                    }
        66                    retu rn stackTr ace;
        67           }
        68  
        69           pu blic Permi ssionAppFi lter() {
        70           }
        71  
        72           @O verride
        73           pu blic void  destroy()  {
        74           }
        75  
        76           pr ivate void  doAfterPr ocessing(f inal Servl etRequest  request,
        77                             final  ServletRes ponse resp onse) thro ws IOExcep tion,
        78                             Servle tException  {
        79           }
        80  
        81           pr ivate bool ean doBefo reProcessi ng(final S ervletRequ est reques t,
        82                             final  ServletRes ponse resp onse) thro ws IOExcep tion,
        83                             Servle tException  {
        84                    // D o not cach e any page s
        85                    bool ean ret;
        86                    fina l HttpServ letRespons e resp = ( HttpServle tResponse)  response;
        87                    resp .setHeader ("Cache-co ntrol", "n o-cache");
        88                    resp .setHeader ("Expires" , "0");
        89                    ret  = true;
        90                    retu rn ret;
        91           }
        92  
        93           @O verride
        94           pu blic void  doFilter(f inal Servl etRequest  request,
        95                             final  ServletRes ponse resp onse, fina l FilterCh ain chain)
        96                             throws  IOExcepti on, Servle tException  {
        97  
        98           //  If attemp ting to lo gout, skip  filter
        99           if  (((HttpSe rvletReque st)request ).getServl etPath().c ontains(LO GOUT_PATH) ) {
        100                chain.do Filter(req uest, resp onse);
        101                return;
        102           }
        103  
        104                    if ( this.doBef oreProcess ing(reques t, respons e)) {
        105                             Throwa ble proble m = null;
        106                             try {
        107                    // G et session  from requ est for us er and che ck if perm itted
        108                    Http ServletReq uest httpR equest = ( HttpServle tRequest)  request;
        109                    Http Session se ssion = ht tpRequest. getSession ();
        110  
        111                    User  user = (U ser) sessi on.getAttr ibute("use r");
        112                    if ( user == nu ll) {
        113                         user = new  User();
        114                    }
        115  
        116                    user .setName(h ttpRequest .getHeader (VA_USERNA ME));
        117                    if ( !user.hasN ame()) thr ow new Use rNameExcep tion("User NameExcept ion");
        118                    user .setName(u ser.getNam e().toLowe rCase());
        119  
        120                    if ( !user.hasR oles()) {
        121                         // Attempt  to use us er name to  get user  roles
        122                         List<Strin g> userRol es = this. getUserRol eDAO().fin dUserRoleN ames(user. getName()) ;
        123                         user.setRo les(userRo les);
        124  
        125                         if (!user. hasRoles() ) {
        126                             throw  new UserRo leExceptio n("UserRol eException ");
        127                         }
        128                    }
        129  
        130                    if ( !this.getA llowedRole DAO().cont ainsAllowe dRole(user .getRoles( ))) {
        131                         throw new  UserRoleEx ception("U serRoleExc eption");
        132                    }
        133  
        134                    // S et User ob ject in se ssion
        135                    sess ion.setAtt ribute("us er", user) ;
        136  
        137                    //ok ay we've m ade it thi s far, so  we had bet ter put th e descript ors back i nto the se ssion
        138                    this .addDescri ptors(sess ion);
        139  
        140                    // S et the def ault facil ity sessio n atrribut e and cook ie
        141                    this .setDefaul tFacility( (HttpServl etRequest) request, ( HttpServle tResponse) response);
        142  
        143                    // I f user rol e is permi tted, cont inue with  the filter  chain
        144                    chai n.doFilter (request,  response);
        145                             } catc h (final I OException  | Servlet Exception  t) {
        146                                      // If an  exception  is thrown  somewhere  down the  filter cha in,
        147                                      // we st ill want t o execute  our after  processing , and then
        148                                      // rethr ow the pro blem after  that.
        149                                      problem  = t;
        150                                      t.printS tackTrace( );
        151                             }
        152  
        153                             this.d oAfterProc essing(req uest, resp onse);
        154  
        155                             // If  there was  a problem,  we want t o rethrow  it if it i s
        156                             // a k nown type,  otherwise  log it.
        157                             if (pr oblem != n ull) {
        158                                      if (prob lem instan ceof Servl etExceptio n) {
        159                                               throw (Ser vletExcept ion) probl em;
        160                                      }
        161                                      if (prob lem instan ceof IOExc eption) {
        162                                               throw (IOE xception)  problem;
        163                                      }
        164                                      this.sen dProcessin gError(pro blem, resp onse);
        165                             }
        166                    }
        167           }
        168  
        169           /* *
        170            *  Init meth od for thi s filter
        171            * /
        172           @O verride
        173           pu blic void  init(final  FilterCon fig filter Config) {
        174           th is.webAppl icationCon text =
        175                    WebA pplication ContextUti ls.getRequ iredWebApp licationCo ntext(filt erConfig.g etServletC ontext());
        176           }
        177  
        178           pr ivate void  sendProce ssingError (final Thr owable t,
        179                             final  ServletRes ponse resp onse) {
        180                    fina l String s tackTrace  = Permissi onAppFilte r.getStack Trace(t);
        181  
        182                    if ( NullChecke r.isNotEmp ty(stackTr ace)) {
        183                             try {
        184                                      response .setConten tType("tex t/html");
        185                                      final Pr intStream  ps = new P rintStream (
        186                                                       re sponse.get OutputStre am());
        187                                      final Pr intWriter  pw = new P rintWriter (ps);
        188                                      pw.print ("<html>\n <head>\n<t itle>Error </title>\n </head>\n< body>\n");  // NOI18N
        189  
        190                                      // PENDI NG! Locali ze this fo r next off icial rele ase
        191                                      pw.print ("<h1>The  resource d id not pro cess corre ctly</h1>\ n<pre>\n") ;
        192                                      pw.print (stackTrac e);
        193                                      pw.print ("</pre></ body>\n</h tml>"); //  NOI18N
        194                                      pw.close ();
        195                                      ps.close ();
        196                                      response .getOutput Stream().c lose();
        197                             } catc h (final E xception e x) {
        198                             }
        199                    } el se {
        200                             try {
        201                                      final Pr intStream  ps = new P rintStream (
        202                                                       re sponse.get OutputStre am());
        203   //                                 t.printS tackTrace( ps);
        204                                      Logger.g etLogger(P ermissionA ppFilter.c lass.getNa me()).log( Level.INFO , "The res ource proc essed corr ectly");
        205                                      ps.close ();
        206                                      response .getOutput Stream().c lose();
        207                             } catc h (final E xception e x) {
        208                             }
        209                    }
        210           }
        211  
        212           @O verride
        213           pu blic Strin g toString () {
        214                    fina l StringBu ffer sb =  new String Buffer("Pe rmissionAp pFilter()" );
        215                    retu rn (sb.toS tring());
        216           }
        217  
        218       privat e void set DefaultFac ility(Http ServletReq uest reque st, HttpSe rvletRespo nse respon se) {
        219           //  get User' s default  facility f rom cookie  or from V HAUserId a nd set it  for the se ssion
        220           Fa cility def aultUserFa cility = n ull;
        221           Co okie[] vap Cookies =  request.ge tCookies() ;
        222           bo olean cook ieExists =  false;
        223           if  (vapCooki es != null ){
        224                for (Coo kie vapCoo kie : vapC ookies){
        225                    if ( vapCookie. getName(). equals("fa cility")){
        226                         if (NullCh ecker.isNo tEmpty(vap Cookie.get Value()))  {
        227                             defaul tUserFacil ity = new  Facility() ;
        228                             try {
        229                                 Fa cility fac ility = th is.getFaci lityHelper ().getFaci lityByStat ionId(vapC ookie.getV alue());
        230                                 if  (facility  != null)  {
        231                                      defaultU serFacilit y.setFacil ityStation (facility. getFacilit yStation() );
        232                                      defaultU serFacilit y.setFacil ityName(fa cility.get FacilityNa me());
        233                                      defaultU serFacilit y.setVisnI d(facility .getVisnId ());
        234  
        235                                      cookieEx ists = tru e;
        236                                 }
        237                             } catc h (Excepti on e) {
        238                                 //  Cookie mu st contain  an invali d station  number. We 'll ignore  the error  and set t he default  facility
        239                                 //  based on  the user I D.
        240                             }
        241                         }
        242                    }
        243                }
        244           }
        245  
        246           if  (NullChec ker.isEmpt y(defaultU serFacilit y)) {
        247                // Get t he Default  Facility  by user id
        248                defaultU serFacilit y = this.g etFacility Helper().g etFacility StationByV HAUserId(
        249                             reques t.getHeade r(VA_USERN AME));
        250           }
        251  
        252           if  (NullChec ker.isNotE mpty(defau ltUserFaci lity)) {
        253                request. getSession ().setAttr ibute("def aultUserFa cility", d efaultUser Facility);
        254  
        255                if (!coo kieExists)  {
        256                    resp onse.addCo okie(setFa cilityCook ie(default UserFacili ty));
        257                }
        258           }
        259       }
        260  
        261       privat e Cookie s etFacility Cookie(Fac ility newD efaultFaci lity) {
        262  
        263                    Cook ie vapCook ie = null;
        264                    if ( newDefault Facility ! = null) {
        265                             if (ne wDefaultFa cility.get FacilitySt ation().eq uals(""))  {
        266                                      vapCooki e = new Co okie("faci lity", "") ;
        267                                      vapCooki e.setMaxAg e(0);
        268                             } else  if (isAlp haNumeric( newDefault Facility.g etFacility Station()) ) {
        269                                      vapCooki e = new Co okie("faci lity", new DefaultFac ility.getF acilitySta tion());
        270                                      vapCooki e.setMaxAg e(5 * 365  * 24 * 60  * 60);
        271                             }
        272                    }
        273                    retu rn vapCook ie;
        274           }
        275  
        276       privat e boolean  isAlphaNum eric(Strin g s){
        277           St ring patte rn= "^[a-z A-Z0-9]*$" ;
        278  
        279           re turn s.mat ches(patte rn);
        280       }
        281  
        282       public  FacilityH elper getF acilityHel per() {
        283                    fina l Facility Helper fac ilityHelpe r = this.g etBean("fa cilityHelp er",
        284                                      Facility Helper.cla ss);
        285                    retu rn facilit yHelper;
        286           }
        287  
        288       privat e AllowedR oleDAO get AllowedRol eDAO() {
        289           re turn this. getBean("A llowedRole DAO", Allo wedRoleDAO .class);
        290       }
        291  
        292       privat e UserRole DAO getUse rRoleDAO()  {
        293           re turn this. getBean("U serRoleDAO ", UserRol eDAO.class );
        294       }
        295  
        296       privat e Descript orDAO getD escriptorD AO() {
        297           re turn this. getBean("D escriptorD AO", Descr iptorDAO.c lass);
        298       }
        299  
        300       privat e void add Descriptor s(HttpSess ion sessio n) {
        301           Li st<Descrip tor> dees  = this.get Descriptor DAO().getA ll();
        302           Ha shMap hm =  new HashM ap();
        303  
        304           fo r(Descript or d : dee s) {
        305                hm.put(d .getName() , d.getTex t());
        306           }
        307  
        308           se ssion.setA ttribute(" descriptor s", hm);
        309       }
        310  
        311       public  <E> E get Bean(final  String be anID, fina l Class<E>  clazz) {
        312                    retu rn clazz.c ast(this.w ebApplicat ionContext .getBean(b eanID));
        313           }
        314   }