124. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/18/2018 3:37:04 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.

124.1 Files compared

# Location File Last Modified
1 CTT_DM2_v7.zip\VUID-rest\src\test\java\gov\vha\vuid\rest\session TestPrismeIntegratedUserService.java Tue Jun 12 16:41:57 2018 UTC
2 CTT_DM2_v7.zip\VUID-rest\src\test\java\gov\vha\vuid\rest\session TestPrismeIntegratedUserService.java Tue Jun 12 21:10:24 2018 UTC

124.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 4 416
Changed 3 6
Inserted 0 0
Removed 0 0

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

124.4 Active regular expressions

No regular expressions were active.

124.5 Comparison detail

  1   /**
  2    * Copyrig ht Notice
  3    *
  4    * This is  a work of  the U.S.  Government  and is no t subject  to copyrig ht
  5    * protect ion in the  United St ates. Fore ign copyri ghts may a pply.
  6    * 
  7    * License d under th e Apache L icense, Ve rsion 2.0  (the "Lice nse");
  8    * you may  not use t his file e xcept in c ompliance  with the L icense.
  9    * You may  obtain a  copy of th e License  at
  10    *
  11    * http:// www.apache .org/licen ses/LICENS E-2.0
  12    *
  13    * Unless  required b y applicab le law or  agreed to  in writing , software
  14    * distrib uted under  the Licen se is dist ributed on  an "AS IS " BASIS,
  15    * WITHOUT  WARRANTIE S OR CONDI TIONS OF A NY KIND, e ither expr ess or imp lied.
  16    * See the  License f or the spe cific lang uage gover ning permi ssions and
  17    * limitat ions under  the Licen se.
  18    */
  19  
  20   package go v.vha.vuid .rest.sess ion;
  21  
  22   import jav a.io.IOExc eption;
  23   import jav a.util.Has hSet;
  24   import jav a.util.Opt ional;
  25   import jav a.util.Set ;
  26   import jav ax.inject. Singleton;
  27   import org .apache.lo gging.log4 j.LogManag er;
  28   import org .apache.lo gging.log4 j.Logger;
  29   import org .glassfish .hk2.api.R ank;
  30   import org .jvnet.hk2 .annotatio ns.Service ;
  31   import com .fasterxml .jackson.c ore.JsonPa rseExcepti on;
  32   import com .fasterxml .jackson.d atabind.Js onMappingE xception;
  33   import gov .vha.isaac .ochre.api .User;
  34   import gov .vha.isaac .ochre.api .PrismeRol e;
  35   import gov .vha.vuid. rest.Appli cationConf ig;
  36  
  37   /**
  38    * 
  39    * {@link  TestPrisme Integrated UserServic e}
  40    *
  41    * @author  <a href=" mailto:joe l.kniaz.li st@gmail.c om">Joel K niaz</a>
  42    *
  43    */
  44   @Service(n ame="rest- prismeUser Service")
  45   @Rank(valu e = 20)
  46   @Singleton
  47   public cla ss TestPri smeIntegra tedUserSer vice exten ds PrismeI ntegratedU serService  implement s PrismeUs erService  {
  48           
  49           pr ivate stat ic Logger  log = LogM anager.get Logger(Tes tPrismeInt egratedUse rService.c lass);
  50           
  51           /* *
  52            *  
  53            * /
  54           pu blic TestP rismeInteg ratedUserS ervice() {
  55                    supe r();
  56           }
  57  
  58           /* *
  59            *  Return a  user and r oles avail able for t hat user
  60            *
  61            *  @param ss oToken
  62            *              the user 's SSO tok en string
  63            *  @return t he user an d roles av ailable to  the user
  64            *  
  65            *  This impl ementation  gets a Us er from PR ISME IFF T estPrismeI tnegratedU serService  is in cla sspath
  66            *  and prism e is reach able, othe rwise, att empts to p arse the t oken as a  test keywo rd from 
  67            *  (i.e. TES T_JSON1) O R to parse  a test st ring of th e form {na me}:{role1 }[{,role2} [{,role3}[ ...]]]
  68            * /
  69           pu blic Optio nal<User>  getUser(St ring ssoTo ken) {
  70                    
  71                    try  {
  72                             return  Optional. of(getUser FromPrisme (ssoToken) );
  73                    } ca tch (Excep tion e) {
  74                             log.in fo("Failed  to retrei ve user fr om prisme  with ssoTo ken '" + s soToken +  "'", e);
  75                             if (Ap plicationC onfig.getI nstance(). isDebugDep loy())
  76                             {
  77                                      //fallba ck to loca l parsing  for test p urposes
  78                                      try {
  79                                               log.info(" Using loca l sso toke n parsing" );
  80                                               return get UserFromTe stToken(ss oToken);
  81                                      } catch  (Exception  e1) {
  82                                               log.error( "Failed to  parse loc al test ss oToken '"  + ssoToken  + "'", e) ;
  83                                               return Opt ional.empt y();
  84                                      }
  85                             }
  86                             else
  87                             {
  88                                      return O ptional.em pty();
  89                             }
  90                    }
  91           }
  92           
  93           pu blic stati c final St ring TEST_ JSON1 = "{ \"roles\": ["
  94           +  "{\"id\":1 9990,\"nam e\":\"read _only\",\" resource_i d\":null,\ "resource_ type\":nul l,\"create d_at\":\"2 016-09-13T 14:48:18.0 00Z\",\"up dated_at\" :\"2016-09 -13T14:48: 18.000Z\"} "
  95           +  ","
  96           +  "{\"id\":1 9991,\"nam e\":\"edit or\",\"res ource_id\" :null,\"re source_typ e\":null,\ "created_a t\":\"2016 -09-13T14: 48:18.000Z \",\"updat ed_at\":\" 2016-09-13 T14:48:18. 000Z\"}"
  97           +  ","
  98           +  "{\"id\":1 9992,\"nam e\":\"revi ewer\",\"r esource_id \":null,\" resource_t ype\":null ,\"created _at\":\"20 16-09-13T1 4:48:18.00 0Z\",\"upd ated_at\": \"2016-09- 13T14:48:1 8.000Z\"}"
  99           +  ","
  100           +  "{\"id\":1 9993,\"nam e\":\"admi nistrator\ ",\"resour ce_id\":nu ll,\"resou rce_type\" :null,\"cr eated_at\" :\"2016-09 -13T14:48: 18.000Z\", \"updated_ at\":\"201 6-09-13T14 :48:18.000 Z\"}"
  101           +  ","
  102           +  "{\"id\":1 9994,\"nam e\":\"mana ger\",\"re source_id\ ":null,\"r esource_ty pe\":null, \"created_ at\":\"201 6-09-13T14 :48:18.000 Z\",\"upda ted_at\":\ "2016-09-1 3T14:48:18 .000Z\"}"
  103           +  ","
  104           +  "{\"id\":1 9995,\"nam e\":\"vuid _requestor \",\"resou rce_id\":n ull,\"reso urce_type\ ":null,\"c reated_at\ ":\"2016-0 9-13T14:48 :18.000Z\" ,\"updated _at\":\"20 16-09-13T1 4:48:18.00 0Z\"}"
  105           +  ","
  106           +  "{\"id\":1 9996,\"nam e\":\"appr over\",\"r esource_id \":null,\" resource_t ype\":null ,\"created _at\":\"20 16-09-13T1 4:48:18.00 0Z\",\"upd ated_at\": \"2016-09- 13T14:48:1 8.000Z\"}"
  107           +  "],\"token _parsed?\" :true,\"us er\":\"TES T\",\"type \":\"ssoi\ ",\"id\":1 0005}";
  108           pu blic stati c final St ring TEST_ JSON2 = "{ \"roles\": ["
  109           +  "{\"id\":1 0000,\"nam e\":\"read _only\",\" resource_i d\":null,\ "resource_ type\":nul l,\"create d_at\":\"2 016-09-13T 14:48:18.0 00Z\",\"up dated_at\" :\"2016-09 -13T14:48: 18.000Z\"} "
  110           +  "],\"token _parsed?\" :true,\"us er\":\" DN S      KniazJ\",\ "type\":\" ssoi\",\"i d\":10005} ";
  111           pu blic stati c final St ring TEST_ JSON3 = "{ \"roles\": ["
  112           +  "{\"id\":1 0000,\"nam e\":\"read _only\",\" resource_i d\":null,\ "resource_ type\":nul l,\"create d_at\":\"2 016-09-13T 14:48:18.0 00Z\",\"up dated_at\" :\"2016-09 -13T14:48: 18.000Z\"} "
  113           +  ","
  114           +  "{\"id\":1 9991,\"nam e\":\"edit or\",\"res ource_id\" :null,\"re source_typ e\":null,\ "created_a t\":\"2016 -09-13T14: 48:18.000Z \",\"updat ed_at\":\" 2016-09-13 T14:48:18. 000Z\"}"
  115           +  "],\"token _parsed?\" :true,\"us er\":\" DN S      EfronJ\",\ "type\":\" ssoi\",\"i d\":10005} ";
  116  
  117           /* *
  118            *  
  119            *  Attempt t o construc t a user f rom a stri ng of the  following  format:
  120            *  
  121            *  {name}:{r ole1}[{,ro le2}[{,rol e3}[...]]]
  122            *  
  123            *  @param ar g
  124            *  @return
  125            * /
  126           pr ivate Opti onal<Strin g> constru ctTestUser (String ar g) {
  127                    try  {
  128                             String [] compone nts = arg. split(":") ;
  129           
  130                             String  name = nu ll;
  131                             Set<Pr ismeRole>  roles = ne w HashSet< >();
  132                             if (co mponents.l ength == 2 ) {
  133                                      if (comp onents[0]. matches("[ A-Za-z][A- Za-z0-9_]* ")) {
  134                                               name = com ponents[0] .trim();
  135           
  136                                               String[] r oleStrings  = compone nts[1].spl it(",");
  137           
  138                                               for (int i  = 0; i <  roleString s.length;  ++i) {
  139                                                       ro les.add(Pr ismeRole.s afeValueOf (roleStrin gs[i].trim ()).get()) ;
  140                                               }
  141                                      }
  142                             }
  143                             
  144                             if (na me != null  && name.l ength() >  0 && roles .size() >  0) {
  145                                      StringBu ilder buil der = new  StringBuil der();
  146                                      builder. append("{\ "roles\":[ ");
  147                                      boolean  addedRole  = false;
  148                                      for (Pri smeRole ro le : roles ) {
  149                                               if (addedR ole) {
  150                                                       bu ilder.appe nd(",");
  151                                               }
  152                                               builder.ap pend("{\"i d\":19990, \"name\":\ "" + role. toString()  
  153                                               + "\",\"re source_id\ ":null,\"r esource_ty pe\":null, \"created_ at\":\"201 6-09-13T14 :48:18.000 Z\",\"upda ted_at\":\ "2016-09-1 3T14:48:18 .000Z\"}") ;
  154           
  155                                               addedRole  = true;
  156                                      }
  157                                      
  158                                      builder. append("], \"token_pa rsed?\":tr ue,\"user\ ":\"" + na me + "\",\ "type\":\" ssoi\",\"i d\":10005} ");
  159                                      
  160                                      return O ptional.of (builder.t oString()) ;
  161                             }
  162                    } ca tch (Excep tion e) {
  163                             // ign ore
  164                    }
  165           
  166                    retu rn Optiona l.empty();
  167           }
  168           
  169           pr ivate Opti onal<User>  getUserFr omTestToke n(String s soToken) t hrows Json ParseExcep tion, Json MappingExc eption, IO Exception  {
  170                    Stri ng jsonToU se = null;
  171           
  172                    Opti onal<Strin g> created Json = con structTest User(ssoTo ken);
  173                    if ( createdJso n.isPresen t()) {
  174                             jsonTo Use = crea tedJson.ge t();
  175                    } el se {
  176                             if (ss oToken.equ als(TEST_J SON1)) {
  177                                      jsonToUs e = TEST_J SON1;
  178                             } else  if (ssoTo ken.equals (TEST_JSON 2)) {
  179                                      jsonToUs e = TEST_J SON2;
  180                             } else  if (ssoTo ken.equals (TEST_JSON 3)) {
  181                                      jsonToUs e = TEST_J SON3;
  182                             } else  if (ssoTo ken.equals ("TEST_JSO N1") || ss oToken.equ als("TEST" )) {
  183                                      jsonToUs e = TEST_J SON1;
  184                             } else  if (ssoTo ken.equals ("TEST_JSO N2")) {
  185                                      jsonToUs e = TEST_J SON2;
  186                             } else  if (ssoTo ken.equals ("TEST_JSO N3")) {
  187                                      jsonToUs e = TEST_J SON3;
  188                             } else  {
  189                                      // Eithe r a real S SO token o r custom J SON
  190                                      jsonToUs e = ssoTok en;
  191                             }
  192                    }
  193           
  194                    /*
  195                     * E xample URL  for get_r oles_by_to ken
  196                      * URL url  = new URL( "https:// DNS                        /rails_pri sme/roles/ get_roles_ by_token.j son?token= " + token) ;
  197                     */
  198                    User  newUser =  null;
  199                    try  {
  200                             newUse r = UserSe rviceUtils .getUserFr omJson(jso nToUse, ss oToken);
  201                    } ca tch (Excep tion e) {
  202                             try {
  203                                      newUser  = UserServ iceUtils.g etUserFrom Json(TEST_ JSON1, sso Token);
  204                             } catc h (IOExcep tion e1) {
  205                                      throw ne w RuntimeE xception(e 1);
  206                             }
  207                    }
  208           
  209                    retu rn Optiona l.of(newUs er);
  210           }
  211   }