46. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/11/2019 10:54:09 AM 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.

46.1 Files compared

# Location File Last Modified
1 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\ccht\service\common\impl SecurityServiceImpl.java Wed May 29 15:26:30 2019 UTC
2 HTRE_P3_v14.5_iter_4_build_14.zip\java\gov\va\med\ccht\service\common\impl SecurityServiceImpl.java Mon Jun 10 19:19:21 2019 UTC

46.2 Comparison summary

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

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

46.4 Active regular expressions

No regular expressions were active.

46.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** *********
  2    * Copyrig ht � 2010  VHA. All r ights rese rved
  3    ********* ********** ********** ********** ********** ********** *********/
  4   package go v.va.med.c cht.servic e.common.i mpl;
  5  
  6   import jav a.util.Arr ayList;
  7   import jav a.util.Dat e;
  8   import jav a.util.Has hSet;
  9   import jav a.util.Lis t;
  10   import jav a.util.Set ;
  11  
  12   import org .apache.co mmons.lang 3.Validate ;
  13   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  14   import org .springfra mework.dao .DataAcces sException ;
  15   import org .springfra mework.lda p.Communic ationExcep tion;
  16   import org .springfra mework.sec urity.core .userdetai ls.Usernam eNotFoundE xception;
  17   import org .springfra mework.ste reotype.Se rvice;
  18  
  19   import gov .va.med.cc ht.model.S impleUser;
  20   import gov .va.med.cc ht.model.U ser;
  21   import gov .va.med.cc ht.model.t erminology .FederalHo liday;
  22   import gov .va.med.cc ht.persist ent.Securi tyDAO;
  23   import gov .va.med.cc ht.service .common.Me rgeService ;
  24   import gov .va.med.cc ht.service .common.Se curityServ ice;
  25   import gov .va.med.fw .model.Ent ityKey;
  26   import gov .va.med.fw .model.lda p.LdapPers on;
  27   import gov .va.med.fw .model.lda p.SearchCr iteria;
  28   import gov .va.med.fw .persisten t.DAOExcep tion;
  29   import gov .va.med.fw .security. Permission ;
  30   import gov .va.med.fw .security. Role;
  31   import gov .va.med.fw .security. RolePermis sion;
  32   import gov .va.med.fw .security. SimpleRole ;
  33   import gov .va.med.fw .security. UserPrinci pal;
  34   import gov .va.med.fw .service.A bstractCom ponent;
  35   import gov .va.med.fw .service.S erviceExce ption;
  36   import gov .va.med.fw .service.l dap.LdapPe rsonServic e;
  37  
  38   /**
  39    * Impleme nts the se curity ser vices to m anage syst em users a nd user pr ofiles
  40    * 
  41    * @author   DNS
  42    */
  43   @Service
  44   public cla ss Securit yServiceIm pl extends  AbstractC omponent i mplements  SecuritySe rvice {
  45  
  46           @A utowired
  47           pr ivate Ldap PersonServ ice ldapPe rsonServic e;
  48           @A utowired
  49           pr ivate Secu rityDAO se curityDAO;
  50           @A utowired
  51           pr ivate Merg eService m ergeServic e;
  52  
  53           /*
  54            *  (non-Java doc)
  55            *  
  56            *  @see
  57            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# getRole(go v.va.med.f w
  58            *  .model.En tityKey)
  59            * /
  60           pu blic Role  getRole(En tityKey<?>  entityKey ) throws S erviceExce ption {
  61                    Vali date.notNu ll(entityK ey);
  62                    Role  role = (R ole) secur ityDAO.get ByKey(enti tyKey);
  63                    retu rn role;
  64           }
  65  
  66           /*
  67            *  (non-Java doc)
  68            *  
  69            *  @see
  70            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# getRole(ja va.lang.St ring
  71            *  )
  72            * /
  73           pu blic Role  getRole(St ring roleN ame) throw s ServiceE xception {
  74                    Vali date.notNu ll(roleNam e);
  75                    try  {
  76                             return  (Role) se curityDAO. getRoleByN ame(roleNa me);
  77                    } ca tch (Excep tion e) {
  78                             throw  new Servic eException ("Security ServiceImp l.getRole:  Error whi le retriev ing Role",  e);
  79                    }
  80           }
  81           
  82           @O verride
  83           pu blic Role  getRoleByI d(long id)  {
  84                    retu rn securit yDAO.getRo leById(id) ;
  85           }        
  86           
  87           /*  * (non-Ja vadoc)
  88            *  
  89            *  @see
  90            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# getUser(ja va.lang.St ring
  91            *  )
  92            * /
  93           pu blic User  getUser(St ring userN ame) throw s ServiceE xception {
  94                    Vali date.notNu ll(userNam e);
  95                    User  user = nu ll;
  96                    // G et the use r from dat abase
  97                    try  {
  98                              user  = (User) s ecurityDAO .getUserBy Name(userN ame);
  99                    } ca tch (Usern ameNotFoun dException  e) {
  100                    }
  101                    catc h(Exceptio n e) {
  102                    
  103                    }
  104  
  105                    // i f user doe sn't exist  in DB cre ate atem u ser for cr eation and
  106                    // r eturn
  107                    if ( user == nu ll) {
  108                              retur n null;
  109                    }
  110  
  111                    retu rn user;
  112           }
  113  
  114           pu blic LdapP erson getL dapUser(St ring samAc ountName)  throws Ser viceExcept ion {
  115                    retu rn ldapPer sonService .findBySam AccountNam e(samAcoun tName);
  116           }
  117  
  118           pu blic Boole an authent icateLdapU ser(String  userDn, S tring pass word) thro ws Service Exception  {
  119                    try  {
  120                             if (ld apPersonSe rvice.auth enticate(u serDn, pas sword)) {
  121                                      return t rue;
  122                             } else  {
  123                                      return f alse;
  124                             }
  125                    } ca tch (Commu nicationEx ception e)  {
  126                             throw  new Servic eException ("Authenti cation Fai led", e);
  127                    }
  128           }
  129  
  130           /*
  131            *  (non-Java doc)
  132            *  
  133            *  @see
  134            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# createUser (gov.va.me d
  135            *  .ccht.ser vice.secur ity.User)
  136            * /
  137           pu blic void  createUser (User user ) throws S erviceExce ption {
  138                    // s ave user i n the ciss  database
  139                    try  {
  140                              // ma ke sure us er is a va lid ldap u ser
  141                              LdapP erson ldap Person = l dapPersonS ervice.fin dBySamAcco untName(us er.getName ());
  142                              if (l dapPerson  == null) {
  143                                               throw new  ServiceExc eption("In valid User  credentia ls");
  144                              }
  145                             // TOD O: Do we n eed this?  Is this an  OHRS requ irement?
  146                              //use r.setDisab led(ldapPe rson.isDis abled());
  147                              
  148                              // up date the u sername to  ldap retu rned user  id
  149                              user. setName(ld apPerson.g etSamAccou ntName());
  150                              user. setTelepho neNumber(l dapPerson. getTelepho neNumber() );
  151                              user. setEmail(l dapPerson. getEmail() );
  152                              // cr eate the n ew user in  the ciss  database
  153                             // TOD O: Do we n eed this?  Is this an  OHRS requ irement?
  154                              //upd ateRoles(u ser);
  155                              secur ityDAO.cre ateUser(us er);
  156                    } ca tch (DAOEx ception e)  {
  157                              throw  new Servi ceExceptio n("Securit yServiceIm pl.createU ser: Error  while cre ating the  User", e);
  158                    }
  159           }
  160  
  161           /*
  162            *  (non-Java doc)
  163            *  
  164            *  @see
  165            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# updateUser (gov.va.me d
  166            *  .ccht.ser vice.secur ity.User)
  167            * /
  168           pu blic void  updateUser (User user ) throws S erviceExce ption {
  169                    try  {
  170                             // upd ate user i n ccht dat abase
  171                             securi tyDAO.upda teUser(use r);
  172                    } ca tch (Excep tion e) {
  173                             logger .error("Er ror while  saving Use r " + user .getUserna me() + " I D: " + use r.getId(),  e);
  174                             throw  new Servic eException ("Error wh ile saving  User " +  user.getUs ername() +  " ID: " +  user.getI d(), e);
  175                    }
  176           }
  177           
  178           pu blic void  createRole (Role role ) throws S erviceExce ption {
  179                    try  {
  180                              secur ityDAO.per sist(role) ;
  181                    } ca tch (DataA ccessExcep tion dae)  {
  182                              throw  new Servi ceExceptio n("Securit yServiceIm pl.createR ole: faile d", dae);
  183                    }
  184           }
  185  
  186           /*
  187            *  (non-Java doc)
  188            *  
  189            *  @see
  190            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# updateRole (gov.va.me d
  191            *  .ccht.ser vice.secur ity.cchtRo le)
  192            * /
  193           pu blic void  updateRole (Role role ) throws S erviceExce ption {
  194  
  195                    try  {
  196                             List<S impleRole>  allRoles  = security DAO.findAl lSimpleRol es();
  197                             for (S impleRole  r : allRol es) {
  198                                      if (r.ge tName().tr im().equal sIgnoreCas e(role.get Name())
  199                                                       &&  (role.get Id() == nu ll || !rol e.getId(). equals(r.g etId())))
  200                                               throw new  ServiceExc eption("Du plicate ro le name fo und");
  201                             }
  202                             
  203                             if(rol e.getInter nalPermiss ions() ==  null){
  204                                      Set<Role Permission > emptySet  = new Has hSet<RoleP ermission> ();
  205                                      role.set InternalPe rmissions( emptySet);
  206                                      
  207                             }
  208                             
  209                             if (ro le.getId()  == null)  {
  210                                      
  211                                      security DAO.update Role(role) ;
  212                             } else  {
  213  
  214                                      Role old Role = sec urityDAO.g etRoleById (role.getI d());
  215                                      security DAO.delete RolePermis sionsFromR ole(oldRol e); // mus t delete o ld role Pe rmissions  first
  216                                      security DAO.update Role(role) ;
  217                             }
  218                                      
  219                    } ca tch (DAOEx ception e)  {
  220                             throw  new Servic eException ("Security ServiceImp l.updateRo le: failed ", e);
  221                    }
  222           }
  223  
  224           /*
  225            *  (non-Java doc)
  226            *  
  227            *  @see
  228            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# deleteRole (gov.va.me d
  229            *  .ccht.mod el.securit y.cchtRole )
  230            * /
  231           pu blic void  deleteRole (Role role ) throws S erviceExce ption {
  232                    // T ODO
  233                    try  {
  234                              secur ityDAO.rem ove(role);
  235                    } ca tch (Excep tion e) {
  236                              throw  new Servi ceExceptio n("Securit yServiceIm pl.deletRo le failed" , e);
  237                    }
  238           }
  239           
  240           @O verride
  241           pu blic List< Role> getA llRoles()  throws Ser viceExcept ion {
  242                    try  {
  243                             return  securityD AO.findAll Roles();
  244  
  245                    } ca tch (DAOEx ception e)  {
  246                             throw  new Servic eException ("getAvail ableRoleNa mes failed ", e);
  247                    }
  248           }
  249  
  250           pu blic List< FederalHol iday> getH olidays(in t year) th rows Servi ceExceptio n {
  251                    try  {
  252                             return  securityD AO.findHol idays(year );
  253                    } ca tch (DAOEx ception e)  {
  254                             throw  new Servic eException ("getHolid ays failed ", e);
  255                    }
  256           }
  257  
  258           pu blic List< SimpleRole > getAllSi mpleRoles( ) throws S erviceExce ption {
  259                    try  {
  260                             return  securityD AO.findAll SimpleRole s();
  261                    } ca tch (DAOEx ception e)  {
  262                             throw  new Servic eException ("getAvail ableRoles  failed", e );
  263                    }
  264           }
  265  
  266           pu blic List< SimpleRole > getAllDM PRoles() t hrows Serv iceExcepti on {
  267                    try  {
  268                             return  securityD AO.findAll DMPRoles() ;
  269                    } ca tch (DAOEx ception e)  {
  270                             throw  new Servic eException ("getAvail ableRoles  failed", e );
  271                    }
  272           }
  273  
  274           /* *
  275            *  Get Permi ssion name s associat ed with th e roles
  276            * /
  277           pu blic Set<S tring> get RolePermis sionNames( Set<Role>  roles) thr ows Servic eException  {
  278                    Set< String> pe rmissionNa mes = new  HashSet<St ring>();
  279                    if ( roles == n ull)
  280                             return  permissio nNames;
  281  
  282                    try  {
  283                             for (R ole role :  roles) {
  284                                      List<Str ing> permi ssions = s ecurityDAO .getRolePe rmissionNa mes(role.g etName());
  285                                      permissi onNames.ad dAll(permi ssions);
  286                             }
  287                             return  permissio nNames;
  288                    } ca tch (DAOEx ception e)  {
  289                             throw  new Servic eException ("getAvail ableRoleNa mes failed ", e);
  290                    }
  291           }
  292  
  293           /*
  294            *  (non-Java doc)
  295            *  
  296            *  @see
  297            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# updateFail edLogin(ja va
  298            *  .lang.Str ing)
  299            * /
  300           pu blic boole an updateF ailedLogin (String us erName) th rows Servi ceExceptio n {
  301                    try  {
  302                             // get  the user  and update
  303                             User u ser = secu rityDAO.ge tUserByNam e(userName );
  304                             if (us er != null  && user.g etId() !=  null) {
  305                                      // set f ailed logi n date
  306                                      // TimeZ one curren tTimeZone  =
  307                                      // TimeZ oneUtils.g etThreadCu rrentTimez one();
  308                                      // DateW ithTimeZon e dt = new
  309                                      // DateW ithTimeZon e(getTrans actinTime( ), current TimeZone);
  310                                      user.set LoginFaile dDate(new  Date());
  311                                      // incre ment faile d login co unt
  312                                      Short fa iledCount  = (short)  (user.getL oginFailed Count() ==  null ? 1  : user.get LoginFaile dCount().s hortValue( ) + 1);
  313                                      user.set LoginFaile dCount(fai ledCount);
  314  
  315                                      // lock  the accoun t if the f ailed coun t >=3
  316                                      if (user .getLoginF ailedCount ().intValu e() >= 3)  {
  317                                               if (!user. isAccountL ocked()) {
  318                                                       us er.setAcco untLockDat e(new Date ());
  319                                                       //  user.setA ccountLock ed(true);
  320                                               }
  321                                      }
  322                                      security DAO.update User(user) ;
  323                                      return u ser.isAcco untLocked( );
  324                             }
  325                             return  false;
  326  
  327                    } ca tch (Excep tion e) {
  328                             throw  new Servic eException ("Get All  Permission s Failed",  e);
  329                    }
  330           }
  331  
  332           pu blic void  updateSucc essFulLogi n(String u serName) t hrows Serv iceExcepti on {
  333                    upda teSuccessF ulLogin(us erName, nu ll);
  334           }
  335  
  336           /*
  337            *  (non-Java doc)
  338            *  
  339            *  @see
  340            *  gov.va.me d.ccht.ser vice.secur ity.Securi tyService# updateSucc essFulLogi n
  341            *  (java.lan g.String)
  342            * /
  343           pu blic void  updateSucc essFulLogi n(String u serName, S tring cred ential) th rows Servi ceExceptio n {
  344                    try  {
  345                             // get  the user  and update
  346                             User u ser = secu rityDAO.ge tUserByNam e(userName );
  347                             if (us er == null ) {
  348                                      user = n ew User(us erName);
  349                             }
  350                             if (cr edential ! = null) {
  351                                      user.set Password(c redential) ;
  352                                      user.get UserCreden tials().ha shUserCred entials();
  353                             }
  354                             update LoginDate( user);
  355  
  356                             securi tyDAO.upda teUser(use r);
  357                    } ca tch (Excep tion e) {
  358                             throw  new Servic eException ("updateSu ccessFulLo gin Failed ", e);
  359                    }
  360           }
  361  
  362           pr ivate void  updateLog inDate(Use r user) {
  363                    // s et success  login dat e
  364                    user .setLastLo ginDate(ne w Date());
  365                    // s et failed  login coun t to 0
  366                    user .setLoginF ailedCount ((short) 0 );
  367           }
  368  
  369           /*
  370            *  (non-Java doc)
  371            *  
  372            *  @see
  373            *  gov.va.me d.fw.secur ity.Securi tyService# updateSucc essFulLogi n(gov.va.m ed
  374            *  .fw.secur ity.UserPr incipal)
  375            * /
  376           pu blic void  updateSucc essFulLogi n(UserPrin cipal user Principal,  boolean u pdateRoles ) throws S erviceExce ption {
  377                    Vali date.notNu ll(userPri ncipal);
  378                    try  {
  379                             // get  the user  and update
  380                             User u ser = secu rityDAO.ge tUserByNam e(userPrin cipal.getU sername()) ;
  381                             if (us er == null  && userPr incipal in stanceof U ser) {
  382                                      user = ( User) user Principal;
  383                             } else  {
  384                                      user.get UserCreden tials().se tPassword( userPrinci pal.getPas sword());                                
  385                                      user.set FirstName( userPrinci pal.getFir stName());
  386                                      user.set MiddleName (userPrinc ipal.getMi ddleName() );
  387                                      user.set LastName(u serPrincip al.getLast Name());
  388                             }
  389  
  390                             user.g etUserCred entials(). hashUserCr edentials( );
  391                             update LoginDate( user);
  392  
  393                             securi tyDAO.upda teUser(use r);
  394                    } ca tch (Excep tion e) {
  395                             throw  new Servic eException ("updateSu ccessFulLo gin Failed ", e);
  396                    }
  397           }
  398  
  399           /*
  400            *  (non-Java doc)
  401            *  
  402            *  @see gov. va.med.cch t.service. security.S ecuritySer vice#getAl lPermissio ns()
  403            * /
  404           pu blic List< Permission > getAllPe rmissions( ) throws S erviceExce ption {
  405                    try  {
  406                             return  securityD AO.findAll Permission s();
  407                    } ca tch (DAOEx ception e)  {
  408                             throw  new Servic eException ("Get All  Permission s Failed",  e);
  409                    }
  410           }
  411  
  412           pu blic List< User> find AppUsers(S earchCrite ria search Criteria)  throws Ser viceExcept ion {
  413                    try  {
  414                             List<U ser> Users  = new Arr ayList<Use r>();
  415                             List<S impleUser>  users = s ecurityDAO .findAppUs ers(search Criteria);
  416                             if (us ers != nul l && users .size() >  0) {
  417                                      for (Sim pleUser pe rson : use rs) {
  418                                               Users.add( new User(p erson));
  419                                      }
  420                             }
  421                             return  Users;
  422                    } ca tch (DAOEx ception e)  {
  423                             throw  new Servic eException ("Security service:fi ndAppUsers  failed",  e);
  424                    }
  425           }
  426  
  427           pu blic UserP rincipal g etAuditUse r(String u serName) t hrows Serv iceExcepti on {
  428                    try  {
  429                             return  securityD AO.getAudi tUser(user Name);
  430                    } ca tch (DAOEx ception e)  {
  431                             throw  new Servic eException ("Security service:ge tAuditUser  failed",  e);
  432                    }
  433           }
  434  
  435           pu blic List< String> ge tUserIds()  throws Se rviceExcep tion {
  436                    try  {
  437                             return  securityD AO.getUser Ids();
  438                    } ca tch (Excep tion e) {
  439                             logger .error("Se curityServ ice.getUse rIds() fai led", e);
  440                             throw  new Servic eException ("Security Service.ge tUserIds()  failed",  e);
  441                    }
  442           }
  443  
  444           pu blic int u pdateUsers (List<Stri ng> userId s) throws  ServiceExc eption {
  445                    int  updateCoun t = 0;
  446                    try  {
  447                             if (us erIds != n ull && use rIds.size( ) > 0) {
  448                                      for (Str ing userId  : userIds ) {
  449                                               User user  = getUser( userId);
  450                                               if (user ! = null) {
  451                                                       up dateUser(u ser);
  452                                                       up dateCount  = updateCo unt + 1;
  453                                               } else {
  454                                                       lo gger.info( "SecurityS ervice.upd ateUsers() : User not  found for  UserId =  " + userId );
  455                                               }
  456                                      }
  457                             }
  458                    } ca tch (Excep tion e) {
  459                             logger .error("Se curityServ ice.update Users(): f ailed", e) ;
  460                             throw  new Servic eException ("Security Service.up dateUsers( ): failed" , e);
  461                    }
  462                    retu rn updateC ount;
  463           }
  464  
  465           pu blic List< User> getS ubmittedRe gistration s(Integer  visnId, In teger faci lityId) th rows Servi ceExceptio n {
  466                    try  {
  467                             return  securityD AO.getSubm ittedRegis trations(v isnId, fac ilityId);
  468                    } ca tch (Excep tion e) {
  469                             logger .error("Se curityServ ice.getSub mittedRegi strations( ): failed" , e);
  470                             throw  new Servic eException ("Security Service.ge tSubmitted Registrati ons(): fai led", e);
  471                    }
  472           }
  473           
  474           pu blic List< User> getN ewRegistra tions(Inte ger visnId , Integer  facilityId ) throws S erviceExce ption {
  475                    try  {
  476                             return  securityD AO.getNewR egistratio ns(visnId,  facilityI d);
  477                    } ca tch (Excep tion e) {
  478                             logger .error("Se curityServ ice.getNew Registrati ons(): fai led", e);
  479                             throw  new Servic eException ("Security Service.ge tNewRegist rations():  failed",  e);
  480                    }
  481           }
  482  
  483           pu blic List< User> getS ubmittedRe gistration sForDmp(In teger visn Id, Intege r facility Id) throws  ServiceEx ception {
  484                    try  {
  485                             return  securityD AO.getSubm ittedRegis trationsFo rDmp(visnI d, facilit yId);
  486                    } ca tch (Excep tion e) {
  487                             logger .error("Se curityServ ice.getSub mittedRegi strationsF orDmp(): f ailed", e) ;
  488                             throw  new Servic eException ("Security Service.ge tSubmitted Registrati onsForDmp( ): failed" , e);
  489                    }
  490           }
  491  
  492           pu blic Secur ityDAO get SecurityDA O() {
  493                    retu rn securit yDAO;
  494           }
  495  
  496           pu blic void  setSecurit yDAO(Secur ityDAO sec urityDAO)  {
  497                    this .securityD AO = secur ityDAO;
  498           }
  499  
  500           pu blic LdapP ersonServi ce getLdap PersonServ ice() {
  501                    retu rn ldapPer sonService ;
  502           }
  503  
  504           pu blic void  setLdapPer sonService (LdapPerso nService l dapPersonS ervice) {
  505                    this .ldapPerso nService =  ldapPerso nService;
  506           }
  507  
  508           pu blic Merge Service ge tMergeServ ice() {
  509                    retu rn mergeSe rvice;
  510           }
  511  
  512           pu blic void  setMergeSe rvice(Merg eService m ergeServic e) {
  513                    this .mergeServ ice = merg eService;
  514           }
  515  
  516           @O verride
  517           pu blic List< User> getU sersByVisn (int visnI d) {
  518                    retu rn securit yDAO.getUs ersByVisn( visnId);
  519           }
  520   }