Produced by Araxis Merge on 9/11/2017 8:05:39 AM Central 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_CIF_2017.4.0.0.zip\MHV_CIF_2017.4.0.0\MHV_CIF_2017.4.0.0\mhv_source\mhv_user\mhv-usermgmt-portal-main\src\main\java\gov\va\med\mhv\usermgmt\main\service\impl | EmployeeSearchServiceImpl.java | Tue May 2 23:46:40 2017 UTC |
2 | MHV_CIF_2017.4.0.0.zip\MHV_CIF_2017.4.0.0\MHV_CIF_2017.4.0.0\mhv_source\mhv_user\mhv-usermgmt-portal-main\src\main\java\gov\va\med\mhv\usermgmt\main\service\impl | EmployeeSearchServiceImpl.java | Thu Sep 7 19:53:00 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 378 |
Changed | 2 | 10 |
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 DN S THUMMP | |
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 | // url=lda p:// IP | |
56 | // adminPr incipal= RED A C T ED | |
57 | // adminPa ssword= REDACTED | |
58 | // searchB ase=DC= RED A C T ED ,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 | // Syst em.out.pri ntln("%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %% ldapEnv ironment.g etAdUrl() " +ldapEnv ironment.g etAdUrl()) ; | |
70 | // Syst em.out.pri ntln("%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %% ldapEn vironment. getAdIntia lCtxFactor y()" + ld apEnvironm ent.getAdI ntialCtxFa ctory()); | |
71 | // Syst em.out.pri ntln("%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %% Context .SECURITY_ CREDENTIAL S T" + lda pEnvironme nt.getAdAd minPasswor d()); | |
72 | ||
73 | // Syst em.out.pri ntln("%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %% Context .SECURITY_ CREDENTIAL S T" + AD_ LDAP_ENVIR ONMENT ); | |
74 | ||
75 | // p erform sea rch | |
76 | try { | |
77 | ldapCo ntext = ne w InitialL dapContext (AD_LDAP_E NVIRONMENT , null); | |
78 | ||
79 | // System .out.print ln("%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% AFTER Ini tialLdapCo ntext" + A D_LDAP_ENV IRONMENT ) ; | |
80 | ||
81 | Naming Enumeratio n searchRe sults = ld apContext. search(lda pEnvironme nt.getAdSe archBase() , searchFi lter, null ); | |
82 | ||
83 | // System .out.print ln("%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% searchRes ults " + s earchResul ts ); | |
84 | // no results fo und | |
85 | if (se archResult s.hasMoreE lements() == false) { | |
86 | userAlre adyExists = false; | |
87 | ||
88 | // System.o ut.println ("%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%% u serAlready Exists " + userAlrea dyExists ) ; | |
89 | // respo nse.setFai lure(true) ; | |
90 | // valid ator.addEr ror(respon se, | |
91 | // UserM anagementM essages.SE ARCH_NO_RE SULTS, nul l); | |
92 | } else { | |
93 | while (s earchResul ts.hasMore Elements() ) { | |
94 | SearchResu lt searchR esult = (S earchResul t) searchR esults.nex t(); | |
95 | Attributes searchRes ultAttribu tes = sear chResult.g etAttribut es(); | |
96 | if (search ResultAttr ibutes != null) { | |
97 | us erAlreadyE xists = tr ue; | |
98 | // if we are using thi s helper m ethod to p opulate | |
99 | // results | |
100 | // for colle ction resp onse, we a dd search result int o | |
101 | // response in differe nt manner | |
102 | /* if (collec tionRespon se) { | |
103 | ((Em ployeeSear chResultCo llectionSe rviceRespo nse) | |
104 | re sponse).ad dEmployeeS earchResul t( | |
105 | conv ertToEmplo yeeSearchR esult(sear chResultAt tributes)) ; | |
106 | } else { | |
107 | ((Em ployeeSear chResultSe rviceRespo nse) respo nse). | |
108 | setE mployeeSea rchResult( | |
109 | conver tToEmploye eSearchRes ult(search ResultAttr ibutes)); | |
110 | }* / | |
111 | // Sy stem.out.p rintln("%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%% %%%% userA lreadyExis ts " + use rAlreadyEx ists ); | |
112 | re sponse.set Failure(fa lse); | |
113 | re sponse.set Success(tr ue); | |
114 | re sponse.set PojoObject (convertTo EmployeeSe archResult (searchRes ultAttribu tes)); | |
115 | } | |
116 | } | |
117 | } | |
118 | } ca tch (Namin gException e) { | |
119 | log.er ror("Faile d to conne ct to Acti ve Directo ry", e); | |
120 | // val idator.add Error(resp onse, | |
121 | // Use rManagemen tMessages. SEARCH_FAI LED, null) ; | |
122 | throw new MHVRun timeExcept ion(messag esUtil.get EmployeeSe archFailed ()); | |
123 | } fi nally { | |
124 | try { | |
125 | if (ldap Context != null) { | |
126 | ldapContex t.close(); // attemp t to close connectio n | |
127 | // regardl ess | |
128 | } | |
129 | } catc h (NamingE xception e ) { | |
130 | log.erro r("Failed to close c onnection to Active Directory" , e); | |
131 | // valid ator.addEr ror(respon se, | |
132 | // UserM anagementM essages.SE ARCH_FAILE D, null); | |
133 | throw ne w MHVRunti meExceptio n(messages Util.getEm ployeeSear chFailed() ); | |
134 | } fina lly { | |
135 | ldapCont ext = null ; // relea se handle to connect ion regard less | |
136 | } | |
137 | } | |
138 | ||
139 | retu rn userAlr eadyExists ; | |
140 | } | |
141 | ||
142 | @O verride | |
143 | pu blic void searchByNa me(String firstName, String la stName, Re sponseUtil response) { | |
144 | ||
145 | // T ODO Auto-g enerated m ethod stub | |
146 | retu rn; | |
147 | } | |
148 | ||
149 | privat e static f inal Emplo yeeSearchR esult conv ertToEmplo yeeSearchR esult( | |
150 | Attribut es attribu tes) throw s NamingEx ception { | |
151 | Employee SearchResu lt employe eSearchRes ult = new EmployeeSe archResult (); | |
152 | ||
153 | if (attr ibutes.get ("sAMAccou ntName") ! = null) | |
154 | empl oyeeSearch Result.set UserName(( String) at tributes.g et( | |
155 | "sAMAccoun tName").ge t()); | |
156 | ||
157 | if (attr ibutes.get ("givenNam e") != nul l) | |
158 | empl oyeeSearch Result.set FirstName( (String) a ttributes. get( | |
159 | "givenName ").get()); | |
160 | ||
161 | if (attr ibutes.get ("sn") != null) | |
162 | empl oyeeSearch Result.set LastName(( String) at tributes.g et("sn") | |
163 | .get()); | |
164 | ||
165 | if (attr ibutes.get ("title") != null) | |
166 | empl oyeeSearch Result.set Title((Str ing) attri butes.get( "title") | |
167 | .get()); | |
168 | ||
169 | if (attr ibutes.get ("physical DeliveryOf ficeName") != null) | |
170 | empl oyeeSearch Result.set Office((St ring) attr ibutes.get ( | |
171 | "physicalD eliveryOff iceName"). get()); | |
172 | ||
173 | if (attr ibutes.get ("departme nt") != nu ll) | |
174 | empl oyeeSearch Result.set Department ((String) attributes .get( | |
175 | "departmen t").get()) ; | |
176 | ||
177 | if (attr ibutes.get ("company" ) != null) | |
178 | empl oyeeSearch Result.set Company((S tring) att ributes.ge t("company ") | |
179 | .get()); | |
180 | ||
181 | if (attr ibutes.get ("telephon eNumber") != null) | |
182 | empl oyeeSearch Result.set Phone((Str ing) attri butes.get( | |
183 | "telephone Number").g et()); | |
184 | ||
185 | if (attr ibutes.get ("mail") ! = null) | |
186 | empl oyeeSearch Result | |
187 | .setEmail( (String) a ttributes. get("mail" ).get()); | |
188 | ||
189 | employee SearchResu lt.setFull Name(emplo yeeSearchR esult.getL astName() | |
190 | + ", " + emplo yeeSearchR esult.getF irstName() ); | |
191 | ||
192 | return e mployeeSea rchResult; | |
193 | } | |
194 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.