acegi.xml 241 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <!--
  5. * ========================================================================
  6. *
  7. * Copyright 2004 Acegi Technology Pty Limited
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. * ========================================================================
  22. -->
  23. <book>
  24. <bookinfo>
  25. <title>Acegi Security System for Spring</title>
  26. <subtitle>Reference Documentation</subtitle>
  27. <releaseinfo>0.8.0</releaseinfo>
  28. <authorgroup>
  29. <author>
  30. <firstname>Ben</firstname>
  31. <surname>Alex</surname>
  32. </author>
  33. </authorgroup>
  34. </bookinfo>
  35. <toc></toc>
  36. <preface id="preface">
  37. <title>Preface</title>
  38. <para>This document provides a reference guide to the Acegi Security
  39. System for Spring, which is a series of classes that deliver
  40. authentication and authorization services within the Spring
  41. Framework.</para>
  42. <para>I would like to acknowledge this reference was prepared using the
  43. DocBook configuration included with the Spring Framework. The Spring team
  44. in turn acknowledge Chris Bauer (Hibernate) for his assistance with their
  45. DocBook.</para>
  46. </preface>
  47. <chapter id="security">
  48. <title>Security</title>
  49. <sect1 id="security-before-you-begin">
  50. <title>Before You Begin</title>
  51. <para>For your security, each official release JAR of Acegi Security has
  52. been signed by the project leader. This does not in any way alter the
  53. liability disclaimer contained in the License, but it does ensure you
  54. are using a properly reviewed, official build of Acegi Security. Please
  55. refer to the <literal>readme.txt</literal> file in the root of the
  56. release distribution for instructions on how to validate the JARs are
  57. correctly signed, and which certificate has been used to sign
  58. them.</para>
  59. </sect1>
  60. <sect1 id="security-introduction">
  61. <title>Introduction</title>
  62. <para>The Acegi Security System for Spring provides authentication and
  63. authorization capabilities for Spring-powered projects, with optional
  64. integration with popular web containers. The security architecture was
  65. designed from the ground up using "The Spring Way" of development, which
  66. includes using bean contexts, interceptors and interface-driven
  67. programming. As a consequence, the Acegi Security System for Spring is
  68. useful out-of-the-box for those seeking to secure their Spring-based
  69. applications, and can be easily adapted to complex customized
  70. requirements.</para>
  71. <para>Security involves two distinct operations, authentication and
  72. authorization. The former relates to resolving whether or not a caller
  73. is who they claim to be. Authorization on the other hand relates to
  74. determining whether or not an authenticated caller is permitted to
  75. perform a given operation.</para>
  76. <para>Throughout the Acegi Security System for Spring, the user, system
  77. or agent that needs to be authenticated is referred to as a "principal".
  78. The security architecture does not have a notion of roles or groups,
  79. which you may be familiar with from other security implementations,
  80. although equivalent functionality is fully accommodated by Acegi
  81. Security.</para>
  82. <sect2 id="security-introduction-status">
  83. <title>Current Status</title>
  84. <para>The Acegi Security System for Spring is widely used by members
  85. of the Spring Community. The APIs are considered stable and only minor
  86. changes are expected. Having said that, like many other projects we
  87. need to strike a balance between backward compatibility and
  88. improvement. Effective version 0.6.1, Acegi Security uses the Apache
  89. Portable Runtime Project versioning guidelines, available from
  90. <literal>http://apr.apache.org/versioning.html</literal>.</para>
  91. <para>Some minor improvements are currently intended prior to the
  92. 1.0.0 release, although each of these represent additional
  93. functionality that will in no way modify the project's central
  94. interfaces or classes. Users of Acegi Security System for Spring
  95. should therefore be comfortable depending on the current version of
  96. the project in their applications.</para>
  97. </sect2>
  98. </sect1>
  99. <sect1 id="security-high-level-design">
  100. <title>High Level Design</title>
  101. <sect2 id="security-high-level-design-key-components">
  102. <title>Key Components</title>
  103. <para>Most enterprise applications have four basic security
  104. requirements. First, they need to be able to authenticate a principal.
  105. Second, they need to be able to secure web requests. Third, enterprise
  106. applications need to be able to secure services layer methods.
  107. Finally, quite often an enterprise application will need to secure
  108. domain object instances. Acegi Security provides a comprehensive
  109. framework for achieving all of these four common enterprise
  110. application security requirements.</para>
  111. <para>The Acegi Security System for Spring essentially comprises eight
  112. key functional parts:</para>
  113. <itemizedlist spacing="compact">
  114. <listitem>
  115. <para>An <literal>Authentication</literal> object which holds the
  116. principal, credentials and the authorities granted to the
  117. principal. The object can also store additional information
  118. associated with an authentication request, such as the source
  119. TCP/IP address.</para>
  120. </listitem>
  121. <listitem>
  122. <para>A <literal>ContextHolder</literal> which holds the
  123. <literal>Authentication</literal> object in a
  124. <literal>ThreadLocal</literal>-bound object.</para>
  125. </listitem>
  126. <listitem>
  127. <para>An <literal>AuthenticationManager</literal> to authenticate
  128. the <literal>Authentication</literal> object presented via the
  129. <literal>ContextHolder</literal>.</para>
  130. </listitem>
  131. <listitem>
  132. <para>An <literal>AccessDecisionManager</literal> to authorize a
  133. given operation.</para>
  134. </listitem>
  135. <listitem>
  136. <para>A <literal>RunAsManager</literal> to optionally replace the
  137. <literal>Authentication</literal> object whilst a given operation
  138. is being executed.</para>
  139. </listitem>
  140. <listitem>
  141. <para>A "secure object" interceptor, which coordinates the
  142. authentication, authorization, run-as replacement, after
  143. invocation handling and execution of a given operation.</para>
  144. </listitem>
  145. <listitem>
  146. <para>An <literal>AfterInvocationManager</literal> which can
  147. modify an <literal>Object</literal> returned from a "secure
  148. object" invocation, such as removing <literal>Collection</literal>
  149. elements a principal does not have authority to access.</para>
  150. </listitem>
  151. <listitem>
  152. <para>An acess control list (ACL) management package, which can be
  153. used to obtain the ACLs applicable for domain object
  154. instances.</para>
  155. </listitem>
  156. </itemizedlist>
  157. <para>A "secure object" interceptor executes most of the Acegi
  158. Security key classes and in doing so delivers the framework's major
  159. features. Given its importance, Figure 1 shows the key relationships
  160. and concrete implementations of
  161. <literal>AbstractSecurityInterceptor</literal>.</para>
  162. <para><mediaobject>
  163. <imageobject role="html">
  164. <imagedata align="center"
  165. fileref="images/SecurityInterception.gif"
  166. format="GIF" />
  167. </imageobject>
  168. <caption>
  169. <para>Figure 1: The key "secure object" model</para>
  170. </caption>
  171. </mediaobject></para>
  172. <para>Each "secure object" interceptor (hereinafter called a "security
  173. interceptor") works with a particular type of "secure object". So,
  174. what is a secure object? Secure objects refer to any type of object
  175. that can have security applied to it. A secure object must provide
  176. some form of callback, so that the security interceptor can
  177. transparently do its work as required, and callback the object when it
  178. is time for it to proceed with the requested operation. If secure
  179. objects cannot provide a native callback approach, a wrapper needs to
  180. be written so this becomes possible.</para>
  181. <para>Each secure object has its own package under
  182. <literal>net.sf.acegisecurity.intercept</literal>. Every other package
  183. in the security system is secure object independent, in that it can
  184. support any type of secure object presented.</para>
  185. <para>Only developers contemplating an entirely new way of
  186. intercepting and authorizing requests would need to use secure objects
  187. directly. For example, it would be possible to build a new secure
  188. object to secure calls to a messaging system that does not use
  189. <literal>MethodInvocation</literal>s. Most Spring applications will
  190. simply use the three currently supported secure object types (AOP
  191. Alliance <literal>MethodInvocation</literal>, AspectJ
  192. <literal>JoinPoint</literal> and web request
  193. <literal>FilterInterceptor</literal>) with complete
  194. transparency.</para>
  195. <para>Each of the eight key parts of Acegi Security are discussed in
  196. detail throughout this document.</para>
  197. </sect2>
  198. <sect2 id="security-high-level-design-supported-secure-objects">
  199. <title>Supported Secure Objects</title>
  200. <para>As shown in the base of Figure 1, the Acegi Security System for
  201. Spring currently supports three secure objects.</para>
  202. <para>The first handles an AOP Alliance
  203. <literal>MethodInvocation</literal>. This is the secure object type
  204. used to protect Spring beans. Developers will generally use this
  205. secure object type to secure their business objects. To make a
  206. standard Spring-hosted bean available as a
  207. <literal>MethodInvocation</literal>, the bean is simply published
  208. through a <literal>ProxyFactoryBean</literal> or
  209. <literal>BeanNameAutoProxyCreator</literal> or
  210. <literal>DefaultAdvisorAutoProxyCreator</literal>. Most Spring
  211. developers would already be familiar with these due to their use in
  212. transactions and other areas of Spring.</para>
  213. <para>The second type is an AspectJ <literal>JoinPoint</literal>.
  214. AspectJ has a particular use in securing domain object instances, as
  215. these are most often managed outside the Spring bean container. By
  216. using AspectJ, standard constructs such as <literal>new
  217. Person();</literal> can be used and full security will be applied to
  218. them by Acegi Security. The
  219. <literal>AspectJSecurityInterceptor</literal> is still managed by
  220. Spring, which creates the aspect singleton and wires it with the
  221. appropriate authentication managers, access decision managers and so
  222. on.</para>
  223. <para>The third type is a <literal>FilterInvocation</literal>. This is
  224. an object included with the Acegi Security System for Spring. It is
  225. created by an included filter and simply wraps the HTTP
  226. <literal>ServletRequest</literal>, <literal>ServletResponse</literal>
  227. and <literal>FilterChain</literal>. The
  228. <literal>FilterInvocation</literal> enables HTTP resources to be
  229. secured. Developers do not usually need to understand the mechanics of
  230. how this works, because they just add the filters to their
  231. <literal>web.xml</literal> and let the security system do its
  232. work.</para>
  233. </sect2>
  234. <sect2 id="security-high-level-design-configuration-attributes">
  235. <title>Configuration Attributes</title>
  236. <para>Every secure object can represent an infinite number of
  237. individual requests. For example, a
  238. <literal>MethodInvocation</literal> can represent the invocation of
  239. any method with any arguments, whilst a
  240. <literal>FilterInvocation</literal> can represent any HTTP URL.</para>
  241. <para>The Acegi Security System for Spring needs to record the
  242. configuration that applies to each of these possible requests. The
  243. security configuration of a request to
  244. <literal>BankManager.getBalance(int accountNumber)</literal> needs to
  245. be very different from the security configuration of a request to
  246. <literal>BankManager.approveLoan(int applicationNumber)</literal>.
  247. Similarly, the security configuration of a request to
  248. <literal>http://some.bank.com/index.htm</literal> needs to be very
  249. different from the security configuration of
  250. <literal>http://some.bank.com/manage/timesheet.jsp</literal>.</para>
  251. <para>To store the various security configurations associated with
  252. different requests, a configuration attribute is used. At an
  253. implementation level a configuration attribute is represented by the
  254. <literal>ConfigAttribute</literal> interface. One concrete
  255. implementation of <literal>ConfigAttribute</literal> is provided,
  256. <literal>SecurityConfig</literal>, which simply stores a configuration
  257. attribute as a <literal>String</literal>.</para>
  258. <para>The collection of <literal>ConfigAttribute</literal>s associated
  259. with a particular request is held in a
  260. <literal>ConfigAttributeDefinition</literal>. This concrete class is
  261. simply a holder of <literal>ConfigAttribute</literal>s and does
  262. nothing special.</para>
  263. <para>When a request is received by the security interceptor, it needs
  264. to determine which configuration attributes apply. In other words, it
  265. needs to find the <literal>ConfigAttributeDefinition</literal> which
  266. applies to the request. This decision is handled by the
  267. <literal>ObjectDefinitionSource</literal> interface. The main method
  268. provided by this interface is <literal>public
  269. ConfigAttributeDefinition getAttributes(Object object)</literal>, with
  270. the <literal>Object</literal> being the secure object. Recall the
  271. secure object contains details of the request, so the
  272. <literal>ObjectDefinitionSource</literal> implementation will be able
  273. to extract the details it requires to lookup the relevant
  274. <literal>ConfigAttributeDefinition</literal>.</para>
  275. </sect2>
  276. </sect1>
  277. <sect1 id="security-request-contexts">
  278. <title>Request Contexts</title>
  279. <sect2 id="security-contexts">
  280. <title>Contexts</title>
  281. <para>Many applications require a way of sharing objects between
  282. classes, but without resorting to passing them in method signatures.
  283. This is commonly achieved by using a <literal>ThreadLocal</literal>.
  284. The Acegi Security System for Spring uses
  285. <literal>ThreadLocal</literal> functionality and introduces the
  286. concept of "request contexts".</para>
  287. <para>By placing an object into a request context, that object becomes
  288. available to any other object on the current thread of execution. The
  289. request context is not passed around as a method parameter, but is
  290. held in a <literal>ThreadLocal</literal>. The Acegi Security System
  291. for Spring uses the request context to pass around the authentication
  292. request and response.</para>
  293. <para><mediaobject>
  294. <imageobject role="html">
  295. <imagedata align="center" fileref="images/Context.gif"
  296. format="GIF" />
  297. </imageobject>
  298. <caption>
  299. <para>Figure 2: The ContextHolder</para>
  300. </caption>
  301. </mediaobject></para>
  302. <para>A request context is a concrete implementation of the
  303. <literal>Context</literal> interface, which exposes a single
  304. method:</para>
  305. <programlisting>public void validate() throws ContextInvalidException;</programlisting>
  306. <para>This <literal>validate()</literal> method is called to confirm
  307. the <literal>Context</literal> is properly setup. An implementation
  308. will typically use this method to check that the objects it holds are
  309. properly setup.</para>
  310. <para>The <literal>ContextHolder</literal> class makes the
  311. <literal>Context</literal> available to the current thread of
  312. execution using a <literal>ThreadLocal</literal>. A
  313. <literal>ContextInterceptor</literal> is also provided, which is
  314. intended to be chained into the bean context using
  315. <literal>ProxyFactoryBean</literal>. The
  316. <literal>ContextInterceptor</literal> simply calls
  317. <literal>Context.validate()</literal>, which guarantees to business
  318. methods that a valid <literal>Context</literal> is available from the
  319. <literal>ContextHolder</literal>.</para>
  320. </sect2>
  321. <sect2 id="security-contexts-secure-contexts">
  322. <title>Secure Contexts</title>
  323. <para>The Acegi Security System for Spring requires the
  324. <literal>ContextHolder</literal> to contain a request context that
  325. implements the <literal>SecureContext</literal> interface. An
  326. implementation is provided named <literal>SecureContextImpl</literal>.
  327. The <literal>SecureContext</literal> simply extends the
  328. <literal>Context</literal> discussed above and adds a holder and
  329. validation for an <literal>Authentication</literal> object.</para>
  330. </sect2>
  331. <sect2 id="security-contexts-custom-contexts">
  332. <title>Custom Contexts</title>
  333. <para>Developers can create their own request context classes to store
  334. application-specific objects. Such request context classes will need
  335. to implement the <literal>Context</literal> interface. If the Acegi
  336. Security System for Spring is to be used, developers must ensure any
  337. custom request contexts implement the <literal>SecureContext</literal>
  338. interface.</para>
  339. </sect2>
  340. <sect2 id="security-contexts-storage">
  341. <title>Context Storage</title>
  342. <para>Central to Acegi Security's design is that the contents of the
  343. <literal>ContextHolder</literal> (ie the <literal>Context</literal>)
  344. can be stored between web requests. This is so that a successfully
  345. authenticated principal can be identified on subsequent requests
  346. through the <literal>Authentication</literal> stored inside a
  347. <literal>SecureContext</literal> implementation. The
  348. <literal>HttpSessionContextIntegrationFilter</literal> exists to
  349. automatically copy the contents of a well-defined
  350. <literal>HttpSession</literal> attribute into the
  351. <literal>ContextHolder</literal>, then at the end of each request,
  352. copy the <literal>ContextHolder</literal> contents back into the
  353. <literal>HttpSession</literal> ready for next request.</para>
  354. <para>It is essential - and an extremely common error of end users -
  355. that <literal>HttpSessionContextIntegrationFilter</literal> appears
  356. before any other Acegi Security filter. This is because other Acegi
  357. Security filters (along with all Acegi Security classes) expect the
  358. <literal>ContextHolder</literal> to contain a valid
  359. <literal>SecureContext</literal> by the time they are called. Acegi
  360. Security filters also expect to be able to modify the
  361. <literal>ContextHolder</literal> contents as they see fit, and
  362. something else will store those between requests if necessary. This is
  363. why <literal>HttpSessionContextIntegrationFilter</literal> must be the
  364. first filter used.</para>
  365. <para>The <literal>HttpSessionContextIntegrationFilter</literal> has
  366. been designed to store all types of <literal>Context</literal> objects
  367. - not merely Acegi Security related contexts. This means, for example,
  368. that you can extend <literal>SecureContextImpl</literal> to store a
  369. locale or some other parameter, and
  370. <literal>HttpSessionContextIntegrationFilter</literal> will
  371. automatically manage it between web requests.</para>
  372. </sect2>
  373. </sect1>
  374. <sect1 id="security-interception">
  375. <title>Security Interception</title>
  376. <sect2 id="security-interception-all-secure-objects">
  377. <title>All Secure Objects</title>
  378. <para>As described in the High Level Design section, each secure
  379. object has its own security interceptor which is responsible for
  380. handling each request. Handling involves a number of
  381. operations:</para>
  382. <orderedlist>
  383. <listitem>
  384. <para>Store the configuration attributes that are associated with
  385. each secure request.</para>
  386. </listitem>
  387. <listitem>
  388. <para>Extract the <literal>ConfigAttributeDefinition</literal>
  389. that applies to the request from the relevant
  390. <literal>ObjectDefinitionSource</literal>.</para>
  391. </listitem>
  392. <listitem>
  393. <para>Obtain the <literal>Authentication</literal> object from the
  394. <literal>SecureContext</literal>, which is held in the
  395. <literal>ContextHolder</literal>.</para>
  396. </listitem>
  397. <listitem>
  398. <para>Pass the <literal>Authentication</literal> object to the
  399. <literal>AuthenticationManager</literal>, update the
  400. <literal>ContextHolder</literal> with the response.</para>
  401. </listitem>
  402. <listitem>
  403. <para>Pass the <literal>Authentication</literal> object, the
  404. <literal>ConfigAttributeDefinition</literal>, and the secure
  405. object to the <literal>AccessDecisionManager</literal>.</para>
  406. </listitem>
  407. <listitem>
  408. <para>Pass the <literal>Authentication</literal> object, the
  409. <literal>ConfigAttributeDefinition</literal>, and the secure
  410. object to the <literal>RunAsManager</literal>.</para>
  411. </listitem>
  412. <listitem>
  413. <para>If the <literal>RunAsManager</literal> returns a new
  414. <literal>Authentication</literal> object, update the
  415. <literal>ContextHolder</literal> with it.</para>
  416. </listitem>
  417. <listitem>
  418. <para>Proceed with the request execution of the secure
  419. object.</para>
  420. </listitem>
  421. <listitem>
  422. <para>If the <literal>RunAsManager</literal> earlier returned a
  423. new <literal>Authentication</literal> object, update the
  424. <literal>ContextHolder</literal> with the
  425. <literal>Authentication</literal> object that was previously
  426. returned by the <literal>AuthenticationManager</literal>.</para>
  427. </listitem>
  428. <listitem>
  429. <para>If an <literal>AfterInvocationManager</literal> is defined,
  430. pass it the result of the secure object execution so that it may
  431. throw an <literal>AccessDeniedException</literal> or mutate the
  432. returned object if required.</para>
  433. </listitem>
  434. <listitem>
  435. <para>Return any result received from the
  436. <literal>AfterInvocationManager</literal>, or if no
  437. <literal>AfterInvocationManager</literal> is defined, simply
  438. return the result provided by the secure object execution.</para>
  439. </listitem>
  440. </orderedlist>
  441. <para>Whilst this may seem quite involved, don't worry. Developers
  442. interact with the security process by simply implementing basic
  443. interfaces (such as <literal>AccessDecisionManager</literal>), which
  444. are fully discussed below.</para>
  445. <para>The <literal>AbstractSecurityInterceptor</literal> handles the
  446. majority of the flow listed above. As shown in Figure 1, each secure
  447. object has its own security interceptor which subclasses
  448. <literal>AbstractSecurityInterceptor</literal>. Each of these secure
  449. object-specific security interceptors are discussed below.</para>
  450. </sect2>
  451. <sect2 id="security-interception-aopalliance">
  452. <title>AOP Alliance (MethodInvocation) Security Interceptor</title>
  453. <para>To secure <literal>MethodInvocation</literal>s, developers
  454. simply add a properly configured
  455. <literal>MethodSecurityInterceptor</literal> into the application
  456. context. Next the beans requiring security are chained into the
  457. interceptor. This chaining is accomplished using Spring’s
  458. <literal>ProxyFactoryBean</literal> or
  459. <literal>BeanNameAutoProxyCreator</literal>, as commonly used by many
  460. other parts of Spring (refer to the sample application for examples).
  461. Alternatively, Acegi Security provides a
  462. <literal>MethodDefinitionSourceAdvisor</literal> which may be used
  463. with Spring's <literal>DefaultAdvisorAutoProxyCreator</literal> to
  464. automatically chain the security interceptor in front of any beans
  465. defined against the <literal>MethodSecurityInterceptor</literal>. The
  466. <literal>MethodSecurityInterceptor</literal> itself is configured as
  467. follows:</para>
  468. <para><programlisting>&lt;bean id="bankManagerSecurity" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  469. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
  470. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  471. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  472. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  473. &lt;property name="afterInvocationManager"&gt;&lt;ref bean="afterInvocationManager"/&gt;&lt;/property&gt;
  474. &lt;property name="objectDefinitionSource"&gt;
  475. &lt;value&gt;
  476. net.sf.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER
  477. net.sf.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER
  478. &lt;/value&gt;
  479. &lt;/property&gt;
  480. &lt;/bean&gt;</programlisting></para>
  481. <para>As shown above, the <literal>MethodSecurityInterceptor</literal>
  482. is configured with a reference to an
  483. <literal>AuthenticationManager</literal>,
  484. <literal>AccessDecisionManager</literal> and
  485. <literal>RunAsManager</literal>, which are each discussed in separate
  486. sections below. In this case we've also defined an
  487. <literal>AfterInvocationManager</literal>, although this is entirely
  488. optional. The <literal>MethodSecurityInterceptor</literal> is also
  489. configured with configuration attributes that apply to different
  490. method signatures. A full discussion of configuration attributes is
  491. provided in the High Level Design section of this document.</para>
  492. <para>The <literal>MethodSecurityInterceptor</literal> can be
  493. configured with configuration attributes in three ways. The first is
  494. via a property editor and the application context, which is shown
  495. above. The second is via defining the configuration attributes in your
  496. source code using Jakarta Commons Attributes. The third is via writing
  497. your own <literal>ObjectDefinitionSource</literal>, although this is
  498. beyond the scope of this document. Irrespective of the approach used,
  499. the <literal>ObjectDefinitionSource</literal> is responsible for
  500. returning a <literal>ConfigAttributeDefinition</literal> object that
  501. contains all of the configuration attributes associated with a single
  502. secure method.</para>
  503. <para>It should be noted that the
  504. <literal>MethodSecurityInterceptor.setObjectDefinitionSource()</literal>
  505. method actually expects an instance of
  506. <literal>MethodDefinitionSource</literal>. This is a marker interface
  507. which subclasses <literal>ObjectDefinitionSource</literal>. It simply
  508. denotes the <literal>ObjectDefinitionSource</literal> understands
  509. <literal>MethodInvocation</literal>s. In the interests of simplicity
  510. we'll continue to refer to the
  511. <literal>MethodDefinitionSource</literal> as an
  512. <literal>ObjectDefinitionSource</literal>, as the distinction is of
  513. little relevance to most users of the
  514. <literal>MethodSecurityInterceptor</literal>.</para>
  515. <para>If using the application context property editor approach (as
  516. shown above), commas are used to delimit the different configuration
  517. attributes that apply to a given method pattern. Each configuration
  518. attribute is assigned into its own <literal>SecurityConfig</literal>
  519. object. The <literal>SecurityConfig</literal> object is discussed in
  520. the High Level Design section.</para>
  521. <para>If using the Jakarta Commons Attributes approach, your bean
  522. context will be configured differently:</para>
  523. <para><programlisting>&lt;bean id="attributes" class="org.springframework.metadata.commons.CommonsAttributes"/&gt;
  524. &lt;bean id="objectDefinitionSource" class="net.sf.acegisecurity.intercept.method.MethodDefinitionAttributes"&gt;
  525. &lt;property name="attributes"&gt;&lt;ref local="attributes"/&gt;&lt;/property&gt;
  526. &lt;/bean&gt;
  527. &lt;bean id="bankManagerSecurity" class="net.sf.acegisecurity.intercept.method.MethodSecurityInterceptor"&gt;
  528. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  529. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  530. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  531. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  532. &lt;property name="objectDefinitionSource"&gt;&lt;ref bean="objectDefinitionSource"/&gt;&lt;/property&gt;
  533. &lt;/bean&gt;</programlisting></para>
  534. <para>In addition, your source code will contain Jakarta Commons
  535. Attributes tags that refer to a concrete implementation of
  536. <literal>ConfigAttribute</literal>. The following example uses the
  537. <literal>SecurityConfig</literal> implementation to represent the
  538. configuration attributes, and results in the same security
  539. configuration as provided by the property editor approach
  540. above:</para>
  541. <para><programlisting>public interface BankManager {
  542. /**
  543. * @@SecurityConfig("ROLE_SUPERVISOR")
  544. * @@SecurityConfig("RUN_AS_SERVER")
  545. */
  546. public void deleteSomething(int id);
  547. /**
  548. * @@SecurityConfig("ROLE_SUPERVISOR")
  549. * @@SecurityConfig("RUN_AS_SERVER")
  550. */
  551. public void deleteAnother(int id);
  552. /**
  553. * @@SecurityConfig("ROLE_TELLER")
  554. * @@SecurityConfig("ROLE_SUPERVISOR")
  555. * @@SecurityConfig("BANKSECURITY_CUSTOMER")
  556. * @@SecurityConfig("RUN_AS_SERVER")
  557. */
  558. public float getBalance(int id);
  559. }</programlisting></para>
  560. <para>You might have noticed the
  561. <literal>validateConfigAttributes</literal> property in the above
  562. <literal>MethodSecurityInterceptor</literal> examples. When set to
  563. <literal>true</literal> (the default), at startup time the
  564. <literal>MethodSecurityInterceptor</literal> will evaluate if the
  565. provided configuration attributes are valid. It does this by checking
  566. each configuration attribute can be processed by either the
  567. <literal>AccessDecisionManager</literal> or the
  568. <literal>RunAsManager</literal>. If neither of these can process a
  569. given configuration attribute, an exception is thrown. If using the
  570. Jakarta Commons Attributes method of configuration, you should set
  571. <literal>validateConfigAttributes</literal> to
  572. <literal>false</literal>.</para>
  573. </sect2>
  574. <sect2 id="security-interception-aspectj">
  575. <title>AspectJ (JoinPoint) Security Interceptor</title>
  576. <para>The AspectJ security interceptor is very similar to the AOP
  577. Alliance security interceptor discussed in the previous section.
  578. Indeed we will only discuss the differences in this section.</para>
  579. <para>The AspectJ interceptor is named
  580. <literal>AspectJSecurityInterceptor</literal>. Unlike the AOP Alliance
  581. security interceptor, which relies on the Spring application context
  582. to weave in the security interceptor via proxying, the
  583. <literal>AspectJSecurityInterceptor</literal> is weaved in via the
  584. AspectJ compiler. It would not be uncommon to use both types of
  585. security interceptors in the same application, with
  586. <literal>AspectJSecurityInterceptor</literal> being used for domain
  587. object instance security and the AOP Alliance
  588. <literal>MethodSecurityInterceptor</literal> being used for services
  589. layer security.</para>
  590. <para>Let's first consider how the
  591. <literal>AspectJSecurityInterceptor</literal> is configured in the
  592. Spring application context:</para>
  593. <para><programlisting>&lt;bean id="bankManagerSecurity" class="net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor"&gt;
  594. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
  595. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  596. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  597. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  598. &lt;property name="afterInvocationManager"&gt;&lt;ref bean="afterInvocationManager"/&gt;&lt;/property&gt;
  599. &lt;property name="objectDefinitionSource"&gt;
  600. &lt;value&gt;
  601. net.sf.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER
  602. net.sf.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER
  603. &lt;/value&gt;
  604. &lt;/property&gt;
  605. &lt;/bean&gt;</programlisting></para>
  606. <para>As you can see, aside from the class name, the
  607. <literal>AspectJSecurityInterceptor</literal> is exactly the same as
  608. the AOP Alliance security interceptor. Indeed the two interceptors can
  609. share the same <literal>objectDefinitionSource</literal>, as the
  610. <literal>ObjectDefinitionSource</literal> works with
  611. <literal>java.lang.reflect.Method</literal>s rather than an AOP
  612. library-specific class. Of course, your access decisions have access
  613. to the relevant AOP library-specific invocation (ie
  614. <literal>MethodInvocation</literal> or <literal>JoinPoint</literal>)
  615. and as such can consider a range of addition criteria when making
  616. access decisions (such as method arguments).</para>
  617. <para>Next you'll need to define an AspectJ <literal>aspect</literal>.
  618. For example:</para>
  619. <para><programlisting>package net.sf.acegisecurity.samples.aspectj;
  620. import net.sf.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor;
  621. import net.sf.acegisecurity.intercept.method.aspectj.AspectJCallback;
  622. import org.springframework.beans.factory.InitializingBean;
  623. public aspect DomainObjectInstanceSecurityAspect implements InitializingBean {
  624. private AspectJSecurityInterceptor securityInterceptor;
  625. pointcut domainObjectInstanceExecution(): target(PersistableEntity)
  626. &amp;&amp; execution(public * *(..)) &amp;&amp; !within(DomainObjectInstanceSecurityAspect);
  627. Object around(): domainObjectInstanceExecution() {
  628. if (this.securityInterceptor != null) {
  629. AspectJCallback callback = new AspectJCallback() {
  630. public Object proceedWithObject() {
  631. return proceed();
  632. }
  633. };
  634. return this.securityInterceptor.invoke(thisJoinPoint, callback);
  635. } else {
  636. return proceed();
  637. }
  638. }
  639. public AspectJSecurityInterceptor getSecurityInterceptor() {
  640. return securityInterceptor;
  641. }
  642. public void setSecurityInterceptor(AspectJSecurityInterceptor securityInterceptor) {
  643. this.securityInterceptor = securityInterceptor;
  644. }
  645. public void afterPropertiesSet() throws Exception {
  646. if (this.securityInterceptor == null)
  647. throw new IllegalArgumentException("securityInterceptor required");
  648. }
  649. }</programlisting></para>
  650. <para>In the above example, the security interceptor will be applied
  651. to every instance of <literal>PersistableEntity</literal>, which is an
  652. abstract class not shown (you can use any other class or
  653. <literal>pointcut</literal> expression you like). For those curious,
  654. <literal>AspectJCallback</literal> is needed because the
  655. <literal>proceed();</literal> statement has special meaning only
  656. within an <literal>around()</literal> body. The
  657. <literal>AspectJSecurityInterceptor</literal> calls this anonymous
  658. <literal>AspectJCallback</literal> class when it wants the target
  659. object to continue.</para>
  660. <para>You will need to configure Spring to load the aspect and wire it
  661. with the <literal>AspectJSecurityInterceptor</literal>. A bean
  662. declaration which achieves this is shown below:</para>
  663. <para><programlisting>&lt;bean id="domainObjectInstanceSecurityAspect"
  664. class="net.sf.acegisecurity.samples.aspectj.DomainObjectInstanceSecurityAspect"
  665. factory-method="aspectOf"&gt;
  666. &lt;property name="securityInterceptor"&gt;&lt;ref bean="aspectJSecurityInterceptor"/&gt;&lt;/property&gt;
  667. &lt;/bean&gt;</programlisting></para>
  668. <para>That's it! Now you can create your beans from anywhere within
  669. your application, using whatever means you think fit (eg <literal>new
  670. Person();</literal>) and they will have the security interceptor
  671. applied.</para>
  672. </sect2>
  673. <sect2 id="security-interception-filterinvocation">
  674. <title>FilterInvocation Security Interceptor</title>
  675. <para>To secure <literal>FilterInvocation</literal>s, developers need
  676. to add a filter to their <literal>web.xml</literal> that delegates to
  677. the <literal>SecurityEnforcementFilter</literal>. A typical
  678. configuration example is provided below: <programlisting>&lt;filter&gt;
  679. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  680. &lt;filter-class&gt;net.sf.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  681. &lt;init-param&gt;
  682. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  683. &lt;param-value&gt;net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter&lt;/param-value&gt;
  684. &lt;/init-param&gt;
  685. &lt;/filter&gt;
  686. &lt;filter-mapping&gt;
  687. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  688. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  689. &lt;/filter-mapping&gt;</programlisting></para>
  690. <para>Notice that the filter is actually a
  691. <literal>FilterToBeanProxy</literal>. Most of the filters used by the
  692. Acegi Security System for Spring use this class. Refer to the Filters
  693. section to learn more about this bean.</para>
  694. <para>In the application context you will need to configure three
  695. beans:</para>
  696. <programlisting>&lt;bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter"&gt;
  697. &lt;property name="filterSecurityInterceptor"&gt;&lt;ref bean="filterInvocationInterceptor"/&gt;&lt;/property&gt;
  698. &lt;property name="authenticationEntryPoint"&gt;&lt;ref bean="authenticationEntryPoint"/&gt;&lt;/property&gt;
  699. &lt;/bean&gt;
  700. &lt;bean id="authenticationEntryPoint" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;
  701. &lt;property name="loginFormUrl"&gt;&lt;value&gt;/acegilogin.jsp&lt;/value&gt;&lt;/property&gt;
  702. &lt;property name="forceHttps"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  703. &lt;/bean&gt;
  704. &lt;bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  705. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  706. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  707. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  708. &lt;property name="objectDefinitionSource"&gt;
  709. &lt;value&gt;
  710. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  711. \A/secure/super/.*\Z=ROLE_WE_DONT_HAVE
  712. \A/secure/.*\Z=ROLE_SUPERVISOR,ROLE_TELLER
  713. &lt;/value&gt;
  714. &lt;/property&gt;
  715. &lt;/bean&gt;</programlisting>
  716. <para>The <literal>AuthenticationEntryPoint</literal> will be called
  717. if the user requests a secure HTTP resource but they are not
  718. authenticated. The class handles presenting the appropriate response
  719. to the user so that authentication can begin. Three concrete
  720. implementations are provided with the Acegi Security System for
  721. Spring: <literal>AuthenticationProcessingFilterEntryPoint</literal>
  722. for commencing a form-based authentication,
  723. <literal>BasicProcessingFilterEntryPoint</literal> for commencing a
  724. HTTP Basic authentication process, and
  725. <literal>CasProcessingFilterEntryPoint</literal> for commencing a Yale
  726. Central Authentication Service (CAS) login. The
  727. <literal>AuthenticationProcessingFilterEntryPoint</literal> and
  728. <literal>CasProcessingFilterEntryPoint</literal> have optional
  729. properties related to forcing the use of HTTPS, so please refer to the
  730. JavaDocs if you require this.</para>
  731. <para>The <literal>PortMapper</literal> provides information on which
  732. HTTPS ports correspond to which HTTP ports. This is used by the
  733. <literal>AuthenticationProcessingFilterEntryPoint</literal> and
  734. several other beans. The default implementation,
  735. <literal>PortMapperImpl</literal>, knows the common HTTP ports 80 and
  736. 8080 map to HTTPS ports 443 and 8443 respectively. You can customise
  737. this mapping if desired.</para>
  738. <para>The <literal>SecurityEnforcementFilter</literal> primarily
  739. provides session management support and initiates authentication when
  740. required. It delegates actual <literal>FilterInvocation</literal>
  741. security decisions to the configured
  742. <literal>FilterSecurityInterceptor</literal>.</para>
  743. <para>Like any other security interceptor, the
  744. <literal>FilterSecurityInterceptor</literal> requires a reference to
  745. an <literal>AuthenticationManager</literal>,
  746. <literal>AccessDecisionManager</literal> and
  747. <literal>RunAsManager</literal>, which are each discussed in separate
  748. sections below. The <literal>FilterSecurityInterceptor</literal> is
  749. also configured with configuration attributes that apply to different
  750. HTTP URL requests. A full discussion of configuration attributes is
  751. provided in the High Level Design section of this document.</para>
  752. <para>The <literal>FilterSecurityInterceptor</literal> can be
  753. configured with configuration attributes in two ways. The first is via
  754. a property editor and the application context, which is shown above.
  755. The second is via writing your own
  756. <literal>ObjectDefinitionSource</literal>, although this is beyond the
  757. scope of this document. Irrespective of the approach used, the
  758. <literal>ObjectDefinitionSource</literal> is responsible for returning
  759. a <literal>ConfigAttributeDefinition</literal> object that contains
  760. all of the configuration attributes associated with a single secure
  761. HTTP URL.</para>
  762. <para>It should be noted that the
  763. <literal>FilterSecurityInterceptor.setObjectDefinitionSource()</literal>
  764. method actually expects an instance of
  765. <literal>FilterInvocationDefinitionSource</literal>. This is a marker
  766. interface which subclasses <literal>ObjectDefinitionSource</literal>.
  767. It simply denotes the <literal>ObjectDefinitionSource</literal>
  768. understands <literal>FilterInvocation</literal>s. In the interests of
  769. simplicity we'll continue to refer to the
  770. <literal>FilterInvocationDefinitionSource</literal> as an
  771. <literal>ObjectDefinitionSource</literal>, as the distinction is of
  772. little relevance to most users of the
  773. <literal>FilterSecurityInterceptor</literal>.</para>
  774. <para>If using the application context property editor approach (as
  775. shown above), commas are used to delimit the different configuration
  776. attributes that apply to each HTTP URL. Each configuration attribute
  777. is assigned into its own <literal>SecurityConfig</literal> object. The
  778. <literal>SecurityConfig</literal> object is discussed in the High
  779. Level Design section. The <literal>ObjectDefinitionSource</literal>
  780. created by the property editor,
  781. <literal>FilterInvocationDefinitionSource</literal>, matches
  782. configuration attributes against <literal>FilterInvocations</literal>
  783. based on expression evaluation of the request URL. Two standard
  784. expression syntaxes are supported. The default is to treat all
  785. expressions as regular expressions. Alternatively, the presence of a
  786. <literal>PATTERN_TYPE_APACHE_ANT</literal> directive will cause all
  787. expressions to be treated as Apache Ant paths. It is not possible to
  788. mix expression syntaxes within the same definition. For example, the
  789. earlier configuration could be generated using Apache Ant paths as
  790. follows:</para>
  791. <para><programlisting>&lt;bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  792. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  793. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  794. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  795. &lt;property name="objectDefinitionSource"&gt;
  796. &lt;value&gt;
  797. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  798. PATTERN_TYPE_APACHE_ANT
  799. /secure/super/**=ROLE_WE_DONT_HAVE
  800. /secure/**=ROLE_SUPERVISOR,ROLE_TELLER
  801. &lt;/value&gt;
  802. &lt;/property&gt;
  803. &lt;/bean&gt;</programlisting></para>
  804. <para>Irrespective of the type of expression syntax used, expressions
  805. are always evaluated in the order they are defined. Thus it is
  806. important that more specific expressions are defined higher in the
  807. list than less specific expressions. This is reflected in our example
  808. above, where the more specific <literal>/secure/super/</literal>
  809. pattern appears higher than the less specific
  810. <literal>/secure/</literal> pattern. If they were reversed, the
  811. <literal>/secure/</literal> pattern would always match and the
  812. <literal>/secure/super/</literal> pattern would never be
  813. evaluated.</para>
  814. <para>The special keyword
  815. <literal>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</literal> causes
  816. the <literal>FilterInvocationDefinitionSource</literal> to
  817. automatically convert a request URL to lowercase before comparison
  818. against the expressions. Whilst by default the case of the request URL
  819. is not converted, it is generally recommended to use
  820. <literal>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</literal> and
  821. write each expression assuming lowercase.</para>
  822. <para>As with other security interceptors, the
  823. <literal>validateConfigAttributes</literal> property is observed. When
  824. set to <literal>true</literal> (the default), at startup time the
  825. <literal>FilterSecurityInterceptor</literal> will evaluate if the
  826. provided configuration attributes are valid. It does this by checking
  827. each configuration attribute can be processed by either the
  828. <literal>AccessDecisionManager</literal> or the
  829. <literal>RunAsManager</literal>. If neither of these can process a
  830. given configuration attribute, an exception is thrown.</para>
  831. </sect2>
  832. </sect1>
  833. <sect1 id="security-authentication">
  834. <title>Authentication</title>
  835. <sect2 id="security-authentication-requests">
  836. <title>Authentication Requests</title>
  837. <para>Authentication requires a way for client code to present its
  838. security identification to the Acegi Security System for Spring. This
  839. is the role of the <literal>Authentication</literal> interface. The
  840. <literal>Authentication</literal> interface holds three important
  841. objects: the principal (the identity of the caller), the credentials
  842. (the proof of the identity of the caller, such as a password), and the
  843. authorities that have been granted to the principal. The principal and
  844. its credentials are populated by the client code, whilst the granted
  845. authorities are populated by the
  846. <literal>AuthenticationManager</literal>.</para>
  847. <para><mediaobject>
  848. <imageobject role="html">
  849. <imagedata align="center" fileref="images/Authentication.gif"
  850. format="GIF" />
  851. </imageobject>
  852. <caption>
  853. <para>Figure 3: Key Authentication Architecture</para>
  854. </caption>
  855. </mediaobject></para>
  856. <para>As shown in Figure 3, the Acegi Security System for Spring
  857. includes several concrete <literal>Authentication</literal>
  858. implementations:</para>
  859. <itemizedlist spacing="compact">
  860. <listitem>
  861. <para><literal>UsernamePasswordAuthenticationToken</literal>
  862. allows a username and password to be presented as the principal
  863. and credentials respectively. It is also what is created by the
  864. HTTP Session Authentication system.</para>
  865. </listitem>
  866. <listitem>
  867. <para><literal>TestingAuthenticationToken</literal> facilitates
  868. unit testing by automatically being considered an authenticated
  869. object by its associated
  870. <literal>AuthenticationProvider</literal>.</para>
  871. </listitem>
  872. <listitem>
  873. <para><literal>RunAsUserToken</literal> is used by the default
  874. run-as authentication replacement implementation. This is
  875. discussed further in the Run-As Authentication Replacement
  876. section.</para>
  877. </listitem>
  878. <listitem>
  879. <para><literal>CasAuthenticationToken</literal> is used to
  880. represent a successful Yale Central Authentication Service (CAS)
  881. authentication. This is discussed further in the CAS
  882. section.</para>
  883. </listitem>
  884. <listitem>
  885. <para><literal>PrincipalAcegiUserToken</literal> and
  886. <literal>JettyAcegiUserToken</literal> implement
  887. <literal>AuthByAdapter</literal> (a subclass of
  888. <literal>Authentication</literal>) and are used whenever
  889. authentication is completed by Acegi Security System for Spring
  890. container adapters. This is discussed further in the Container
  891. Adapters section.</para>
  892. </listitem>
  893. </itemizedlist>
  894. <para>The authorities granted to a principal are represented by the
  895. <literal>GrantedAuthority</literal> interface. The
  896. <literal>GrantedAuthority</literal> interface is discussed at length
  897. in the Authorization section.</para>
  898. </sect2>
  899. <sect2 id="security-authentication-manager">
  900. <title>Authentication Manager</title>
  901. <para>As discussed in the Security Interception section, the
  902. <literal>AbstractSecurityInterceptor</literal> extracts the
  903. <literal>Authentication</literal> object from the
  904. <literal>SecureContext</literal> in the
  905. <literal>ContextHolder</literal>. This is then passed to an
  906. <literal>AuthenticationManager</literal>. The
  907. <literal>AuthenticationManager</literal> interface is very
  908. simple:</para>
  909. <programlisting>public Authentication authenticate(Authentication authentication) throws AuthenticationException;</programlisting>
  910. <para>Implementations of <literal>AuthenticationManager</literal> are
  911. required to throw an <literal>AuthenticationException</literal> should
  912. authentication fail, or return a fully populated
  913. <literal>Authentication</literal> object. In particular, the returned
  914. <literal>Authentication</literal> object should contain an array of
  915. <literal>GrantedAuthority</literal> objects. The
  916. <literal>SecurityInterceptor</literal> places the populated
  917. <literal>Authentication</literal> object back in the
  918. <literal>SecureContext</literal> in the
  919. <literal>ContextHolder</literal>, overwriting the original
  920. <literal>Authentication</literal> object.</para>
  921. <para>The <literal>AuthenticationException</literal> has a number of
  922. subclasses. The most important are
  923. <literal>BadCredentialsException</literal> (an incorrect principal or
  924. credentials), <literal>DisabledException</literal> and
  925. <literal>LockedException</literal>. The latter two exceptions indicate
  926. the principal was found, but the credentials were not checked and
  927. authentication is denied. An
  928. <literal>AuthenticationServiceException</literal> is also provided,
  929. which indicates the authentication system could not process the
  930. request (eg a database was unavailable).
  931. <literal>AuthenticationException</literal> also has a
  932. <literal>CredentialsExpiredException</literal> and
  933. <literal>AccoungtExpiredException</literal> subclass, although these
  934. are less commonly used.</para>
  935. </sect2>
  936. <sect2 id="security-authentication-provider">
  937. <title>Provider-Based Authentication</title>
  938. <para>Whilst the basic <literal>Authentication</literal> and
  939. <literal>AuthenticationManager</literal> interfaces enable users to
  940. develop their own authentication systems, users should consider using
  941. the provider-based authentication packages provided by the Acegi
  942. Security System for Spring. The key class,
  943. <literal>ProviderManager</literal>, is configured via the bean context
  944. with a list of <literal>AuthenticationProvider</literal>s:</para>
  945. <para><programlisting>&lt;bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager"&gt;
  946. &lt;property name="providers"&gt;
  947. &lt;list&gt;
  948. &lt;ref bean="daoAuthenticationProvider"/&gt;
  949. &lt;ref bean="someOtherAuthenticationProvider"/&gt;
  950. &lt;/list&gt;
  951. &lt;/property&gt;
  952. &lt;/bean&gt;</programlisting></para>
  953. <para><literal>ProviderManager</literal> calls a series of registered
  954. <literal>AuthenticationProvider</literal> implementations, until one
  955. is found that indicates it is able to authenticate a given
  956. <literal>Authentication</literal> class. When the first compatible
  957. <literal>AuthenticationProvider</literal> is located, it is passed the
  958. authentication request. The <literal>AuthenticationProvider</literal>
  959. will then either throw an <literal>AuthenticationException</literal>
  960. or return a fully populated <literal>Authentication</literal>
  961. object.</para>
  962. <para>Note the <literal>ProviderManager</literal> may throw a
  963. <literal>ProviderNotFoundException</literal> (a subclass of
  964. <literal>AuthenticationException</literal>) if it none of the
  965. registered <literal>AuthenticationProviders</literal> can validate the
  966. <literal>Authentication</literal> object.</para>
  967. <para>Several <literal>AuthenticationProvider</literal>
  968. implementations are provided with the Acegi Security System for
  969. Spring:</para>
  970. <para><itemizedlist spacing="compact">
  971. <listitem>
  972. <para><literal>TestingAuthenticationProvider</literal> is able
  973. to authenticate a <literal>TestingAuthenticationToken</literal>.
  974. The limit of its authentication is simply to treat whatever is
  975. contained in the <literal>TestingAuthenticationToken</literal>
  976. as valid. This makes it ideal for use during unit testing, as
  977. you can create an <literal>Authentication</literal> object with
  978. precisely the <literal>GrantedAuthority</literal> objects
  979. required for calling a given method. You definitely would not
  980. register this <literal>AuthenticationProvider</literal> on a
  981. production system.</para>
  982. </listitem>
  983. <listitem>
  984. <para><literal>DaoAuthenticationProvider</literal> is able to
  985. authenticate a
  986. <literal>UsernamePasswordAuthenticationToken</literal> by
  987. accessing an authentication respository via a data access
  988. object. This is discussed further below, as it is the main way
  989. authentication is initially handled.</para>
  990. </listitem>
  991. <listitem>
  992. <para><literal>RunAsImplAuthenticationToken</literal> is able to
  993. authenticate a <literal>RunAsUserToken</literal>. This is
  994. discussed further in the Run-As Authentication Replacement
  995. section. You would not register this
  996. <literal>AuthenticationProvider</literal> if you were not using
  997. run-as replacement.</para>
  998. </listitem>
  999. <listitem>
  1000. <para><literal>AuthByAdapterProvider</literal> is able to
  1001. authenticate any <literal>AuthByAdapter</literal> (a subclass of
  1002. <literal>Authentication</literal> used with container adapters).
  1003. This is discussed further in the Container Adapters section. You
  1004. would not register this
  1005. <literal>AuthenticationProvider</literal> if you were not using
  1006. container adapters.</para>
  1007. </listitem>
  1008. <listitem>
  1009. <para><literal>CasAuthenticationProvider</literal> is able to
  1010. authenticate Yale Central Authentication Service (CAS) tickets.
  1011. This is discussed further in the CAS Single Sign On
  1012. section.</para>
  1013. </listitem>
  1014. <listitem>
  1015. <para><literal>JaasAuthenticationProvider</literal> is able to
  1016. delegate authentication requests to a JAAS
  1017. <literal>LoginModule</literal>. This is discussed further
  1018. below.</para>
  1019. </listitem>
  1020. </itemizedlist></para>
  1021. </sect2>
  1022. <sect2 id="security-authentication-provider-dao">
  1023. <title>Data Access Object Authentication Provider</title>
  1024. <para>The Acegi Security System for Spring includes a
  1025. production-quality <literal>AuthenticationProvider</literal>
  1026. implementation called <literal>DaoAuthenticationProvider</literal>.
  1027. This authentication provider is able to authenticate a
  1028. <literal>UsernamePasswordAuthenticationToken</literal> by obtaining
  1029. authentication details from a data access object configured at bean
  1030. creation time:</para>
  1031. <para><programlisting>&lt;bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  1032. &lt;property name="authenticationDao"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  1033. &lt;property name="saltSource"&gt;&lt;ref bean="saltSource"/&gt;&lt;/property&gt;
  1034. &lt;property name="passwordEncoder"&gt;&lt;ref bean="passwordEncoder"/&gt;&lt;/property&gt;
  1035. &lt;/bean&gt;</programlisting></para>
  1036. <para>The <literal>PasswordEncoder</literal> and
  1037. <literal>SaltSource</literal> are optional. A
  1038. <literal>PasswordEncoder</literal> provides encoding and decoding of
  1039. passwords obtained from the authentication repository. A
  1040. <literal>SaltSource</literal> enables the passwords to be populated
  1041. with a "salt", which enhances the security of the passwords in the
  1042. authentication repository. <literal>PasswordEncoder</literal>
  1043. implementations are provided with the Acegi Security System for Spring
  1044. covering MD5, SHA and cleartext encodings. Two
  1045. <literal>SaltSource</literal> implementations are also provided:
  1046. <literal>SystemWideSaltSource</literal> which encodes all passwords
  1047. with the same salt, and <literal>ReflectionSaltSource</literal>, which
  1048. inspects a given property of the returned
  1049. <literal>UserDetails</literal> object to obtain the salt. Please refer
  1050. to the JavaDocs for further details on these optional features.</para>
  1051. <para>In addition to the properties above, the
  1052. <literal>DaoAuthenticationProvider</literal> supports optional caching
  1053. of <literal>UserDetails</literal> objects. The
  1054. <literal>UserCache</literal> interface enables the
  1055. <literal>DaoAuthenticationProvider</literal> to place a
  1056. <literal>UserDetails</literal> object into the cache, and retrieve it
  1057. from the cache upon subsequent authentication attempts for the same
  1058. username. By default the <literal>DaoAuthenticationProvider</literal>
  1059. uses the <literal>NullUserCache</literal>, which performs no caching.
  1060. A usable caching implementation is also provided,
  1061. <literal>EhCacheBasedUserCache</literal>, which is configured as
  1062. follows:</para>
  1063. <para><programlisting>&lt;bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  1064. &lt;property name="authenticationDao"&gt;&lt;ref bean="authenticationDao"/&gt;&lt;/property&gt;
  1065. &lt;property name="userCache"&gt;&lt;ref bean="userCache"/&gt;&lt;/property&gt;
  1066. &lt;/bean&gt;
  1067. &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;
  1068. &lt;property name="configLocation"&gt;
  1069. &lt;value&gt;classpath:/ehcache-failsafe.xml&lt;/value&gt;
  1070. &lt;/property&gt;
  1071. &lt;/bean&gt;
  1072. &lt;bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;
  1073. &lt;property name="cacheManager"&gt;
  1074. &lt;ref local="cacheManager"/&gt;
  1075. &lt;/property&gt;
  1076. &lt;property name="cacheName"&gt;
  1077. &lt;value&gt;userCache&lt;/value&gt;
  1078. &lt;/property&gt;
  1079. &lt;/bean&gt;
  1080. &lt;bean id="userCache" class="net.sf.acegisecurity.providers.dao.cache.EhCacheBasedUserCache"&gt;
  1081. &lt;property name="cache"&gt;&lt;ref local="userCacheBackend"/&gt;&lt;/property&gt;
  1082. &lt;/bean&gt;</programlisting></para>
  1083. <para>All Acegi Security EH-CACHE implementations (including
  1084. <literal>EhCacheBasedUserCache</literal>) require an EH-CACHE
  1085. <literal>Cache</literal> object. The <literal>Cache</literal> object
  1086. can be obtained from wherever you like, although we recommend you use
  1087. Spring's factory classes as shown in the above configuration. If using
  1088. Spring's factory classes, please refer to the Spring documentation for
  1089. further details on how to optimise the cache storage location, memory
  1090. usage, eviction policies, timeouts etc.</para>
  1091. <para>For a class to be able to provide the
  1092. <literal>DaoAuthenticationProvider</literal> with access to an
  1093. authentication repository, it must implement the
  1094. <literal>AuthenticationDao</literal> interface:</para>
  1095. <para><programlisting>public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException;</programlisting></para>
  1096. <para>The <literal>UserDetails</literal> is an interface that provides
  1097. getters that guarantee non-null provision of basic authentication
  1098. information such as the username, password, granted authorities and
  1099. whether the user is enabled or disabled. A concrete implementation,
  1100. <literal>User</literal>, is also provided. Acegi Security users will
  1101. need to decide when writing their <literal>AuthenticationDao</literal>
  1102. what type of <literal>UserDetails</literal> to return. In most cases
  1103. <literal>User</literal> will be used directly or subclassed, although
  1104. special circumstances (such as object relational mappers) may require
  1105. users to write their own <literal>UserDetails</literal> implementation
  1106. from scratch. <literal>UserDetails</literal> is often used to store
  1107. additional principal-related properties (such as their telephone
  1108. number and email address), so they can be easily used by web
  1109. views.</para>
  1110. <para>Given <literal>AuthenticationDao</literal> is so simple to
  1111. implement, it should be easy for users to retrieve authentication
  1112. information using a persistence strategy of their choice.</para>
  1113. <para>A design decision was made not to support account locking in the
  1114. <literal>DaoAuthenticationProvider</literal>, as doing so would have
  1115. increased the complexity of the <literal>AuthenticationDao</literal>
  1116. interface. For instance, a method would be required to increase the
  1117. count of unsuccessful authentication attempts. Such functionality
  1118. could be easily provided by leveraging the application event
  1119. publishing features discussed below.</para>
  1120. <para><literal>DaoAuthenticationProvider</literal> returns an
  1121. <literal>Authentication</literal> object which in turn has its
  1122. <literal>principal</literal> property set. The principal will be
  1123. either a <literal>String</literal> (which is essentially the username)
  1124. or a <literal>UserDetails</literal> object (which was looked up from
  1125. the <literal>AuthenticationDao</literal>). By default the
  1126. <literal>UserDetails</literal> is returned, as this enables
  1127. applications to add extra properties potentially of use in
  1128. applications, such as the user's full name, email address etc. If
  1129. using container adapters, or if your applications were written to
  1130. operate with <literal>String</literal>s (as was the case for releases
  1131. prior to Acegi Security 0.6), you should set the
  1132. <literal>DaoAuthenticationProvider.forcePrincipalAsString</literal>
  1133. property to <literal>true</literal> in your application
  1134. context.</para>
  1135. </sect2>
  1136. <sect2 id="security-authentication-provider-events">
  1137. <title>Event Publishing</title>
  1138. <para>The <literal>DaoAuthenticationProvider</literal> automatically
  1139. obtains the <literal>ApplicationContext</literal> it is running in at
  1140. startup time. This allows the provider to publish events through the
  1141. standard Spring event framework. Three types of event messages are
  1142. published:</para>
  1143. <itemizedlist spacing="compact">
  1144. <listitem>
  1145. <para><literal>AuthenticationSuccessEvent</literal> is published
  1146. when an authentication request is successful.</para>
  1147. </listitem>
  1148. <listitem>
  1149. <para><literal>AuthenticationFailureDisabledEvent</literal> is
  1150. published when an authentication request is unsuccessful because
  1151. the returned <literal>UserDetails</literal> is disabled. This is
  1152. normally the case when an account is locked.</para>
  1153. </listitem>
  1154. <listitem>
  1155. <para><literal>AuthenticationFailureAccountExpiredEvent</literal>
  1156. is published when an authentication request is unsuccessful
  1157. because the returned <literal>UserDetails</literal> indicates the
  1158. account has expired. Some applications may wish to distinguish
  1159. between an account being disabled and expired.</para>
  1160. </listitem>
  1161. <listitem>
  1162. <para><literal>AuthenticationFailureCredentialsExpiredEvent</literal>
  1163. is published when an authentication request is unsuccessful
  1164. because the returned <literal>UserDetails</literal> indicates the
  1165. account's credentials have expired. Some applications may wish to
  1166. expire the credentials if, for example, a password is not changed
  1167. with sufficient regularity.</para>
  1168. </listitem>
  1169. <listitem>
  1170. <para><literal>AuthenticationFailureUsernameNotFoundEvent</literal>
  1171. is published when an authentication request is unsuccessful
  1172. because the <literal>AuthenticationDao</literal> could not locate
  1173. the <literal>UserDetails</literal>.</para>
  1174. </listitem>
  1175. <listitem>
  1176. <para><literal>AuthenticationFailurePasswordEvent</literal> is
  1177. published when an authentication request is unsuccessful because
  1178. the presented password did not match that in the
  1179. <literal>UserDetails</literal>.</para>
  1180. </listitem>
  1181. </itemizedlist>
  1182. <para>Each event contains two objects: the
  1183. <literal>Authentication</literal> object that represented the
  1184. authentication request, and the <literal>UserDetails</literal> object
  1185. that was found in response to the authentication request (clearly the
  1186. latter will be a dummy object in the case of
  1187. <literal>AuthenticationFailureUsernameNotFoundEvent</literal>). The
  1188. <literal>Authentication</literal> interface provides a
  1189. <literal>getDetails()</literal> method which often includes
  1190. information that event consumers may find useful (eg the TCP/IP
  1191. address that the authentication request originated from).</para>
  1192. <para>As per standard Spring event handling, you can receive these
  1193. events by adding a bean to the application context which implements
  1194. the <literal>ApplicationListener</literal> interface. Included with
  1195. Acegi Security is a <literal>LoggerListener</literal> class which
  1196. receives these events and publishes their details to Commons Logging.
  1197. Refer to the JavaDocs for <literal>LoggerListener</literal> for
  1198. details on the logging priorities used for different message
  1199. types.</para>
  1200. <para>This event publishing system enables you to implement account
  1201. locking and record authentication event history. This might be of
  1202. interest to application users, who can be advised of the times and
  1203. source IP address of all unsuccessful password attempts (and account
  1204. lockouts) since their last successful login. Such capabilities are
  1205. simple to implement and greatly improve the security of your
  1206. application.</para>
  1207. </sect2>
  1208. <sect2 id="security-authentication-provider-in-memory">
  1209. <title>In-Memory Authentication</title>
  1210. <para>Whilst it is easy to use the
  1211. <literal>DaoAuthenticationProvider</literal> and create a custom
  1212. <literal>AuthenticationDao</literal> implementation that extracts
  1213. information from a persistence engine of choice, many applications do
  1214. not require such complexity. One alternative is to configure an
  1215. authentication repository in the application context itself using the
  1216. <literal>InMemoryDaoImpl</literal>:</para>
  1217. <para><programlisting>&lt;bean id="inMemoryDaoImpl" class="net.sf.acegisecurity.providers.dao.memory.InMemoryDaoImpl"&gt;
  1218. &lt;property name="userMap"&gt;
  1219. &lt;value&gt;
  1220. marissa=koala,ROLE_TELLER,ROLE_SUPERVISOR
  1221. dianne=emu,ROLE_TELLER
  1222. scott=wombat,ROLE_TELLER
  1223. peter=opal,disabled,ROLE_TELLER
  1224. &lt;/value&gt;
  1225. &lt;/property&gt;
  1226. &lt;/bean&gt;</programlisting></para>
  1227. <para>The <literal>userMap</literal> property contains each of the
  1228. usernames, passwords, a list of granted authorities and an optional
  1229. enabled/disabled keyword. Commas delimit each token. The username must
  1230. appear to the left of the equals sign, and the password must be the
  1231. first token to the right of the equals sign. The
  1232. <literal>enabled</literal> and <literal>disabled</literal> keywords
  1233. (case insensitive) may appear in the second or any subsequent token.
  1234. Any remaining tokens are treated as granted authorities, which are
  1235. created as <literal>GrantedAuthorityImpl</literal> objects (refer to
  1236. the Authorization section for further discussion on granted
  1237. authorities). Note that if a user has no password and/or no granted
  1238. authorities, the user will not be created in the in-memory
  1239. authentication repository.</para>
  1240. </sect2>
  1241. <sect2 id="security-authentication-provider-jdbc">
  1242. <title>JDBC Authentication</title>
  1243. <para>The Acegi Security System for Spring also includes an
  1244. authentication provider that can obtain authentication information
  1245. from a JDBC data source. The typical configuration for the
  1246. <literal>JdbcDaoImpl</literal> is shown below:</para>
  1247. <para><programlisting>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
  1248. &lt;property name="driverClassName"&gt;&lt;value&gt;org.hsqldb.jdbcDriver&lt;/value&gt;&lt;/property&gt;
  1249. &lt;property name="url"&gt;&lt;value&gt;jdbc:hsqldb:hsql://localhost:9001&lt;/value&gt;&lt;/property&gt;
  1250. &lt;property name="username"&gt;&lt;value&gt;sa&lt;/value&gt;&lt;/property&gt;
  1251. &lt;property name="password"&gt;&lt;value&gt;&lt;/value&gt;&lt;/property&gt;
  1252. &lt;/bean&gt;
  1253. &lt;bean id="jdbcDaoImpl" class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl"&gt;
  1254. &lt;property name="dataSource"&gt;&lt;ref bean="dataSource"/&gt;&lt;/property&gt;
  1255. &lt;/bean&gt;</programlisting></para>
  1256. <para>You can use different relational database management systems by
  1257. modifying the <literal>DriverManagerDataSource</literal> shown above.
  1258. Irrespective of the database used, a standard schema must be used as
  1259. indicated in <literal>dbinit.txt</literal>.</para>
  1260. <para>If you default schema is unsuitable for your needs,
  1261. <literal>JdbcDaoImpl</literal> provides two properties that allow
  1262. customisation of the SQL statements. You may also subclass the
  1263. <literal>JdbcDaoImpl</literal> if further customisation is necessary.
  1264. Please refer to the JavaDocs for details.</para>
  1265. <para>The Acegi Security System for Spring ships with a Hypersonic SQL
  1266. instance that has the required authentication information and sample
  1267. data already populated. To use this server, simply execute the
  1268. <literal>server.bat</literal> or <literal>server.sh</literal> script
  1269. included in the distribution. This will load a new database server
  1270. instance that will service requests made to the URL indicated in the
  1271. bean context configuration shown above.</para>
  1272. </sect2>
  1273. <sect2 id="security-authentication-provider-jaas">
  1274. <title>JAAS Authentication</title>
  1275. <para>Acegi Security provides a package able to delegate
  1276. authentication requests to the Java Authentication and Authorization
  1277. Service (JAAS). This package is discussed in detail below.</para>
  1278. <para>Central to JAAS operation are login configuration files. To
  1279. learn more about JAAS login configuration files, consult the JAAS
  1280. reference documentation available from Sun Microsystems. We expect you
  1281. to have a basic understanding of JAAS and its login configuration file
  1282. syntax in order to understand this section.</para>
  1283. <sect3>
  1284. <title>JaasAuthenticationProvider</title>
  1285. <para>The <literal>JaasAuthenticationProvider</literal> attempts to
  1286. authenticate a user’s principal and credentials through JAAS.</para>
  1287. <para>Let’s assume we have a JAAS login configuration file,
  1288. <literal>/WEB-INF/login.conf</literal>, with the following
  1289. contents:</para>
  1290. <para><programlisting>JAASTest {
  1291. sample.SampleLoginModule required;
  1292. };</programlisting></para>
  1293. <para>Like all Acegi Security beans, the
  1294. <literal>JaasAuthenticationProvider</literal> is configured via the
  1295. application context. The following definitions would correspond to
  1296. the above JAAS login configuration file:</para>
  1297. <para><programlisting>&lt;bean id="jaasAuthenticationProvider" class="net.sf.acegisecurity.providers.jaas.JaasAuthenticationProvider"&gt;
  1298. &lt;property name="loginConfig"&gt;
  1299. &lt;value&gt;/WEB-INF/login.conf&lt;/value&gt;
  1300. &lt;/property&gt;
  1301. &lt;property name="loginContextName"&gt;
  1302. &lt;value&gt;JAASTest&lt;/value&gt;
  1303. &lt;/property&gt;
  1304. &lt;property name="callbackHandlers"&gt;
  1305. &lt;list&gt;
  1306. &lt;bean class="net.sf.acegisecurity.providers.jaas.JaasNameCallbackHandler"/&gt;
  1307. &lt;bean class="net.sf.acegisecurity.providers.jaas.JaasPasswordCallbackHandler"/&gt;
  1308. &lt;/list&gt;
  1309. &lt;/property&gt;
  1310. &lt;property name="authorityGranters"&gt;
  1311. &lt;list&gt;
  1312. &lt;bean class="net.sf.acegisecurity.providers.jaas.TestAuthorityGranter"/&gt;
  1313. &lt;/list&gt;
  1314. &lt;/property&gt;
  1315. &lt;/bean&gt;</programlisting></para>
  1316. <para>The <literal>CallbackHandler</literal>s and
  1317. <literal>AuthorityGranter</literal>s are discussed below.</para>
  1318. </sect3>
  1319. <sect3>
  1320. <title>Callbacks</title>
  1321. <para>Most JAAS <literal>LoginModule</literal>s require a callback
  1322. of some sort. These callbacks are usually used to obtain the
  1323. username and password from the user. In an Acegi Security
  1324. deployment, Acegi Security is responsible for this user interaction
  1325. (typically via a reference to a
  1326. <literal>ContextHolder</literal>-managed
  1327. <literal>Authentication</literal> object). The JAAS package for
  1328. Acegi Security provides two default callback handlers,
  1329. <literal>JaasNameCallbackHandler</literal> and
  1330. <literal>JaasPasswordCallbackHandler</literal>. Each of these
  1331. callback handlers implement
  1332. <literal>JaasAuthenticationCallbackHandler</literal>. In most cases
  1333. these callback handlers can simply be used without understanding the
  1334. internal mechanics. For those needing full control over the callback
  1335. behavior, internally <literal>JaasAutheticationProvider</literal>
  1336. wraps these <literal>JaasAuthenticationCallbackHandler</literal>s
  1337. with an <literal>InternalCallbackHandler</literal>. The
  1338. <literal>InternalCallbackHandler</literal> is the class that
  1339. actually implements JAAS’ normal <literal>CallbackHandler</literal>
  1340. interface. Any time that the JAAS <literal>LoginModule</literal> is
  1341. used, it is passed a list of application context configured
  1342. <literal>InternalCallbackHandler</literal>s. If the
  1343. <literal>LoginModule</literal> requests a callback against the
  1344. <literal>InternalCallbackHandler</literal>s, the callback is in-turn
  1345. passed to the <literal>JaasAuthenticationCallbackHandler</literal>s
  1346. being wrapped.</para>
  1347. </sect3>
  1348. <sect3>
  1349. <title>AuthorityGranters</title>
  1350. <para>JAAS works with principals. Even “roles” are represented as
  1351. principals in JAAS. Acegi Security, on the other hand, works with
  1352. <literal>Authentication</literal> objects. Each
  1353. <literal>Authentication</literal> object contains a single
  1354. principal, and multiple <literal>GrantedAuthority</literal>[]s. To
  1355. facilitate mapping between these different concepts, the Acegi
  1356. Security JAAS package includes an
  1357. <literal>AuthorityGranter</literal> interface. An
  1358. <literal>AuthorityGranter</literal> is responsible for inspecting a
  1359. JAAS principal and returning a <literal>String</literal>. The
  1360. <literal>JaasAuthenticationProvider</literal> then creates a
  1361. <literal>JaasGrantedAuthority</literal> (which implements Acegi
  1362. Security’s <literal>GrantedAuthority</literal> interface) containing
  1363. both the <literal>AuthorityGranter</literal>-returned
  1364. <literal>String</literal> and the JAAS principal that the
  1365. <literal>AuthorityGranter</literal> was passed. The
  1366. <literal>JaasAuthenticationProvider</literal> obtains the JAAS
  1367. principals by firstly successfully authenticating the user’s
  1368. credentials using the JAAS <literal>LoginModule</literal>, and then
  1369. accessing the <literal>LoginContext</literal> it returns. A call to
  1370. <literal>LoginContext.getSubject().getPrincipals()</literal> is
  1371. made, with each resulting principal passed to each
  1372. <literal>AuthorityGranter</literal> defined against the
  1373. <literal>JaasAuthenticationProvider.setAuthorityGranters(List)</literal>
  1374. property. Acegi Security does not include any production
  1375. <literal>AuthorityGranter</literal>s given every JAAS principal has
  1376. an implementation-specific meaning. However, there is a
  1377. <literal>TestAuthorityGranter</literal> in the unit tests that
  1378. demonstrates a simple <literal>AuthorityGranter</literal>
  1379. implementation.</para>
  1380. </sect3>
  1381. </sect2>
  1382. <sect2 id="security-authentication-recommendations">
  1383. <title>Authentication Recommendations</title>
  1384. <para>With the heavy use of interfaces throughout the authentication
  1385. system (<literal>Authentication</literal>,
  1386. <literal>AuthenticationManager</literal>,
  1387. <literal>AuthenticationProvider</literal> and
  1388. <literal>AuthenticationDao</literal>) it might be confusing to a new
  1389. user to know which part of the authentication system to customize. In
  1390. general, the following is recommended:</para>
  1391. <itemizedlist>
  1392. <listitem>
  1393. <para>Use the
  1394. <literal>UsernamePasswordAuthenticationToken</literal>
  1395. implementation where possible.</para>
  1396. </listitem>
  1397. <listitem>
  1398. <para>If you simply need to implement a new authentication
  1399. repository (eg to obtain user details from your application’s
  1400. existing database), use the
  1401. <literal>DaoAuthenticationProvider</literal> along with the
  1402. <literal>AuthenticationDao</literal>. It is the fastest and safest
  1403. way to integrate an external database.</para>
  1404. </listitem>
  1405. <listitem>
  1406. <para>If you're using Container Adapters or a
  1407. <literal>RunAsManager</literal> that replaces the
  1408. <literal>Authentication</literal> object, ensure you have
  1409. registered the <literal>AuthByAdapterProvider</literal> and
  1410. <literal>RunAsManagerImplProvider</literal> respectively with your
  1411. <literal>ProviderManager</literal>.</para>
  1412. </listitem>
  1413. <listitem>
  1414. <para>Never enable the
  1415. <literal>TestingAuthenticationProvider</literal> on a production
  1416. system. Doing so will allow any client to simply present a
  1417. <literal>TestingAuthenticationToken</literal> and obtain whatever
  1418. access they request.</para>
  1419. </listitem>
  1420. <listitem>
  1421. <para>Adding a new <literal>AuthenticationProvider</literal> is
  1422. sufficient to support most custom authentication requirements.
  1423. Only unusual requirements would require the
  1424. <literal>ProviderManager</literal> to be replaced with a different
  1425. <literal>AuthenticationManager</literal>.</para>
  1426. </listitem>
  1427. </itemizedlist>
  1428. </sect2>
  1429. </sect1>
  1430. <sect1 id="security-authorization">
  1431. <title>Authorization</title>
  1432. <sect2 id="security-authorization-granted-authorities">
  1433. <title>Granted Authorities</title>
  1434. <para>As briefly mentioned in the Authentication section, all
  1435. <literal>Authentication</literal> implementations are required to
  1436. store an array of <literal>GrantedAuthority</literal> objects. These
  1437. represent the authorities that have been granted to the principal. The
  1438. <literal>GrantedAuthority</literal> objects are inserted into the
  1439. <literal>Authentication</literal> object by the
  1440. <literal>AuthenticationManager</literal> and are later read by
  1441. <literal>AccessDecisionManager</literal>s when making authorization
  1442. decisions.</para>
  1443. <para><literal>GrantedAuthority</literal> is an interface with only
  1444. one method:</para>
  1445. <para><programlisting>public String getAuthority();</programlisting></para>
  1446. <para>This method allows <literal>AccessDecisionManager</literal>s to
  1447. obtain a precise <literal>String</literal> representation of the
  1448. <literal>GrantedAuthority</literal>. By returning a representation as
  1449. a <literal>String</literal>, a <literal>GrantedAuthority</literal> can
  1450. be easily "read" by most <literal>AccessDecisionManager</literal>s. If
  1451. a <literal>GrantedAuthority</literal> cannot be precisely represented
  1452. as a <literal>String</literal>, the
  1453. <literal>GrantedAuthority</literal> is considered "complex" and
  1454. <literal>getAuthority()</literal> must return
  1455. <literal>null</literal>.</para>
  1456. <para>An example of a "complex" <literal>GrantedAuthority</literal>
  1457. would be an implementation that stores a list of operations and
  1458. authority thresholds that apply to different customer account numbers.
  1459. Representing this complex <literal>GrantedAuthority</literal> as a
  1460. <literal>String</literal> would be quite complex, and as a result the
  1461. <literal>getAuthority()</literal> method should return
  1462. <literal>null</literal>. This will indicate to any
  1463. <literal>AccessDecisionManager</literal> that it will need to
  1464. specifically support the <literal>GrantedAuthority</literal>
  1465. implementation in order to understand its contents.</para>
  1466. <para>The Acegi Security System for Spring includes one concrete
  1467. <literal>GrantedAuthority</literal> implementation,
  1468. <literal>GrantedAuthorityImpl</literal>. This allows any
  1469. user-specified <literal>String</literal> to be converted into a
  1470. <literal>GrantedAuthority</literal>. All
  1471. <literal>AuthenticationProvider</literal>s included with the security
  1472. architecture use <literal>GrantedAuthorityImpl</literal> to populate
  1473. the <literal>Authentication</literal> object.</para>
  1474. </sect2>
  1475. <sect2 id="security-authorization-access-decision-managers">
  1476. <title>Access Decision Managers</title>
  1477. <para>The <literal>AccessDecisionManager</literal> is called by the
  1478. <literal>AbstractSecurityInterceptor</literal> and is responsible for
  1479. making final access control decisions. The
  1480. <literal>AccessDecisionManager</literal> interface contains three
  1481. methods:</para>
  1482. <para><programlisting>public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config) throws AccessDeniedException;
  1483. public boolean supports(ConfigAttribute attribute);
  1484. public boolean supports(Class clazz);</programlisting></para>
  1485. <para>As can be seen from the first method, the
  1486. <literal>AccessDecisionManager</literal> is passed via method
  1487. parameters all information that is likely to be of value in assessing
  1488. an authorization decision. In particular, passing the secure
  1489. <literal>Object</literal> enables those arguments contained in the
  1490. actual secure object invocation to be inspected. For example, let's
  1491. assume the secure object was a <literal>MethodInvocation</literal>. It
  1492. would be easy to query the <literal>MethodInvocation</literal> for any
  1493. <literal>Customer</literal> argument, and then implement some sort of
  1494. security logic in the <literal>AccessDecisionManager</literal> to
  1495. ensure the principal is permitted to operate on that customer.
  1496. Implementations are expected to throw an
  1497. <literal>AccessDeniedException</literal> if access is denied.</para>
  1498. <para>The <literal>supports(ConfigAttribute)</literal> method is
  1499. called by the <literal>AbstractSecurityInterceptor</literal> at
  1500. startup time to determine if the
  1501. <literal>AccessDecisionManager</literal> can process the passed
  1502. <literal>ConfigAttribute</literal>. The
  1503. <literal>supports(Class)</literal> method is called by a security
  1504. interceptor implementation to ensure the configured
  1505. <literal>AccessDecisionManager</literal> supports the type of secure
  1506. object that the security interceptor will present.</para>
  1507. </sect2>
  1508. <sect2 id="security-authorization-voting-decision-manager">
  1509. <title>Voting Decision Manager</title>
  1510. <para>Whilst users can implement their own
  1511. <literal>AccessDecisionManager</literal> to control all aspects of
  1512. authorization, the Acegi Security System for Spring includes several
  1513. <literal>AccessDecisionManager</literal> implementations that are
  1514. based on voting. Figure 4 illustrates the relevant classes.</para>
  1515. <para><mediaobject>
  1516. <imageobject role="html">
  1517. <imagedata align="center"
  1518. fileref="images/AccessDecisionVoting.gif"
  1519. format="GIF" />
  1520. </imageobject>
  1521. <caption>
  1522. <para>Figure 4: Voting Decision Manager</para>
  1523. </caption>
  1524. </mediaobject></para>
  1525. <para>Using this approach, a series of
  1526. <literal>AccessDecisionVoter</literal> implementations are polled on
  1527. an authorization decision. The
  1528. <literal>AccessDecisionManager</literal> then decides whether or not
  1529. to throw an <literal>AccessDeniedException</literal> based on its
  1530. assessment of the votes.</para>
  1531. <para>The <literal>AccessDecisionVoter</literal> interface has three
  1532. methods:</para>
  1533. <para><programlisting>public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config);
  1534. public boolean supports(ConfigAttribute attribute);
  1535. public boolean supports(Class clazz);</programlisting></para>
  1536. <para>Concrete implementations return an <literal>int</literal>, with
  1537. possible values being reflected in the
  1538. <literal>AccessDecisionVoter</literal> static fields
  1539. <literal>ACCESS_ABSTAIN</literal>, <literal>ACCESS_DENIED</literal>
  1540. and <literal>ACCESS_GRANTED</literal>. A voting implementation will
  1541. return <literal>ACCESS_ABSTAIN</literal> if it has no opinion on an
  1542. authorization decision. If it does have an opinion, it must return
  1543. either <literal>ACCESS_DENIED</literal> or
  1544. <literal>ACCESS_GRANTED</literal>.</para>
  1545. <para>There are three concrete
  1546. <literal>AccessDecisionManager</literal>s provided with the Acegi
  1547. Security System for Spring that tally the votes. The
  1548. <literal>ConsensusBased</literal> implementation will grant or deny
  1549. access based on the consensus of non-abstain votes. Properties are
  1550. provided to control behavior in the event of an equality of votes or
  1551. if all votes are abstain. The <literal>AffirmativeBased</literal>
  1552. implementation will grant access if one or more
  1553. <literal>ACCESS_GRANTED</literal> votes were received (ie a deny vote
  1554. will be ignored, provided there was at least one grant vote). Like the
  1555. <literal>ConsensusBased</literal> implementation, there is a parameter
  1556. that controls the behavior if all voters abstain. The
  1557. <literal>UnanimousBased</literal> provider expects unanimous
  1558. <literal>ACCESS_GRANTED</literal> votes in order to grant access,
  1559. ignoring abstains. It will deny access if there is any
  1560. <literal>ACCESS_DENIED</literal> vote. Like the other implementations,
  1561. there is a parameter that controls the behaviour if all voters
  1562. abstain.</para>
  1563. <para>It is possible to implement a custom
  1564. <literal>AccessDecisionManager</literal> that tallies votes
  1565. differently. For example, votes from a particular
  1566. <literal>AccessDecisionVoter</literal> might receive additional
  1567. weighting, whilst a deny vote from a particular voter may have a veto
  1568. effect.</para>
  1569. <para>There are two concrete <literal>AccessDecisionVoter</literal>
  1570. implementations provided with the Acegi Security System for Spring.
  1571. The <literal>RoleVoter</literal> class will vote if any
  1572. ConfigAttribute begins with <literal>ROLE_</literal>. It will vote to
  1573. grant access if there is a <literal>GrantedAuthority</literal> which
  1574. returns a <literal>String</literal> representation (via the
  1575. <literal>getAuthority()</literal> method) exactly equal to one or more
  1576. <literal>ConfigAttributes</literal> starting with
  1577. <literal>ROLE_</literal>. If there is no exact match of any
  1578. <literal>ConfigAttribute</literal> starting with
  1579. <literal>ROLE_</literal>, the <literal>RoleVoter</literal> will vote
  1580. to deny access. If no <literal>ConfigAttribute</literal> begins with
  1581. <literal>ROLE_</literal>, the voter will abstain.
  1582. <literal>RoleVoter</literal> is case sensitive on comparisons as well
  1583. as the <literal>ROLE_</literal> prefix.</para>
  1584. <para>BasicAclEntryVoter is the other concrete voter included with
  1585. Acegi Security. It integrates with Acegi Security's
  1586. <literal>AclManager</literal> (discussed later). This voter is
  1587. designed to have multiple instances in the same application context,
  1588. such as:</para>
  1589. <para><programlisting>&lt;bean id="aclContactReadVoter" class="net.sf.acegisecurity.vote.BasicAclEntryVoter"&gt;
  1590. &lt;property name="processConfigAttribute"&gt;&lt;value&gt;ACL_CONTACT_READ&lt;/value&gt;&lt;/property&gt;
  1591. &lt;property name="processDomainObjectClass"&gt;&lt;value&gt;sample.contact.Contact&lt;/value&gt;&lt;/property&gt;
  1592. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  1593. &lt;property name="requirePermission"&gt;
  1594. &lt;list&gt;
  1595. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  1596. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  1597. &lt;/list&gt;
  1598. &lt;/property&gt;
  1599. &lt;/bean&gt;
  1600. &lt;bean id="aclContactDeleteVoter" class="net.sf.acegisecurity.vote.BasicAclEntryVoter"&gt;
  1601. &lt;property name="processConfigAttribute"&gt;&lt;value&gt;ACL_CONTACT_DELETE&lt;/value&gt;&lt;/property&gt;
  1602. &lt;property name="processDomainObjectClass"&gt;&lt;value&gt;sample.contact.Contact&lt;/value&gt;&lt;/property&gt;
  1603. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  1604. &lt;property name="requirePermission"&gt;
  1605. &lt;list&gt;
  1606. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  1607. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.DELETE"/&gt;
  1608. &lt;/list&gt;
  1609. &lt;/property&gt;
  1610. &lt;/bean&gt;</programlisting></para>
  1611. <para>In the above example, you'd define
  1612. <literal>ACL_CONTACT_READ</literal> or
  1613. <literal>ACL_CONTACT_DELETE</literal> against some methods on a
  1614. <literal>MethodSecurityInterceptor</literal> or
  1615. <literal>AspectJSecurityInterceptor</literal>. When those methods are
  1616. invoked, the above applicable voter defined above would vote to grant
  1617. or deny access. The voter would look at the method invocation to
  1618. locate the first argument of type
  1619. <literal>sample.contact.Contact</literal>, and then pass that
  1620. <literal>Contact</literal> to the <literal>AclManager</literal>. The
  1621. <literal>AclManager</literal> will then return an access control list
  1622. (ACL) that applies to the current <literal>Authentication</literal>.
  1623. Assuming that ACL contains one of the listed
  1624. <literal>requirePermission</literal>s, the voter will vote to grant
  1625. access. If the ACL does not contain one of the permissions defined
  1626. against the voter, the voter will vote to deny access.
  1627. <literal>BasicAclEntryVoter</literal> is an important class as it
  1628. allows you to build truly complex applications with domain object
  1629. security entirely defined in the application context. If you're
  1630. interested in learning more about Acegi Security's ACL capabilities
  1631. and how best to apply them, please see the ACL and "After Invocation"
  1632. sections of this reference guide, and the Contacts sample
  1633. application.</para>
  1634. <para>It is also possible to implement a custom
  1635. <literal>AccessDecisionVoter</literal>. Several examples are provided
  1636. in the Acegi Security System for Spring unit tests, including
  1637. <literal>ContactSecurityVoter</literal> and
  1638. <literal>DenyVoter</literal>. The
  1639. <literal>ContactSecurityVoter</literal> abstains from voting decisions
  1640. where a <literal>CONTACT_OWNED_BY_CURRENT_USER</literal>
  1641. <literal>ConfigAttribute</literal> is not found. If voting, it queries
  1642. the <literal>MethodInvocation</literal> to extract the owner of the
  1643. <literal>Contact</literal> object that is subject of the method call.
  1644. It votes to grant access if the <literal>Contact</literal> owner
  1645. matches the principal presented in the
  1646. <literal>Authentication</literal> object. It could have just as easily
  1647. compared the <literal>Contact</literal> owner with some
  1648. <literal>GrantedAuthority</literal> the
  1649. <literal>Authentication</literal> object presented. All of this is
  1650. achieved with relatively few lines of code and demonstrates the
  1651. flexibility of the authorization model.</para>
  1652. </sect2>
  1653. <sect2 id="security-authorization-taglib">
  1654. <title>Authorization-Related Tag Libraries</title>
  1655. <para>The Acegi Security System for Spring comes bundled with several
  1656. JSP tag libraries that eases JSP writing. The tag libraries are known
  1657. as <literal>authz</literal> and provide a range of different
  1658. services.</para>
  1659. <para>All taglib classes are included in the core
  1660. <literal>acegi-security-xx.jar</literal> file, with the
  1661. <literal>authz.tld</literal> located in the JAR's
  1662. <literal>META-INF</literal> directory. This means for JSP 1.2+ web
  1663. containers you can simply include the JAR in the WAR's
  1664. <literal>WEB-INF/lib</literal> directory and it will be available. If
  1665. you're using a JSP 1.1 container, you'll need to declare the JSP
  1666. taglib in your <literal>web.xml file</literal>, and include
  1667. <literal>authz.tld</literal> in the <literal>WEB-INF/lib</literal>
  1668. directory. The following fragment is added to
  1669. <literal>web.xml</literal>:</para>
  1670. <para><programlisting>&lt;taglib&gt;
  1671. &lt;taglib-uri&gt;http://acegisecurity.sf.net/authz&lt;/taglib-uri&gt;
  1672. &lt;taglib-location&gt;/WEB-INF/authz.tld&lt;/taglib-location&gt;
  1673. &lt;/taglib&gt;</programlisting></para>
  1674. <sect3>
  1675. <title>AuthorizeTag</title>
  1676. <para><literal>AuthorizeTag</literal> is used to include content if
  1677. the current principal holds certain
  1678. <literal>GrantedAuthority</literal>s.</para>
  1679. <para>The following JSP fragment illustrates how to use the
  1680. <literal>AuthorizeTag</literal>:</para>
  1681. <para><programlisting>&lt;authz:authorize ifAllGranted="ROLE_SUPERVISOR"&gt;
  1682. &lt;td&gt;
  1683. &lt;A HREF="del.htm?id=&lt;c:out value="${contact.id}"/&gt;"&gt;Del&lt;/A&gt;
  1684. &lt;/td&gt;
  1685. &lt;/authz:authorize&gt;</programlisting></para>
  1686. <para>This tag would cause the tag's body to be output if the
  1687. principal has been granted ROLE_SUPERVISOR.</para>
  1688. <para>The <literal>authz:authorize</literal> tag declares the
  1689. following attributes:</para>
  1690. <para><itemizedlist spacing="compact">
  1691. <listitem>
  1692. <para><literal>ifAllGranted</literal>: All the listed roles
  1693. must be granted for the tag to output its body.</para>
  1694. </listitem>
  1695. <listitem>
  1696. <para><literal>ifAnyGranted</literal>: Any of the listed roles
  1697. must be granted for the tag to output its body.</para>
  1698. </listitem>
  1699. <listitem>
  1700. <para><literal>ifNotGranted</literal>: None of the listed
  1701. roles must be granted for the tag to output its body.</para>
  1702. </listitem>
  1703. </itemizedlist></para>
  1704. <para>You'll note that in each attribute you can list multiple
  1705. roles. Simply separate the roles using a comma. The
  1706. <literal>authorize</literal> tag ignores whitespace in
  1707. attributes.</para>
  1708. <para>The tag library logically ANDs all of it's parameters
  1709. together. This means that if you combine two or more attributes, all
  1710. attributes must be true for the tag to output it's body. Don't add
  1711. an <literal>ifAllGranted="ROLE_SUPERVISOR"</literal>, followed by an
  1712. <literal>ifNotGranted="ROLE_SUPERVISOR"</literal>, or you'll be
  1713. surprised to never see the tag's body.</para>
  1714. <para>By requiring all attributes to return true, the authorize tag
  1715. allows you to create more complex authorization scenarios. For
  1716. example, you could declare an
  1717. <literal>ifAllGranted="ROLE_SUPERVISOR"</literal> and an
  1718. <literal>ifNotGranted="ROLE_NEWBIE_SUPERVISOR"</literal> in the same
  1719. tag, in order to prevent new supervisors from seeing the tag body.
  1720. However it would no doubt be simpler to use
  1721. <literal>ifAllGranted="ROLE_EXPERIENCED_SUPERVISOR"</literal> rather
  1722. than inserting NOT conditions into your design.</para>
  1723. <para>One last item: the tag verifies the authorizations in a
  1724. specific order: first <literal>ifNotGranted</literal>, then
  1725. <literal>ifAllGranted</literal>, and finally,
  1726. <literal>ifAnyGranted</literal>.</para>
  1727. </sect3>
  1728. <sect3>
  1729. <title>AuthenticationTag</title>
  1730. <para><literal>AuthenticationTag</literal> is used to simply output
  1731. the current principal to the web page.</para>
  1732. <para>The following JSP fragment illustrates how to use the
  1733. <literal>AuthenticationTag</literal>:</para>
  1734. <para><programlisting>&lt;authz:authentication operation="principal"/&gt;</programlisting></para>
  1735. <para>This tag would cause the principal's name to be output. The
  1736. taglib properly supports the various types of principals that can
  1737. exist in the <literal>Authentication</literal> object, such as a
  1738. <literal>String</literal> or <literal>UserDetails</literal>
  1739. instance.</para>
  1740. <para>The "operation" attribute must always be "principal". This may
  1741. be expanded in the future, such as obtaining other
  1742. <literal>Authentication</literal>-related properties such as email
  1743. address or telephone numbers.</para>
  1744. </sect3>
  1745. <sect3>
  1746. <title>AclTag</title>
  1747. <para><literal>AclTag</literal> is used to include content if the
  1748. current principal has a ACL to the indicated domain object.</para>
  1749. <para>The following JSP fragment illustrates how to use the
  1750. <literal>AclTag</literal>:</para>
  1751. <para><programlisting>&lt;authz:acl domainObject="${contact}" hasPermission="16,1"&gt;
  1752. &lt;td&gt;&lt;A HREF="&lt;c:url value="del.htm"&gt;&lt;c:param name="contactId" value="${contact.id}"/&gt;&lt;/c:url&gt;"&gt;Del&lt;/A&gt;&lt;/td&gt;
  1753. &lt;/authz:acl&gt;</programlisting></para>
  1754. <para>This tag would cause the tag's body to be output if the
  1755. principal holds either permission 16 or permission 1 for the
  1756. "contact" domain object. The numbers are actually integers that are
  1757. used with <literal>AbstractBasicAclEntry</literal> bit masking.
  1758. Please refer tro the ACL section of this reference guide to
  1759. understand more about the ACL capabilities of Acegi Security.</para>
  1760. </sect3>
  1761. </sect2>
  1762. <sect2 id="security-authorization-recommendations">
  1763. <title>Authorization Recommendations</title>
  1764. <para>Given there are several ways to achieve similar authorization
  1765. outcomes in the Acegi Security System for Spring, the following
  1766. general recommendations are made:</para>
  1767. <itemizedlist>
  1768. <listitem>
  1769. <para>Grant authorities using
  1770. <literal>GrantedAuthorityImpl</literal> where possible. Because it
  1771. is already supported by the Acegi Security System for Spring, you
  1772. avoid the need to create custom
  1773. <literal>AuthenticationManager</literal> or
  1774. <literal>AuthenticationProvider</literal> implementations simply
  1775. to populate the <literal>Authentication</literal> object with a
  1776. custom <literal>GrantedAuthority</literal>.</para>
  1777. </listitem>
  1778. <listitem>
  1779. <para>Writing an <literal>AccessDecisionVoter</literal>
  1780. implementation and using either <literal>ConsensusBased</literal>,
  1781. <literal>AffirmativeBased</literal> or
  1782. <literal>UnanimousBased</literal> as the
  1783. <literal>AccessDecisionManager</literal> may be the best approach
  1784. to implementing your custom access decision rules.</para>
  1785. </listitem>
  1786. </itemizedlist>
  1787. </sect2>
  1788. </sect1>
  1789. <sect1 id="afterinvocation">
  1790. <title>After Invocation Handling</title>
  1791. <sect2 id="afterinvocation-overview">
  1792. <title>Overview</title>
  1793. <para>Whilst the <literal>AccessDecisionManager</literal> is called by
  1794. the <literal>AbstractSecurityInterceptor</literal> before proceeding
  1795. with the secure object invocation, some applications need a way of
  1796. modifying the object actually returned by the secure object
  1797. invocation. Whilst you could easily implement your own AOP concern to
  1798. achieve this, Acegi Security provides a convenient hook that has
  1799. several concrete implementations that integrate with its ACL
  1800. capabilities.</para>
  1801. <para>Figure 5 illustrates Acegi Security's
  1802. <literal>AfterInvocationManager</literal> and its concrete
  1803. implementations.</para>
  1804. <para><mediaobject>
  1805. <imageobject role="html">
  1806. <imagedata align="center" fileref="images/AfterInvocation.gif"
  1807. format="GIF" />
  1808. </imageobject>
  1809. <caption>
  1810. <para>Figure 5: After Invocation Implementation</para>
  1811. </caption>
  1812. </mediaobject></para>
  1813. <para>Like many other parts of Acegi Security,
  1814. <literal>AfterInvocationManager</literal> has a single concrete
  1815. implementation, <literal>AfterInvocationProvider</literal>, which
  1816. polls a list of <literal>AfterInvocationProvider</literal>s. Each
  1817. <literal>AfterInvocationProvider</literal> is allowed to modify the
  1818. return object or throw an <literal>AccessDeniedException</literal>.
  1819. Indeed multiple providers can modify the object, as the result of the
  1820. previous provider is passed to the next in the list. Let's now
  1821. consider our ACL-aware implementations of
  1822. <literal>AfterInvocationProvider</literal>.</para>
  1823. </sect2>
  1824. <sect2 id="afterinvocation-acl-aware">
  1825. <title>ACL-Aware AfterInvocationProviders</title>
  1826. <para>A common services layer method we've all written at one stage or
  1827. another looks like this:</para>
  1828. <para><programlisting>public Contact getById(Integer id);</programlisting></para>
  1829. <para>Quite often, only principals with permission to read the
  1830. <literal>Contact</literal> should be allowed to obtain it. In this
  1831. situation the <literal>AccessDecisionManager</literal> approach
  1832. provided by the <literal>AbstractSecurityInterceptor</literal> will
  1833. not suffice. This is because the identity of the
  1834. <literal>Contact</literal> is all that is available before the secure
  1835. object is invoked. The
  1836. <literal>BasicAclAfterInvocationProvider</literal> delivers a
  1837. solution, and is configured as follows:</para>
  1838. <para><programlisting>&lt;bean id="afterAclRead" class="net.sf.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationProvider"&gt;
  1839. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  1840. &lt;property name="requirePermission"&gt;
  1841. &lt;list&gt;
  1842. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  1843. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  1844. &lt;/list&gt;
  1845. &lt;/property&gt;
  1846. &lt;/bean&gt;</programlisting></para>
  1847. <para>In the above example, the <literal>Contact</literal> will be
  1848. retrieved and passed to the
  1849. <literal>BasicAclEntryAfterInvocationProvider</literal>. The provider
  1850. will thrown an <literal>AccessDeniedException</literal> if one of the
  1851. listed <literal>requirePermission</literal>s is not held by the
  1852. <literal>Authentication</literal>. The
  1853. <literal>BasicAclEntryAfterInvocationProvider</literal> queries the
  1854. <literal>AclManager</literal> to determine the ACL that applies for
  1855. this domain object to this <literal>Authentication</literal>.</para>
  1856. <para>Similar to the
  1857. <literal>BasicAclEntryAfterInvocationProvider</literal> is
  1858. <literal>BasicAclEntryAfterInvocationCollectionFilteringProvider</literal>.
  1859. It is designed to remove <literal>Collection</literal> or array
  1860. elements for which a principal does not have access. It never thrown
  1861. an <literal>AccessDeniedException</literal> - simply silently removes
  1862. the offending elements. The provider is configured as follows:</para>
  1863. <para><programlisting>&lt;bean id="afterAclCollectionRead" class="net.sf.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationCollectionFilteringProvider"&gt;
  1864. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  1865. &lt;property name="requirePermission"&gt;
  1866. &lt;list&gt;
  1867. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  1868. &lt;ref local="net.sf.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  1869. &lt;/list&gt;
  1870. &lt;/property&gt;
  1871. &lt;/bean&gt;</programlisting></para>
  1872. <para>As you can imagine, the returned <literal>Object</literal> must
  1873. be a <literal>Collection</literal> or array for this provider to
  1874. operate. It will remove any element if the
  1875. <literal>AclManager</literal> indicates the
  1876. <literal>Authentication</literal> does not hold one of the listed
  1877. <literal>requirePermission</literal>s.</para>
  1878. <para>The Contacts sample application demonstrates these two
  1879. <literal>AfterInvocationProvider</literal>s.</para>
  1880. </sect2>
  1881. </sect1>
  1882. <sect1 id="security-run-as">
  1883. <title>Run-As Authentication Replacement</title>
  1884. <sect2 id="security-run-as-purpose">
  1885. <title>Purpose</title>
  1886. <para>The <literal>AbstractSecurityInterceptor</literal> is able to
  1887. temporarily replace the <literal>Authentication</literal> object in
  1888. the <literal>SecureContext</literal> and
  1889. <literal>ContextHolder</literal> during the
  1890. <literal>SecurityInterceptorCallback</literal>. This only occurs if
  1891. the original <literal>Authentication</literal> object was successfully
  1892. processed by the <literal>AuthenticationManager</literal> and
  1893. <literal>AccessDecisionManager</literal>. The
  1894. <literal>RunAsManager</literal> will indicate the replacement
  1895. <literal>Authentication</literal> object, if any, that should be used
  1896. during the <literal>SecurityInterceptorCallback</literal>.</para>
  1897. <para>By temporarily replacing the <literal>Authentication</literal>
  1898. object during a <literal>SecurityInterceptorCallback</literal>, the
  1899. secured invocation will be able to call other objects which require
  1900. different authentication and authorization credentials. It will also
  1901. be able to perform any internal security checks for specific
  1902. <literal>GrantedAuthority</literal> objects. Because Acegi Security
  1903. provides a number of helper classes that automatically configure
  1904. remoting protocols based on the contents of the
  1905. <literal>ContextHolder</literal>, these run-as replacements are
  1906. particularly useful when calling remote web services.</para>
  1907. </sect2>
  1908. <sect2 id="security-run-as-usage">
  1909. <title>Usage</title>
  1910. <para>A <literal>RunAsManager</literal> interface is provided by the
  1911. Acegi Security System for Spring:</para>
  1912. <para><programlisting>public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config);
  1913. public boolean supports(ConfigAttribute attribute);
  1914. public boolean supports(Class clazz);</programlisting></para>
  1915. <para>The first method returns the <literal>Authentication</literal>
  1916. object that should replace the existing
  1917. <literal>Authentication</literal> object for the duration of the
  1918. method invocation. If the method returns <literal>null</literal>, it
  1919. indicates no replacement should be made. The second method is used by
  1920. the <literal>AbstractSecurityInterceptor</literal> as part of its
  1921. startup validation of configuration attributes. The
  1922. <literal>supports(Class)</literal> method is called by a security
  1923. interceptor implementation to ensure the configured
  1924. <literal>RunAsManager</literal> supports the type of secure object
  1925. that the security interceptor will present.</para>
  1926. <para>One concrete implementation of a <literal>RunAsManager</literal>
  1927. is provided with the Acegi Security System for Spring. The
  1928. <literal>RunAsManagerImpl</literal> class returns a replacement
  1929. <literal>RunAsUserToken</literal> if any
  1930. <literal>ConfigAttribute</literal> starts with
  1931. <literal>RUN_AS_</literal>. If any such
  1932. <literal>ConfigAttribute</literal> is found, the replacement
  1933. <literal>RunAsUserToken</literal> will contain the same principal,
  1934. credentials and granted authorities as the original
  1935. <literal>Authentication</literal> object, along with a new
  1936. <literal>GrantedAuthorityImpl</literal> for each
  1937. <literal>RUN_AS_</literal> <literal>ConfigAttribute</literal>. Each
  1938. new <literal>GrantedAuthorityImpl</literal> will be prefixed with
  1939. <literal>ROLE_</literal>, followed by the <literal>RUN_AS</literal>
  1940. <literal>ConfigAttribute</literal>. For example, a
  1941. <literal>RUN_AS_SERVER</literal> will result in the replacement
  1942. <literal>RunAsUserToken</literal> containing a
  1943. <literal>ROLE_RUN_AS_SERVER</literal> granted authority.</para>
  1944. <para>The replacement <literal>RunAsUserToken</literal> is just like
  1945. any other <literal>Authentication</literal> object. It needs to be
  1946. authenticated by the <literal>AuthenticationManager</literal>,
  1947. probably via delegation to a suitable
  1948. <literal>AuthenticationProvider</literal>. The
  1949. <literal>RunAsImplAuthenticationProvider</literal> performs such
  1950. authentication. It simply accepts as valid any
  1951. <literal>RunAsUserToken</literal> presented.</para>
  1952. <para>To ensure malicious code does not create a
  1953. <literal>RunAsUserToken</literal> and present it for guaranteed
  1954. acceptance by the <literal>RunAsImplAuthenticationProvider</literal>,
  1955. the hash of a key is stored in all generated tokens. The
  1956. <literal>RunAsManagerImpl</literal> and
  1957. <literal>RunAsImplAuthenticationProvider</literal> is created in the
  1958. bean context with the same key:</para>
  1959. <para><programlisting>&lt;bean id="runAsManager" class="net.sf.acegisecurity.runas.RunAsManagerImpl"&gt;
  1960. &lt;property name="key"&gt;&lt;value&gt;my_run_as_password&lt;/value&gt;&lt;/property&gt;
  1961. &lt;/bean&gt;</programlisting><programlisting>&lt;bean id="runAsAuthenticationProvider" class="net.sf.acegisecurity.runas.RunAsImplAuthenticationProvider"&gt;
  1962. &lt;property name="key"&gt;&lt;value&gt;my_run_as_password&lt;/value&gt;&lt;/property&gt;
  1963. &lt;/bean&gt;</programlisting></para>
  1964. <para>By using the same key, each <literal>RunAsUserToken</literal>
  1965. can be validated it was created by an approved
  1966. <literal>RunAsManagerImpl</literal>. The
  1967. <literal>RunAsUserToken</literal> is immutable after creation for
  1968. security reasons.</para>
  1969. </sect2>
  1970. </sect1>
  1971. <sect1 id="security-ui">
  1972. <title>User Interfacing with the ContextHolder</title>
  1973. <sect2 id="security-ui-purpose">
  1974. <title>Purpose</title>
  1975. <para>Everything presented so far assumes one thing: the
  1976. <literal>ContextHolder</literal> is populated with a valid
  1977. <literal>SecureContext</literal>, which in turn contains a valid
  1978. <literal>Authentication</literal> object. Developers are free to do
  1979. this in whichever way they like, such as directly calling the relevant
  1980. objects at runtime. However, several classes have been provided to
  1981. make this process transparent in many situations. We call these
  1982. classes "authentication mechanisms".</para>
  1983. <para>The <literal>net.sf.acegisecurity.ui</literal> package provides
  1984. what we call "authentication processing mechanisms". An authentication
  1985. processing mechanism is solely concerned with received an
  1986. authentication request from the principal, testing if it seems valid,
  1987. and if so, placing the authentication request token onto the
  1988. ContextHolder. Of course, if the authentication request is invalid,
  1989. the authentication processing mechanism is responsible for informing
  1990. the principal in whatever way is appropriate to the protocol.</para>
  1991. <para>Recall the HttpSessionContextIntegrationFilter (discussed in the
  1992. context section) is responsible for storing the ContextHolder contents
  1993. between invocations. This means no authentication processing mechanism
  1994. need ever interact directly with HttpSession. Indeed
  1995. HttpSessionContextIntegrationFilter has been designed to minimise the
  1996. unnecessary creation of HttpSessions, as might occur when using Basic
  1997. authentication for example.</para>
  1998. <para>There are several authentication processing mechanisms included
  1999. with Acegi Security, which will be briefly discussed in this chapter.
  2000. The most popular (and almost always recommended) approach is HTTP Form
  2001. Authentication, which uses a login form to authenticate the user.
  2002. Another approach (commonly use with web services) is HTTP Basic
  2003. Authentication, which allows clients to use HTTP headers to present
  2004. authentication information to the Acegi Security System for Spring.
  2005. Alternatively, you can also use Yale Central Authentication Service
  2006. (CAS) for enterprise-wide single sign on. The final (and generally
  2007. unrecommended) approach is via Container Adapters, which allow
  2008. supported web containers to perform the authentication themselves.
  2009. HTTP Form Authentication and Basic Authentication is discussed below,
  2010. whilst CAS and Container Adapters are discussed in separate sections
  2011. of this document.</para>
  2012. </sect2>
  2013. <sect2 id="security-ui-http-form">
  2014. <title>HTTP Form Authentication</title>
  2015. <para>HTTP Form Authentication involves using the
  2016. <literal>AuthenticationProcessingFilter</literal> to process a login
  2017. form. The login form simply contains <literal>j_username</literal> and
  2018. <literal>j_password</literal> input fields, and posts to a URL that is
  2019. monitored by the filter (by default
  2020. <literal>j_acegi_security_check</literal>). The filter is defined in
  2021. <literal>web.xml</literal> behind a
  2022. <literal>FilterToBeanProxy</literal> as follows:</para>
  2023. <para><programlisting>&lt;filter&gt;
  2024. &lt;filter-name&gt;Acegi Authentication Processing Filter&lt;/filter-name&gt;
  2025. &lt;filter-class&gt;net.sf.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  2026. &lt;init-param&gt;
  2027. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  2028. &lt;param-value&gt;net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter&lt;/param-value&gt;
  2029. &lt;/init-param&gt;
  2030. &lt;/filter&gt;
  2031. &lt;filter-mapping&gt;
  2032. &lt;filter-name&gt;Acegi Authentication Processing Filter&lt;/filter-name&gt;
  2033. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  2034. &lt;/filter-mapping&gt;</programlisting></para>
  2035. <para>For a discussion of <literal>FilterToBeanProxy</literal>, please
  2036. refer to the Filters section. The application context will need to
  2037. define the <literal>AuthenticationProcessingFilter</literal>:</para>
  2038. <para><programlisting>&lt;bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter"&gt;
  2039. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2040. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/acegilogin.jsp?login_error=1&lt;/value&gt;&lt;/property&gt;
  2041. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;
  2042. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_security_check&lt;/value&gt;&lt;/property&gt;
  2043. &lt;/bean&gt;</programlisting></para>
  2044. <para>The configured <literal>AuthenticationManager</literal>
  2045. processes each authentication request. If authentication fails, the
  2046. browser will be redirected to the
  2047. <literal>authenticationFailureUrl</literal>. The
  2048. <literal>AuthenticationException</literal> will be placed into the
  2049. <literal>HttpSession</literal> attribute indicated by
  2050. <literal>AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY</literal>,
  2051. enabling a reason to be provided to the user on the error page.</para>
  2052. <para>If authentication is successful, the resulting
  2053. <literal>Authentication</literal> object will be placed into the
  2054. <literal>ContextHolder</literal>.</para>
  2055. <para>Once the <literal>ContextHolder</literal> has been updated, the
  2056. browser will need to be redirected to the target URL. The target URL
  2057. is usually indicated by the <literal>HttpSession</literal> attribute
  2058. specified by
  2059. <literal>AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL_KEY</literal>.
  2060. This attribute is automatically set by the
  2061. <literal>SecurityEnforcementFilter</literal> when an
  2062. <literal>AuthenticationException</literal> occurs, so that after login
  2063. is completed the user can return to what they were trying to access.
  2064. If for some reason the <literal>HttpSession</literal> does not
  2065. indicate the target URL, the browser will be redirected to the
  2066. <literal>defaultTargetUrl</literal> property.</para>
  2067. <para>Because this authentication approach is fully contained within a
  2068. single web application, HTTP Form Authentication is recommended to be
  2069. used instead of Container Adapters.</para>
  2070. </sect2>
  2071. <sect2 id="security-ui-http-basic">
  2072. <title>HTTP Basic Authentication</title>
  2073. <para>The Acegi Security System for Spring provides a
  2074. <literal>BasicProcessingFilter</literal> which is capable of
  2075. processing basic authentication credentials presented in HTTP headers.
  2076. This can be used for authenticating calls made by Spring remoting
  2077. protocols (such as Hessian and Burlap), as well as normal user agents
  2078. (such as Internet Explorer and Navigator). The standard governing HTTP
  2079. Basic Authentication is defined by RFC 1945, Section 11, and the
  2080. <literal>BasicProcessingFilter</literal> conforms with this RFC. Basic
  2081. Authentication is an attractive approach to authentication, because it
  2082. is very widely deployed in user agents and implementation is extremely
  2083. simple (it's just a Base64 encoding of the username:password,
  2084. specified in a HTTP header).</para>
  2085. <para>To implement HTTP Basic Authentication, it is necessary to
  2086. define <literal>BasicProcessingFilter</literal> in the fitler chain.
  2087. The application context will need to define the
  2088. <literal>BasicProcessingFilter</literal> and its required
  2089. collaborator:</para>
  2090. <para><programlisting>&lt;bean id="basicProcessingFilter" class="net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter"&gt;
  2091. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2092. &lt;property name="authenticationEntryPoint"&gt;&lt;ref bean="authenticationEntryPoint"/&gt;&lt;/property&gt;
  2093. &lt;/bean&gt;
  2094. &lt;bean id="authenticationEntryPoint" class="net.sf.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint"&gt;
  2095. &lt;property name="realmName"&gt;&lt;value&gt;Name Of Your Realm&lt;/value&gt;&lt;/property&gt;
  2096. &lt;/bean&gt;</programlisting></para>
  2097. <para>The configured <literal>AuthenticationManager</literal>
  2098. processes each authentication request. If authentication fails, the
  2099. configured <literal>AuthenticationEntryPoint</literal> will be used to
  2100. retry the authentication process. Usually you will use the
  2101. <literal>BasicProcessingFilterEntryPoint</literal>, which returns a
  2102. 401 response with a suitable header to retry HTTP Basic
  2103. authentication. If authentication is successful, the resulting
  2104. <literal>Authentication</literal> object will be placed into the
  2105. <literal>ContextHolder</literal>.</para>
  2106. <para>If the authentication event was successful, or authentication
  2107. was not attempted because the HTTP header did not contain a supported
  2108. authentication request, the filter chain will continue as normal. The
  2109. only time the filter chain will be interrupted is if authentication
  2110. fails and the <literal>AuthenticationEntryPoint</literal> is called,
  2111. as discussed in the previous paragraph.</para>
  2112. </sect2>
  2113. <sect2 id="security-ui-http-digest">
  2114. <title>HTTP Digest Authentication</title>
  2115. <para>The Acegi Security System for Spring provides a
  2116. <literal>DigestProcessingFilter</literal> which is capable of
  2117. processing digest authentication credentials presented in HTTP
  2118. headers. Digest Authentication attempts to solve many of the
  2119. weakenesses of Basic authentication, specifically by ensuring
  2120. credentials are never sent in clear text across the wire. Many user
  2121. agents support Digest Authentication, including FireFox and Internet
  2122. Explorer. The standard governing HTTP Digest Authentication is defined
  2123. by RFC 2617, which updates an earlier version of the Digest
  2124. Authentication standard prescribed by RFC 2069. Most user agents
  2125. implement RFC 2617. The Acegi Security
  2126. <literal>DigestProcessingFilter</literal> is compatible with the
  2127. "<literal>auth</literal>" quality of protection
  2128. (<literal>qop</literal>) prescribed by RFC 2617, which also provides
  2129. backward compatibility with RFC 2069. Digest Authentication is a
  2130. highly attractive option if you need to use unencrypted HTTP (ie no
  2131. TLS/HTTPS) and wish to maximise security of the authentication
  2132. process. Indeed Digest Authentication is a mandatory requirement for
  2133. the WebDAV protocol, as noted by RFC 2518 Section 17.1, so we should
  2134. expect to see it increasingly deployed and replacing Basic
  2135. Authentication.</para>
  2136. <para>Digest Authentication is definitely the most secure choice
  2137. between Form Authentication, Basic Authentication and Digest
  2138. Authentication, although extra security also means more complex user
  2139. agent implementations. Central to Digest Authentication is a "nonce".
  2140. This is a value the server generates. Acegi Security's nonce adopts
  2141. the following format:</para>
  2142. <para><programlisting>base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
  2143. expirationTime: The date and time when the nonce expires, expressed in milliseconds
  2144. key: A private key to prevent modification of the nonce token
  2145. </programlisting></para>
  2146. <para>The <literal>DigestProcessingFilterEntryPoint</literal> has a
  2147. property specifying the <literal>key</literal> used for generating the
  2148. nonce tokens, along with a <literal>nonceValiditySeconds</literal>
  2149. property for determining the expiration time (default 300, which
  2150. equals five minutes). Whilstever the nonce is valid, the digest is
  2151. computed by concatenating various strings including the username,
  2152. password, nonce, URI being requested, a client-generated nonce (merely
  2153. a random value which the user agent generates each request), the realm
  2154. name etc, then performing an MD5 hash. Both the server and user agent
  2155. perform this digest computation, resulting in different hash codes if
  2156. they disagree on an included value (eg password). In the Acegi
  2157. Security implementation, if the server-generated nonce has merely
  2158. expired (but the digest was otherwise valid), the
  2159. <literal>DigestProcessingFilterEntryPoint</literal> will send a
  2160. <literal>"stale=true"</literal> header. This tells the user agent
  2161. there is no need to disturb the user (as the password and username etc
  2162. is correct), but simply to try again using a new nonce.</para>
  2163. <para>An appropriate value for
  2164. <literal>DigestProcessingFilterEntryPoint</literal>'s
  2165. <literal>nonceValiditySeconds</literal> parameter will depend on your
  2166. application. Extremely secure applications should note that an
  2167. intercepted authentication header can be used to impersonate the
  2168. principal until the <literal>expirationTime</literal> contained in the
  2169. nonce is reached. This is the key principle when selecting an
  2170. appropriate setting, but it would be unusual for immensly secure
  2171. applications to not be running over TLS/HTTPS in the first
  2172. instance.</para>
  2173. <para>Because of the more complex implementation of Digest
  2174. Authentication, there are often user agent issues. For example,
  2175. Internet Explorer fails to present an "<literal>opaque</literal>"
  2176. token on subsequent requests in the same session. The Acegi Security
  2177. filters therefore encapsulate all state information into the
  2178. "<literal>nonce</literal>" token instead. In our testing, the Acegi
  2179. Security implementation works reliably with FireFox and Internet
  2180. Explorer, correctly handling nonce timeouts etc.</para>
  2181. <para>Now that we've reviewed the theory, let's see how to use it. To
  2182. implement HTTP Digest Authentication, it is necessary to define
  2183. <literal>DigestProcessingFilter</literal> in the fitler chain. The
  2184. application context will need to define the
  2185. <literal>DigestProcessingFilter</literal> and its required
  2186. collaborators:</para>
  2187. <para><programlisting>&lt;bean id="digestProcessingFilter" class="net.sf.acegisecurity.ui.digestauth.DigestProcessingFilter"&gt;
  2188. &lt;property name="authenticationDao"&gt;&lt;ref local="jdbcDaoImpl"/&gt;&lt;/property&gt;
  2189. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="digestProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  2190. &lt;property name="userCache"&gt;&lt;ref local="userCache"/&gt;&lt;/property&gt;
  2191. &lt;/bean&gt;
  2192. &lt;bean id="digestProcessingFilterEntryPoint" class="net.sf.acegisecurity.ui.digestauth.DigestProcessingFilterEntryPoint"&gt;
  2193. &lt;property name="realmName"&gt;&lt;value&gt;Contacts Realm via Digest Authentication&lt;/value&gt;&lt;/property&gt;
  2194. &lt;property name="key"&gt;&lt;value&gt;acegi&lt;/value&gt;&lt;/property&gt;
  2195. &lt;property name="nonceValiditySeconds"&gt;&lt;value&gt;10&lt;/value&gt;&lt;/property&gt;
  2196. &lt;/bean&gt;</programlisting></para>
  2197. <para>The configured <literal>AuthenticationDao</literal> is needed
  2198. because <literal>DigestProcessingFilter</literal> must have direct
  2199. access to the clear text password of a user. Digest Authentication
  2200. will NOT work if you are using encoded passwords in your DAO. The DAO
  2201. collaborator, along with the <literal>UserCache</literal>, are
  2202. typically shared directly with a
  2203. <literal>DaoAuthenticationProvider</literal>. The
  2204. <literal>authenticationEntryPoint</literal> property must be
  2205. <literal>DigestProcessingFilterEntryPoint</literal>, so that
  2206. <literal>DigestProcessingFilter</literal> can obtain the correct
  2207. <literal>realmName</literal> and <literal>key</literal> for digest
  2208. calculations.</para>
  2209. <para>Like <literal>BasicAuthenticationFilter</literal>, if
  2210. authentication is successful an <literal>Authentication</literal>
  2211. request token will be placed into the
  2212. <literal>ContextHolder</literal>. If the authentication event was
  2213. successful, or authentication was not attempted because the HTTP
  2214. header did not contain a Digest Authentication request, the filter
  2215. chain will continue as normal. The only time the filter chain will be
  2216. interrupted is if authentication fails and the
  2217. <literal>AuthenticationEntryPoint</literal> is called, as discussed in
  2218. the previous paragraph.</para>
  2219. <para>Digest Authentication's RFC offers a range of additional
  2220. features to further increase security. For example, the nonce can be
  2221. changed on every request. Despite this, the Acegi Security
  2222. implementation was designed to minimise the complexity of the
  2223. implementation (and the doubtless user agent incompatibilities that
  2224. would emerge), and avoid needing to store server-side state. You are
  2225. invited to review RFC 2617 if you wish to explore these features in
  2226. more detail. As far as we are aware, the Acegi Security implementation
  2227. does comply with the minimum standards of this RFC.</para>
  2228. </sect2>
  2229. <sect2 id="security-ui-anonymous">
  2230. <title>Anonymous Authentication</title>
  2231. <para>Particularly in the case of web request URI security, sometimes
  2232. it is more convenient to assign configuration attributes against every
  2233. possible secure object invocation. Put differently, sometimes it is
  2234. nice to say <literal>ROLE_SOMETHING</literal> is required by default
  2235. and only allow certain exceptions to this rule, such as for login,
  2236. logout and home pages of an application. There are also other
  2237. situations where anonymous authentication would be desired, such as
  2238. when an auditing interceptor queries the
  2239. <literal>ContextHolder</literal> to identify which principal was
  2240. responsible for a given operation. Such classes can be authored with
  2241. more robustness if they know the <literal>ContextHolder</literal>
  2242. always contains an <literal>Authentication</literal> object, and never
  2243. <literal>null</literal>.</para>
  2244. <para>Acegi Security provides three classes that together provide an
  2245. anoymous authentication feature.
  2246. <literal>AnonymousAuthenticationToken</literal> is an implementation
  2247. of <literal>Authentication</literal>, and stores the
  2248. <literal>GrantedAuthority</literal>[]s which apply to the anonymous
  2249. principal. There is a corresponding
  2250. <literal>AnonymousAuthenticationProvider</literal>, which is chained
  2251. into the <literal>ProviderManager</literal> so that
  2252. <literal>AnonymousAuthenticationTokens</literal> are accepted.
  2253. Finally, there is an AnonymousProcessingFilter, which is chained after
  2254. the normal authentication mechanisms and automatically add an
  2255. <literal>AnonymousAuthenticationToken</literal> to the
  2256. <literal>ContextHolder</literal> if there is no existing
  2257. <literal>Authentication</literal> held there. The definition of the
  2258. filter and authentication provider appears as follows:</para>
  2259. <para><programlisting>&lt;bean id="anonymousProcessingFilter" class="net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter"&gt;
  2260. &lt;property name="key"&gt;&lt;value&gt;foobar&lt;/value&gt;&lt;/property&gt;
  2261. &lt;property name="userAttribute"&gt;&lt;value&gt;anonymousUser,ROLE_ANONYMOUS&lt;/value&gt;&lt;/property&gt;
  2262. &lt;/bean&gt;
  2263. &lt;bean id="anonymousAuthenticationProvider" class="net.sf.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider"&gt;
  2264. &lt;property name="key"&gt;&lt;value&gt;foobar&lt;/value&gt;&lt;/property&gt;
  2265. &lt;/bean&gt;</programlisting></para>
  2266. <para>The <literal>key</literal> is shared between the filter and
  2267. authentication provider, so that tokens created by the former are
  2268. accepted by the latter. The <literal>userAttribute</literal> is
  2269. expressed in the form of
  2270. <literal>usernameInTheAuthenticationToken,grantedAuthority[,grantedAuthority]</literal>.
  2271. This is the same syntax as used after the equals sign for
  2272. <literal>InMemoryDaoImpl</literal>'s <literal>userMap</literal>
  2273. property.</para>
  2274. <para>As explained earlier, the benefit of anonymous authentication is
  2275. that all URI patterns can have security applied to them. For
  2276. example:</para>
  2277. <para><programlisting>&lt;bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  2278. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2279. &lt;property name="accessDecisionManager"&gt;&lt;ref local="httpRequestAccessDecisionManager"/&gt;&lt;/property&gt;
  2280. &lt;property name="objectDefinitionSource"&gt;
  2281. &lt;value&gt;
  2282. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  2283. PATTERN_TYPE_APACHE_ANT
  2284. /index.jsp=ROLE_ANONYMOUS,ROLE_USER
  2285. /hello.htm=ROLE_ANONYMOUS,ROLE_USER
  2286. /logoff.jsp=ROLE_ANONYMOUS,ROLE_USER
  2287. /acegilogin.jsp=ROLE_ANONYMOUS,ROLE_USER
  2288. /**=ROLE_USER
  2289. &lt;/value&gt;
  2290. &lt;/property&gt;
  2291. &lt;/bean&gt;</programlisting>Rounding out the anonymous authentication
  2292. discussion is the <literal>AuthenticationTrustResolver</literal>
  2293. interface, with its corresponding
  2294. <literal>AuthenticationTrustResolverImpl</literal> implementation.
  2295. This interface provides an
  2296. <literal>isAnonymous(Authentication)</literal> method, which allows
  2297. interested classes to take into account this special type of
  2298. authentication status. The
  2299. <literal>SecurityEnforcementFilter</literal> uses this interface in
  2300. processing <literal>AccessDeniedException</literal>s. If an
  2301. <literal>AccessDeniedException</literal> is thrown, and the
  2302. authentication is of an anonymous type, instead of throwing a 403
  2303. (forbidden) response, the filter will instead commence the
  2304. <literal>AuthenticationEntryPoint</literal> so the principal can
  2305. authenticate properly. This is a necessary distinction, otherwise
  2306. principals would always be deemed "authenticated" and never be given
  2307. an opportunity to login via form, basic, digest or some other normal
  2308. authentication mechanism.</para>
  2309. </sect2>
  2310. <sect2 id="security-ui-well-known">
  2311. <title>Well-Known Locations</title>
  2312. <para>Prior to release 0.8.0, Acegi Security referred to "well-known
  2313. locations" in discussions about storing the
  2314. <literal>Authentication</literal>. This approach did not explicitly
  2315. separate the function of <literal>HttpSession</literal> storage of
  2316. <literal>ContextHolder</literal> contents from the processing of
  2317. authentication requests received through various protocols. In
  2318. addition, the previous approach did not facilitate storage of
  2319. non-<literal>Authentication</literal> objects between requests, which
  2320. was limiting usefulness of the <literal>ContextHolder</literal> system
  2321. to member of the community. For these reasons, the notion of
  2322. well-known locations was abandoned, the
  2323. <literal>HttpSessionContextIntegrationFilter</literal> was
  2324. established, and the purpose of authentication processing mechanisms
  2325. was explicitly defined and limited to interaction with the
  2326. <literal>ContextHolder</literal> only. There is no need to refer to
  2327. well-known locations any more and we hope this clearer separation of
  2328. responsibilities enhances understanding of the project.</para>
  2329. </sect2>
  2330. </sect1>
  2331. <sect1 id="security-container-adapters">
  2332. <title>Container Adapters</title>
  2333. <sect2 id="security-container-adapters-overview">
  2334. <title>Overview</title>
  2335. <para>Very early versions of the Acegi Security System for Spring
  2336. exclusively used Container Adapters for interfacing authentication
  2337. with end users. Whilst this worked well, it required considerable time
  2338. to support multiple container versions and the configuration itself
  2339. was relatively time-consuming for developers. For this reason the HTTP
  2340. Form Authentication and HTTP Basic Authentication approaches were
  2341. developed, and are today recommended for almost all
  2342. applications.</para>
  2343. <para>Container Adapters enable the Acegi Security System for Spring
  2344. to integrate directly with the containers used to host end user
  2345. applications. This integration means that applications can continue to
  2346. leverage the authentication and authorization capabilities built into
  2347. containers (such as <literal>isUserInRole()</literal> and form-based
  2348. or basic authentication), whilst benefiting from the enhanced security
  2349. interception capabilities provided by the Acegi Security System for
  2350. Spring (it should be noted that Acegi Security also offers
  2351. <literal>ContextHolderAwareRequestWrapper</literal> to deliver
  2352. <literal>isUserInRole()</literal> and similar Servlet Specification
  2353. compatibility methods).</para>
  2354. <para>The integration between a container and the Acegi Security
  2355. System for Spring is achieved through an adapter. The adapter provides
  2356. a container-compatible user authentication provider, and needs to
  2357. return a container-compatible user object.</para>
  2358. <para>The adapter is instantiated by the container and is defined in a
  2359. container-specific configuration file. The adapter then loads a Spring
  2360. application context which defines the normal authentication manager
  2361. settings, such as the authentication providers that can be used to
  2362. authenticate the request. The application context is usually named
  2363. <literal>acegisecurity.xml</literal> and is placed in a
  2364. container-specific location.</para>
  2365. <para>The Acegi Security System for Spring currently supports Jetty,
  2366. Catalina (Tomcat), JBoss and Resin. Additional container adapters can
  2367. easily be written.</para>
  2368. </sect2>
  2369. <sect2 id="security-container-adapters-adapter-provider">
  2370. <title>Adapter Authentication Provider</title>
  2371. <para>As is always the case, the container adapter generated
  2372. <literal>Authentication</literal> object still needs to be
  2373. authenticated by an <literal>AuthenticationManager</literal> when
  2374. requested to do so by the
  2375. <literal>AbstractSecurityInterceptor</literal>. The
  2376. <literal>AuthenticationManager</literal> needs to be certain the
  2377. adapter-provided <literal>Authentication</literal> object is valid and
  2378. was actually authenticated by a trusted adapter.</para>
  2379. <para>Adapters create <literal>Authentication</literal> objects which
  2380. are immutable and implement the <literal>AuthByAdapter</literal>
  2381. interface. These objects store the hash of a key that is defined by
  2382. the adapter. This allows the <literal>Authentication</literal> object
  2383. to be validated by the <literal>AuthByAdapterProvider</literal>. This
  2384. authentication provider is defined as follows:</para>
  2385. <para><programlisting>&lt;bean id="authByAdapterProvider" class="net.sf.acegisecurity.adapters.AuthByAdapterProvider"&gt;
  2386. &lt;property name="key"&gt;&lt;value&gt;my_password&lt;/value&gt;&lt;/property&gt;
  2387. &lt;/bean&gt;</programlisting></para>
  2388. <para>The key must match the key that is defined in the
  2389. container-specific configuration file that starts the adapter. The
  2390. <literal>AuthByAdapterProvider</literal> automatically accepts as
  2391. valid any <literal>AuthByAdapter</literal> implementation that returns
  2392. the expected hash of the key.</para>
  2393. <para>To reiterate, this means the adapter will perform the initial
  2394. authentication using providers such as
  2395. <literal>DaoAuthenticationProvider</literal>, returning an
  2396. <literal>AuthByAdapter</literal> instance that contains a hash code of
  2397. the key. Later, when an application calls a security interceptor
  2398. managed resource, the <literal>AuthByAdapter</literal> instance in the
  2399. <literal>SecureContext</literal> in the
  2400. <literal>ContextHolder</literal> will be tested by the application's
  2401. <literal>AuthByAdapterProvider</literal>. There is no requirement for
  2402. additional authentication providers such as
  2403. <literal>DaoAuthenticationProvider</literal> within the
  2404. application-specific application context, as the only type of
  2405. <literal>Authentication</literal> instance that will be presented by
  2406. the application is from the container adapter.</para>
  2407. <para>Classloader issues are frequent with containers and the use of
  2408. container adapters illustrates this further. Each container requires a
  2409. very specific configuration. The installation instructions are
  2410. provided below. Once installed, please take the time to try the sample
  2411. application to ensure your container adapter is properly
  2412. configured.</para>
  2413. <para>When using container adapters with the
  2414. <literal>DaoAuthenticationProvider</literal>, ensure you set its
  2415. <literal>forcePrincipalAsString</literal> property to
  2416. <literal>true</literal>.</para>
  2417. </sect2>
  2418. <sect2 id="security-container-adapters-catalina">
  2419. <title>Catalina (Tomcat) Installation</title>
  2420. <para>The following was tested with Jakarta Tomcat 4.1.30 and
  2421. 5.0.19.</para>
  2422. <para><literal>$CATALINA_HOME</literal> refers to the root of your
  2423. Catalina (Tomcat) installation.</para>
  2424. <para>Edit your <literal>$CATALINA_HOME/conf/server.xml</literal> file
  2425. so the <literal>&lt;Engine&gt;</literal> section contains only one
  2426. active <literal>&lt;Realm&gt;</literal> entry. An example realm
  2427. entry:</para>
  2428. <para><programlisting> &lt;Realm className="net.sf.acegisecurity.adapters.catalina.CatalinaAcegiUserRealm"
  2429. appContextLocation="conf/acegisecurity.xml"
  2430. key="my_password" /&gt;</programlisting></para>
  2431. <para>Be sure to remove any other <literal>&lt;Realm&gt;</literal>
  2432. entry from your <literal>&lt;Engine&gt;</literal> section.</para>
  2433. <para>Copy <literal>acegisecurity.xml</literal> into
  2434. <literal>$CATALINA_HOME/conf</literal>.</para>
  2435. <para>Copy <literal>acegi-security-catalina-XX.jar</literal> into
  2436. <literal>$CATALINA_HOME/server/lib</literal>.</para>
  2437. <para>Copy the following files into
  2438. <literal>$CATALINA_HOME/common/lib</literal>:</para>
  2439. <itemizedlist>
  2440. <listitem>
  2441. <para><literal>aopalliance.jar</literal></para>
  2442. </listitem>
  2443. <listitem>
  2444. <para><literal>spring.jar</literal></para>
  2445. </listitem>
  2446. <listitem>
  2447. <para><literal>commons-codec.jar</literal></para>
  2448. </listitem>
  2449. <listitem>
  2450. <para><literal>burlap.jar</literal></para>
  2451. </listitem>
  2452. <listitem>
  2453. <para><literal>hessian.jar</literal></para>
  2454. </listitem>
  2455. </itemizedlist>
  2456. <para>None of the above JAR files (or
  2457. <literal>acegi-security-XX.jar</literal>) should be in your
  2458. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  2459. in your <literal>web.xml</literal> does not matter with
  2460. Catalina.</para>
  2461. <para>We have received reports of problems using this Container
  2462. Adapter with Mac OS X. A work-around is to use a script such as
  2463. follows:</para>
  2464. <para><programlisting>#!/bin/sh
  2465. export CATALINA_HOME="/Library/Tomcat"
  2466. export JAVA_HOME="/Library/Java/Home"
  2467. cd /
  2468. $CATALINA_HOME/bin/startup.sh</programlisting></para>
  2469. </sect2>
  2470. <sect2 id="security-container-adapters-jetty">
  2471. <title>Jetty Installation</title>
  2472. <para>The following was tested with Jetty 4.2.18.</para>
  2473. <para><literal>$JETTY_HOME</literal> refers to the root of your Jetty
  2474. installation.</para>
  2475. <para>Edit your <literal>$JETTY_HOME/etc/jetty.xml</literal> file so
  2476. the <literal>&lt;Configure class&gt;</literal> section has a new
  2477. addRealm call:</para>
  2478. <para><programlisting> &lt;Call name="addRealm"&gt;
  2479. &lt;Arg&gt;
  2480. &lt;New class="net.sf.acegisecurity.adapters.jetty.JettyAcegiUserRealm"&gt;
  2481. &lt;Arg&gt;Spring Powered Realm&lt;/Arg&gt;
  2482. &lt;Arg&gt;my_password&lt;/Arg&gt;
  2483. &lt;Arg&gt;etc/acegisecurity.xml&lt;/Arg&gt;
  2484. &lt;/New&gt;
  2485. &lt;/Arg&gt;
  2486. &lt;/Call&gt;</programlisting></para>
  2487. <para>Copy <literal>acegisecurity.xml</literal> into
  2488. <literal>$JETTY_HOME/etc</literal>.</para>
  2489. <para>Copy the following files into
  2490. <literal>$JETTY_HOME/ext</literal>:<itemizedlist>
  2491. <listitem>
  2492. <para><literal>aopalliance.jar</literal></para>
  2493. </listitem>
  2494. <listitem>
  2495. <para><literal>commons-logging.jar</literal></para>
  2496. </listitem>
  2497. <listitem>
  2498. <para><literal>spring.jar</literal></para>
  2499. </listitem>
  2500. <listitem>
  2501. <para><literal>acegi-security-jetty-XX.jar</literal></para>
  2502. </listitem>
  2503. <listitem>
  2504. <para><literal>commons-codec.jar</literal></para>
  2505. </listitem>
  2506. <listitem>
  2507. <para><literal>burlap.jar</literal></para>
  2508. </listitem>
  2509. <listitem>
  2510. <para><literal>hessian.jar</literal></para>
  2511. </listitem>
  2512. </itemizedlist></para>
  2513. <para>None of the above JAR files (or
  2514. <literal>acegi-security-XX.jar</literal>) should be in your
  2515. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  2516. in your <literal>web.xml</literal> does matter with Jetty. The
  2517. <literal>web.xml</literal> must express the same
  2518. <literal>&lt;realm-name&gt;</literal> as your
  2519. <literal>jetty.xml</literal> (in the example above, "Spring Powered
  2520. Realm").</para>
  2521. </sect2>
  2522. <sect2 id="security-container-adapters-joss">
  2523. <title>JBoss Installation</title>
  2524. <para>The following was tested with JBoss 3.2.6.</para>
  2525. <para><literal>$JBOSS_HOME</literal> refers to the root of your JBoss
  2526. installation.</para>
  2527. <para>There are two different ways of making spring context available
  2528. to the Jboss integration classes.</para>
  2529. <para>The first approach is by editing your
  2530. <literal>$JBOSS_HOME/server/your_config/conf/login-config.xml</literal>
  2531. file so that it contains a new entry under the
  2532. <literal>&lt;Policy&gt;</literal> section:</para>
  2533. <para><programlisting> &lt;application-policy name = "SpringPoweredRealm"&gt;
  2534. &lt;authentication&gt;
  2535. &lt;login-module code = "net.sf.acegisecurity.adapters.jboss.JbossSpringLoginModule"
  2536. flag = "required"&gt;
  2537. &lt;module-option name = "appContextLocation"&gt;acegisecurity.xml&lt;/module-option&gt;
  2538. &lt;module-option name = "key"&gt;my_password&lt;/module-option&gt;
  2539. &lt;/login-module&gt;
  2540. &lt;/authentication&gt;
  2541. &lt;/application-policy&gt;</programlisting></para>
  2542. <para>Copy <literal>acegisecurity.xml</literal> into
  2543. <literal>$JBOSS_HOME/server/your_config/conf</literal>.</para>
  2544. <para>In this configuration <literal>acegisecurity.xml</literal>
  2545. contains the spring context definition including all the
  2546. authentication manager beans. You have to bear in mind though, that
  2547. <literal>SecurityContext</literal> is created and destroyed on each
  2548. login request, so the login operation might become costly.
  2549. Alternatively, the second approach is to use Spring singleton
  2550. capabilities through
  2551. <literal>org.springframework.beans.factory.access.SingletonBeanFactoryLocator</literal>.
  2552. The required configuration for this approach is:</para>
  2553. <para><programlisting> &lt;application-policy name = "SpringPoweredRealm"&gt;
  2554. &lt;authentication&gt;
  2555. &lt;login-module code = "net.sf.acegisecurity.adapters.jboss.JbossSpringLoginModule"
  2556. flag = "required"&gt;
  2557. &lt;module-option name = "singletonId"&gt;springRealm&lt;/module-option&gt;
  2558. &lt;module-option name = "key"&gt;my_password&lt;/module-option&gt;
  2559. &lt;module-option name = "authenticationManager"&gt;authenticationManager&lt;/module-option&gt;
  2560. &lt;/login-module&gt;
  2561. &lt;/authentication&gt;
  2562. &lt;/application-policy&gt;</programlisting></para>
  2563. <para>In the above code fragment,
  2564. <literal>authenticationManager</literal> is a helper property that
  2565. defines the expected name of the
  2566. <literal>AuthenticationManager</literal> in case you have several
  2567. defined in the IoC container. The <literal>singletonId</literal>
  2568. property references a bean defined in a
  2569. <literal>beanRefFactory.xml</literal> file. This file needs to be
  2570. available from anywhere on the JBoss classpath, including
  2571. <literal>$JBOSS_HOME/server/your_config/conf</literal>. The
  2572. <literal>beanRefFactory.xml</literal> contains the following
  2573. declaration:</para>
  2574. <para><programlisting>&lt;beans&gt;
  2575. &lt;bean id="springRealm" singleton="true" lazy-init="true" class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
  2576. &lt;constructor-arg&gt;
  2577. &lt;list&gt;
  2578. &lt;value&gt;acegisecurity.xml&lt;/value&gt;
  2579. &lt;/list&gt;
  2580. &lt;/constructor-arg&gt;
  2581. &lt;/bean&gt;
  2582. &lt;/beans&gt;</programlisting></para>
  2583. <para>Finally, irrespective of the configuration approach you need to
  2584. copy the following files into
  2585. <literal>$JBOSS_HOME/server/your_config/lib</literal>:<itemizedlist>
  2586. <listitem>
  2587. <para><literal>aopalliance.jar</literal></para>
  2588. </listitem>
  2589. <listitem>
  2590. <para><literal>spring.jar</literal></para>
  2591. </listitem>
  2592. <listitem>
  2593. <para><literal>acegi-security-jboss-XX.jar</literal></para>
  2594. </listitem>
  2595. <listitem>
  2596. <para><literal>commons-codec.jar</literal></para>
  2597. </listitem>
  2598. <listitem>
  2599. <para><literal>burlap.jar</literal></para>
  2600. </listitem>
  2601. <listitem>
  2602. <para><literal>hessian.jar</literal></para>
  2603. </listitem>
  2604. </itemizedlist></para>
  2605. <para>None of the above JAR files (or
  2606. <literal>acegi-security-XX.jar</literal>) should be in your
  2607. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  2608. in your <literal>web.xml</literal> does not matter with JBoss.
  2609. However, your web application's
  2610. <literal>WEB-INF/jboss-web.xml</literal> must express the same
  2611. <literal>&lt;security-domain&gt;</literal> as your
  2612. <literal>login-config.xml</literal>. For example, to match the above
  2613. example, your <literal>jboss-web.xml</literal> would look like
  2614. this:</para>
  2615. <para><programlisting>&lt;jboss-web&gt;
  2616. &lt;security-domain&gt;java:/jaas/SpringPoweredRealm&lt;/security-domain&gt;
  2617. &lt;/jboss-web&gt;</programlisting></para>
  2618. </sect2>
  2619. <sect2 id="security-container-adapters-resin">
  2620. <title>Resin Installation</title>
  2621. <para>The following was tested with Resin 3.0.6.</para>
  2622. <para><literal>$RESIN_HOME</literal> refers to the root of your Resin
  2623. installation.</para>
  2624. <para>Resin provides several ways to support the container adapter. In
  2625. the instructions below we have elected to maximise consistency with
  2626. other container adapter configurations. This will allow Resin users to
  2627. simply deploy the sample application and confirm correct
  2628. configuration. Developers comfortable with Resin are naturally able to
  2629. use its capabilities to package the JARs with the web application
  2630. itself, and/or support single sign-on.</para>
  2631. <para>Copy the following files into
  2632. <literal>$RESIN_HOME/lib</literal>:<itemizedlist>
  2633. <listitem>
  2634. <para><literal>aopalliance.jar</literal></para>
  2635. </listitem>
  2636. <listitem>
  2637. <para><literal>commons-logging.jar</literal></para>
  2638. </listitem>
  2639. <listitem>
  2640. <para><literal>spring.jar</literal></para>
  2641. </listitem>
  2642. <listitem>
  2643. <para><literal>acegi-security-resin-XX.jar</literal></para>
  2644. </listitem>
  2645. <listitem>
  2646. <para><literal>commons-codec.jar</literal></para>
  2647. </listitem>
  2648. <listitem>
  2649. <para><literal>burlap.jar</literal></para>
  2650. </listitem>
  2651. <listitem>
  2652. <para><literal>hessian.jar</literal></para>
  2653. </listitem>
  2654. </itemizedlist></para>
  2655. <para>Unlike the container-wide <literal>acegisecurity.xml</literal>
  2656. files used by other container adapters, each Resin web application
  2657. will contain its own
  2658. <literal>WEB-INF/resin-acegisecurity.xml</literal> file. Each web
  2659. application will also contain a <literal>resin-web.xml</literal> file
  2660. which Resin uses to start the container adapter:</para>
  2661. <para><programlisting>&lt;web-app&gt;
  2662. &lt;authenticator&gt;
  2663. &lt;type&gt;net.sf.acegisecurity.adapters.resin.ResinAcegiAuthenticator&lt;/type&gt;
  2664. &lt;init&gt;
  2665. &lt;app-context-location&gt;WEB-INF/resin-acegisecurity.xml&lt;/app-context-location&gt;
  2666. &lt;key&gt;my_password&lt;/key&gt;
  2667. &lt;/init&gt;
  2668. &lt;/authenticator&gt;
  2669. &lt;/web-app&gt;</programlisting></para>
  2670. <para>With the basic configuration provided above, none of the JAR
  2671. files listed (or <literal>acegi-security-XX.jar</literal>) should be
  2672. in your application's <literal>WEB-INF/lib</literal>. The realm name
  2673. indicated in your <literal>web.xml</literal> does not matter with
  2674. Resin, as the relevant authentication class is indicated by the
  2675. <literal>&lt;authenticator&gt;</literal> setting.</para>
  2676. </sect2>
  2677. </sect1>
  2678. <sect1 id="security-cas">
  2679. <title>Yale Central Authentication Service (CAS) Single Sign On</title>
  2680. <sect2 id="security-cas-overview">
  2681. <title>Overview</title>
  2682. <para>Yale University produces an enterprise-wide single sign on
  2683. system known as CAS. Unlike other initiatives, Yale's Central
  2684. Authentication Service is open source, widely used, simple to
  2685. understand, platform independent, and supports proxy capabilities. The
  2686. Acegi Security System for Spring fully supports CAS, and provides an
  2687. easy migration path from single-application deployments of Acegi
  2688. Security through to multiple-application deployments secured by an
  2689. enterprise-wide CAS server.</para>
  2690. <para>You can learn more about CAS at
  2691. <literal>http://www.yale.edu/tp/auth/</literal>. You will need to
  2692. visit this URL to download the CAS Server files. Whilst the Acegi
  2693. Security System for Spring includes two CAS libraries in the
  2694. "-with-dependencies" ZIP file, you will still need the CAS Java Server
  2695. Pages and <literal>web.xml</literal> to customise and deploy your CAS
  2696. server.</para>
  2697. </sect2>
  2698. <sect2 id="security-cas-how-cas-works">
  2699. <title>How CAS Works</title>
  2700. <para>Whilst the CAS web site above contains two documents that detail
  2701. the architecture of CAS, we present the general overview again here
  2702. within the context of the Acegi Security System for Spring. The
  2703. following refers to CAS 2.0, being the version of CAS that Acegi
  2704. Security System for Spring supports.</para>
  2705. <para>Somewhere in your enterprise you will need to setup a CAS
  2706. server. The CAS server is simply a standard WAR file, so there isn't
  2707. anything difficult about setting up your server. Inside the WAR file
  2708. you will customise the login and other single sign on pages displayed
  2709. to users. You will also need to specify in the web.xml a
  2710. <literal>PasswordHandler</literal>. The
  2711. <literal>PasswordHandler</literal> has a simple method that returns a
  2712. boolean as to whether a given username and password is valid. Your
  2713. <literal>PasswordHandler</literal> implementation will need to link
  2714. into some type of backend authentication repository, such as an LDAP
  2715. server or database.</para>
  2716. <para>If you are already running an existing CAS server instance, you
  2717. will have already established a <literal>PasswordHandler</literal>. If
  2718. you do not already have a <literal>PasswordHandler</literal>, you
  2719. might prefer to use the Acegi Security System for Spring
  2720. <literal>CasPasswordHandler</literal> class. This class delegates
  2721. through to the standard Acegi Security
  2722. <literal>AuthenticationManager</literal>, enabling you to use a
  2723. security configuration you might already have in place. You do not
  2724. need to use the <literal>CasPasswordHandler</literal> class on your
  2725. CAS server if you do not wish. The Acegi Security System for Spring
  2726. will function as a CAS client successfully irrespective of the
  2727. <literal>PasswordHandler</literal> you've chosen for your CAS
  2728. server.</para>
  2729. <para>Apart from the CAS server itself, the other key player is of
  2730. course the secure web applications deployed throughout your
  2731. enterprise. These web applications are known as "services". There are
  2732. two types of services: standard services and proxy services. A proxy
  2733. service is able to request resources from other services on behalf of
  2734. the user. This will be explained more fully later.</para>
  2735. <para>Services can be developed in a large variety of languages, due
  2736. to CAS 2.0's very light XML-based protocol. The Yale CAS home page
  2737. contains a clients archive which demonstrates CAS clients in Java,
  2738. Active Server Pages, Perl, Python and others. Naturally, Java support
  2739. is very strong given the CAS server is written in Java. You do not
  2740. need to use any of CAS' client classes in applications secured by the
  2741. Acegi Security System for Spring. This is handled transparently for
  2742. you.</para>
  2743. <para>The basic interaction between a web browser, CAS server and an
  2744. Acegi Security for System Spring secured service is as follows:</para>
  2745. <orderedlist>
  2746. <listitem>
  2747. <para>The web user is browsing the service's public pages. CAS or
  2748. Acegi Security is not involved.</para>
  2749. </listitem>
  2750. <listitem>
  2751. <para>The user eventually requests a page that is either secure or
  2752. one of the beans it uses is secure. Acegi Security's
  2753. <literal>SecurityEnforcementFilter</literal> will detect the
  2754. <literal>AuthenticationException</literal>.</para>
  2755. </listitem>
  2756. <listitem>
  2757. <para>Because the user's <literal>Authentication</literal> object
  2758. (or lack thereof) caused an
  2759. <literal>AuthenticationException</literal>, the
  2760. <literal>SecurityEnforcementFilter</literal> will call the
  2761. configured <literal>AuthenticationEntryPoint</literal>. If using
  2762. CAS, this will be the
  2763. <literal>CasProcessingFilterEntryPoint</literal> class.</para>
  2764. </listitem>
  2765. <listitem>
  2766. <para>The <literal>CasProcessingFilterEntry</literal> point will
  2767. redirect the user's browser to the CAS server. It will also
  2768. indicate a <literal>service</literal> parameter, which is the
  2769. callback URL for the Acegi Security service. For example, the URL
  2770. to which the browser is redirected might be
  2771. <literal>https://my.company.com/cas/login?service=https%3A%2F%2Fserver3.company.com%2Fwebapp%2Fj_acegi_cas_security_check</literal>.</para>
  2772. </listitem>
  2773. <listitem>
  2774. <para>After the user's browser redirects to CAS, they will be
  2775. prompted for their username and password. If the user presents a
  2776. session cookie which indicates they've previously logged on, they
  2777. will not be prompted to login again (there is an exception to this
  2778. procedure, which we'll cover later). CAS will use the
  2779. <literal>PasswordHandler</literal> discussed above to decide
  2780. whether the username and password is valid.</para>
  2781. </listitem>
  2782. <listitem>
  2783. <para>Upon successful login, CAS will redirect the user's browser
  2784. back to the original service. It will also include a
  2785. <literal>ticket</literal> parameter, which is an opaque string
  2786. representing the "service ticket". Continuing our earlier example,
  2787. the URL the browser is redirected to might be
  2788. <literal>https://server3.company.com/webapp/j_acegi_cas_security_check?ticket=ST-0-ER94xMJmn6pha35CQRoZ</literal>.</para>
  2789. </listitem>
  2790. <listitem>
  2791. <para>Back in the service web application, the
  2792. <literal>CasProcessingFilter</literal> is always listening for
  2793. requests to <literal>/j_acegi_cas_security_check</literal> (this
  2794. is configurable, but we'll use the defaults in this introduction).
  2795. The processing filter will construct a
  2796. <literal>UsernamePasswordAuthenticationToken</literal>
  2797. representing the service ticket. The principal will be equal to
  2798. <literal>CasProcessingFilter.CAS_STATEFUL_IDENTIFIER</literal>,
  2799. whilst the credentials will be the service ticket opaque value.
  2800. This authentication request will then be handed to the configured
  2801. <literal>AuthenticationManager</literal>.</para>
  2802. </listitem>
  2803. <listitem>
  2804. <para>The <literal>AuthenticationManager</literal> implementation
  2805. will be the <literal>ProviderManager</literal>, which is in turn
  2806. configured with the <literal>CasAuthenticationProvider</literal>.
  2807. The <literal>CasAuthenticationProvider</literal> only responds to
  2808. <literal>UsernamePasswordAuthenticationToken</literal>s containing
  2809. the CAS-specific principal (such as
  2810. <literal>CasProcessingFilter.CAS_STATEFUL_IDENTIFIER</literal>)
  2811. and <literal>CasAuthenticationToken</literal>s (discussed
  2812. later).</para>
  2813. </listitem>
  2814. <listitem>
  2815. <para><literal>CasAuthenticationProvider</literal> will validate
  2816. the service ticket using a <literal>TicketValidator</literal>
  2817. implementation. Acegi Security includes one implementation, the
  2818. <literal>CasProxyTicketValidator</literal>. This implementation a
  2819. ticket validation class included in the CAS client library. The
  2820. <literal>CasProxyTicketValidator</literal> makes a HTTPS request
  2821. to the CAS server in order to validate the service ticket. The
  2822. <literal>CasProxyTicketValidator</literal> may also include a
  2823. proxy callback URL, which is included in this example:
  2824. <literal>https://my.company.com/cas/proxyValidate?service=https%3A%2F%2Fserver3.company.com%2Fwebapp%2Fj_acegi_cas_security_check&amp;ticket=ST-0-ER94xMJmn6pha35CQRoZ&amp;pgtUrl=https://server3.company.com/webapp/casProxy/receptor</literal>.</para>
  2825. </listitem>
  2826. <listitem>
  2827. <para>Back on the CAS server, the proxy validation request will be
  2828. received. If the presented service ticket matches the service URL
  2829. the ticket was issued to, CAS will provide an affirmative response
  2830. in XML indicating the username. If any proxy was involved in the
  2831. authentication (discussed below), the list of proxies is also
  2832. included in the XML response.</para>
  2833. </listitem>
  2834. <listitem>
  2835. <para>[OPTIONAL] If the request to the CAS validation service
  2836. included the proxy callback URL (in the <literal>pgtUrl</literal>
  2837. parameter), CAS will include a <literal>pgtIou</literal> string in
  2838. the XML response. This <literal>pgtIou</literal> represents a
  2839. proxy-granting ticket IOU. The CAS server will then create its own
  2840. HTTPS connection back to the <literal>pgtUrl</literal>. This is to
  2841. mutually authenticate the CAS server and the claimed service URL.
  2842. The HTTPS connection will be used to send a proxy granting ticket
  2843. to the original web application. For example,
  2844. <literal>https://server3.company.com/webapp/casProxy/receptor?pgtIou=PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt&amp;pgtId=PGT-1-si9YkkHLrtACBo64rmsi3v2nf7cpCResXg5MpESZFArbaZiOKH</literal>.
  2845. We suggest you use CAS' <literal>ProxyTicketReceptor</literal>
  2846. servlet to receive these proxy-granting tickets, if they are
  2847. required.</para>
  2848. </listitem>
  2849. <listitem>
  2850. <para>The <literal>CasProxyTicketValidator</literal> will parse
  2851. the XML received from the CAS server. It will return to the
  2852. <literal>CasAuthenticationProvider</literal> a
  2853. <literal>TicketResponse</literal>, which includes the username
  2854. (mandatory), proxy list (if any were involved), and proxy-granting
  2855. ticket IOU (if the proxy callback was requested).</para>
  2856. </listitem>
  2857. <listitem>
  2858. <para>Next <literal>CasAuthenticationProvider</literal> will call
  2859. a configured <literal>CasProxyDecider</literal>. The
  2860. <literal>CasProxyDecider</literal> indicates whether the proxy
  2861. list in the <literal>TicketResponse</literal> is acceptable to the
  2862. service. Several implementations are provided with the Acegi
  2863. Security System: <literal>RejectProxyTickets</literal>,
  2864. <literal>AcceptAnyCasProxy</literal> and
  2865. <literal>NamedCasProxyDecider</literal>. These names are largely
  2866. self-explanatory, except <literal>NamedCasProxyDecider</literal>
  2867. which allows a <literal>List</literal> of trusted proxies to be
  2868. provided.</para>
  2869. </listitem>
  2870. <listitem>
  2871. <para><literal>CasAuthenticationProvider</literal> will next
  2872. request a <literal>CasAuthoritiesPopulator</literal> to advise the
  2873. <literal>GrantedAuthority</literal> objects that apply to the user
  2874. contained in the <literal>TicketResponse</literal>. Acegi Security
  2875. includes a <literal>DaoCasAuthoritiesPopulator</literal> which
  2876. simply uses the <literal>AuthenticationDao</literal>
  2877. infrastructure to find the <literal>UserDetails</literal> and
  2878. their associated <literal>GrantedAuthority</literal>s. Note that
  2879. the password and enabled/disabled status of
  2880. <literal>UserDetails</literal> returned by the
  2881. <literal>AuthenticationDao</literal> are ignored, as the CAS
  2882. server is responsible for authentication decisions.
  2883. <literal>DaoCasAuthoritiesPopulator</literal> is only concerned
  2884. with retrieving the <literal>GrantedAuthority</literal>s.</para>
  2885. </listitem>
  2886. <listitem>
  2887. <para>If there were no problems,
  2888. <literal>CasAuthenticationProvider</literal> constructs a
  2889. <literal>CasAuthenticationToken</literal> including the details
  2890. contained in the <literal>TicketResponse</literal> and the
  2891. <literal>GrantedAuthority</literal>s. The
  2892. <literal>CasAuthenticationToken</literal> contains the hash of a
  2893. key, so that the <literal>CasAuthenticationProvider</literal>
  2894. knows it created it.</para>
  2895. </listitem>
  2896. <listitem>
  2897. <para>Control then returns to
  2898. <literal>CasProcessingFilter</literal>, which places the created
  2899. <literal>CasAuthenticationToken</literal> into the
  2900. <literal>HttpSession</literal> attribute named
  2901. <literal>HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY</literal>.</para>
  2902. </listitem>
  2903. <listitem>
  2904. <para>The user's browser is redirected to the original page that
  2905. caused the <literal>AuthenticationException</literal>.</para>
  2906. </listitem>
  2907. <listitem>
  2908. <para>As the <literal>Authentication</literal> object is now in
  2909. the well-known location, it is handled like any other
  2910. authentication approach. Usually the
  2911. <literal>HttpSessionIntegrationFilter</literal> will be used to
  2912. associate the <literal>Authentication</literal> object with the
  2913. <literal>ContextHolder</literal> for the duration of each
  2914. request.</para>
  2915. </listitem>
  2916. </orderedlist>
  2917. <para>It's good that you're still here! It might sound involved, but
  2918. you can relax as the Acegi Security System for Spring classes hide
  2919. much of the complexity. Let's now look at how this is
  2920. configured.</para>
  2921. </sect2>
  2922. <sect2 id="security-cas-install-server">
  2923. <title>CAS Server Installation (Optional)</title>
  2924. <para>As mentioned above, the Acegi Security System for Spring
  2925. includes a <literal>PasswordHandler</literal> that bridges your
  2926. existing <literal>AuthenticationManager</literal> into CAS. You do not
  2927. need to use this <literal>PasswordHandler</literal> to use Acegi
  2928. Security on the client side (any CAS
  2929. <literal>PasswordHandler</literal> will do).</para>
  2930. <para>To install, you will need to download and extract the CAS server
  2931. archive. We used version 2.0.12. There will be a
  2932. <literal>/web</literal> directory in the root of the deployment. Copy
  2933. an <literal>applicationContext.xml</literal> containing your
  2934. <literal>AuthenticationManager</literal> as well as the
  2935. <literal>CasPasswordHandler</literal> into the
  2936. <literal>/web/WEB-INF</literal> directory. A sample
  2937. <literal>applicationContext.xml</literal> is included below:</para>
  2938. <programlisting>&lt;bean id="inMemoryDaoImpl" class="net.sf.acegisecurity.providers.dao.memory.InMemoryDaoImpl"&gt;
  2939. &lt;property name="userMap"&gt;
  2940. &lt;value&gt;
  2941. marissa=koala,ROLES_IGNORED_BY_CAS
  2942. dianne=emu,ROLES_IGNORED_BY_CAS
  2943. scott=wombat,ROLES_IGNORED_BY_CAS
  2944. peter=opal,disabled,ROLES_IGNORED_BY_CAS
  2945. &lt;/value&gt;
  2946. &lt;/property&gt;
  2947. &lt;/bean&gt;
  2948. &lt;bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  2949. &lt;property name="authenticationDao"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  2950. &lt;/bean&gt;
  2951. &lt;bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager"&gt;
  2952. &lt;property name="providers"&gt;
  2953. &lt;list&gt;
  2954. &lt;ref bean="daoAuthenticationProvider"/&gt;
  2955. &lt;/list&gt;
  2956. &lt;/property&gt;
  2957. &lt;/bean&gt;
  2958. &lt;bean id="casPasswordHandler" class="net.sf.acegisecurity.adapters.cas.CasPasswordHandler"&gt;
  2959. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2960. &lt;/bean&gt;</programlisting>
  2961. <para>Note the granted authorities are ignored by CAS because it has
  2962. no way of communicating the granted authorities to calling
  2963. applications. CAS is only concerned with username and passwords (and
  2964. the enabled/disabled status).</para>
  2965. <para>Next you will need to edit the existing
  2966. <literal>/web/WEB-INF/web.xml</literal> file. Add (or edit in the case
  2967. of the <literal>authHandler</literal> property) the following
  2968. lines:</para>
  2969. <para><programlisting>&lt;context-param&gt;
  2970. &lt;param-name&gt;edu.yale.its.tp.cas.authHandler&lt;/param-name&gt;
  2971. &lt;param-value&gt;net.sf.acegisecurity.adapters.cas.CasPasswordHandlerProxy&lt;/param-value&gt;
  2972. &lt;/context-param&gt;
  2973. &lt;context-param&gt;
  2974. &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
  2975. &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
  2976. &lt;/context-param&gt;
  2977. &lt;listener&gt;
  2978. &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  2979. &lt;/listener&gt;</programlisting></para>
  2980. <para>Copy the <literal>spring.jar</literal> and
  2981. <literal>acegi-security.jar</literal> files into
  2982. <literal>/web/WEB-INF/lib</literal>. Now use the <literal>ant
  2983. dist</literal> task in the <literal>build.xml</literal> in the root of
  2984. the directory structure. This will create
  2985. <literal>/lib/cas.war</literal>, which is ready for deployment to your
  2986. servlet container.</para>
  2987. <para>Note CAS heavily relies on HTTPS. You can't even test the system
  2988. without a HTTPS certificate. Whilst you should refer to your web
  2989. container's documentation on setting up HTTPS, if you need some
  2990. additional help or a test certificate you might like to check the
  2991. <literal>samples/contacts/etc/ssl</literal> directory.</para>
  2992. </sect2>
  2993. <sect2 id="security-cas-install-client">
  2994. <title>CAS Acegi Security System Client Installation</title>
  2995. <para>The web application side of CAS is made easy due to the Acegi
  2996. Security System for Spring. It is assumed you already know the basics
  2997. of using the Acegi Security System for Spring, so these are not
  2998. covered again below. Only the CAS-specific beans are mentioned.</para>
  2999. <para>You will need to add a <literal>ServiceProperties</literal> bean
  3000. to your application context. This represents your service:</para>
  3001. <para><programlisting>&lt;bean id="serviceProperties" class="net.sf.acegisecurity.ui.cas.ServiceProperties"&gt;
  3002. &lt;property name="service"&gt;&lt;value&gt;https://localhost:8443/contacts-cas/j_acegi_cas_security_check&lt;/value&gt;&lt;/property&gt;
  3003. &lt;property name="sendRenew"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  3004. &lt;/bean&gt;</programlisting></para>
  3005. <para>The <literal>service</literal> must equal a URL that will be
  3006. monitored by the <literal>CasProcessingFilter</literal>. The
  3007. <literal>sendRenew</literal> defaults to false, but should be set to
  3008. true if your application is particularly sensitive. What this
  3009. parameter does is tell the CAS login service that a single sign on
  3010. login is unacceptable. Instead, the user will need to re-enter their
  3011. username and password in order to gain access to the service.</para>
  3012. <para>The following beans should be configured to commence the CAS
  3013. authentication process:</para>
  3014. <para><programlisting>&lt;bean id="casProcessingFilter" class="net.sf.acegisecurity.ui.cas.CasProcessingFilter"&gt;
  3015. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  3016. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/casfailed.jsp&lt;/value&gt;&lt;/property&gt;
  3017. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;
  3018. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_cas_security_check&lt;/value&gt;&lt;/property&gt;
  3019. &lt;/bean&gt;
  3020. &lt;bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter"&gt;
  3021. &lt;property name="filterSecurityInterceptor"&gt;&lt;ref bean="filterInvocationInterceptor"/&gt;&lt;/property&gt;
  3022. &lt;property name="authenticationEntryPoint"&gt;&lt;ref bean="casProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  3023. &lt;/bean&gt;
  3024. &lt;bean id="casProcessingFilterEntryPoint" class="net.sf.acegisecurity.ui.cas.CasProcessingFilterEntryPoint"&gt;
  3025. &lt;property name="loginUrl"&gt;&lt;value&gt;https://localhost:8443/cas/login&lt;/value&gt;&lt;/property&gt;
  3026. &lt;property name="serviceProperties"&gt;&lt;ref bean="serviceProperties"/&gt;&lt;/property&gt;
  3027. &lt;/bean&gt;</programlisting></para>
  3028. <para>You will also need to add the
  3029. <literal>CasProcessingFilter</literal> to web.xml:</para>
  3030. <para><programlisting>&lt;filter&gt;
  3031. &lt;filter-name&gt;Acegi CAS Processing Filter&lt;/filter-name&gt;
  3032. &lt;filter-class&gt;net.sf.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  3033. &lt;init-param&gt;
  3034. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  3035. &lt;param-value&gt;net.sf.acegisecurity.ui.cas.CasProcessingFilter&lt;/param-value&gt;
  3036. &lt;/init-param&gt;
  3037. &lt;/filter&gt;
  3038. &lt;filter-mapping&gt;
  3039. &lt;filter-name&gt;Acegi CAS Processing Filter&lt;/filter-name&gt;
  3040. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  3041. &lt;/filter-mapping&gt;</programlisting></para>
  3042. <para>The <literal>CasProcessingFilter</literal> has very similar
  3043. properties to the <literal>AuthenticationProcessingFilter</literal>
  3044. (used for form-based logins). Each property is
  3045. self-explanatory.</para>
  3046. <para>For CAS to operate, the
  3047. <literal>SecurityEnforcementFilter</literal> must have its
  3048. <literal>authenticationEntryPoint</literal> property set to the
  3049. <literal>CasProcessingFilterEntryPoint</literal> bean.</para>
  3050. <para>The <literal>CasProcessingFilterEntryPoint</literal> must refer
  3051. to the <literal>ServiceProperties</literal> bean (discussed above),
  3052. which provides the URL to the enterprise's CAS login server. This is
  3053. where the user's browser will be redirected.</para>
  3054. <para>Next you need to add an <literal>AuthenticationManager</literal>
  3055. that uses <literal>CasAuthenticationProvider</literal> and its
  3056. collaborators:</para>
  3057. <para><programlisting>&lt;bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager"&gt;
  3058. &lt;property name="providers"&gt;
  3059. &lt;list&gt;
  3060. &lt;ref bean="casAuthenticationProvider"/&gt;
  3061. &lt;/list&gt;
  3062. &lt;/property&gt;
  3063. &lt;/bean&gt;
  3064. &lt;bean id="casAuthenticationProvider" class="net.sf.acegisecurity.providers.cas.CasAuthenticationProvider"&gt;
  3065. &lt;property name="casAuthoritiesPopulator"&gt;&lt;ref bean="casAuthoritiesPopulator"/&gt;&lt;/property&gt;
  3066. &lt;property name="casProxyDecider"&gt;&lt;ref bean="casProxyDecider"/&gt;&lt;/property&gt;
  3067. &lt;property name="ticketValidator"&gt;&lt;ref bean="casProxyTicketValidator"/&gt;&lt;/property&gt;
  3068. &lt;property name="statelessTicketCache"&gt;&lt;ref bean="statelessTicketCache"/&gt;&lt;/property&gt;
  3069. &lt;property name="key"&gt;&lt;value&gt;my_password_for_this_auth_provider_only&lt;/value&gt;&lt;/property&gt;
  3070. &lt;/bean&gt;
  3071. &lt;bean id="casProxyTicketValidator" class="net.sf.acegisecurity.providers.cas.ticketvalidator.CasProxyTicketValidator"&gt;
  3072. &lt;property name="casValidate"&gt;&lt;value&gt;https://localhost:8443/cas/proxyValidate&lt;/value&gt;&lt;/property&gt;
  3073. &lt;property name="proxyCallbackUrl"&gt;&lt;value&gt;https://localhost:8443/contacts-cas/casProxy/receptor&lt;/value&gt;&lt;/property&gt;
  3074. &lt;property name="serviceProperties"&gt;&lt;ref bean="serviceProperties"/&gt;&lt;/property&gt;
  3075. &lt;!-- &lt;property name="trustStore"&gt;&lt;value&gt;/some/path/to/your/lib/security/cacerts&lt;/value&gt;&lt;/property&gt; --&gt;
  3076. &lt;/bean&gt;
  3077. &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;
  3078. &lt;property name="configLocation"&gt;
  3079. &lt;value&gt;classpath:/ehcache-failsafe.xml&lt;/value&gt;
  3080. &lt;/property&gt;
  3081. &lt;/bean&gt;
  3082. &lt;bean id="ticketCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;
  3083. &lt;property name="cacheManager"&gt;
  3084. &lt;ref local="cacheManager"/&gt;
  3085. &lt;/property&gt;
  3086. &lt;property name="cacheName"&gt;
  3087. &lt;value&gt;ticketCache&lt;/value&gt;
  3088. &lt;/property&gt;
  3089. &lt;/bean&gt;
  3090. &lt;bean id="statelessTicketCache" class="net.sf.acegisecurity.providers.cas.cache.EhCacheBasedTicketCache"&gt;
  3091. &lt;property name="cache"&gt;&lt;ref local="ticketCacheBackend"/&gt;&lt;/property&gt;
  3092. &lt;/bean&gt;
  3093. &lt;bean id="casAuthoritiesPopulator" class="net.sf.acegisecurity.providers.cas.populator.DaoCasAuthoritiesPopulator"&gt;
  3094. &lt;property name="authenticationDao"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3095. &lt;/bean&gt;
  3096. &lt;bean id="casProxyDecider" class="net.sf.acegisecurity.providers.cas.proxy.RejectProxyTickets"/&gt;</programlisting></para>
  3097. <para>The beans are all reasonable self-explanatory if you refer back
  3098. to the "How CAS Works" section. Careful readers might notice one
  3099. surprise: the <literal>statelessTicketCache</literal> property of the
  3100. <literal>CasAuthenticationProvider</literal>. This is discussed in
  3101. detail in the "Advanced CAS Usage" section.</para>
  3102. <para>Note the <literal>CasProxyTicketValidator</literal> has a
  3103. remarked out <literal>trustStore</literal> property. This property
  3104. might be helpful if you experience HTTPS certificate issues. Also note
  3105. the <literal>proxyCallbackUrl</literal> is set so the service can
  3106. receive a proxy-granting ticket. As mentioned above, this is optional
  3107. and unnecessary if you do not require proxy-granting tickets. If you
  3108. do use this feature, you will need to configure a suitable servlet to
  3109. receive the proxy-granting tickets. We suggest you use CAS'
  3110. <literal>ProxyTicketReceptor</literal> by adding the following to your
  3111. web application's <literal>web.xml</literal>:</para>
  3112. <para><programlisting>&lt;servlet&gt;
  3113. &lt;servlet-name&gt;casproxy&lt;/servlet-name&gt;
  3114. &lt;servlet-class&gt;edu.yale.its.tp.cas.proxy.ProxyTicketReceptor&lt;/servlet-class&gt;
  3115. &lt;/servlet&gt;
  3116. &lt;servlet-mapping&gt;
  3117. &lt;servlet-name&gt;casproxy&lt;/servlet-name&gt;
  3118. &lt;url-pattern&gt;/casProxy/*&lt;/url-pattern&gt;
  3119. &lt;/servlet-mapping&gt;</programlisting></para>
  3120. <para>This completes the configuration of CAS. If you haven't made any
  3121. mistakes, your web application should happily work within the
  3122. framework of CAS single sign on. No other parts of the Acegi Security
  3123. System for Spring need to be concerned about the fact CAS handled
  3124. authentication.</para>
  3125. <para>There is also a <literal>contacts-cas.war</literal> file in the
  3126. sample applications directory. This sample application uses the above
  3127. settings and can be deployed to see CAS in operation.</para>
  3128. </sect2>
  3129. <sect2 id="security-cas-advanced-usage">
  3130. <title>Advanced CAS Usage</title>
  3131. <para>The <literal>CasAuthenticationProvider</literal> distinguishes
  3132. between stateful and stateless clients. A stateful client is
  3133. considered any that originates via the
  3134. <literal>CasProcessingFilter</literal>. A stateless client is any that
  3135. presents an authentication request via the
  3136. <literal>UsernamePasswordAuthenticationToken</literal> with a
  3137. principal equal to
  3138. <literal>CasProcessingFilter.CAS_STATELESS_IDENTIFIER</literal>.</para>
  3139. <para>Stateless clients are likely to be via remoting protocols such
  3140. as Hessian and Burlap. The <literal>BasicProcessingFilter</literal> is
  3141. still used in this case, but the remoting protocol client is expected
  3142. to present a username equal to the static string above, and a password
  3143. equal to a CAS service ticket. Clients should acquire a CAS service
  3144. ticket directly from the CAS server.</para>
  3145. <para>Because remoting protocols have no way of presenting themselves
  3146. within the context of a <literal>HttpSession</literal>, it isn't
  3147. possible to rely on the <literal>HttpSession</literal>'s
  3148. <literal>HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY</literal>
  3149. attribute to locate the <literal>CasAuthenticationToken</literal>.
  3150. Furthermore, because the CAS server invalidates a service ticket after
  3151. it has been validated by the <literal>TicketValidator</literal>,
  3152. presenting the same service ticket on subsequent requests will not
  3153. work. It is similarly very difficult to obtain a proxy-granting ticket
  3154. for a remoting protocol client, as they are often deployed on client
  3155. machines which rarely have HTTPS URLs that would be accessible to the
  3156. CAS server.</para>
  3157. <para>One obvious option is to not use CAS at all for remoting
  3158. protocol clients. However, this would eliminate many of the desirable
  3159. features of CAS.</para>
  3160. <para>As a middle-ground, the
  3161. <literal>CasAuthenticationProvider</literal> uses a
  3162. <literal>StatelessTicketCache</literal>. This is used solely for
  3163. requests with a principal equal to
  3164. <literal>CasProcessingFilter.CAS_STATELESS_IDENTIFIER</literal>. What
  3165. happens is the <literal>CasAuthenticationProvider</literal> will store
  3166. the resulting <literal>CasAuthenticationToken</literal> in the
  3167. <literal>StatelessTicketCache</literal>, keyed on the service ticket.
  3168. Accordingly, remoting protocol clients can present the same service
  3169. ticket and the <literal>CasAuthenticationProvider</literal> will not
  3170. need to contact the CAS server for validation (aside from the first
  3171. request).</para>
  3172. <para>The other aspect of advanced CAS usage involves creating proxy
  3173. tickets from the proxy-granting ticket. As indicated above, we
  3174. recommend you use CAS' <literal>ProxyTicketReceptor</literal> to
  3175. receive these tickets. The <literal>ProxyTicketReceptor</literal>
  3176. provides a static method that enables you to obtain a proxy ticket by
  3177. presenting the proxy-granting IOU ticket. You can obtain the
  3178. proxy-granting IOU ticket by calling
  3179. <literal>CasAuthenticationToken.getProxyGrantingTicketIou()</literal>.</para>
  3180. <para>It is hoped you find CAS integration easy and useful with the
  3181. Acegi Security System for Spring classes. Welcome to enterprise-wide
  3182. single sign on!</para>
  3183. </sect2>
  3184. </sect1>
  3185. <sect1 id="security-channels">
  3186. <title>Channel Security</title>
  3187. <sect2 id="security-channels-overview">
  3188. <title>Overview</title>
  3189. <para>In addition to coordinating the authentication and authorization
  3190. requirements of your application, the Acegi Security System for Spring
  3191. is also able to ensure unauthenticated web requests have certain
  3192. properties. These properties may include being of a particular
  3193. transport type, having a particular <literal>HttpSession</literal>
  3194. attribute set and so on. The most common requirement is for your web
  3195. requests to be received using a particular transport protocol, such as
  3196. HTTPS.</para>
  3197. <para>An important issue in considering transport security is that of
  3198. session hijacking. Your web container manages a
  3199. <literal>HttpSession</literal> by reference to a
  3200. <literal>jsessionid</literal> that is sent to user agents either via a
  3201. cookie or URL rewriting. If the <literal>jsessionid</literal> is ever
  3202. sent over HTTP, there is a possibility that session identifier can be
  3203. intercepted and used to impersonate the user after they complete the
  3204. authentication process. This is because most web containers maintain
  3205. the same session identifier for a given user, even after they switch
  3206. from HTTP to HTTPS pages.</para>
  3207. <para>If session hijacking is considered too significant a risk for
  3208. your particular application, the only option is to use HTTPS for every
  3209. request. This means the <literal>jsessionid</literal> is never sent
  3210. across an insecure channel. You will need to ensure your
  3211. <literal>web.xml</literal>-defined
  3212. <literal>&lt;welcome-file&gt;</literal> points to a HTTPS location,
  3213. and the application never directs the user to a HTTP location. The
  3214. Acegi Security System for Spring provides a solution to assist with
  3215. the latter.</para>
  3216. </sect2>
  3217. <sect2 id="security-channels-installation">
  3218. <title>Configuration</title>
  3219. <para>To utilise Acegi Security's channel security services, add the
  3220. following lines to <literal>web.xml</literal>:</para>
  3221. <para><programlisting>&lt;filter&gt;
  3222. &lt;filter-name&gt;Acegi Channel Processing Filter&lt;/filter-name&gt;
  3223. &lt;filter-class&gt;net.sf.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  3224. &lt;init-param&gt;
  3225. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  3226. &lt;param-value&gt;net.sf.acegisecurity.securechannel.ChannelProcessingFilter&lt;/param-value&gt;
  3227. &lt;/init-param&gt;
  3228. &lt;/filter&gt;
  3229. &lt;filter-mapping&gt;
  3230. &lt;filter-name&gt;Acegi Channel Processing Filter&lt;/filter-name&gt;
  3231. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  3232. &lt;/filter-mapping&gt;</programlisting></para>
  3233. <para>As usual when running <literal>FilterToBeanProxy</literal>, you
  3234. will also need to configure the filter in your application
  3235. context:</para>
  3236. <para><programlisting>&lt;bean id="channelProcessingFilter" class="net.sf.acegisecurity.securechannel.ChannelProcessingFilter"&gt;
  3237. &lt;property name="channelDecisionManager"&gt;&lt;ref bean="channelDecisionManager"/&gt;&lt;/property&gt;
  3238. &lt;property name="filterInvocationDefinitionSource"&gt;
  3239. &lt;value&gt;
  3240. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  3241. \A/secure/.*\Z=REQUIRES_SECURE_CHANNEL
  3242. \A/acegilogin.jsp.*\Z=REQUIRES_SECURE_CHANNEL
  3243. \A/j_acegi_security_check.*\Z=REQUIRES_SECURE_CHANNEL
  3244. \A.*\Z=REQUIRES_INSECURE_CHANNEL
  3245. &lt;/value&gt;
  3246. &lt;/property&gt;
  3247. &lt;/bean&gt;
  3248. &lt;bean id="channelDecisionManager" class="net.sf.acegisecurity.securechannel.ChannelDecisionManagerImpl"&gt;
  3249. &lt;property name="channelProcessors"&gt;
  3250. &lt;list&gt;
  3251. &lt;ref bean="secureChannelProcessor"/&gt;
  3252. &lt;ref bean="insecureChannelProcessor"/&gt;
  3253. &lt;/list&gt;
  3254. &lt;/property&gt;
  3255. &lt;/bean&gt;
  3256. &lt;bean id="secureChannelProcessor" class="net.sf.acegisecurity.securechannel.SecureChannelProcessor"/&gt;
  3257. &lt;bean id="insecureChannelProcessor" class="net.sf.acegisecurity.securechannel.InsecureChannelProcessor"/&gt;</programlisting></para>
  3258. <para>Like <literal>FilterSecurityInterceptor</literal>, Apache Ant
  3259. style paths are also supported by the
  3260. <literal>ChannelProcessingFilter</literal>.</para>
  3261. <para>The <literal>ChannelProcessingFilter</literal> operates by
  3262. filtering all web requests and determining the configuration
  3263. attributes that apply. It then delegates to the
  3264. <literal>ChannelDecisionManager</literal>. The default implementation,
  3265. <literal>ChannelDecisionManagerImpl</literal>, should suffice in most
  3266. cases. It simply delegates through the list of configured
  3267. <literal>ChannelProcessor</literal> instances. A
  3268. <literal>ChannelProcessor</literal> will review the request, and if it
  3269. is unhappy with the request (eg it was received across the incorrect
  3270. transport protocol), it will perform a redirect, throw an exception or
  3271. take whatever other action is appropriate.</para>
  3272. <para>Included with the Acegi Security System for Spring are two
  3273. concrete <literal>ChannelProcessor</literal> implementations:
  3274. <literal>SecureChannelProcessor</literal> ensures requests with a
  3275. configuration attribute of <literal>REQUIRES_SECURE_CHANNEL</literal>
  3276. are received over HTTPS, whilst
  3277. <literal>InsecureChannelProcessor</literal> ensures requests with a
  3278. configuration attribute of
  3279. <literal>REQUIRES_INSECURE_CHANNEL</literal> are received over HTTP.
  3280. Both implementations delegate to a
  3281. <literal>ChannelEntryPoint</literal> if the required transport
  3282. protocol is not used. The two <literal>ChannelEntryPoint</literal>
  3283. implementations included with Acegi Security simply redirect the
  3284. request to HTTP and HTTPS as appropriate. Appropriate defaults are
  3285. assigned to the <literal>ChannelProcessor</literal> implementations
  3286. for the configuration attribute keywords they respond to and the
  3287. <literal>ChannelEntryPoint</literal> they delegate to, although you
  3288. have the ability to override these using the application
  3289. context.</para>
  3290. <para>Note that the redirections are absolute (eg
  3291. http://www.company.com:8080/app/page), not relative (eg /app/page).
  3292. During testing it was discovered that Internet Explorer 6 Service Pack
  3293. 1 has a bug whereby it does not respond correctly to a redirection
  3294. instruction which also changes the port to use. Accordingly, absolute
  3295. URLs are used in conjunction with bug detection logic in the
  3296. <literal>PortResolverImpl</literal> that is wired up by default to
  3297. many Acegi Security beans. Please refer to the JavaDocs for
  3298. <literal>PortResolverImpl</literal> for further details.</para>
  3299. </sect2>
  3300. <sect2 id="security-channels-usage">
  3301. <title>Usage</title>
  3302. <para>Once configured, using the channel security filter is very easy.
  3303. Simply request pages without regard to the protocol (ie HTTP or HTTPS)
  3304. or port (eg 80, 8080, 443, 8443 etc). Obviously you'll still need a
  3305. way of making the initial request (probably via the
  3306. <literal>web.xml</literal> <literal>&lt;welcome-file&gt;</literal> or
  3307. a well-known home page URL), but once this is done the filter will
  3308. perform redirects as defined by your application context.</para>
  3309. <para>You can also add your own <literal>ChannelProcessor</literal>
  3310. implementations to the <literal>ChannelDecisionManagerImpl</literal>.
  3311. For example, you might set a <literal>HttpSession</literal> attribute
  3312. when a human user is detected via a "enter the contents of this
  3313. graphic" procedure. Your <literal>ChannelProcessor</literal> would
  3314. respond to say <literal>REQUIRES_HUMAN_USER</literal> configuration
  3315. attributes and redirect to an appropriate entry point to start the
  3316. human user validation process if the <literal>HttpSession</literal>
  3317. attribute is not currently set.</para>
  3318. <para>To decide whether a security check belongs in a
  3319. <literal>ChannelProcessor</literal> or an
  3320. <literal>AccessDecisionVoter</literal>, remember that the former is
  3321. designed to handle unauthenticated requests, whilst the latter is
  3322. designed to handle authenticated requests. The latter therefore has
  3323. access to the granted authorities of the authenticated principal. In
  3324. addition, problems detected by a <literal>ChannelProcessor</literal>
  3325. will generally cause a HTTP/HTTPS redirection so its requirements can
  3326. be met, whilst problems detected by an
  3327. <literal>AccessDecisionVoter</literal> will ultimately result in an
  3328. <literal>AccessDeniedException</literal> (depending on the governing
  3329. <literal>AccessDecisionManager</literal>).</para>
  3330. </sect2>
  3331. </sect1>
  3332. <sect1 id="acls">
  3333. <title>Instance-Based Access Control List (ACL) Security</title>
  3334. <sect2 id="acls-overview">
  3335. <title>Overview</title>
  3336. <para>Complex applications often will find the need to define access
  3337. permissions not simply at a web request or method invocation level.
  3338. Instead, security decisions need to comprise both who
  3339. (<literal>Authentication</literal>), where
  3340. (<literal>MethodInvocation</literal>) and what
  3341. (<literal>SomeDomainObject</literal>). In other words, authorization
  3342. decisions also need to consider the actual domain object instance
  3343. subject of a method invocation.</para>
  3344. <para>Imagine you're designing an application for a pet clinic. There
  3345. will be two main groups of users of your Spring-based application:
  3346. staff of the pet clinic, as well as the pet clinic's customers. The
  3347. staff will have access to all of the data, whilst your customers will
  3348. only be able to see their own customer records. To make it a little
  3349. more interesting, your customers can allow other users to see their
  3350. customer records, such as their "puppy preschool "mentor or president
  3351. of their local "Pony Club". Using Acegi Security System for Spring as
  3352. the foundation, you have several approaches that can be
  3353. used:<orderedlist>
  3354. <listitem>
  3355. <para>Write your business methods to enforce the security. You
  3356. could consult a collection within the
  3357. <literal>Customer</literal> domain object instance to determine
  3358. which users have access. By using the
  3359. <literal>ContextHolder.getContext()</literal> and casting it to
  3360. <literal>SecureContext</literal>, you'll be able to access the
  3361. <literal>Authentication</literal> object.</para>
  3362. </listitem>
  3363. <listitem>
  3364. <para>Write an <literal>AccessDecisionVoter</literal> to enforce
  3365. the security from the <literal>GrantedAuthority[]</literal>s
  3366. stored in the <literal>Authentication</literal> object. This
  3367. would mean your <literal>AuthenticationManager</literal> would
  3368. need to populate the <literal>Authentication</literal> with
  3369. custom <literal>GrantedAuthority</literal>[]s representing each
  3370. of the <literal>Customer</literal> domain object instances the
  3371. principal has access to.</para>
  3372. </listitem>
  3373. <listitem>
  3374. <para>Write an <literal>AccessDecisionVoter</literal> to enforce
  3375. the security and open the target <literal>Customer</literal>
  3376. domain object directly. This would mean your voter needs access
  3377. to a DAO that allows it to retrieve the
  3378. <literal>Customer</literal> object. It would then access the
  3379. <literal>Customer</literal> object's collection of approved
  3380. users and make the appropriate decision.</para>
  3381. </listitem>
  3382. </orderedlist></para>
  3383. <para>Each one of these approaches is perfectly legitimate. However,
  3384. the first couples your authorization checking to your business code.
  3385. The main problems with this include the enhanced difficulty of unit
  3386. testing and the fact it would be more difficult to reuse the
  3387. <literal>Customer</literal> authorization logic elsewhere. Obtaining
  3388. the <literal>GrantedAuthority[]</literal>s from the
  3389. <literal>Authentication</literal> object is also fine, but will not
  3390. scale to large numbers of <literal>Customer</literal>s. If a user
  3391. might be able to access 5,000 <literal>Customer</literal>s (unlikely
  3392. in this case, but imagine if it were a popular vet for a large Pony
  3393. Club!) the amount of memory consumed and time required to construct
  3394. the <literal>Authentication</literal> object would be undesirable. The
  3395. final method, opening the <literal>Customer</literal> directly from
  3396. external code, is probably the best of the three. It achieves
  3397. separation of concerns, and doesn't misuse memory or CPU cycles, but
  3398. it is still inefficient in that both the
  3399. <literal>AccessDecisionVoter</literal> and the eventual business
  3400. method itself will perform a call to the DAO responsible for
  3401. retrieving the <literal>Customer</literal> object. Two accesses per
  3402. method invocation is clearly undesirable. In addition, with every
  3403. approach listed you'll need to write your own access control list
  3404. (ACL) persistence and business logic from scratch.</para>
  3405. <para>Fortunately, there is another alternative, which we'll talk
  3406. about below.</para>
  3407. </sect2>
  3408. <sect2 id="acls-acl-package">
  3409. <title>The net.sf.acegisecurity.acl Package</title>
  3410. <para>The <literal>net.sf.acegisecurity.acl</literal> package is very
  3411. simple, comprising only a handful of interfaces and a single class, as
  3412. shown in Figure 6. It provides the basic foundation for access control
  3413. list (ACL) lookups.</para>
  3414. <para><mediaobject>
  3415. <imageobject role="html">
  3416. <imagedata align="center" fileref="images/ACLSecurity.gif"
  3417. format="GIF" />
  3418. </imageobject>
  3419. <caption>
  3420. <para>Figure 6: Access Control List Manager</para>
  3421. </caption>
  3422. </mediaobject></para>
  3423. <para>The central interface is <literal>AclManager</literal>, which is
  3424. defined by two methods:</para>
  3425. <para><programlisting>public AclEntry[] getAcls(java.lang.Object domainInstance);
  3426. public AclEntry[] getAcls(java.lang.Object domainInstance, Authentication authentication);</programlisting></para>
  3427. <para><literal>AclManager</literal> is intended to be used as a
  3428. collaborator against your business objects, or, more desirably,
  3429. <literal>AccessDecisionVoter</literal>s. This means you use Spring's
  3430. normal <literal>ApplicationContext</literal> features to wire up your
  3431. <literal>AccessDecisionVoter</literal> (or business method) with an
  3432. <literal>AclManager</literal>. Consideration was given to placing the
  3433. ACL information in the <literal>ContextHolder</literal>, but it was
  3434. felt this would be inefficient both in terms of memory usage as well
  3435. as the time spent loading potentially unused ACL information. The
  3436. trade-off of needing to wire up a collaborator for those objects
  3437. requiring ACL information is rather minor, particularly in a
  3438. Spring-managed application.</para>
  3439. <para>The first method of the <literal>AclManager</literal> will
  3440. return all ACLs applying to the domain object instance passed to it.
  3441. The second method does the same, but only returns those ACLs which
  3442. apply to the passed <literal>Authentication</literal> object.</para>
  3443. <para>The <literal>AclEntry</literal> interface returned by
  3444. <literal>AclManager</literal> is merely a marker interface. You will
  3445. need to provide an implementation that reflects that ACL permissions
  3446. for your application.</para>
  3447. <para>Rounding out the <literal>net.sf.acegisecurity.acl</literal>
  3448. package is an <literal>AclProviderManager</literal> class, with a
  3449. corresponding <literal>AclProvider</literal> interface.
  3450. <literal>AclProviderManager</literal> is a concrete implementation of
  3451. <literal>AclManager</literal>, which iterates through registered
  3452. <literal>AclProvider</literal>s. The first
  3453. <literal>AclProvider</literal> that indicates it can authoritatively
  3454. provide ACL information for the presented domain object instance will
  3455. be used. This is very similar to the
  3456. <literal>AuthenticationProvider</literal> interface used for
  3457. authentication.</para>
  3458. <para>With this background, let's now look at a usable ACL
  3459. implementation.</para>
  3460. </sect2>
  3461. <sect2 id="acls-masking">
  3462. <title>Integer Masked ACLs</title>
  3463. <para>Acegi Security System for Spring includes a production-quality
  3464. ACL provider implementation, which is shown in Figure 7.</para>
  3465. <para><mediaobject>
  3466. <imageobject role="html">
  3467. <imagedata align="center" fileref="images/BasicAclProvider.gif"
  3468. format="GIF" />
  3469. </imageobject>
  3470. <caption>
  3471. <para>Figure 7: Basic ACL Manager</para>
  3472. </caption>
  3473. </mediaobject></para>
  3474. <para>The implementation is based on integer masking, which is
  3475. commonly used for ACL permissions given its flexibility and speed.
  3476. Anyone who has used Unix's <literal>chmod</literal> command will know
  3477. all about this type of permission masking (eg <literal>chmod
  3478. 777</literal>). You'll find the classes and interfaces for the integer
  3479. masking ACL package under
  3480. <literal>net.sf.acegisecurity.acl.basic</literal>.</para>
  3481. <para>Extending the <literal>AclEntry</literal> interface is a
  3482. <literal>BasicAclEntry</literal> interface, with the main methods
  3483. shown below:</para>
  3484. <para><programlisting>public AclObjectIdentity getAclObjectIdentity();
  3485. public AclObjectIdentity getAclObjectParentIdentity();
  3486. public int getMask();
  3487. public java.lang.Object getRecipient();</programlisting></para>
  3488. <para>As shown, each <literal>BasicAclEntry</literal> has four main
  3489. properties. The <literal>mask</literal> is the integer that represents
  3490. the permissions granted to the <literal>recipient</literal>. The
  3491. <literal>aclObjectIdentity</literal> is able to identify the domain
  3492. object instance for which the ACL applies, and the
  3493. <literal>aclObjectParentIdentity</literal> optionally specifies the
  3494. parent of the domain object instance. Multiple
  3495. <literal>BasicAclEntry</literal>s usually exist against a single
  3496. domain object instance, and as suggested by the parent identity
  3497. property, permissions granted higher in the object hierarchy will
  3498. trickle down and be inherited (unless blocked by integer zero).</para>
  3499. <para><literal>BasicAclEntry</literal> implementations typically
  3500. provide convenience methods, such as
  3501. <literal>isReadAllowed()</literal>, to avoid application classes
  3502. needing to perform bit masking themselves. The
  3503. <literal>SimpleAclEntry</literal> and
  3504. <literal>AbstractBasicAclEntry</literal> demonstrate and provide much
  3505. of this bit masking logic.</para>
  3506. <para>The <literal>AclObjectIdentity</literal> itself is merely a
  3507. marker interface, so you need to provide implementations for your
  3508. domain objects. However, the package does include a
  3509. <literal>NamedEntityObjectIdentity</literal> implementation which will
  3510. suit many needs. The <literal>NamedEntityObjectIdentity</literal>
  3511. identifies a given domain object instance by the classname of the
  3512. instance and the identity of the instance. A
  3513. <literal>NamedEntityObjectIdentity</literal> can be constructed
  3514. manually (by calling the constructor and providing the classname and
  3515. identity <literal>String</literal>s), or by passing in any domain
  3516. object that contains a <literal>getId()</literal> method.</para>
  3517. <para>The actual <literal>AclProvider</literal> implementation is
  3518. named <literal>BasicAclProvider</literal>. It has adopted a similar
  3519. design to that used by the authentication-related
  3520. <literal>DaoAuthenticationProvder</literal>. Specifically, you define
  3521. a <literal>BasicAclDao</literal> against the provider, so different
  3522. ACL repository types can be accessed in a pluggable manner. The
  3523. <literal>BasicAclProvider</literal> also supports pluggable cache
  3524. providers (with Acegi Security System for Spring including an
  3525. implementation that fronts EH-CACHE).</para>
  3526. <para>The <literal>BasicAclDao</literal> interface is very simple to
  3527. implement:</para>
  3528. <para><programlisting>public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity);</programlisting></para>
  3529. <para>A <literal>BasicAclDao</literal> implementation needs to
  3530. understand the presented <literal>AclObjectIdentity</literal> and how
  3531. it maps to a storage repository, find the relevant records, and create
  3532. appropriate <literal>BasicAclEntry</literal> objects and return
  3533. them.</para>
  3534. <para>Acegi Security includes a single <literal>BasicAclDao</literal>
  3535. implementation called <literal>JdbcDaoImpl</literal>. As implied by
  3536. the name, <literal>JdbcDaoImpl</literal> accesses ACL information from
  3537. a JDBC database. There is also an extended version of this DAO,
  3538. <literal>JdbcExtendedDaoImpl</literal>, which provides CRUD operations
  3539. on the JDBC database, although we won't discuss these features here.
  3540. The default database schema and some sample data will aid in
  3541. understanding its function:</para>
  3542. <para><programlisting>CREATE TABLE acl_object_identity (
  3543. id IDENTITY NOT NULL,
  3544. object_identity VARCHAR_IGNORECASE(250) NOT NULL,
  3545. parent_object INTEGER,
  3546. acl_class VARCHAR_IGNORECASE(250) NOT NULL,
  3547. CONSTRAINT unique_object_identity UNIQUE(object_identity),
  3548. FOREIGN KEY (parent_object) REFERENCES acl_object_identity(id)
  3549. );
  3550. CREATE TABLE acl_permission (
  3551. id IDENTITY NOT NULL,
  3552. acl_object_identity INTEGER NOT NULL,
  3553. recipient VARCHAR_IGNORECASE(100) NOT NULL,
  3554. mask INTEGER NOT NULL,
  3555. CONSTRAINT unique_recipient UNIQUE(acl_object_identity, recipient),
  3556. FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id)
  3557. );
  3558. INSERT INTO acl_object_identity VALUES (1, 'corp.DomainObject:1', null, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');
  3559. INSERT INTO acl_object_identity VALUES (2, 'corp.DomainObject:2', 1, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');
  3560. INSERT INTO acl_object_identity VALUES (3, 'corp.DomainObject:3', 1, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');
  3561. INSERT INTO acl_object_identity VALUES (4, 'corp.DomainObject:4', 1, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');
  3562. INSERT INTO acl_object_identity VALUES (5, 'corp.DomainObject:5', 3, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');
  3563. INSERT INTO acl_object_identity VALUES (6, 'corp.DomainObject:6', 3, 'net.sf.acegisecurity.acl.basic.SimpleAclEntry');
  3564. INSERT INTO acl_permission VALUES (null, 1, 'ROLE_SUPERVISOR', 1);
  3565. INSERT INTO acl_permission VALUES (null, 2, 'ROLE_SUPERVISOR', 0);
  3566. INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);
  3567. INSERT INTO acl_permission VALUES (null, 3, 'scott', 14);
  3568. INSERT INTO acl_permission VALUES (null, 6, 'scott', 1);</programlisting></para>
  3569. <para>As can be seen, database-specific constraints are used
  3570. extensively to ensure the integrity of the ACL information. If you
  3571. need to use a different database (Hypersonic SQL statements are shown
  3572. above), you should try to implement equivalent constraints.</para>
  3573. <para>The <literal>JdbcDaoImpl</literal> will only respond to requests
  3574. for <literal>NamedEntityObjectIdentity</literal>s. It converts such
  3575. identities into a single <literal>String</literal>, comprising
  3576. the<literal> NamedEntityObjectIdentity.getClassname()</literal> +
  3577. <literal>":"</literal> +
  3578. <literal>NamedEntityObjectIdentity.getId()</literal>. This yields the
  3579. type of <literal>object_identity</literal> values shown above. As
  3580. indicated by the sample data, each database row corresponds to a
  3581. single <literal>BasicAclEntry</literal>. As stated earlier and
  3582. demonstrated by <literal>corp.DomainObject:2</literal> in the above
  3583. sample data, each domain object instance will often have multiple
  3584. <literal>BasicAclEntry</literal>[]s.</para>
  3585. <para>As <literal>JdbcDaoImpl</literal> is required to return concrete
  3586. <literal>BasicAclEntry</literal> classes, it needs to know which
  3587. <literal>BasicAclEntry</literal> implementation it is to create and
  3588. populate. This is the role of the <literal>acl_class</literal> column.
  3589. <literal>JdbcDaoImpl</literal> will create the indicated class and set
  3590. its <literal>mask</literal>, <literal>recipient</literal>,
  3591. <literal>aclObjectIdentity</literal> and
  3592. <literal>aclObjectParentIdentity</literal> properties.</para>
  3593. <para>As you can probably tell from the sample data, the
  3594. <literal>parent_object_identity</literal> value can either be null or
  3595. in the same format as the <literal>object_identity</literal>. If
  3596. non-null, <literal>JdbcDaoImpl</literal> will create a
  3597. <literal>NamedEntityObjectIdentity</literal> to place inside the
  3598. returned <literal>BasicAclEntry</literal> class.</para>
  3599. <para>Returning to the <literal>BasicAclProvider</literal>, before it
  3600. can poll the <literal>BasicAclDao</literal> implementation it needs to
  3601. convert the domain object instance it was passed into an
  3602. <literal>AclObjectIdentity</literal>.
  3603. <literal>BasicAclProvider</literal> has a <literal>protected
  3604. AclObjectIdentity obtainIdentity(Object domainInstance)</literal>
  3605. method that is responsible for this. As a protected method, it enables
  3606. subclasses to easily override. The normal implementation checks
  3607. whether the passed domain object instance implements the
  3608. <literal>AclObjectIdentityAware</literal> interface, which is merely a
  3609. getter for an <literal>AclObjectIdentity</literal>. If the domain
  3610. object does implement this interface, that is the identity returned.
  3611. If the domain object does not implement this interface, the method
  3612. will attempt to create an <literal>AclObjectIdentity</literal> by
  3613. passing the domain object instance to the constructor of a class
  3614. defined by the
  3615. <literal>BasicAclProvider.getDefaultAclObjectIdentity()</literal>
  3616. method. By default the defined class is
  3617. <literal>NamedEntityObjectIdentity</literal>, which was described in
  3618. more detail above. Therefore, you will need to either (i) provide a
  3619. <literal>getId()</literal> method on your domain objects, (ii)
  3620. implement <literal>AclObjectIdentityAware</literal> on your domain
  3621. objects, (iii) provide an alternative
  3622. <literal>AclObjectIdentity</literal> implementation that will accept
  3623. your domain object in its constructor, or (iv) override the
  3624. <literal>obtainIdentity(Object)</literal> method.</para>
  3625. <para>Once the <literal>AclObjectIdentity</literal> of the domain
  3626. object instance is determined, the <literal>BasicAclProvider</literal>
  3627. will poll the DAO to obtain its <literal>BasicAclEntry</literal>[]s.
  3628. If any of the entries returned by the DAO indicate there is a parent,
  3629. that parent will be polled, and the process will repeat until there is
  3630. no further parent. The permissions assigned to a
  3631. <literal>recipient</literal> closest to the domain object instance
  3632. will always take priority and override any inherited permissions. From
  3633. the sample data above, the following inherited permissions would
  3634. apply:</para>
  3635. <para><programlisting>--- Mask integer 0 = no permissions
  3636. --- Mask integer 1 = administer
  3637. --- Mask integer 2 = read
  3638. --- Mask integer 6 = read and write permissions
  3639. --- Mask integer 14 = read and write and create permissions
  3640. ---------------------------------------------------------------------
  3641. --- *** INHERITED RIGHTS FOR DIFFERENT INSTANCES AND RECIPIENTS ***
  3642. --- INSTANCE RECIPIENT PERMISSION(S) (COMMENT #INSTANCE)
  3643. ---------------------------------------------------------------------
  3644. --- 1 ROLE_SUPERVISOR Administer
  3645. --- 2 ROLE_SUPERVISOR None (overrides parent #1)
  3646. --- marissa Read
  3647. --- 3 ROLE_SUPERVISOR Administer (from parent #1)
  3648. --- scott Read, Write, Create
  3649. --- 4 ROLE_SUPERVISOR Administer (from parent #1)
  3650. --- 5 ROLE_SUPERVISOR Administer (from parent #3)
  3651. --- scott Read, Write, Create (from parent #3)
  3652. --- 6 ROLE_SUPERVISOR Administer (from parent #3)
  3653. --- scott Administer (overrides parent #3)</programlisting></para>
  3654. <para>So the above explains how a domain object instance has its
  3655. <literal>AclObjectIdentity</literal> discovered, and the
  3656. <literal>BasicAclDao</literal> will be polled successively until an
  3657. array of inherited permissions is constructed for the domain object
  3658. instance. The final step is to determine the
  3659. <literal>BasicAclEntry</literal>[]s that are actually applicable to a
  3660. given <literal>Authentication</literal> object.</para>
  3661. <para>As you would recall, the <literal>AclManager</literal> (and all
  3662. delegates, up to and including <literal>BasicAclProvider</literal>)
  3663. provides a method which returns only those
  3664. <literal>BasicAclEntry</literal>[]s applying to a passed
  3665. <literal>Authentication</literal> object.
  3666. <literal>BasicAclProvider</literal> delivers this functionality by
  3667. delegating the filtering operation to an
  3668. <literal>EffectiveAclsResolver</literal> implementation. The default
  3669. implementation,
  3670. <literal>GrantedAuthorityEffectiveAclsResolver</literal>, will iterate
  3671. through the <literal>BasicAclEntry</literal>[]s and include only those
  3672. where the <literal>recipient</literal> is equal to either the
  3673. <literal>Authentication</literal>'s <literal>principal</literal> or
  3674. any of the <literal>Authentication</literal>'s
  3675. <literal>GrantedAuthority</literal>[]s. Please refer to the JavaDocs
  3676. for more information.</para>
  3677. </sect2>
  3678. <sect2 id="acls-conclusion">
  3679. <title>Conclusion</title>
  3680. <para>Acegi Security's instance-specific ACL packages shield you from
  3681. much of the complexity of developing your own ACL approach. The
  3682. interfaces and classes detailed above provide a scalable, customisable
  3683. ACL solution that is decoupled from your application code. Whilst the
  3684. reference documentation may suggest complexity, the basic
  3685. implementation is able to support most typical applications
  3686. out-of-the-box.</para>
  3687. </sect2>
  3688. </sect1>
  3689. <sect1 id="security-filters">
  3690. <title>Filters</title>
  3691. <sect2 id="security-filters-overview">
  3692. <title>Overview</title>
  3693. <para>The Acegi Security System for Spring uses filters extensively.
  3694. Each filter is covered in detail in a respective section of this
  3695. document. This section includes information that applies to all
  3696. filters.</para>
  3697. </sect2>
  3698. <sect2 id="security-filters-filtertobeanproxy">
  3699. <title>FilterToBeanProxy</title>
  3700. <para>Most filters are configured using the
  3701. <literal>FilterToBeanProxy</literal>. An example configuration from
  3702. <literal>web.xml</literal> follows:</para>
  3703. <para><programlisting>&lt;filter&gt;
  3704. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  3705. &lt;filter-class&gt;net.sf.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  3706. &lt;init-param&gt;
  3707. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  3708. &lt;param-value&gt;net.sf.acegisecurity.ClassThatImplementsFilter&lt;/param-value&gt;
  3709. &lt;/init-param&gt;
  3710. &lt;/filter&gt;</programlisting></para>
  3711. <para>Notice that the filter in <literal>web.xml</literal> is actually
  3712. a <literal>FilterToBeanProxy</literal>, and not the filter that will
  3713. actually implements the logic of the filter. What
  3714. <literal>FilterToBeanProxy</literal> does is delegate the
  3715. <literal>Filter</literal>'s methods through to a bean which is
  3716. obtained from the Spring application context. This enables the bean to
  3717. benefit from the Spring application context lifecycle support and
  3718. configuration flexibility. The bean must implement
  3719. <literal>javax.servlet.Filter</literal>.</para>
  3720. <para>The <literal>FilterToBeanProxy</literal> only requires a single
  3721. initialization parameter, <literal>targetClass</literal> or
  3722. <literal>targetBean</literal>. The <literal>targetClass</literal>
  3723. parameter locates the first object in the application context of the
  3724. specified class, whilst <literal>targetBean</literal> locates the
  3725. object by bean name. Like standard Spring web applications, the
  3726. <literal>FilterToBeanProxy</literal> accesses the application context
  3727. via<literal>
  3728. WebApplicationContextUtils.getWebApplicationContext(ServletContext)</literal>,
  3729. so you should configure a <literal>ContextLoaderListener</literal> in
  3730. <literal>web.xml</literal>.</para>
  3731. <para>There is a lifecycle issue to consider when hosting
  3732. <literal>Filter</literal>s in an IoC container instead of a servlet
  3733. container. Specifically, which container should be responsible for
  3734. calling the <literal>Filter</literal>'s "startup" and "shutdown"
  3735. methods? It is noted that the order of initialization and destruction
  3736. of a <literal>Filter</literal> can vary by servlet container, and this
  3737. can cause problems if one <literal>Filter</literal> depends on
  3738. configuration settings established by an earlier initialized
  3739. <literal>Filter</literal>. The Spring IoC container on the other hand
  3740. has more comprehensive lifecycle/IoC interfaces (such as
  3741. <literal>InitializingBean</literal>,
  3742. <literal>DisposableBean</literal>, <literal>BeanNameAware</literal>,
  3743. <literal>ApplicationContextAware</literal> and many others) as well as
  3744. a well-understood interface contract, predictable method invocation
  3745. ordering, autowiring support, and even options to avoid implementing
  3746. Spring interfaces (eg the <literal>destroy-method</literal> attribute
  3747. in Spring XML). For this reason we recommend the use of Spring
  3748. lifecycle services instead of servlet container lifecycle services
  3749. wherever possible. By default <literal>FilterToBeanProxy</literal>
  3750. will not delegate <literal>init(FilterConfig)</literal> and
  3751. <literal>destroy()</literal> methods through to the proxied bean. If
  3752. you do require such invocations to be delegated, set the
  3753. <literal>lifecycle</literal> initialization parameter to
  3754. <literal>servlet-container-managed</literal>.</para>
  3755. </sect2>
  3756. <sect2 id="security-filters-filterchainproxy">
  3757. <title>FilterChainProxy</title>
  3758. <para>Whilst <literal>FilterToBeanProxy</literal> is a very useful
  3759. class, the problem is that the lines of code required for
  3760. <literal>&lt;filter&gt;</literal> and
  3761. <literal>&lt;filter-mapping&gt;</literal> entries in
  3762. <literal>web.xml</literal> explodes when using more than a few
  3763. filters. To overcome this issue, Acegi Security provides a
  3764. <literal>FilterChainProxy</literal> class. It is wired using a
  3765. <literal>FilterToBeanProxy</literal> (just like in the example above),
  3766. but the target class is
  3767. <literal>net.sf.acegisecurity.util.FilterChainProxy</literal>. The
  3768. filter chain is then declared in the application context, using code
  3769. such as this:</para>
  3770. <para><programlisting>&lt;bean id="filterChainProxy" class="net.sf.acegisecurity.util.FilterChainProxy"&gt;
  3771. &lt;property name="filterInvocationDefinitionSource"&gt;
  3772. &lt;value&gt;
  3773. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  3774. PATTERN_TYPE_APACHE_ANT
  3775. /webServices/**=httpSessionContextIntegrationFilterWithASCFalse,basicProcessingFilter,securityEnforcementFilter
  3776. /**=httpSessionContextIntegrationFilterWithASCTrue,authenticationProcessingFilter,securityEnforcementFilter
  3777. &lt;/value&gt;
  3778. &lt;/property&gt;
  3779. &lt;/bean&gt;</programlisting></para>
  3780. <para>You may notice similarities with the way
  3781. <literal>SecurityEnforcementFilter</literal> is declared. Both regular
  3782. expressions and Ant Paths are supported, and the most specific URIs
  3783. appear first. At runtime the <literal>FilterChainProxy</literal> will
  3784. locate the first URI pattern that matches the current web request.
  3785. Each of the corresponding configuration attributes represent the name
  3786. of a bean defined in the application context. The filters will then be
  3787. invoked in the order they are specified, with standard
  3788. <literal>FilterChain</literal> behaviour being respected (a
  3789. <literal>Filter</literal> can elect not to proceed with the chain if
  3790. it wishes to end processing).</para>
  3791. <para>As you can see, <literal>FitlerChainProxy</literal> requires the
  3792. duplication of filter names for different request patterns (in the
  3793. above example, <literal>httpSessionContextIntegrationFilter</literal>
  3794. and <literal>securityEnforcementFilter</literal> are duplicated). This
  3795. design decision was made to enable <literal>FilterChainProxy</literal>
  3796. to specify different <literal>Filter</literal> invocation orders for
  3797. different URI patterns, and also to improve both the expressiveness
  3798. (in terms of regular expressions, Ant Paths, and any custom
  3799. <literal>FilterInvocationDefinitionSource</literal> implementations)
  3800. and clarity of which <literal>Filter</literal>s should be
  3801. invoked.</para>
  3802. <para>You may have noticed we have declared two
  3803. <literal>HttpSessionContextIntegrationFilter</literal>s in the filter
  3804. chain (<literal>ASC</literal> is short for
  3805. <literal>allowSessionCreation</literal>, a property of
  3806. <literal>HttpSessionContextIntegrationFilter</literal>). As web
  3807. services will never present a <literal>jsessionid</literal> on future
  3808. requests, creating <literal>HttpSession</literal>s for such user
  3809. agents would be wasteful. If you had a high-volume application which
  3810. required maximum scalability, we recommend you use the approach shown
  3811. above. For smaller applications, using a single
  3812. <literal>HttpSessionContextIntegrationFilter</literal> (with its
  3813. default <literal>allowSessionCreation</literal> as
  3814. <literal>true</literal>) would likely be sufficient.</para>
  3815. <para>In relation to lifecycle issues, the
  3816. <literal>FilterChainProxy</literal> will always delegate
  3817. <literal>init(FilterConfig)</literal> and <literal>destroy()</literal>
  3818. methods through to the underlaying <literal>Filter</literal>s if such
  3819. methods are called against <literal>FilterChainProxy</literal> itself.
  3820. In this case, <literal>FilterChainProxy</literal> guarantees to only
  3821. initialize and destroy each <literal>Filter</literal> once,
  3822. irrespective of how many times it is declared by the
  3823. <literal>FilterInvocationDefinitionSource</literal>. You control the
  3824. overall choice as to whether these methods are called or not via the
  3825. <literal>lifecycle</literal> initialization parameter of the
  3826. <literal>FilterToBeanProxy</literal> that proxies
  3827. <literal>FilterChainProxy</literal>. As discussed above, by default
  3828. any servlet container lifecycle invocations are not delegated through
  3829. to <literal>FilterChainProxy</literal>.</para>
  3830. </sect2>
  3831. <sect2 id="security-filters-order">
  3832. <title>Filter Ordering</title>
  3833. <para>The order that filters are defined in <literal>web.xml</literal>
  3834. is important. NB: THE FILTER ORDER CHANGED FROM VERSION 0.8.0.</para>
  3835. <para>Irrespective of which filters you are actually using, the order
  3836. of the <literal>&lt;filter-mapping&gt;</literal>s should be as
  3837. follows:</para>
  3838. <orderedlist>
  3839. <listitem>
  3840. <para><literal>ChannelProcessingFilter</literal>, because it might
  3841. need to redirect to a different protocol</para>
  3842. </listitem>
  3843. <listitem>
  3844. <para><literal>HttpSessionContextIntegrationFilter</literal>, so a
  3845. <literal>Context</literal> can be setup in the
  3846. <literal>ContextHolder</literal> at the beginning of a web
  3847. request, and any changes to the Context can be copied to the
  3848. <literal>HttpSession</literal> when the web request ends (ready
  3849. for use with the next web request)</para>
  3850. </listitem>
  3851. <listitem>
  3852. <para>Authentication processing mechanisms -
  3853. <literal>AuthenticationProcessingFilter</literal>,
  3854. <literal>CasProcessingFilter</literal>,
  3855. <literal>BasicProcessingFilter, HttpRequestIntegrationFilter,
  3856. JbossIntegrationFilter</literal> etc - so that the
  3857. <literal>ContextHolder</literal> can be modified to contain a
  3858. valid <literal>Authentication</literal> request token</para>
  3859. </listitem>
  3860. <listitem>
  3861. <para>The <literal>ContextHolderAwareRequestFilter</literal>, if
  3862. you are using it to install an Acegi Security aware
  3863. <literal>HttpServletRequestWrapper</literal> into your servlet
  3864. container</para>
  3865. </listitem>
  3866. <listitem>
  3867. <para><literal>AnonymousProcessingFilter</literal>, so that if no
  3868. earlier authentication processing mechanism updated the
  3869. <literal>ContextHolder</literal>, an anonymous
  3870. <literal>Authentication</literal> object will be put there</para>
  3871. </listitem>
  3872. <listitem>
  3873. <para><literal>SecurityEnforcementFilter</literal>, to protect web
  3874. URIs and catch any Acegi Security exceptions so that an
  3875. appropriate <literal>AuthenticationEntryPoint</literal> can be
  3876. launched</para>
  3877. </listitem>
  3878. </orderedlist>
  3879. <para>All of the above filters use
  3880. <literal>FilterToBeanProxy</literal> or
  3881. <literal>FilterChainProxy</literal>, which is discussed in the
  3882. previous sections. It is recommended that a single
  3883. <literal>FilterToBeProxy</literal> proxy through to a single
  3884. <literal>FilterChainProxy</literal> for each application, with that
  3885. <literal>FilterChainProxy</literal> defining all of the Acegi Security
  3886. <literal>Filter</literal>s.</para>
  3887. <para>If you're using SiteMesh, ensure the Acegi Security filters
  3888. execute before the SiteMesh filters are called. This enables the
  3889. <literal>ContextHolder</literal> to be populated in time for use by
  3890. SiteMesh decorators.</para>
  3891. </sect2>
  3892. </sect1>
  3893. <sect1 id="security-sample">
  3894. <title>Contacts Sample Application</title>
  3895. <para>Included with the Acegi Security System for Spring is a very
  3896. simple application that can demonstrate the basic security facilities
  3897. provided by the system (and confirm your Container Adapter is properly
  3898. configured if you're using one).</para>
  3899. <para>If you build from CVS, the Contacts sample application includes
  3900. three deployable versions:
  3901. <literal>acegi-security-sample-contacts-filter.war</literal> is
  3902. configured with the HTTP Session Authentication approach. The
  3903. <literal><literal>acegi-security-sample-contacts-ca.war</literal></literal>
  3904. is configured to use a Container Adapter. Finally,
  3905. <literal>acegi-security-sample-contacts-cas.war</literal> is designed to
  3906. work with a Yale CAS server. If you're just wanting to see how the
  3907. sample application works, please use
  3908. <literal><literal>acegi-security-sample-contacts-filter.war</literal></literal>
  3909. as it does not require special configuration of your container. This is
  3910. also the artifact included in ofiical release ZIPs.</para>
  3911. <para>To deploy, simply copy the relevant WAR file from the Acegi
  3912. Security System for Spring distribution into your container’s
  3913. <literal>webapps</literal> directory.</para>
  3914. <para>After starting your container, check the application can load.
  3915. Visit
  3916. <literal>http://localhost:</literal><literal><literal>8080/</literal>acegi-security-sample-contacts-filter</literal>
  3917. (or whichever URL is appropriate for your web container and the WAR you
  3918. deployed). A random contact should be displayed. Click "Refresh" several
  3919. times and you will see different contacts. The business method that
  3920. provides this random contact is not secured.</para>
  3921. <para>Next, click "Debug". You will be prompted to authenticate, and a
  3922. series of usernames and passwords are suggested on that page. Simply
  3923. authenticate with any of these and view the resulting page. It should
  3924. contain a success message similar to the following:</para>
  3925. <blockquote>
  3926. <para>Context on ContextHolder is of type:
  3927. net.sf.acegisecurity.context.secure.SecureContextImpl</para>
  3928. <para>The Context implements SecureContext.</para>
  3929. <para>Authentication object is of type:
  3930. net.sf.acegisecurity.adapters.PrincipalAcegiUserToken</para>
  3931. <para>Authentication object as a String:
  3932. net.sf.acegisecurity.adapters.PrincipalAcegiUserToken@e9a7c2:
  3933. Username: marissa; Password: [PROTECTED]; Authenticated: true; Granted
  3934. Authorities: ROLE_TELLER, ROLE_SUPERVISOR</para>
  3935. <para>Authentication object holds the following granted
  3936. authorities:</para>
  3937. <para>ROLE_TELLER (getAuthority(): ROLE_TELLER)</para>
  3938. <para>ROLE_SUPERVISOR (getAuthority(): ROLE_SUPERVISOR)</para>
  3939. <para>SUCCESS! Your [container adapter|web filter] appears to be
  3940. properly configured!</para>
  3941. </blockquote>
  3942. <para>If you receive a different message, and deployed
  3943. <literal>acegi-security-sample-contacts-ca.war</literal>, check you have
  3944. properly configured your Container Adapter as described elsewhere in
  3945. this reference guide.</para>
  3946. <para>Once you successfully receive the above message, return to the
  3947. sample application's home page and click "Manage". You can then try out
  3948. the application. Notice that only the contacts available to the
  3949. currently logged on user are displayed, and only users with
  3950. <literal>ROLE_SUPERVISOR</literal> are granted access to delete their
  3951. contacts. Behind the scenes, the
  3952. <literal>MethodSecurityInterceptor</literal> is securing the business
  3953. objects. If you're using
  3954. <literal><literal>acegi-security-sample-contacts-filter.war</literal></literal>
  3955. or <literal>acegi-security-sample-contacts-cas.war</literal>, the
  3956. <literal>FilterSecurityInterceptor</literal> is also securing the HTTP
  3957. requests. If using either of these WARs, be sure to try visiting
  3958. <literal>http://localhost:8080/contacts/secure/super</literal>, which
  3959. will demonstrate access being denied by the
  3960. <literal>SecurityEnforcementFilter</literal>. Note the sample
  3961. application enables you to modify the access control lists associated
  3962. with different contacts. Be sure to give this a try and understand how
  3963. it works by reviewing the sample application's application context XML
  3964. files.</para>
  3965. <para>The Contacts sample application also include a
  3966. <literal>client</literal> directory. Inside you will find a small
  3967. application that queries the backend business objects using several web
  3968. services protocols. This demonstrates how to use the Acegi Security
  3969. System for Spring for authentication with Spring remoting protocols. To
  3970. try this client, ensure your servlet container is still running the
  3971. Contacts sample application, and then execute <literal>client marissa
  3972. koala</literal>. The command-line parameters respectively represent the
  3973. username to use, and the password to use. Note that you may need to edit
  3974. <literal>client.properties</literal> to use a different target
  3975. URL.</para>
  3976. <para>Please note the sample application's <literal>client</literal>
  3977. does not currently support CAS. You can still give it a try, though, if
  3978. you're ambitious: try <literal>client _cas_stateless_
  3979. YOUR-SERVICE-TICKET-ID</literal>.</para>
  3980. </sect1>
  3981. <sect1 id="security-become-involved">
  3982. <title>Become Involved</title>
  3983. <para>We welcome you to become involved in the Acegi Security System for
  3984. Spring project. There are many ways of contributing, including reading
  3985. the mailing list and responding to questions from other people, writing
  3986. new code, improving existing code, assisting with documentation, or
  3987. simply making suggestions.</para>
  3988. <para>SourceForge provides CVS services for the project, allowing
  3989. anybody to access the latest code. If you wish to contribute new code,
  3990. please observe the following requirements. These exist to maintain the
  3991. quality and consistency of the project:</para>
  3992. <itemizedlist>
  3993. <listitem>
  3994. <para>Use a suitable IDE Jalopy plug-in to convert your code into
  3995. the project's consistent style</para>
  3996. </listitem>
  3997. <listitem>
  3998. <para>Ensure your code does not break any unit tests (run the Maven
  3999. <literal>test:test</literal> goal)</para>
  4000. </listitem>
  4001. <listitem>
  4002. <para>If you have added new code, please provide suitable unit tests
  4003. (use the Maven <literal>clover:html-report</literal> to view
  4004. coverage)</para>
  4005. </listitem>
  4006. <listitem>
  4007. <para>Join the acegisecurity-developer and acegisecurity-cvs mailing
  4008. lists so you're in the loop</para>
  4009. </listitem>
  4010. <listitem>
  4011. <para>Use CamelCase</para>
  4012. </listitem>
  4013. <listitem>
  4014. <para>Add a CVS <literal>$Id: index.xml,v 1.3 2004/04/02 21:12:25
  4015. fbos Exp $</literal> tag to the JavaDocs for any new class you
  4016. create</para>
  4017. </listitem>
  4018. </itemizedlist>
  4019. </sect1>
  4020. <sect1 id="security-further">
  4021. <title>Further Information</title>
  4022. <para>Questions and comments on the Acegi Security System for Spring are
  4023. welcome. Please use the Spring Community Forum web site at
  4024. <literal>http://forum.springframework.org</literal>. You're also welcome
  4025. to join the acegisecurity-developer mailing list. Our project home page
  4026. (where you can obtain the latest release of the project and access to
  4027. CVS, mailing lists, forums etc) is at
  4028. <literal>http://acegisecurity.sourceforge.net</literal>.</para>
  4029. </sect1>
  4030. </chapter>
  4031. </book>