acegi.xml 265 KB

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