144. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/13/2018 10:35:23 AM Eastern Standard 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.

144.1 Files compared

# Location File Last Modified
1 v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\ccht\persistent\hibernate SecurityDAOImpl.java Fri Dec 7 17:36:32 2018 UTC
2 v12.5_iter_7_build 51.zip\TRM_Upgrade\src\main\java\gov\va\med\ccht\persistent\hibernate SecurityDAOImpl.java Wed Dec 12 22:33:38 2018 UTC

144.2 Comparison summary

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

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

144.4 Active regular expressions

No regular expressions were active.

144.5 Comparison detail

  1   /********* ********** ********** ********** ********** ********** *********
  2    * Copyrig ht � 2010  VHA. All r ights rese rved
  3    ********* ********** ********** ********** ********** ********** *********/
  4   package go v.va.med.c cht.persis tent.hiber nate;
  5  
  6   import jav a.util.Arr ayList;
  7   import jav a.util.Col lection;
  8   import jav a.util.Has hMap;
  9   import jav a.util.Has hSet;
  10   import jav a.util.Lis t;
  11   import jav a.util.Map ;
  12   import jav a.util.Set ;
  13  
  14   import jav ax.persist ence.NoRes ultExcepti on;
  15   import jav ax.persist ence.Query ;
  16  
  17   import org .apache.co mmons.lang .StringUti ls;
  18   import org .apache.co mmons.lang .Validate;
  19   import org .apache.lo g4j.Logger ;
  20   import org .hibernate .Session;
  21   import org .hibernate .SessionFa ctory;
  22   import org .springfra mework.bea ns.factory .annotatio n.Autowire d;
  23   import org .springfra mework.sec urity.core .GrantedAu thority;
  24   import org .springfra mework.sec urity.core .authority .SimpleGra ntedAuthor ity;
  25   import org .springfra mework.sec urity.core .userdetai ls.UserDet ails;
  26   import org .springfra mework.sec urity.core .userdetai ls.Usernam eNotFoundE xception;
  27   import org .springfra mework.ste reotype.Re pository;
  28   import org .springfra mework.tra nsaction.a nnotation. Transactio nal;
  29  
  30   import gov .va.med.cc ht.model.S impleUser;
  31   import gov .va.med.cc ht.model.U ser;
  32   import gov .va.med.cc ht.model.U serRole;
  33   import gov .va.med.cc ht.model.c ommon.Simp leFacility ;
  34   import gov .va.med.cc ht.model.c ommon.Simp leVisn;
  35   import gov .va.med.cc ht.model.c ommon.Vend or;
  36   import gov .va.med.cc ht.model.t erminology .FederalHo liday;
  37   import gov .va.med.cc ht.model.t erminology .Registrat ionStatus;
  38   import gov .va.med.cc ht.persist ent.Securi tyDAO;
  39   import gov .va.med.fw .model.Ent ityKey;
  40   import gov .va.med.fw .model.Use rPrincipal Impl;
  41   import gov .va.med.fw .model.lda p.SearchCr iteria;
  42   import gov .va.med.fw .persisten t.DAOExcep tion;
  43   import gov .va.med.fw .security. Permission ;
  44   import gov .va.med.fw .security. Role;
  45   import gov .va.med.fw .security. RolePermis sion;
  46   import gov .va.med.fw .security. SimpleRole ;
  47   import gov .va.med.fw .security. UserPrinci pal;
  48  
  49   /**
  50    * 
  51    * 
  52    * @author   DNS
  53    */
  54   @Repositor y
  55   @Transacti onal
  56   public cla ss Securit yDAOImpl i mplements  SecurityDA O {
  57           
  58           // constructo rs for Imp l file so  we can moc k session
  59       public  SecurityD AOImpl() {
  60       }
  61  
  62       public  SecurityD AOImpl(Ses sionFactor y factory)  {
  63           se ssionFacto ry = facto ry;
  64       }
  65           
  66           pr ivate Logg er logger  = Logger.g etLogger(S ecurityDAO Impl.class );
  67  
  68       @Autow ired
  69           pr ivate Sess ionFactory  sessionFa ctory;
  70       
  71           pr otected Se ssion getS ession() {
  72                    retu rn this.se ssionFacto ry.getCurr entSession ();
  73           }
  74           
  75           pu blic void  setSession Factory(Se ssionFacto ry session Factory) {
  76                    this .sessionFa ctory = se ssionFacto ry;
  77           }
  78       
  79           /*
  80            *  Get user  by name
  81            *  
  82            *  @param us erId
  83            *  @return
  84            *  @throws D AOExceptio n
  85            * /
  86           pu blic User  getUserByN ame(String  userId) {
  87  
  88                    fina l String s ql = "sele ct * from  ht.app_use r where us er_name='"  + userId  +"'";
  89                    retu rn getSess ion().crea teNativeQu ery(sql, U ser.class) .getSingle Result();
  90           }
  91           
  92           /* *
  93            *  Delete a  role
  94            *  
  95            *  @param id entifier
  96            *  @return
  97            * /
  98           @O verride
  99           pu blic void  deleteUser Role(UserR ole userRo le) {
  100                    
  101                    Vali date.notNu ll(userRol e, "Role i dentifier  can not be  null.");
  102                    Vali date.notNu ll(userRol e.getId(),  "Role ide ntifier ke y can not  be null.") ;
  103  
  104                    getS ession().r emove(user Role);
  105           }
  106  
  107           @S uppressWar nings("unc hecked")
  108           @O verride
  109           pu blic List< User> getS ubmittedRe gistration s(Integer  visnId, In teger faci lityId) {
  110                    Stri ng sql = " select l f rom " + Us er.class.g etName() +  " l where  l.registr ationStatu s.code !=  :registrat ionStatus" ;
  111                    Quer y query;
  112                    
  113                    if ( visnId !=  null && vi snId > 0)  {
  114                             sql +=  " and l.v isn.id = : visnId";
  115                             query  = getSessi on().creat eQuery(sql );
  116                             query. setParamet er("regist rationStat us", Regis trationSta tus.APPROV ED);
  117                             query. setParamet er("visnId ", visnId) ;
  118                             return  query.get ResultList ();
  119                    }els e if (faci lityId !=  null && fa cilityId >  0) {
  120                             sql +=  " and l.f acility.id  = :facili tyId";
  121                             query  = getSessi on().creat eQuery(sql );
  122                             query. setParamet er("regist rationStat us", Regis trationSta tus.APPROV ED);
  123                             query. setParamet er("facili tyId", fac ilityId);
  124                             return  query.get ResultList ();
  125                    }
  126                    else  {
  127                             query  = getSessi on().creat eQuery(sql );
  128                             query. setParamet er("regist rationStat us", Regis trationSta tus.APPROV ED);
  129                             return  query.get ResultList ();
  130                    }
  131           }
  132           
  133           @S uppressWar nings("unc hecked")
  134           @O verride
  135           pu blic List< User> getN ewRegistra tions(Inte ger visnId , Integer  facilityId ) {
  136                    Stri ng sql = " select l f rom " + Us er.class.g etName() +  " l where  l.registr ationStatu s.code = : registrati onStatus";
  137                    Quer y query;
  138                    
  139                    if ( visnId !=  null && vi snId > 0)  {
  140                             sql +=  " and l.v isn.id = : visnId";
  141                             query  = getSessi on().creat eQuery(sql );
  142                             query. setParamet er("regist rationStat us", Regis trationSta tus.SUBMIT TED);
  143                             query. setParamet er("visnId ", visnId) ;
  144                             return  query.get ResultList ();
  145                    }els e if (faci lityId !=  null && fa cilityId >  0) {
  146                             sql +=  " and l.f acility.id  = :facili tyId";
  147                             query  = getSessi on().creat eQuery(sql );
  148                             query. setParamet er("regist rationStat us", Regis trationSta tus.SUBMIT TED);
  149                             query. setParamet er("facili tyId", fac ilityId);
  150                             return  query.get ResultList ();
  151                    }
  152                    else  {
  153                             query  = getSessi on().creat eQuery(sql );
  154                             query. setParamet er("regist rationStat us", Regis trationSta tus.SUBMIT TED);
  155                             return  query.get ResultList ();
  156                    }
  157           }
  158  
  159           @S uppressWar nings("unc hecked")
  160           @O verride
  161           pu blic List< User> getS ubmittedRe gistration sForDmp(In teger visn Id, Intege r facility Id) throws  DAOExcept ion {
  162                    try  {
  163                             Map<St ring, Obje ct> params  = new Has hMap<Strin g, Object> ();
  164                             params .put("regi strationSt atus", Reg istrationS tatus.APPR OVED);  
  165                             
  166                             String  sql = "se lect l fro m " + User .class.get Name() + "  l where l .registrat ionStatus. code != :r egistratio nStatus an d (l.regis trationRea son.name l ike '%DMP% ' or l.reg istrationR eason.name  = 'Traini ng Center  Staff')";
  167                             if (vi snId != nu ll) {
  168                                      sql += "  and l.vis n.id = :vi snId";
  169                                      params.p ut("visnId ", visnId) ;
  170                             }else  if (facili tyId != nu ll) {
  171                                      sql += "  and l.fac ility.id =  :facility Id";
  172                                      params.p ut("facili tyId", fac ilityId);
  173                             }
  174                             
  175                             final  Query quer y = getSes sion().cre ateQuery(s ql);
  176                             for(St ring field : params.k eySet()) {
  177                                      query.se tParameter (field, pa rams.get(f ield));
  178                             }
  179                             return  query.get ResultList ();
  180                    } ca tch (Excep tion e) {
  181                             throw  new DAOExc eption("ge tSubmitted Registrati onsForDmp  failed: ",  e);
  182                    }
  183           }
  184           
  185           /* *
  186            *  Create us er in the  IHTA datab ase
  187            *  
  188            *  @param us er
  189            *  @throws D AOExceptio n
  190            * /
  191           pu blic void  createUser (User user ) {
  192                    getS ession().p ersist(use r);
  193           }
  194  
  195           /* *
  196            *  Update us er in the  IHTA datab ase
  197            *  
  198            *  @param us er
  199            *  @throws D AOExceptio n
  200            * /
  201           pu blic void  updateUser (User user ) {
  202  
  203                    for  (UserRole  ur : user. getRoles() ) {
  204                             ur.set User(user) ;
  205                    }
  206                    
  207                    getS ession().s aveOrUpdat e(user);
  208           }
  209  
  210           /* *
  211            *  Update ro le in the  IHTA datab ase
  212            *  
  213            *  @param ro le
  214            *  @throws D AOExceptio n
  215            * /
  216           pu blic void  updateRole (Role role ) throws D AOExceptio n {
  217                    
  218                    getS ession().s aveOrUpdat e(role);
  219           }
  220  
  221           /*
  222            *  (non-Java doc)
  223            *  
  224            *  @see gov. va.med.IHT A.persiste nt.Securit yDAO#findA llRoles()
  225            * /
  226           @S uppressWar nings("unc hecked")
  227           pu blic List< Role> find AllRoles()  throws DA OException  {
  228                    
  229                    try  {
  230                             String  sql = "se lect l fro m " + Role .class.get Name() + "  l";
  231                             final  Query quer y = getSes sion().cre ateQuery(s ql);
  232                             return  query.get ResultList ();
  233                    } ca tch (Excep tion e) {
  234                             throw  new DAOExc eption("fi ndAllRoles  failed: " , e);
  235                    }
  236           }
  237  
  238           @S uppressWar nings("unc hecked")
  239           pu blic List< SimpleRole > findAllS impleRoles () throws  DAOExcepti on {
  240                    try  {
  241                             String  sql = "se lect l fro m " + Simp leRole.cla ss.getName () + " l w here l.id  != 2020 or der by l.n ame";
  242                             return  getSessio n().create Query(sql) .getResult List();
  243                    } ca tch (Excep tion e) {
  244                             throw  new DAOExc eption("fi ndAllRoles  failed: " , e);
  245                    }
  246           }
  247  
  248           @S uppressWar nings("unc hecked")
  249           pu blic List< SimpleRole > findAllD MPRoles()  throws DAO Exception  {
  250                    try  {
  251                             String  sql = "se lect l fro m " + Simp leRole.cla ss.getName () + " l w here l.nam e like '%D MP%' order  by l.name ";
  252                             return  getSessio n().create Query(sql) .getResult List();
  253                    } ca tch (Excep tion e) {
  254                             throw  new DAOExc eption("fi ndAllDMPRo les failed : ", e);
  255                    }
  256           }
  257  
  258           /*
  259            *  (non-Java doc)
  260            *  
  261            *  @see
  262            *  gov.va.me d.IHTA.per sistent.Se curityDAO# findAllPer missions(g ov.va.med.
  263            *  fw.securi ty.Applica tion)
  264            * /
  265           @S uppressWar nings("unc hecked")
  266           pu blic List< Permission > findAllP ermissions () throws  DAOExcepti on {
  267  
  268                    try  {
  269                             final  String sql  = "select  l from "  + Permissi on.class.g etName() +  " l";
  270                             return  getSessio n().create Query(sql) .getResult List();
  271                    } ca tch (Excep tion e) {
  272                             throw  new DAOExc eption("fi ndAllPermi ssions fai led: ", e) ;
  273                    }
  274           }
  275  
  276           /*
  277            *  (non-Java doc)
  278            *  
  279            *  @see
  280            *  gov.va.me d.IHTA.per sistent.Se curityDAO# getRoleByN ame(java.l ang.String )
  281            * /
  282           @S uppressWar nings("unc hecked")
  283           pu blic Role  getRoleByN ame(String  roleName)  {
  284                    
  285                    Stri ng sql = " select l f rom " + Ro le.class.g etName() +  " l where  UPPER(l.n ame) = :ro leName";
  286                    fina l Query qu ery = getS ession().c reateQuery (sql);
  287                    quer y.setParam eter("role Name", rol eName);
  288                    
  289                    List <Role> lis t = query. getResultL ist();
  290                    if ( list != nu ll && list .size() >  0)
  291                             return  list.get( 0);
  292                    retu rn null;
  293           }
  294           
  295           @O verride
  296           pu blic Role  getRoleByI d(long id)  {
  297                    retu rn getSess ion().get( Role.class , id);
  298           }        
  299           
  300           
  301  
  302           pu blic Simpl eRole getS impleRoleB yName(Stri ng roleNam e) throws  DAOExcepti on {
  303                    try  {
  304                             String  sql = "se lect l fro m " + Simp leRole.cla ss.getName ()
  305                                               + " l wher e l.name =  :roleName ";
  306                             final  Query quer y = getSes sion().cre ateQuery(s ql);
  307                             query. setParamet er("roleNa me", roleN ame);
  308                             return  (SimpleRo le) query. getSingleR esult();
  309                    } ca tch (Excep tion e) {
  310                             throw  new DAOExc eption("ge tSimpleRol eByName Fa iled ", e) ;
  311                    }
  312           }
  313  
  314           /*
  315            *  (non-Java doc)
  316            *  
  317            *  @see gov. va.med.IHT A.persiste nt.Securit yDAO#getAv ailableRol eNames()
  318            * /
  319   //      @S uppressWar nings("unc hecked")
  320   //      pu blic List< String> ge tAvailable RoleNames( Applicatio n applicat ion) throw s DAOExcep tion {
  321   //               
  322   //               logg er.error(" $$$$$$ fix  me");
  323   //               retu rn null;
  324   ////             try  {
  325   ////                      String  query = " select l.n ame from "  + Role.cl ass.getNam e() + " l  ";
  326   ////                      Map<St ring, Obje ct> params  = new Has hMap<Strin g, Object> ();
  327   ////                      if (ap plication  != null) {
  328   ////                               query =  query + "  where l.ap plication. applicatio nName = :a pplication Name";
  329   ////                               params.p ut("applic ationName" , applicat ion.getApp licationNa me());
  330   ////                      }
  331   ////                      return  getJpaTem plate().fi ndByNamedP arams(quer y, params) ;
  332   ////             } ca tch (Excep tion e) {
  333   ////                      throw  new DAOExc eption("ge tAvailable RoleNames  failed", e );
  334   ////             }
  335   //      }
  336  
  337           /*
  338            *  (non-Java doc)
  339            *  
  340            *  @see
  341            *  gov.va.me d.IHTA.per sistent.Se curityDAO# getRolePer missions(j ava.lang.S tring
  342            *  )
  343            * /
  344           @S uppressWar nings("unc hecked")
  345           pu blic List< String> ge tRolePermi ssionNames (String ro leName) th rows DAOEx ception {
  346                    try  {
  347                             String  sql = "se lect r.int ernalPermi ssions.per mission.na me from "
  348                                               + Role.cla ss.getName () + " r w here r.nam e = :roleN ame";
  349                             final  Query quer y = getSes sion().cre ateQuery(s ql).setPar ameter("ro leName", r oleName);
  350                             return  query.get ResultList ();
  351                    } ca tch (Excep tion e) {
  352                             throw  new DAOExc eption("ge tRolePermi ssionNames  failed",  e);
  353                    }
  354           }
  355  
  356           @S uppressWar nings("unc hecked")
  357           pu blic UserP rincipal g etAuditUse r(String u serName) t hrows DAOE xception {
  358                    Vali date.notNu ll(userNam e);
  359                    try  {
  360                             final  String sql  = "select  USER_NAME , FIRST_NA ME, MIDDLE _NAME, LAS T_NAME"
  361                                               + " from h t.app_user "
  362                                               + " where  upper(USER _NAME) = : userName";
  363                             final  Query quer y = getSes sion().cre ateNativeQ uery(sql). setParamet er("userNa me", userN ame);
  364  
  365                             List<O bject[]> r esults = q uery.getRe sultList() ;
  366  
  367                             if (re sults != n ull) {
  368                                      for (Obj ect[] resu lt : resul ts) {
  369                                               UserPrinci palImpl us er = new U serPrincip alImpl((St ring) resu lt[0]);
  370                                               user.setFi rstName((S tring) res ult[1]);
  371                                               user.setMi ddleName(( String) re sult[2]);
  372                                               user.setLa stName((St ring) resu lt[3]);
  373                                               return use r;
  374                                      }
  375                             }
  376                             return  new UserP rincipalIm pl(userNam e);
  377  
  378                    } ca tch (Excep tion e) {
  379                             throw  new DAOExc eption("ge tAuditUser  failed",  e);
  380                    }
  381           }
  382  
  383           @S uppressWar nings("unc hecked")
  384           pu blic List< FederalHol iday> find Holidays(i nt year) t hrows DAOE xception {
  385                    
  386                    try  {
  387                             String  sql = "se lect h fro m " + Fede ralHoliday .class.get Name() + "  h where y ear(h.acti veDate) =  :year";
  388                             final  Query quer y = getSes sion().cre ateQuery(s ql).setPar ameter("ye ar", year) ;
  389                             
  390                             return  query.get ResultList ();
  391                    } ca tch (Excep tion e) {
  392                             throw  new DAOExc eption("fi ndHolidays  failed: " , e);
  393                    }
  394           }
  395  
  396           @S uppressWar nings("unc hecked")
  397           pu blic List< String> ge tUserIds()  throws DA OException  {
  398                    try  {
  399                             final  String sql  = "select  USER_NAME  from ht.a pp_user";
  400                             final  Query quer y = getSes sion().cre ateNativeQ uery(sql);
  401  
  402                             return  query.get ResultList ();
  403                             
  404                    } ca tch (Excep tion e) {
  405                             throw  new DAOExc eption("ge tAuditUser  failed",  e);
  406                    }
  407           }
  408  
  409           @S uppressWar nings("unc hecked")
  410           pu blic List< SimpleUser > findAppU sers(Searc hCriteria  searchCrit eria) thro ws DAOExce ption {
  411                    try  {
  412                             //user  name sear ch
  413                             if (St ringUtils. isNotEmpty (searchCri teria.getS AMAccountN ame())){
  414                                      final St ring sql =  "select l  from " +  SimpleUser .class.get Name()
  415                                                       +  " l where  upper(l.us erCredenti als.userID ) = :userI d";
  416  
  417                                      return g etSession( ).createQu ery(sql)
  418                                                       .s etParamete r("userId" , searchCr iteria.get SAMAccount Name())
  419                                                       .g etResultLi st();                                                            
  420                             }//Las t name and  first nam e search
  421                             else i f (StringU tils.isNot Empty(sear chCriteria .getLastNa me())){
  422                                      String s ql = "sele ct l from  " + Simple User.class .getName()
  423                                               + " l wher e l.lastNa me = :last Name";
  424                                      Query qu ery = getS ession().c reateQuery (sql);
  425                                      if (Stri ngUtils.is NotEmpty(s earchCrite ria.getFir stName()))  {
  426                                               sql = sql  + " and l. firstName  like :firs tName";
  427                                               query = ge tSession() .createQue ry(sql);
  428                                               // Find fi rst names  that start  with the  value of t he first n ame search  criteria.
  429                                               query.setP arameter(" firstName" , searchCr iteria.get FirstName( ) + "%");
  430                                      }
  431                                      query.se tParameter ("lastName ", searchC riteria.ge tLastName( ));
  432                                      //return  the resul t set                           
  433                                      return q uery.getRe sultList() ;   
  434                             }//Rol e and VISN  or facili ty search 
  435                             else i f (searchC riteria.ge tRoles().s ize() > 0)  {        
  436                                      final Ma p<String,O bject> map  = new Has hMap<Strin g,Object>( );
  437                                      map.put( "roles", s earchCrite ria.getRol es());
  438                                      String s ql = "sele ct l from  " + Simple User.class .getName()
  439                                      + " l wh ere l.id i n (select  distinct u r.user.id  from " + U serRole.cl ass.getNam e()
  440                                      + " ur w here ur.ro le.name in  (:roles)) ";
  441                                      if (sear chCriteria .getVisns( ) != null  && searchC riteria.ge tVisns().s ize() > 0)  {
  442                                               sql += " a nd l.visn. id in (sel ect v.id f rom " + Si mpleVisn.c lass.getNa me() +
  443                                               " v where  v.name in  (:visns))" ;
  444                                               map.put("v isns", sea rchCriteri a.getVisns ());
  445                                      }
  446                                      if (sear chCriteria .getStatio ns() != nu ll && sear chCriteria .getStatio ns().size( ) > 0) {
  447                                               sql += " a nd l.facil ity.id in  (select f. id from "  + SimpleFa cility.cla ss.getName () +
  448                                               " f where  f.stationN umber in ( :stations) )";
  449                                               map.put("s tations",  searchCrit eria.getSt ations());
  450                                      }                                           
  451                                      if (sear chCriteria .getVendor s() != nul l && searc hCriteria. getVendors ().size()  > 0) {
  452                                               sql += " a nd l.vendo r.id in (s elect ven. id from "  + Vendor.c lass.getNa me() +
  453                                               " ven wher e ven.name  in (:vend ors))";
  454                                               map.put("v endors", s earchCrite ria.getVen dors());
  455                                      }
  456                                      
  457                                      final Qu ery query  = getSessi on().creat eQuery(sql );
  458                                      for(Stri ng field:  map.keySet ()) {
  459                                               query.setP arameter(f ield, map. get(field) );
  460                                      }
  461                                      
  462                                      return q uery.getRe sultList() ;
  463                             } else  {
  464                                      throw ne w Exceptio n("findApp Users fail ed: Invali d Search c riteria");
  465                             }
  466                    }cat ch (Except ion e){
  467                             throw  new DAOExc eption("fi ndAppUsers  failed",  e);
  468                    }
  469           }
  470           
  471           @O verride
  472      public  UserDetail s loadUser ByUsername (String us ername) th rows Usern ameNotFoun dException  {
  473                    try  {
  474                             final  User user  = getUserB yName(user name);
  475                             if (us er == null )
  476                                      throw ne w Username NotFoundEx ception("S orry, no u ser with t he name '"  + usernam e + "' was  found.");
  477                             Collec tion<Simpl eRole> sim pleRoles =  getRolesB yUserName( username);
  478  
  479                             List<S tring> mas terRoles =  new Array List<>();
  480                             // cha nged for S SO
  481                             for (O bject obj  : simpleRo les) {
  482                                      if(obj i nstanceof  SimpleRole  ) {
  483                                               masterRole s.add(((Si mpleRole)o bj).getNam e());
  484                                      }
  485                                      else if( obj instan ceof Role)  {
  486                                               masterRole s.add(((Ro le)obj).ge tName());
  487                                      }
  488                             }
  489  
  490                             // Add  default r ole for al l valid us ers
  491                             if (!m asterRoles .contains( "CCHT_USER ")) {
  492                                      masterRo les.add("C CHT_USER") ;
  493                             }
  494                             user.s etLdapRole s(new Hash Set<>(mast erRoles));
  495  
  496                             final  Set<String > permissi ons = new  HashSet<St ring>();
  497                             // now  loop thro ugh and ge t permissi ons for ea ch role an d add to
  498                             // the  authoriti es
  499                             for (O bject elem ent : mast erRoles) {
  500                                      String r oleName =  (String) e lement;
  501                                      Role rol e = getRol eByName(ro leName);
  502                                      if (role  != null & & role.get Permission s() != nul l) {
  503                                               for (Objec t element2  : role.ge tPermissio ns()) {
  504                                                       Pe rmission p ermission  = (Permiss ion) eleme nt2;
  505                                                       pe rmissions. add(permis sion.getNa me());
  506                                               }
  507                                      }
  508                             }
  509                             permis sions.addA ll(masterR oles);
  510  
  511                             // TOD O: OHRS sp ecific cod e?
  512                             // Set <String> a ppSpecific Permission s = new Ha shSet<Stri ng>();
  513                             // for  (String p ermName :  permission s) {
  514                             // if  (permName. startsWith (subsystem PrefixToCh eck)) {
  515                             // app SpecificPe rmissions. add(permNa me.substri ng(subsyst emPrefixTo Check.leng th(),
  516                             // per mName.leng th())
  517                             // + s ubsystemSu ffixToAdd) ;
  518                             // }
  519                             // }
  520                             // per missions.a ddAll(appS pecificPer missions);
  521  
  522                             // add  user name
  523                             permis sions.add( username);
  524  
  525                             List<G rantedAuth ority> rol es = new A rrayList<> (permissio ns.size()) ;
  526  
  527                             for (S tring elem ent : perm issions) {
  528                                      GrantedA uthority a uthority =  new Simpl eGrantedAu thority(el ement);
  529                                      roles.ad d(authorit y);
  530                             }
  531  
  532                             user.s etAuthorit ies(roles) ;
  533                             return  user;
  534                    } ca tch(NoResu ltExceptio n e) {
  535                             throw  new Userna meNotFound Exception( "No result  found for  username  = " + user name, e);
  536                    } ca tch (Excep tion e) {
  537                             throw  new Runtim eException (e);
  538                    }
  539           }
  540           
  541           @O verride
  542           @S uppressWar nings("unc hecked")
  543           pu blic List< SimpleRole > getRoles ByUserName (String us erName) {
  544                    fina l String s ql = "sele ct distinc t ur.role  from " + U serRole.cl ass.getNam e()
  545                                      + " ur w here ur.us er.userCre dentials.u serID = :u serName";
  546                    fina l Query qu ery = getS ession().c reateQuery (sql).setP arameter(" userName",  userName) ;
  547                    
  548                    retu rn query.g etResultLi st();
  549           }
  550  
  551           @O verride
  552           pu blic Map<S tring, Use rPrincipal <?>> findU sersWithAn yRole(List <String> r oleNames)  {
  553                    
  554                    if(r oleNames = = null ||  roleNames. size() ==  0) {
  555                             return  new HashM ap<String,  UserPrinc ipal<?>>() ;
  556                    }
  557                    
  558                    Stri ng sql = " select dis tinct ur.u ser.userCr edentials. userID, ur .user from  "
  559                                      + UserRo le.class.g etName() +  " ur wher e ur.role. name in (: roleNames) ";
  560                    
  561                    @Sup pressWarni ngs("unche cked")
  562                    List <Object[]>  rows = ge tSession() .createQue ry(sql).se tParameter List("role Names", ro leNames).g etResultLi st();
  563  
  564                    Map< String, Us erPrincipa l<?>> resu lts = new  HashMap<>( );
  565                    for  (Object[]  row : rows )
  566                             result s.put((Str ing) row[0 ], (UserPr incipal<?> ) row[1]);
  567                    retu rn results ;
  568           }
  569  
  570           @O verride
  571           pu blic void  deleteEnti ty(Object  obj) throw s DAOExcep tion {
  572                    // T ODO Auto-g enerated m ethod stub
  573                    getS ession().d elete(obj) ;
  574                    
  575           }
  576  
  577           @O verride
  578           pu blic void  flush() {
  579                    // T ODO Auto-g enerated m ethod stub
  580                    
  581           }
  582  
  583           @O verride
  584           pu blic void  persist(Ro le role) {
  585                    getS ession().p ersist(rol e);
  586           }
  587           
  588           @O verride
  589           pu blic void  persist(Us erRole use rRole) {
  590                    getS ession().p ersist(use rRole);
  591           }
  592  
  593           @O verride
  594           pu blic void  remove(Rol e role) {
  595                    getS ession().r emove(role );
  596           }
  597           
  598           @O verride
  599           pu blic void  remove(Use rRole user Role) {
  600                    getS ession().r emove(user Role);
  601           }
  602  
  603           @O verride
  604           pu blic Objec t getByKey (EntityKey <?> entity Key) {
  605                    Obje ct entity  = getSessi on().get(e ntityKey.g etEntityCl ass(), ent ityKey.get KeyValue() );
  606                    retu rn entity;
  607           }
  608  
  609           @O verride
  610           pu blic void  deleteRole (Role role ) {
  611                    getS ession().r emove(role );
  612           }
  613           
  614           pu blic void  deleteRole Permission sFromRole( Role role)  {
  615                    
  616                    if ( role.getIn ternalPerm issions()  != null )  {
  617                             for (f inal RoleP ermission  rolePermis sion : rol e.getInter nalPermiss ions()) {
  618                                      getSessi on().delet e(rolePerm ission);
  619                             }
  620                    }
  621           }
  622   }