211. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 9/15/2018 10:48:58 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.

211.1 Files compared

# Location File Last Modified
1 MHV_2018.4.0.0.zip\2018.4.0.0\national portal\mhv_source\mhv_vamf\mhv-vamf-portal-portlet\src\main\java\gov\va\med\mhv\vamf\util VamfJwtUtility.java Thu Aug 23 21:31:40 2018 UTC
2 MHV_2018.4.0.0.zip\2018.4.0.0\national portal\mhv_source\mhv_vamf\mhv-vamf-portal-portlet\src\main\java\gov\va\med\mhv\vamf\util VamfJwtUtility.java Sat Sep 15 23:50:18 2018 UTC

211.2 Comparison summary

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

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

211.4 Active regular expressions

No regular expressions were active.

211.5 Comparison detail

  1   /**
  2    * 
  3    */
  4   package go v.va.med.m hv.vamf.ut il;
  5  
  6   import jav a.text.Sim pleDateFor mat;
  7   import jav a.util.Arr ays;
  8   import jav a.util.Cal endar;
  9   import jav a.util.Dat e;
  10   import jav a.util.Lis t;
  11   import jav a.util.UUI D;
  12  
  13   import org .apache.co mmons.code c.binary.B ase64;
  14   import org .apache.co mmons.logg ing.Log;
  15   import org .apache.co mmons.logg ing.LogFac tory;
  16  
  17   import com .auth0.jwt .JWT;
  18   import com .auth0.jwt .algorithm s.Algorith m;
  19   import com .auth0.jwt .interface s.DecodedJ WT;
  20   import com .google.gs on.Gson;
  21   import com .google.gs on.GsonBui lder;
  22   import com .google.gs on.JsonEle ment;
  23   import com .google.gs on.JsonPar ser;
  24  
  25  
  26   /**
  27    * @author   DNS
  28    *
  29    */
  30   public cla ss VamfJwt Utility {
  31           
  32           pr ivate stat ic final L og LOG = L ogFactory. getLog(Vam fJwtUtilit y.class);
  33           
  34           pr ivate stat ic final S tring DF_J WT_DOB = " yyyy-MM-dd ";
  35           
  36           pr ivate Algo rithm sign ingAlgorit hm;
  37           
  38           pr ivate Stri ng issuerI d;
  39           
  40           pr ivate Inte ger notBef oreMinutes ;
  41           
  42           pr ivate Inte ger expire sAfterMinu tes;
  43           
  44           pu blic VamfJ wtUtility( String iss uerId, Int eger notBe foreMinute s, Integer  expireAft erMinutes,  String pr ivateKey)  {
  45                    this .issuerId  = issuerId ;
  46                    this .notBefore Minutes =  notBeforeM inutes;
  47                    this .expiresAf terMinutes  = expireA fterMinute s;
  48                    this .signingAl gorithm =  Algorithm. RSA512(Jwt Signer.loa dPrivateKe y(privateK ey));
  49           }
  50           
  51           pu blic Strin g createMo bileWebTok en(String  firstName,  String mi ddleName,  String las tName, Str ing icn, S tring ssn,  String em ail, Strin g gender,  Date birth Date, Stri ng mhvId,  String aut henticatio nAuthority , String m hvSessionI d) {
  52                    
  53                    Stri ng jwtGend er = "";
  54                    if(g ender != n ull) {
  55                             if("Fe male".equa lsIgnoreCa se(gender) ) {
  56                                      jwtGende r = "F";
  57                             }
  58                             else i f("Male".e qualsIgnor eCase(gend er)) {
  59                                      jwtGende r = "M";
  60                             }
  61                    }
  62                    
  63                    Stri ng jwtAuth entication Authority  = "";
  64                    if(a uthenticat ionAuthori ty != null ) {
  65                             if(aut henticatio nAuthority .toUpperCa se().conta ins("DSLOG ON")) {
  66                                      jwtAuthe nticationA uthority =  "DSLOGON" ;
  67                             }
  68                             else {
  69                                      jwtAuthe nticationA uthority =  "MHV";
  70                             }
  71                    }
  72                    
  73                    if(L OG.isDebug Enabled())  {
  74                             LOG.de bug(String .format("C reating mo bile web t oken with  paramters  First Name : %s, Last  Name: %s,  ICN: %s,  Email: %s,  MHV ID: % s.", 
  75                                               firstName,  lastName,  icn, emai l, mhvId)) ;
  76                    }
  77                    
  78                    // s etup some  dates used  when crea ting the w eb token
  79                    Cale ndar expir eAfter = C alendar.ge tInstance( );
  80                    expi reAfter.ad d(Calendar .MINUTE, e xpiresAfte rMinutes);
  81                    
  82                    Cale ndar notBe fore = Cal endar.getI nstance();
  83                    notB efore.add( Calendar.M INUTE, (-1  * notBefo reMinutes) );
  84                    
  85                    
  86                    Stri ng dob = ( birthDate  != null) ?  new Simpl eDateForma t(DF_JWT_D OB).format (birthDate ) : "";
  87                    
  88                    if(L OG.isDebug Enabled())  {
  89                             LOG.de bug(String .format("C urrent Tim e: %s, Not  Before: % s, JWT Exp ire After:  %s", new  Date(), no tBefore.ge tTime(), e xpireAfter .getTime() ));
  90                    }
  91                    
  92                    // c reate the  input JSON  web token
  93                    Stri ng token =  JWT.creat e()
  94                                      .withCla im(VamfJwt ClaimsCons tants.AUTH ENTICATED,  Boolean.T RUE)
  95                    .wit hClaim(Vam fJwtClaims Constants. USER_FIRST _NAME, fir stName)
  96                    .wit hClaim(Vam fJwtClaims Constants. USER_LAST_ NAME, last Name)
  97                    .wit hClaim(Vam fJwtClaims Constants. USER_MIDDL E_NAME, (m iddleName= =null)?"": middleName )
  98                    .wit hClaim(Vam fJwtClaims Constants. USER_ICN,  icn)
  99                    .wit hClaim(Vam fJwtClaims Constants. ID_TYPE, " ICN")
  100                    .wit hClaim(Vam fJwtClaims Constants. USER_SSN,  ssn)
  101                    .wit hClaim(Vam fJwtClaims Constants. USER_EMAIL _ADDRESS,( email==nul l)?"":emai l)
  102                    .wit hClaim(Vam fJwtClaims Constants. USER_SOURC E, "MHV")
  103                    .wit hClaim(Vam fJwtClaims Constants. AUTHENTICA TION_AUTHO RITY, jwtA uthenticat ionAuthori ty)
  104                    .wit hClaim(Vam fJwtClaims Constants. USER_GENDE R, jwtGend er)
  105                    .wit hClaim(Vam fJwtClaims Constants. USER_BIRTH _DATE, dob )
  106                    .wit hClaim(Vam fJwtClaims Constants. MHV_SESSIO N_ID, mhvS essionId)
  107                    .wit hArrayClai m(VamfJwtC laimsConst ants.AUTH_ ROLES_CLAI M,new Stri ng[]{VamfJ wtClaimsCo nstants.AU TH_ROLE_VE TERAN})
  108                    .wit hJWTId(UUI D.randomUU ID().toStr ing())
  109                    .wit hSubject(i cn) //  wa s mhvId
  110                    .wit hIssuer(is suerId)
  111                    .wit hExpiresAt (expireAft er.getTime ())
  112                    .wit hNotBefore (notBefore .getTime() )
  113                    .sig n(signingA lgorithm);
  114                    
  115                    if(L OG.isDebug Enabled())  {
  116                             LOG.de bug(String .format("M HV JWT Gen erated Tok en:\n%s",  prettyPars eJwt(token )));
  117                    }
  118                    
  119                    retu rn token;
  120           }
  121           
  122           pu blic boole an isToken Invalid(St ring userV amfJsonWeb Token) {
  123                    
  124                    Deco dedJWT jwt  = JWT.dec ode(userVa mfJsonWebT oken);
  125                    Long  notBefore  = jwt.get NotBefore( ).getTime( );
  126                    Long  expiratio n = jwt.ge tExpiresAt ().getTime ();
  127                    Long  now = Sys tem.curren tTimeMilli s();
  128           
  129                    retu rn now < n otBefore | | expirati on < now; 
  130           }
  131           
  132           pr ivate Stri ng prettyP arseJwt(St ring jwt){
  133                    Gson  gson = ne w GsonBuil der().setP rettyPrint ing().crea te();
  134           re turn gson. toJson(get JsonElemen t(jwt));
  135       }
  136           
  137           pr ivate Json Element ge tJsonEleme nt(String  encodedJwt ) {
  138           Li st<String>  jwtSectio ns = Array s.asList(e ncodedJwt. split("\\. "));
  139           if (jwtSectio ns.size()  != 3) thro w new Ille galArgumen tException ("Did find  the stand ard 3-sect ion JWT en coded stri ng.");
  140           St ring paylo ad = new S tring(Base 64.decodeB ase64(jwtS ections.ge t(1).getBy tes()));
  141           Js onParser p arser = ne w JsonPars er();
  142           re turn parse r.parse(pa yload);
  143           }
  144   }