acegi.xml 313 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048
  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</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>Acegi Security provides a comprehensive security solution for
  39. J2EE-based enterprise software applications. As you will discover as you
  40. venture through this reference guide, we have tried to provide you a
  41. useful and highly configurable security system.</para>
  42. <para>Security is an ever-moving target, and it's important to pursue a
  43. comprehensive, system-wide approach. In security circles we encourage you
  44. to adopt "layers of security", so that each layer tries to be as secure as
  45. possible in its own right, with successive layers providing additional
  46. security. The "tighter" the security of each layer, the more robust and
  47. safe your application will be. At the bottom level you'll need to deal
  48. with issues such as transport security and system identification, in order
  49. to mitigate man-in-the-middle attacks. Next you'll generally utilise
  50. firewalls, perhaps with VPNs or IP security to ensure only authorised
  51. systems can attempt to connect. In corporate environments you may deploy a
  52. DMZ to separate public-facing servers from backend database and
  53. application servers. Your operating system will also play a critical part,
  54. addressing issues such as running processes as non-privileged users and
  55. maximising file system security. An operating system will usually also be
  56. configured with its own firewall. Hopefully somewhere along the way you'll
  57. be trying to prevent denial of service and brute force attacks against the
  58. system. An intrusion detection system will also be especially useful for
  59. monitoring and responding to attacks, with such systems able to take
  60. protective action such as blocking offending TCP/IP addresses in
  61. real-time. Moving to the higher layers, your Java Virtual Machine will
  62. hopefully be configured to minimize the permissions granted to different
  63. Java types, and then your application will add its own problem
  64. domain-specific security configuration. Acegi Security makes this latter
  65. area - application security - much easier.</para>
  66. <para>Of course, you will need to properly address all security layers
  67. mentioned above, together with managerial factors that encompass every
  68. layer. A non-exhaustive list of such managerial factors would include
  69. security bulletin monitoring, patching, personnel vetting, audits, change
  70. control, engineering management systems, data backup, disaster recovery,
  71. performance benchmarking, load monitoring, centralised logging, incident
  72. response procedures etc.</para>
  73. <para>With Acegi Security being focused on helping you with the enterprise
  74. application security layer, you will find that there are as many different
  75. requirements as there are business problem domains. A banking application
  76. has different needs from an ecommerce application. An ecommerce
  77. application has different needs from a corporate sales force automation
  78. tool. These custom requirements make application security interesting,
  79. challenging and rewarding.</para>
  80. <para>This reference guide has been largely restructured for the 1.0.0
  81. release of Acegi Security. Please read Part I, <link
  82. linkend="overall-architecture">Overall Architecture</link>, in its
  83. entirety. The remaining parts of the reference guide are structured in a
  84. more traditional reference style, designed to be read on an as-required
  85. basis.</para>
  86. <para>We hope that you find this reference guide useful, and we welcome
  87. your feedback and <link linkend="jira">suggestions</link>.</para>
  88. <para>Finally, welcome to the Acegi Security <link
  89. linkend="community">community</link>.</para>
  90. </preface>
  91. <part id="overall-architecture">
  92. <title>Overall Architecture</title>
  93. <partintro>
  94. <para>Like most software, Acegi Security has certain central interfaces,
  95. classes and conceptual abstractions that are commonly used throughout
  96. the framework. In this part of the reference guide we will introduce
  97. Acegi Security, before examining these central elements that are
  98. necessary to successfully planning and executing an Acegi Security
  99. integration.</para>
  100. </partintro>
  101. <chapter id="introduction">
  102. <title>Introduction</title>
  103. <sect1 id="before-you-begin">
  104. <title>Before You Begin</title>
  105. <para>For your security, each official release JAR of Acegi Security
  106. has been signed by the project leader. This does not in any way alter
  107. the liability disclaimer contained in the License, but it does ensure
  108. you are using a properly reviewed, official build of Acegi Security.
  109. Please refer to the <literal>readme.txt</literal> file in the root of
  110. the release distribution for instructions on how to validate the JARs
  111. are correctly signed, and which certificate has been used to sign
  112. them.</para>
  113. </sect1>
  114. <sect1 id="what-is-acegi-security">
  115. <title>What is Acegi Security?</title>
  116. <para>Acegi Security provides comprehensive security services for
  117. J2EE-based enterprise software applications. There is a particular
  118. emphasis on supporting projects built using The Spring Framework,
  119. which is the leading J2EE solution for enterprise software
  120. development. If you're not using Spring for developing enterprise
  121. applications, we warmly encourage you to take a closer look at it.
  122. Some familiarity with Spring - and in particular dependency injection
  123. principles - will help you get up to speed with Acegi Security more
  124. easily.</para>
  125. <para>People use Acegi Security for many reasons, but most are drawn
  126. to the project after finding the security features of J2EE's Servlet
  127. Specification or EJB Specification lack the depth required for typical
  128. enterprise application scenarios. Whilst mentioning these standards,
  129. it's important to recognise that they are not portable at a WAR or EAR
  130. level. Therefore, if you switch server environments, it is typically a
  131. lot of work to reconfigure your application's security in the new
  132. target environment. Using Acegi Security overcomes these problems, and
  133. also brings you dozens of other useful, entirely customisable security
  134. features.</para>
  135. <para>As you probably know, security comprises two major operations.
  136. The first is known as "authentication", which is the process of
  137. establishing a principal is who they claim to be. A "principal"
  138. generally means a user, device or some other system which can perform
  139. an action in your application. "Authorization" refers to the process
  140. of deciding whether a principal is allowed to perform an action in
  141. your application. To arrive at the point where an authorization
  142. decision is needed, the identity of the principal has already been
  143. established by the authentication process. These concepts are common,
  144. and not at all specific to Acegi Security.</para>
  145. <para>At an authentication level, Acegi Security supports a wide range
  146. of authentication models. Most of these authentication models are
  147. either provided by third parties, or are developed by relevant
  148. standards bodies such as the Internet Engineering Task Force. In
  149. addition, Acegi Security provides its own set of authentication
  150. features. Specifically, Acegi Security currently supports
  151. authentication with all of these technologies:</para>
  152. <itemizedlist spacing="compact">
  153. <listitem>
  154. <para>HTTP BASIC authentication headers (an IEFT RFC-based
  155. standard)</para>
  156. </listitem>
  157. <listitem>
  158. <para>HTTP Digest authentication headers (an IEFT RFC-based
  159. standard)</para>
  160. </listitem>
  161. <listitem>
  162. <para>HTTP X.509 client certificate exchange (an IEFT RFC-based
  163. standard)</para>
  164. </listitem>
  165. <listitem>
  166. <para>LDAP (a very common approach to cross-platform
  167. authentication needs, especially in large environments)</para>
  168. </listitem>
  169. <listitem>
  170. <para>Form-based authentication (for simple user interface
  171. needs)</para>
  172. </listitem>
  173. <listitem>
  174. <para>Computer Associates Siteminder</para>
  175. </listitem>
  176. <listitem>
  177. <para>JA-SIG Central Authentication Service (otherwise known as
  178. CAS, which is a popular open source single sign on system)</para>
  179. </listitem>
  180. <listitem>
  181. <para>Transparent authentication context propagation for Remote
  182. Method Invocation (RMI) and HttpInvoker (a Spring remoting
  183. protocol)</para>
  184. </listitem>
  185. <listitem>
  186. <para>Automatic "remember-me" authentication (so you can tick a
  187. box to avoid re-authentication for a predetermined period of
  188. time)</para>
  189. </listitem>
  190. <listitem>
  191. <para>Anonymous authentication (allowing every call to
  192. automatically assume a particular security identity)</para>
  193. </listitem>
  194. <listitem>
  195. <para>Run-as authentication (which is useful if one call should
  196. proceed with a different security identity)</para>
  197. </listitem>
  198. <listitem>
  199. <para>Java Authentication and Authorization Service (JAAS)</para>
  200. </listitem>
  201. <listitem>
  202. <para>Container integration with JBoss, Jetty, Resin and Tomcat
  203. (so you can still use Container Manager Authentication if
  204. desired)</para>
  205. </listitem>
  206. <listitem>
  207. <para>Your own authentication systems (see below)</para>
  208. </listitem>
  209. </itemizedlist>
  210. <para>Many independent software vendors (ISVs) adopt Acegi Security
  211. because of this rich choice of authentication models. Doing so allows
  212. them to quickly integrate their solutions with whatever their end
  213. clients need, without undertaking a lot of engineering or requiring
  214. the client to change their environment. If none of the above
  215. authentication mechanisms suit your needs, Acegi Security is an open
  216. platform and it is quite simple to write your own authentication
  217. mechanism. Many corporate users of Acegi Security need to integrate
  218. with "legacy" systems that don't follow any particular security
  219. standards, and Acegi Security is happy to "play nicely" with such
  220. systems.</para>
  221. <para>Sometimes the mere process of authentication isn't enough.
  222. Sometimes you need to also differentiate security based on the way a
  223. principal is interacting with your application. For example, you might
  224. want to ensure requests only arrive over HTTPS, in order to protect
  225. passwords from eavesdropping or end users from man-in-the-middle
  226. attacks. Or, you might want to ensure that an actual human being is
  227. making the requests and not some robot or other automated process.
  228. This is especially helpful to protect password recovery processes from
  229. brute force attacks, or simply to make it harder for people to
  230. duplicate your application's key content. To help you achieve these
  231. goals, Acegi Security fully supports automatic "channel security",
  232. together with JCaptcha integration for human user detection.</para>
  233. <para>Irrespective of how authentication was undertaken, Acegi
  234. Security provides a deep set of authorization capabilities. There are
  235. three main areas of interest in respect of authorization, these being
  236. authorizing web requests, authorizing methods can be invoked, and
  237. authorizing access to individual domain object instances. To help you
  238. understand the differences, consider the authorization capabilities
  239. found in the Servlet Specification web pattern security, EJB Container
  240. Managed Security and file system security respectively. Acegi Security
  241. provides deep capabilities in all of these important areas, which
  242. we'll explore later in this reference guide.</para>
  243. </sect1>
  244. <sect1 id="history">
  245. <title>History</title>
  246. <para>Acegi Security began in late 2003, when a question was posed on
  247. the Spring Developers' mailing list asking whether there had been any
  248. consideration given to a Spring-based security implementation. At the
  249. time the Spring community was relatively small (especially by today's
  250. size!), and indeed Spring itself had only existed as a SourceForge
  251. project from early 2003. The response to the question was that it was
  252. a worthwhile area, although a lack of time currently prevented its
  253. exploration.</para>
  254. <para>With that in mind, a simple security implementation was built
  255. and not released. A few weeks later another member of the Spring
  256. community inquired about security, and at the time this code was
  257. offered to them. Several other requests followed, and by January 2004
  258. around twenty people were using the code. These pioneering users were
  259. joined by others who suggested a SourceForge project was in order,
  260. which was duly established in March 2004.</para>
  261. <para>In those early days, the project didn't have any of its own
  262. authentication modules. Container Managed Security was relied upon for
  263. the authentication process, with Acegi Security instead focusing on
  264. authorization. This was suitable at first, but as more and more users
  265. requested additional container support, the fundamental limitation of
  266. container-specific authentication realm interfaces was experienced.
  267. There was also a related issue of adding new JARs to the container's
  268. classpath, which was a common source of end user confusion and
  269. misconfiguration.</para>
  270. <para>Acegi Security-specific authentication services were
  271. subsequently introduced. Around a year later, the Acegi Security
  272. became an official Spring Framework subproject. The 1.0.0 final
  273. release was published in May 2006 - after more than two and a half
  274. years of active use in numerous production software projects and many
  275. hundreds of improvements and community contributions.</para>
  276. <para>Today Acegi Security enjoys a strong and active open source
  277. community. There are thousands of messages about Acegi Security on the
  278. support forums. Fourteen developers work on the code itself, with an
  279. active community who also regularly share patches and support their
  280. peers.</para>
  281. </sect1>
  282. <sect1 id="release-numbering">
  283. <title>Release Numbering</title>
  284. <para>It is useful to understand how Acegi Security release numbers
  285. work, as it will help you identify the effort (or lack thereof)
  286. involved in migrating to future releases of the project. Officially,
  287. we use the Apache Portable Runtime Project versioning guidelines,
  288. which can be viewed at
  289. <literal>http://apr.apache.org/versioning.html</literal>. We quote the
  290. introduction contained on that page for your convenience:</para>
  291. <para><quote>Versions are denoted using a standard triplet of
  292. integers: MAJOR.MINOR.PATCH. The basic intent is that MAJOR versions
  293. are incompatible, large-scale upgrades of the API. MINOR versions
  294. retain source and binary compatibility with older minor versions, and
  295. changes in the PATCH level are perfectly compatible, forwards and
  296. backwards.</quote></para>
  297. </sect1>
  298. </chapter>
  299. <chapter id="technical-overview">
  300. <title>Technical Overview</title>
  301. <sect1 id="runtime-environment">
  302. <title>Runtime Environment</title>
  303. <para>Acegi Security is written to execute within a standard Java 1.3
  304. Runtime Environment. It also supports Java 5.0, although the Java
  305. types which are specific to this release are packaged in a separate
  306. package with the suffix "tiger" in their JAR filename. As Acegi
  307. Security aims to operate in a self-contained manner, there is no need
  308. to place any special configuration files into your Java Runtime
  309. Environment. In particular, there is no need to configure a special
  310. Java Authentication and Authorization Service (JAAS) policy file or
  311. place Acegi Security into common classpath locations.</para>
  312. <para>Similarly, if you are using an EJB Container or Servlet
  313. Container there is no need to put any special configuration files
  314. anywhere, nor include Acegi Security in a server classloader.</para>
  315. <para>This above design offers maximum deployment time flexibility, as
  316. you can simply copy your target artifact (be it a JAR, WAR or EAR)
  317. from one system to another and it will immediately work.</para>
  318. </sect1>
  319. <sect1 id="shared-components">
  320. <title>Shared Components</title>
  321. <para>Let's explore some of the most important shared components in
  322. Acegi Security. Components are considered "shared" if they are central
  323. to the framework and the framework cannot operate without them. These
  324. Java types represent the building blocks of the remaining system, so
  325. it's important to understand that they're there, even if you don't
  326. need to directly interact with them.</para>
  327. <para>The most fundamental object is
  328. <literal>SecurityContextHolder</literal>. This is where we store
  329. details of the present security context of the application, which
  330. includes details of the principal currently using the application. By
  331. default the <literal>SecurityContextHolder</literal> uses a
  332. <literal>ThreadLocal</literal> to store these details, which means
  333. that the security context is always available to methods in the same
  334. thread of execution, even if the security context is not explicitly
  335. passed around as an argument those methods. Using a
  336. <literal>ThreadLocal</literal> in this way is quite safe if care is
  337. taken to clear the thread after the present principal's request is
  338. processed. Of course, Acegi Security takes care of for you
  339. automatically so there is no need to worry about it.</para>
  340. <para>Some applications aren't entirely suitable for using a
  341. <literal>ThreadLocal</literal>, because of the specific way they work
  342. with threads. For example, a Swing client might want all threads in a
  343. Java Virtual Machine to use the same security context. For this
  344. situation you would use the
  345. <literal>SecurityContextHolder.MODE_GLOBAL</literal>. Other
  346. applications might want to have threads spawned by the secure thread
  347. also assume the same security identity. This is achieved by using
  348. <literal>SecurityContextHolder.MODE_INHERITABLETHREADLOCAL</literal>.
  349. You can change the mode from the default
  350. <literal>SecurityContextHolder.MODE_THREADLOCAL</literal> in two ways.
  351. The first is to set a system property. Alternatively, call a static
  352. method on <literal>SecurityContextHolder</literal>. Most applications
  353. won't need to change from the default, but if you do, take a look at
  354. the JavaDocs for <literal>SecurityContextHolder</literal> to learn
  355. more.</para>
  356. <para>Inside the <literal>SecurityContextHolder</literal> we store
  357. details of the principal currently interacting with the application.
  358. Acegi Security uses an <literal>Authentication</literal> object to
  359. represent this information. Whilst you won't normally need to create
  360. an <literal>Authentication</literal> object yourself, it is fairly
  361. common for users to query the <literal>Authentication</literal>
  362. object. You can use the following code block - from anywhere in your
  363. application - to do this:</para>
  364. <programlisting>Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  365. if (obj instanceof UserDetails) {
  366. String username = ((UserDetails)obj).getUsername();
  367. } else {
  368. String username = obj.toString();
  369. }</programlisting>
  370. <para>The above code introduces a number of interesting relationships
  371. and key objects. First, you will notice that there is an intermediate
  372. object between <literal>SecurityContextHolder</literal> and
  373. <literal>Authentication</literal>. The
  374. <literal>SecurityContextHolder.getContext()</literal> method is
  375. actually returning a <literal>SecurityContext</literal>. Acegi
  376. Security uses a few different <literal>SecurityContext</literal>
  377. implementations, such as if we need to store special information
  378. related to a request that is not principal-specific. A good example of
  379. this is our JCaptcha integration, which needs to know whether the
  380. current request came from a human user or not. Because such a decision
  381. has nothing at all to do with the principal the request may or may not
  382. be authenticated as, we store it in the
  383. <literal>SecurityContext</literal>.</para>
  384. <para>Another item to note from the above code fragment is that you
  385. can obtain a principal from the <literal>Authentication</literal>
  386. object. The principal is just an <literal>Object</literal>. Most of
  387. the time this can be cast into a <literal>UserDetails</literal>
  388. object. <literal>UserDetails</literal> is a central interface in Acegi
  389. Security. It represents a principal, but in an extensible and
  390. application-specific way. Think of <literal>UserDetails</literal> as
  391. the adapter between your own user database and what Acegi Security
  392. needs inside the <literal>SecurityContextHolder</literal>. Being a
  393. representation of something from your own user database, quite often
  394. you will cast the <literal>UserDetails</literal> to the original
  395. object that your application provided, so you can call
  396. business-specific methods (like <literal>getEmail()</literal>,
  397. <literal>getEmployeeNumber()</literal> and so on).</para>
  398. <para>By now you're probably wondering, so when do I provide a
  399. <literal>UserDetails</literal> object? How do I do that? I thought you
  400. said this thing was declarative and I didn't need to write any Java
  401. code - what gives? The short answer is that there is a special
  402. interface called <literal>UserDetailsService</literal>. The only
  403. method on this interface accepts a <literal>String</literal>-based
  404. username argument and returns a <literal>UserDetails</literal>. Most
  405. authentication providers that ship with Acegi Security delegate to a
  406. <literal>UserDetailsService</literal> as part of the authentication
  407. process. The <literal>UserDetailsService</literal> is used to build
  408. the <literal>Authentication</literal> object that is stored in the
  409. <literal>SecurityContextHolder</literal>. The good news is that we
  410. provide a number of <literal>UserDetailsService</literal>
  411. implementations, including one that uses an in-memory map and another
  412. that uses JDBC. Most users tends to write their own, though, with such
  413. implementations often simply sitting on top of an existing Data Access
  414. Object (DAO) that represents their employees, customers, or other
  415. users of the enterprise application. Remember the advantage that
  416. whatever your UserDetailsService returns can always be obtained from
  417. the <literal>SecurityContextHolder</literal>, as per the above code
  418. fragment.</para>
  419. <para>Besides the principal, another important method provided by
  420. <literal>Authentication</literal> is
  421. <literal>getAuthorities(</literal>). This method provides an array of
  422. <literal>GrantedAuthority</literal> objects. A
  423. <literal>GrantedAuthority</literal> is, not surprisingly, an authority
  424. that is granted to the principal. Such authorities are usually
  425. "roles", such as <literal>ROLE_ADMINISTRATOR</literal> or
  426. <literal>ROLE_HR_SUPERVISOR</literal>. These roles are later on
  427. configured for web authorization, method authorization and domain
  428. object authorization. Other parts of Acegi Security are capable of
  429. interpreting these authorities, and expect them to be present. You
  430. will usually return <literal>GrantedAuthority</literal> objects from
  431. the <literal>UserDetailsService</literal>.</para>
  432. <para>Usually the <literal>GrantedAuthority</literal> objects are
  433. application-wide permissions. They are not specific to a given domain
  434. object. Thus, you wouldn't likely have a
  435. <literal>GrantedAuthority</literal> to represent a permission to
  436. <literal>Employee</literal> object number 54, because if there are
  437. thousands of such authorities you would quickly run out of memory (or,
  438. at the very least, cause the application to take a long time to
  439. authenticate a user). Of course, Acegi Security is expressly designed
  440. to handle this common requirement, but you'd instead use the project's
  441. domain object security capabilities for this purpose.</para>
  442. <para>Last but not least, sometimes you will need to store the
  443. <literal>SecurityContext</literal> between HTTP requests. Other times
  444. the principal will re-authenticate on every request, although most of
  445. the time it will be stored. The
  446. <literal>HttpSessionContextIntegrationFilter</literal> is responsible
  447. for storing a <literal>SecurityContext</literal> between HTTP
  448. requests. As suggested by the name of the class, the
  449. <literal>HttpSession</literal> is used to store this information. You
  450. should never interact directly with the <literal>HttpSession</literal>
  451. for security purposes. There is simply no justification for doing so -
  452. always use the <literal>SecurityContextHolder</literal>
  453. instead.</para>
  454. <para>Just to recap, the major building blocks of Acegi Security
  455. are:</para>
  456. <itemizedlist spacing="compact">
  457. <listitem>
  458. <para><literal>SecurityContextHolder</literal>, to provide any
  459. type access to the <literal>SecurityContext</literal>.</para>
  460. </listitem>
  461. <listitem>
  462. <para><literal>SecurityContext</literal>, to hold the
  463. <literal>Authentication</literal> and possibly request-specific
  464. security information.</para>
  465. </listitem>
  466. <listitem>
  467. <para><literal>HttpSessionContextIntegrationFilter</literal>, to
  468. store the <literal>SecurityContext</literal> in the
  469. <literal>HttpSession</literal> between web requests.</para>
  470. </listitem>
  471. <listitem>
  472. <para><literal>Authentication</literal>, to represent the
  473. principal in an Acegi Security-specific manner.</para>
  474. </listitem>
  475. <listitem>
  476. <para><literal>GrantedAuthority</literal>, to reflect the
  477. application-wide permissions granted to a principal.</para>
  478. </listitem>
  479. <listitem>
  480. <para><literal>UserDetails</literal>, to provide the necessary
  481. information to build an Authentication object from your
  482. application's DAOs.</para>
  483. </listitem>
  484. <listitem>
  485. <para><literal>UserDetailsService</literal>, to create a
  486. <literal>UserDetails</literal> when passed in a
  487. <literal>String</literal>-based username (or certificate ID or
  488. alike).</para>
  489. </listitem>
  490. </itemizedlist>
  491. <para>Now that you've gained an understanding of these repeatedly-used
  492. components, let's take a closer look at the process of
  493. authentication.</para>
  494. </sect1>
  495. <sect1 id="common-authentication">
  496. <title>Authentication</title>
  497. <para>As mentioned in the beginning of this reference guide, Acegi
  498. Security can participate in many different authentication
  499. environments. Whilst we recommend people use Acegi Security for
  500. authentication and not integrate with existing Container Managed
  501. Authentication, it is nevertheless supported - as is integrating with
  502. your own proprietary authentication system. Let's first explore
  503. authentication from the perspective of Acegi Security managing web
  504. security entirely on its own, which is illustrative of the most
  505. complex and most common situation.</para>
  506. <para>Consider a typical web application's authentication
  507. process:</para>
  508. <orderedlist>
  509. <listitem>
  510. <para>You visit the home page, and click on a link.</para>
  511. </listitem>
  512. <listitem>
  513. <para>A request goes to the server, and the server decides that
  514. you've asked for a protected resource.</para>
  515. </listitem>
  516. <listitem>
  517. <para>As you're not presently authenticated, the server sends back
  518. a response indicating that you must authenticate. The response
  519. will either be a HTTP response code, or a redirect to a particular
  520. web page.</para>
  521. </listitem>
  522. <listitem>
  523. <para>Depending on the authentication mechanism, your browser will
  524. either redirect to the specific web page so that you can fill out
  525. the form, or the browser will somehow retrieve your identity (eg a
  526. BASIC authentication dialogue box, a cookie, a X509 certificate
  527. etc).</para>
  528. </listitem>
  529. <listitem>
  530. <para>The browser will send back a response to the server. This
  531. will either be a HTTP POST containing the contents of the form
  532. that you filled out, or a HTTP header containing your
  533. authentication details.</para>
  534. </listitem>
  535. <listitem>
  536. <para>Next the server will decide whether or not the presented
  537. credentials are valid. If they're valid, the next step will
  538. happen. If they're invalid, usually your browser will be asked to
  539. try again (so you return to step two above).</para>
  540. </listitem>
  541. <listitem>
  542. <para>The original request that you made to cause the
  543. authentication process will be retried. Hopefully you've
  544. authenticated with sufficient granted authorities to access the
  545. protected resource. If you have sufficient access, the request
  546. will be successful. Otherwise, you'll receive back a HTTP error
  547. code 403, which means "forbidden".</para>
  548. </listitem>
  549. </orderedlist>
  550. <para>Acegi Security has distinct classes responsible for most of the
  551. steps described above. The main participants (in the order that they
  552. are used) are the <literal>ExceptionTranslationFilter</literal>, an
  553. <literal>AuthenticationEntryPoint</literal>, an authentication
  554. mechanism, and an <literal>AuthenticationProvider</literal>.</para>
  555. <para><literal>ExceptionTranslationFilter</literal> is an Acegi
  556. Security filter that has responsibility for detecting any Acegi
  557. Security exceptions that are thrown. Such exceptions will generally be
  558. thrown by an <literal>AbstractSecurityInterceptor</literal>, which is
  559. the main provider of authorization services. We will discuss
  560. <literal>AbstractSecurityInterceptor</literal> in the next section,
  561. but for now we just need to know that it produces Java exceptions and
  562. knows nothing about HTTP or how to go about authenticating a
  563. principal. Instead the <literal>ExceptionTranslationFilter</literal>
  564. offers this service, with specific responsibility for either returning
  565. error code 403 (if the principal has been authenticated and therefore
  566. simply lacks sufficient access - as per step seven above), or
  567. launching an <literal>AuthenticationEntryPoint</literal> (if the
  568. principal has not been authenticated and therefore we need to go
  569. commence step three).</para>
  570. <para>The <literal>AuthenticationEntryPoint</literal> is responsible
  571. for step three in the above list. As you can imagine, each web
  572. application will have a default authentication strategy (well, this
  573. can be configured like nearly everything else in Acegi Security, but
  574. let's keep it simple for now). Each major authentication system will
  575. have its own <literal>AuthenticationEntryPoint</literal>
  576. implementation, which takes actions such as described in step
  577. three.</para>
  578. <para>After your browser decides to submit your authentication
  579. credentials (either as a HTTP form post or HTTP header) there needs to
  580. be something on the server that "collects" these authentication
  581. details. By now we're at step six in the above list. In Acegi Security
  582. was have a special name for the function of collecting authentication
  583. details from a user agent (usually a web browser), and that name is
  584. "authentication mechanism". After the authentication details are
  585. collected from the user agent, an "<literal>Authentication</literal>
  586. request" object is built and then presented to an
  587. AuthenticationProvider.</para>
  588. <para>The last played in the Acegi Security authentication process is
  589. an <literal>AuthenticationProvider</literal>. Quite simply, it is
  590. responsible for taking an <literal>Authentication</literal> request
  591. object and deciding whether or not it is valid. The provider will
  592. either throw an exception, or return a fully populated
  593. <literal>Authentication</literal> object. Remember our good friends,
  594. <literal>UserDetails</literal> and
  595. <literal>UserDetailsService</literal>? If not, head back to the
  596. previous section and refresh your memory. Most
  597. <literal>AuthenticationProvider</literal>s will ask a
  598. <literal>UserDetailsService</literal> to provide a
  599. <literal>UserDetails</literal> object. As mentioned earlier, most
  600. application will provide their own
  601. <literal>UserDetailsService</literal>, although some will be able to
  602. use the JDBC or in-memory implementation that ships with Acegi
  603. Security. The resultant <literal>UserDetails</literal> object - and
  604. particularly the <literal>GrantedAuthority[]</literal>s contained
  605. within the <literal>UserDetails</literal> object - will be used when
  606. building the fully populated <literal>Authentication</literal>
  607. object.</para>
  608. <para>After the authentication mechanism receives back the
  609. fully-populated <literal>Authentication</literal> object, it will deem
  610. the request valid, put the <literal>Authentication</literal> into the
  611. <literal>SecurityContextHolder</literal>, and cause the original
  612. request to be retried (step seven above). If, on the other hand, the
  613. <literal>AuthenticationProvider</literal> rejected the request, the
  614. authentication mechanism will ask the user agent to retry (step two
  615. above).</para>
  616. <para>Whilst this describes the typical authentication workflow, the
  617. good news is that Acegi Security doesn't mind how you put an
  618. <literal>Authentication</literal> inside the
  619. <literal>SecurityContextHolder</literal>. The only critical
  620. requirement is that the <literal>SecurityContextHolder</literal>
  621. contains an <literal>Authentication</literal> that represents a
  622. principal before the <literal>AbstractSecurityInterceptor</literal>
  623. needs to authorize a request.</para>
  624. <para>You can (and many users do) write their own filters or MVC
  625. controllers to provide interoperability with authentication systems
  626. that are not based on Acegi Security. For example, you might be using
  627. Container Managed Authentication which makes the current user
  628. available from a ThreadLocal or JNDI location. Or you might work for a
  629. company that has a legacy proprietary authentication system, which is
  630. a corporate "standard" over which you have little control. In such
  631. situations it's quite easy to get Acegi Security to work, and still
  632. provide authorization capabilities. All you need to do is write a
  633. filter (or equivalent) that reads the third-party user information
  634. from a location, build an Acegi Security-specific Authentication
  635. object, and put it onto the SecurityContextHolder. It's quite easy to
  636. do this, and a fully-supported integration approach.</para>
  637. </sect1>
  638. <sect1 id="secure-objects">
  639. <title>Secure Objects</title>
  640. <para>If you're familiar with AOP, you'd be aware there are different
  641. types of advice available: before, after, throws and around. An around
  642. advice is very useful, because an advisor can elect whether or not to
  643. proceed with a method invocation, whether or not to modify the
  644. response, and whether or not to throw an exception. Acegi Security
  645. provides an around advice for method invocations as well as web
  646. requests. We achieve an around advice for method invocations using AOP
  647. Alliance, and we achieve an around advice for web requests using a
  648. standard Filter.</para>
  649. <para>For those not familiar with AOP, the key point to understand is
  650. that Acegi Security can help you protect method invocations as well as
  651. web requests. Most people are interested in securing method
  652. invocations on their services layer. This is because the services
  653. layer is where most business logic resides in current-generation J2EE
  654. applications (for clarification, the author disapproves of this design
  655. and instead advocates properly encapsulated domain objects together
  656. with the DTO, assembly, facade and transparent persistence patterns,
  657. but as anemic domain objects is the present mainstream approach, we'll
  658. talk about it here). If you just need to secure method invocations to
  659. the services layer, using the Spring's standard AOP platform
  660. (otherwise known as AOP Alliance) will be adequate. If you need to
  661. secure domain objects directly, you will likely find that AspectJ is
  662. worth considering.</para>
  663. <para>You can elect to perform method authorization using AspectJ or
  664. AOP Alliance, or you can elect to perform web request authorization
  665. using filters. You can use zero, one, two or three of these approaches
  666. together. The mainstream usage is to perform some web request
  667. authorization, coupled with some AOP Alliance method invocation
  668. authorization on the services layer.</para>
  669. <para>Acegi Security uses the term "secure object" to refer to any
  670. object that can have security applies to it. Each secure object
  671. supported by Acegi Security has its own class, which is a subclass of
  672. <literal>AbstractSecurityInterceptor</literal>. Importantly, by the
  673. time the <literal>AbstractSecurityInterceptor</literal> is run, the
  674. <literal>SecurityContextHolder</literal> will contain a valid
  675. <literal>Authentication</literal> if the principal has been
  676. authenticated.</para>
  677. <para>The <literal>AbstractSecurityInterceptor</literal> provides a
  678. consistent workflow for handling secure object requests. This workflow
  679. includes looking up the "configuration attributes" associated with the
  680. present request. A "configuration attribute" can be thought of as a
  681. String that has special meaning to the classes used by
  682. <literal>AbstractSecurityInterceptor</literal>. They're normally
  683. configured against your AbstractSecurityInterceptor using XML. Anyway,
  684. the <literal>AbstractSecurityInterceptor</literal> will ask an
  685. <literal>AccessDecisionManager</literal> "here's the configuration
  686. attributes, here's the current <literal>Authentication</literal>
  687. object, and here's details of the current request - is this particular
  688. principal allowed to perform this particular operation?".</para>
  689. <para>Assuming <literal>AccessDecisionManager</literal> decides to
  690. allow the request, the <literal>AbstractSecurityInterceptor</literal>
  691. will normally just proceed with the request. Having said that, on rare
  692. occasions users may want to replace the
  693. <literal>Authentication</literal> inside the
  694. <literal>SecurityContext</literal> with a different
  695. <literal>Authentication</literal>, which is handled by the
  696. <literal>AccessDecisionManager</literal> calling a
  697. <literal>RunAsManager</literal>. This might be useful in reasonably
  698. unusual situations, such as if a services layer method needs to call a
  699. remote system and present a different identity. Because Acegi Security
  700. automatically propagates security identity from one server to another
  701. (assuming you're using a properly-configured RMI or HttpInvoker
  702. remoting protocol client), this may be useful.</para>
  703. <para>Following the secure object proceeding and then returning -
  704. which may mean a method invocation completing or a filter chain
  705. proceeding - the <literal>AbstractSecurityInterceptor</literal> gets
  706. one final chance to handle the invocation. At this stage the
  707. <literal>AbstractSecurityInterceptor</literal> is interested in
  708. possibly modifying the return object. We might want this to happen
  709. because an authorization decision couldn't be made "on the way in" to
  710. a secure object invocation. Being highly pluggable,
  711. <literal>AbstractSecurityInterceptor</literal> will pass control to an
  712. <literal>AfterInvocationManager</literal> to actually modify the
  713. object if needed. This class even can entirely replace the object, or
  714. throw an exception, or not change it in any way.</para>
  715. <para>Because <literal>AbstractSecurityInterceptor</literal> is the
  716. central template class, it seems fitting that the first figure should
  717. be devoted to it.</para>
  718. <para><mediaobject>
  719. <imageobject role="html">
  720. <imagedata align="center"
  721. fileref="images/SecurityInterception.gif"
  722. format="GIF" />
  723. </imageobject>
  724. <caption>
  725. <para>Figure 1: The key "secure object" model</para>
  726. </caption>
  727. </mediaobject></para>
  728. <para>Only developers contemplating an entirely new way of
  729. intercepting and authorizing requests would need to use secure objects
  730. directly. For example, it would be possible to build a new secure
  731. object to secure calls to a messaging system. Anything that requires
  732. security and also provides a way of intercepting a call (like the AOP
  733. around advice semantics) is capable of being made into a secure
  734. object. Having said that, most Spring applications will simply use the
  735. three currently supported secure object types (AOP Alliance
  736. <literal>MethodInvocation</literal>, AspectJ
  737. <literal>JoinPoint</literal> and web request
  738. <literal>FilterInterceptor</literal>) with complete
  739. transparency.</para>
  740. </sect1>
  741. <sect1 id="common-conclusion">
  742. <title>Conclusion</title>
  743. <para>Congratulations! You have enough of a high-level picture of
  744. Acegi Security to embark on your project. We've explored the shared
  745. components, how authentication works, and reviewed the common
  746. authorization concept of a "secure object". Everything that follows in
  747. this reference guide may or may not apply to your particular needs,
  748. and can be read in any order.</para>
  749. </sect1>
  750. </chapter>
  751. <chapter id="supporting-infrastructure">
  752. <title>Supporting Infrastructure</title>
  753. <para>This chapter introduces some of the supplementary and supporting
  754. infrastructure used by Acegi Security. If a capability is not directly
  755. related to security, yet included in the Acegi Security project, we will
  756. discuss it in this chapter.</para>
  757. <sect1 id="localization">
  758. <title>Localization</title>
  759. <para>Acegi Security supports localization of exception messages that
  760. end users are likely to see. If your application is designed for
  761. English users, you don't need to do anything as by default all Acegi
  762. Security messages are in English. If you need to support other
  763. locales, everything you need to know is contained in this
  764. section.</para>
  765. <para>All exception messages can be localized, including messages
  766. related to authentication failures and access being denied
  767. (authorization failures). Exceptions and logging that is focused on
  768. developers or system deployers (including incorrect attributes,
  769. interface contract violations, using incorrect constructors, startup
  770. time validation, debug-level logging) etc are not localized and
  771. instead are hard-coded in English within Acegi Security's code.</para>
  772. <para>Shipping in the <literal>acegi-security-xx.jar</literal> you
  773. will find an <literal>org.acegisecurity</literal> package that in turn
  774. contains a <literal>messages.properties</literal> file. This should be
  775. referred to by your <literal>ApplicationContext</literal>, as Acegi
  776. Security classes implement Spring's
  777. <literal>MessageSourceAware</literal> interface and expect the message
  778. resolver to be dependency injected at application context startup
  779. time. Usually all you need to do is register a bean inside your
  780. application context to refer to the messages. An example is shown
  781. below:</para>
  782. <para><programlisting>&lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
  783. &lt;property name="basename"&gt;&lt;value&gt;org/acegisecurity/messages&lt;/value&gt;&lt;/property&gt;
  784. &lt;/bean&gt; </programlisting></para>
  785. <para>The <literal>messages.properties</literal> is named in
  786. accordance with standard resource bundles and represents the default
  787. language supported by Acegi Securtiy messages. This default file is in
  788. English. If you do not register a message source, Acegi Security will
  789. still work correctly and fallback to hard-coded English versions of
  790. the messages.</para>
  791. <para>If you wish to customize the
  792. <literal>messages.properties</literal> file, or support other
  793. languages, you should copy the file, rename it accordingly, and
  794. register it inside the above bean definition. There are not a large
  795. number of message keys inside this file, so localization should not be
  796. considered a major initiative. If you do perform localization of this
  797. file, please consider sharing your work with the community by logging
  798. a JIRA task and attaching your appropriately-named localized version
  799. of <literal>messages.properties</literal>.</para>
  800. <para>Rounding out the discussion on localization is the Spring
  801. <literal>ThreadLocal</literal> known as
  802. <literal>org.springframework.context.i18n.LocaleContextHolder</literal>.
  803. You should set the <literal>LocaleContextHolder</literal> to represent
  804. the preferred <literal>Locale</literal> of each user. Acegi Security
  805. will attempt to locate a message from the message source using the
  806. <literal>Locale</literal> obtained from this
  807. <literal>ThreadLocal</literal>. Please refer to Spring documentation
  808. for further details on using <literal>LocaleContextHolder</literal>
  809. and the helper classes that can automatically set it for you (eg
  810. <literal>AcceptHeaderLocaleResolver</literal>,
  811. <literal>CookieLocaleResolver</literal>,
  812. <literal>FixedLocaleResolver</literal>,
  813. <literal>SessionLocaleResolver</literal> etc)</para>
  814. </sect1>
  815. <sect1 id="filters">
  816. <title>Filters</title>
  817. <para>Acegi Security uses many filters, as referred to throughout the
  818. remainder of this reference guide. You have a choice in how these
  819. filters are added to your web application, in that you can use either
  820. <literal>FilterToBeanProxy</literal> or
  821. <literal>FilterChainProxy</literal>. We'll look at both below.</para>
  822. <para>Most filters are configured using the
  823. <literal>FilterToBeanProxy</literal>. An example configuration from
  824. <literal>web.xml</literal> follows:</para>
  825. <para><programlisting>&lt;filter&gt;
  826. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  827. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  828. &lt;init-param&gt;
  829. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  830. &lt;param-value&gt;org.acegisecurity.ClassThatImplementsFilter&lt;/param-value&gt;
  831. &lt;/init-param&gt;
  832. &lt;/filter&gt;</programlisting></para>
  833. <para>Notice that the filter in <literal>web.xml</literal> is actually
  834. a <literal>FilterToBeanProxy</literal>, and not the filter that will
  835. actually implement the logic of the filter. What
  836. <literal>FilterToBeanProxy</literal> does is delegate the
  837. <literal>Filter</literal>'s methods through to a bean which is
  838. obtained from the Spring application context. This enables the bean to
  839. benefit from the Spring application context lifecycle support and
  840. configuration flexibility. The bean must implement
  841. <literal>javax.servlet.Filter</literal>.</para>
  842. <para>The <literal>FilterToBeanProxy</literal> only requires a single
  843. initialization parameter, <literal>targetClass</literal> or
  844. <literal>targetBean</literal>. The <literal>targetClass</literal>
  845. parameter locates the first object in the application context of the
  846. specified class, whilst <literal>targetBean</literal> locates the
  847. object by bean name. Like standard Spring web applications, the
  848. <literal>FilterToBeanProxy</literal> accesses the application context
  849. via<literal>
  850. WebApplicationContextUtils.getWebApplicationContext(ServletContext)</literal>,
  851. so you should configure a <literal>ContextLoaderListener</literal> in
  852. <literal>web.xml</literal>.</para>
  853. <para>There is a lifecycle issue to consider when hosting
  854. <literal>Filter</literal>s in an IoC container instead of a servlet
  855. container. Specifically, which container should be responsible for
  856. calling the <literal>Filter</literal>'s "startup" and "shutdown"
  857. methods? It is noted that the order of initialization and destruction
  858. of a <literal>Filter</literal> can vary by servlet container, and this
  859. can cause problems if one <literal>Filter</literal> depends on
  860. configuration settings established by an earlier initialized
  861. <literal>Filter</literal>. The Spring IoC container on the other hand
  862. has more comprehensive lifecycle/IoC interfaces (such as
  863. <literal>InitializingBean</literal>,
  864. <literal>DisposableBean</literal>, <literal>BeanNameAware</literal>,
  865. <literal>ApplicationContextAware</literal> and many others) as well as
  866. a well-understood interface contract, predictable method invocation
  867. ordering, autowiring support, and even options to avoid implementing
  868. Spring interfaces (eg the <literal>destroy-method</literal> attribute
  869. in Spring XML). For this reason we recommend the use of Spring
  870. lifecycle services instead of servlet container lifecycle services
  871. wherever possible. By default <literal>FilterToBeanProxy</literal>
  872. will not delegate <literal>init(FilterConfig)</literal> and
  873. <literal>destroy()</literal> methods through to the proxied bean. If
  874. you do require such invocations to be delegated, set the
  875. <literal>lifecycle</literal> initialization parameter to
  876. <literal>servlet-container-managed</literal>.</para>
  877. <para>Rather than using <literal>FilterToBeanProxy</literal>, we
  878. strongly recommend to use <literal>FilterChainProxy</literal> instead.
  879. Whilst <literal>FilterToBeanProxy</literal> is a very useful class,
  880. the problem is that the lines of code required for
  881. <literal>&lt;filter&gt;</literal> and
  882. <literal>&lt;filter-mapping&gt;</literal> entries in
  883. <literal>web.xml</literal> explodes when using more than a few
  884. filters. To overcome this issue, Acegi Security provides a
  885. <literal>FilterChainProxy</literal> class. It is wired using a
  886. <literal>FilterToBeanProxy</literal> (just like in the example above),
  887. but the target class is
  888. <literal>org.acegisecurity.util.FilterChainProxy</literal>. The filter
  889. chain is then declared in the application context, using code such as
  890. this:</para>
  891. <para><programlisting>&lt;bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy"&gt;
  892. &lt;property name="filterInvocationDefinitionSource"&gt;
  893. &lt;value&gt;
  894. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  895. PATTERN_TYPE_APACHE_ANT
  896. /webServices/**=httpSessionContextIntegrationFilterWithASCFalse,basicProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor
  897. /**=httpSessionContextIntegrationFilterWithASCTrue,authenticationProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor
  898. &lt;/value&gt;
  899. &lt;/property&gt;
  900. &lt;/bean&gt; </programlisting></para>
  901. <para>You may notice similarities with the way
  902. <literal>FilterSecurityInterceptor</literal> is declared. Both regular
  903. expressions and Ant Paths are supported, and the most specific URIs
  904. appear first. At runtime the <literal>FilterChainProxy</literal> will
  905. locate the first URI pattern that matches the current web request.
  906. Each of the corresponding configuration attributes represent the name
  907. of a bean defined in the application context. The filters will then be
  908. invoked in the order they are specified, with standard
  909. <literal>FilterChain</literal> behaviour being respected (a
  910. <literal>Filter</literal> can elect not to proceed with the chain if
  911. it wishes to end processing).</para>
  912. <para>As you can see, <literal>FilterChainProxy</literal> requires the
  913. duplication of filter names for different request patterns (in the
  914. above example, <literal>exceptionTranslationFilter</literal> and
  915. <literal>filterSecurityInterceptor</literal> are duplicated). This
  916. design decision was made to enable <literal>FilterChainProxy</literal>
  917. to specify different <literal>Filter</literal> invocation orders for
  918. different URI patterns, and also to improve both the expressiveness
  919. (in terms of regular expressions, Ant Paths, and any custom
  920. <literal>FilterInvocationDefinitionSource</literal> implementations)
  921. and clarity of which <literal>Filter</literal>s should be
  922. invoked.</para>
  923. <para>You may have noticed we have declared two
  924. <literal>HttpSessionContextIntegrationFilter</literal>s in the filter
  925. chain (<literal>ASC</literal> is short for
  926. <literal>allowSessionCreation</literal>, a property of
  927. <literal>HttpSessionContextIntegrationFilter</literal>). As web
  928. services will never present a <literal>jsessionid</literal> on future
  929. requests, creating <literal>HttpSession</literal>s for such user
  930. agents would be wasteful. If you had a high-volume application which
  931. required maximum scalability, we recommend you use the approach shown
  932. above. For smaller applications, using a single
  933. <literal>HttpSessionContextIntegrationFilter</literal> (with its
  934. default <literal>allowSessionCreation</literal> as
  935. <literal>true</literal>) would likely be sufficient.</para>
  936. <para>In relation to lifecycle issues, the
  937. <literal>FilterChainProxy</literal> will always delegate
  938. <literal>init(FilterConfig)</literal> and <literal>destroy()</literal>
  939. methods through to the underlaying <literal>Filter</literal>s if such
  940. methods are called against <literal>FilterChainProxy</literal> itself.
  941. In this case, <literal>FilterChainProxy</literal> guarantees to only
  942. initialize and destroy each <literal>Filter</literal> once,
  943. irrespective of how many times it is declared by the
  944. <literal>FilterInvocationDefinitionSource</literal>. You control the
  945. overall choice as to whether these methods are called or not via the
  946. <literal>lifecycle</literal> initialization parameter of the
  947. <literal>FilterToBeanProxy</literal> that proxies
  948. <literal>FilterChainProxy</literal>. As discussed above, by default
  949. any servlet container lifecycle invocations are not delegated through
  950. to <literal>FilterChainProxy</literal>.</para>
  951. <para>The order that filters are defined in <literal>web.xml</literal>
  952. is very important. Irrespective of which filters you are actually
  953. using, the order of the <literal>&lt;filter-mapping&gt;</literal>s
  954. should be as follows:</para>
  955. <orderedlist>
  956. <listitem>
  957. <para><literal>ChannelProcessingFilter</literal>, because it might
  958. need to redirect to a different protocol</para>
  959. </listitem>
  960. <listitem>
  961. <para><literal>ConcurrentSessionFilter</literal>, because it
  962. doesn't use any <literal>SecurityContextHolder</literal>
  963. functionality but needs to update the
  964. <literal>SessionRegistry</literal> to reflect ongoing requests
  965. from the principal</para>
  966. </listitem>
  967. <listitem>
  968. <para><literal>HttpSessionContextIntegrationFilter</literal>, so a
  969. <literal>SecurityContext</literal> can be setup in the
  970. <literal>SecurityContextHolder</literal> at the beginning of a web
  971. request, and any changes to the <literal>SecurityContext</literal>
  972. can be copied to the <literal>HttpSession</literal> when the web
  973. request ends (ready for use with the next web request)</para>
  974. </listitem>
  975. <listitem>
  976. <para>Authentication processing mechanisms -
  977. <literal>AuthenticationProcessingFilter</literal>,
  978. <literal>CasProcessingFilter</literal>,
  979. <literal>BasicProcessingFilter, HttpRequestIntegrationFilter,
  980. JbossIntegrationFilter</literal> etc - so that the
  981. <literal>SecurityContextHolder</literal> can be modified to
  982. contain a valid <literal>Authentication</literal> request
  983. token</para>
  984. </listitem>
  985. <listitem>
  986. <para>The
  987. <literal>SecurityContextHolderAwareRequestFilter</literal>, if you
  988. are using it to install an Acegi Security aware
  989. <literal>HttpServletRequestWrapper</literal> into your servlet
  990. container</para>
  991. </listitem>
  992. <listitem>
  993. <para><literal>RememberMeProcessingFilter</literal>, so that if no
  994. earlier authentication processing mechanism updated the
  995. <literal>SecurityContextHolder</literal>, and the request presents
  996. a cookie that enables remember-me services to take place, a
  997. suitable remembered
  998. <literal><literal>Authentication</literal></literal> object will
  999. be put there</para>
  1000. </listitem>
  1001. <listitem>
  1002. <para><literal>AnonymousProcessingFilter</literal>, so that if no
  1003. earlier authentication processing mechanism updated the
  1004. <literal>SecurityContextHolder</literal>, an anonymous
  1005. <literal>Authentication</literal> object will be put there</para>
  1006. </listitem>
  1007. <listitem>
  1008. <para><literal>ExceptionTranslationFilter</literal>, to catch any
  1009. Acegi Security exceptions so that either a HTTP error response can
  1010. be returned or an appropriate
  1011. <literal>AuthenticationEntryPoint</literal> can be launched</para>
  1012. </listitem>
  1013. <listitem>
  1014. <para><literal>FilterSecurityInterceptor</literal>, to protect web
  1015. URIs</para>
  1016. </listitem>
  1017. </orderedlist>
  1018. <para>All of the above filters use
  1019. <literal>FilterToBeanProxy</literal> or
  1020. <literal>FilterChainProxy</literal>. It is recommended that a single
  1021. <literal>FilterToBeanProxy</literal> proxy through to a single
  1022. <literal>FilterChainProxy</literal> for each application, with that
  1023. <literal>FilterChainProxy</literal> defining all of Acegi Security
  1024. <literal>Filter</literal>s.</para>
  1025. <para>If you're using SiteMesh, ensure Acegi Security filters execute
  1026. before the SiteMesh filters are called. This enables the
  1027. <literal>SecurityContextHolder</literal> to be populated in time for
  1028. use by SiteMesh decorators</para>
  1029. </sect1>
  1030. </chapter>
  1031. <chapter id="channel-security">
  1032. <title>Channel Security</title>
  1033. <sect1 id="channel-security-overview">
  1034. <title>Overview</title>
  1035. <para>In addition to coordinating the authentication and authorization
  1036. requirements of your application, Acegi Security is also able to
  1037. ensure unauthenticated web requests have certain properties. These
  1038. properties may include being of a particular transport type, having a
  1039. particular <literal>HttpSession</literal> attribute set and so on. The
  1040. most common requirement is for your web requests to be received using
  1041. a particular transport protocol, such as HTTPS.</para>
  1042. <para>An important issue in considering transport security is that of
  1043. session hijacking. Your web container manages a
  1044. <literal>HttpSession</literal> by reference to a
  1045. <literal>jsessionid</literal> that is sent to user agents either via a
  1046. cookie or URL rewriting. If the <literal>jsessionid</literal> is ever
  1047. sent over HTTP, there is a possibility that session identifier can be
  1048. intercepted and used to impersonate the user after they complete the
  1049. authentication process. This is because most web containers maintain
  1050. the same session identifier for a given user, even after they switch
  1051. from HTTP to HTTPS pages.</para>
  1052. <para>If session hijacking is considered too significant a risk for
  1053. your particular application, the only option is to use HTTPS for every
  1054. request. This means the <literal>jsessionid</literal> is never sent
  1055. across an insecure channel. You will need to ensure your
  1056. <literal>web.xml</literal>-defined
  1057. <literal>&lt;welcome-file&gt;</literal> points to a HTTPS location,
  1058. and the application never directs the user to a HTTP location. Acegi
  1059. Security provides a solution to assist with the latter.</para>
  1060. </sect1>
  1061. <sect1 id="channel-security-config">
  1062. <title>Configuration</title>
  1063. <para>To utilise Acegi Security's channel security services, add the
  1064. following lines to <literal>web.xml</literal>:</para>
  1065. <para><programlisting>
  1066. &lt;filter&gt;
  1067. &lt;filter-name&gt;Acegi Channel Processing Filter&lt;/filter-name&gt;
  1068. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  1069. &lt;init-param&gt;
  1070. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  1071. &lt;param-value&gt;org.acegisecurity.securechannel.ChannelProcessingFilter&lt;/param-value&gt;
  1072. &lt;/init-param&gt;
  1073. &lt;/filter&gt;
  1074. &lt;filter-mapping&gt;
  1075. &lt;filter-name&gt;Acegi Channel Processing Filter&lt;/filter-name&gt;
  1076. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  1077. &lt;/filter-mapping&gt;
  1078. </programlisting></para>
  1079. <para>As usual when running <literal>FilterToBeanProxy</literal>, you
  1080. will also need to configure the filter in your application
  1081. context:</para>
  1082. <para><programlisting>
  1083. &lt;bean id="channelProcessingFilter" class="org.acegisecurity.securechannel.ChannelProcessingFilter"&gt;
  1084. &lt;property name="channelDecisionManager"&gt;&lt;ref bean="channelDecisionManager"/&gt;&lt;/property&gt;
  1085. &lt;property name="filterInvocationDefinitionSource"&gt;
  1086. &lt;value&gt;
  1087. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  1088. \A/secure/.*\Z=REQUIRES_SECURE_CHANNEL
  1089. \A/acegilogin.jsp.*\Z=REQUIRES_SECURE_CHANNEL
  1090. \A/j_acegi_security_check.*\Z=REQUIRES_SECURE_CHANNEL
  1091. \A.*\Z=REQUIRES_INSECURE_CHANNEL
  1092. &lt;/value&gt;
  1093. &lt;/property&gt;
  1094. &lt;/bean&gt;
  1095. &lt;bean id="channelDecisionManager" class="org.acegisecurity.securechannel.ChannelDecisionManagerImpl"&gt;
  1096. &lt;property name="channelProcessors"&gt;
  1097. &lt;list&gt;
  1098. &lt;ref bean="secureChannelProcessor"/&gt;
  1099. &lt;ref bean="insecureChannelProcessor"/&gt;
  1100. &lt;/list&gt;
  1101. &lt;/property&gt;
  1102. &lt;/bean&gt;
  1103. &lt;bean id="secureChannelProcessor" class="org.acegisecurity.securechannel.SecureChannelProcessor"/&gt;
  1104. &lt;bean id="insecureChannelProcessor" class="org.acegisecurity.securechannel.InsecureChannelProcessor"/&gt;
  1105. </programlisting></para>
  1106. <para>Like <literal>FilterSecurityInterceptor</literal>, Apache Ant
  1107. style paths are also supported by the
  1108. <literal>ChannelProcessingFilter</literal>.</para>
  1109. <para>The <literal>ChannelProcessingFilter</literal> operates by
  1110. filtering all web requests and determining the configuration
  1111. attributes that apply. It then delegates to the
  1112. <literal>ChannelDecisionManager</literal>. The default implementation,
  1113. <literal>ChannelDecisionManagerImpl</literal>, should suffice in most
  1114. cases. It simply delegates through the list of configured
  1115. <literal>ChannelProcessor</literal> instances. A
  1116. <literal>ChannelProcessor</literal> will review the request, and if it
  1117. is unhappy with the request (eg it was received across the incorrect
  1118. transport protocol), it will perform a redirect, throw an exception or
  1119. take whatever other action is appropriate.</para>
  1120. <para>Included with Acegi Security are two concrete
  1121. <literal>ChannelProcessor</literal> implementations:
  1122. <literal>SecureChannelProcessor</literal> ensures requests with a
  1123. configuration attribute of <literal>REQUIRES_SECURE_CHANNEL</literal>
  1124. are received over HTTPS, whilst
  1125. <literal>InsecureChannelProcessor</literal> ensures requests with a
  1126. configuration attribute of
  1127. <literal>REQUIRES_INSECURE_CHANNEL</literal> are received over HTTP.
  1128. Both implementations delegate to a
  1129. <literal>ChannelEntryPoint</literal> if the required transport
  1130. protocol is not used. The two <literal>ChannelEntryPoint</literal>
  1131. implementations included with Acegi Security simply redirect the
  1132. request to HTTP and HTTPS as appropriate. Appropriate defaults are
  1133. assigned to the <literal>ChannelProcessor</literal> implementations
  1134. for the configuration attribute keywords they respond to and the
  1135. <literal>ChannelEntryPoint</literal> they delegate to, although you
  1136. have the ability to override these using the application
  1137. context.</para>
  1138. <para>Note that the redirections are absolute (eg
  1139. <literal>http://www.company.com:8080/app/page</literal>), not relative
  1140. (eg <literal>/app/page</literal>). During testing it was discovered
  1141. that Internet Explorer 6 Service Pack 1 has a bug whereby it does not
  1142. respond correctly to a redirection instruction which also changes the
  1143. port to use. Accordingly, absolute URLs are used in conjunction with
  1144. bug detection logic in the <literal>PortResolverImpl</literal> that is
  1145. wired up by default to many Acegi Security beans. Please refer to the
  1146. JavaDocs for <literal>PortResolverImpl</literal> for further
  1147. details.</para>
  1148. </sect1>
  1149. <sect1 id="channel-security-conclusion">
  1150. <title>Conclusion</title>
  1151. <para>Once configured, using the channel security filter is very easy.
  1152. Simply request pages without regard to the protocol (ie HTTP or HTTPS)
  1153. or port (eg 80, 8080, 443, 8443 etc). Obviously you'll still need a
  1154. way of making the initial request (probably via the
  1155. <literal>web.xml</literal> <literal>&lt;welcome-file&gt;</literal> or
  1156. a well-known home page URL), but once this is done the filter will
  1157. perform redirects as defined by your application context.</para>
  1158. <para>You can also add your own <literal>ChannelProcessor</literal>
  1159. implementations to the <literal>ChannelDecisionManagerImpl</literal>.
  1160. For example, you might set a <literal>HttpSession</literal> attribute
  1161. when a human user is detected via a "enter the contents of this
  1162. graphic" procedure. Your <literal>ChannelProcessor</literal> would
  1163. respond to say <literal>REQUIRES_HUMAN_USER</literal> configuration
  1164. attributes and redirect to an appropriate entry point to start the
  1165. human user validation process if the <literal>HttpSession</literal>
  1166. attribute is not currently set.</para>
  1167. <para>To decide whether a security check belongs in a
  1168. <literal>ChannelProcessor</literal> or an
  1169. <literal>AccessDecisionVoter</literal>, remember that the former is
  1170. designed to handle unauthenticated requests, whilst the latter is
  1171. designed to handle authenticated requests. The latter therefore has
  1172. access to the granted authorities of the authenticated principal. In
  1173. addition, problems detected by a <literal>ChannelProcessor</literal>
  1174. will generally cause a HTTP/HTTPS redirection so its requirements can
  1175. be met, whilst problems detected by an
  1176. <literal>AccessDecisionVoter</literal> will ultimately result in an
  1177. <literal>AccessDeniedException</literal> (depending on the governing
  1178. <literal>AccessDecisionManager</literal>).</para>
  1179. </sect1>
  1180. </chapter>
  1181. <chapter id="taglib">
  1182. <title>Tag Libraries</title>
  1183. <sect1 id="taglib-overview">
  1184. <title>Overview</title>
  1185. <para>Acegi Security comes bundled with several JSP tag libraries that
  1186. eases JSP writing. The tag libraries are known as
  1187. <literal>authz</literal> and provide a range of different
  1188. services.</para>
  1189. </sect1>
  1190. <sect1 id="taglib-config">
  1191. <title>Configuration</title>
  1192. <para>All taglib classes are included in the core
  1193. <literal>acegi-security-xx.jar</literal> file, with the
  1194. <literal>authz.tld</literal> located in the JAR's
  1195. <literal>META-INF</literal> directory. This means for JSP 1.2+ web
  1196. containers you can simply include the JAR in the WAR's
  1197. <literal>WEB-INF/lib</literal> directory and it will be available. If
  1198. you're using a JSP 1.1 container, you'll need to declare the JSP
  1199. taglib in your <literal>web.xml file</literal>, and include
  1200. <literal>authz.tld</literal> in the <literal>WEB-INF/lib</literal>
  1201. directory. The following fragment is added to
  1202. <literal>web.xml</literal>:</para>
  1203. <para><programlisting>&lt;taglib&gt;
  1204. &lt;taglib-uri&gt;http://acegisecurity.org/authz&lt;/taglib-uri&gt;
  1205. &lt;taglib-location&gt;/WEB-INF/authz.tld&lt;/taglib-location&gt;
  1206. &lt;/taglib&gt; </programlisting></para>
  1207. </sect1>
  1208. <sect1 id="taglib-usage">
  1209. <title>Usage</title>
  1210. <para>Now that you've configured the tag libraries, refer to the
  1211. individual reference guide sections for details on how to use
  1212. them.</para>
  1213. </sect1>
  1214. </chapter>
  1215. </part>
  1216. <part id="authentication">
  1217. <title>Authentication</title>
  1218. <partintro>
  1219. <para>In this part of the reference guide we will examine individual
  1220. authentication mechanisms and their corresponding
  1221. <literal>AuthenticationProvider</literal>s. We'll also look at how to
  1222. configure authentication more generally, including if you have several
  1223. authentication approaches that need to be chained together.</para>
  1224. </partintro>
  1225. <chapter id="authentication-common-auth-services">
  1226. <title>Common Authentication Services</title>
  1227. <sect1 id="mechanisms-providers-entry-points">
  1228. <title>Mechanisms, Providers and Entry Points</title>
  1229. <para>If you're using Acegi Security-provided authentication
  1230. approaches, you'll usually need to configure a web filter, together
  1231. with an <literal>AuthenticationProvider</literal> and
  1232. <literal>AuthenticationEntryPoint</literal>. In this section we are
  1233. going to explore an example application that needs to support both
  1234. form-based authentication (ie so a nice HTML page is presented to a
  1235. user for them to login) plus BASIC authentication (ie so a web service
  1236. or similar can access protected resources).</para>
  1237. <para>In the web.xml, this application will need a single Acegi
  1238. Security filter in order to use the FilterChainProxy. Nearly every
  1239. Acegi Security application will have such an entry, and it looks like
  1240. this:</para>
  1241. <para><programlisting>&lt;filter&gt;
  1242. &lt;filter-name&gt;Acegi Filter Chain Proxy&lt;/filter-name&gt;
  1243. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  1244. &lt;init-param&gt;
  1245. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  1246. &lt;param-value&gt;org.acegisecurity.util.FilterChainProxy&lt;/param-value&gt;
  1247. &lt;/init-param&gt;
  1248. &lt;/filter&gt;
  1249. &lt;filter-mapping&gt;
  1250. &lt;filter-name&gt;Acegi Filter Chain Proxy&lt;/filter-name&gt;
  1251. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  1252. &lt;/filter-mapping&gt;</programlisting></para>
  1253. <para>The above declarations will cause every web request to be passed
  1254. through to Acegi Security's FilterChainProxy. As explained in the
  1255. filters section of this reference guide, the FilterChainProxy is a
  1256. generally-useful class that enables web requests to be passed to
  1257. different filters based on the URL patterns. Those delegated filters
  1258. are managed inside the application context, so they can benefit from
  1259. dependency injection. Let's have a look at what the FilterChainProxy
  1260. bean definition would look like inside your application
  1261. context:</para>
  1262. <para><programlisting>&lt;bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy"&gt;
  1263. &lt;property name="filterInvocationDefinitionSource"&gt;
  1264. &lt;value&gt;
  1265. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  1266. PATTERN_TYPE_APACHE_ANT
  1267. /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,switchUserProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
  1268. &lt;/value&gt;
  1269. &lt;/property&gt;
  1270. &lt;/bean&gt;</programlisting></para>
  1271. <para>Internally Acegi Security will use a
  1272. <literal>PropertyEditor</literal> to convert the string presented in
  1273. the above XML fragment into a
  1274. <literal>FilterInvocationDefinitionSource</literal> object. What's
  1275. important to note at this stage is that a series of filters will be
  1276. run - in the order specified by the declaration - and each of those
  1277. filters are actually the <literal>&lt;bean id&gt;</literal> of another
  1278. bean inside the application context. So, in our case some extra beans
  1279. will also appear in the application context, and they'll be named
  1280. <literal>httpSessionContextIntegrationFilter</literal>,
  1281. <literal>logoutFilter</literal> and so on. The order that the filters
  1282. should appear is discussed in the filters section of the reference
  1283. guide - although they are correct in the above example.</para>
  1284. <para>In our example we have the
  1285. <literal>AuthenticationProcessingFilter</literal> and
  1286. <literal>BasicProcessingFilter</literal> being used. These are the
  1287. "authentication mechanisms" that respond to form-based authentication
  1288. and BASIC HTTP header-based authentication respectively (we discussed
  1289. the role of authentication mechanisms earlier in this reference
  1290. guide). If you weren't using form or BASIC authentication, neither of
  1291. these beans would be defined. You'd instead define filters applicable
  1292. to your desired authentication environment, such as
  1293. <literal>DigestProcessingFilter</literal> or
  1294. <literal>CasProcessingFilter</literal>. Refer to the individual
  1295. chapters of this part of the reference guide to learn how to configure
  1296. each of these authentication mechanisms.</para>
  1297. <para>Recall that
  1298. <literal>HttpSessionContextIntegrationFilter</literal> keeps the
  1299. contents of the <literal>SecurityContext</literal> between invocations
  1300. inside a HTTP session. This means the authentication mechanisms are
  1301. only used once, being when the principal initially tries to
  1302. authenticate. The rest of the time the authentication mechanisms sit
  1303. there and silently pass the request through to the next filter in the
  1304. chain. That is a practical requirement due to the fact that few
  1305. authentication approaches present credentials on each and every call
  1306. (BASIC authentication being a notable exception), but what happens if
  1307. a principal's account gets cancelled or disabled or otherwise changed
  1308. (eg an increase or decrease in <literal>GrantedAuthority[]</literal>s)
  1309. after the initial authentication step? Let's look at how that is
  1310. handled now.</para>
  1311. <para>The major authorization provider for secure objects has
  1312. previously been introduced as
  1313. <literal>AbstractSecurityInterceptor</literal>. This class needs to
  1314. have access to an <literal>AuthenticationManager</literal>. It also
  1315. has configurable settings to indicate whether an
  1316. <literal>Authentication</literal> object should be re-authenticated on
  1317. each secure object invocation. By default it just accepts any
  1318. <literal>Authentication</literal> inside the
  1319. <literal>SecurityContextHolder</literal> is authenticated if
  1320. <literal>Authentication.isAuthenticated()</literal> returns true. This
  1321. is great for performance, but not ideal if you want to ensure
  1322. up-to-the-moment authentication validity. For such cases you'll
  1323. probably want to set the
  1324. <literal>AbstractSecurityInterceptor.alwaysReauthenticate</literal>
  1325. property to true.</para>
  1326. <para>You might be asking yourself, "what's this
  1327. <literal>AuthenticationManager</literal>?". We haven't explored it
  1328. before, but we have discussed the concept of an
  1329. <literal>AuthenticationProvider</literal>. Quite simply, an
  1330. AuthenticationManager is responsible for passing requests through a
  1331. chain of AuthenticationProviders. It's a little like the filter chain
  1332. we discussed earlier, although there are some differences. There is
  1333. only one AuthenticationManager implementation shipped with Acegi
  1334. Security, so let's look at how it's configured for the example we're
  1335. using in this chapter:</para>
  1336. <para><programlisting>&lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  1337. &lt;property name="providers"&gt;
  1338. &lt;list&gt;
  1339. &lt;ref local="daoAuthenticationProvider"/&gt;
  1340. &lt;ref local="anonymousAuthenticationProvider"/&gt;
  1341. &lt;ref local="rememberMeAuthenticationProvider"/&gt;
  1342. &lt;/list&gt;
  1343. &lt;/property&gt;
  1344. &lt;/bean&gt;</programlisting></para>
  1345. <para>It's probably worth mentioning at this point that your
  1346. authentication mechanisms (which are usually filters) are also
  1347. injected with a reference to the
  1348. <literal>AuthenticationManager</literal>. So both
  1349. <literal>AbstractSecurityInterceptor</literal> as well as the
  1350. authentication mechanisms will use the above
  1351. <literal>ProviderManager</literal> to poll a list of
  1352. <literal>AuthenticationProvider</literal>s.</para>
  1353. <para>In our example we have three providers. They are tried in the
  1354. order shown (which is implied by the use of a <literal>List</literal>
  1355. instead of a <literal>Set</literal>), with each provider able to
  1356. attempt authentication, or skip authentication by simply returning
  1357. <literal>null</literal>. If all implementations return null, the
  1358. <literal>ProviderManager</literal> will throw a suitable exception. If
  1359. you're interested in learning more about chaining providers, please
  1360. refer to the <literal>ProviderManager</literal> JavaDocs.</para>
  1361. <para>The providers to use will sometimes be interchangeable with the
  1362. authentication mechanisms, whilst at other times they will depend on a
  1363. specific authentication mechanism. For example, the
  1364. <literal>DaoAuthenticationProvider</literal> just needs a string-based
  1365. username and password. Various authentication mechanisms result in the
  1366. collection of a string-based username and password, including (but not
  1367. limited to) BASIC and form authentication. Equally, some
  1368. authentication mechanisms create an authentication request object
  1369. which can only be interpreted by a single type of
  1370. <literal>AuthenticationProvider</literal>. An example of this
  1371. one-to-one mapping would be JA-SIG CAS, which uses the notion of a
  1372. service ticket which can therefore only be authenticated by
  1373. <literal>CasAuthenticationProvider</literal>. A further example of a
  1374. one-to-one mapping would be the LDAP authentication mechanism, which
  1375. can only be processed an the
  1376. <literal>LdapAuthenticationProvider</literal>. The specifics of such
  1377. relationships are detailed in the JavaDocs for each class, plus the
  1378. authentication approach-specific chapters of this reference guide. You
  1379. need not be terribly concerned about this implementation detail,
  1380. because if you forget to register a suitable provider, you'll simply
  1381. receive a <literal>ProviderNotFoundException</literal> when an attempt
  1382. to authenticate is made.</para>
  1383. <para>After configuring the correct authentication mechanisms in the
  1384. <literal>FilterChainProxy</literal>, and ensuring that a corresponding
  1385. <literal>AuthenticationProvider</literal> is registered in the
  1386. <literal>ProviderManager</literal>, your last step is to configure an
  1387. <literal>AuthenticationEntryPoint</literal>. Recall that earlier we
  1388. discussed the role of <literal>ExceptionTranslationFilter</literal>,
  1389. which is used when HTTP-based requests should receive back a HTTP
  1390. header or HTTP redirect in order to start authentication. Continuing
  1391. on with our earlier example:</para>
  1392. <para><programlisting>&lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;
  1393. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="authenticationProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  1394. &lt;property name="accessDeniedHandler"&gt;
  1395. &lt;bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl"&gt;
  1396. &lt;property name="errorPage" value="/accessDenied.jsp"/&gt;
  1397. &lt;/bean&gt;
  1398. &lt;/property&gt;
  1399. &lt;/bean&gt;
  1400. &lt;bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;
  1401. &lt;property name="loginFormUrl"&gt;&lt;value&gt;/acegilogin.jsp&lt;/value&gt;&lt;/property&gt;
  1402. &lt;property name="forceHttps"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  1403. &lt;/bean&gt;</programlisting></para>
  1404. <para>Notice that the <literal>ExceptionTranslationFilter</literal>
  1405. requires two collaborators. The first,
  1406. <literal>AccessDeniedHandlerImpl</literal>, uses a
  1407. <literal>RequestDispatcher</literal> forward to display the specified
  1408. access denied error page. We use a forward so that the
  1409. <literal>SecurityContextHolder</literal> still contains details of the
  1410. principal, which may be useful for display to the user (in old
  1411. releases of Acegi Security we relied upon the servlet container to
  1412. handle a 403 error message, which lacked this useful contextual
  1413. information). <literal>AccessDeniedHandlerImpl</literal> will also set
  1414. the HTTP header to 403, which is the official error code to indicate
  1415. access denied. In the case of the
  1416. <literal>AuthentionEntryPoint</literal>, here we're setting what
  1417. action we would like taken when an unauthenticated principal attempts
  1418. to perform a protected operation. Because in our example we're going
  1419. to be using form-based authentication, we specify
  1420. <literal>AuthenticationProcessinFilterEntryPoint</literal> and the URL
  1421. of the login page. Your application will usually only have one entry
  1422. point, and most authentication approaches define their own specific
  1423. <literal>AuthenticationEntryPoint</literal>. Details of which entry
  1424. point to use for each authentication approach is discussed in the
  1425. authentication approach-specific chapters of this reference
  1426. guide.</para>
  1427. </sect1>
  1428. <sect1 id="userdetails-and-associated-types">
  1429. <title>UserDetails and Associated Types</title>
  1430. <para>As mentioned in the first part of the reference guide, most
  1431. authentication providers take advantage of the
  1432. <literal>UserDetails</literal> and
  1433. <literal>UserDetailsService</literal> interfaces. The contract for
  1434. this latter interface consists of a single method:</para>
  1435. <para><programlisting>public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException;</programlisting></para>
  1436. <para>The returned <literal>UserDetails</literal> is an interface that
  1437. provides getters that guarantee non-null provision of basic
  1438. authentication information such as the username, password, granted
  1439. authorities and whether the user is enabled or disabled. Most
  1440. authentication providers will use a
  1441. <literal>UserDetailsService</literal>, even if the username and
  1442. password are not actually used as part of the authentication decision.
  1443. Generally such provider will be using the returned
  1444. <literal>UserDetails</literal> object just for its
  1445. <literal>GrantedAuthority[]</literal> information, because some other
  1446. system (like LDAP or X509 or CAS etc) has undertaken the
  1447. responsibility of actually validating the credentials.</para>
  1448. <para>A single concrete implementation of
  1449. <literal>UserDetails</literal> is provided with Acegi Security, being
  1450. the <literal>User</literal> class. Acegi Security users will need to
  1451. decide when writing their <literal>UserDetailsService</literal> what
  1452. concrete <literal>UserDetails</literal> class to return. In most cases
  1453. <literal>User</literal> will be used directly or subclassed, although
  1454. special circumstances (such as object relational mappers) may require
  1455. users to write their own <literal>UserDetails</literal> implementation
  1456. from scratch. This is not such an unusual situation, and users should
  1457. not hesitate to simply return their normal domain object that
  1458. represents a user of the system. This is especially common given that
  1459. <literal>UserDetails</literal> is often used to store additional
  1460. principal-related properties (such as their telephone number and email
  1461. address), so that they can be easily used by web views.</para>
  1462. <para>Given <literal>UserDetailsService</literal> is so simple to
  1463. implement, it should be easy for users to retrieve authentication
  1464. information using a persistence strategy of their choice. Having said
  1465. that, Acegi Security does include a couple of useful base
  1466. implementations, which we'll look at below.</para>
  1467. <sect2 id="in-memory-service">
  1468. <title>In-Memory Authentication</title>
  1469. <para>Whilst it is easy to use create a custom
  1470. <literal>UserDetailsService</literal> implementation that extracts
  1471. information from a persistence engine of choice, many applications
  1472. do not require such complexity. This is particularly true if you're
  1473. undertaking a rapid prototype or just starting integrating Acegi
  1474. Security, when you don't really want to spend time configuring
  1475. databases or writing <literal>UserDetailsService</literal>
  1476. implementations. For this sort of situation, a simple option is to
  1477. configure the <literal>InMemoryDaoImpl</literal>
  1478. implementation:</para>
  1479. <para><programlisting>&lt;bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl"&gt;
  1480. &lt;property name="userMap"&gt;
  1481. &lt;value&gt;
  1482. marissa=koala,ROLE_TELLER,ROLE_SUPERVISOR
  1483. dianne=emu,ROLE_TELLER
  1484. scott=wombat,ROLE_TELLER
  1485. peter=opal,disabled,ROLE_TELLER
  1486. &lt;/value&gt;
  1487. &lt;/property&gt;
  1488. &lt;/bean&gt; </programlisting></para>
  1489. <para>In the above example, the <literal>userMap</literal> property
  1490. contains each of the usernames, passwords, a list of granted
  1491. authorities and an optional enabled/disabled keyword. Commas are
  1492. used to delimit each token. The username must appear to the left of
  1493. the equals sign, and the password must be the first token to the
  1494. right of the equals sign. The <literal>enabled</literal> and
  1495. <literal>disabled</literal> keywords (case insensitive) may appear
  1496. in the second or any subsequent token. Any remaining tokens are
  1497. treated as granted authorities, which are created as
  1498. <literal>GrantedAuthorityImpl</literal> objects (this is just for
  1499. your reference - most application don't need custom
  1500. <literal>GrantedAuthority</literal> implementations, so using the
  1501. default implementation in this manner is just fine). Note that if a
  1502. user has no password and/or no granted authorities, the user will
  1503. not be created in the in-memory authentication repository.</para>
  1504. <para><literal>InMemoryDaoImpl</literal> also offers a
  1505. <literal>setUserProperties(Properties)</literal> method, which
  1506. allows you to externalise the
  1507. <literal>java.util.Properties</literal> in another Spring configured
  1508. bean or an external properties file. You might like to use Spring's
  1509. <literal>PropertiesFactoryBean</literal>, which is useful for
  1510. loading such external properties files. This setter might prove
  1511. useful for simple applications that have a larger number of users,
  1512. or deployment-time configuration changes, but do not wish to use a
  1513. full database for handling authentication details.</para>
  1514. </sect2>
  1515. <sect2 id="jdbc-service">
  1516. <title>JDBC Authentication</title>
  1517. <para>Acegi Security also includes a
  1518. <literal>UserDetailsService</literal> that can obtain authentication
  1519. information from a JDBC data source. Internally Spring JDBC is used,
  1520. so it avoids the complexity of a fully-featured object relational
  1521. mapper (ORM) just to store user details. If your application does
  1522. use an ORM tool, you might prefer to write a custom
  1523. <literal>UserDetailsService</literal> to reuse the mapping files
  1524. you've probably already created. Returning to
  1525. <literal>JdbcDaoImpl</literal>, an example configuration is shown
  1526. below:</para>
  1527. <para><programlisting>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
  1528. &lt;property name="driverClassName"&gt;&lt;value&gt;org.hsqldb.jdbcDriver&lt;/value&gt;&lt;/property&gt;
  1529. &lt;property name="url"&gt;&lt;value&gt;jdbc:hsqldb:hsql://localhost:9001&lt;/value&gt;&lt;/property&gt;
  1530. &lt;property name="username"&gt;&lt;value&gt;sa&lt;/value&gt;&lt;/property&gt;
  1531. &lt;property name="password"&gt;&lt;value&gt;&lt;/value&gt;&lt;/property&gt;
  1532. &lt;/bean&gt;
  1533. &lt;bean id="jdbcDaoImpl" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"&gt;
  1534. &lt;property name="dataSource"&gt;&lt;ref bean="dataSource"/&gt;&lt;/property&gt;
  1535. &lt;/bean&gt; </programlisting></para>
  1536. <para>You can use different relational database management systems
  1537. by modifying the <literal>DriverManagerDataSource</literal> shown
  1538. above. You can also use a global data source obtained from JNDI, as
  1539. per normal Spring options. Irrespective of the database used and how
  1540. a <literal>DataSource</literal> is obtained, a standard schema must
  1541. be used as indicated in <literal>dbinit.txt</literal>. You can
  1542. download this file from the Acegi Security web site.</para>
  1543. <para>If you default schema is unsuitable for your needs,
  1544. <literal>JdbcDaoImpl</literal> provides two properties that allow
  1545. customisation of the SQL statements. You may also subclass the
  1546. <literal>JdbcDaoImpl</literal> if further customisation is
  1547. necessary. Please refer to the JavaDocs for details, although please
  1548. note that the class is not intended for complex custom subclasses.
  1549. If you have complex needs (such as a special schema or would like a
  1550. certain <literal>UserDetails</literal> implementation returned),
  1551. you'd be better off writing your own
  1552. <literal>UserDetailsService</literal>. The base implementation
  1553. provided with Acegi Security is intended for typical situations, and
  1554. does not offer infinite configuration flexibility.</para>
  1555. </sect2>
  1556. </sect1>
  1557. <sect1 id="concurrent-sessions">
  1558. <title>Concurrent Session Handling</title>
  1559. <para>Acegi Security is able to prevent a principal from concurrently
  1560. authenticating to the same application more than a specified number of
  1561. times. Many ISVs take advantage of this to enforce licensing, whilst
  1562. network administrators like this feature because it helps prevent
  1563. people from sharing login names. You can, for example, stop user
  1564. "Batman" from logging onto the web application from two different
  1565. sessions.</para>
  1566. <para>To use concurrent session support, you'll need to add the
  1567. following to <literal>web.xml</literal>:</para>
  1568. <para><programlisting>&lt;listener&gt;
  1569. &lt;listener-class&gt;org.acegisecurity.ui.session.HttpSessionEventPublisher&lt;/listener-class&gt;
  1570. &lt;/listener&gt; </programlisting></para>
  1571. <para>In addition, you will need to add the
  1572. <literal>org.acegisecurity.concurrent.ConcurrentSessionFilter</literal>
  1573. to your <literal>FilterChainProxy</literal>. The
  1574. ConcurrentSessionFilter requires only one property,
  1575. <literal>sessionRegistry</literal>, which generally points to an
  1576. instance of <literal>SessionRegistryImpl</literal>.</para>
  1577. <para>The <literal>web.xml</literal>
  1578. <literal>HttpSessionEventPublisher</literal> causes an
  1579. <literal>ApplicationEvent</literal> to be published to the Spring
  1580. <literal>ApplicationContext</literal> every time a
  1581. <literal>HttpSession</literal> commences or terminates. This is
  1582. critical, as it allows the <literal>SessionRegistryImpl</literal> to
  1583. be notified when a session ends.</para>
  1584. <para>You will also need to wire up the
  1585. <literal>ConcurrentSessionControllerImpl</literal> and refer to it
  1586. from your <literal>ProviderManager</literal> bean:</para>
  1587. <para><programlisting>&lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  1588. &lt;property name="providers"&gt;
  1589. &lt;!-- your providers go here --&gt;
  1590. &lt;/property&gt;
  1591. &lt;property name="sessionController"&gt;&lt;ref bean="concurrentSessionController"/&gt;&lt;/property&gt;
  1592. &lt;/bean&gt;
  1593. &lt;bean id="concurrentSessionController" class="org.acegisecurity.concurrent.ConcurrentSessionControllerImpl"&gt;
  1594. &lt;property name="maximumSessions"&gt;&lt;value&gt;1&lt;/value&gt;&lt;/property&gt;
  1595. &lt;property name="sessionRegistry"&gt;&lt;ref local="sessionRegistry"/&gt;&lt;/property&gt;
  1596. &lt;/bean&gt;
  1597. &lt;bean id="sessionRegistry" class="org.acegisecurity.concurrent.SessionRegistryImpl"/&gt;</programlisting></para>
  1598. </sect1>
  1599. <sect1 id="authentication-taglibs">
  1600. <title>Authentication Tag Libraries</title>
  1601. <para><literal>AuthenticationTag</literal> is used to simply output a
  1602. property of the current principal's
  1603. <literal>Authentication.getPrincipal()</literal> object to the web
  1604. page.</para>
  1605. <para>The following JSP fragment illustrates how to use the
  1606. <literal>AuthenticationTag</literal>:</para>
  1607. <para><programlisting>&lt;authz:authentication operation="username"/&gt;</programlisting></para>
  1608. <para>This tag would cause the principal's name to be output. Here we
  1609. are assuming the <literal>Authentication.getPrincipal()</literal> is a
  1610. <literal>UserDetails</literal> object, which is generally the case
  1611. when using the typical
  1612. <literal>DaoAuthenticationProvider</literal>.</para>
  1613. </sect1>
  1614. </chapter>
  1615. <chapter id="dao-provider">
  1616. <title>DAO Authentication Provider</title>
  1617. <sect1 id="dao-provider-overview">
  1618. <title>Overview</title>
  1619. <para>Acegi Security includes a production-quality
  1620. <literal>AuthenticationProvider</literal> implementation called
  1621. <literal>DaoAuthenticationProvider</literal>. This authentication
  1622. provider is compatible with all of the authentication mechanisms that
  1623. generate a <literal>UsernamePasswordAuthenticationToken</literal>, and
  1624. is probably the most commonly used provider in the framework. Like
  1625. most of the other authentication providers, the
  1626. DaoAuthenticationProvider leverages a UserDetailsService in order to
  1627. lookup the username, password and GrantedAuthority[]s. Unlike most of
  1628. the other authentication providers that leverage UserDetailsService,
  1629. this authentication provider actually requires the password to be
  1630. presented, and the provider will actually evaluate the validity or
  1631. otherwise of the password presented in an authentication request
  1632. object.</para>
  1633. </sect1>
  1634. <sect1 id="dao-provider-config">
  1635. <title>Configuration</title>
  1636. <para>Aside from adding DaoAuthenticationProvider to your
  1637. ProviderManager list (as discussed at the start of this part of the
  1638. reference guide), and ensuring a suitable authentication mechanism is
  1639. configured to present a UsernamePasswordAuthenticationToken, the
  1640. configuration of the provider itself is rather simple:</para>
  1641. <para><programlisting>&lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  1642. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  1643. &lt;property name="saltSource"&gt;&lt;ref bean="saltSource"/&gt;&lt;/property&gt;
  1644. &lt;property name="passwordEncoder"&gt;&lt;ref bean="passwordEncoder"/&gt;&lt;/property&gt;
  1645. &lt;/bean&gt; </programlisting></para>
  1646. <para>The <literal>PasswordEncoder</literal> and
  1647. <literal>SaltSource</literal> are optional. A
  1648. <literal>PasswordEncoder</literal> provides encoding and decoding of
  1649. passwords presented in the <literal>UserDetails</literal> object that
  1650. is returned from the configured <literal>UserDetailsService</literal>.
  1651. A <literal>SaltSource</literal> enables the passwords to be populated
  1652. with a "salt", which enhances the security of the passwords in the
  1653. authentication repository. <literal>PasswordEncoder</literal>
  1654. implementations are provided with Acegi Security covering MD5, SHA and
  1655. cleartext encodings. Two <literal>SaltSource</literal> implementations
  1656. are also provided: <literal>SystemWideSaltSource</literal> which
  1657. encodes all passwords with the same salt, and
  1658. <literal>ReflectionSaltSource</literal>, which inspects a given
  1659. property of the returned <literal>UserDetails</literal> object to
  1660. obtain the salt. Please refer to the JavaDocs for further details on
  1661. these optional features.</para>
  1662. <para>In addition to the properties above, the
  1663. <literal>DaoAuthenticationProvider</literal> supports optional caching
  1664. of <literal>UserDetails</literal> objects. The
  1665. <literal>UserCache</literal> interface enables the
  1666. <literal>DaoAuthenticationProvider</literal> to place a
  1667. <literal>UserDetails</literal> object into the cache, and retrieve it
  1668. from the cache upon subsequent authentication attempts for the same
  1669. username. By default the <literal>DaoAuthenticationProvider</literal>
  1670. uses the <literal>NullUserCache</literal>, which performs no caching.
  1671. A usable caching implementation is also provided,
  1672. <literal>EhCacheBasedUserCache</literal>, which is configured as
  1673. follows:</para>
  1674. <para><programlisting>&lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  1675. &lt;property name="userDetailsService"&gt;&lt;ref bean="userDetailsService"/&gt;&lt;/property&gt;
  1676. &lt;property name="userCache"&gt;&lt;ref bean="userCache"/&gt;&lt;/property&gt;
  1677. &lt;/bean&gt;
  1678. &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;
  1679. &lt;property name="configLocation"&gt;
  1680. &lt;value&gt;classpath:/ehcache-failsafe.xml&lt;/value&gt;
  1681. &lt;/property&gt;
  1682. &lt;/bean&gt;
  1683. &lt;bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;
  1684. &lt;property name="cacheManager"&gt;
  1685. &lt;ref local="cacheManager"/&gt;
  1686. &lt;/property&gt;
  1687. &lt;property name="cacheName"&gt;
  1688. &lt;value&gt;userCache&lt;/value&gt;
  1689. &lt;/property&gt;
  1690. &lt;/bean&gt;
  1691. &lt;bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache"&gt;
  1692. &lt;property name="cache"&gt;&lt;ref local="userCacheBackend"/&gt;&lt;/property&gt;
  1693. &lt;/bean&gt; </programlisting></para>
  1694. <para>All Acegi Security EH-CACHE implementations (including
  1695. <literal>EhCacheBasedUserCache</literal>) require an EH-CACHE
  1696. <literal>Cache</literal> object. The <literal>Cache</literal> object
  1697. can be obtained from wherever you like, although we recommend you use
  1698. Spring's factory classes as shown in the above configuration. If using
  1699. Spring's factory classes, please refer to the Spring documentation for
  1700. further details on how to optimise the cache storage location, memory
  1701. usage, eviction policies, timeouts etc.</para>
  1702. <para>A design decision was made not to support account locking in the
  1703. <literal>DaoAuthenticationProvider</literal>, as doing so would have
  1704. increased the complexity of the <literal>UserDetailsService</literal>
  1705. interface. For instance, a method would be required to increase the
  1706. count of unsuccessful authentication attempts. Such functionality
  1707. could be easily provided by leveraging the application event
  1708. publishing features discussed below.</para>
  1709. <para><literal>DaoAuthenticationProvider</literal> returns an
  1710. <literal>Authentication</literal> object which in turn has its
  1711. <literal>principal</literal> property set. The principal will be
  1712. either a <literal>String</literal> (which is essentially the username)
  1713. or a <literal>UserDetails</literal> object (which was looked up from
  1714. the <literal>UserDetailsService</literal>). By default the
  1715. <literal>UserDetails</literal> is returned, as this enables
  1716. applications to add extra properties potentially of use in
  1717. applications, such as the user's full name, email address etc. If
  1718. using container adapters, or if your applications were written to
  1719. operate with <literal>String</literal>s (as was the case for releases
  1720. prior to Acegi Security 0.6), you should set the
  1721. <literal>DaoAuthenticationProvider.forcePrincipalAsString</literal>
  1722. property to <literal>true</literal> in your application context</para>
  1723. </sect1>
  1724. </chapter>
  1725. <chapter id="jaas">
  1726. <title>Java Authentication and Authorization Service (JAAS)
  1727. Provider</title>
  1728. <sect1 id="jaas-overview">
  1729. <title>Overview</title>
  1730. <para>Acegi Security provides a package able to delegate
  1731. authentication requests to the Java Authentication and Authorization
  1732. Service (JAAS). This package is discussed in detail below.</para>
  1733. <para>Central to JAAS operation are login configuration files. To
  1734. learn more about JAAS login configuration files, consult the JAAS
  1735. reference documentation available from Sun Microsystems. We expect you
  1736. to have a basic understanding of JAAS and its login configuration file
  1737. syntax in order to understand this section.</para>
  1738. </sect1>
  1739. <sect1 id="jaas-config">
  1740. <title>Configuration</title>
  1741. <para>The <literal>JaasAuthenticationProvider</literal> attempts to
  1742. authenticate a user’s principal and credentials through JAAS.</para>
  1743. <para>Let’s assume we have a JAAS login configuration file,
  1744. <literal>/WEB-INF/login.conf</literal>, with the following
  1745. contents:</para>
  1746. <para><programlisting>JAASTest {
  1747. sample.SampleLoginModule required;
  1748. };</programlisting></para>
  1749. <para>Like all Acegi Security beans, the
  1750. <literal>JaasAuthenticationProvider</literal> is configured via the
  1751. application context. The following definitions would correspond to the
  1752. above JAAS login configuration file:</para>
  1753. <para><programlisting>
  1754. &lt;bean id="jaasAuthenticationProvider" class="org.acegisecurity.providers.jaas.JaasAuthenticationProvider"&gt;
  1755. &lt;property name="loginConfig"&gt;
  1756. &lt;value&gt;/WEB-INF/login.conf&lt;/value&gt;
  1757. &lt;/property&gt;
  1758. &lt;property name="loginContextName"&gt;
  1759. &lt;value&gt;JAASTest&lt;/value&gt;
  1760. &lt;/property&gt;
  1761. &lt;property name="callbackHandlers"&gt;
  1762. &lt;list&gt;
  1763. &lt;bean class="org.acegisecurity.providers.jaas.JaasNameCallbackHandler"/&gt;
  1764. &lt;bean class="org.acegisecurity.providers.jaas.JaasPasswordCallbackHandler"/&gt;
  1765. &lt;/list&gt;
  1766. &lt;/property&gt;
  1767. &lt;property name="authorityGranters"&gt;
  1768. &lt;list&gt;
  1769. &lt;bean class="org.acegisecurity.providers.jaas.TestAuthorityGranter"/&gt;
  1770. &lt;/list&gt;
  1771. &lt;/property&gt;
  1772. &lt;/bean&gt;
  1773. </programlisting></para>
  1774. <para>The <literal>CallbackHandler</literal>s and
  1775. <literal>AuthorityGranter</literal>s are discussed below.</para>
  1776. <sect2 id="jaas-callbackhandler">
  1777. <title id="jaas-callback-handler">JAAS CallbackHandler</title>
  1778. <para>Most JAAS <literal>LoginModule</literal>s require a callback
  1779. of some sort. These callbacks are usually used to obtain the
  1780. username and password from the user.</para>
  1781. <para>In an Acegi Security deployment, Acegi Security is responsible
  1782. for this user interaction (via the authentication mechanism). Thus,
  1783. by the time the authentication request is delegated through to JAAS,
  1784. Acegi Security's authentication mechanism will already have
  1785. fully-populated an <literal>Authentication</literal> object
  1786. containing all the information required by the JAAS
  1787. <literal>LoginModule</literal>.</para>
  1788. <para>Therefore, the JAAS package for Acegi Security provides two
  1789. default callback handlers,
  1790. <literal>JaasNameCallbackHandler</literal> and
  1791. <literal>JaasPasswordCallbackHandler</literal>. Each of these
  1792. callback handlers implement
  1793. <literal>JaasAuthenticationCallbackHandler</literal>. In most cases
  1794. these callback handlers can simply be used without understanding the
  1795. internal mechanics.</para>
  1796. <para>For those needing full control over the callback behavior,
  1797. internally <literal>JaasAutheticationProvider</literal> wraps these
  1798. <literal>JaasAuthenticationCallbackHandler</literal>s with an
  1799. <literal>InternalCallbackHandler</literal>. The
  1800. <literal>InternalCallbackHandler</literal> is the class that
  1801. actually implements JAAS’ normal <literal>CallbackHandler</literal>
  1802. interface. Any time that the JAAS <literal>LoginModule</literal> is
  1803. used, it is passed a list of application context configured
  1804. <literal>InternalCallbackHandler</literal>s. If the
  1805. <literal>LoginModule</literal> requests a callback against the
  1806. <literal>InternalCallbackHandler</literal>s, the callback is in-turn
  1807. passed to the <literal>JaasAuthenticationCallbackHandler</literal>s
  1808. being wrapped.</para>
  1809. </sect2>
  1810. <sect2 id="jaas-authoritygranter">
  1811. <title id="jaas-authority-granter">JAAS AuthorityGranter</title>
  1812. <para>JAAS works with principals. Even "roles" are represented as
  1813. principals in JAAS. Acegi Security, on the other hand, works with
  1814. <literal>Authentication</literal> objects. Each
  1815. <literal>Authentication</literal> object contains a single
  1816. principal, and multiple <literal>GrantedAuthority</literal>[]s. To
  1817. facilitate mapping between these different concepts, Acegi
  1818. Security's JAAS package includes an
  1819. <literal>AuthorityGranter</literal> interface.</para>
  1820. <para>An <literal>AuthorityGranter</literal> is responsible for
  1821. inspecting a JAAS principal and returning a
  1822. <literal>String</literal>. The
  1823. <literal>JaasAuthenticationProvider</literal> then creates a
  1824. <literal>JaasGrantedAuthority</literal> (which implements Acegi
  1825. Security’s <literal>GrantedAuthority</literal> interface) containing
  1826. both the <literal>AuthorityGranter</literal>-returned
  1827. <literal>String</literal> and the JAAS principal that the
  1828. <literal>AuthorityGranter</literal> was passed. The
  1829. <literal>JaasAuthenticationProvider</literal> obtains the JAAS
  1830. principals by firstly successfully authenticating the user’s
  1831. credentials using the JAAS <literal>LoginModule</literal>, and then
  1832. accessing the <literal>LoginContext</literal> it returns. A call to
  1833. <literal>LoginContext.getSubject().getPrincipals()</literal> is
  1834. made, with each resulting principal passed to each
  1835. <literal>AuthorityGranter</literal> defined against the
  1836. <literal>JaasAuthenticationProvider.setAuthorityGranters(List)</literal>
  1837. property.</para>
  1838. <para>Acegi Security does not include any production
  1839. <literal>AuthorityGranter</literal>s given that every JAAS principal
  1840. has an implementation-specific meaning. However, there is a
  1841. <literal>TestAuthorityGranter</literal> in the unit tests that
  1842. demonstrates a simple <literal>AuthorityGranter</literal>
  1843. implementation.</para>
  1844. </sect2>
  1845. </sect1>
  1846. </chapter>
  1847. <chapter id="siteminder">
  1848. <title>Siteminder Authentication Mechanism</title>
  1849. <sect1 id="siteminder-overview">
  1850. <title>Overview</title>
  1851. <para>Siteminder is a commercial single sign on solution by Computer
  1852. Associates.</para>
  1853. <para>Acegi Security provides a filter,
  1854. <literal>SiteminderAuthenticationProcessingFilter</literal> and
  1855. provider, <literal>SiteminderAuthenticationProvider</literal> that can
  1856. be used to process requests that have been pre-authenticated by
  1857. Siteminder. This filter assumes that you're using Siteminder for
  1858. <emphasis>authentication</emphasis>, and that you're using Acegi
  1859. Security for <emphasis>authorization</emphasis>. The use of Siteminder
  1860. for <emphasis>authorization</emphasis> is not yet directly supported
  1861. by Acegi Security.</para>
  1862. <para>When using Siteminder, an agent is setup on your web server to
  1863. intercept a principal's first call to your application. The agent
  1864. redirects the web request to a single sign-on login page, and once
  1865. authenticated, your application receives the request. Inside the HTTP
  1866. request is a header - such as <literal>SM_USER</literal> - which
  1867. identifies the authenticated principal (please refer to your
  1868. organization's "single sign-on" group for header details in your
  1869. particular configuration).</para>
  1870. </sect1>
  1871. <sect1 id="siteminder-config">
  1872. <title>Configuration</title>
  1873. <para>The first step in setting up Acegi Security's Siteminder support
  1874. is to define the authentication mechanism that will inspect the HTTP
  1875. header discussed earlier. It will be responsible for generating a
  1876. <literal>UsernamePasswordAuthenticationToken</literal> that is later
  1877. sent to the <literal>SiteminderAuthenticationProvider</literal>. Let's
  1878. look at an example:</para>
  1879. <para><programlisting>&lt;bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.SiteminderAuthenticationProcessingFilter"&gt;
  1880. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  1881. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/login.jsp?login_error=1&lt;/value&gt;&lt;/property&gt;
  1882. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/security.do?method=getMainMenu&lt;/value&gt;&lt;/property&gt;
  1883. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_security_check&lt;/value&gt;&lt;/property&gt;
  1884. &lt;property name="siteminderUsernameHeaderKey"&gt;&lt;value&gt;SM_USER&lt;/value&gt;&lt;/property&gt;
  1885. &lt;property name="formUsernameParameterKey"&gt;&lt;value&gt;j_username&lt;/value&gt;&lt;/property&gt;
  1886. &lt;/bean&gt;</programlisting></para>
  1887. <para>In our example above, the bean is being provided an
  1888. <literal>AuthenticationManager</literal>, as is normally needed by
  1889. authentication mechanisms. Several URLs are also specified, with the
  1890. values being self-explanatory. It's important to also specify the HTTP
  1891. header that Acegi Security should inspect. If you additionally want to
  1892. support form-based authentication (i.e. in your development
  1893. environment where Siteminder is not installed), specify the form's
  1894. username parameter as well - just don't do this in production!</para>
  1895. <para>Note that you'll need a
  1896. <literal><literal>SiteminderAuthenticationProvider</literal></literal>
  1897. configured against your <literal>ProviderManager</literal> in order to
  1898. use the Siteminder authentication mechanism. Normally an
  1899. <literal>AuthenticationProvider</literal> expects the password
  1900. property to match what it retrieves from the
  1901. <literal>UserDetailsSource</literal>, but in this case, authentication
  1902. has already been handled by Siteminder, so password property is not
  1903. even relevant. This may sound like a security weakness, but remember
  1904. that users have to authenticate with Siteminder before your
  1905. application ever receives the requests, so the purpose of your custom
  1906. <literal>UserDetailsService</literal> should simply be to build the
  1907. complete <literal>Authentication</literal> object (ie with suitable
  1908. <literal>GrantedAuthority[]</literal>s).</para>
  1909. <para>Advanced tip and word to the wise: If you additionally want to
  1910. support form-based authentication in your development environment
  1911. (where Siteminder is typically not installed), specify the form's
  1912. username parameter as well. Just don't do this in production!</para>
  1913. </sect1>
  1914. </chapter>
  1915. <chapter id="runas">
  1916. <title>Run-As Authentication Replacement</title>
  1917. <sect1 id="runas-overview">
  1918. <title>Overview</title>
  1919. <para>The <literal>AbstractSecurityInterceptor</literal> is able to
  1920. temporarily replace the <literal>Authentication</literal> object in
  1921. the <literal>SecurityContext</literal> and
  1922. <literal>SecurityContextHolder</literal> during the secure object
  1923. callback phase. This only occurs if the original
  1924. <literal>Authentication</literal> object was successfully processed by
  1925. the <literal>AuthenticationManager</literal> and
  1926. <literal>AccessDecisionManager</literal>. The
  1927. <literal>RunAsManager</literal> will indicate the replacement
  1928. <literal>Authentication</literal> object, if any, that should be used
  1929. during the <literal>SecurityInterceptorCallback</literal>.</para>
  1930. <para>By temporarily replacing the <literal>Authentication</literal>
  1931. object during the secure object callback phase, the secured invocation
  1932. will be able to call other objects which require different
  1933. authentication and authorization credentials. It will also be able to
  1934. perform any internal security checks for specific
  1935. <literal>GrantedAuthority</literal> objects. Because Acegi Security
  1936. provides a number of helper classes that automatically configure
  1937. remoting protocols based on the contents of the
  1938. <literal>SecurityContextHolder</literal>, these run-as replacements
  1939. are particularly useful when calling remote web services</para>
  1940. </sect1>
  1941. <sect1 id="runas-config">
  1942. <title>Configuration</title>
  1943. <para>A <literal>RunAsManager</literal> interface is provided by Acegi
  1944. Security:</para>
  1945. <para><programlisting>public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config);
  1946. public boolean supports(ConfigAttribute attribute);
  1947. public boolean supports(Class clazz);</programlisting></para>
  1948. <para>The first method returns the <literal>Authentication</literal>
  1949. object that should replace the existing
  1950. <literal>Authentication</literal> object for the duration of the
  1951. method invocation. If the method returns <literal>null</literal>, it
  1952. indicates no replacement should be made. The second method is used by
  1953. the <literal>AbstractSecurityInterceptor</literal> as part of its
  1954. startup validation of configuration attributes. The
  1955. <literal>supports(Class)</literal> method is called by a security
  1956. interceptor implementation to ensure the configured
  1957. <literal>RunAsManager</literal> supports the type of secure object
  1958. that the security interceptor will present.</para>
  1959. <para>One concrete implementation of a <literal>RunAsManager</literal>
  1960. is provided with Acegi Security. The
  1961. <literal>RunAsManagerImpl</literal> class returns a replacement
  1962. <literal>RunAsUserToken</literal> if any
  1963. <literal>ConfigAttribute</literal> starts with
  1964. <literal>RUN_AS_</literal>. If any such
  1965. <literal>ConfigAttribute</literal> is found, the replacement
  1966. <literal>RunAsUserToken</literal> will contain the same principal,
  1967. credentials and granted authorities as the original
  1968. <literal>Authentication</literal> object, along with a new
  1969. <literal>GrantedAuthorityImpl</literal> for each
  1970. <literal>RUN_AS_</literal> <literal>ConfigAttribute</literal>. Each
  1971. new <literal>GrantedAuthorityImpl</literal> will be prefixed with
  1972. <literal>ROLE_</literal>, followed by the <literal>RUN_AS</literal>
  1973. <literal>ConfigAttribute</literal>. For example, a
  1974. <literal>RUN_AS_SERVER</literal> will result in the replacement
  1975. <literal>RunAsUserToken</literal> containing a
  1976. <literal>ROLE_RUN_AS_SERVER</literal> granted authority.</para>
  1977. <para>The replacement <literal>RunAsUserToken</literal> is just like
  1978. any other <literal>Authentication</literal> object. It needs to be
  1979. authenticated by the <literal>AuthenticationManager</literal>,
  1980. probably via delegation to a suitable
  1981. <literal>AuthenticationProvider</literal>. The
  1982. <literal>RunAsImplAuthenticationProvider</literal> performs such
  1983. authentication. It simply accepts as valid any
  1984. <literal>RunAsUserToken</literal> presented.</para>
  1985. <para>To ensure malicious code does not create a
  1986. <literal>RunAsUserToken</literal> and present it for guaranteed
  1987. acceptance by the <literal>RunAsImplAuthenticationProvider</literal>,
  1988. the hash of a key is stored in all generated tokens. The
  1989. <literal>RunAsManagerImpl</literal> and
  1990. <literal>RunAsImplAuthenticationProvider</literal> is created in the
  1991. bean context with the same key:</para>
  1992. <para><programlisting>
  1993. &lt;bean id="runAsManager" class="org.acegisecurity.runas.RunAsManagerImpl"&gt;
  1994. &lt;property name="key"&gt;&lt;value&gt;my_run_as_password&lt;/value&gt;&lt;/property&gt;
  1995. &lt;/bean&gt;
  1996. &lt;bean id="runAsAuthenticationProvider" class="org.acegisecurity.runas.RunAsImplAuthenticationProvider"&gt;
  1997. &lt;property name="key"&gt;&lt;value&gt;my_run_as_password&lt;/value&gt;&lt;/property&gt;
  1998. &lt;/bean&gt;
  1999. </programlisting></para>
  2000. <para>By using the same key, each <literal>RunAsUserToken</literal>
  2001. can be validated it was created by an approved
  2002. <literal>RunAsManagerImpl</literal>. The
  2003. <literal>RunAsUserToken</literal> is immutable after creation for
  2004. security reasons</para>
  2005. </sect1>
  2006. </chapter>
  2007. <chapter id="form">
  2008. <title>Form Authentication Mechanism</title>
  2009. <sect1 id="form-overview">
  2010. <title>Overview</title>
  2011. <para>HTTP Form Authentication involves using the
  2012. <literal>AuthenticationProcessingFilter</literal> to process a login
  2013. form. This is the most common way that application authenticate end
  2014. users. Form-based authentication is entirely compatible with the DAO
  2015. and JAAS authentication providers.</para>
  2016. </sect1>
  2017. <sect1 id="form-config">
  2018. <title>Configuration</title>
  2019. <para>The login form simply contains <literal>j_username</literal> and
  2020. <literal>j_password</literal> input fields, and posts to a URL that is
  2021. monitored by the filter (by default
  2022. <literal>j_acegi_security_check</literal>). The filter is defined in
  2023. <literal>web.xml</literal> behind a
  2024. <literal>FilterToBeanProxy</literal> as follows:</para>
  2025. <para><programlisting>&lt;filter&gt;
  2026. &lt;filter-name&gt;Acegi Authentication Processing Filter&lt;/filter-name&gt;
  2027. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  2028. &lt;init-param&gt;
  2029. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  2030. &lt;param-value&gt;org.acegisecurity.ui.webapp.AuthenticationProcessingFilter&lt;/param-value&gt;
  2031. &lt;/init-param&gt;
  2032. &lt;/filter&gt;
  2033. &lt;filter-mapping&gt;
  2034. &lt;filter-name&gt;Acegi Authentication Processing Filter&lt;/filter-name&gt;
  2035. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  2036. &lt;/filter-mapping&gt;</programlisting></para>
  2037. <para>For a discussion of <literal>FilterToBeanProxy</literal>, please
  2038. refer to the Filters section. The application context will need to
  2039. define the <literal>AuthenticationProcessingFilter</literal>:</para>
  2040. <para><programlisting>&lt;bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"&gt;
  2041. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2042. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/acegilogin.jsp?login_error=1&lt;/value&gt;&lt;/property&gt;
  2043. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;
  2044. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_security_check&lt;/value&gt;&lt;/property&gt;
  2045. &lt;/bean&gt; </programlisting></para>
  2046. <para>The configured <literal>AuthenticationManager</literal>
  2047. processes each authentication request. If authentication fails, the
  2048. browser will be redirected to the
  2049. <literal>authenticationFailureUrl</literal>. The
  2050. <literal>AuthenticationException</literal> will be placed into the
  2051. <literal>HttpSession</literal> attribute indicated by
  2052. <literal>AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY</literal>,
  2053. enabling a reason to be provided to the user on the error page.</para>
  2054. <para>If authentication is successful, the resulting
  2055. <literal>Authentication</literal> object will be placed into the
  2056. <literal>SecurityContextHolder</literal>.</para>
  2057. <para>Once the <literal>SecurityContextHolder</literal> has been
  2058. updated, the browser will need to be redirected to the target URL. The
  2059. target URL is usually indicated by the <literal>HttpSession</literal>
  2060. attribute specified by
  2061. <literal>AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL_KEY</literal>.
  2062. This attribute is automatically set by the
  2063. <literal>ExceptionTranslationFilter</literal> when an
  2064. <literal>AuthenticationException</literal> occurs, so that after login
  2065. is completed the user can return to what they were trying to access.
  2066. If for some reason the <literal>HttpSession</literal> does not
  2067. indicate the target URL, the browser will be redirected to the
  2068. <literal>defaultTargetUrl</literal> property.</para>
  2069. </sect1>
  2070. </chapter>
  2071. <chapter id="basic">
  2072. <title>BASIC Authentication Mechanism</title>
  2073. <sect1 id="basic-overview">
  2074. <title>Overview</title>
  2075. <para>Acegi Security provides a
  2076. <literal>BasicProcessingFilter</literal> which is capable of
  2077. processing basic authentication credentials presented in HTTP headers.
  2078. This can be used for authenticating calls made by Spring remoting
  2079. protocols (such as Hessian and Burlap), as well as normal user agents
  2080. (such as Internet Explorer and Navigator). The standard governing HTTP
  2081. Basic Authentication is defined by RFC 1945, Section 11, and the
  2082. <literal>BasicProcessingFilter</literal> conforms with this RFC. Basic
  2083. Authentication is an attractive approach to authentication, because it
  2084. is very widely deployed in user agents and implementation is extremely
  2085. simple (it's just a Base64 encoding of the username:password,
  2086. specified in a HTTP header).</para>
  2087. </sect1>
  2088. <sect1 id="basic-config">
  2089. <title>Configuration</title>
  2090. <para>To implement HTTP Basic Authentication, it is necessary to
  2091. define <literal>BasicProcessingFilter</literal> in the filter chain.
  2092. The application context will need to define the
  2093. <literal>BasicProcessingFilter</literal> and its required
  2094. collaborator:</para>
  2095. <para><programlisting>
  2096. &lt;bean id="basicProcessingFilter" class="org.acegisecurity.ui.basicauth.BasicProcessingFilter"&gt;
  2097. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2098. &lt;property name="authenticationEntryPoint"&gt;&lt;ref bean="authenticationEntryPoint"/&gt;&lt;/property&gt;
  2099. &lt;/bean&gt;
  2100. &lt;bean id="authenticationEntryPoint" class="org.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint"&gt;
  2101. &lt;property name="realmName"&gt;&lt;value&gt;Name Of Your Realm&lt;/value&gt;&lt;/property&gt;
  2102. &lt;/bean&gt;
  2103. </programlisting></para>
  2104. <para>The configured <literal>AuthenticationManager</literal>
  2105. processes each authentication request. If authentication fails, the
  2106. configured <literal>AuthenticationEntryPoint</literal> will be used to
  2107. retry the authentication process. Usually you will use the
  2108. <literal>BasicProcessingFilterEntryPoint</literal>, which returns a
  2109. 401 response with a suitable header to retry HTTP Basic
  2110. authentication. If authentication is successful, the resulting
  2111. <literal>Authentication</literal> object will be placed into the
  2112. <literal>SecurityContextHolder</literal>.</para>
  2113. <para>If the authentication event was successful, or authentication
  2114. was not attempted because the HTTP header did not contain a supported
  2115. authentication request, the filter chain will continue as normal. The
  2116. only time the filter chain will be interrupted is if authentication
  2117. fails and the <literal>AuthenticationEntryPoint</literal> is called,
  2118. as discussed in the previous paragraph</para>
  2119. </sect1>
  2120. </chapter>
  2121. <chapter id="digest">
  2122. <title>Digest Authentication</title>
  2123. <sect1 id="digest-overview">
  2124. <title>Overview</title>
  2125. <para>Acegi Security provides a
  2126. <literal>DigestProcessingFilter</literal> which is capable of
  2127. processing digest authentication credentials presented in HTTP
  2128. headers. Digest Authentication attempts to solve many of the
  2129. weaknesses of Basic authentication, specifically by ensuring
  2130. credentials are never sent in clear text across the wire. Many user
  2131. agents support Digest Authentication, including FireFox and Internet
  2132. Explorer. The standard governing HTTP Digest Authentication is defined
  2133. by RFC 2617, which updates an earlier version of the Digest
  2134. Authentication standard prescribed by RFC 2069. Most user agents
  2135. implement RFC 2617. Acegi Security
  2136. <literal>DigestProcessingFilter</literal> is compatible with the
  2137. "<literal>auth</literal>" quality of protection
  2138. (<literal>qop</literal>) prescribed by RFC 2617, which also provides
  2139. backward compatibility with RFC 2069. Digest Authentication is a
  2140. highly attractive option if you need to use unencrypted HTTP (ie no
  2141. TLS/HTTPS) and wish to maximise security of the authentication
  2142. process. Indeed Digest Authentication is a mandatory requirement for
  2143. the WebDAV protocol, as noted by RFC 2518 Section 17.1, so we should
  2144. expect to see it increasingly deployed and replacing Basic
  2145. Authentication.</para>
  2146. <para>Digest Authentication is definitely the most secure choice
  2147. between Form Authentication, Basic Authentication and Digest
  2148. Authentication, although extra security also means more complex user
  2149. agent implementations. Central to Digest Authentication is a "nonce".
  2150. This is a value the server generates. Acegi Security's nonce adopts
  2151. the following format:</para>
  2152. <para><programlisting>base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
  2153. expirationTime: The date and time when the nonce expires, expressed in milliseconds
  2154. key: A private key to prevent modification of the nonce token
  2155. </programlisting></para>
  2156. <para>The <literal>DigestProcessingFilterEntryPoint</literal> has a
  2157. property specifying the <literal>key</literal> used for generating the
  2158. nonce tokens, along with a <literal>nonceValiditySeconds</literal>
  2159. property for determining the expiration time (default 300, which
  2160. equals five minutes). Whist ever the nonce is valid, the digest is
  2161. computed by concatenating various strings including the username,
  2162. password, nonce, URI being requested, a client-generated nonce (merely
  2163. a random value which the user agent generates each request), the realm
  2164. name etc, then performing an MD5 hash. Both the server and user agent
  2165. perform this digest computation, resulting in different hash codes if
  2166. they disagree on an included value (eg password). In Acegi Security
  2167. implementation, if the server-generated nonce has merely expired (but
  2168. the digest was otherwise valid), the
  2169. <literal>DigestProcessingFilterEntryPoint</literal> will send a
  2170. <literal>"stale=true"</literal> header. This tells the user agent
  2171. there is no need to disturb the user (as the password and username etc
  2172. is correct), but simply to try again using a new nonce.</para>
  2173. <para>An appropriate value for
  2174. <literal>DigestProcessingFilterEntryPoint</literal>'s
  2175. <literal>nonceValiditySeconds</literal> parameter will depend on your
  2176. application. Extremely secure applications should note that an
  2177. intercepted authentication header can be used to impersonate the
  2178. principal until the <literal>expirationTime</literal> contained in the
  2179. nonce is reached. This is the key principle when selecting an
  2180. appropriate setting, but it would be unusual for immensely secure
  2181. applications to not be running over TLS/HTTPS in the first
  2182. instance.</para>
  2183. <para>Because of the more complex implementation of Digest
  2184. Authentication, there are often user agent issues. For example,
  2185. Internet Explorer fails to present an "<literal>opaque</literal>"
  2186. token on subsequent requests in the same session. Acegi Security
  2187. filters therefore encapsulate all state information into the
  2188. "<literal>nonce</literal>" token instead. In our testing, Acegi
  2189. Security implementation works reliably with FireFox and Internet
  2190. Explorer, correctly handling nonce timeouts etc.</para>
  2191. </sect1>
  2192. <sect1 id="digest-config">
  2193. <title>Configuration</title>
  2194. <para>Now that we've reviewed the theory, let's see how to use it. To
  2195. implement HTTP Digest Authentication, it is necessary to define
  2196. <literal>DigestProcessingFilter</literal> in the fitler chain. The
  2197. application context will need to define the
  2198. <literal>DigestProcessingFilter</literal> and its required
  2199. collaborators:</para>
  2200. <para><programlisting>
  2201. &lt;bean id="digestProcessingFilter" class="org.acegisecurity.ui.digestauth.DigestProcessingFilter"&gt;
  2202. &lt;property name="userDetailsService"&gt;&lt;ref local="jdbcDaoImpl"/&gt;&lt;/property&gt;
  2203. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="digestProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  2204. &lt;property name="userCache"&gt;&lt;ref local="userCache"/&gt;&lt;/property&gt;
  2205. &lt;/bean&gt;
  2206. &lt;bean id="digestProcessingFilterEntryPoint" class="org.acegisecurity.ui.digestauth.DigestProcessingFilterEntryPoint"&gt;
  2207. &lt;property name="realmName"&gt;&lt;value&gt;Contacts Realm via Digest Authentication&lt;/value&gt;&lt;/property&gt;
  2208. &lt;property name="key"&gt;&lt;value&gt;acegi&lt;/value&gt;&lt;/property&gt;
  2209. &lt;property name="nonceValiditySeconds"&gt;&lt;value&gt;10&lt;/value&gt;&lt;/property&gt;
  2210. &lt;/bean&gt;
  2211. </programlisting></para>
  2212. <para>The configured <literal>UserDetailsService</literal> is needed
  2213. because <literal>DigestProcessingFilter</literal> must have direct
  2214. access to the clear text password of a user. Digest Authentication
  2215. will NOT work if you are using encoded passwords in your DAO. The DAO
  2216. collaborator, along with the <literal>UserCache</literal>, are
  2217. typically shared directly with a
  2218. <literal>DaoAuthenticationProvider</literal>. The
  2219. <literal>authenticationEntryPoint</literal> property must be
  2220. <literal>DigestProcessingFilterEntryPoint</literal>, so that
  2221. <literal>DigestProcessingFilter</literal> can obtain the correct
  2222. <literal>realmName</literal> and <literal>key</literal> for digest
  2223. calculations.</para>
  2224. <para>Like <literal>BasicAuthenticationFilter</literal>, if
  2225. authentication is successful an <literal>Authentication</literal>
  2226. request token will be placed into the
  2227. <literal>SecurityContextHolder</literal>. If the authentication event
  2228. was successful, or authentication was not attempted because the HTTP
  2229. header did not contain a Digest Authentication request, the filter
  2230. chain will continue as normal. The only time the filter chain will be
  2231. interrupted is if authentication fails and the
  2232. <literal>AuthenticationEntryPoint</literal> is called, as discussed in
  2233. the previous paragraph.</para>
  2234. <para>Digest Authentication's RFC offers a range of additional
  2235. features to further increase security. For example, the nonce can be
  2236. changed on every request. Despite this, Acegi Security implementation
  2237. was designed to minimise the complexity of the implementation (and the
  2238. doubtless user agent incompatibilities that would emerge), and avoid
  2239. needing to store server-side state. You are invited to review RFC 2617
  2240. if you wish to explore these features in more detail. As far as we are
  2241. aware, Acegi Security implementation does comply with the minimum
  2242. standards of this RFC.</para>
  2243. </sect1>
  2244. </chapter>
  2245. <chapter id="anonymous">
  2246. <title>Anonymous Authentication</title>
  2247. <sect1 id="anonymous-overview">
  2248. <title>Overview</title>
  2249. <para>Particularly in the case of web request URI security, sometimes
  2250. it is more convenient to assign configuration attributes against every
  2251. possible secure object invocation. Put differently, sometimes it is
  2252. nice to say <literal>ROLE_SOMETHING</literal> is required by default
  2253. and only allow certain exceptions to this rule, such as for login,
  2254. logout and home pages of an application. There are also other
  2255. situations where anonymous authentication would be desired, such as
  2256. when an auditing interceptor queries the
  2257. <literal>SecurityContextHolder</literal> to identify which principal
  2258. was responsible for a given operation. Such classes can be authored
  2259. with more robustness if they know the
  2260. <literal>SecurityContextHolder</literal> always contains an
  2261. <literal>Authentication</literal> object, and never
  2262. <literal>null</literal>.</para>
  2263. </sect1>
  2264. <sect1 id="anonymous-config">
  2265. <title>Configuration</title>
  2266. <para>Acegi Security provides three classes that together provide an
  2267. anonymous authentication feature.
  2268. <literal>AnonymousAuthenticationToken</literal> is an implementation
  2269. of <literal>Authentication</literal>, and stores the
  2270. <literal>GrantedAuthority</literal>[]s which apply to the anonymous
  2271. principal. There is a corresponding
  2272. <literal>AnonymousAuthenticationProvider</literal>, which is chained
  2273. into the <literal>ProviderManager</literal> so that
  2274. <literal>AnonymousAuthenticationTokens</literal> are accepted.
  2275. Finally, there is an AnonymousProcessingFilter, which is chained after
  2276. the normal authentication mechanisms and automatically add an
  2277. <literal>AnonymousAuthenticationToken</literal> to the
  2278. <literal>SecurityContextHolder</literal> if there is no existing
  2279. <literal>Authentication</literal> held there. The definition of the
  2280. filter and authentication provider appears as follows:</para>
  2281. <para><programlisting>
  2282. &lt;bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter"&gt;
  2283. &lt;property name="key"&gt;&lt;value&gt;foobar&lt;/value&gt;&lt;/property&gt;
  2284. &lt;property name="userAttribute"&gt;&lt;value&gt;anonymousUser,ROLE_ANONYMOUS&lt;/value&gt;&lt;/property&gt;
  2285. &lt;/bean&gt;
  2286. &lt;bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider"&gt;
  2287. &lt;property name="key"&gt;&lt;value&gt;foobar&lt;/value&gt;&lt;/property&gt;
  2288. &lt;/bean&gt;
  2289. </programlisting></para>
  2290. <para>The <literal>key</literal> is shared between the filter and
  2291. authentication provider, so that tokens created by the former are
  2292. accepted by the latter. The <literal>userAttribute</literal> is
  2293. expressed in the form of
  2294. <literal>usernameInTheAuthenticationToken,grantedAuthority[,grantedAuthority]</literal>.
  2295. This is the same syntax as used after the equals sign for
  2296. <literal>InMemoryDaoImpl</literal>'s <literal>userMap</literal>
  2297. property.</para>
  2298. <para>As explained earlier, the benefit of anonymous authentication is
  2299. that all URI patterns can have security applied to them. For
  2300. example:</para>
  2301. <para><programlisting>
  2302. &lt;bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  2303. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2304. &lt;property name="accessDecisionManager"&gt;&lt;ref local="httpRequestAccessDecisionManager"/&gt;&lt;/property&gt;
  2305. &lt;property name="objectDefinitionSource"&gt;
  2306. &lt;value&gt;
  2307. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  2308. PATTERN_TYPE_APACHE_ANT
  2309. /index.jsp=ROLE_ANONYMOUS,ROLE_USER
  2310. /hello.htm=ROLE_ANONYMOUS,ROLE_USER
  2311. /logoff.jsp=ROLE_ANONYMOUS,ROLE_USER
  2312. /acegilogin.jsp*=ROLE_ANONYMOUS,ROLE_USER
  2313. /**=ROLE_USER
  2314. &lt;/value&gt;
  2315. &lt;/property&gt;
  2316. &lt;/bean&gt;
  2317. </programlisting>Rounding out the anonymous authentication discussion
  2318. is the <literal>AuthenticationTrustResolver</literal> interface, with
  2319. its corresponding <literal>AuthenticationTrustResolverImpl</literal>
  2320. implementation. This interface provides an
  2321. <literal>isAnonymous(Authentication)</literal> method, which allows
  2322. interested classes to take into account this special type of
  2323. authentication status. The
  2324. <literal>ExceptionTranslationFilter</literal> uses this interface in
  2325. processing <literal>AccessDeniedException</literal>s. If an
  2326. <literal>AccessDeniedException</literal> is thrown, and the
  2327. authentication is of an anonymous type, instead of throwing a 403
  2328. (forbidden) response, the filter will instead commence the
  2329. <literal>AuthenticationEntryPoint</literal> so the principal can
  2330. authenticate properly. This is a necessary distinction, otherwise
  2331. principals would always be deemed "authenticated" and never be given
  2332. an opportunity to login via form, basic, digest or some other normal
  2333. authentication mechanism</para>
  2334. </sect1>
  2335. </chapter>
  2336. <chapter id="remember-me">
  2337. <title>Remember-Me Authentication</title>
  2338. <sect1 id="remember-me-overview">
  2339. <title>Overview</title>
  2340. <para>Remember-me authentication refers to web sites being able to
  2341. remember the identity of a principal between sessions. This is
  2342. typically accomplished by sending a cookie to the browser, with the
  2343. cookie being detected during future sessions and causing automated
  2344. login to take place. Acegi Security provides the necessary hooks so
  2345. that such operations can take place, along with providing a concrete
  2346. implementation that uses hashing to preserve the security of
  2347. cookie-based tokens.</para>
  2348. </sect1>
  2349. <sect1 id="remember-me-config">
  2350. <title>Configuration</title>
  2351. <para>Remember-me authentication is not used with basic
  2352. authentication, given it is often not used with
  2353. <literal>HttpSession</literal>s. Remember-me is used with
  2354. <literal>AuthenticationProcessingFilter</literal>, and is implemented
  2355. via hooks in the <literal>AbstractProcessingFilter</literal>
  2356. superclass. The hooks will invoke a concrete
  2357. <literal>RememberMeServices</literal> at the appropriate times. The
  2358. interface looks like this:</para>
  2359. <para><programlisting>public Authentication autoLogin(HttpServletRequest request, HttpServletResponse response);
  2360. public void loginFail(HttpServletRequest request, HttpServletResponse response);
  2361. public void loginSuccess(HttpServletRequest request, HttpServletResponse response, Authentication successfulAuthentication);</programlisting></para>
  2362. <para>Please refer to JavaDocs for a fuller discussion on what the
  2363. methods do, although note at this stage
  2364. <literal>AbstractProcessingFilter</literal> only calls the
  2365. <literal>loginFail()</literal> and <literal>loginSuccess()</literal>
  2366. methods. The <literal>autoLogin()</literal> method is called by
  2367. <literal>RememberMeProcessingFilter</literal> whenever the
  2368. <literal>SecurityContextHolder</literal> does not contain an
  2369. <literal>Authentication</literal>. This interface therefore provides
  2370. the underlaying remember-me implementation with sufficient
  2371. notification of authentication-related events, and delegates to the
  2372. implementation whenever a candidate web request might contain a cookie
  2373. and wish to be remembered.</para>
  2374. <para>This design allows any number of remember-me implementation
  2375. strategies. In the interests of simplicity and avoiding the need for
  2376. DAO implementations that specify write and create methods, Acegi
  2377. Security's only concrete implementation,
  2378. <literal>TokenBasedRememberMeServices</literal>, uses hashing to
  2379. achieve a useful remember-me strategy. In essence a cookie is sent to
  2380. the browser upon successful interactive authentication, with that
  2381. cookie being composed as follows:</para>
  2382. <para><programlisting>base64(username + ":" + expirationTime + ":" + md5Hex(username + ":" + expirationTime + ":" password + ":" + key))
  2383. username: As identifiable to TokenBasedRememberMeServices.getUserDetailsService()
  2384. password: That matches the relevant UserDetails retrieved from TokenBasedRememberMeServices.getUserDetailsService()
  2385. expirationTime: The date and time when the remember-me token expires, expressed in milliseconds
  2386. key: A private key to prevent modification of the remember-me token
  2387. </programlisting></para>
  2388. <para>As such the remember-me token is valid only for the period
  2389. specified, and provided that the username, password and key does not
  2390. change. Notably, this has a potential security issue in that a
  2391. captured remember-me token will be usable from any user agent until
  2392. such time as the token expires. This is the same issue as with digest
  2393. authentication. If a principal is aware a token has been captured,
  2394. they can easily change their password and immediately invalidate all
  2395. remember-me tokens on issue. However, if more significant security is
  2396. needed a rolling token approach should be used (this would require a
  2397. database) or remember-me services should simply not be used.</para>
  2398. <para><literal>TokenBasedRememberMeServices</literal> generates a
  2399. <literal>RememberMeAuthenticationToken</literal>, which is processed
  2400. by <literal>RememberMeAuthenticationProvider</literal>. A
  2401. <literal>key</literal> is shared between this authentication provider
  2402. and the <literal>TokenBasedRememberMeServices</literal>. In addition,
  2403. <literal>TokenBasedRememberMeServices</literal> requires A
  2404. UserDetailsService from which it can retrieve the username and
  2405. password for signature comparison purposes, and generate the
  2406. <literal>RememberMeAuthenticationToken</literal> to contain the
  2407. correct <literal>GrantedAuthority</literal>[]s. Some sort of logout
  2408. command should be provided by the application (typically via a JSP)
  2409. that invalidates the cookie upon user request. See the Contacts Sample
  2410. application's <literal>logout.jsp</literal> for an example.</para>
  2411. <para>The beans required in an application context to enable
  2412. remember-me services are as follows:</para>
  2413. <para><programlisting>
  2414. &lt;bean id="rememberMeProcessingFilter" class="org.acegisecurity.ui.rememberme.RememberMeProcessingFilter"&gt;
  2415. &lt;property name="rememberMeServices"&gt;&lt;ref local="rememberMeServices"/&gt;&lt;/property&gt;
  2416. &lt;/bean&gt;
  2417. &lt;bean id="rememberMeServices" class="org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices"&gt;
  2418. &lt;property name="userDetailsService"&gt;&lt;ref local="jdbcDaoImpl"/&gt;&lt;/property&gt;
  2419. &lt;property name="key"&gt;&lt;value&gt;springRocks&lt;/value&gt;&lt;/property&gt;
  2420. &lt;/bean&gt;
  2421. &lt;bean id="rememberMeAuthenticationProvider" class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider"&gt;
  2422. &lt;property name="key"&gt;&lt;value&gt;springRocks&lt;/value&gt;&lt;/property&gt;
  2423. &lt;/bean&gt;
  2424. </programlisting>Don't forget to add your
  2425. <literal>RememberMeServices</literal> implementation to your
  2426. <literal>AuthenticationProcessingFilter.setRememberMeServices()</literal>
  2427. property, include the
  2428. <literal>RememberMeAuthenticationProvider</literal> in your
  2429. <literal>AuthenticationManager.setProviders()</literal> list, and add
  2430. a call to <literal>RememberMeProcessingFilter</literal> into your
  2431. <literal>FilterChainProxy</literal> (typically immediately after your
  2432. <literal>AuthenticationProcessingFilter</literal>)</para>
  2433. </sect1>
  2434. </chapter>
  2435. <chapter id="x509">
  2436. <title>X509 Authentication</title>
  2437. <sect1 id="x509-overview">
  2438. <title>Overview</title>
  2439. <para>The most common use of X509 certificate authentication is in
  2440. verifying the identity of a server when using SSL, most commonly when
  2441. using HTTPS from a browser. The browser will automatically check that
  2442. the certificate presented by a server has been issued (ie digitally
  2443. signed) by one of a list of trusted certificate authorities which it
  2444. maintains.</para>
  2445. <para>You can also use SSL with <quote>mutual authentication</quote>;
  2446. the server will then request a valid certificate from the client as
  2447. part of the SSL handshake. The server will authenticate the client by
  2448. checking that it's certificate is signed by an acceptable authority.
  2449. If a valid certificate has been provided, it can be obtained through
  2450. the servlet API in an application. Acegi Security X509 module extracts
  2451. the certificate using a filter and passes it to the configured X509
  2452. authentication provider to allow any additional application-specific
  2453. checks to be applied. It also maps the certificate to an application
  2454. user and loads that user's set of granted authorities for use with the
  2455. standard Acegi Security infrastructure.</para>
  2456. <para>You should be familiar with using certificates and setting up
  2457. client authentication for your servlet container before attempting to
  2458. use it with Acegi Security. Most of the work is in creating and
  2459. installing suitable certificates and keys. For example, if you're
  2460. using Tomcat then read the instructions here <ulink
  2461. url="http://jakarta.apache.org/tomcat/tomcat-5.0-doc/ssl-howto.html"></ulink>.
  2462. It's important that you get this working before trying it out with
  2463. Acegi Security</para>
  2464. </sect1>
  2465. <sect1 id="x509-with-acegi">
  2466. <title>Using X509 with Acegi Security</title>
  2467. <para>With X509 authentication, there is no explicit login procedure
  2468. so the implementation is relatively simple; there is no need to
  2469. redirect requests in order to interact with the user. As a result,
  2470. some of the classes behave slightly differently from their equivalents
  2471. in other packages. For example, the default <quote>entry point</quote>
  2472. class, which is normally responsible for starting the authentication
  2473. process, is only invoked if the certificate is rejected and it always
  2474. returns an error to the user. With a suitable bean configuration, the
  2475. normal sequence of events is as follows <orderedlist>
  2476. <listitem>
  2477. <para>The <classname>X509ProcessingFilter</classname> extracts
  2478. the certificate from the request and uses it as the credentials
  2479. for an authentication request. The generated authentication
  2480. request is an <classname>X509AuthenticationToken</classname>.
  2481. The request is passed to the authentication manager.</para>
  2482. </listitem>
  2483. <listitem>
  2484. <para>The <classname>X509AuthenticationProvider</classname>
  2485. receives the token. Its main concern is to obtain the user
  2486. information (in particular the user's granted authorities) that
  2487. matches the certificate. It delegates this responsibility to an
  2488. <interfacename>X509AuthoritiesPopulator</interfacename>.</para>
  2489. </listitem>
  2490. <listitem>
  2491. <para>The populator's single method,
  2492. <methodname>getUserDetails(X509Certificate
  2493. userCertificate)</methodname> is invoked. Implementations should
  2494. return a <classname>UserDetails</classname> instance containing
  2495. the array of <classname>GrantedAuthority</classname> objects for
  2496. the user. This method can also choose to reject the certificate
  2497. (for example if it doesn't contain a matching user name). In
  2498. such cases it should throw a
  2499. <exceptionname>BadCredentialsException</exceptionname>. A
  2500. DAO-based implementation,
  2501. <classname>DaoX509AuthoritiesPopulator</classname>, is provided
  2502. which extracts the user's name from the subject <quote>common
  2503. name</quote> (CN) in the certificate. It also allows you to set
  2504. your own regular expression to match a different part of the
  2505. subject's distinguished name. A UserDetailsService is used to
  2506. load the user information.<!-- TODO: Give email matching as an example --></para>
  2507. </listitem>
  2508. <listitem>
  2509. <para>If everything has gone smoothly then there should be a
  2510. valid <classname>Authentication</classname> object in the secure
  2511. context and the invocation will procede as normal. If no
  2512. certificate was found, or the certificate was rejected, then the
  2513. <classname>ExceptionTranslationFilter</classname> will invoke
  2514. the <classname>X509ProcessingFilterEntryPoint</classname> which
  2515. returns a 403 error (forbidden) to the user.</para>
  2516. </listitem>
  2517. </orderedlist></para>
  2518. </sect1>
  2519. <sect1 id="x509-config">
  2520. <title>Configuration</title>
  2521. <para>There is a version of the <link
  2522. linkend="contacts-sample">Contacts Sample Application</link> which
  2523. uses X509. Copy the beans and filter setup from this as a starting
  2524. point for configuring your own application. A set of example
  2525. certificates is also included which you can use to configure your
  2526. server. These are <itemizedlist>
  2527. <listitem>
  2528. <para><filename>marissa.p12</filename>: A PKCS12 format file
  2529. containing the client key and certificate. These should be
  2530. installed in your browser. It maps to the user
  2531. <quote>marissa</quote> in the application.</para>
  2532. </listitem>
  2533. <listitem>
  2534. <para><filename>server.p12</filename>: The server certificate
  2535. and key for HTTPS connections.</para>
  2536. </listitem>
  2537. <listitem>
  2538. <para><filename>ca.jks</filename>: A Java keystore containing
  2539. the certificate for the authority which issued marissa's
  2540. certificate. This will be used by the container to validate
  2541. client certificates.</para>
  2542. </listitem>
  2543. </itemizedlist> For JBoss 3.2.7 (with Tomcat 5.0), the SSL
  2544. configuration in the <filename>server.xml</filename> file looks like
  2545. this <programlisting>
  2546. &lt;!-- SSL/TLS Connector configuration --&gt;
  2547. &lt;Connector port="8443" address="${jboss.bind.address}"
  2548. maxThreads="100" minSpareThreads="5" maxSpareThreads="15"
  2549. scheme="https" secure="true"
  2550. sslProtocol = "TLS"
  2551. clientAuth="true" keystoreFile="${jboss.server.home.dir}/conf/server.p12"
  2552. keystoreType="PKCS12" keystorePass="password"
  2553. truststoreFile="${jboss.server.home.dir}/conf/ca.jks"
  2554. truststoreType="JKS" truststorePass="password"
  2555. /&gt;
  2556. </programlisting><parameter>clientAuth</parameter> can also be set to
  2557. <parameter>want</parameter> if you still want SSL connections to
  2558. succeed even if the client doesn't provide a certificate. Obviously
  2559. these clients won't be able to access any objects secured by Acegi
  2560. Security (unless you use a non-X509 authentication mechanism, such as
  2561. BASIC authentication, to authenticate the user)</para>
  2562. </sect1>
  2563. </chapter>
  2564. <chapter id="ldap">
  2565. <title>LDAP Authentication</title>
  2566. <sect1 id="ldap-overview">
  2567. <title>Overview</title>
  2568. <para>LDAP is often used by organizations as a central repository for
  2569. user information and as an authentication service. It can also be used
  2570. to store the role information for application users.</para>
  2571. <para>There are many different scenarios for how an LDAP server may be
  2572. configured so Acegi LDAP provider is fully configurable. It uses
  2573. separate strategy interfaces for authentication and role retrieval and
  2574. provides default implementations which can be configured to handle a
  2575. wide range of situations.</para>
  2576. <para>You should be familiar with LDAP before trying to use it with
  2577. Acegi. The following link provides a good introduction to the concepts
  2578. involved and a guide to setting up a directory using the free LDAP
  2579. server OpenLDAP: <ulink
  2580. url="http://www.zytrax.com/books/ldap/"></ulink>. Some familiarity
  2581. with the JNDI APIs used to access LDAP from Java may also be useful.
  2582. We don't use any third-party LDAP libraries (Mozilla/Netscape, JLDAP
  2583. etc.) in the LDAP provider.</para>
  2584. </sect1>
  2585. <sect1 id="ldap-with-acegi">
  2586. <title>Using LDAP with Acegi Security</title>
  2587. <para>The main LDAP provider class is
  2588. <classname>org.acegisecurity.providers.ldap.LdapAuthenticationProvider</classname>.
  2589. This bean doesn't actually do much itself other than implement the
  2590. <methodname>retrieveUser</methodname> method required by its base
  2591. class,
  2592. <classname>AbstractUserDetailsAuthenticationProvider</classname>. It
  2593. delegates the work to two other beans, an
  2594. <interfacename>LdapAuthenticator</interfacename> and an
  2595. <interfacename>LdapAuthoritiesPopulator</interfacename> which are
  2596. responsible for authenticating the user and retrieving the user's set
  2597. of <interfacename>GrantedAuthority</interfacename>s
  2598. respectively.</para>
  2599. <sect2 id="ldap-ldap-authenticators">
  2600. <title>LdapAuthenticator Implementations</title>
  2601. <para>The authenticator is also responsible for retrieving any
  2602. required user attributes. This is because the permissions on the
  2603. attributes may depend on the type of authentication being used. For
  2604. example, if binding as the user, it may be necessary to read them
  2605. with the user's own permissions.</para>
  2606. <para>There are currently two authentication strategies supplied
  2607. with Acegi Security: <itemizedlist>
  2608. <listitem>
  2609. <para>Authentication directly to the LDAP server ("bind"
  2610. authentication).</para>
  2611. </listitem>
  2612. <listitem>
  2613. <para>Password comparison, where the password supplied by the
  2614. user is compared with the one stored in the repository. This
  2615. can either be done by retrieving the value of the password
  2616. attribute and checking it locally or by performing an LDAP
  2617. "compare" operation, where the supplied password is passed to
  2618. the server for comparison and the real password value is never
  2619. retrieved.</para>
  2620. </listitem>
  2621. </itemizedlist></para>
  2622. <sect3 id="ldap-ldap-authenticators-common">
  2623. <title>Common Functionality</title>
  2624. <para>Before it is possible to authenticate a user (by either
  2625. strategy), the distinguished name (DN) has to be obtained from the
  2626. login name supplied to the application. This can be done either by
  2627. simple pattern-matching (by setting the
  2628. <property>setUserDnPatterns</property> array property) or by
  2629. setting the <property>userSearch</property> property. For the DN
  2630. pattern-matching approach, a standard Java pattern format is used,
  2631. and the login name will be substituted for the parameter
  2632. <parameter>{0}</parameter>. The pattern should be relative to the
  2633. DN that the configured
  2634. <interfacename>InitialDirContextFactory</interfacename> will bind
  2635. to (see the section on <link
  2636. linkend="ldap-dircontextfactory">connecting to the LDAP
  2637. server</link> for more information on this). For example, if you
  2638. are using an LDAP server specified by the URL
  2639. <literal>ldap://monkeymachine.co.uk/dc=acegisecurity,dc=org</literal>,
  2640. and have a pattern <literal>uid={0},ou=greatapes</literal>, then a
  2641. login name of "gorilla" will map to a DN
  2642. <literal>uid=gorilla,ou=greatapes,dc=acegisecurity,dc=org</literal>.
  2643. Each configured DN pattern will be tried in turn until a match is
  2644. found. For information on using a search, see the section on <link
  2645. linkend="ldap-searchobjects">search objects</link> below. A
  2646. combination of the two approaches can also be used - the patterns
  2647. will be checked first and if no matching DN is found, the search
  2648. will be used.</para>
  2649. </sect3>
  2650. <sect3 id="ldap-ldap-authenticators-bind">
  2651. <title>BindAuthenticator</title>
  2652. <para>The class
  2653. <classname>org.acegisecurity.providers.ldap.authenticator.BindAuthenticator</classname>
  2654. implements the bind authentication strategy. It simply attempts to
  2655. bind as the user.</para>
  2656. </sect3>
  2657. <sect3 id="ldap-ldap-authenticators-password">
  2658. <title>PasswordComparisonAuthenticator</title>
  2659. <para>The class
  2660. <classname>org.acegisecurity.providers.ldap.authenticator.PasswordComparisonAuthenticator</classname>
  2661. implements the password comparison authentication strategy.</para>
  2662. </sect3>
  2663. <sect3 id="ldap-ldap-authenticators-active-directory">
  2664. <title>Active Directory Authentication</title>
  2665. <para>In addition to standard LDAP authentication (binding with a
  2666. DN), Active Directory has its own non-standard syntax for user
  2667. authentication.</para>
  2668. </sect3>
  2669. </sect2>
  2670. <sect2 id="ldap-dircontextfactory">
  2671. <title>Connecting to the LDAP Server</title>
  2672. <para>The beans discussed above have to be able to connect to the
  2673. server. They both have to be supplied with an
  2674. <interfacename>InitialDirContextFactory</interfacename> instance.
  2675. Unless you have special requirements, this will usually be a
  2676. <classname>DefaultInitialDirContextFactory</classname> bean, which
  2677. can be configured with the URL of your LDAP server and optionally
  2678. with the username and password of a "manager" user which will be
  2679. used by default when binding to the server (instead of binding
  2680. anonymously). It currently supports "simple" LDAP
  2681. authentication.</para>
  2682. <para><classname>DefaultInitialDirContextFactory</classname> uses
  2683. Sun's JNDI LDAP implementation by default (the one that comes with
  2684. the JDK). It also supports the built in connection pooling offered
  2685. by Sun's provider. Connections which are obtained either anonymously
  2686. or with the "manager" user's identity will be pooled automatically.
  2687. Connections obtained with a specific user's identity will not be
  2688. pooled. Connection pooling can be disabled completely by setting the
  2689. <property>useConnectionPool</property> property to false.</para>
  2690. <para>See the <ulink
  2691. url="http://acegisecurity.org/multiproject/acegi-security/xref/org/acegisecurity/providers/ldap/DefaultInitialDirContextFactory.html">class
  2692. Javadoc and source</ulink> for more information on this bean and its
  2693. properties.</para>
  2694. </sect2>
  2695. <sect2 id="ldap-searchobjects">
  2696. <title>LDAP Search Objects</title>
  2697. <para>Often more a more complicated strategy than simple DN-matching
  2698. is required to locate a user entry in the directory. This can be
  2699. encapsulated in an <interfacename>LdapUserSearch</interfacename>
  2700. instance which can be supplied to the authenticator implementations,
  2701. for example, to allow them to locate a user. The supplied
  2702. implementation is
  2703. <classname>FilterBasedLdapUserSearch</classname>.</para>
  2704. <sect3 id="ldap-searchobjects-filter">
  2705. <title
  2706. id="ldap-searchobjects-filter-based"><classname>FilterBasedLdapUserSearch</classname></title>
  2707. <para>This bean uses an LDAP filter to match the user object in
  2708. the directory. The process is explained in the Javadoc for the
  2709. corresponding search method on the <ulink
  2710. url="http://java.sun.com/j2se/1.4.2/docs/api/javax/naming/directory/DirContext.html#search(javax.naming.Name,%20java.lang.String,%20java.lang.Object[],%20javax.naming.directory.SearchControls)">JDK
  2711. DirContext class</ulink>. As explained there, the search filter
  2712. can be supplied with parameters. For this class, the only valid
  2713. parameter is <parameter>{0}</parameter> which will be replaced
  2714. with the user's login name.</para>
  2715. </sect3>
  2716. </sect2>
  2717. </sect1>
  2718. <sect1 id="ldap-config">
  2719. <title>Configuration</title>
  2720. <para>There is a version of the <link
  2721. linkend="contacts-sample">Contacts Sample Application</link> which
  2722. uses LDAP. You can copy the beans and filter setup from this as a
  2723. starting point for configuring your own application.</para>
  2724. <para>A typical configuration, using some of the beans we've discussed
  2725. above, might look like this: <programlisting>
  2726. &lt;bean id="initialDirContextFactory"
  2727. class="org.acegisecurity.ldap.DefaultInitialDirContextFactory"&gt;
  2728. &lt;constructor-arg value="ldap://monkeymachine:389/dc=acegisecurity,dc=org"/&gt;
  2729. &lt;property name="managerDn"&gt;&lt;value&gt;cn=manager,dc=acegisecurity,dc=org&lt;/value&gt;&lt;/property&gt;
  2730. &lt;property name="managerPassword"&gt;&lt;value&gt;password&lt;/value&gt;&lt;/property&gt;
  2731. &lt;/bean&gt;
  2732. &lt;bean id="userSearch"
  2733. class="org.acegisecurity.ldap.search.FilterBasedLdapUserSearch"&gt;
  2734. &lt;constructor-arg index="0"&gt;
  2735. &lt;value&gt;&lt;/value&gt;
  2736. &lt;/constructor-arg&gt;
  2737. &lt;constructor-arg index="1"&gt;
  2738. &lt;value&gt;(uid={0})&lt;/value&gt;
  2739. &lt;/constructor-arg&gt;
  2740. &lt;constructor-arg index="2"&gt;
  2741. &lt;ref local="initialDirContextFactory" /&gt;
  2742. &lt;/constructor-arg&gt;
  2743. &lt;property name="searchSubtree"&gt;
  2744. &lt;value&gt;true&lt;/value&gt;
  2745. &lt;/property&gt;
  2746. &lt;/bean&gt;
  2747. &lt;bean id="ldapAuthProvider"
  2748. class="org.acegisecurity.providers.ldap.LdapAuthenticationProvider"&gt;
  2749. &lt;constructor-arg&gt;
  2750. &lt;bean class="org.acegisecurity.providers.ldap.authenticator.BindAuthenticator"&gt;
  2751. &lt;constructor-arg&gt;&lt;ref local="initialDirContextFactory"/&gt;&lt;/constructor-arg&gt;
  2752. &lt;property name="userDnPatterns"&gt;&lt;list&gt;&lt;value&gt;uid={0},ou=people&lt;/value&gt;&lt;/list&gt;&lt;/property&gt;
  2753. &lt;/bean&gt;
  2754. &lt;/constructor-arg&gt;
  2755. &lt;constructor-arg&gt;
  2756. &lt;bean class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator"&gt;
  2757. &lt;constructor-arg&gt;&lt;ref local="initialDirContextFactory"/&gt;&lt;/constructor-arg&gt;
  2758. &lt;constructor-arg&gt;&lt;value&gt;ou=groups&lt;/value&gt;&lt;/constructor-arg&gt;
  2759. &lt;property name="groupRoleAttribute"&gt;&lt;value&gt;ou&lt;/value&gt;&lt;/property&gt;
  2760. &lt;/bean&gt;
  2761. &lt;/constructor-arg&gt;
  2762. &lt;/bean&gt;
  2763. </programlisting> This would set up the provider to access an LDAP
  2764. server with URL
  2765. <literal>ldap://monkeymachine:389/dc=acegisecurity,dc=org</literal>.
  2766. Authentication will be performed by attempting to bind with the DN
  2767. <literal>uid=&lt;user-login-name&gt;,ou=people,dc=acegisecurity,dc=org</literal>.
  2768. After successful authentication, roles will be assigned to the user by
  2769. searching under the DN
  2770. <literal>ou=groups,dc=acegisecurity,dc=org</literal> with the default
  2771. filter <literal>(member=&lt;user's-DN&gt;)</literal>. The role name
  2772. will be taken from the <quote>ou</quote> attribute of each
  2773. match.</para>
  2774. <para>We've also included the configuration for a user search object,
  2775. which uses the filter
  2776. <literal>(uid=&lt;user-login-name&gt;)</literal>. This could be used
  2777. instead of the DN-pattern (or in addition to it), by setting the
  2778. authenticator's <property>userSearch</property> property. The
  2779. authenticator would then call the search object to obtain the correct
  2780. user's DN before attempting to bind as this user.</para>
  2781. </sect1>
  2782. </chapter>
  2783. <chapter id="cas">
  2784. <title>CAS Authentication</title>
  2785. <sect1 id="cas-overview">
  2786. <title>Overview</title>
  2787. <para>JA-SIG produces an enterprise-wide single sign on system known
  2788. as CAS. Unlike other initiatives, JA-SIG's Central Authentication
  2789. Service is open source, widely used, simple to understand, platform
  2790. independent, and supports proxy capabilities. Acegi Security fully
  2791. supports CAS, and provides an easy migration path from
  2792. single-application deployments of Acegi Security through to
  2793. multiple-application deployments secured by an enterprise-wide CAS
  2794. server.</para>
  2795. <para>You can learn more about CAS at
  2796. <literal>http://www.ja-sig.org/products/cas/</literal>. You will need
  2797. to visit this URL to download the CAS Server files. Whilst Acegi
  2798. Security includes two CAS libraries in the "-with-dependencies" ZIP
  2799. file, you will still need the CAS Java Server Pages and
  2800. <literal>web.xml</literal> to customise and deploy your CAS
  2801. server.</para>
  2802. </sect1>
  2803. <sect1 id="cas-how-it-works">
  2804. <title>How CAS Works</title>
  2805. <para>Whilst the CAS web site above contains two documents that detail
  2806. the architecture of CAS, we present the general overview again here
  2807. within the context of Acegi Security. The following refers to both CAS
  2808. 2.0 (produced by Yale) and CAS 3.0 (produced by JA-SIG), being the
  2809. versions of CAS that Acegi Security supports.</para>
  2810. <para>Somewhere in your enterprise you will need to setup a CAS
  2811. server. The CAS server is simply a standard WAR file, so there isn't
  2812. anything difficult about setting up your server. Inside the WAR file
  2813. you will customise the login and other single sign on pages displayed
  2814. to users.</para>
  2815. <para>If you are deploying CAS 2.0, you will also need to specify in
  2816. the web.xml a <literal>PasswordHandler</literal>. The
  2817. <literal>PasswordHandler</literal> has a simple method that returns a
  2818. boolean as to whether a given username and password is valid. Your
  2819. <literal>PasswordHandler</literal> implementation will need to link
  2820. into some type of backend authentication repository, such as an LDAP
  2821. server or database.</para>
  2822. <para>If you are already running an existing CAS 2.0 server instance,
  2823. you will have already established a
  2824. <literal>PasswordHandler</literal>. If you do not already have a
  2825. <literal>PasswordHandler</literal>, you might prefer to use Acegi
  2826. Security <literal>CasPasswordHandler</literal> class. This class
  2827. delegates through to the standard Acegi Security
  2828. <literal>AuthenticationManager</literal>, enabling you to use a
  2829. security configuration you might already have in place. You do not
  2830. need to use the <literal>CasPasswordHandler</literal> class on your
  2831. CAS server if you do not wish. Acegi Security will function as a CAS
  2832. client successfully irrespective of the
  2833. <literal>PasswordHandler</literal> you've chosen for your CAS
  2834. server.</para>
  2835. <para>If you are deploying CAS 3.0, you will also need to specify an
  2836. <literal>AuthenticationHandler</literal> in the
  2837. deployerConfigContext.xml included with CAS. The
  2838. <literal>AuthenticationHandler</literal> has a simple method that
  2839. returns a boolean as to whether a given set of Credentials is valid.
  2840. Your <literal>AuthenticationHandler</literal> implementation will need
  2841. to link into some type of backend authentication repository, such as
  2842. an LDAP server or database. CAS itself includes numerous
  2843. <literal>AuthenticationHandler</literal>s out of the box to assist
  2844. with this.</para>
  2845. <para>If you are already running an existing CAS 3.0 server instance,
  2846. you will have already established an
  2847. <literal>AuthenticationHandler</literal>. If you do not already have
  2848. an <literal>AuthenticationHandler</literal>, you might prefer to use
  2849. Acegi Security <literal>CasAuthenticationHandler</literal> class. This
  2850. class delegates through to the standard Acegi Security
  2851. <literal>AuthenticationManager</literal>, enabling you to use a
  2852. security configuration you might already have in place. You do not
  2853. need to use the <literal>CasAuthenticationHandler</literal> class on
  2854. your CAS server if you do not wish. Acegi Security will function as a
  2855. CAS client successfully irrespective of the
  2856. <literal>AuthenticationHandler</literal> you've chosen for your CAS
  2857. server.</para>
  2858. <para>Apart from the CAS server itself, the other key player is of
  2859. course the secure web applications deployed throughout your
  2860. enterprise. These web applications are known as "services". There are
  2861. two types of services: standard services and proxy services. A proxy
  2862. service is able to request resources from other services on behalf of
  2863. the user. This will be explained more fully later.</para>
  2864. <para>Services can be developed in a large variety of languages, due
  2865. to CAS 2.0's very light XML-based protocol. The JA-SIG CAS home page
  2866. contains a clients archive which demonstrates CAS clients in Java,
  2867. Active Server Pages, Perl, Python and others. Naturally, Java support
  2868. is very strong given the CAS server is written in Java. You do not
  2869. need to use any of CAS' client classes in applications secured by
  2870. Acegi Security. This is handled transparently for you.</para>
  2871. <para>The basic interaction between a web browser, CAS server and an
  2872. Acegi Security for System Spring secured service is as follows:</para>
  2873. <orderedlist>
  2874. <listitem>
  2875. <para>The web user is browsing the service's public pages. CAS or
  2876. Acegi Security is not involved.</para>
  2877. </listitem>
  2878. <listitem>
  2879. <para>The user eventually requests a page that is either secure or
  2880. one of the beans it uses is secure. Acegi Security's
  2881. <literal>ExceptionTranslationFilter</literal> will detect the
  2882. <literal>AuthenticationException</literal>.</para>
  2883. </listitem>
  2884. <listitem>
  2885. <para>Because the user's <literal>Authentication</literal> object
  2886. (or lack thereof) caused an
  2887. <literal>AuthenticationException</literal>, the
  2888. <literal>ExceptionTranslationFilter</literal> will call the
  2889. configured <literal>AuthenticationEntryPoint</literal>. If using
  2890. CAS, this will be the
  2891. <literal>CasProcessingFilterEntryPoint</literal> class.</para>
  2892. </listitem>
  2893. <listitem>
  2894. <para>The <literal>CasProcessingFilterEntry</literal> point will
  2895. redirect the user's browser to the CAS server. It will also
  2896. indicate a <literal>service</literal> parameter, which is the
  2897. callback URL for Acegi Security service. For example, the URL to
  2898. which the browser is redirected might be
  2899. <literal>https://my.company.com/cas/login?service=https%3A%2F%2Fserver3.company.com%2Fwebapp%2Fj_acegi_cas_security_check</literal>.</para>
  2900. </listitem>
  2901. <listitem>
  2902. <para>After the user's browser redirects to CAS, they will be
  2903. prompted for their username and password. If the user presents a
  2904. session cookie which indicates they've previously logged on, they
  2905. will not be prompted to login again (there is an exception to this
  2906. procedure, which we'll cover later). CAS will use the
  2907. <literal>PasswordHandler</literal> (or
  2908. <literal>AuthenticationHandler</literal> if using CAS 3.0)
  2909. discussed above to decide whether the username and password is
  2910. valid.</para>
  2911. </listitem>
  2912. <listitem>
  2913. <para>Upon successful login, CAS will redirect the user's browser
  2914. back to the original service. It will also include a
  2915. <literal>ticket</literal> parameter, which is an opaque string
  2916. representing the "service ticket". Continuing our earlier example,
  2917. the URL the browser is redirected to might be
  2918. <literal>https://server3.company.com/webapp/j_acegi_cas_security_check?ticket=ST-0-ER94xMJmn6pha35CQRoZ</literal>.</para>
  2919. </listitem>
  2920. <listitem>
  2921. <para>Back in the service web application, the
  2922. <literal>CasProcessingFilter</literal> is always listening for
  2923. requests to <literal>/j_acegi_cas_security_check</literal> (this
  2924. is configurable, but we'll use the defaults in this introduction).
  2925. The processing filter will construct a
  2926. <literal>UsernamePasswordAuthenticationToken</literal>
  2927. representing the service ticket. The principal will be equal to
  2928. <literal>CasProcessingFilter.CAS_STATEFUL_IDENTIFIER</literal>,
  2929. whilst the credentials will be the service ticket opaque value.
  2930. This authentication request will then be handed to the configured
  2931. <literal>AuthenticationManager</literal>.</para>
  2932. </listitem>
  2933. <listitem>
  2934. <para>The <literal>AuthenticationManager</literal> implementation
  2935. will be the <literal>ProviderManager</literal>, which is in turn
  2936. configured with the <literal>CasAuthenticationProvider</literal>.
  2937. The <literal>CasAuthenticationProvider</literal> only responds to
  2938. <literal>UsernamePasswordAuthenticationToken</literal>s containing
  2939. the CAS-specific principal (such as
  2940. <literal>CasProcessingFilter.CAS_STATEFUL_IDENTIFIER</literal>)
  2941. and <literal>CasAuthenticationToken</literal>s (discussed
  2942. later).</para>
  2943. </listitem>
  2944. <listitem>
  2945. <para><literal>CasAuthenticationProvider</literal> will validate
  2946. the service ticket using a <literal>TicketValidator</literal>
  2947. implementation. Acegi Security includes one implementation, the
  2948. <literal>CasProxyTicketValidator</literal>. This implementation a
  2949. ticket validation class included in the CAS client library. The
  2950. <literal>CasProxyTicketValidator</literal> makes a HTTPS request
  2951. to the CAS server in order to validate the service ticket. The
  2952. <literal>CasProxyTicketValidator</literal> may also include a
  2953. proxy callback URL, which is included in this example:
  2954. <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>
  2955. </listitem>
  2956. <listitem>
  2957. <para>Back on the CAS server, the proxy validation request will be
  2958. received. If the presented service ticket matches the service URL
  2959. the ticket was issued to, CAS will provide an affirmative response
  2960. in XML indicating the username. If any proxy was involved in the
  2961. authentication (discussed below), the list of proxies is also
  2962. included in the XML response.</para>
  2963. </listitem>
  2964. <listitem>
  2965. <para>[OPTIONAL] If the request to the CAS validation service
  2966. included the proxy callback URL (in the <literal>pgtUrl</literal>
  2967. parameter), CAS will include a <literal>pgtIou</literal> string in
  2968. the XML response. This <literal>pgtIou</literal> represents a
  2969. proxy-granting ticket IOU. The CAS server will then create its own
  2970. HTTPS connection back to the <literal>pgtUrl</literal>. This is to
  2971. mutually authenticate the CAS server and the claimed service URL.
  2972. The HTTPS connection will be used to send a proxy granting ticket
  2973. to the original web application. For example,
  2974. <literal>https://server3.company.com/webapp/casProxy/receptor?pgtIou=PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt&amp;pgtId=PGT-1-si9YkkHLrtACBo64rmsi3v2nf7cpCResXg5MpESZFArbaZiOKH</literal>.
  2975. We suggest you use CAS' <literal>ProxyTicketReceptor</literal>
  2976. servlet to receive these proxy-granting tickets, if they are
  2977. required.</para>
  2978. </listitem>
  2979. <listitem>
  2980. <para>The <literal>CasProxyTicketValidator</literal> will parse
  2981. the XML received from the CAS server. It will return to the
  2982. <literal>CasAuthenticationProvider</literal> a
  2983. <literal>TicketResponse</literal>, which includes the username
  2984. (mandatory), proxy list (if any were involved), and proxy-granting
  2985. ticket IOU (if the proxy callback was requested).</para>
  2986. </listitem>
  2987. <listitem>
  2988. <para>Next <literal>CasAuthenticationProvider</literal> will call
  2989. a configured <literal>CasProxyDecider</literal>. The
  2990. <literal>CasProxyDecider</literal> indicates whether the proxy
  2991. list in the <literal>TicketResponse</literal> is acceptable to the
  2992. service. Several implementations are provided with Acegi Security
  2993. System: <literal>RejectProxyTickets</literal>,
  2994. <literal>AcceptAnyCasProxy</literal> and
  2995. <literal>NamedCasProxyDecider</literal>. These names are largely
  2996. self-explanatory, except <literal>NamedCasProxyDecider</literal>
  2997. which allows a <literal>List</literal> of trusted proxies to be
  2998. provided.</para>
  2999. </listitem>
  3000. <listitem>
  3001. <para><literal>CasAuthenticationProvider</literal> will next
  3002. request a <literal>CasAuthoritiesPopulator</literal> to advise the
  3003. <literal>GrantedAuthority</literal> objects that apply to the user
  3004. contained in the <literal>TicketResponse</literal>. Acegi Security
  3005. includes a <literal>DaoCasAuthoritiesPopulator</literal> which
  3006. simply uses the <literal>UserDetailsService</literal>
  3007. infrastructure to find the <literal>UserDetails</literal> and
  3008. their associated <literal>GrantedAuthority</literal>s. Note that
  3009. the password and enabled/disabled status of
  3010. <literal>UserDetails</literal> returned by the
  3011. <literal>UserDetailsService</literal> are ignored, as the CAS
  3012. server is responsible for authentication decisions.
  3013. <literal>DaoCasAuthoritiesPopulator</literal> is only concerned
  3014. with retrieving the <literal>GrantedAuthority</literal>s.</para>
  3015. </listitem>
  3016. <listitem>
  3017. <para>If there were no problems,
  3018. <literal>CasAuthenticationProvider</literal> constructs a
  3019. <literal>CasAuthenticationToken</literal> including the details
  3020. contained in the <literal>TicketResponse</literal> and the
  3021. <literal>GrantedAuthority</literal>s. The
  3022. <literal>CasAuthenticationToken</literal> contains the hash of a
  3023. key, so that the <literal>CasAuthenticationProvider</literal>
  3024. knows it created it.</para>
  3025. </listitem>
  3026. <listitem>
  3027. <para>Control then returns to
  3028. <literal>CasProcessingFilter</literal>, which places the created
  3029. <literal>CasAuthenticationToken</literal> into the
  3030. <literal>HttpSession</literal> attribute named
  3031. <literal>HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY</literal>.</para>
  3032. </listitem>
  3033. <listitem>
  3034. <para>The user's browser is redirected to the original page that
  3035. caused the <literal>AuthenticationException</literal>.</para>
  3036. </listitem>
  3037. <listitem>
  3038. <para>As the <literal>Authentication</literal> object is now in
  3039. the well-known location, it is handled like any other
  3040. authentication approach. Usually the
  3041. <literal>HttpSessionIntegrationFilter</literal> will be used to
  3042. associate the <literal>Authentication</literal> object with the
  3043. <literal>SecurityContextHolder</literal> for the duration of each
  3044. request.</para>
  3045. </listitem>
  3046. </orderedlist>
  3047. <para>It's good that you're still here! It might sound involved, but
  3048. you can relax as Acegi Security classes hide much of the complexity.
  3049. Let's now look at how this is configured</para>
  3050. </sect1>
  3051. <sect1 id="cas-server">
  3052. <title>Optional CAS Server Setup</title>
  3053. <para>Acegi Security can even act as the backend which a CAS version
  3054. 2.0 or 3.0 server utilises. The configuration approach is described
  3055. below. Of course, if you have an existing CAS environment you might
  3056. just like to use it instead.</para>
  3057. <sect2 id="cas-server-2">
  3058. <title>CAS Version 2.0</title>
  3059. <para>As mentioned above, Acegi Security includes a
  3060. <literal>PasswordHandler</literal> that bridges your existing
  3061. <literal>AuthenticationManager</literal> into CAS 2.0. You do not
  3062. need to use this <literal>PasswordHandler</literal> to use Acegi
  3063. Security on the client side (any CAS
  3064. <literal>PasswordHandler</literal> will do).</para>
  3065. <para>To install, you will need to download and extract the CAS
  3066. server archive. We used version 2.0.12. There will be a
  3067. <literal>/web</literal> directory in the root of the deployment.
  3068. Copy an <literal>applicationContext.xml</literal> containing your
  3069. <literal>AuthenticationManager</literal> as well as the
  3070. <literal>CasPasswordHandler</literal> into the
  3071. <literal>/web/WEB-INF</literal> directory. A sample
  3072. <literal>applicationContext.xml</literal> is included below:</para>
  3073. <programlisting>
  3074. &lt;bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl"&gt;
  3075. &lt;property name="userMap"&gt;
  3076. &lt;value&gt;
  3077. marissa=koala,ROLES_IGNORED_BY_CAS
  3078. dianne=emu,ROLES_IGNORED_BY_CAS
  3079. scott=wombat,ROLES_IGNORED_BY_CAS
  3080. peter=opal,disabled,ROLES_IGNORED_BY_CAS
  3081. &lt;/value&gt;
  3082. &lt;/property&gt;
  3083. &lt;/bean&gt;
  3084. &lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  3085. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3086. &lt;/bean&gt;
  3087. &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  3088. &lt;property name="providers"&gt;
  3089. &lt;list&gt;
  3090. &lt;ref bean="daoAuthenticationProvider"/&gt;
  3091. &lt;/list&gt;
  3092. &lt;/property&gt;
  3093. &lt;/bean&gt;
  3094. &lt;bean id="casPasswordHandler" class="org.acegisecurity.adapters.cas.CasPasswordHandler"&gt;
  3095. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  3096. &lt;/bean&gt;
  3097. </programlisting>
  3098. <para>Note the granted authorities are ignored by CAS because it has
  3099. no way of communicating the granted authorities to calling
  3100. applications. CAS is only concerned with username and passwords (and
  3101. the enabled/disabled status).</para>
  3102. <para>Next you will need to edit the existing
  3103. <literal>/web/WEB-INF/web.xml</literal> file. Add (or edit in the
  3104. case of the <literal>authHandler</literal> property) the following
  3105. lines:</para>
  3106. <para><programlisting>
  3107. &lt;context-param&gt;
  3108. &lt;param-name&gt;edu.yale.its.tp.cas.authHandler&lt;/param-name&gt;
  3109. &lt;param-value&gt;org.acegisecurity.adapters.cas.CasPasswordHandlerProxy&lt;/param-value&gt;
  3110. &lt;/context-param&gt;
  3111. &lt;context-param&gt;
  3112. &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
  3113. &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
  3114. &lt;/context-param&gt;
  3115. &lt;listener&gt;
  3116. &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  3117. &lt;/listener&gt;
  3118. </programlisting></para>
  3119. <para>Copy the <literal>spring.jar</literal> and
  3120. <literal>acegi-security.jar</literal> files into
  3121. <literal>/web/WEB-INF/lib</literal>. Now use the <literal>ant
  3122. dist</literal> task in the <literal>build.xml</literal> in the root
  3123. of the directory structure. This will create
  3124. <literal>/lib/cas.war</literal>, which is ready for deployment to
  3125. your servlet container.</para>
  3126. <para>Note CAS heavily relies on HTTPS. You can't even test the
  3127. system without a HTTPS certificate. Whilst you should refer to your
  3128. web container's documentation on setting up HTTPS, if you need some
  3129. additional help or a test certificate you might like to check the
  3130. <literal>samples/contacts/etc/ssl</literal> directory</para>
  3131. </sect2>
  3132. <sect2 id="cas-server-3">
  3133. <title>CAS Version 3.0</title>
  3134. <para>As mentioned above, Acegi Security includes an
  3135. <literal>AuthenticationHandler</literal> that bridges your existing
  3136. <literal>AuthenticationManager</literal> into CAS 3.0. You do not
  3137. need to use this <literal>AuthenticationHandler</literal> to use
  3138. Acegi Security on the client side (any CAS
  3139. <literal>AuthenticationHandler</literal> will do).</para>
  3140. <para>To install, you will need to download and extract the CAS
  3141. server archive. We used version 3.0.4. There will be a
  3142. <literal>/webapp</literal> directory in the root of the deployment.
  3143. Edit the an <literal>deployerConfigContext.xml</literal> so that it
  3144. contains your <literal>AuthenticationManager</literal> as well as
  3145. the <literal>CasAuthenticationHandler</literal>. A sample
  3146. <literal>applicationContext.xml</literal> is included below:</para>
  3147. <programlisting>
  3148. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  3149. &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  3150. &lt;beans&gt;
  3151. &lt;bean
  3152. id="authenticationManager"
  3153. class="org.jasig.cas.authentication.AuthenticationManagerImpl"&gt;
  3154. &lt;property name="credentialsToPrincipalResolvers"&gt;
  3155. &lt;list&gt;
  3156. &lt;bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" /&gt;
  3157. &lt;bean class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /&gt;
  3158. &lt;/list&gt;
  3159. &lt;/property&gt;
  3160. &lt;property name="authenticationHandlers"&gt;
  3161. &lt;list&gt;
  3162. &lt;bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" /&gt;
  3163. &lt;bean class="org.acegisecurity.adapters.cas3.CasAuthenticationHandler"&gt;
  3164. &lt;property name="authenticationManager" ref="acegiAuthenticationManager" /&gt;
  3165. &lt;/bean&gt;
  3166. &lt;/list&gt;
  3167. &lt;/property&gt;
  3168. &lt;/bean&gt;
  3169. &lt;bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl"&gt;
  3170. &lt;property name="userMap"&gt;
  3171. &lt;value&gt;
  3172. marissa=koala,ROLES_IGNORED_BY_CAS
  3173. dianne=emu,ROLES_IGNORED_BY_CAS
  3174. scott=wombat,ROLES_IGNORED_BY_CAS
  3175. peter=opal,disabled,ROLES_IGNORED_BY_CAS
  3176. &lt;/value&gt;
  3177. &lt;/property&gt;
  3178. &lt;/bean&gt;
  3179. &lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  3180. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3181. &lt;/bean&gt;
  3182. &lt;bean id="acegiAuthenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  3183. &lt;property name="providers"&gt;
  3184. &lt;list&gt;
  3185. &lt;ref bean="daoAuthenticationProvider"/&gt;
  3186. &lt;/list&gt;
  3187. &lt;/property&gt;
  3188. &lt;/bean&gt;
  3189. &lt;/beans&gt;
  3190. </programlisting>
  3191. <para>Note the granted authorities are ignored by CAS because it has
  3192. no way of communicating the granted authorities to calling
  3193. applications. CAS is only concerned with username and passwords (and
  3194. the enabled/disabled status).</para>
  3195. <para>Copy Acegi<literal>-security.jar</literal> file into
  3196. <literal>/localPlugins/lib</literal>. Now use the <literal>ant
  3197. war</literal> task in the <literal>build.xml</literal> in the
  3198. /localPlugins directory. This will create
  3199. <literal>/localPlugins/target/cas.war</literal>, which is ready for
  3200. deployment to your servlet container.</para>
  3201. <para>Note CAS heavily relies on HTTPS. You can't even test the
  3202. system without a HTTPS certificate. Whilst you should refer to your
  3203. web container's documentation on setting up HTTPS, if you need some
  3204. additional help or a test certificate you might like to check the
  3205. CAS documentation on setting up SSL:
  3206. <literal>http://www.ja-sig.org/products/cas/server/ssl/index.html</literal></para>
  3207. </sect2>
  3208. </sect1>
  3209. <sect1 id="cas-client">
  3210. <title>Configuration of CAS Client</title>
  3211. <para>The web application side of CAS is made easy due to Acegi
  3212. Security. It is assumed you already know the basics of using Acegi
  3213. Security, so these are not covered again below. Only the CAS-specific
  3214. beans are mentioned.</para>
  3215. <para>You will need to add a <literal>ServiceProperties</literal> bean
  3216. to your application context. This represents your service:</para>
  3217. <para><programlisting>
  3218. &lt;bean id="serviceProperties" class="org.acegisecurity.ui.cas.ServiceProperties"&gt;
  3219. &lt;property name="service"&gt;&lt;value&gt;https://localhost:8443/contacts-cas/j_acegi_cas_security_check&lt;/value&gt;&lt;/property&gt;
  3220. &lt;property name="sendRenew"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  3221. &lt;/bean&gt;
  3222. </programlisting></para>
  3223. <para>The <literal>service</literal> must equal a URL that will be
  3224. monitored by the <literal>CasProcessingFilter</literal>. The
  3225. <literal>sendRenew</literal> defaults to false, but should be set to
  3226. true if your application is particularly sensitive. What this
  3227. parameter does is tell the CAS login service that a single sign on
  3228. login is unacceptable. Instead, the user will need to re-enter their
  3229. username and password in order to gain access to the service.</para>
  3230. <para>The following beans should be configured to commence the CAS
  3231. authentication process:</para>
  3232. <para><programlisting>
  3233. &lt;bean id="casProcessingFilter" class="org.acegisecurity.ui.cas.CasProcessingFilter"&gt;
  3234. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  3235. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/casfailed.jsp&lt;/value&gt;&lt;/property&gt;
  3236. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;
  3237. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_cas_security_check&lt;/value&gt;&lt;/property&gt;
  3238. &lt;/bean&gt;
  3239. &lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;
  3240. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="casProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  3241. &lt;/bean&gt;
  3242. &lt;bean id="casProcessingFilterEntryPoint" class="org.acegisecurity.ui.cas.CasProcessingFilterEntryPoint"&gt;
  3243. &lt;property name="loginUrl"&gt;&lt;value&gt;https://localhost:8443/cas/login&lt;/value&gt;&lt;/property&gt;
  3244. &lt;property name="serviceProperties"&gt;&lt;ref bean="serviceProperties"/&gt;&lt;/property&gt;
  3245. &lt;/bean&gt;
  3246. </programlisting></para>
  3247. <para>You will also need to add the
  3248. <literal>CasProcessingFilter</literal> to web.xml:</para>
  3249. <para><programlisting>
  3250. &lt;filter&gt;
  3251. &lt;filter-name&gt;Acegi CAS Processing Filter&lt;/filter-name&gt;
  3252. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  3253. &lt;init-param&gt;
  3254. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  3255. &lt;param-value&gt;org.acegisecurity.ui.cas.CasProcessingFilter&lt;/param-value&gt;
  3256. &lt;/init-param&gt;
  3257. &lt;/filter&gt;
  3258. &lt;filter-mapping&gt;
  3259. &lt;filter-name&gt;Acegi CAS Processing Filter&lt;/filter-name&gt;
  3260. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  3261. &lt;/filter-mapping&gt;
  3262. </programlisting></para>
  3263. <para>The <literal>CasProcessingFilter</literal> has very similar
  3264. properties to the <literal>AuthenticationProcessingFilter</literal>
  3265. (used for form-based logins). Each property is
  3266. self-explanatory.</para>
  3267. <para>For CAS to operate, the
  3268. <literal>ExceptionTranslationFilter</literal> must have its
  3269. <literal>authenticationEntryPoint</literal> property set to the
  3270. <literal>CasProcessingFilterEntryPoint</literal> bean.</para>
  3271. <para>The <literal>CasProcessingFilterEntryPoint</literal> must refer
  3272. to the <literal>ServiceProperties</literal> bean (discussed above),
  3273. which provides the URL to the enterprise's CAS login server. This is
  3274. where the user's browser will be redirected.</para>
  3275. <para>Next you need to add an <literal>AuthenticationManager</literal>
  3276. that uses <literal>CasAuthenticationProvider</literal> and its
  3277. collaborators:</para>
  3278. <para><programlisting>
  3279. &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  3280. &lt;property name="providers"&gt;
  3281. &lt;list&gt;
  3282. &lt;ref bean="casAuthenticationProvider"/&gt;
  3283. &lt;/list&gt;
  3284. &lt;/property&gt;
  3285. &lt;/bean&gt;
  3286. &lt;bean id="casAuthenticationProvider" class="org.acegisecurity.providers.cas.CasAuthenticationProvider"&gt;
  3287. &lt;property name="casAuthoritiesPopulator"&gt;&lt;ref bean="casAuthoritiesPopulator"/&gt;&lt;/property&gt;
  3288. &lt;property name="casProxyDecider"&gt;&lt;ref bean="casProxyDecider"/&gt;&lt;/property&gt;
  3289. &lt;property name="ticketValidator"&gt;&lt;ref bean="casProxyTicketValidator"/&gt;&lt;/property&gt;
  3290. &lt;property name="statelessTicketCache"&gt;&lt;ref bean="statelessTicketCache"/&gt;&lt;/property&gt;
  3291. &lt;property name="key"&gt;&lt;value&gt;my_password_for_this_auth_provider_only&lt;/value&gt;&lt;/property&gt;
  3292. &lt;/bean&gt;
  3293. &lt;bean id="casProxyTicketValidator" class="org.acegisecurity.providers.cas.ticketvalidator.CasProxyTicketValidator"&gt;
  3294. &lt;property name="casValidate"&gt;&lt;value&gt;https://localhost:8443/cas/proxyValidate&lt;/value&gt;&lt;/property&gt;
  3295. &lt;property name="proxyCallbackUrl"&gt;&lt;value&gt;https://localhost:8443/contacts-cas/casProxy/receptor&lt;/value&gt;&lt;/property&gt;
  3296. &lt;property name="serviceProperties"&gt;&lt;ref bean="serviceProperties"/&gt;&lt;/property&gt;
  3297. &lt;!-- &lt;property name="trustStore"&gt;&lt;value&gt;/some/path/to/your/lib/security/cacerts&lt;/value&gt;&lt;/property&gt; --&gt;
  3298. &lt;/bean&gt;
  3299. &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;
  3300. &lt;property name="configLocation"&gt;
  3301. &lt;value&gt;classpath:/ehcache-failsafe.xml&lt;/value&gt;
  3302. &lt;/property&gt;
  3303. &lt;/bean&gt;
  3304. &lt;bean id="ticketCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;
  3305. &lt;property name="cacheManager"&gt;
  3306. &lt;ref local="cacheManager"/&gt;
  3307. &lt;/property&gt;
  3308. &lt;property name="cacheName"&gt;
  3309. &lt;value&gt;ticketCache&lt;/value&gt;
  3310. &lt;/property&gt;
  3311. &lt;/bean&gt;
  3312. &lt;bean id="statelessTicketCache" class="org.acegisecurity.providers.cas.cache.EhCacheBasedTicketCache"&gt;
  3313. &lt;property name="cache"&gt;&lt;ref local="ticketCacheBackend"/&gt;&lt;/property&gt;
  3314. &lt;/bean&gt;
  3315. &lt;bean id="casAuthoritiesPopulator" class="org.acegisecurity.providers.cas.populator.DaoCasAuthoritiesPopulator"&gt;
  3316. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3317. &lt;/bean&gt;
  3318. &lt;bean id="casProxyDecider" class="org.acegisecurity.providers.cas.proxy.RejectProxyTickets"/&gt;
  3319. </programlisting></para>
  3320. <para>The beans are all reasonable self-explanatory if you refer back
  3321. to the "How CAS Works" section. Careful readers might notice one
  3322. surprise: the <literal>statelessTicketCache</literal> property of the
  3323. <literal>CasAuthenticationProvider</literal>. This is discussed in
  3324. detail in the "Advanced CAS Usage" section.</para>
  3325. <para>Note the <literal>CasProxyTicketValidator</literal> has a
  3326. remarked out <literal>trustStore</literal> property. This property
  3327. might be helpful if you experience HTTPS certificate issues. Also note
  3328. the <literal>proxyCallbackUrl</literal> is set so the service can
  3329. receive a proxy-granting ticket. As mentioned above, this is optional
  3330. and unnecessary if you do not require proxy-granting tickets. If you
  3331. do use this feature, you will need to configure a suitable servlet to
  3332. receive the proxy-granting tickets. We suggest you use CAS'
  3333. <literal>ProxyTicketReceptor</literal> by adding the following to your
  3334. web application's <literal>web.xml</literal>:</para>
  3335. <para><programlisting>
  3336. &lt;servlet&gt;
  3337. &lt;servlet-name&gt;casproxy&lt;/servlet-name&gt;
  3338. &lt;servlet-class&gt;edu.yale.its.tp.cas.proxy.ProxyTicketReceptor&lt;/servlet-class&gt;
  3339. &lt;/servlet&gt;
  3340. &lt;servlet-mapping&gt;
  3341. &lt;servlet-name&gt;casproxy&lt;/servlet-name&gt;
  3342. &lt;url-pattern&gt;/casProxy/*&lt;/url-pattern&gt;
  3343. &lt;/servlet-mapping&gt;
  3344. </programlisting></para>
  3345. <para>This completes the configuration of CAS. If you haven't made any
  3346. mistakes, your web application should happily work within the
  3347. framework of CAS single sign on. No other parts of Acegi Security need
  3348. to be concerned about the fact CAS handled authentication.</para>
  3349. <para>There is also a <literal>contacts-cas.war</literal> file in the
  3350. sample applications directory. This sample application uses the above
  3351. settings and can be deployed to see CAS in operation</para>
  3352. </sect1>
  3353. <sect1 id="cas-advanced">
  3354. <title>Advanced Issues</title>
  3355. <para>The <literal>CasAuthenticationProvider</literal> distinguishes
  3356. between stateful and stateless clients. A stateful client is
  3357. considered any that originates via the
  3358. <literal>CasProcessingFilter</literal>. A stateless client is any that
  3359. presents an authentication request via the
  3360. <literal>UsernamePasswordAuthenticationToken</literal> with a
  3361. principal equal to
  3362. <literal>CasProcessingFilter.CAS_STATELESS_IDENTIFIER</literal>.</para>
  3363. <para>Stateless clients are likely to be via remoting protocols such
  3364. as Hessian and Burlap. The <literal>BasicProcessingFilter</literal> is
  3365. still used in this case, but the remoting protocol client is expected
  3366. to present a username equal to the static string above, and a password
  3367. equal to a CAS service ticket. Clients should acquire a CAS service
  3368. ticket directly from the CAS server.</para>
  3369. <para>Because remoting protocols have no way of presenting themselves
  3370. within the context of a <literal>HttpSession</literal>, it isn't
  3371. possible to rely on the <literal>HttpSession</literal>'s
  3372. <literal>HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY</literal>
  3373. attribute to locate the <literal>CasAuthenticationToken</literal>.
  3374. Furthermore, because the CAS server invalidates a service ticket after
  3375. it has been validated by the <literal>TicketValidator</literal>,
  3376. presenting the same service ticket on subsequent requests will not
  3377. work. It is similarly very difficult to obtain a proxy-granting ticket
  3378. for a remoting protocol client, as they are often deployed on client
  3379. machines which rarely have HTTPS URLs that would be accessible to the
  3380. CAS server.</para>
  3381. <para>One obvious option is to not use CAS at all for remoting
  3382. protocol clients. However, this would eliminate many of the desirable
  3383. features of CAS.</para>
  3384. <para>As a middle-ground, the
  3385. <literal>CasAuthenticationProvider</literal> uses a
  3386. <literal>StatelessTicketCache</literal>. This is used solely for
  3387. requests with a principal equal to
  3388. <literal>CasProcessingFilter.CAS_STATELESS_IDENTIFIER</literal>. What
  3389. happens is the <literal>CasAuthenticationProvider</literal> will store
  3390. the resulting <literal>CasAuthenticationToken</literal> in the
  3391. <literal>StatelessTicketCache</literal>, keyed on the service ticket.
  3392. Accordingly, remoting protocol clients can present the same service
  3393. ticket and the <literal>CasAuthenticationProvider</literal> will not
  3394. need to contact the CAS server for validation (aside from the first
  3395. request).</para>
  3396. <para>The other aspect of advanced CAS usage involves creating proxy
  3397. tickets from the proxy-granting ticket. As indicated above, we
  3398. recommend you use CAS' <literal>ProxyTicketReceptor</literal> to
  3399. receive these tickets. The <literal>ProxyTicketReceptor</literal>
  3400. provides a static method that enables you to obtain a proxy ticket by
  3401. presenting the proxy-granting IOU ticket. You can obtain the
  3402. proxy-granting IOU ticket by calling
  3403. <literal>CasAuthenticationToken.getProxyGrantingTicketIou()</literal>.</para>
  3404. <para>It is hoped you find CAS integration easy and useful with Acegi
  3405. Security classes. Welcome to enterprise-wide single sign on!</para>
  3406. </sect1>
  3407. </chapter>
  3408. <chapter id="ca">
  3409. <title>Container Adapter Authentication</title>
  3410. <sect1 id="ca-overview">
  3411. <title>Overview</title>
  3412. <para>Very early versions of Acegi Security exclusively used Container
  3413. Adapters for interfacing authentication with end users. Whilst this
  3414. worked well, it required considerable time to support multiple
  3415. container versions and the configuration itself was relatively
  3416. time-consuming for developers. For this reason the HTTP Form
  3417. Authentication and HTTP Basic Authentication approaches were
  3418. developed, and are today recommended for almost all
  3419. applications.</para>
  3420. <para>Container Adapters enable Acegi Security to integrate directly
  3421. with the containers used to host end user applications. This
  3422. integration means that applications can continue to leverage the
  3423. authentication and authorization capabilities built into containers
  3424. (such as <literal>isUserInRole()</literal> and form-based or basic
  3425. authentication), whilst benefiting from the enhanced security
  3426. interception capabilities provided by Acegi Security (it should be
  3427. noted that Acegi Security also offers
  3428. <literal>ContextHolderAwareRequestWrapper</literal> to deliver
  3429. <literal>isUserInRole()</literal> and similar Servlet Specification
  3430. compatibility methods).</para>
  3431. <para>The integration between a container and Acegi Security is
  3432. achieved through an adapter. The adapter provides a
  3433. container-compatible user authentication provider, and needs to return
  3434. a container-compatible user object.</para>
  3435. <para>The adapter is instantiated by the container and is defined in a
  3436. container-specific configuration file. The adapter then loads a Spring
  3437. application context which defines the normal authentication manager
  3438. settings, such as the authentication providers that can be used to
  3439. authenticate the request. The application context is usually named
  3440. <literal>acegisecurity.xml</literal> and is placed in a
  3441. container-specific location.</para>
  3442. <para>Acegi Security currently supports Jetty, Catalina (Tomcat),
  3443. JBoss and Resin. Additional container adapters can easily be
  3444. written</para>
  3445. </sect1>
  3446. <sect1 id="ca-adapter">
  3447. <title>Adapter Authentication Provider</title>
  3448. <para>As is always the case, the container adapter generated
  3449. <literal>Authentication</literal> object still needs to be
  3450. authenticated by an <literal>AuthenticationManager</literal> when
  3451. requested to do so by the
  3452. <literal>AbstractSecurityInterceptor</literal>. The
  3453. <literal>AuthenticationManager</literal> needs to be certain the
  3454. adapter-provided <literal>Authentication</literal> object is valid and
  3455. was actually authenticated by a trusted adapter.</para>
  3456. <para>Adapters create <literal>Authentication</literal> objects which
  3457. are immutable and implement the <literal>AuthByAdapter</literal>
  3458. interface. These objects store the hash of a key that is defined by
  3459. the adapter. This allows the <literal>Authentication</literal> object
  3460. to be validated by the <literal>AuthByAdapterProvider</literal>. This
  3461. authentication provider is defined as follows:</para>
  3462. <para><programlisting>&lt;bean id="authByAdapterProvider" class="org.acegisecurity.adapters.AuthByAdapterProvider"&gt;
  3463. &lt;property name="key"&gt;&lt;value&gt;my_password&lt;/value&gt;&lt;/property&gt;
  3464. &lt;/bean&gt; </programlisting></para>
  3465. <para>The key must match the key that is defined in the
  3466. container-specific configuration file that starts the adapter. The
  3467. <literal>AuthByAdapterProvider</literal> automatically accepts as
  3468. valid any <literal>AuthByAdapter</literal> implementation that returns
  3469. the expected hash of the key.</para>
  3470. <para>To reiterate, this means the adapter will perform the initial
  3471. authentication using providers such as
  3472. <literal>DaoAuthenticationProvider</literal>, returning an
  3473. <literal>AuthByAdapter</literal> instance that contains a hash code of
  3474. the key. Later, when an application calls a security interceptor
  3475. managed resource, the <literal>AuthByAdapter</literal> instance in the
  3476. <literal>SecurityContext</literal> in the
  3477. <literal>SecurityContextHolder</literal> will be tested by the
  3478. application's <literal>AuthByAdapterProvider</literal>. There is no
  3479. requirement for additional authentication providers such as
  3480. <literal>DaoAuthenticationProvider</literal> within the
  3481. application-specific application context, as the only type of
  3482. <literal>Authentication</literal> instance that will be presented by
  3483. the application is from the container adapter.</para>
  3484. <para>Classloader issues are frequent with containers and the use of
  3485. container adapters illustrates this further. Each container requires a
  3486. very specific configuration. The installation instructions are
  3487. provided below. Once installed, please take the time to try the sample
  3488. application to ensure your container adapter is properly
  3489. configured.</para>
  3490. <para>When using container adapters with the
  3491. <literal>DaoAuthenticationProvider</literal>, ensure you set its
  3492. <literal>forcePrincipalAsString</literal> property to
  3493. <literal>true</literal>.</para>
  3494. </sect1>
  3495. <sect1 id="ca-jetty">
  3496. <title>Jetty</title>
  3497. <para>The following was tested with Jetty 4.2.18.</para>
  3498. <para><literal>$JETTY_HOME</literal> refers to the root of your Jetty
  3499. installation.</para>
  3500. <para>Edit your <literal>$JETTY_HOME/etc/jetty.xml</literal> file so
  3501. the <literal>&lt;Configure class&gt;</literal> section has a new
  3502. <literal>addRealm</literal> call:</para>
  3503. <para><programlisting>
  3504. &lt;Call name="addRealm"&gt;
  3505. &lt;Arg&gt;
  3506. &lt;New class="org.acegisecurity.adapters.jetty.JettyAcegiUserRealm"&gt;
  3507. &lt;Arg&gt;Spring Powered Realm&lt;/Arg&gt;
  3508. &lt;Arg&gt;my_password&lt;/Arg&gt;
  3509. &lt;Arg&gt;etc/acegisecurity.xml&lt;/Arg&gt;
  3510. &lt;/New&gt;
  3511. &lt;/Arg&gt;
  3512. &lt;/Call&gt;
  3513. </programlisting></para>
  3514. <para>Copy <literal>acegisecurity.xml</literal> into
  3515. <literal>$JETTY_HOME/etc</literal>.</para>
  3516. <para>Copy the following files into
  3517. <literal>$JETTY_HOME/ext</literal>:<itemizedlist>
  3518. <listitem>
  3519. <para><literal>aopalliance.jar</literal></para>
  3520. </listitem>
  3521. <listitem>
  3522. <para><literal>commons-logging.jar</literal></para>
  3523. </listitem>
  3524. <listitem>
  3525. <para><literal>spring.jar</literal></para>
  3526. </listitem>
  3527. <listitem>
  3528. <para><literal>acegi-security-jetty-XX.jar</literal></para>
  3529. </listitem>
  3530. <listitem>
  3531. <para><literal>commons-codec.jar</literal></para>
  3532. </listitem>
  3533. <listitem>
  3534. <para><literal>burlap.jar</literal></para>
  3535. </listitem>
  3536. <listitem>
  3537. <para><literal>hessian.jar</literal></para>
  3538. </listitem>
  3539. </itemizedlist></para>
  3540. <para>None of the above JAR files (or
  3541. <literal>acegi-security-XX.jar</literal>) should be in your
  3542. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  3543. in your <literal>web.xml</literal> does matter with Jetty. The
  3544. <literal>web.xml</literal> must express the same
  3545. <literal>&lt;realm-name&gt;</literal> as your
  3546. <literal>jetty.xml</literal> (in the example above, "Spring Powered
  3547. Realm").</para>
  3548. </sect1>
  3549. <sect1 id="ca-jboss">
  3550. <title>JBoss</title>
  3551. <para>The following was tested with JBoss 3.2.6.</para>
  3552. <para><literal>$JBOSS_HOME</literal> refers to the root of your JBoss
  3553. installation.</para>
  3554. <para>There are two different ways of making spring context available
  3555. to the Jboss integration classes.</para>
  3556. <para>The first approach is by editing your
  3557. <literal>$JBOSS_HOME/server/your_config/conf/login-config.xml</literal>
  3558. file so that it contains a new entry under the
  3559. <literal>&lt;Policy&gt;</literal> section:</para>
  3560. <para><programlisting>
  3561. &lt;application-policy name = "SpringPoweredRealm"&gt;
  3562. &lt;authentication&gt;
  3563. &lt;login-module code = "org.acegisecurity.adapters.jboss.JbossAcegiLoginModule"
  3564. flag = "required"&gt;
  3565. &lt;module-option name = "appContextLocation"&gt;acegisecurity.xml&lt;/module-option&gt;
  3566. &lt;module-option name = "key"&gt;my_password&lt;/module-option&gt;
  3567. &lt;/login-module&gt;
  3568. &lt;/authentication&gt;
  3569. &lt;/application-policy&gt;
  3570. </programlisting></para>
  3571. <para>Copy <literal>acegisecurity.xml</literal> into
  3572. <literal>$JBOSS_HOME/server/your_config/conf</literal>.</para>
  3573. <para>In this configuration <literal>acegisecurity.xml</literal>
  3574. contains the spring context definition including all the
  3575. authentication manager beans. You have to bear in mind though, that
  3576. <literal>SecurityContext</literal> is created and destroyed on each
  3577. login request, so the login operation might become costly.
  3578. Alternatively, the second approach is to use Spring singleton
  3579. capabilities through
  3580. <literal>org.springframework.beans.factory.access.SingletonBeanFactoryLocator</literal>.
  3581. The required configuration for this approach is:</para>
  3582. <para><programlisting>
  3583. &lt;application-policy name = "SpringPoweredRealm"&gt;
  3584. &lt;authentication&gt;
  3585. &lt;login-module code = "org.acegisecurity.adapters.jboss.JbossAcegiLoginModule"
  3586. flag = "required"&gt;
  3587. &lt;module-option name = "singletonId"&gt;springRealm&lt;/module-option&gt;
  3588. &lt;module-option name = "key"&gt;my_password&lt;/module-option&gt;
  3589. &lt;module-option name = "authenticationManager"&gt;authenticationManager&lt;/module-option&gt;
  3590. &lt;/login-module&gt;
  3591. &lt;/authentication&gt;
  3592. &lt;/application-policy&gt;
  3593. </programlisting></para>
  3594. <para>In the above code fragment,
  3595. <literal>authenticationManager</literal> is a helper property that
  3596. defines the expected name of the
  3597. <literal>AuthenticationManager</literal> in case you have several
  3598. defined in the IoC container. The <literal>singletonId</literal>
  3599. property references a bean defined in a
  3600. <literal>beanRefFactory.xml</literal> file. This file needs to be
  3601. available from anywhere on the JBoss classpath, including
  3602. <literal>$JBOSS_HOME/server/your_config/conf</literal>. The
  3603. <literal>beanRefFactory.xml</literal> contains the following
  3604. declaration:</para>
  3605. <para><programlisting>
  3606. &lt;beans&gt;
  3607. &lt;bean id="springRealm" singleton="true" lazy-init="true" class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
  3608. &lt;constructor-arg&gt;
  3609. &lt;list&gt;
  3610. &lt;value&gt;acegisecurity.xml&lt;/value&gt;
  3611. &lt;/list&gt;
  3612. &lt;/constructor-arg&gt;
  3613. &lt;/bean&gt;
  3614. &lt;/beans&gt;
  3615. </programlisting></para>
  3616. <para>Finally, irrespective of the configuration approach you need to
  3617. copy the following files into
  3618. <literal>$JBOSS_HOME/server/your_config/lib</literal>:<itemizedlist>
  3619. <listitem>
  3620. <para><literal>aopalliance.jar</literal></para>
  3621. </listitem>
  3622. <listitem>
  3623. <para><literal>spring.jar</literal></para>
  3624. </listitem>
  3625. <listitem>
  3626. <para><literal>acegi-security-jboss-XX.jar</literal></para>
  3627. </listitem>
  3628. <listitem>
  3629. <para><literal>commons-codec.jar</literal></para>
  3630. </listitem>
  3631. <listitem>
  3632. <para><literal>burlap.jar</literal></para>
  3633. </listitem>
  3634. <listitem>
  3635. <para><literal>hessian.jar</literal></para>
  3636. </listitem>
  3637. </itemizedlist></para>
  3638. <para>None of the above JAR files (or
  3639. <literal>acegi-security-XX.jar</literal>) should be in your
  3640. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  3641. in your <literal>web.xml</literal> does not matter with JBoss.
  3642. However, your web application's
  3643. <literal>WEB-INF/jboss-web.xml</literal> must express the same
  3644. <literal>&lt;security-domain&gt;</literal> as your
  3645. <literal>login-config.xml</literal>. For example, to match the above
  3646. example, your <literal>jboss-web.xml</literal> would look like
  3647. this:</para>
  3648. <para><programlisting>
  3649. &lt;jboss-web&gt;
  3650. &lt;security-domain&gt;java:/jaas/SpringPoweredRealm&lt;/security-domain&gt;
  3651. &lt;/jboss-web&gt;</programlisting></para>
  3652. <para>JBoss is a widely-used container adapter (mostly due to the need
  3653. to support legacy EJBs), so please let us know if you have any
  3654. difficulties.</para>
  3655. </sect1>
  3656. <sect1 id="ca-resin">
  3657. <title>Resin</title>
  3658. <para>The following was tested with Resin 3.0.6.</para>
  3659. <para><literal>$RESIN_HOME</literal> refers to the root of your Resin
  3660. installation.</para>
  3661. <para>Resin provides several ways to support the container adapter. In
  3662. the instructions below we have elected to maximise consistency with
  3663. other container adapter configurations. This will allow Resin users to
  3664. simply deploy the sample application and confirm correct
  3665. configuration. Developers comfortable with Resin are naturally able to
  3666. use its capabilities to package the JARs with the web application
  3667. itself, and/or support single sign-on.</para>
  3668. <para>Copy the following files into
  3669. <literal>$RESIN_HOME/lib</literal>:<itemizedlist>
  3670. <listitem>
  3671. <para><literal>aopalliance.jar</literal></para>
  3672. </listitem>
  3673. <listitem>
  3674. <para><literal>commons-logging.jar</literal></para>
  3675. </listitem>
  3676. <listitem>
  3677. <para><literal>spring.jar</literal></para>
  3678. </listitem>
  3679. <listitem>
  3680. <para><literal>acegi-security-resin-XX.jar</literal></para>
  3681. </listitem>
  3682. <listitem>
  3683. <para><literal>commons-codec.jar</literal></para>
  3684. </listitem>
  3685. <listitem>
  3686. <para><literal>burlap.jar</literal></para>
  3687. </listitem>
  3688. <listitem>
  3689. <para><literal>hessian.jar</literal></para>
  3690. </listitem>
  3691. </itemizedlist></para>
  3692. <para>Unlike the container-wide <literal>acegisecurity.xml</literal>
  3693. files used by other container adapters, each Resin web application
  3694. will contain its own
  3695. <literal>WEB-INF/resin-acegisecurity.xml</literal> file. Each web
  3696. application will also contain a <literal>resin-web.xml</literal> file
  3697. which Resin uses to start the container adapter:</para>
  3698. <para><programlisting>
  3699. &lt;web-app&gt;
  3700. &lt;authenticator&gt;
  3701. &lt;type&gt;org.acegisecurity.adapters.resin.ResinAcegiAuthenticator&lt;/type&gt;
  3702. &lt;init&gt;
  3703. &lt;app-context-location&gt;WEB-INF/resin-acegisecurity.xml&lt;/app-context-location&gt;
  3704. &lt;key&gt;my_password&lt;/key&gt;
  3705. &lt;/init&gt;
  3706. &lt;/authenticator&gt;
  3707. &lt;/web-app&gt;
  3708. </programlisting></para>
  3709. <para>With the basic configuration provided above, none of the JAR
  3710. files listed (or <literal>acegi-security-XX.jar</literal>) should be
  3711. in your application's <literal>WEB-INF/lib</literal>. The realm name
  3712. indicated in your <literal>web.xml</literal> does not matter with
  3713. Resin, as the relevant authentication class is indicated by the
  3714. <literal>&lt;authenticator&gt;</literal> setting</para>
  3715. </sect1>
  3716. <sect1 id="ca-tomcat">
  3717. <title>Tomcat</title>
  3718. <para>The following was tested with Jakarta Tomcat 4.1.30 and
  3719. 5.0.19.</para>
  3720. <para><literal>$CATALINA_HOME</literal> refers to the root of your
  3721. Catalina (Tomcat) installation.</para>
  3722. <para>Edit your <literal>$CATALINA_HOME/conf/server.xml</literal> file
  3723. so the <literal>&lt;Engine&gt;</literal> section contains only one
  3724. active <literal>&lt;Realm&gt;</literal> entry. An example realm
  3725. entry:</para>
  3726. <para><programlisting> &lt;Realm className="org.acegisecurity.adapters.catalina.CatalinaAcegiUserRealm"
  3727. appContextLocation="conf/acegisecurity.xml"
  3728. key="my_password" /&gt;</programlisting></para>
  3729. <para>Be sure to remove any other <literal>&lt;Realm&gt;</literal>
  3730. entry from your <literal>&lt;Engine&gt;</literal> section.</para>
  3731. <para>Copy <literal>acegisecurity.xml</literal> into
  3732. <literal>$CATALINA_HOME/conf</literal>.</para>
  3733. <para>Copy <literal>acegi-security-catalina-XX.jar</literal> into
  3734. <literal>$CATALINA_HOME/server/lib</literal>.</para>
  3735. <para>Copy the following files into
  3736. <literal>$CATALINA_HOME/common/lib</literal>:</para>
  3737. <itemizedlist>
  3738. <listitem>
  3739. <para><literal>aopalliance.jar</literal></para>
  3740. </listitem>
  3741. <listitem>
  3742. <para><literal>spring.jar</literal></para>
  3743. </listitem>
  3744. <listitem>
  3745. <para><literal>commons-codec.jar</literal></para>
  3746. </listitem>
  3747. <listitem>
  3748. <para><literal>burlap.jar</literal></para>
  3749. </listitem>
  3750. <listitem>
  3751. <para><literal>hessian.jar</literal></para>
  3752. </listitem>
  3753. </itemizedlist>
  3754. <para>None of the above JAR files (or
  3755. <literal>acegi-security-XX.jar</literal>) should be in your
  3756. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  3757. in your <literal>web.xml</literal> does not matter with
  3758. Catalina.</para>
  3759. <para>We have received reports of problems using this Container
  3760. Adapter with Mac OS X. A work-around is to use a script such as
  3761. follows:</para>
  3762. <para><programlisting>#!/bin/sh
  3763. export CATALINA_HOME="/Library/Tomcat"
  3764. export JAVA_HOME="/Library/Java/Home"
  3765. cd /
  3766. $CATALINA_HOME/bin/startup.sh</programlisting></para>
  3767. <para>Finally, restart Tomcat.</para>
  3768. </sect1>
  3769. </chapter>
  3770. </part>
  3771. <part id="authorization">
  3772. <title>Authorization</title>
  3773. <partintro>
  3774. <para>The advanced authorization capabilities within Acegi Security
  3775. represent one of the most compelling reasons for its popularity.
  3776. Irrespective of how you choose to authenticate - whether using an Acegi
  3777. Security-provided mechanism and provider, or integrating with a
  3778. container or other non-Acegi Security authentication authority - you
  3779. will find the authorization services can be used within your application
  3780. in a consistent and simple way.</para>
  3781. <para>In this part we'll explore the different
  3782. <literal>AbstractSecurityInterceptor</literal> implementations, which
  3783. were introduced in Part I. We then move on to explore how to fine-tune
  3784. authorization through use of domain access control lists.</para>
  3785. </partintro>
  3786. <chapter id="authorization-common">
  3787. <title>Common Authorization Concepts</title>
  3788. <sect1 id="authorities">
  3789. <title>Authorities</title>
  3790. <para>As briefly mentioned in the Authentication section, all
  3791. <literal>Authentication</literal> implementations are required to
  3792. store an array of <literal>GrantedAuthority</literal> objects. These
  3793. represent the authorities that have been granted to the principal. The
  3794. <literal>GrantedAuthority</literal> objects are inserted into the
  3795. <literal>Authentication</literal> object by the
  3796. <literal>AuthenticationManager</literal> and are later read by
  3797. <literal>AccessDecisionManager</literal>s when making authorization
  3798. decisions.</para>
  3799. <para><literal>GrantedAuthority</literal> is an interface with only
  3800. one method:</para>
  3801. <para><programlisting>public String getAuthority();</programlisting></para>
  3802. <para>This method allows <literal>AccessDecisionManager</literal>s to
  3803. obtain a precise <literal>String</literal> representation of the
  3804. <literal>GrantedAuthority</literal>. By returning a representation as
  3805. a <literal>String</literal>, a <literal>GrantedAuthority</literal> can
  3806. be easily "read" by most <literal>AccessDecisionManager</literal>s. If
  3807. a <literal>GrantedAuthority</literal> cannot be precisely represented
  3808. as a <literal>String</literal>, the
  3809. <literal>GrantedAuthority</literal> is considered "complex" and
  3810. <literal>getAuthority()</literal> must return
  3811. <literal>null</literal>.</para>
  3812. <para>An example of a "complex" <literal>GrantedAuthority</literal>
  3813. would be an implementation that stores a list of operations and
  3814. authority thresholds that apply to different customer account numbers.
  3815. Representing this complex <literal>GrantedAuthority</literal> as a
  3816. <literal>String</literal> would be quite complex, and as a result the
  3817. <literal>getAuthority()</literal> method should return
  3818. <literal>null</literal>. This will indicate to any
  3819. <literal>AccessDecisionManager</literal> that it will need to
  3820. specifically support the <literal>GrantedAuthority</literal>
  3821. implementation in order to understand its contents.</para>
  3822. <para>Acegi Security includes one concrete
  3823. <literal>GrantedAuthority</literal> implementation,
  3824. <literal>GrantedAuthorityImpl</literal>. This allows any
  3825. user-specified <literal>String</literal> to be converted into a
  3826. <literal>GrantedAuthority</literal>. All
  3827. <literal>AuthenticationProvider</literal>s included with the security
  3828. architecture use <literal>GrantedAuthorityImpl</literal> to populate
  3829. the <literal>Authentication</literal> object.</para>
  3830. </sect1>
  3831. <sect1 id="pre-invocation">
  3832. <title>Pre-Invocation Handling</title>
  3833. <para>The <literal>AccessDecisionManager</literal> is called by the
  3834. <literal>AbstractSecurityInterceptor</literal> and is responsible for
  3835. making final access control decisions. The
  3836. <literal>AccessDecisionManager</literal> interface contains three
  3837. methods:</para>
  3838. <para><programlisting>public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config) throws AccessDeniedException;
  3839. public boolean supports(ConfigAttribute attribute);
  3840. public boolean supports(Class clazz);</programlisting></para>
  3841. <para>As can be seen from the first method, the
  3842. <literal>AccessDecisionManager</literal> is passed via method
  3843. parameters all information that is likely to be of value in assessing
  3844. an authorization decision. In particular, passing the secure
  3845. <literal>Object</literal> enables those arguments contained in the
  3846. actual secure object invocation to be inspected. For example, let's
  3847. assume the secure object was a <literal>MethodInvocation</literal>. It
  3848. would be easy to query the <literal>MethodInvocation</literal> for any
  3849. <literal>Customer</literal> argument, and then implement some sort of
  3850. security logic in the <literal>AccessDecisionManager</literal> to
  3851. ensure the principal is permitted to operate on that customer.
  3852. Implementations are expected to throw an
  3853. <literal>AccessDeniedException</literal> if access is denied.</para>
  3854. <para>The <literal>supports(ConfigAttribute)</literal> method is
  3855. called by the <literal>AbstractSecurityInterceptor</literal> at
  3856. startup time to determine if the
  3857. <literal>AccessDecisionManager</literal> can process the passed
  3858. <literal>ConfigAttribute</literal>. The
  3859. <literal>supports(Class)</literal> method is called by a security
  3860. interceptor implementation to ensure the configured
  3861. <literal>AccessDecisionManager</literal> supports the type of secure
  3862. object that the security interceptor will present.</para>
  3863. <para>Whilst users can implement their own
  3864. <literal>AccessDecisionManager</literal> to control all aspects of
  3865. authorization, Acegi Security includes several
  3866. <literal>AccessDecisionManager</literal> implementations that are
  3867. based on voting. Figure 4 illustrates the relevant classes.</para>
  3868. <para><mediaobject>
  3869. <imageobject role="html">
  3870. <imagedata align="center"
  3871. fileref="images/AccessDecisionVoting.gif"
  3872. format="GIF" />
  3873. </imageobject>
  3874. <caption>
  3875. <para>Figure 4: Voting Decision Manager</para>
  3876. </caption>
  3877. </mediaobject></para>
  3878. <para>Using this approach, a series of
  3879. <literal>AccessDecisionVoter</literal> implementations are polled on
  3880. an authorization decision. The
  3881. <literal>AccessDecisionManager</literal> then decides whether or not
  3882. to throw an <literal>AccessDeniedException</literal> based on its
  3883. assessment of the votes.</para>
  3884. <para>The <literal>AccessDecisionVoter</literal> interface has three
  3885. methods:</para>
  3886. <para><programlisting>public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config);
  3887. public boolean supports(ConfigAttribute attribute);
  3888. public boolean supports(Class clazz);</programlisting></para>
  3889. <para>Concrete implementations return an <literal>int</literal>, with
  3890. possible values being reflected in the
  3891. <literal>AccessDecisionVoter</literal> static fields
  3892. <literal>ACCESS_ABSTAIN</literal>, <literal>ACCESS_DENIED</literal>
  3893. and <literal>ACCESS_GRANTED</literal>. A voting implementation will
  3894. return <literal>ACCESS_ABSTAIN</literal> if it has no opinion on an
  3895. authorization decision. If it does have an opinion, it must return
  3896. either <literal>ACCESS_DENIED</literal> or
  3897. <literal>ACCESS_GRANTED</literal>.</para>
  3898. <para>There are three concrete
  3899. <literal>AccessDecisionManager</literal>s provided with Acegi Security
  3900. that tally the votes. The <literal>ConsensusBased</literal>
  3901. implementation will grant or deny access based on the consensus of
  3902. non-abstain votes. Properties are provided to control behavior in the
  3903. event of an equality of votes or if all votes are abstain. The
  3904. <literal>AffirmativeBased</literal> implementation will grant access
  3905. if one or more <literal>ACCESS_GRANTED</literal> votes were received
  3906. (ie a deny vote will be ignored, provided there was at least one grant
  3907. vote). Like the <literal>ConsensusBased</literal> implementation,
  3908. there is a parameter that controls the behavior if all voters abstain.
  3909. The <literal>UnanimousBased</literal> provider expects unanimous
  3910. <literal>ACCESS_GRANTED</literal> votes in order to grant access,
  3911. ignoring abstains. It will deny access if there is any
  3912. <literal>ACCESS_DENIED</literal> vote. Like the other implementations,
  3913. there is a parameter that controls the behaviour if all voters
  3914. abstain.</para>
  3915. <para>It is possible to implement a custom
  3916. <literal>AccessDecisionManager</literal> that tallies votes
  3917. differently. For example, votes from a particular
  3918. <literal>AccessDecisionVoter</literal> might receive additional
  3919. weighting, whilst a deny vote from a particular voter may have a veto
  3920. effect.</para>
  3921. <para>There are two concrete <literal>AccessDecisionVoter</literal>
  3922. implementations provided with Acegi Security. The
  3923. <literal>RoleVoter</literal> class will vote if any ConfigAttribute
  3924. begins with <literal>ROLE_</literal>. It will vote to grant access if
  3925. there is a <literal>GrantedAuthority</literal> which returns a
  3926. <literal>String</literal> representation (via the
  3927. <literal>getAuthority()</literal> method) exactly equal to one or more
  3928. <literal>ConfigAttributes</literal> starting with
  3929. <literal>ROLE_</literal>. If there is no exact match of any
  3930. <literal>ConfigAttribute</literal> starting with
  3931. <literal>ROLE_</literal>, the <literal>RoleVoter</literal> will vote
  3932. to deny access. If no <literal>ConfigAttribute</literal> begins with
  3933. <literal>ROLE_</literal>, the voter will abstain.
  3934. <literal>RoleVoter</literal> is case sensitive on comparisons as well
  3935. as the <literal>ROLE_</literal> prefix.</para>
  3936. <para><literal>BasicAclEntryVoter</literal> is the other concrete
  3937. voter included with Acegi Security. It integrates with Acegi
  3938. Security's <literal>AclManager</literal> (discussed later). This voter
  3939. is designed to have multiple instances in the same application
  3940. context, such as:</para>
  3941. <para><programlisting>&lt;bean id="aclContactReadVoter" class="org.acegisecurity.vote.BasicAclEntryVoter"&gt;
  3942. &lt;property name="processConfigAttribute"&gt;&lt;value&gt;ACL_CONTACT_READ&lt;/value&gt;&lt;/property&gt;
  3943. &lt;property name="processDomainObjectClass"&gt;&lt;value&gt;sample.contact.Contact&lt;/value&gt;&lt;/property&gt;
  3944. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  3945. &lt;property name="requirePermission"&gt;
  3946. &lt;list&gt;
  3947. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  3948. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  3949. &lt;/list&gt;
  3950. &lt;/property&gt;
  3951. &lt;/bean&gt;
  3952. &lt;bean id="aclContactDeleteVoter" class="org.acegisecurity.vote.BasicAclEntryVoter"&gt;
  3953. &lt;property name="processConfigAttribute"&gt;&lt;value&gt;ACL_CONTACT_DELETE&lt;/value&gt;&lt;/property&gt;
  3954. &lt;property name="processDomainObjectClass"&gt;&lt;value&gt;sample.contact.Contact&lt;/value&gt;&lt;/property&gt;
  3955. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  3956. &lt;property name="requirePermission"&gt;
  3957. &lt;list&gt;
  3958. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  3959. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.DELETE"/&gt;
  3960. &lt;/list&gt;
  3961. &lt;/property&gt;
  3962. &lt;/bean&gt; </programlisting></para>
  3963. <para>In the above example, you'd define
  3964. <literal>ACL_CONTACT_READ</literal> or
  3965. <literal>ACL_CONTACT_DELETE</literal> against some methods on a
  3966. <literal>MethodSecurityInterceptor</literal> or
  3967. <literal>AspectJSecurityInterceptor</literal>. When those methods are
  3968. invoked, the above applicable voter defined above would vote to grant
  3969. or deny access. The voter would look at the method invocation to
  3970. locate the first argument of type
  3971. <literal>sample.contact.Contact</literal>, and then pass that
  3972. <literal>Contact</literal> to the <literal>AclManager</literal>. The
  3973. <literal>AclManager</literal> will then return an access control list
  3974. (ACL) that applies to the current <literal>Authentication</literal>.
  3975. Assuming that ACL contains one of the listed
  3976. <literal>requirePermission</literal>s, the voter will vote to grant
  3977. access. If the ACL does not contain one of the permissions defined
  3978. against the voter, the voter will vote to deny access.
  3979. <literal>BasicAclEntryVoter</literal> is an important class as it
  3980. allows you to build truly complex applications with domain object
  3981. security entirely defined in the application context. If you're
  3982. interested in learning more about Acegi Security's ACL capabilities
  3983. and how best to apply them, please see the ACL and "After Invocation"
  3984. sections of this reference guide, and the Contacts sample
  3985. application.</para>
  3986. <para>It is also possible to implement a custom
  3987. <literal>AccessDecisionVoter</literal>. Several examples are provided
  3988. in Acegi Security unit tests, including
  3989. <literal>ContactSecurityVoter</literal> and
  3990. <literal>DenyVoter</literal>. The
  3991. <literal>ContactSecurityVoter</literal> abstains from voting decisions
  3992. where a <literal>CONTACT_OWNED_BY_CURRENT_USER</literal>
  3993. <literal>ConfigAttribute</literal> is not found. If voting, it queries
  3994. the <literal>MethodInvocation</literal> to extract the owner of the
  3995. <literal>Contact</literal> object that is subject of the method call.
  3996. It votes to grant access if the <literal>Contact</literal> owner
  3997. matches the principal presented in the
  3998. <literal>Authentication</literal> object. It could have just as easily
  3999. compared the <literal>Contact</literal> owner with some
  4000. <literal>GrantedAuthority</literal> the
  4001. <literal>Authentication</literal> object presented. All of this is
  4002. achieved with relatively few lines of code and demonstrates the
  4003. flexibility of the authorization model.</para>
  4004. <para>TODO: Remove references to the old ACL package when it's
  4005. deprecated, and have all references to the replacement package limited
  4006. to the chapter describing the new ACL implementation.</para>
  4007. </sect1>
  4008. <sect1 id="after-invocation">
  4009. <title>After Invocation Handling</title>
  4010. <para>Whilst the <literal>AccessDecisionManager</literal> is called by
  4011. the <literal>AbstractSecurityInterceptor</literal> before proceeding
  4012. with the secure object invocation, some applications need a way of
  4013. modifying the object actually returned by the secure object
  4014. invocation. Whilst you could easily implement your own AOP concern to
  4015. achieve this, Acegi Security provides a convenient hook that has
  4016. several concrete implementations that integrate with its ACL
  4017. capabilities.</para>
  4018. <para>Figure 5 illustrates Acegi Security's
  4019. <literal>AfterInvocationManager</literal> and its concrete
  4020. implementations.</para>
  4021. <para><mediaobject>
  4022. <imageobject role="html">
  4023. <imagedata align="center" fileref="images/AfterInvocation.gif"
  4024. format="GIF" />
  4025. </imageobject>
  4026. <caption>
  4027. <para>Figure 5: After Invocation Implementation</para>
  4028. </caption>
  4029. </mediaobject></para>
  4030. <para>Like many other parts of Acegi Security,
  4031. <literal>AfterInvocationManager</literal> has a single concrete
  4032. implementation, <literal>AfterInvocationProvider</literal>, which
  4033. polls a list of <literal>AfterInvocationProvider</literal>s. Each
  4034. <literal>AfterInvocationProvider</literal> is allowed to modify the
  4035. return object or throw an <literal>AccessDeniedException</literal>.
  4036. Indeed multiple providers can modify the object, as the result of the
  4037. previous provider is passed to the next in the list. Let's now
  4038. consider our ACL-aware implementations of
  4039. <literal>AfterInvocationProvider</literal>.</para>
  4040. <para>Please be aware that if you're using
  4041. <literal>AfterInvocationManager</literal>, you will still need
  4042. configuration attributes that allow the
  4043. <literal>MethodSecurityInterceptor</literal>'s
  4044. <literal>AccessDecisionManager</literal> to allow an operation. If
  4045. you're using the typical Acegi Security included
  4046. <literal>AccessDecisionManager</literal> implementations, having no
  4047. configuration attributes defined for a particular secure method
  4048. invocation will cause each <literal>AccessDecisionVoter</literal> to
  4049. abstain from voting. In turn, if the
  4050. <literal>AccessDecisionManager</literal> property
  4051. "<literal>allowIfAllAbstainDecisions</literal>" is
  4052. <literal>false</literal>, an <literal>AccessDeniedException</literal>
  4053. will be thrown. You may avoid this potential issue by either (i)
  4054. setting "<literal>allowIfAllAbstainDecisions</literal>" to
  4055. <literal>true</literal> (although this is generally not recommended)
  4056. or (ii) simply ensure that there is at least one configuration
  4057. attribute that an <literal>AccessDecisionVoter</literal> will vote to
  4058. grant access for. This latter (recommended) approach is usually
  4059. achieved through a <literal>ROLE_USER</literal> or
  4060. <literal>ROLE_AUTHENTICATED</literal> configuration attribute</para>
  4061. <sect2 id="after-invocation-acl-aware">
  4062. <title>ACL-Aware AfterInvocationProviders</title>
  4063. <para>TODO: This section will be removed when we deprecate the
  4064. existing ACL package. It should be discussed with the context of the
  4065. ACL implementation chapter instead.</para>
  4066. <para>A common services layer method we've all written at one stage
  4067. or another looks like this:</para>
  4068. <para><programlisting>public Contact getById(Integer id);</programlisting></para>
  4069. <para>Quite often, only principals with permission to read the
  4070. <literal>Contact</literal> should be allowed to obtain it. In this
  4071. situation the <literal>AccessDecisionManager</literal> approach
  4072. provided by the <literal>AbstractSecurityInterceptor</literal> will
  4073. not suffice. This is because the identity of the
  4074. <literal>Contact</literal> is all that is available before the
  4075. secure object is invoked. The
  4076. <literal>BasicAclAfterInvocationProvider</literal> delivers a
  4077. solution, and is configured as follows:</para>
  4078. <para><programlisting>&lt;bean id="afterAclRead" class="org.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationProvider"&gt;
  4079. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  4080. &lt;property name="requirePermission"&gt;
  4081. &lt;list&gt;
  4082. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  4083. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  4084. &lt;/list&gt;
  4085. &lt;/property&gt;
  4086. &lt;/bean&gt; </programlisting></para>
  4087. <para>In the above example, the <literal>Contact</literal> will be
  4088. retrieved and passed to the
  4089. <literal>BasicAclEntryAfterInvocationProvider</literal>. The
  4090. provider will thrown an <literal>AccessDeniedException</literal> if
  4091. one of the listed <literal>requirePermission</literal>s is not held
  4092. by the <literal>Authentication</literal>. The
  4093. <literal>BasicAclEntryAfterInvocationProvider</literal> queries the
  4094. <literal>AclManager</literal> to determine the ACL that applies for
  4095. this domain object to this <literal>Authentication</literal>.</para>
  4096. <para>Similar to the
  4097. <literal>BasicAclEntryAfterInvocationProvider</literal> is
  4098. <literal>BasicAclEntryAfterInvocationCollectionFilteringProvider</literal>.
  4099. It is designed to remove <literal>Collection</literal> or array
  4100. elements for which a principal does not have access. It never thrown
  4101. an <literal>AccessDeniedException</literal> - simply silently
  4102. removes the offending elements. The provider is configured as
  4103. follows:</para>
  4104. <para><programlisting>&lt;bean id="afterAclCollectionRead" class="org.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationCollectionFilteringProvider"&gt;
  4105. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  4106. &lt;property name="requirePermission"&gt;
  4107. &lt;list&gt;
  4108. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  4109. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  4110. &lt;/list&gt;
  4111. &lt;/property&gt;
  4112. &lt;/bean&gt; </programlisting></para>
  4113. <para>As you can imagine, the returned <literal>Object</literal>
  4114. must be a <literal>Collection</literal> or array for this provider
  4115. to operate. It will remove any element if the
  4116. <literal>AclManager</literal> indicates the
  4117. <literal>Authentication</literal> does not hold one of the listed
  4118. <literal>requirePermission</literal>s.</para>
  4119. <para>The Contacts sample application demonstrates these two
  4120. <literal>AfterInvocationProvider</literal>s.</para>
  4121. </sect2>
  4122. </sect1>
  4123. <sect1 id="authorization-taglibs">
  4124. <title>Authorization Tag Libraries</title>
  4125. <para><literal>AuthorizeTag</literal> is used to include content if
  4126. the current principal holds certain
  4127. <literal>GrantedAuthority</literal>s.</para>
  4128. <para>The following JSP fragment illustrates how to use the
  4129. <literal>AuthorizeTag</literal>:</para>
  4130. <para><programlisting>&lt;authz:authorize ifAllGranted="ROLE_SUPERVISOR"&gt;
  4131. &lt;td&gt;
  4132. &lt;A HREF="del.htm?id=&lt;c:out value="${contact.id}"/&gt;"&gt;Del&lt;/A&gt;
  4133. &lt;/td&gt;
  4134. &lt;/authz:authorize&gt; </programlisting></para>
  4135. <para>This tag would cause the tag's body to be output if the
  4136. principal has been granted ROLE_SUPERVISOR.</para>
  4137. <para>The <literal>authz:authorize</literal> tag declares the
  4138. following attributes:</para>
  4139. <para><itemizedlist spacing="compact">
  4140. <listitem>
  4141. <para><literal>ifAllGranted</literal>: All the listed roles must
  4142. be granted for the tag to output its body.</para>
  4143. </listitem>
  4144. <listitem>
  4145. <para><literal>ifAnyGranted</literal>: Any of the listed roles
  4146. must be granted for the tag to output its body.</para>
  4147. </listitem>
  4148. <listitem>
  4149. <para><literal>ifNotGranted</literal>: None of the listed roles
  4150. must be granted for the tag to output its body.</para>
  4151. </listitem>
  4152. </itemizedlist></para>
  4153. <para>You'll note that in each attribute you can list multiple roles.
  4154. Simply separate the roles using a comma. The
  4155. <literal>authorize</literal> tag ignores whitespace in
  4156. attributes.</para>
  4157. <para>The tag library logically ANDs all of it's parameters together.
  4158. This means that if you combine two or more attributes, all attributes
  4159. must be true for the tag to output it's body. Don't add an
  4160. <literal>ifAllGranted="ROLE_SUPERVISOR"</literal>, followed by an
  4161. <literal>ifNotGranted="ROLE_SUPERVISOR"</literal>, or you'll be
  4162. surprised to never see the tag's body.</para>
  4163. <para>By requiring all attributes to return true, the authorize tag
  4164. allows you to create more complex authorization scenarios. For
  4165. example, you could declare an
  4166. <literal>ifAllGranted="ROLE_SUPERVISOR"</literal> and an
  4167. <literal>ifNotGranted="ROLE_NEWBIE_SUPERVISOR"</literal> in the same
  4168. tag, in order to prevent new supervisors from seeing the tag body.
  4169. However it would no doubt be simpler to use
  4170. <literal>ifAllGranted="ROLE_EXPERIENCED_SUPERVISOR"</literal> rather
  4171. than inserting NOT conditions into your design.</para>
  4172. <para>One last item: the tag verifies the authorizations in a specific
  4173. order: first <literal>ifNotGranted</literal>, then
  4174. <literal>ifAllGranted</literal>, and finally, <literal>if
  4175. AnyGranted</literal>.</para>
  4176. <para><literal>AclTag</literal> is used to include content if the
  4177. current principal has a ACL to the indicated domain object.</para>
  4178. <para>The following JSP fragment illustrates how to use the
  4179. <literal>AclTag</literal>:</para>
  4180. <para><programlisting>
  4181. &lt;authz:acl domainObject="${contact}" hasPermission="16,1"&gt;
  4182. &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;
  4183. &lt;/authz:acl&gt;
  4184. </programlisting></para>
  4185. <para>This tag would cause the tag's body to be output if the
  4186. principal holds either permission 16 or permission 1 for the "contact"
  4187. domain object. The numbers are actually integers that are used with
  4188. <literal>AbstractBasicAclEntry</literal> bit masking. Please refer to
  4189. the ACL section of this reference guide to understand more about the
  4190. ACL capabilities of Acegi Security</para>
  4191. </sect1>
  4192. </chapter>
  4193. <chapter id="secure-object-impls">
  4194. <title>Secure Object Implementations</title>
  4195. <sect1 id="aop-alliance">
  4196. <title>AOP Alliance (MethodInvocation) Security Interceptor</title>
  4197. <para>To secure <literal>MethodInvocation</literal>s, developers
  4198. simply add a properly configured
  4199. <literal>MethodSecurityInterceptor</literal> into the application
  4200. context. Next the beans requiring security are chained into the
  4201. interceptor. This chaining is accomplished using Spring’s
  4202. <literal>ProxyFactoryBean</literal> or
  4203. <literal>BeanNameAutoProxyCreator</literal>, as commonly used by many
  4204. other parts of Spring (refer to the sample application for examples).
  4205. Alternatively, Acegi Security provides a
  4206. <literal>MethodDefinitionSourceAdvisor</literal> which may be used
  4207. with Spring's <literal>DefaultAdvisorAutoProxyCreator</literal> to
  4208. automatically chain the security interceptor in front of any beans
  4209. defined against the <literal>MethodSecurityInterceptor</literal>. The
  4210. <literal>MethodSecurityInterceptor</literal> itself is configured as
  4211. follows:</para>
  4212. <programlisting>&lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  4213. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
  4214. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4215. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4216. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4217. &lt;property name="afterInvocationManager"&gt;&lt;ref bean="afterInvocationManager"/&gt;&lt;/property&gt;
  4218. &lt;property name="objectDefinitionSource"&gt;
  4219. &lt;value&gt;
  4220. org.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER
  4221. org.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER
  4222. &lt;/value&gt;
  4223. &lt;/property&gt;
  4224. &lt;/bean&gt; </programlisting>
  4225. <para>As shown above, the <literal>MethodSecurityInterceptor</literal>
  4226. is configured with a reference to an
  4227. <literal>AuthenticationManager</literal>,
  4228. <literal>AccessDecisionManager</literal> and
  4229. <literal>RunAsManager</literal>, which are each discussed in separate
  4230. sections below. In this case we've also defined an
  4231. <literal>AfterInvocationManager</literal>, although this is entirely
  4232. optional. The <literal>MethodSecurityInterceptor</literal> is also
  4233. configured with configuration attributes that apply to different
  4234. method signatures. A full discussion of configuration attributes is
  4235. provided in the High Level Design section of this document.</para>
  4236. <para>The <literal>MethodSecurityInterceptor</literal> can be
  4237. configured with configuration attributes in three ways. The first is
  4238. via a property editor and the application context, which is shown
  4239. above. The second is via defining the configuration attributes in your
  4240. source code using Jakarta Commons Attributes or Java 5 Annotations.
  4241. The third is via writing your own
  4242. <literal>ObjectDefinitionSource</literal>, although this is beyond the
  4243. scope of this document. Irrespective of the approach used, the
  4244. <literal>ObjectDefinitionSource</literal> is responsible for returning
  4245. a <literal>ConfigAttributeDefinition</literal> object that contains
  4246. all of the configuration attributes associated with a single secure
  4247. method.</para>
  4248. <para>It should be noted that the
  4249. <literal>MethodSecurityInterceptor.setObjectDefinitionSource()</literal>
  4250. method actually expects an instance of
  4251. <literal>MethodDefinitionSource</literal>. This is a marker interface
  4252. which subclasses <literal>ObjectDefinitionSource</literal>. It simply
  4253. denotes the <literal>ObjectDefinitionSource</literal> understands
  4254. <literal>MethodInvocation</literal>s. In the interests of simplicity
  4255. we'll continue to refer to the
  4256. <literal>MethodDefinitionSource</literal> as an
  4257. <literal>ObjectDefinitionSource</literal>, as the distinction is of
  4258. little relevance to most users of the
  4259. <literal>MethodSecurityInterceptor</literal>.</para>
  4260. <para>If using the application context property editor approach (as
  4261. shown above), commas are used to delimit the different configuration
  4262. attributes that apply to a given method pattern. Each configuration
  4263. attribute is assigned into its own <literal>SecurityConfig</literal>
  4264. object. The <literal>SecurityConfig</literal> object is discussed in
  4265. the High Level Design section.</para>
  4266. <para>If you are using the Jakarta Commons Attributes approach, your
  4267. bean context will be configured differently:</para>
  4268. <programlisting>&lt;bean id="attributes" class="org.springframework.metadata.commons.CommonsAttributes"/&gt;
  4269. &lt;bean id="objectDefinitionSource" class="org.acegisecurity.intercept.method.MethodDefinitionAttributes"&gt;
  4270. &lt;property name="attributes"&gt;&lt;ref local="attributes"/&gt;&lt;/property&gt;
  4271. &lt;/bean&gt;
  4272. &lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  4273. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  4274. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4275. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4276. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4277. &lt;property name="objectDefinitionSource"&gt;&lt;ref bean="objectDefinitionSource"/&gt;&lt;/property&gt;
  4278. &lt;/bean&gt; </programlisting>
  4279. <para>In addition, your source code will contain Jakarta Commons
  4280. Attributes tags that refer to a concrete implementation of
  4281. <literal>ConfigAttribute</literal>. The following example uses the
  4282. <literal>SecurityConfig</literal> implementation to represent the
  4283. configuration attributes, and results in the same security
  4284. configuration as provided by the property editor approach
  4285. above:</para>
  4286. <programlisting>public interface BankManager {
  4287. /**
  4288. * @@SecurityConfig("ROLE_SUPERVISOR")
  4289. * @@SecurityConfig("RUN_AS_SERVER")
  4290. */
  4291. public void deleteSomething(int id);
  4292. /**
  4293. * @@SecurityConfig("ROLE_SUPERVISOR")
  4294. * @@SecurityConfig("RUN_AS_SERVER")
  4295. */
  4296. public void deleteAnother(int id);
  4297. /**
  4298. * @@SecurityConfig("ROLE_TELLER")
  4299. * @@SecurityConfig("ROLE_SUPERVISOR")
  4300. * @@SecurityConfig("BANKSECURITY_CUSTOMER")
  4301. * @@SecurityConfig("RUN_AS_SERVER")
  4302. */
  4303. public float getBalance(int id);
  4304. }</programlisting>
  4305. <para>If you are using the Acegi Security Java 5 Annotations approach,
  4306. your bean context will be configured as follows:</para>
  4307. <programlisting>&lt;bean id="attributes" class="org.acegisecurity.annotation.SecurityAnnotationAttributes"/&gt;
  4308. &lt;bean id="objectDefinitionSource" class="org.acegisecurity.intercept.method.MethodDefinitionAttributes"&gt;
  4309. &lt;property name="attributes"&gt;&lt;ref local="attributes"/&gt;&lt;/property&gt;
  4310. &lt;/bean&gt;
  4311. &lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  4312. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  4313. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4314. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4315. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4316. &lt;property name="objectDefinitionSource"&gt;&lt;ref bean="objectDefinitionSource"/&gt;&lt;/property&gt;
  4317. &lt;/bean&gt; </programlisting>
  4318. <para>In addition, your source code will contain Acegi Java 5 Security
  4319. Annotations that represent the <literal>ConfigAttribute</literal>. The
  4320. following example uses the <literal>@Secured</literal> annotations to
  4321. represent the configuration attributes, and results in the same
  4322. security configuration as provided by the property editor
  4323. approach:</para>
  4324. <programlisting>import org.acegisecurity.annotation.Secured;
  4325. public interface BankManager {
  4326. /**
  4327. * Delete something
  4328. */
  4329. @Secured({"ROLE_SUPERVISOR","RUN_AS_SERVER" })
  4330. public void deleteSomething(int id);
  4331. /**
  4332. * Delete another
  4333. */
  4334. @Secured({"ROLE_SUPERVISOR","RUN_AS_SERVER" })
  4335. public void deleteAnother(int id);
  4336. /**
  4337. * Get balance
  4338. */
  4339. @Secured({"ROLE_TELLER","ROLE_SUPERVISOR","BANKSECURITY_CUSTOMER","RUN_AS_SERVER" })
  4340. public float getBalance(int id);
  4341. }</programlisting>
  4342. <para>You might have noticed the
  4343. <literal>validateConfigAttributes</literal> property in the above
  4344. <literal>MethodSecurityInterceptor</literal> examples. When set to
  4345. <literal>true</literal> (the default), at startup time the
  4346. <literal>MethodSecurityInterceptor</literal> will evaluate if the
  4347. provided configuration attributes are valid. It does this by checking
  4348. each configuration attribute can be processed by either the
  4349. <literal>AccessDecisionManager</literal> or the
  4350. <literal>RunAsManager</literal>. If neither of these can process a
  4351. given configuration attribute, an exception is thrown. If using the
  4352. Jakarta Commons Attributes method of configuration, you should set
  4353. <literal>validateConfigAttributes</literal> to
  4354. <literal>false</literal>.</para>
  4355. <para>Please note that when using
  4356. <literal>BeanNameAutoProxyCreator</literal> to create the required
  4357. proxy for security, the configuration must contain the property
  4358. <literal>proxyTargetClass</literal> set to <literal>true</literal>.
  4359. Otherwise, the method passed to
  4360. <literal>MethodSecurityInterceptor.invoke</literal> is the proxy's
  4361. caller, not the proxy's target. Note that this introduces a
  4362. requirement on CGLIB. See an example of using
  4363. <literal>BeanNameAutoProxyCreator</literal> below:</para>
  4364. <programlisting>&lt;bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt;
  4365. &lt;property name="interceptorNames"&gt;
  4366. &lt;list&gt;&lt;value&gt;methodSecurityInterceptor&lt;/value&gt;&lt;/list&gt;
  4367. &lt;/property&gt;
  4368. &lt;property name="beanNames"&gt;
  4369. &lt;list&gt;&lt;value&gt;targetObjectName&lt;/value&gt;&lt;/list&gt;
  4370. &lt;/property&gt;
  4371. &lt;property name="proxyTargetClass" value="true"/&gt;
  4372. &lt;/bean&gt; </programlisting>
  4373. </sect1>
  4374. <sect1 id="aspectj">
  4375. <title>AspectJ (JoinPoint) Security Interceptor</title>
  4376. <para>The AspectJ security interceptor is very similar to the AOP
  4377. Alliance security interceptor discussed in the previous section.
  4378. Indeed we will only discuss the differences in this section.</para>
  4379. <para>The AspectJ interceptor is named
  4380. <literal>AspectJSecurityInterceptor</literal>. Unlike the AOP Alliance
  4381. security interceptor, which relies on the Spring application context
  4382. to weave in the security interceptor via proxying, the
  4383. <literal>AspectJSecurityInterceptor</literal> is weaved in via the
  4384. AspectJ compiler. It would not be uncommon to use both types of
  4385. security interceptors in the same application, with
  4386. <literal>AspectJSecurityInterceptor</literal> being used for domain
  4387. object instance security and the AOP Alliance
  4388. <literal>MethodSecurityInterceptor</literal> being used for services
  4389. layer security.</para>
  4390. <para>Let's first consider how the
  4391. <literal>AspectJSecurityInterceptor</literal> is configured in the
  4392. Spring application context:</para>
  4393. <programlisting>&lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor"&gt;
  4394. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
  4395. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4396. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4397. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4398. &lt;property name="afterInvocationManager"&gt;&lt;ref bean="afterInvocationManager"/&gt;&lt;/property&gt;
  4399. &lt;property name="objectDefinitionSource"&gt;
  4400. &lt;value&gt;
  4401. org.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER
  4402. org.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER
  4403. &lt;/value&gt;
  4404. &lt;/property&gt;
  4405. &lt;/bean&gt; </programlisting>
  4406. <para>As you can see, aside from the class name, the
  4407. <literal>AspectJSecurityInterceptor</literal> is exactly the same as
  4408. the AOP Alliance security interceptor. Indeed the two interceptors can
  4409. share the same <literal>objectDefinitionSource</literal>, as the
  4410. <literal>ObjectDefinitionSource</literal> works with
  4411. <literal>java.lang.reflect.Method</literal>s rather than an AOP
  4412. library-specific class. Of course, your access decisions have access
  4413. to the relevant AOP library-specific invocation (ie
  4414. <literal>MethodInvocation</literal> or <literal>JoinPoint</literal>)
  4415. and as such can consider a range of addition criteria when making
  4416. access decisions (such as method arguments).</para>
  4417. <para>Next you'll need to define an AspectJ <literal>aspect</literal>.
  4418. For example:</para>
  4419. <programlisting>package org.acegisecurity.samples.aspectj;
  4420. import org.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor;
  4421. import org.acegisecurity.intercept.method.aspectj.AspectJCallback;
  4422. import org.springframework.beans.factory.InitializingBean;
  4423. public aspect DomainObjectInstanceSecurityAspect implements InitializingBean {
  4424. private AspectJSecurityInterceptor securityInterceptor;
  4425. pointcut domainObjectInstanceExecution(): target(PersistableEntity)
  4426. &amp;&amp; execution(public * *(..)) &amp;&amp; !within(DomainObjectInstanceSecurityAspect);
  4427. Object around(): domainObjectInstanceExecution() {
  4428. if (this.securityInterceptor != null) {
  4429. AspectJCallback callback = new AspectJCallback() {
  4430. public Object proceedWithObject() {
  4431. return proceed();
  4432. }
  4433. };
  4434. return this.securityInterceptor.invoke(thisJoinPoint, callback);
  4435. } else {
  4436. return proceed();
  4437. }
  4438. }
  4439. public AspectJSecurityInterceptor getSecurityInterceptor() {
  4440. return securityInterceptor;
  4441. }
  4442. public void setSecurityInterceptor(AspectJSecurityInterceptor securityInterceptor) {
  4443. this.securityInterceptor = securityInterceptor;
  4444. }
  4445. public void afterPropertiesSet() throws Exception {
  4446. if (this.securityInterceptor == null)
  4447. throw new IllegalArgumentException("securityInterceptor required");
  4448. }
  4449. }</programlisting>
  4450. <para>In the above example, the security interceptor will be applied
  4451. to every instance of <literal>PersistableEntity</literal>, which is an
  4452. abstract class not shown (you can use any other class or
  4453. <literal>pointcut</literal> expression you like). For those curious,
  4454. <literal>AspectJCallback</literal> is needed because the
  4455. <literal>proceed();</literal> statement has special meaning only
  4456. within an <literal>around()</literal> body. The
  4457. <literal>AspectJSecurityInterceptor</literal> calls this anonymous
  4458. <literal>AspectJCallback</literal> class when it wants the target
  4459. object to continue.</para>
  4460. <para>You will need to configure Spring to load the aspect and wire it
  4461. with the <literal>AspectJSecurityInterceptor</literal>. A bean
  4462. declaration which achieves this is shown below:</para>
  4463. <programlisting>
  4464. &lt;bean id="domainObjectInstanceSecurityAspect"
  4465. class="org.acegisecurity.samples.aspectj.DomainObjectInstanceSecurityAspect"
  4466. factory-method="aspectOf"&gt;
  4467. &lt;property name="securityInterceptor"&gt;&lt;ref bean="aspectJSecurityInterceptor"/&gt;&lt;/property&gt;
  4468. &lt;/bean&gt;
  4469. </programlisting>
  4470. <para>That's it! Now you can create your beans from anywhere within
  4471. your application, using whatever means you think fit (eg <literal>new
  4472. Person();</literal>) and they will have the security interceptor
  4473. applied.</para>
  4474. </sect1>
  4475. <sect1 id="filter-invocation-authorization">
  4476. <title>FilterInvocation Security Interceptor</title>
  4477. <para>To secure <literal>FilterInvocation</literal>s, developers need
  4478. to add a filter to their <literal>web.xml</literal> that delegates to
  4479. the <literal>FilterSecurityInterceptor</literal>. A typical
  4480. configuration example is provided below:</para>
  4481. <programlisting>&lt;filter&gt;
  4482. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  4483. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  4484. &lt;init-param&gt;
  4485. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  4486. &lt;param-value&gt;org.acegisecurity.intercept.web.FilterSecurityInterceptor&lt;/param-value&gt;
  4487. &lt;/init-param&gt;
  4488. &lt;/filter&gt;
  4489. &lt;filter-mapping&gt;
  4490. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  4491. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  4492. &lt;/filter-mapping&gt;</programlisting>
  4493. <para>Notice that the filter is actually a
  4494. <literal>FilterToBeanProxy</literal>. Most of the filters used by
  4495. Acegi Security use this class. Refer to the Filters section to learn
  4496. more about this bean.</para>
  4497. <para>In the application context you will need to configure three
  4498. beans:</para>
  4499. <programlisting>&lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;
  4500. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="authenticationEntryPoint"/&gt;&lt;/property&gt;
  4501. &lt;/bean&gt;
  4502. &lt;bean id="authenticationEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;
  4503. &lt;property name="loginFormUrl"&gt;&lt;value&gt;/acegilogin.jsp&lt;/value&gt;&lt;/property&gt;
  4504. &lt;property name="forceHttps"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  4505. &lt;/bean&gt;
  4506. &lt;bean id="filterSecurityInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  4507. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4508. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4509. &lt;property name="objectDefinitionSource"&gt;
  4510. &lt;value&gt;
  4511. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  4512. \A/secure/super/.*\Z=ROLE_WE_DONT_HAVE
  4513. \A/secure/.*\Z=ROLE_SUPERVISOR,ROLE_TELLER
  4514. &lt;/value&gt;
  4515. &lt;/property&gt;
  4516. &lt;/bean&gt; </programlisting>
  4517. <para>The <classname>ExceptionTranslationFilter</classname> provides
  4518. the bridge between Java exceptions and HTTP responses. It is solely
  4519. concerned with maintaining the user interface. This filter does not do
  4520. any actual security enforcement. If an
  4521. <exceptionname>AuthenticationException</exceptionname> is detected,
  4522. the filter will call the AuthenticationEntryPoint to commence the
  4523. authentication process (e.g. a user login).</para>
  4524. <para>The <literal>AuthenticationEntryPoint</literal> will be called
  4525. if the user requests a secure HTTP resource but they are not
  4526. authenticated. The class handles presenting the appropriate response
  4527. to the user so that authentication can begin. Three concrete
  4528. implementations are provided with Acegi Security:
  4529. <literal>AuthenticationProcessingFilterEntryPoint</literal> for
  4530. commencing a form-based authentication,
  4531. <literal>BasicProcessingFilterEntryPoint</literal> for commencing a
  4532. HTTP Basic authentication process, and
  4533. <literal>CasProcessingFilterEntryPoint</literal> for commencing a
  4534. JA-SIG Central Authentication Service (CAS) login. The
  4535. <literal>AuthenticationProcessingFilterEntryPoint</literal> and
  4536. <literal>CasProcessingFilterEntryPoint</literal> have optional
  4537. properties related to forcing the use of HTTPS, so please refer to the
  4538. JavaDocs if you require this.</para>
  4539. <para><literal>FilterSecurityInterceptor</literal> is responsible for
  4540. handling the security of HTTP resources. Like any other security
  4541. interceptor, it requires a reference to an
  4542. <literal>AuthenticationManager</literal> and an
  4543. <literal>AccessDecisionManager</literal>, which are both discussed in
  4544. separate sections below. The
  4545. <literal>FilterSecurityInterceptor</literal> is also configured with
  4546. configuration attributes that apply to different HTTP URL requests. A
  4547. full discussion of configuration attributes is provided in the High
  4548. Level Design section of this document.</para>
  4549. <para>The <literal>FilterSecurityInterceptor</literal> can be
  4550. configured with configuration attributes in two ways. The first is via
  4551. a property editor and the application context, which is shown above.
  4552. The second is via writing your own
  4553. <literal>ObjectDefinitionSource</literal>, although this is beyond the
  4554. scope of this document. Irrespective of the approach used, the
  4555. <literal>ObjectDefinitionSource</literal> is responsible for returning
  4556. a <literal>ConfigAttributeDefinition</literal> object that contains
  4557. all of the configuration attributes associated with a single secure
  4558. HTTP URL.</para>
  4559. <para>It should be noted that the
  4560. <literal>FilterSecurityInterceptor.setObjectDefinitionSource()</literal>
  4561. method actually expects an instance of
  4562. <literal>FilterInvocationDefinitionSource</literal>. This is a marker
  4563. interface which subclasses <literal>ObjectDefinitionSource</literal>.
  4564. It simply denotes the <literal>ObjectDefinitionSource</literal>
  4565. understands <literal>FilterInvocation</literal>s. In the interests of
  4566. simplicity we'll continue to refer to the
  4567. <literal>FilterInvocationDefinitionSource</literal> as an
  4568. <literal>ObjectDefinitionSource</literal>, as the distinction is of
  4569. little relevance to most users of the
  4570. <literal>FilterSecurityInterceptor</literal>.</para>
  4571. <para>If using the application context property editor approach (as
  4572. shown above), commas are used to delimit the different configuration
  4573. attributes that apply to each HTTP URL. Each configuration attribute
  4574. is assigned into its own <literal>SecurityConfig</literal> object. The
  4575. <literal>SecurityConfig</literal> object is discussed in the High
  4576. Level Design section. The <literal>ObjectDefinitionSource</literal>
  4577. created by the property editor,
  4578. <literal>FilterInvocationDefinitionSource</literal>, matches
  4579. configuration attributes against <literal>FilterInvocations</literal>
  4580. based on expression evaluation of the request URL. Two standard
  4581. expression syntaxes are supported. The default is to treat all
  4582. expressions as regular expressions. Alternatively, the presence of a
  4583. <literal>PATTERN_TYPE_APACHE_ANT</literal> directive will cause all
  4584. expressions to be treated as Apache Ant paths. It is not possible to
  4585. mix expression syntaxes within the same definition. For example, the
  4586. earlier configuration could be generated using Apache Ant paths as
  4587. follows:</para>
  4588. <programlisting>&lt;bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  4589. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4590. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4591. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4592. &lt;property name="objectDefinitionSource"&gt;
  4593. &lt;value&gt;
  4594. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  4595. PATTERN_TYPE_APACHE_ANT
  4596. /secure/super/**=ROLE_WE_DONT_HAVE
  4597. /secure/**=ROLE_SUPERVISOR,ROLE_TELLER
  4598. &lt;/value&gt;
  4599. &lt;/property&gt;
  4600. &lt;/bean&gt; </programlisting>
  4601. <para>Irrespective of the type of expression syntax used, expressions
  4602. are always evaluated in the order they are defined. Thus it is
  4603. important that more specific expressions are defined higher in the
  4604. list than less specific expressions. This is reflected in our example
  4605. above, where the more specific <literal>/secure/super/</literal>
  4606. pattern appears higher than the less specific
  4607. <literal>/secure/</literal> pattern. If they were reversed, the
  4608. <literal>/secure/</literal> pattern would always match and the
  4609. <literal>/secure/super/</literal> pattern would never be
  4610. evaluated.</para>
  4611. <para>The special keyword
  4612. <literal>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</literal> causes
  4613. the <literal>FilterInvocationDefinitionSource</literal> to
  4614. automatically convert a request URL to lowercase before comparison
  4615. against the expressions. Whilst by default the case of the request URL
  4616. is not converted, it is generally recommended to use
  4617. <literal>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</literal> and
  4618. write each expression assuming lowercase.</para>
  4619. <para>As with other security interceptors, the
  4620. <literal>validateConfigAttributes</literal> property is observed. When
  4621. set to <literal>true</literal> (the default), at startup time the
  4622. <literal>FilterSecurityInterceptor</literal> will evaluate if the
  4623. provided configuration attributes are valid. It does this by checking
  4624. each configuration attribute can be processed by either the
  4625. <literal>AccessDecisionManager</literal> or the
  4626. <literal>RunAsManager</literal>. If neither of these can process a
  4627. given configuration attribute, an exception is thrown.</para>
  4628. </sect1>
  4629. </chapter>
  4630. <chapter id="domain-acls">
  4631. <title>Domain Object Security</title>
  4632. <section id="domain-acls-overview">
  4633. <title>Overview</title>
  4634. <para>Complex applications often will find the need to define access
  4635. permissions not simply at a web request or method invocation level.
  4636. Instead, security decisions need to comprise both who
  4637. (<literal>Authentication</literal>), where
  4638. (<literal>MethodInvocation</literal>) and what
  4639. (<literal>SomeDomainObject</literal>). In other words, authorization
  4640. decisions also need to consider the actual domain object instance
  4641. subject of a method invocation.</para>
  4642. <para>Imagine you're designing an application for a pet clinic. There
  4643. will be two main groups of users of your Spring-based application:
  4644. staff of the pet clinic, as well as the pet clinic's customers. The
  4645. staff will have access to all of the data, whilst your customers will
  4646. only be able to see their own customer records. To make it a little
  4647. more interesting, your customers can allow other users to see their
  4648. customer records, such as their "puppy preschool "mentor or president
  4649. of their local "Pony Club". Using Acegi Security as the foundation,
  4650. you have several approaches that can be used:<orderedlist>
  4651. <listitem>
  4652. <para>Write your business methods to enforce the security. You
  4653. could consult a collection within the
  4654. <literal>Customer</literal> domain object instance to determine
  4655. which users have access. By using the
  4656. <literal>SecurityContextHolder.getContext().getAuthentication()</literal>,
  4657. you'll be able to access the <literal>Authentication</literal>
  4658. object.</para>
  4659. </listitem>
  4660. <listitem>
  4661. <para>Write an <literal>AccessDecisionVoter</literal> to enforce
  4662. the security from the <literal>GrantedAuthority[]</literal>s
  4663. stored in the <literal>Authentication</literal> object. This
  4664. would mean your <literal>AuthenticationManager</literal> would
  4665. need to populate the <literal>Authentication</literal> with
  4666. custom <literal>GrantedAuthority</literal>[]s representing each
  4667. of the <literal>Customer</literal> domain object instances the
  4668. principal has access to.</para>
  4669. </listitem>
  4670. <listitem>
  4671. <para>Write an <literal>AccessDecisionVoter</literal> to enforce
  4672. the security and open the target <literal>Customer</literal>
  4673. domain object directly. This would mean your voter needs access
  4674. to a DAO that allows it to retrieve the
  4675. <literal>Customer</literal> object. It would then access the
  4676. <literal>Customer</literal> object's collection of approved
  4677. users and make the appropriate decision.</para>
  4678. </listitem>
  4679. </orderedlist></para>
  4680. <para>Each one of these approaches is perfectly legitimate. However,
  4681. the first couples your authorization checking to your business code.
  4682. The main problems with this include the enhanced difficulty of unit
  4683. testing and the fact it would be more difficult to reuse the
  4684. <literal>Customer</literal> authorization logic elsewhere. Obtaining
  4685. the <literal>GrantedAuthority[]</literal>s from the
  4686. <literal>Authentication</literal> object is also fine, but will not
  4687. scale to large numbers of <literal>Customer</literal>s. If a user
  4688. might be able to access 5,000 <literal>Customer</literal>s (unlikely
  4689. in this case, but imagine if it were a popular vet for a large Pony
  4690. Club!) the amount of memory consumed and time required to construct
  4691. the <literal>Authentication</literal> object would be undesirable. The
  4692. final method, opening the <literal>Customer</literal> directly from
  4693. external code, is probably the best of the three. It achieves
  4694. separation of concerns, and doesn't misuse memory or CPU cycles, but
  4695. it is still inefficient in that both the
  4696. <literal>AccessDecisionVoter</literal> and the eventual business
  4697. method itself will perform a call to the DAO responsible for
  4698. retrieving the <literal>Customer</literal> object. Two accesses per
  4699. method invocation is clearly undesirable. In addition, with every
  4700. approach listed you'll need to write your own access control list
  4701. (ACL) persistence and business logic from scratch.</para>
  4702. <para>Fortunately, there is another alternative, which we'll talk
  4703. about below.</para>
  4704. </section>
  4705. <section id="domain-acls-basic">
  4706. <title>Basic ACL Package</title>
  4707. <para>Please note that our Basic ACL services are currently being
  4708. refactored. We expect release 1.1.0 will contain this new code.
  4709. Planned code is already in the Acegi Security Subversion sandbox, so
  4710. please check there if you have a new application requiring ACLs or are
  4711. in the planning stages. The Basic ACL services will be deprecated from
  4712. release 1.1.0.</para>
  4713. <para>The <literal>org.acegisecurity.acl</literal> package is very
  4714. simple, comprising only a handful of interfaces and a single class, as
  4715. shown in Figure 6. It provides the basic foundation for access control
  4716. list (ACL) lookups.</para>
  4717. <para><mediaobject>
  4718. <imageobject role="html">
  4719. <imagedata align="center" fileref="images/ACLSecurity.gif"
  4720. format="GIF" />
  4721. </imageobject>
  4722. <caption>
  4723. <para>Figure 6: Access Control List Manager</para>
  4724. </caption>
  4725. </mediaobject></para>
  4726. <para>The central interface is <literal>AclManager</literal>, which is
  4727. defined by two methods:</para>
  4728. <para><programlisting>public AclEntry[] getAcls(java.lang.Object domainInstance);
  4729. public AclEntry[] getAcls(java.lang.Object domainInstance, Authentication authentication);</programlisting></para>
  4730. <para><literal>AclManager</literal> is intended to be used as a
  4731. collaborator against your business objects, or, more desirably,
  4732. <literal>AccessDecisionVoter</literal>s. This means you use Spring's
  4733. normal <literal>ApplicationContext</literal> features to wire up your
  4734. <literal>AccessDecisionVoter</literal> (or business method) with an
  4735. <literal>AclManager</literal>. Consideration was given to placing the
  4736. ACL information in the <literal>ContextHolder</literal>, but it was
  4737. felt this would be inefficient both in terms of memory usage as well
  4738. as the time spent loading potentially unused ACL information. The
  4739. trade-off of needing to wire up a collaborator for those objects
  4740. requiring ACL information is rather minor, particularly in a
  4741. Spring-managed application.</para>
  4742. <para>The first method of the <literal>AclManager</literal> will
  4743. return all ACLs applying to the domain object instance passed to it.
  4744. The second method does the same, but only returns those ACLs which
  4745. apply to the passed <literal>Authentication</literal> object.</para>
  4746. <para>The <literal>AclEntry</literal> interface returned by
  4747. <literal>AclManager</literal> is merely a marker interface. You will
  4748. need to provide an implementation that reflects that ACL permissions
  4749. for your application.</para>
  4750. <para>Rounding out the <literal>org.acegisecurity.acl</literal>
  4751. package is an <literal>AclProviderManager</literal> class, with a
  4752. corresponding <literal>AclProvider</literal> interface.
  4753. <literal>AclProviderManager</literal> is a concrete implementation of
  4754. <literal>AclManager</literal>, which iterates through registered
  4755. <literal>AclProvider</literal>s. The first
  4756. <literal>AclProvider</literal> that indicates it can authoritatively
  4757. provide ACL information for the presented domain object instance will
  4758. be used. This is very similar to the
  4759. <literal>AuthenticationProvider</literal> interface used for
  4760. authentication.</para>
  4761. <para>With this background, let's now look at a usable ACL
  4762. implementation.</para>
  4763. <para>Acegi Security includes a production-quality ACL provider
  4764. implementation, which is shown in Figure 7.</para>
  4765. <para><mediaobject>
  4766. <imageobject role="html">
  4767. <imagedata align="center" fileref="images/BasicAclProvider.gif"
  4768. format="GIF" />
  4769. </imageobject>
  4770. <caption>
  4771. <para>Figure 7: Basic ACL Manager</para>
  4772. </caption>
  4773. </mediaobject></para>
  4774. <para>The implementation is based on integer masking, which is
  4775. commonly used for ACL permissions given its flexibility and speed.
  4776. Anyone who has used Unix's <literal>chmod</literal> command will know
  4777. all about this type of permission masking (eg <literal>chmod
  4778. 777</literal>). You'll find the classes and interfaces for the integer
  4779. masking ACL package under
  4780. <literal>org.acegisecurity.acl.basic</literal>.</para>
  4781. <para>Extending the <literal>AclEntry</literal> interface is a
  4782. <literal>BasicAclEntry</literal> interface, with the main methods
  4783. shown below:</para>
  4784. <para><programlisting>public AclObjectIdentity getAclObjectIdentity();
  4785. public AclObjectIdentity getAclObjectParentIdentity();
  4786. public int getMask();
  4787. public java.lang.Object getRecipient();</programlisting></para>
  4788. <para>As shown, each <literal>BasicAclEntry</literal> has four main
  4789. properties. The <literal>mask</literal> is the integer that represents
  4790. the permissions granted to the <literal>recipient</literal>. The
  4791. <literal>aclObjectIdentity</literal> is able to identify the domain
  4792. object instance for which the ACL applies, and the
  4793. <literal>aclObjectParentIdentity</literal> optionally specifies the
  4794. parent of the domain object instance. Multiple
  4795. <literal>BasicAclEntry</literal>s usually exist against a single
  4796. domain object instance, and as suggested by the parent identity
  4797. property, permissions granted higher in the object hierarchy will
  4798. trickle down and be inherited (unless blocked by integer zero).</para>
  4799. <para><literal>BasicAclEntry</literal> implementations typically
  4800. provide convenience methods, such as
  4801. <literal>isReadAllowed()</literal>, to avoid application classes
  4802. needing to perform bit masking themselves. The
  4803. <literal>SimpleAclEntry</literal> and
  4804. <literal>AbstractBasicAclEntry</literal> demonstrate and provide much
  4805. of this bit masking logic.</para>
  4806. <para>The <literal>AclObjectIdentity</literal> itself is merely a
  4807. marker interface, so you need to provide implementations for your
  4808. domain objects. However, the package does include a
  4809. <literal>NamedEntityObjectIdentity</literal> implementation which will
  4810. suit many needs. The <literal>NamedEntityObjectIdentity</literal>
  4811. identifies a given domain object instance by the classname of the
  4812. instance and the identity of the instance. A
  4813. <literal>NamedEntityObjectIdentity</literal> can be constructed
  4814. manually (by calling the constructor and providing the classname and
  4815. identity <literal>String</literal>s), or by passing in any domain
  4816. object that contains a <literal>getId()</literal> method.</para>
  4817. <para>The actual <literal>AclProvider</literal> implementation is
  4818. named <literal>BasicAclProvider</literal>. It has adopted a similar
  4819. design to that used by the authentication-related
  4820. <literal>DaoAuthenticationProvder</literal>. Specifically, you define
  4821. a <literal>BasicAclDao</literal> against the provider, so different
  4822. ACL repository types can be accessed in a pluggable manner. The
  4823. <literal>BasicAclProvider</literal> also supports pluggable cache
  4824. providers (with Acegi Security including an implementation that fronts
  4825. EH-CACHE).</para>
  4826. <para>The <literal>BasicAclDao</literal> interface is very simple to
  4827. implement:</para>
  4828. <para><programlisting>public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity);</programlisting></para>
  4829. <para>A <literal>BasicAclDao</literal> implementation needs to
  4830. understand the presented <literal>AclObjectIdentity</literal> and how
  4831. it maps to a storage repository, find the relevant records, and create
  4832. appropriate <literal>BasicAclEntry</literal> objects and return
  4833. them.</para>
  4834. <para>Acegi Security includes a single <literal>BasicAclDao</literal>
  4835. implementation called <literal>JdbcDaoImpl</literal>. As implied by
  4836. the name, <literal>JdbcDaoImpl</literal> accesses ACL information from
  4837. a JDBC database. There is also an extended version of this DAO,
  4838. <literal>JdbcExtendedDaoImpl</literal>, which provides CRUD operations
  4839. on the JDBC database, although we won't discuss these features here.
  4840. The default database schema and some sample data will aid in
  4841. understanding its function:</para>
  4842. <para><programlisting>CREATE TABLE acl_object_identity (
  4843. id IDENTITY NOT NULL,
  4844. object_identity VARCHAR_IGNORECASE(250) NOT NULL,
  4845. parent_object INTEGER,
  4846. acl_class VARCHAR_IGNORECASE(250) NOT NULL,
  4847. CONSTRAINT unique_object_identity UNIQUE(object_identity),
  4848. FOREIGN KEY (parent_object) REFERENCES acl_object_identity(id)
  4849. );
  4850. CREATE TABLE acl_permission (
  4851. id IDENTITY NOT NULL,
  4852. acl_object_identity INTEGER NOT NULL,
  4853. recipient VARCHAR_IGNORECASE(100) NOT NULL,
  4854. mask INTEGER NOT NULL,
  4855. CONSTRAINT unique_recipient UNIQUE(acl_object_identity, recipient),
  4856. FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id)
  4857. );
  4858. INSERT INTO acl_object_identity VALUES (1, 'corp.DomainObject:1', null, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4859. INSERT INTO acl_object_identity VALUES (2, 'corp.DomainObject:2', 1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4860. INSERT INTO acl_object_identity VALUES (3, 'corp.DomainObject:3', 1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4861. INSERT INTO acl_object_identity VALUES (4, 'corp.DomainObject:4', 1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4862. INSERT INTO acl_object_identity VALUES (5, 'corp.DomainObject:5', 3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4863. INSERT INTO acl_object_identity VALUES (6, 'corp.DomainObject:6', 3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4864. INSERT INTO acl_permission VALUES (null, 1, 'ROLE_SUPERVISOR', 1);
  4865. INSERT INTO acl_permission VALUES (null, 2, 'ROLE_SUPERVISOR', 0);
  4866. INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);
  4867. INSERT INTO acl_permission VALUES (null, 3, 'scott', 14);
  4868. INSERT INTO acl_permission VALUES (null, 6, 'scott', 1);</programlisting></para>
  4869. <para>As can be seen, database-specific constraints are used
  4870. extensively to ensure the integrity of the ACL information. If you
  4871. need to use a different database (Hypersonic SQL statements are shown
  4872. above), you should try to implement equivalent constraints. The
  4873. equivalent Oracle configuration is:</para>
  4874. <para><programlisting>CREATE TABLE ACL_OBJECT_IDENTITY (
  4875. ID number(19,0) not null,
  4876. OBJECT_IDENTITY varchar2(255) NOT NULL,
  4877. PARENT_OBJECT number(19,0),
  4878. ACL_CLASS varchar2(255) NOT NULL,
  4879. primary key (ID)
  4880. );
  4881. ALTER TABLE ACL_OBJECT_IDENTITY ADD CONTRAINT FK_PARENT_OBJECT foreign key (ID) references ACL_OBJECT_IDENTITY
  4882. CREATE SEQUENCE ACL_OBJECT_IDENTITY_SEQ;
  4883. CREATE OR REPLACE TRIGGER ACL_OBJECT_IDENTITY_ID
  4884. BEFORE INSERT ON ACL_OBJECT_IDENTITY
  4885. FOR EACH ROW
  4886. BEGIN
  4887. SELECT ACL_OBJECT_IDENTITY_SEQ.NEXTVAL INTO :new.id FROM dual;
  4888. END;
  4889. CREATE TABLE ACL_PERMISSION (
  4890. ID number(19,0) not null,
  4891. ACL_OBJECT_IDENTITY number(19,0) NOT NULL,
  4892. RECIPIENT varchar2(255) NOT NULL,
  4893. MASK number(19,0) NOT NULL,
  4894. primary key (ID)
  4895. );
  4896. ALTER TABLE ACL_PERMISSION ADD CONTRAINT UNIQUE_ID_RECIPIENT unique (acl_object_identity, recipient);
  4897. CREATE SEQUENCE ACL_PERMISSION_SEQ;
  4898. CREATE OR REPLACE TRIGGER ACL_PERMISSION_ID
  4899. BEFORE INSERT ON ACL_PERMISSION
  4900. FOR EACH ROW
  4901. BEGIN
  4902. SELECT ACL_PERMISSION_SEQ.NEXTVAL INTO :new.id FROM dual;
  4903. END;
  4904. &lt;bean id="basicAclExtendedDao" class="org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl"&gt;
  4905. &lt;property name="dataSource"&gt;
  4906. &lt;ref bean="dataSource"/&gt;
  4907. &lt;/property&gt;
  4908. &lt;property name="objectPropertiesQuery" value="${acegi.objectPropertiesQuery}"/&gt;
  4909. &lt;/bean&gt;
  4910. &lt;prop key="acegi.objectPropertiesQuery"&gt;SELECT CHILD.ID, CHILD.OBJECT_IDENTITY, CHILD.ACL_CLASS, PARENT.OBJECT_IDENTITY as PARENT_OBJECT_IDENTITY FROM acl_object_identity as CHILD LEFT OUTER JOIN acl_object_identity as PARENT ON CHILD.parent_object=PARENT.id WHERE CHILD.object_identity = ?&lt;/prop&gt; </programlisting></para>
  4911. <para>The <literal>JdbcDaoImpl</literal> will only respond to requests
  4912. for <literal>NamedEntityObjectIdentity</literal>s. It converts such
  4913. identities into a single <literal>String</literal>, comprising
  4914. the<literal> NamedEntityObjectIdentity.getClassname()</literal> +
  4915. <literal>":"</literal> +
  4916. <literal>NamedEntityObjectIdentity.getId()</literal>. This yields the
  4917. type of <literal>object_identity</literal> values shown above. As
  4918. indicated by the sample data, each database row corresponds to a
  4919. single <literal>BasicAclEntry</literal>. As stated earlier and
  4920. demonstrated by <literal>corp.DomainObject:2</literal> in the above
  4921. sample data, each domain object instance will often have multiple
  4922. <literal>BasicAclEntry</literal>[]s.</para>
  4923. <para>As <literal>JdbcDaoImpl</literal> is required to return concrete
  4924. <literal>BasicAclEntry</literal> classes, it needs to know which
  4925. <literal>BasicAclEntry</literal> implementation it is to create and
  4926. populate. This is the role of the <literal>acl_class</literal> column.
  4927. <literal>JdbcDaoImpl</literal> will create the indicated class and set
  4928. its <literal>mask</literal>, <literal>recipient</literal>,
  4929. <literal>aclObjectIdentity</literal> and
  4930. <literal>aclObjectParentIdentity</literal> properties.</para>
  4931. <para>As you can probably tell from the sample data, the
  4932. <literal>parent_object_identity</literal> value can either be null or
  4933. in the same format as the <literal>object_identity</literal>. If
  4934. non-null, <literal>JdbcDaoImpl</literal> will create a
  4935. <literal>NamedEntityObjectIdentity</literal> to place inside the
  4936. returned <literal>BasicAclEntry</literal> class.</para>
  4937. <para>Returning to the <literal>BasicAclProvider</literal>, before it
  4938. can poll the <literal>BasicAclDao</literal> implementation it needs to
  4939. convert the domain object instance it was passed into an
  4940. <literal>AclObjectIdentity</literal>.
  4941. <literal>BasicAclProvider</literal> has a <literal>protected
  4942. AclObjectIdentity obtainIdentity(Object domainInstance)</literal>
  4943. method that is responsible for this. As a protected method, it enables
  4944. subclasses to easily override. The normal implementation checks
  4945. whether the passed domain object instance implements the
  4946. <literal>AclObjectIdentityAware</literal> interface, which is merely a
  4947. getter for an <literal>AclObjectIdentity</literal>. If the domain
  4948. object does implement this interface, that is the identity returned.
  4949. If the domain object does not implement this interface, the method
  4950. will attempt to create an <literal>AclObjectIdentity</literal> by
  4951. passing the domain object instance to the constructor of a class
  4952. defined by the
  4953. <literal>BasicAclProvider.getDefaultAclObjectIdentity()</literal>
  4954. method. By default the defined class is
  4955. <literal>NamedEntityObjectIdentity</literal>, which was described in
  4956. more detail above. Therefore, you will need to either (i) provide a
  4957. <literal>getId()</literal> method on your domain objects, (ii)
  4958. implement <literal>AclObjectIdentityAware</literal> on your domain
  4959. objects, (iii) provide an alternative
  4960. <literal>AclObjectIdentity</literal> implementation that will accept
  4961. your domain object in its constructor, or (iv) override the
  4962. <literal>obtainIdentity(Object)</literal> method.</para>
  4963. <para>Once the <literal>AclObjectIdentity</literal> of the domain
  4964. object instance is determined, the <literal>BasicAclProvider</literal>
  4965. will poll the DAO to obtain its <literal>BasicAclEntry</literal>[]s.
  4966. If any of the entries returned by the DAO indicate there is a parent,
  4967. that parent will be polled, and the process will repeat until there is
  4968. no further parent. The permissions assigned to a
  4969. <literal>recipient</literal> closest to the domain object instance
  4970. will always take priority and override any inherited permissions. From
  4971. the sample data above, the following inherited permissions would
  4972. apply:</para>
  4973. <para><programlisting>--- Mask integer 0 = no permissions
  4974. --- Mask integer 1 = administer
  4975. --- Mask integer 2 = read
  4976. --- Mask integer 6 = read and write permissions
  4977. --- Mask integer 14 = read and write and create permissions
  4978. ---------------------------------------------------------------------
  4979. --- *** INHERITED RIGHTS FOR DIFFERENT INSTANCES AND RECIPIENTS ***
  4980. --- INSTANCE RECIPIENT PERMISSION(S) (COMMENT #INSTANCE)
  4981. ---------------------------------------------------------------------
  4982. --- 1 ROLE_SUPERVISOR Administer
  4983. --- 2 ROLE_SUPERVISOR None (overrides parent #1)
  4984. --- marissa Read
  4985. --- 3 ROLE_SUPERVISOR Administer (from parent #1)
  4986. --- scott Read, Write, Create
  4987. --- 4 ROLE_SUPERVISOR Administer (from parent #1)
  4988. --- 5 ROLE_SUPERVISOR Administer (from parent #3)
  4989. --- scott Read, Write, Create (from parent #3)
  4990. --- 6 ROLE_SUPERVISOR Administer (from parent #3)
  4991. --- scott Administer (overrides parent #3)</programlisting></para>
  4992. <para>So the above explains how a domain object instance has its
  4993. <literal>AclObjectIdentity</literal> discovered, and the
  4994. <literal>BasicAclDao</literal> will be polled successively until an
  4995. array of inherited permissions is constructed for the domain object
  4996. instance. The final step is to determine the
  4997. <literal>BasicAclEntry</literal>[]s that are actually applicable to a
  4998. given <literal>Authentication</literal> object.</para>
  4999. <para>As you would recall, the <literal>AclManager</literal> (and all
  5000. delegates, up to and including <literal>BasicAclProvider</literal>)
  5001. provides a method which returns only those
  5002. <literal>BasicAclEntry</literal>[]s applying to a passed
  5003. <literal>Authentication</literal> object.
  5004. <literal>BasicAclProvider</literal> delivers this functionality by
  5005. delegating the filtering operation to an
  5006. <literal>EffectiveAclsResolver</literal> implementation. The default
  5007. implementation,
  5008. <literal>GrantedAuthorityEffectiveAclsResolver</literal>, will iterate
  5009. through the <literal>BasicAclEntry</literal>[]s and include only those
  5010. where the <literal>recipient</literal> is equal to either the
  5011. <literal>Authentication</literal>'s <literal>principal</literal> or
  5012. any of the <literal>Authentication</literal>'s
  5013. <literal>GrantedAuthority</literal>[]s. Please refer to the JavaDocs
  5014. for more information.</para>
  5015. <mediaobject>
  5016. <imageobject role="html">
  5017. <imagedata align="center" fileref="images/Permissions.gif"
  5018. format="GIF" />
  5019. </imageobject>
  5020. <caption>
  5021. <para>Figure 8: ACL Instantiation Approach</para>
  5022. </caption>
  5023. </mediaobject>
  5024. <para>The above figure explains the key relationships between objects
  5025. in the Basic ACL package.</para>
  5026. </section>
  5027. </chapter>
  5028. </part>
  5029. <part id="resources">
  5030. <title>Other Resources</title>
  5031. <partintro>
  5032. <para>In addition to this reference guide, a number of other resources
  5033. exist to help you learn how to use Acegi Security. These resources are
  5034. discussed in this section.</para>
  5035. </partintro>
  5036. <chapter id="sample-apps">
  5037. <title id="samples">Sample Applications</title>
  5038. <sect1 id="contacts-sample">
  5039. <title id="contacts">Contacts</title>
  5040. <para>Included with Acegi Security is a very simple application that
  5041. can demonstrate the basic security facilities provided by the system
  5042. (and confirm your Container Adapter is properly configured if you're
  5043. using one).</para>
  5044. <para>If you build from Subversion, the Contacts sample application
  5045. includes three deployable versions:
  5046. <literal>acegi-security-sample-contacts-filter.war</literal> is
  5047. configured with the HTTP Session Authentication approach.
  5048. Acegi<literal><literal>-security-sample-contacts-ca.war</literal></literal>
  5049. is configured to use a Container Adapter. Finally,
  5050. <literal>acegi-security-sample-contacts-cas.war</literal> is designed
  5051. to work with a JA-SIG CAS server. If you're just wanting to see how
  5052. the sample application works, please use
  5053. <literal><literal>acegi-security-sample-contacts-filter.war</literal></literal>
  5054. as it does not require special configuration of your container. This
  5055. is also the artifact included in official release ZIPs.</para>
  5056. <para>To deploy, simply copy the relevant WAR file from Acegi Security
  5057. distribution into your container’s <literal>webapps</literal>
  5058. directory.</para>
  5059. <para>After starting your container, check the application can load.
  5060. Visit
  5061. <literal>http://localhost:</literal><literal><literal>8080/</literal>acegi-security-sample-contacts-filter</literal>
  5062. (or whichever URL is appropriate for your web container and the WAR
  5063. you deployed). A random contact should be displayed. Click "Refresh"
  5064. several times and you will see different contacts. The business method
  5065. that provides this random contact is not secured.</para>
  5066. <para>Next, click "Debug". You will be prompted to authenticate, and a
  5067. series of usernames and passwords are suggested on that page. Simply
  5068. authenticate with any of these and view the resulting page. It should
  5069. contain a success message similar to the following:</para>
  5070. <blockquote>
  5071. <para>Context on SecurityContextHolder is of type:
  5072. org.acegisecurity.context.SecurityContextImpl</para>
  5073. <para>The Context implements SecurityContext.</para>
  5074. <para>Authentication object is of type:
  5075. org.acegisecurity.adapters.PrincipalAcegiUserToken</para>
  5076. <para>Authentication object as a String:
  5077. org.acegisecurity.adapters.PrincipalAcegiUserToken@e9a7c2: Username:
  5078. marissa; Password: [PROTECTED]; Authenticated: true; Granted
  5079. Authorities: ROLE_TELLER, ROLE_SUPERVISOR</para>
  5080. <para>Authentication object holds the following granted
  5081. authorities:</para>
  5082. <para>ROLE_TELLER (getAuthority(): ROLE_TELLER)</para>
  5083. <para>ROLE_SUPERVISOR (getAuthority(): ROLE_SUPERVISOR)</para>
  5084. <para>SUCCESS! Your [container adapter|web filter] appears to be
  5085. properly configured!</para>
  5086. </blockquote>
  5087. <para>If you receive a different message, and deployed
  5088. <literal>acegi-security-sample-contacts-ca.war</literal>, check you
  5089. have properly configured your Container Adapter as described elsewhere
  5090. in this reference guide.</para>
  5091. <para>Once you successfully receive the above message, return to the
  5092. sample application's home page and click "Manage". You can then try
  5093. out the application. Notice that only the contacts available to the
  5094. currently logged on user are displayed, and only users with
  5095. <literal>ROLE_SUPERVISOR</literal> are granted access to delete their
  5096. contacts. Behind the scenes, the
  5097. <literal>MethodSecurityInterceptor</literal> is securing the business
  5098. objects. If you're using
  5099. <literal><literal>acegi-security-sample-contacts-filter.war</literal></literal>
  5100. or <literal>acegi-security-sample-contacts-cas.war</literal>, the
  5101. <literal>FilterSecurityInterceptor</literal> is also securing the HTTP
  5102. requests. If using either of these WARs, be sure to try visiting
  5103. <literal>http://localhost:8080/contacts/secure/super</literal>, which
  5104. will demonstrate access being denied by the
  5105. <literal>FilterSecurityInterceptor</literal>. Note the sample
  5106. application enables you to modify the access control lists associated
  5107. with different contacts. Be sure to give this a try and understand how
  5108. it works by reviewing the sample application's application context XML
  5109. files.</para>
  5110. <para>The Contacts sample application also include a
  5111. <literal>client</literal> directory. Inside you will find a small
  5112. application that queries the backend business objects using several
  5113. web services protocols. This demonstrates how to use Acegi Security
  5114. for authentication with Spring remoting protocols. To try this client,
  5115. ensure your servlet container is still running the Contacts sample
  5116. application, and then execute <literal>client marissa koala</literal>.
  5117. The command-line parameters respectively represent the username to
  5118. use, and the password to use. Note that you may need to edit
  5119. <literal>client.properties</literal> to use a different target
  5120. URL.</para>
  5121. <para>Please note the sample application's <literal>client</literal>
  5122. does not currently support CAS. You can still give it a try, though,
  5123. if you're ambitious: try <literal>client _cas_stateless_
  5124. YOUR-SERVICE-TICKET-ID</literal>.</para>
  5125. </sect1>
  5126. <sect1 id="tutorial-sample">
  5127. <title>Tutorial Sample</title>
  5128. <para>Whilst the <link linkend="contacts-sample">Contacts
  5129. Sample</link> is quite advanced in that it illustrates the more
  5130. powerful features of domain object access control lists and so on,
  5131. sometimes you just want to start with a nice basic example. The
  5132. tutorial sample is intended to provide this for you.</para>
  5133. <para>The compiled tutorial is included in the distribution ZIP file,
  5134. ready to be deployed into your web container. Authentication is
  5135. handled by the <link
  5136. linkend="dao-provider">DaoAuthenticationProvider</link>, using the
  5137. <link linkend="in-memory-service">in-memory</link>
  5138. <literal>UserDetailsService</literal> that sources information from
  5139. the <literal>users.properties</literal> file located in the WAR's
  5140. <literal>/WEB-INF</literal> directory. The <link
  5141. linkend="form">form-based</link> authentication mechanism is used,
  5142. with the commonly-used <link linkend="remember-me">remember-me</link>
  5143. authentication provider used to automatically remember the login using
  5144. cookies.</para>
  5145. <para>In terms of authorization, to keep things simple we've
  5146. configured the tutorial to only perform some basic <link
  5147. linkend="filter-invocation-authorization">web filter
  5148. authorization</link>. We've wired two common <link
  5149. linkend="pre-invocation">pre-invocation access decision voters</link>,
  5150. being the <literal>RoleVoter</literal> and
  5151. <literal>AuthenticatedVoter</literal>, such that
  5152. <literal>ROLE_*</literal> configuration attributes and
  5153. <literal>IS_AUTHENTICATED_*</literal> configuration attributes may be
  5154. used. Of course, it's extremely easy to add in other providers, with
  5155. most users probably starting with some services-layer security using
  5156. <link linkend="aop-alliance">MethodSecurityInterceptor</link>.</para>
  5157. <para>We recommend you start with the tutorial sample, as the XML is
  5158. minimal and easy to follow. All of the needed <link
  5159. linkend="filters">filters</link> are configured properly, and using
  5160. best practise. Most importantly, you can easily this one XML file (and
  5161. its corresponding <literal>web.xml</literal> entries) to your existing
  5162. application. Only when this basic integration is achieved do we
  5163. suggest you attempt adding in method authorization or domain object
  5164. security.</para>
  5165. </sect1>
  5166. </chapter>
  5167. <chapter id="community">
  5168. <title>Community Support</title>
  5169. <sect1 id="jira">
  5170. <title>Use JIRA for Issue Tracking</title>
  5171. <para>Acegi Security uses JIRA to manage bug reports and enhancement
  5172. requests. If you find a bug, please log a report using JIRA. Do not
  5173. log it on the support forum, mailing list or by emailing the project's
  5174. developers. Such approaches are ad-hoc and we prefer to manage bugs
  5175. using a more formal process.</para>
  5176. <para>If possible, in your JIRA report please provide a JUnit test
  5177. that demonstrates any incorrect behaviour. Or, better yet, provide a
  5178. patch that corrects the issue. Similarly, enhancements are welcome to
  5179. be logged in JIRA, although we only accept commit enhancement requests
  5180. if you include corresponding unit tests. This is necessary to ensure
  5181. project test coverage is adequately maintained.</para>
  5182. <para>You can access JIRA at <ulink
  5183. url="http://opensource.atlassian.com/projects/spring/secure/BrowseProject.jspa?id=10040"></ulink>.</para>
  5184. </sect1>
  5185. <sect1 id="becoming-involved">
  5186. <title>Becoming Involved</title>
  5187. <para>We welcome you to become involved in Acegi Security project.
  5188. There are many ways of contributing, including reading the mailing
  5189. list and responding to questions from other people, writing new code,
  5190. improving existing code, assisting with documentation, developing
  5191. samples or tutorials, or simply making suggestions.</para>
  5192. <para>Please read our project policies web page that is available on
  5193. Acegi Security home page. This explains the path to become a
  5194. committer, and the administration approaches we use within the
  5195. project.</para>
  5196. </sect1>
  5197. <sect1 id="further-info">
  5198. <title>Further Information</title>
  5199. <para>Questions and comments on Acegi Security are welcome. Please use
  5200. the Spring Community Forum web site at <ulink
  5201. url="http://forum.springframework.org"></ulink> for all support
  5202. issues. Remember to use JIRA for bug reports, as explained above.
  5203. Everyone is also welcome to join the Acegisecurity-developer mailing
  5204. list and participate in design discussions. It's also a good way of
  5205. finding out what's happening with regard to release timing, and the
  5206. traffic volume is quite light. Finally, our project home page (where
  5207. you can obtain the latest release of the project and convenient links
  5208. to Subversion, JIRA, mailing lists, forums etc) is at <ulink
  5209. url="http://acegisecurity.org"></ulink>.</para>
  5210. </sect1>
  5211. </chapter>
  5212. </part>
  5213. </book>