Produced by Araxis Merge on 11/20/2017 2:16:16 PM GMT 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.
# | Location | File | Last Modified |
---|---|---|---|
1 | Mon Nov 20 14:16:16 2017 UTC | ||
2 | C:\Merge Test Files\8.5.23\java\org\apache\catalina\authenticator\jaspic | PersistentProviderRegistrations.java | Thu Sep 28 11:32:16 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 0 | 0 |
Changed | 0 | 0 |
Inserted | 1 | 257 |
Removed | 0 | 0 |
Whitespace | Consecutive whitespace is treated as a single space |
---|---|
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 | * Licens ed to the Apache Sof tware Foun dation (AS F) under o ne or more | |||||
3 | * contri butor lice nse agreem ents. See the NOTIC E file dis tributed w ith | |||||
4 | * this w ork for ad ditional i nformation regarding copyright ownership . | |||||
5 | * The AS F licenses this file to You un der the Ap ache Licen se, Versio n 2.0 | |||||
6 | * (the " License"); you may n ot use thi s file exc ept in com pliance wi th | |||||
7 | * the Li cense. Yo u may obta in a copy of the Lic ense at | |||||
8 | * | |||||
9 | * htt p://www.ap ache.org/l icenses/LI CENSE-2.0 | |||||
10 | * | |||||
11 | * Unless required by applica ble law or agreed to in writin g, softwar e | |||||
12 | * distri buted unde r the Lice nse is dis tributed o n an "AS I S" BASIS, | |||||
13 | * WITHOU T WARRANTI ES OR COND ITIONS OF ANY KIND, either exp ress or im plied. | |||||
14 | * See th e License for the sp ecific lan guage gove rning perm issions an d | |||||
15 | * limita tions unde r the Lice nse. | |||||
16 | */ | |||||
17 | package or g.apache.c atalina.au thenticato r.jaspic; | |||||
18 | ||||||
19 | import jav a.io.File; | |||||
20 | import jav a.io.FileI nputStream ; | |||||
21 | import jav a.io.FileO utputStrea m; | |||||
22 | import jav a.io.IOExc eption; | |||||
23 | import jav a.io.Input Stream; | |||||
24 | import jav a.io.Outpu tStream; | |||||
25 | import jav a.io.Outpu tStreamWri ter; | |||||
26 | import jav a.io.Write r; | |||||
27 | import jav a.nio.char set.Standa rdCharsets ; | |||||
28 | import jav a.util.Arr ayList; | |||||
29 | import jav a.util.Has hMap; | |||||
30 | import jav a.util.Lis t; | |||||
31 | import jav a.util.Map ; | |||||
32 | import jav a.util.Map .Entry; | |||||
33 | ||||||
34 | import org .apache.ju li.logging .Log; | |||||
35 | import org .apache.ju li.logging .LogFactor y; | |||||
36 | import org .apache.to mcat.util. digester.D igester; | |||||
37 | import org .apache.to mcat.util. res.String Manager; | |||||
38 | import org .xml.sax.S AXExceptio n; | |||||
39 | ||||||
40 | /** | |||||
41 | * Utility class for the loadi ng and sav ing of JAS PIC persis tent provi der | |||||
42 | * registr ations. | |||||
43 | */ | |||||
44 | final clas s Persiste ntProvider Registrati ons { | |||||
45 | ||||||
46 | privat e static f inal Log l og = LogFa ctory.getL og(Persist entProvide rRegistrat ions.class ); | |||||
47 | privat e static f inal Strin gManager s m = | |||||
48 | StringMa nager.getM anager(Per sistentPro viderRegis trations.c lass); | |||||
49 | ||||||
50 | ||||||
51 | privat e Persiste ntProvider Registrati ons() { | |||||
52 | // Utility c lass. Hide default c onstructor | |||||
53 | } | |||||
54 | ||||||
55 | ||||||
56 | static Providers loadProvi ders(File configFile ) { | |||||
57 | tr y (InputSt ream is = new FileIn putStream( configFile )) { | |||||
58 | // Const ruct a dig ester to r ead the XM L input fi le | |||||
59 | Digester digester = new Dige ster(); | |||||
60 | ||||||
61 | try { | |||||
62 | dige ster.setFe ature("htt p://apache .org/xml/f eatures/al low-java-e ncodings", true); | |||||
63 | dige ster.setVa lidating(t rue); | |||||
64 | dige ster.setNa mespaceAwa re(true); | |||||
65 | } catch (Exception e) { | |||||
66 | thro w new Secu rityExcept ion(e); | |||||
67 | } | |||||
68 | ||||||
69 | // Creat e an objec t to hold the parse results an d put it o n the top | |||||
70 | // of th e digester 's stack | |||||
71 | Provider s result = new Provi ders(); | |||||
72 | digester .push(resu lt); | |||||
73 | ||||||
74 | // Confi gure the d igester | |||||
75 | digester .addObject Create("ja spic-provi ders/provi der", Prov ider.class .getName() ); | |||||
76 | digester .addSetPro perties("j aspic-prov iders/prov ider"); | |||||
77 | digester .addSetNex t("jaspic- providers/ provider", "addProvi der", Prov ider.class .getName() ); | |||||
78 | ||||||
79 | digester .addObject Create("ja spic-provi ders/provi der/proper ty", Prope rty.class. getName()) ; | |||||
80 | digester .addSetPro perties("j aspic-prov iders/prov ider/prope rty"); | |||||
81 | digester .addSetNex t("jaspic- providers/ provider/p roperty", "addProper ty", Prope rty.class. getName()) ; | |||||
82 | ||||||
83 | // Parse the input | |||||
84 | digester .parse(is) ; | |||||
85 | ||||||
86 | return r esult; | |||||
87 | } catch (IOE xception | SAXExcept ion e) { | |||||
88 | throw ne w Security Exception( e); | |||||
89 | } | |||||
90 | } | |||||
91 | ||||||
92 | ||||||
93 | static void writ eProviders (Providers providers , File con figFile) { | |||||
94 | Fi le configF ileOld = n ew File(co nfigFile.g etAbsolute Path() + " .old"); | |||||
95 | Fi le configF ileNew = n ew File(co nfigFile.g etAbsolute Path() + " .new"); | |||||
96 | ||||||
97 | // Remove le ft over te mporary fi les if pre sent | |||||
98 | if (configFi leOld.exis ts()) { | |||||
99 | if (conf igFileOld. delete()) { | |||||
100 | thro w new Secu rityExcept ion(sm.get String( | |||||
101 | "persi stentProvi derRegistr ations.exi stsDeleteF ail", | |||||
102 | config FileOld.ge tAbsoluteP ath())); | |||||
103 | } | |||||
104 | } | |||||
105 | if (configFi leNew.exis ts()) { | |||||
106 | if (conf igFileNew. delete()) { | |||||
107 | thro w new Secu rityExcept ion(sm.get String( | |||||
108 | "persi stentProvi derRegistr ations.exi stsDeleteF ail", | |||||
109 | config FileNew.ge tAbsoluteP ath())); | |||||
110 | } | |||||
111 | } | |||||
112 | ||||||
113 | // Write out the provi ders to th e temporar y new file | |||||
114 | tr y (OutputS tream fos = new File OutputStre am(configF ileNew); | |||||
115 | Writ er writer = new Outp utStreamWr iter(fos, StandardCh arsets.UTF _8)) { | |||||
116 | writer.w rite( | |||||
117 | "<?xml ver sion='1.0' encoding= 'utf-8'?>\ n" + | |||||
118 | "<jaspic-p roviders\n " + | |||||
119 | " xmlns =\"http:// tomcat.apa che.org/xm l\"\n" + | |||||
120 | " xmlns :xsi=\"htt p://www.w3 .org/2001/ XMLSchema- instance\" \n" + | |||||
121 | " xsi:s chemaLocat ion=\"http ://tomcat. apache.org /xml jaspi c-provider s.xsd\"\n" + | |||||
122 | " versi on=\"1.0\" >\n"); | |||||
123 | for (Pro vider prov ider : pro viders.pro viders) { | |||||
124 | writ er.write(" <provide r classNam e=\""); | |||||
125 | writ er.write(p rovider.ge tClassName ()); | |||||
126 | writ er.write(" \" layer=\ ""); | |||||
127 | writ er.write(p rovider.ge tLayer()); | |||||
128 | writ er.write(" \" appCont ext=\""); | |||||
129 | writ er.write(p rovider.ge tAppContex t()); | |||||
130 | if ( provider.g etDescript ion() != n ull) { | |||||
131 | writer.wri te("\" des cription=\ ""); | |||||
132 | writer.wri te(provide r.getDescr iption()); | |||||
133 | } | |||||
134 | writ er.write(" \">\n"); | |||||
135 | for (Entry<Str ing,String > entry : provider.g etProperti es().entry Set()) { | |||||
136 | writer.wri te(" <p roperty na me=\""); | |||||
137 | writer.wri te(entry.g etKey()); | |||||
138 | writer.wri te("\" val ue=\""); | |||||
139 | writer.wri te(entry.g etValue()) ; | |||||
140 | writer.wri te("\"/>\n "); | |||||
141 | } | |||||
142 | writ er.write(" </provid er>\n"); | |||||
143 | } | |||||
144 | writer.w rite("</ja spic-provi ders>\n"); | |||||
145 | } catch (IOE xception e ) { | |||||
146 | configFi leNew.dele te(); | |||||
147 | throw ne w Security Exception( e); | |||||
148 | } | |||||
149 | ||||||
150 | // Move the current fi le out of the way | |||||
151 | if (configFi le.isFile( )) { | |||||
152 | if (!con figFile.re nameTo(con figFileOld )) { | |||||
153 | thro w new Secu rityExcept ion(sm.get String("pe rsistentPr oviderRegi strations. moveFail", | |||||
154 | config File.getAb solutePath (), config FileOld.ge tAbsoluteP ath())); | |||||
155 | } | |||||
156 | } | |||||
157 | ||||||
158 | // Move the new file i nto place | |||||
159 | if (!configF ileNew.ren ameTo(conf igFile)) { | |||||
160 | throw ne w Security Exception( sm.getStri ng("persis tentProvid erRegistra tions.move Fail", | |||||
161 | configFile New.getAbs olutePath( ), configF ile.getAbs olutePath( ))); | |||||
162 | } | |||||
163 | ||||||
164 | // Remove th e old file | |||||
165 | if (configFi leOld.exis ts() && !c onfigFileO ld.delete( )) { | |||||
166 | log.warn (sm.getStr ing("persi stentProvi derRegistr ations.del eteFail", | |||||
167 | configFile Old.getAbs olutePath( ))); | |||||
168 | } | |||||
169 | } | |||||
170 | ||||||
171 | ||||||
172 | public static cl ass Provid ers { | |||||
173 | pr ivate fina l List<Pro vider> pro viders = n ew ArrayLi st<>(); | |||||
174 | ||||||
175 | pu blic void addProvide r(Provider provider) { | |||||
176 | provider s.add(prov ider); | |||||
177 | } | |||||
178 | ||||||
179 | pu blic List< Provider> getProvide rs() { | |||||
180 | return p roviders; | |||||
181 | } | |||||
182 | } | |||||
183 | ||||||
184 | ||||||
185 | public static cl ass Provid er { | |||||
186 | pr ivate Stri ng classNa me; | |||||
187 | pr ivate Stri ng layer; | |||||
188 | pr ivate Stri ng appCont ext; | |||||
189 | pr ivate Stri ng descrip tion; | |||||
190 | pr ivate fina l Map<Stri ng,String> propertie s = new Ha shMap<>(); | |||||
191 | ||||||
192 | ||||||
193 | pu blic Strin g getClass Name() { | |||||
194 | return c lassName; | |||||
195 | } | |||||
196 | pu blic void setClassNa me(String className) { | |||||
197 | this.cla ssName = c lassName; | |||||
198 | } | |||||
199 | ||||||
200 | ||||||
201 | pu blic Strin g getLayer () { | |||||
202 | return l ayer; | |||||
203 | } | |||||
204 | pu blic void setLayer(S tring laye r) { | |||||
205 | this.lay er = layer ; | |||||
206 | } | |||||
207 | ||||||
208 | ||||||
209 | pu blic Strin g getAppCo ntext() { | |||||
210 | return a ppContext; | |||||
211 | } | |||||
212 | pu blic void setAppCont ext(String appContex t) { | |||||
213 | this.app Context = appContext ; | |||||
214 | } | |||||
215 | ||||||
216 | ||||||
217 | pu blic Strin g getDescr iption() { | |||||
218 | return d escription ; | |||||
219 | } | |||||
220 | pu blic void setDescrip tion(Strin g descript ion) { | |||||
221 | this.des cription = descripti on; | |||||
222 | } | |||||
223 | ||||||
224 | ||||||
225 | pu blic void addPropert y(Property property) { | |||||
226 | properti es.put(pro perty.getN ame(), pro perty.getV alue()); | |||||
227 | } | |||||
228 | vo id addProp erty(Strin g name, St ring value ) { | |||||
229 | properti es.put(nam e, value); | |||||
230 | } | |||||
231 | pu blic Map<S tring,Stri ng> getPro perties() { | |||||
232 | return p roperties; | |||||
233 | } | |||||
234 | } | |||||
235 | ||||||
236 | ||||||
237 | public static cl ass Proper ty { | |||||
238 | pr ivate Stri ng name; | |||||
239 | pr ivate Stri ng value; | |||||
240 | ||||||
241 | ||||||
242 | pu blic Strin g getName( ) { | |||||
243 | return n ame; | |||||
244 | } | |||||
245 | pu blic void setName(St ring name) { | |||||
246 | this.nam e = name; | |||||
247 | } | |||||
248 | ||||||
249 | ||||||
250 | pu blic Strin g getValue () { | |||||
251 | return v alue; | |||||
252 | } | |||||
253 | pu blic void setValue(S tring valu e) { | |||||
254 | this.val ue = value ; | |||||
255 | } | |||||
256 | } | |||||
257 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2017 Araxis Ltd (www.araxis.com). All rights reserved.