Produced by Araxis Merge on 3/24/2017 5:17:19 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | MHV_2017.2.0.0 Code In Flight.zip\National Portal\mhv_user\mhv-usermgmt-portal-main\src\main\java\gov\va\med\mhv\usermgmt\main\service\impl | EmployeeSearchServiceImpl.java | Tue May 10 03:21:52 2016 UTC |
| 2 | MHV_2017.2.0.0 Code In Flight.zip\National Portal\mhv_user\mhv-usermgmt-portal-main\src\main\java\gov\va\med\mhv\usermgmt\main\service\impl | EmployeeSearchServiceImpl.java | Fri Mar 24 20:43:12 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 362 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 1 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.m hv.usermgm t.main.ser vice.impl; | |
| 5 | ||
| 6 | import jav a.util.Has htable; | |
| 7 | ||
| 8 | import jav ax.naming. Context; | |
| 9 | import jav ax.naming. NamingEnum eration; | |
| 10 | import jav ax.naming. NamingExce ption; | |
| 11 | import jav ax.naming. directory. Attributes ; | |
| 12 | import jav ax.naming. directory. SearchResu lt; | |
| 13 | import jav ax.naming. ldap.Initi alLdapCont ext; | |
| 14 | import jav ax.naming. ldap.LdapC ontext; | |
| 15 | ||
| 16 | import org .apache.lo gging.log4 j.LogManag er; | |
| 17 | import org .apache.lo gging.log4 j.Logger; | |
| 18 | import org .springfra mework.bea ns.factory .annotatio n.Autowire d; | |
| 19 | import org .springfra mework.ste reotype.Co mponent; | |
| 20 | ||
| 21 | import gov .va.med.mh v.common.a pi.util.Re sponseUtil ; | |
| 22 | import gov .va.med.mh v.usermgmt .common.dt o.Employee SearchResu lt; | |
| 23 | import gov .va.med.mh v.usermgmt .exception .MHVRuntim eException ; | |
| 24 | import gov .va.med.mh v.usermgmt .persist.l dap.LdapEn vironment; | |
| 25 | import gov .va.med.mh v.usermgmt .service.E mployeeSea rchService ; | |
| 26 | import gov .va.med.mh v.usermgmt .util.Mess agesUtil; | |
| 27 | ||
| 28 | /** | |
| 29 | * @author
|
|
| 30 | */ | |
| 31 | @Component | |
| 32 | public cla ss Employe eSearchSer viceImpl i mplements EmployeeSe archServic e { | |
| 33 | ||
| 34 | pr otected st atic Logge r log = Lo gManager.g etLogger(E mployeeSea rchService Impl.class ); | |
| 35 | ||
| 36 | @A utowired | |
| 37 | pr ivate Ldap Environmen t ldapEnvi ronment; | |
| 38 | ||
| 39 | @A utowired | |
| 40 | pr ivate Mess agesUtil m essagesUti l; | |
| 41 | ||
| 42 | @O verride | |
| 43 | pu blic Boole an searchB yUserName( String use rName, boo lean colle ctionRespo nse, Respo nseUtil re sponse) { | |
| 44 | Bool ean userAl readyExist s = false; | |
| 45 | ||
| 46 | if ( userName ! = null) { | |
| 47 | userNa me = userN ame.replac eAll("\\*" , ""); // no user en tered | |
| 48 | // wildc ard charac ters | |
| 49 | userNa me = userN ame.trim() ; // trim spaces | |
| 50 | } | |
| 51 | ||
| 52 | // c reate the search str ingf | |
| 53 | Stri ng searchF ilter = "( &(objectCl ass=user)( sAMAccount Name=" + u serName + "))"; | |
| 54 | ||
| 55 | // u rl=ldap:// 10.224.88. 92:3268 | |
| 56 | // a dminPrinci pal=VAAUST IN\\mhvadm in | |
| 57 | // a dminPasswo rd=P@ssw0r d | |
| 58 | // s earchBase= DC=VAAUSTI N,DC=DEV | |
| 59 | ||
| 60 | Hash table<Stri ng, String > AD_LDAP_ ENVIRONMEN T = new Ha shtable<St ring, Stri ng>(); | |
| 61 | AD_L DAP_ENVIRO NMENT.put( Context.IN ITIAL_CONT EXT_FACTOR Y, ldapEnv ironment.g etAdIntial CtxFactory ()); | |
| 62 | AD_L DAP_ENVIRO NMENT.put( Context.SE CURITY_AUT HENTICATIO N, ldapEnv ironment.g etAdSecuri tyAuthenti cation()); | |
| 63 | AD_L DAP_ENVIRO NMENT.put( Context.PR OVIDER_URL , ldapEnvi ronment.ge tAdUrl()); | |
| 64 | AD_L DAP_ENVIRO NMENT.put( Context.SE CURITY_PRI NCIPAL, ld apEnvironm ent.getAdA dminPrinci pal()); | |
| 65 | AD_L DAP_ENVIRO NMENT.put( Context.SE CURITY_CRE DENTIALS, ldapEnviro nment.getA dAdminPass word()); | |
| 66 | ||
| 67 | Ldap Context ld apContext = null; | |
| 68 | ||
| 69 | // p erform sea rch | |
| 70 | try { | |
| 71 | ldapCo ntext = ne w InitialL dapContext (AD_LDAP_E NVIRONMENT , null); | |
| 72 | ||
| 73 | Naming Enumeratio n searchRe sults = ld apContext. search(lda pEnvironme nt.getAdSe archBase() , searchFi lter, null ); | |
| 74 | // no results fo und | |
| 75 | if (se archResult s.hasMoreE lements() == false) { | |
| 76 | userAlre adyExists = false; | |
| 77 | // respo nse.setFai lure(true) ; | |
| 78 | // valid ator.addEr ror(respon se, | |
| 79 | // UserM anagementM essages.SE ARCH_NO_RE SULTS, nul l); | |
| 80 | } else { | |
| 81 | while (s earchResul ts.hasMore Elements() ) { | |
| 82 | SearchResu lt searchR esult = (S earchResul t) searchR esults.nex t(); | |
| 83 | Attributes searchRes ultAttribu tes = sear chResult.g etAttribut es(); | |
| 84 | if (search ResultAttr ibutes != null) { | |
| 85 | us erAlreadyE xists = tr ue; | |
| 86 | // if we are using thi s helper m ethod to p opulate | |
| 87 | // results | |
| 88 | // for colle ction resp onse, we a dd search result int o | |
| 89 | // response in differe nt manner | |
| 90 | /* if (collec tionRespon se) { | |
| 91 | ((Em ployeeSear chResultCo llectionSe rviceRespo nse) | |
| 92 | re sponse).ad dEmployeeS earchResul t( | |
| 93 | conv ertToEmplo yeeSearchR esult(sear chResultAt tributes)) ; | |
| 94 | } else { | |
| 95 | ((Em ployeeSear chResultSe rviceRespo nse) respo nse). | |
| 96 | setE mployeeSea rchResult( | |
| 97 | conver tToEmploye eSearchRes ult(search ResultAttr ibutes)); | |
| 98 | }* / | |
| 99 | ||
| 100 | re sponse.set Failure(fa lse); | |
| 101 | re sponse.set Success(tr ue); | |
| 102 | re sponse.set PojoObject (convertTo EmployeeSe archResult (searchRes ultAttribu tes)); | |
| 103 | } | |
| 104 | } | |
| 105 | } | |
| 106 | } ca tch (Namin gException e) { | |
| 107 | log.er ror("Faile d to conne ct to Acti ve Directo ry", e); | |
| 108 | // val idator.add Error(resp onse, | |
| 109 | // Use rManagemen tMessages. SEARCH_FAI LED, null) ; | |
| 110 | throw new MHVRun timeExcept ion(messag esUtil.get EmployeeSe archFailed ()); | |
| 111 | } fi nally { | |
| 112 | try { | |
| 113 | if (ldap Context != null) { | |
| 114 | ldapContex t.close(); // attemp t to close connectio n | |
| 115 | // regardl ess | |
| 116 | } | |
| 117 | } catc h (NamingE xception e ) { | |
| 118 | log.erro r("Failed to close c onnection to Active Directory" , e); | |
| 119 | // valid ator.addEr ror(respon se, | |
| 120 | // UserM anagementM essages.SE ARCH_FAILE D, null); | |
| 121 | throw ne w MHVRunti meExceptio n(messages Util.getEm ployeeSear chFailed() ); | |
| 122 | } fina lly { | |
| 123 | ldapCont ext = null ; // relea se handle to connect ion regard less | |
| 124 | } | |
| 125 | } | |
| 126 | ||
| 127 | retu rn userAlr eadyExists ; | |
| 128 | } | |
| 129 | ||
| 130 | @O verride | |
| 131 | pu blic void searchByNa me(String firstName, String la stName, Re sponseUtil response) { | |
| 132 | ||
| 133 | // T ODO Auto-g enerated m ethod stub | |
| 134 | retu rn; | |
| 135 | } | |
| 136 | ||
| 137 | privat e static f inal Emplo yeeSearchR esult conv ertToEmplo yeeSearchR esult( | |
| 138 | Attribut es attribu tes) throw s NamingEx ception { | |
| 139 | Employee SearchResu lt employe eSearchRes ult = new EmployeeSe archResult (); | |
| 140 | ||
| 141 | if (attr ibutes.get ("sAMAccou ntName") ! = null) | |
| 142 | empl oyeeSearch Result.set UserName(( String) at tributes.g et( | |
| 143 | "sAMAccoun tName").ge t()); | |
| 144 | ||
| 145 | if (attr ibutes.get ("givenNam e") != nul l) | |
| 146 | empl oyeeSearch Result.set FirstName( (String) a ttributes. get( | |
| 147 | "givenName ").get()); | |
| 148 | ||
| 149 | if (attr ibutes.get ("sn") != null) | |
| 150 | empl oyeeSearch Result.set LastName(( String) at tributes.g et("sn") | |
| 151 | .get()); | |
| 152 | ||
| 153 | if (attr ibutes.get ("title") != null) | |
| 154 | empl oyeeSearch Result.set Title((Str ing) attri butes.get( "title") | |
| 155 | .get()); | |
| 156 | ||
| 157 | if (attr ibutes.get ("physical DeliveryOf ficeName") != null) | |
| 158 | empl oyeeSearch Result.set Office((St ring) attr ibutes.get ( | |
| 159 | "physicalD eliveryOff iceName"). get()); | |
| 160 | ||
| 161 | if (attr ibutes.get ("departme nt") != nu ll) | |
| 162 | empl oyeeSearch Result.set Department ((String) attributes .get( | |
| 163 | "departmen t").get()) ; | |
| 164 | ||
| 165 | if (attr ibutes.get ("company" ) != null) | |
| 166 | empl oyeeSearch Result.set Company((S tring) att ributes.ge t("company ") | |
| 167 | .get()); | |
| 168 | ||
| 169 | if (attr ibutes.get ("telephon eNumber") != null) | |
| 170 | empl oyeeSearch Result.set Phone((Str ing) attri butes.get( | |
| 171 | "telephone Number").g et()); | |
| 172 | ||
| 173 | if (attr ibutes.get ("mail") ! = null) | |
| 174 | empl oyeeSearch Result | |
| 175 | .setEmail( (String) a ttributes. get("mail" ).get()); | |
| 176 | ||
| 177 | employee SearchResu lt.setFull Name(emplo yeeSearchR esult.getL astName() | |
| 178 | + ", " + emplo yeeSearchR esult.getF irstName() ); | |
| 179 | ||
| 180 | return e mployeeSea rchResult; | |
| 181 | } | |
| 182 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.