Produced by Araxis Merge on 10/18/2018 2:02:21 PM 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 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\TransactionContext\main\src\java\gov\va\med\imaging\transactioncontext | TransactionContextProxyInvocationHandler.java | Thu Oct 11 13:30:11 2018 UTC |
2 | VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\TransactionContext\main\src\java\gov\va\med\imaging\transactioncontext | TransactionContextProxyInvocationHandler.java | Wed Oct 17 19:07:33 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 2216 |
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.i maging.tra nsactionco ntext; | |
5 | ||
6 | import gov .va.med.Ap plicationP ropertyAcc essor; | |
7 | import gov .va.med.im aging.Stac kTraceAnal yzer; | |
8 | import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmPrinci pal; | |
9 | import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmSecuri tyContext; | |
10 | import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmPrinci pal.Authen ticationCr edentialsT ype; | |
11 | import jav a.io.IOExc eption; | |
12 | import jav a.lang.ref lect.Invoc ationHandl er; | |
13 | import jav a.lang.ref lect.Metho d; | |
14 | import org .apache.lo gging.log4 j.LogManag er; | |
15 | import org .apache.lo gging.log4 j.Logger; | |
16 | ||
17 | /** | |
18 | * @author PI I
|
|
19 | * | |
20 | */ | |
21 | public cla ss Transac tionContex tProxyInvo cationHand ler | |
22 | implements Invocatio nHandler | |
23 | { | |
24 | /* * | |
25 | * Meta Meth od method name const ants | |
26 | * / | |
27 | pr ivate stat ic final S tring SET_ MEMENTO = "setMement o"; | |
28 | pr ivate stat ic final S tring GET_ CONTEXT_DE BUG_STATE = "getCont extDebugSt ate"; | |
29 | pr ivate stat ic final S tring IS_C LIENT_PRIN CIPAL = "i sClientPri ncipal"; | |
30 | pr ivate stat ic final S tring GET_ DISPLAY_ID ENTITY = " getDisplay Identity"; | |
31 | pr ivate stat ic final S tring CLEA R = "clear "; | |
32 | pr ivate stat ic final S tring GET_ MEMENTO = "getMement o"; | |
33 | pr ivate stat ic final S tring GET_ IDENTITY = "getIdent ity"; | |
34 | pr ivate stat ic final S tring CREA TE_CHILD_C LONE = "cr eateChildC lone"; | |
35 | pr ivate stat ic final S tring GET_ ADDITIONAL _DEBUG_INF ORMATION = "getAddit ionalDebug Informatio n"; | |
36 | ||
37 | /* * | |
38 | * The stand ard prefix for a GET accessor. | |
39 | * Note we o nly do Str ing proper ties so no "is" meth ods but we have | |
40 | * some spec ial cases with boole n types in VistaReal mPrincipal . | |
41 | * / | |
42 | pr ivate stat ic final S tring GET_ ACCESSOR_P REFIX = "g et"; | |
43 | pr ivate stat ic final S tring IS_A CCESSOR_PR EFIX = "is "; | |
44 | ||
45 | /* * | |
46 | * The stand ard prefix for a SET accessor. | |
47 | * / | |
48 | pr ivate stat ic final S tring SET_ ACCESSOR_P REFIX = "s et"; | |
49 | ||
50 | pr ivate stat ic final S tring ADD_ ACCESSOR_P REFIX = "a dd"; | |
51 | ||
52 | /* * | |
53 | * Logger ac cessor met hods get t heir value s from app lication p roperties | |
54 | * preferent ially over "real" pr operties. | |
55 | * / | |
56 | pr ivate stat ic final S tring LOGG ER_ACCESSO R_PREFIX = "Logger"; // i.e. as in getLog gerSiteNam e() | |
57 | pr ivate stat ic final S tring LOGG ER_PROPERT Y_PREFIX = "logger"; // i.e. lo ggerSiteNa me | |
58 | ||
59 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ==== | |
60 | // Known Pro perties by the type of access granted | |
61 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ==== | |
62 | ||
63 | // Immutable Propertie s | |
64 | pr ivate stat ic final S tring ACCE SS_CODE_PR OPERTY = " accessCode "; // mutable if princi pal is cli ent type | |
65 | pr ivate stat ic final S tring VERI FY_CODE_PR OPERTY = " verifyCode "; // mutable if princi pal is cli ent type | |
66 | pr ivate stat ic final S tring NAME _PROPERTY = "name"; | |
67 | pr ivate stat ic final S tring REAL M_PROPERTY = "realm" ; | |
68 | pr ivate stat ic final S tring AUTH ENTICATED_ BY_DELEGAT E_PROPERTY = "authen ticatedByD elegate"; | |
69 | pr ivate stat ic final S tring CRED ENTIALS_TY PE_PROPERT Y = "crede ntialsType "; | |
70 | pr ivate stat ic final S tring SECU RITY_HASHC ODE_PROPER TY = "secu rityHashCo de"; | |
71 | pr ivate stat ic final S tring AUTH ENTICATED_ BY_VISTA_P ROPERTY = "authentic atedByVist a"; | |
72 | ||
73 | pr ivate stat ic boolean isImmutab leProperty (String pr opertyName ) | |
74 | { | |
75 | retu rn | |
76 | ACCESS _CODE_PROP ERTY.equal s(property Name) || | |
77 | VERIFY _CODE_PROP ERTY.equal s(property Name) || | |
78 | NAME_P ROPERTY.eq uals(prope rtyName) | | | |
79 | REALM_ PROPERTY.e quals(prop ertyName) || | |
80 | AUTHEN TICATED_BY _DELEGATE_ PROPERTY.e quals(prop ertyName) || | |
81 | CREDEN TIALS_TYPE _PROPERTY. equals(pro pertyName) || | |
82 | SECURI TY_HASHCOD E_PROPERTY .equals(pr opertyName ) || | |
83 | AUTHEN TICATED_BY _VISTA_PRO PERTY.equa ls(propert yName); | |
84 | } | |
85 | ||
86 | // Requestor Propertie s | |
87 | pr ivate stat ic final S tring SITE _NAME_PROP ERTY = "si teName"; | |
88 | pr ivate stat ic final S tring SITE _NUMBER_PR OPERTY = " siteNumber "; | |
89 | pr ivate fina l static S tring SSN_ PROPERTY = "ssn"; | |
90 | pr ivate stat ic final S tring DUZ_ PROPERTY = "duz"; | |
91 | pr ivate stat ic final S tring FULL NAME_PROPE RTY = "ful lName"; | |
92 | pr ivate stat ic final S tring SECU RITY_TOKEN _PROPERTY = "brokerS ecurityTok en"; | |
93 | pr ivate stat ic final S tring CACH E_LOCATION _ID_PROPER TY = "cach eLocationI d"; | |
94 | pr ivate stat ic final S tring USER _DIVISION_ PROPERTY = "userDivi sion"; | |
95 | ||
96 | pr ivate stat ic boolean isRequest orProperty (String pr opertyName ) | |
97 | { | |
98 | retu rn | |
99 | SITE_N AME_PROPER TY.equals( propertyNa me) || | |
100 | SITE_N UMBER_PROP ERTY.equal s(property Name) || | |
101 | SSN_PR OPERTY.equ als(proper tyName) || | |
102 | DUZ_PR OPERTY.equ als(proper tyName) || | |
103 | FULLNA ME_PROPERT Y.equals(p ropertyNam e) || | |
104 | SECURI TY_TOKEN_P ROPERTY.eq uals(prope rtyName) | | | |
105 | CACHE_ LOCATION_I D_PROPERTY .equals(pr opertyName ) || | |
106 | USER_D IVISION_PR OPERTY.equ als(proper tyName); | |
107 | } | |
108 | ||
109 | pr ivate fina l static S tring DEBU G_PROPERTY = "debugI nformation "; | |
110 | ||
111 | pr ivate stat ic boolean isDebugPr operty(Str ing proper tyName) | |
112 | { | |
113 | retu rn DEBUG_P ROPERTY.eq uals(prope rtyName); | |
114 | } | |
115 | ||
116 | // Applicati onProperty Accessor i nstances w ill take a ny Object instance a nd try to | |
117 | // extract a value in t he desired type. If they cann ot do the type conve rsion then | |
118 | // they retu rn null. | |
119 | pr ivate stat ic Applica tionProper tyAccessor <String> s tringPrope rtyAccesso r; | |
120 | ||
121 | pr ivate stat ic Applica tionProper tyAccessor <Boolean> booleanPro pertyAcces sor; | |
122 | ||
123 | pr ivate stat ic Applica tionProper tyAccessor <Character > characte rPropertyA ccessor; | |
124 | ||
125 | pr ivate stat ic Applica tionProper tyAccessor <Byte> byt ePropertyA ccessor; | |
126 | pr ivate stat ic Applica tionProper tyAccessor <Short> sh ortPropert yAccessor; | |
127 | ||
128 | pr ivate stat ic Applica tionProper tyAccessor <Integer> integerPro pertyAcces sor; | |
129 | pr ivate stat ic Applica tionProper tyAccessor <Long> lon gPropertyA ccessor; | |
130 | ||
131 | pr ivate stat ic Applica tionProper tyAccessor <Float> fl oatPropert yAccessor; | |
132 | pr ivate stat ic Applica tionProper tyAccessor <Double> d oublePrope rtyAccesso r; | |
133 | ||
134 | pr ivate stat ic Applica tionProper tyAccessor <Object> o bjectPrope rtyAccesso r; | |
135 | ||
136 | pr ivate stat ic boolean warnOnPro pertOverwr ite = fals e; | |
137 | ||
138 | st atic | |
139 | { | |
140 | stri ngProperty Accessor = | |
141 | new Ap plicationP ropertyAcc essor<Stri ng>("toStr ing", null ); | |
142 | ||
143 | try | |
144 | { | |
145 | bool eanPropert yAccessor = | |
146 | new Ap plicationP ropertyAcc essor<Bool ean>("bool eanValue", | |
147 | Boolean. class.getM ethod("par seBoolean" , new Clas s[]{String .class}) | |
148 | ); | |
149 | } | |
150 | catc h (Excepti on e) | |
151 | { | |
152 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating b oolean pro perty acce ssor", e); | |
153 | } | |
154 | ||
155 | char acterPrope rtyAccesso r = | |
156 | new Ap plicationP ropertyAcc essor<Char acter>("ch arValue", null); | |
157 | ||
158 | try | |
159 | { | |
160 | bytePr opertyAcce ssor = | |
161 | new Appl icationPro pertyAcces sor<Byte>( "byteValue ", | |
162 | Byte.class .getMethod ("parseByt e", new Cl ass[]{Stri ng.class}) | |
163 | ); | |
164 | } | |
165 | catc h (Excepti on e) | |
166 | { | |
167 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating b yte proper ty accesso r", e); | |
168 | } | |
169 | ||
170 | try | |
171 | { | |
172 | shortP ropertyAcc essor = | |
173 | new Appl icationPro pertyAcces sor<Short> ("shortVal ue", | |
174 | Short.clas s.getMetho d("parseSh ort", new Class[]{St ring.class }) | |
175 | ); | |
176 | } | |
177 | catc h (Excepti on e) | |
178 | { | |
179 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating s hort prope rty access or", e); | |
180 | } | |
181 | ||
182 | try | |
183 | { | |
184 | intege rPropertyA ccessor = | |
185 | new Appl icationPro pertyAcces sor<Intege r>("intVal ue", | |
186 | Integer.cl ass.getMet hod("parse Int", new Class[]{St ring.class }) | |
187 | ); | |
188 | } | |
189 | catc h (Excepti on e) | |
190 | { | |
191 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating i nteger pro perty acce ssor", e); | |
192 | } | |
193 | ||
194 | try | |
195 | { | |
196 | longPr opertyAcce ssor = | |
197 | new Appl icationPro pertyAcces sor<Long>( "longValue ", | |
198 | Long.class .getMethod ("parseLon g", new Cl ass[]{Stri ng.class}) | |
199 | ); | |
200 | } | |
201 | catc h (Excepti on e) | |
202 | { | |
203 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating l ong proper ty accesso r", e); | |
204 | } | |
205 | ||
206 | try | |
207 | { | |
208 | floatP ropertyAcc essor = | |
209 | new Appl icationPro pertyAcces sor<Float> ("floatVal ue", | |
210 | Float.clas s.getMetho d("parseFl oat", new Class[]{St ring.class }) | |
211 | ); | |
212 | } | |
213 | catc h (Excepti on e) | |
214 | { | |
215 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating f loat prope rty access or", e); | |
216 | } | |
217 | ||
218 | try | |
219 | { | |
220 | double PropertyAc cessor = | |
221 | new Appl icationPro pertyAcces sor<Double >("doubleV alue", | |
222 | Double.cla ss.getMeth od("parseD ouble", ne w Class[]{ String.cla ss}) | |
223 | ); | |
224 | } | |
225 | catc h (Excepti on e) | |
226 | { | |
227 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating d ouble prop erty acces sor", e); | |
228 | } | |
229 | ||
230 | try | |
231 | { | |
232 | object PropertyAc cessor = n ew Applica tionProper tyAccessor <Object>(n ull, null) ; | |
233 | } | |
234 | catc h (Excepti on e) | |
235 | { | |
236 | LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception creating d ouble prop erty acces sor", e); | |
237 | } | |
238 | } | |
239 | ||
240 | pr ivate stat ic Applica tionProper tyAccessor <?> getPro pertyAcces sorForType (Class<?> clazz) | |
241 | { | |
242 | if(B oolean.cla ss.isAssig nableFrom( clazz) || Boolean.TY PE == claz z ) | |
243 | return booleanPr opertyAcce ssor; | |
244 | if(B yte.class. isAssignab leFrom(cla zz) || Byt e.TYPE == clazz) | |
245 | return bytePrope rtyAccesso r; | |
246 | if(C haracter.c lass.isAss ignableFro m(clazz) | | Characte r.TYPE == clazz ) | |
247 | return character PropertyAc cessor; | |
248 | if(S hort.class .isAssigna bleFrom(cl azz) || Sh ort.TYPE = = clazz ) | |
249 | return shortProp ertyAccess or; | |
250 | if(I nteger.cla ss.isAssig nableFrom( clazz) || Integer.TY PE == claz z ) | |
251 | return integerPr opertyAcce ssor; | |
252 | if(L ong.class. isAssignab leFrom(cla zz) || Lon g.TYPE == clazz ) | |
253 | return longPrope rtyAccesso r; | |
254 | if(F loat.class .isAssigna bleFrom(cl azz) || Fl oat.TYPE = = clazz ) | |
255 | return floatProp ertyAccess or; | |
256 | if(D ouble.clas s.isAssign ableFrom(c lazz) || D ouble.TYPE == clazz ) | |
257 | return doublePro pertyAcces sor; | |
258 | if(S tring.clas s == clazz ) | |
259 | return stringPro pertyAcces sor; | |
260 | ||
261 | retu rn objectP ropertyAcc essor; | |
262 | } | |
263 | ||
264 | /* * | |
265 | * if true t hen a warn ing will b e logged w hen a prop erty value is overwr itten | |
266 | * this shou ld usually be false because it can produ ce so much log outpu t that | |
267 | * it signif icantly sl ows unit t esting | |
268 | * @return | |
269 | * / | |
270 | pu blic stati c boolean isWarnOnPr opertOverw rite() | |
271 | { | |
272 | retu rn warnOnP ropertOver write; | |
273 | } | |
274 | ||
275 | pu blic stati c void set WarnOnProp ertOverwri te(boolean warnOnPro pertOverwr ite) | |
276 | { | |
277 | Tran sactionCon textProxyI nvocationH andler.war nOnPropert Overwrite = warnOnPr opertOverw rite; | |
278 | } | |
279 | ||
280 | /* * | |
281 | * Return a boolean in dicating i f a transa ction cont ext has be en establi shed. | |
282 | * Returns t rue if a c all to cre ate a Tran sactionCon textProxyI nvocationH andler wou ld | |
283 | * result in a valid t ransaction context. If the un derlying s ecurity co ntext does not | |
284 | * exist the n this wil l return f alse and a new insta nce of Tra nsactionCo ntextProxy Invocation Handler | |
285 | * will be r unning aga inst a "cl ient" inst ance of Pr incipal wi th no real security context. | |
286 | * Note that this diff ers from t esting the get() met hod result for null, which | |
287 | * will crea te a trans action con text. | |
288 | * | |
289 | * @return | |
290 | * / | |
291 | pu blic stati c boolean isTransact ionContext Establishe d() | |
292 | { | |
293 | retu rn VistaRe almSecurit yContext.g et() != nu ll; | |
294 | } | |
295 | ||
296 | // the insta nce logger | |
297 | pr ivate fina l static L ogger logg er = LogMa nager.getL ogger(Tran sactionCon textProxyI nvocationH andler.cla ss); | |
298 | ||
299 | // the Vista RealmPrinc ipal insta nce that t his transa ction cont ext wraps | |
300 | pr ivate fina l VistaRea lmPrincipa l principa l; | |
301 | ||
302 | /* * | |
303 | * Construct a new Tra nsactionCo ntextProxy Invocation Handler us ing the cu rrent | |
304 | * threads V istaRealmP rincipal a s the back ing store. | |
305 | * | |
306 | * / | |
307 | pu blic Trans actionCont extProxyIn vocationHa ndler() | |
308 | { | |
309 | supe r(); | |
310 | ||
311 | Vist aRealmPrin cipal temp Principal = VistaRea lmSecurity Context.ge t(); | |
312 | if(t empPrincip al == null ) | |
313 | { | |
314 | Throwa ble t = ne w Throwabl e(); | |
315 | StackT raceAnalyz er analyze r = new St ackTraceAn alyzer( t. getStackTr ace() ); | |
316 | StackT raceElemen t culprit = analyzer .getFirstE lementNotI nPackage(" gov.va.med .imaging.t ransaction context"); | |
317 | //t.pr intStackTr ace(); | |
318 | ||
319 | // JMW 1/26/2012 - we neve r pay atte ntion to t his warnin g message so I'm dow n grading the log le vel so it doesn't sh ow up as m uch | |
320 | logger .debug( | |
321 | "VistaRe almSecurit yContext p rincipal h as not bee n created on thread '" + Threa d.currentT hread().ge tName() + "' before instantiat ing Transa ctionConte xt. \n" + | |
322 | "A null security c ontext wil l be creat ed.\n" + | |
323 | "If this occurs wh ile runnin g in a ser ver enviro nment then \n" + | |
324 | "\tthe t hread is c urrently o perating w ith no rea l security context\n " + | |
325 | "\tasycn chronous p roxy threa ds will ha ve a secur ity contex t assigned when they are used. \n" + | |
326 | "If this occurs wh ile runnin g in a cli ent enviro nment then \n" + | |
327 | "\tthe a pplication should se t the secu rity conte xt before calling pr oxies.\n" + | |
328 | "The mos t likely c alling cod e is '" + culprit.ge tClassName () + ":" + + culprit .getLineNu mber() + " '." | |
329 | ); | |
330 | ||
331 | tempPr incipal = new VistaR ealmPrinci pal("clien t", true, Authentica tionCreden tialsType. Password); | |
332 | //temp Principal = null; | |
333 | } | |
334 | ||
335 | prin cipal = te mpPrincipa l; | |
336 | Vist aRealmSecu rityContex t.set(prin cipal); | |
337 | } | |
338 | ||
339 | /* * | |
340 | * | |
341 | * @param pr incipal | |
342 | * / | |
343 | pu blic Trans actionCont extProxyIn vocationHa ndler(fina l VistaRea lmPrincipa l principa l) | |
344 | { | |
345 | supe r(); | |
346 | Vist aRealmPrin cipal temp Principal = VistaRea lmSecurity Context.ge t(); | |
347 | if(t empPrincip al == null ) | |
348 | { | |
349 | this.p rincipal = principal ; | |
350 | VistaR ealmSecuri tyContext. set(princi pal); | |
351 | } | |
352 | else | |
353 | { | |
354 | logger .warn("Att empt to se t Principa l instance in Transa ctionConte xt after t ransaction context h as been es tablished. "); | |
355 | this.p rincipal = tempPrinc ipal; | |
356 | } | |
357 | } | |
358 | ||
359 | /* * | |
360 | * | |
361 | * @param se curityCont extMemento | |
362 | * @throws I llegalArgu mentExcept ion | |
363 | * / | |
364 | pu blic Trans actionCont extProxyIn vocationHa ndler(fina l Object s ecurityCon textMement o) | |
365 | th rows Illeg alArgument Exception | |
366 | { | |
367 | supe r(); | |
368 | if(s ecurityCon textMement o instance of VistaRe almPrincip al) | |
369 | this.p rincipal = (VistaRea lmPrincipa l)security ContextMem ento; | |
370 | else | |
371 | throw new Illega lArgumentE xception(" Security C ontext Mem ento is of an unknow n type"); | |
372 | } | |
373 | ||
374 | /* * | |
375 | * @return t he princip al | |
376 | * / | |
377 | pr ivate Vist aRealmPrin cipal getP rincipal() | |
378 | { | |
379 | retu rn this.pr incipal; | |
380 | } | |
381 | ||
382 | pr ivate Bool ean isClie ntPrincipa l() | |
383 | { | |
384 | Vist aRealmPrin cipal p = getPrincip al(); | |
385 | retu rn p != nu ll && p in stanceof C lientPrinc ipal; | |
386 | } | |
387 | ||
388 | /* * | |
389 | * All invoc ations sho uld come t hrough the Transacti onContext interface. We do on e of two t hings | |
390 | * with the invoke(): | |
391 | * first, if it is a k nown acces sor method being cal led we sim ply pass t he | |
392 | * call to t he known m ethod, | |
393 | * second: i f the meth od is not one of the known met hods and i t is a Str ing access or (i.e. | |
394 | * String ge tX(){} or void setX( String val ue)) then we get or set the va lue from a | |
395 | * Map<Strin g,String> that is ma intained b y the Vist aRealmPrin cipal inst ance. | |
396 | * | |
397 | * @see java .lang.refl ect.Invoca tionHandle r#invoke(j ava.lang.O bject, jav a.lang.ref lect.Metho d, java.la ng.Object[ ]) | |
398 | * / | |
399 | pu blic synch ronized Ob ject invok e(Object p roxy, Meth od method, Object[] args) | |
400 | th rows Throw able | |
401 | { | |
402 | //lo gger.debug ("...enter ing invoke method.") ; | |
403 | try | |
404 | { | |
405 | // met a-methods are method s that ret urn info a bout the t ransaction | |
406 | // con text and n ot necessa rily the t ransaction context p roperties | |
407 | // for example: getting a memento (s erializabl e represen tation) | |
408 | return invokeMet aMethods(g etPrincipa l(), proxy , method, args); | |
409 | } | |
410 | catc h(NoSuchMe thodExcept ion nsmX) | |
411 | { | |
412 | // if the securi ty princip al has bee n cleared then just return a n ull | |
413 | if(pri ncipal == null) | |
414 | { | |
415 | logger.w arn("Attem pt to call method " + method.g etName() + " after s ecurity co ntext has been clear ed is bein g ignored. "); | |
416 | return n ull; | |
417 | } | |
418 | ||
419 | try | |
420 | { | |
421 | return i nvokeKnown Method(get Principal( ), method, args); | |
422 | } | |
423 | catch (NoSuchMet hodExcepti on nsmX2) | |
424 | { | |
425 | // if th e method i s not one of the sta tically ma pped metho ds then pa rse the me thod | |
426 | // to ge t the fiel d name des ired. | |
427 | return i nvokeUnkno wnMethod(g etPrincipa l(), metho d, args); | |
428 | } | |
429 | } | |
430 | ||
431 | } | |
432 | ||
433 | /* * | |
434 | * MetaMetho ds are tra nsaction c ontext man agement me thods. | |
435 | * In genera l, applica tion code should not call thes e methods. These | |
436 | * methods a re used pr edominantl y for tran sferring t ransaction context | |
437 | * between a synchronou s threads (and for t esting). | |
438 | * Mete-meth ods are ca lled befor e checking that a pr incipal ex ists, meta -methods | |
439 | * that rely on the ex istence of a Princip al must ch eck that i t exists b efore | |
440 | * continuin g. | |
441 | * | |
442 | * @param pr oxy | |
443 | * @param pr oxy2 | |
444 | * @param me thod | |
445 | * @param ar gs | |
446 | * / | |
447 | pr ivate Obje ct invokeM etaMethods (VistaReal mPrincipal principal , Object p roxy, Meth od method, Object[] args) | |
448 | th rows NoSuc hMethodExc eption | |
449 | { | |
450 | //lo gger.debug ("...enter ing invoke MetaMethod s method." ); | |
451 | // t he setMeme nto method may run w ithout a P rincipal i nstance as sociated t o the cont ext, | |
452 | // b ecause it sets one | |
453 | if( SET_MEMENT O.equals(m ethod.getN ame()) && (args != n ull && arg s.length = = 1) && ar gs[0] inst anceof Tra nsactionCo ntextMemen to ) | |
454 | { | |
455 | try | |
456 | { | |
457 | VistaRea lmPrincipa l principa lClone = T ransaction ContextMem ento.creat e((Transac tionContex tMemento)a rgs[0]); | |
458 | principa l.setAll(p rincipalCl one); | |
459 | ||
460 | return n ull; | |
461 | } | |
462 | catch (Throwable x) | |
463 | { | |
464 | String l ocation; | |
465 | if( x.ge tStackTrac e() != nul l && x.get StackTrace ().length > 0) | |
466 | { | |
467 | location = x.getStac kTrace()[0 ].getFileN ame() + ": " + x.getS tackTrace( )[0].getLi neNumber() ; | |
468 | } | |
469 | else | |
470 | location = "<locatio n unknown> "; | |
471 | ||
472 | logger.e rror(locat ion, x); | |
473 | return n ull; | |
474 | } | |
475 | } | |
476 | ||
477 | // A s close to bulletpro of as we c an make it , return a useful de scription of the cur rent conte xt | |
478 | // s tate. | |
479 | if(G ET_CONTEXT _DEBUG_STA TE.equals( method.get Name()) && | |
480 | (metho d.getParam eterTypes( ) == null || method. getParamet erTypes(). length == 0) && | |
481 | java.l ang.String .class.equ als(method .getReturn Type()) ) | |
482 | { | |
483 | return buildCont extStateDe bugString( ); | |
484 | } | |
485 | ||
486 | // m ethods bel ow this co nditional may rely o n the Prin cipal exis ting. | |
487 | if(p rincipal = = null) | |
488 | { | |
489 | logger .warn("Att empt to ca ll method " + method .getName() + " with no securit y context is being i gnored."); | |
490 | return null; | |
491 | } | |
492 | ||
493 | if( IS_CLIENT_ PRINCIPAL. equals(met hod.getNam e()) && (a rgs == nul l || args. length == 0) && Bool ean.class. isAssignab leFrom(met hod.getRet urnType()) ) | |
494 | { | |
495 | return isClientP rincipal() ; | |
496 | } | |
497 | ||
498 | if( GET_DISPLA Y_IDENTITY .equals(me thod.getNa me()) && ( args == nu ll || args .length == 0) && Str ing.class. isAssignab leFrom(met hod.getRet urnType()) ) | |
499 | { | |
500 | return principal .getAccess Code() + " , " + prin cipal.getA pplication Property(" transactio nId"); | |
501 | } | |
502 | ||
503 | if( CLEAR.equa ls(method. getName()) && (args == null || args.leng th == 0) ) | |
504 | { | |
505 | VistaR ealmSecuri tyContext. clear(); | |
506 | princi pal = null ; | |
507 | return null; | |
508 | } | |
509 | ||
510 | if( GET_MEMENT O.equals(m ethod.getN ame()) && (args == n ull || arg s.length = = 0) && Tr ansactionC ontextMeme nto.class. isAssignab leFrom(met hod.getRet urnType()) ) | |
511 | { | |
512 | try | |
513 | { | |
514 | Transact ionContext Memento me mento = Tr ansactionC ontextMeme nto.create (principal ); | |
515 | return m emento; | |
516 | } | |
517 | catch (IOExcepti on x) | |
518 | { | |
519 | logger.e rror(x); | |
520 | return n ull; | |
521 | } | |
522 | } | |
523 | ||
524 | if( GET_IDENTI TY.equals( method.get Name()) && (args == null || ar gs.length == 0) ) | |
525 | { | |
526 | return new Integ er(princip al == null ? 0 : Sys tem.identi tyHashCode (principal )); | |
527 | } | |
528 | ||
529 | if( CREATE_CHI LD_CLONE.e quals(meth od.getName ()) && (ar gs == null || args.l ength == 0 ) ) | |
530 | { | |
531 | return principal == null ? null : pr incipal.cl one(); | |
532 | } | |
533 | ||
534 | if(G ET_ADDITIO NAL_DEBUG_ INFORMATIO N.equals(m ethod.getN ame()) && | |
535 | (method. getParamet erTypes() == null || method.ge tParameter Types().le ngth == 0) && | |
536 | java.lan g.String.c lass.equal s(method.g etReturnTy pe()) ) | |
537 | { | |
538 | return buildAddi tionalDebu gInformati onString() ; | |
539 | } | |
540 | ||
541 | Stri ngBuilder msg = new StringBuil der(); | |
542 | msg. append("Me thod ["+ m ethod.getN ame() + "] did not m ake it thr u any of t he IF stat ements."); | |
543 | msg. append(" Method Ret urn Type: ["+method. getReturnT ype()+"]") ; | |
544 | msg. append(" Method Par ameter Typ es: ["+ me thod.getPa rameterTyp es()+"]"); | |
545 | ||
546 | logg er.trace(m sg.toStrin g()); | |
547 | thro w new NoSu chMethodEx ception(); | |
548 | } | |
549 | ||
550 | /* * | |
551 | * @return | |
552 | * / | |
553 | pr ivate Obje ct buildCo ntextState DebugStrin g() | |
554 | { | |
555 | if(p rincipal = = null) | |
556 | return "Principa l is not s et, transa ction cont ext unavai lable."; | |
557 | ||
558 | if(T ransaction Context.de bugPropert ies == nul l) | |
559 | return "No debug propertie s configur ed."; | |
560 | ||
561 | Stri ngBuilder sb = new S tringBuild er(); | |
562 | ||
563 | for( String pro pertyName : Transact ionContext .debugProp erties) | |
564 | { | |
565 | sb.app end(proper tyName); | |
566 | sb.app end('='); | |
567 | sb.app end('\''); | |
568 | ||
569 | Object value = n ull; | |
570 | if(isI mmutablePr operty(pro pertyName) ) | |
571 | value = invokeImmu tablePrope rtyGetAcce ssor(princ ipal, prop ertyName); | |
572 | else i f(isReques torPropert y(property Name)) | |
573 | value = invokeProp ertyGetAcc essor(prin cipal, pro pertyName) ; | |
574 | else | |
575 | value = principal. getApplica tionProper ty(propert yName); | |
576 | ||
577 | sb.app end(value= =null ? "< null>" : v alue.toStr ing()); | |
578 | sb.app end('\''); | |
579 | } | |
580 | ||
581 | retu rn sb.toSt ring(); | |
582 | } | |
583 | ||
584 | pr ivate Stri ng buildAd ditionalDe bugInforma tionString () | |
585 | { | |
586 | if(p rincipal = = null) | |
587 | return null; | |
588 | ||
589 | if(T ransaction Context.ad ditionalDe bugInforma tionProper ties == nu ll) | |
590 | return null; | |
591 | ||
592 | Stri ngBuilder sb = new S tringBuild er(); | |
593 | Stri ng prefix = ""; | |
594 | ||
595 | for( String pro pertyName : Transact ionContext .additiona lDebugInfo rmationPro perties) | |
596 | { | |
597 | Object value = n ull; | |
598 | if(isI mmutablePr operty(pro pertyName) ) | |
599 | value = invokeImmu tablePrope rtyGetAcce ssor(princ ipal, prop ertyName); | |
600 | else i f(isReques torPropert y(property Name)) | |
601 | value = invokeProp ertyGetAcc essor(prin cipal, pro pertyName) ; | |
602 | else | |
603 | value = principal. getApplica tionProper ty(propert yName); | |
604 | ||
605 | if(val ue != null ) | |
606 | { | |
607 | sb.appen d(prefix); | |
608 | sb.appen d(property Name); | |
609 | sb.appen d('='); | |
610 | sb.appen d(value.to String()); | |
611 | prefix = Transacti onContext. debugInfor mationDeli miter; | |
612 | } | |
613 | } | |
614 | ||
615 | // i f none of the proper ties have values the n just ret urn null | |
616 | if(s b.length() == 0) | |
617 | return null; | |
618 | ||
619 | retu rn sb.toSt ring(); | |
620 | } | |
621 | ||
622 | /* * | |
623 | * Invoke on e of the k nown metho ds, those that map d irectly to VistaReal mPrincipal calls. | |
624 | * NOTE: all of these methods ar e, and mus t be, Stri ng accesso rs. | |
625 | * @param pr incipal | |
626 | * @param me thod | |
627 | * @param ar gs | |
628 | * @return | |
629 | * @throws N oSuchMetho dException - thrown if the met hod is not one of th e known ma ppings | |
630 | * / | |
631 | pr ivate Obje ct invokeK nownMethod (VistaReal mPrincipal principal , Method m ethod, Obj ect[] args ) | |
632 | th rows NoSuc hMethodExc eption | |
633 | { | |
634 | //lo gger.debug ("...enter ing invoke KnownMetho d method." ); | |
635 | if(p rincipal ! = null) | |
636 | { | |
637 | String methodNam e = method .getName() ; // the acces sor name | |
638 | String propertyN ame = getP ropertyNam e(methodNa me, true); // the p roperty na me for log ger proper ties will have logge r stripped off | |
639 | boolea n isGetter Args = arg s == null || args.le ngth == 0; // true if the arg list is c ompatible with a Str ing getter | |
640 | boolea n isSetter Args = arg s != null && args.le ngth == 1 && args[0] instanceo f String; // true if the arg list is c ompatible with a Str ing setter | |
641 | ||
642 | // === ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
643 | // Imm utable fie lds | |
644 | // Vis taRealm se ts these. | |
645 | // === ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
646 | ||
647 | if(isI mmutablePr operty(pro pertyName) ) | |
648 | { | |
649 | if(isGet terAccesso r(methodNa me) && isG etterArgs) | |
650 | return inv okeImmutab leProperty GetAccesso r(principa l, propert yName); | |
651 | else if( isSetterA ccessor(me thodName) && isSette rArgs ) | |
652 | { | |
653 | // if the backing Pr incipal in stance is a ClientPr incipal th en allow c hanges to UID and PW D | |
654 | if(isClien tPrincipal ()) | |
655 | { | |
656 | if ( ACCESS_C ODE_PROPER TY.equals( propertyNa me) ) | |
657 | prin cipal.setA ccessCode( (String)ar gs[0]); | |
658 | if ( VERIFY_C ODE_PROPER TY.equals( propertyNa me) ) | |
659 | prin cipal.setV erifyCode( (String)ar gs[0]); | |
660 | } | |
661 | else | |
662 | { | |
663 | St ackTraceAn alyzer ana lyzer = St ackTraceAn alyzer.cur rentStackA nalyzer(); | |
664 | St ackTraceEl ement elem ent = anal yzer.getFi rstElement NotInPacka ge( this.g etClass(). getPackage ().getName () ); | |
665 | lo gger.warn( | |
666 | "Att empt to se t transact ion contex t property '" + prop ertyName + "', which is immuta ble in the current c ontext.\n" + | |
667 | "Lik ely culpri t is [" + Thread.cur rentThread ().getName () + "]'" + element. getClassNa me() + "." + element .getMethod Name() + " :" + eleme nt.getLine Number() + "'. " | |
668 | ); | |
669 | } | |
670 | return nul l; | |
671 | } | |
672 | else | |
673 | { | |
674 | logger.war n("Attempt to set im mutable tr ansaction context pr operty '" + property Name + "' or calling get acces sor with a rguments i s being ig nored."); | |
675 | return nul l; | |
676 | } | |
677 | } | |
678 | ||
679 | // === ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
680 | // Rea l Requesto r Fields a nd Logger Requestor Fields | |
681 | // Rea l requesto r fields a re always retreived from real properties though th ey may com e from | |
682 | // HTT P headers or webserv ice elemen ts. | |
683 | // Log ger reques tor fields may come from the a pplication propertie s or the " real" prop erties | |
684 | // if the applic ation prop erties do not exist. | |
685 | // See the comme nts below on the set ter method s for more info. | |
686 | // === ========== ========== ========== ========== ========== ========== ========== ========== ======= | |
687 | else i f(isReques torPropert y(property Name)) | |
688 | { | |
689 | if( isGe tterAccess or(methodN ame) && is GetterArgs ) | |
690 | { | |
691 | if( isGetL oggerAcces sor(method Name) ) | |
692 | re turn invok eLoggerPro pertyGetAc cessor(pri ncipal, pr opertyName ); | |
693 | else | |
694 | re turn invok ePropertyG etAccessor (principal , property Name); | |
695 | } | |
696 | ||
697 | if( isSe tterAccess or(methodN ame) && is SetterArgs ) | |
698 | return inv okePropert ySetAccess or(princip al, proper tyName, (S tring)args [0]); | |
699 | ||
700 | logger.w arn("Attem pt to acce ss transac tion conte xt propert y '" + pro pertyName + | |
701 | "' but eithe r method n aming or a rgument li st is not correct. Accessor m ethods mus t follow J avaBean st andards fo r String p roperties" ); | |
702 | return n ull; | |
703 | } | |
704 | else i f(isDebugP roperty(pr opertyName )) | |
705 | { | |
706 | if( isGe tterAccess or(methodN ame) && is GetterArgs ) | |
707 | { | |
708 | return inv okeLoggerP ropertyGet Accessor(p rincipal, propertyNa me); | |
709 | } | |
710 | ||
711 | if( isSe tterAccess or(methodN ame) && is SetterArgs ) | |
712 | { | |
713 | String new Value = (S tring)args [0]; | |
714 | setApplica tionProper ty(princip al, proper tyName, ne wValue); | |
715 | return nul l; | |
716 | } | |
717 | if((isAd derAccesso r(methodNa me) && isS etterArgs )) | |
718 | { | |
719 | String old Value = in vokeLogger PropertyGe tAccessor( principal, propertyN ame); | |
720 | String new Value = (S tring)args [0]; | |
721 | if((oldVal ue != null ) && (oldV alue.lengt h() > 0)) | |
722 | { | |
723 | ne wValue = o ldValue + Transactio nContext.d ebugInform ationDelim iter + new Value; | |
724 | } | |
725 | setApplica tionProper ty(princip al, proper tyName, ne wValue); | |
726 | return nul l; | |
727 | } | |
728 | ||
729 | logger.w arn("Attem pt to acce ss transac tion conte xt propert y '" + pro pertyName + | |
730 | "' but eithe r method n aming or a rgument li st is not correct. Accessor m ethods mus t follow J avaBean st andards fo r String p roperties" ); | |
731 | return n ull; | |
732 | } | |
733 | ||
734 | // we don't know what the method is, throw a N oSuchMetho dException | |
735 | // the caller sh ould inter pret this as an unkn own method not as a runtime er ror | |
736 | else | |
737 | { | |
738 | StringBu ilder msg = new Stri ngBuilder( ); | |
739 | msg.appe nd("Method Name: [" + methodNa me+"]"); | |
740 | msg.appe nd("Proper ty Name: [ " + proper tyName+"]" ); | |
741 | msg.appe nd(" Is immutable? [" + isIm mutablePro perty(prop ertyName)+ "]"); | |
742 | msg.appe nd(" Is requestor? ["+ isReq uestorProp erty(prope rtyName)+" ]"); | |
743 | msg.appe nd(" Is debug? [" + isDebugP roperty(pr opertyName )+"]"); | |
744 | logger.t race(msg.t oString()) ; | |
745 | throw ne w NoSuchMe thodExcept ion(); | |
746 | } | |
747 | } | |
748 | else | |
749 | { | |
750 | logger .warn("Att empted to call Trans actionCont ext method '" + meth od.getName () + "' an d backing instance o f VistaRea lmPrincipa l does not exist."); | |
751 | return null; | |
752 | } | |
753 | } | |
754 | ||
755 | /* * | |
756 | * Whether a field may be set de pends on w hether it has alread y been set and wheth er the | |
757 | * values we re set by VistARealm (not by t he delegat e realm). | |
758 | * VistaReal m sourced values are immutable . | |
759 | * Requestor informati on that is being add ed to a Vi staRealmPr incipal in stance tha t was | |
760 | * originall y populate d by Vista Realm will be stored as applic ation prop erties | |
761 | * and will be accessi ble as get LoggingXXX methods. | |
762 | * Requestor informati on that is being add ed to a Vi staRealmPr incipal in stance tha t was | |
763 | * NOT origi nally popu lated by V istaRealm will be st ored in th e "real" p roperties | |
764 | * and will be accessi ble as eit her getXXX or getLog gingXXX me thods. | |
765 | * The getLo ggingXXX m ethods ret urn the ap plication properties if they e xist, else they retu rn | |
766 | * the field s of the s ame names. | |
767 | * | |
768 | * @param pr incipal | |
769 | * @param pr opertyName | |
770 | * @param st ring | |
771 | * @return | |
772 | * / | |
773 | pr ivate Stri ng invokeP ropertySet Accessor(V istaRealmP rincipal p rincipal, String pro pertyName, String va lue) | |
774 | { | |
775 | Stri ng oldValu e = invoke PropertyGe tAccessor( principal, propertyN ame); | |
776 | ||
777 | if(o ldValue != null) | |
778 | logger .info("Ove rwriting k nown prope rty '" + p ropertyNam e + "'; fr om '" + ol dValue + " ' to '" + value + "' ."); | |
779 | ||
780 | if(p rincipal.i sAuthentic atedByDele gate()) | |
781 | { | |
782 | if( SI TE_NAME_PR OPERTY.equ als(proper tyName) ) | |
783 | principa l.setSiteN ame(value) ; | |
784 | if( SI TE_NUMBER_ PROPERTY.e quals(prop ertyName) ) | |
785 | principa l.setSiteN umber(valu e); | |
786 | if( SS N_PROPERTY .equals(pr opertyName ) ) | |
787 | principa l.setSsn(v alue); | |
788 | if( DU Z_PROPERTY .equals(pr opertyName ) ) | |
789 | principa l.setDuz(v alue); | |
790 | if( FU LLNAME_PRO PERTY.equa ls(propert yName) ) | |
791 | principa l.setFullN ame(value) ; | |
792 | if( SE CURITY_TOK EN_PROPERT Y.equals(p ropertyNam e)) | |
793 | principa l.setSecur ityToken(v alue); | |
794 | if( CA CHE_LOCATI ON_ID_PROP ERTY.equal s(property Name)) | |
795 | principa l.setCache LocationId (value); | |
796 | if( US ER_DIVISIO N_PROPERTY .equals(pr opertyName )) | |
797 | principa l.setUserD ivision(va lue); | |
798 | ||
799 | } | |
800 | else | |
801 | setApp licationPr operty(pri ncipal, pr opertyName , value); | |
802 | ||
803 | retu rn null; | |
804 | } | |
805 | ||
806 | /* * | |
807 | * Real Requ estor Fiel ds and Log ger Reques tor Fields | |
808 | * Real requ estor fiel ds are alw ays retrei ved from r eal proper ties thoug h they may come from | |
809 | * HTTP head ers or web service el ements. | |
810 | * Logger re questor fi elds may c ome from t he applica tion prope rties or t he "real" properties | |
811 | * if the ap plication properties do not ex ist. | |
812 | * See the c omments be low on the setter me thods for more info. | |
813 | * | |
814 | * This meth od provide s a mappin g from pro perty name to get ac cessor for known pro perties | |
815 | * | |
816 | * @param pr incipal | |
817 | * @param pr opertyName | |
818 | * @return | |
819 | * / | |
820 | pr ivate Stri ng invokeP ropertyGet Accessor(V istaRealmP rincipal p rincipal, String pro pertyName) | |
821 | { | |
822 | if( SITE_NAME_ PROPERTY.e quals(prop ertyName) ) | |
823 | return principal .getSiteNa me(); | |
824 | if( SITE_NUMBE R_PROPERTY .equals(pr opertyName ) ) | |
825 | return principal .getSiteNu mber(); | |
826 | if( SSN_PROPER TY.equals( propertyNa me) ) | |
827 | return principal .getSsn(); | |
828 | if( DUZ_PROPER TY.equals( propertyNa me) ) | |
829 | return principal .getDuz(); | |
830 | if( FULLNAME_P ROPERTY.eq uals(prope rtyName) ) | |
831 | return principal .getFullNa me(); | |
832 | if( SECURITY_T OKEN_PROPE RTY.equals (propertyN ame)) | |
833 | return principal .getSecuri tyToken(); | |
834 | if( CACHE_LOCA TION_ID_PR OPERTY.equ als(proper tyName)) | |
835 | return principal .getCacheL ocationId( ); | |
836 | if( USER_DIVIS ION_PROPER TY.equals( propertyNa me)) | |
837 | return principal .getUserDi vision(); | |
838 | ||
839 | retu rn null; | |
840 | } | |
841 | ||
842 | /* * | |
843 | * Real Requ estor Fiel ds and Log ger Reques tor Fields | |
844 | * Real requ estor fiel ds are alw ays retrei ved from r eal proper ties thoug h they may come from | |
845 | * HTTP head ers or web service el ements. | |
846 | * Logger re questor fi elds may c ome from t he applica tion prope rties or t he "real" properties | |
847 | * if the ap plication properties do not ex ist. | |
848 | * See the c omments be low on the setter me thods for more info. | |
849 | * | |
850 | * Get the p roperty va lue from t he applica tion prope rties firs t and then from the | |
851 | * known pro perties if the prope rtyName is not set i n the appl ication pr operties | |
852 | * | |
853 | * @param pr incipal | |
854 | * @param pr opertyName | |
855 | * @return | |
856 | * / | |
857 | pr ivate Stri ng invokeL oggerPrope rtyGetAcce ssor(Vista RealmPrinc ipal princ ipal, Stri ng propert yName) | |
858 | { | |
859 | Obje ct propert yValue = g etApplicat ionPropert y(principa l, propert yName); | |
860 | retu rn propert yValue == null ? | |
861 | invoke PropertyGe tAccessor( principal, propertyN ame) : | |
862 | proper tyValue.to String(); | |
863 | } | |
864 | ||
865 | /* * | |
866 | * @param pr incipal | |
867 | * @param pr opertyName | |
868 | * @return | |
869 | * / | |
870 | pr ivate Obje ct invokeI mmutablePr opertyGetA ccessor(Vi staRealmPr incipal pr incipal, S tring prop ertyName) | |
871 | { | |
872 | // a ccess code and name are synono mous | |
873 | // n ame is par t of the P rincipal i nterface, which Tran sactionCon text exten ds | |
874 | if( ACCESS_COD E_PROPERTY .equals(pr opertyName ) || NAME_ PROPERTY.e quals(prop ertyName) ) | |
875 | return principal .getAccess Code(); | |
876 | ||
877 | if( VERIFY_COD E_PROPERTY .equals(pr opertyName ) ) | |
878 | return principal .getVerify Code(); | |
879 | ||
880 | if( REALM_PROP ERTY.equal s(property Name) ) | |
881 | return principal .getRealm( ); | |
882 | ||
883 | if( AUTHENTICA TED_BY_DEL EGATE_PROP ERTY.equal s(property Name) ) | |
884 | return (Boolean) ( principa l.isAuthen ticatedByD elegate() ); | |
885 | ||
886 | if( CREDENTIAL S_TYPE_PRO PERTY.equa ls(propert yName) ) | |
887 | return principal .getCreden tialsType( ).toString (); | |
888 | ||
889 | if( SECURITY_H ASHCODE_PR OPERTY.equ als(proper tyName) ) | |
890 | return principal .getSecuri tyHashCode (); | |
891 | ||
892 | if(A UTHENTICAT ED_BY_VIST A_PROPERTY .equals(pr opertyName )) | |
893 | return new Boole an( princi pal.isAuth enticatedB yVista() ) ; | |
894 | ||
895 | logg er.warn("A ttempt to get unknow n immutabl e transact ion contex t properti es '" + pr opertyName + "' is b eing ignor ed."); | |
896 | retu rn null; | |
897 | } | |
898 | ||
899 | /* * | |
900 | * @param pr opertyName | |
901 | * @return | |
902 | * / | |
903 | pr ivate bool ean isLogg erProperty (String pr opertyName ) | |
904 | { | |
905 | retu rn propert yName.star tsWith(LOG GER_PROPER TY_PREFIX) ; | |
906 | } | |
907 | ||
908 | /* * | |
909 | * Unknown M ethods are accessors on applic ation prop erties. V istaRealm has nothin g to | |
910 | * do with t hese other than stor ing them i n the thre ad local o n behalf o f the appl ication. | |
911 | * | |
912 | * Invoke an unknown a ccessor. The access or name mu st be enco ded in the method na me using | |
913 | * the JavaB ean standa rd. The r eturn type of the me thod must be a base java.lang. * for get methods, | |
914 | * or void f or set met hods. Set methods m ust take o ne object argument. | |
915 | * The value s are get/ set in the VistaReal mPrincipal attribute Map. | |
916 | * | |
917 | * @param pr incipal | |
918 | * @param me thod | |
919 | * @param ar gs | |
920 | * @return | |
921 | * / | |
922 | pr ivate Obje ct invokeU nknownMeth od(VistaRe almPrincip al princip al, Method method, O bject[] ar gs) | |
923 | { | |
924 | //lo gger.debug ("...enter ing invoke UnknownMet hod method ."); | |
925 | if(p rincipal ! = null) | |
926 | { | |
927 | String methodNam e = method .getName() ; | |
928 | boolea n isIsGett er = metho dName.star tsWith(IS_ ACCESSOR_P REFIX); | |
929 | boolea n isGetter = methodN ame.starts With(GET_A CCESSOR_PR EFIX); | |
930 | boolea n isSetter = methodN ame.starts With(SET_A CCESSOR_PR EFIX); | |
931 | ||
932 | // if the method name does not start with 'get ' or 'set' then we d on't know what | |
933 | // to do with it | |
934 | if(!is Getter && !isSetter && !isIsGe tter) | |
935 | return n ull; | |
936 | ||
937 | String propertyN ame = getP ropertyNam e(methodNa me, false) ; | |
938 | Object currentVa lue = getA pplication Property(p rincipal, propertyNa me); | |
939 | ||
940 | // if it is a pr oper gette r method t hen try to convert t o the retu rn type of the | |
941 | // met hod | |
942 | if( is Getter || isIsGetter ) | |
943 | { | |
944 | Class<?> getterRet urnType = method.get ReturnType (); | |
945 | Applicat ionPropert yAccessor< ?> accesso r = getPro pertyAcces sorForType (getterRet urnType); | |
946 | ||
947 | return a ccessor.ge tValueAs(c urrentValu e); | |
948 | } | |
949 | ||
950 | // if it is a pr oper sette r then set the prope rty by nam e | |
951 | if(isS etter && a rgs != nul l && args. length == 1) | |
952 | { | |
953 | StackTra ceAnalyzer analyzer = StackTra ceAnalyzer .currentSt ackAnalyze r(); | |
954 | StackTra ceElement element = analyzer.g etFirstEle mentNotInP ackage( th is.getClas s().getPac kage().get Name() ); | |
955 | ||
956 | if(curre ntValue != null) | |
957 | { | |
958 | if( isWarn OnPropertO verwrite() ) | |
959 | lo gger.warn( "Transact ionContext [" + princ ipal.hashC ode() + "] " + | |
960 | "Ove rwriting a pplication property '" + prope rtyName + "'; from ' " + curren tValue + " ' to '" + | |
961 | (arg s[0] == nu ll ? "<nul l>" : args [0].toStri ng()) + "' .\n" + | |
962 | (ele ment == nu ll ? | |
963 | "Unkno wn offendi ng element " : | |
964 | "Offen ding eleme nt may be '" + eleme nt.getClas sName() + "." + elem ent.getMet hodName() + ":" + el ement.getL ineNumber( ) + "'" | |
965 | ) | |
966 | ); | |
967 | } | |
968 | logger.d ebug( (ele ment == nu ll ? "unkn own" : (el ement.getC lassName() + ":" + e lement.get LineNumber ())) + | |
969 | " is setti ng propert y name '" + property Name + "' from value '" + curr entValue + "' to '" + args[0] + "'"); | |
970 | ||
971 | setAppli cationProp erty(princ ipal, prop ertyName, args[0]); | |
972 | } | |
973 | return null; | |
974 | } | |
975 | else | |
976 | { | |
977 | logger .warn("Att empted to call Trans actionCont ext method '" + meth od.getName () + "' an d backing instance o f VistaRea lmPrincipa l does not exist."); | |
978 | return null; | |
979 | } | |
980 | } | |
981 | ||
982 | /* * | |
983 | * Semantic Helper Met hod | |
984 | * | |
985 | * @param pr incipal | |
986 | * @param pr opertyName | |
987 | * @param va lue | |
988 | * / | |
989 | pr ivate void setApplic ationPrope rty(VistaR ealmPrinci pal princi pal, Strin g property Name, Obje ct value) | |
990 | { | |
991 | prin cipal.setA pplication Property(p ropertyNam e, value); | |
992 | } | |
993 | ||
994 | /* * | |
995 | * Semantic Helper Met hod | |
996 | * | |
997 | * @param pr incipal | |
998 | * @param pr opertyName | |
999 | * @return | |
1000 | * / | |
1001 | pr ivate Obje ct getAppl icationPro perty(Vist aRealmPrin cipal prin cipal, Str ing proper tyName) | |
1002 | { | |
1003 | retu rn princip al.getAppl icationPro perty(prop ertyName); | |
1004 | } | |
1005 | ||
1006 | /* * | |
1007 | * If the me thod name is getXXX or setXXX return the | |
1008 | * (i.e. fir st char is lower cas e). | |
1009 | * | |
1010 | * e.g. getS iteNumber => siteNum ber | |
1011 | * setS umpin => s umpin | |
1012 | * | |
1013 | * @param ac cessorMeth odName | |
1014 | * @return | |
1015 | * / | |
1016 | pr ivate Stri ng getProp ertyName(S tring acce ssorMethod Name, bool ean remove LoggerPref ix) | |
1017 | { | |
1018 | bool ean isIs = isIsAcces sor(access orMethodNa me); | |
1019 | bool ean isGett er = isGet terAccesso r(accessor MethodName ); | |
1020 | bool ean isSett er = isSet terAccesso r(accessor MethodName ); | |
1021 | bool ean isAdde r = isAdde rAccessor( accessorMe thodName); | |
1022 | ||
1023 | // i f the meth od name do es not sta rt with 'g et' or 'se t' then we don't kno w what | |
1024 | // t o do with it | |
1025 | if( ! isGetter && ! isSe tter && !i sAdder) | |
1026 | return null; | |
1027 | ||
1028 | int prefixLeng th = | |
1029 | isIs ? IS_ACCESS OR_PREFIX. length() : | |
1030 | isGett er ? GET_A CCESSOR_PR EFIX.lengt h() : | |
1031 | isSett er ? SET_A CCESSOR_PR EFIX.lengt h() : | |
1032 | ADD_AC CESSOR_PRE FIX.length (); | |
1033 | ||
1034 | // t here must be a field name to b e a proper accessor, i.e. get( ) is not a proper | |
1035 | // a ccessor as far as we are conce rned | |
1036 | if( accessorMe thodName.l ength() <= prefixLen gth ) | |
1037 | return null; | |
1038 | ||
1039 | // the fi eldname be gins after the 'is', 'get' or 'set' | |
1040 | Stri ng propert yName = ac cessorMeth odName.sub string(pre fixLength) ; | |
1041 | ||
1042 | // l ower case the first char | |
1043 | prop ertyName = propertyN ame.substr ing(0,1).t oLowerCase () + (prop ertyName.l ength()>1 ? property Name.subst ring(1) : ""); | |
1044 | ||
1045 | if(r emoveLogge rPrefix && propertyN ame.starts With(LOGGE R_PROPERTY _PREFIX)) | |
1046 | { | |
1047 | proper tyName = p ropertyNam e.substrin g(LOGGER_P ROPERTY_PR EFIX.lengt h()); | |
1048 | proper tyName = p ropertyNam e.substrin g(0,1).toL owerCase() + (proper tyName.len gth()>1 ? propertyNa me.substri ng(1) : "" ); | |
1049 | } | |
1050 | ||
1051 | retu rn propert yName; | |
1052 | } | |
1053 | ||
1054 | /* * | |
1055 | * Create a standard g etter meth od name fr om the pro perty name . | |
1056 | * | |
1057 | * @param pr opertyName | |
1058 | * @return | |
1059 | * / | |
1060 | pr ivate Stri ng getGett erName(Str ing proper tyName) | |
1061 | { | |
1062 | retu rn GET_ACC ESSOR_PREF IX + prope rtyName.su bstring(0, 1).toUpper Case() + ( propertyNa me.length( )>1 ? prop ertyName.s ubstring(1 ) : ""); | |
1063 | } | |
1064 | ||
1065 | /* * | |
1066 | * Create a standard s etter meth od name fr om the pro perty name . | |
1067 | * | |
1068 | * @param pr opertyName | |
1069 | * @return | |
1070 | * / | |
1071 | pr ivate Stri ng getSett erName(Str ing proper tyName) | |
1072 | { | |
1073 | retu rn SET_ACC ESSOR_PREF IX + prope rtyName.su bstring(0, 1).toUpper Case() + ( propertyNa me.length( )>1 ? prop ertyName.s ubstring(1 ) : ""); | |
1074 | } | |
1075 | ||
1076 | pr ivate bool ean isGett erAccessor (String me thodName) | |
1077 | { | |
1078 | retu rn methodN ame.starts With(GET_A CCESSOR_PR EFIX) || m ethodName. startsWith (IS_ACCESS OR_PREFIX) ; | |
1079 | } | |
1080 | ||
1081 | pr ivate bool ean isIsAc cessor(Str ing method Name) | |
1082 | { | |
1083 | retu rn methodN ame.starts With(IS_AC CESSOR_PRE FIX); | |
1084 | } | |
1085 | ||
1086 | pr ivate bool ean isSett erAccessor (String me thodName) | |
1087 | { | |
1088 | retu rn methodN ame.starts With(SET_A CCESSOR_PR EFIX); | |
1089 | } | |
1090 | ||
1091 | pr ivate bool ean isAdde rAccessor( String met hodName) | |
1092 | { | |
1093 | retu rn methodN ame.starts With(ADD_A CCESSOR_PR EFIX); | |
1094 | } | |
1095 | ||
1096 | /* * | |
1097 | * Accessor methods th at start e ith "getLo gger" or " isLogger" are consid ered | |
1098 | * known pro perties bu t are hand led specia l. This m ethod just tells us that the | |
1099 | * method na me matches the patte rn. | |
1100 | * | |
1101 | * @param me thodName | |
1102 | * @return | |
1103 | * / | |
1104 | pr ivate bool ean isGetL oggerAcces sor(String methodNam e) | |
1105 | { | |
1106 | retu rn methodN ame.starts With(GET_A CCESSOR_PR EFIX + LOG GER_ACCESS OR_PREFIX) || method Name.start sWith(IS_A CCESSOR_PR EFIX + LOG GER_ACCESS OR_PREFIX) ; | |
1107 | } | |
1108 | ||
1109 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.