acegi.xml 314 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060
  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.sf.net/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 HTTP Request Security Filter&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>) that can
  1855. be used to process requests that have been pre-authenticated by
  1856. Siteminder. This filter assumes that you're using Siteminder for
  1857. <emphasis>authentication</emphasis>, and that you're using Acegi
  1858. Security for <emphasis>authorization</emphasis>. The use of Siteminder
  1859. for <emphasis>authorization</emphasis> is not yet directly supported
  1860. by Acegi Security.</para>
  1861. <para>In Siteminder, an agent is setup on your web server to intercept
  1862. a principal's first call to your application. The agent redirect the
  1863. web request to a single sign on login page, and then your application
  1864. receives the request. Inside the HTTP headers is a header - such as
  1865. <literal>SM_USER</literal> - which identifies the authenticated
  1866. principal. Please refer to your organization's "single sign-on" group
  1867. for header details in your particular configuration.</para>
  1868. </sect1>
  1869. <sect1 id="siteminder-config">
  1870. <title>Configuration</title>
  1871. <para>The first step in setting up Acegi Security's Siteminder support
  1872. is to define the authentication mechanism that will inspect the HTTP
  1873. header discussed earlier. It will then generate a
  1874. <literal>UsernamePasswordAuthenticationToken</literal> that can later
  1875. on be sent to the <literal>DaoAuthenticationProvider</literal>. Let's
  1876. look at an example:</para>
  1877. <para><programlisting>&lt;bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.SiteminderAuthenticationProcessingFilter"&gt;
  1878. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  1879. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/login.jsp?login_error=1&lt;/value&gt;&lt;/property&gt;
  1880. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/security.do?method=getMainMenu&lt;/value&gt;&lt;/property&gt;
  1881. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_security_check&lt;/value&gt;&lt;/property&gt;
  1882. &lt;property name="siteminderUsernameHeaderKey"&gt;&lt;value&gt;SM_USER&lt;/value&gt;&lt;/property&gt;
  1883. &lt;property name="siteminderPasswordHeaderKey"&gt;&lt;value&gt;SM_USER&lt;/value&gt;&lt;/property&gt;
  1884. &lt;/bean&gt;</programlisting></para>
  1885. <para>In our example above, the bean is being provided an
  1886. <literal>AuthenticationManager</literal>, as is normally needed by
  1887. authentication mechanisms. Several URLs are also specified, with the
  1888. values being self-explanatory. It's important to also specify the HTTP
  1889. headers that Acegi Security should inspect. Most people won't need the
  1890. password value since Siteminder has already authenticated the user, so
  1891. it's typical to use the same header for both.</para>
  1892. <para>Note that you'll need a
  1893. <literal><literal>DaoAuthenticationProvider</literal></literal>
  1894. configured against your <literal>ProviderManager</literal> in order to
  1895. use the Siteminder authentication mechanism. Normally a
  1896. <literal>DaoAuthenticationProvider</literal> expects the password
  1897. property to match what it retrieves from the
  1898. <literal>UserDetailsSource</literal>. In this case, authentication has
  1899. already been handled by Siteminder and you've specified the same HTTP
  1900. header for both username and password. As such, you must modify the
  1901. code of <literal>DaoAuthenticationProvider</literal> to simply make
  1902. sure the username and password values match. This may sound like a
  1903. security weakness, but remember that users have to authenticate with
  1904. Siteminder before your application ever receives the requests, so the
  1905. purpose of your custom <literal>DaoAuthenticationProvider</literal>
  1906. should simply be to build the complete
  1907. <literal>Authentication</literal> object (ie with suitable
  1908. <literal>GrantedAuthority[]</literal>s).</para>
  1909. <para>Advanced tip and word to the wise: the
  1910. <literal>SiteminderAuthenticationProcessingFilter</literal> actually
  1911. extends <literal>AuthenticationProcessingFilter</literal> and thus
  1912. additionally supports form validation. If you configure the filter to
  1913. support both, and code your
  1914. <literal>daoAuthenticationProvider</literal> to match the username and
  1915. passwords as described above, you'll potentially defeat any security
  1916. you have in place if the web server's Siteminder agent is deactivated.
  1917. Don't do this, especially in production!</para>
  1918. <para>TODO: We should write a dedicated
  1919. <literal>AuthenticationProvider</literal> rather than require users to
  1920. modify their <literal>DaoAuthenticationProvider</literal>. Also review
  1921. the mixed use of SiteminderAuthenticationProcessingFilter, as it's
  1922. inconsistent with the rest of Acegi Security's authentication
  1923. mechanisms which are high cohesion.</para>
  1924. </sect1>
  1925. </chapter>
  1926. <chapter id="runas">
  1927. <title>Run-As Authentication Replacement</title>
  1928. <sect1 id="runas-overview">
  1929. <title>Overview</title>
  1930. <para>The <literal>AbstractSecurityInterceptor</literal> is able to
  1931. temporarily replace the <literal>Authentication</literal> object in
  1932. the <literal>SecurityContext</literal> and
  1933. <literal>SecurityContextHolder</literal> during the secure object
  1934. callback phase. This only occurs if the original
  1935. <literal>Authentication</literal> object was successfully processed by
  1936. the <literal>AuthenticationManager</literal> and
  1937. <literal>AccessDecisionManager</literal>. The
  1938. <literal>RunAsManager</literal> will indicate the replacement
  1939. <literal>Authentication</literal> object, if any, that should be used
  1940. during the <literal>SecurityInterceptorCallback</literal>.</para>
  1941. <para>By temporarily replacing the <literal>Authentication</literal>
  1942. object during the secure object callback phase, the secured invocation
  1943. will be able to call other objects which require different
  1944. authentication and authorization credentials. It will also be able to
  1945. perform any internal security checks for specific
  1946. <literal>GrantedAuthority</literal> objects. Because Acegi Security
  1947. provides a number of helper classes that automatically configure
  1948. remoting protocols based on the contents of the
  1949. <literal>SecurityContextHolder</literal>, these run-as replacements
  1950. are particularly useful when calling remote web services</para>
  1951. </sect1>
  1952. <sect1 id="runas-config">
  1953. <title>Configuration</title>
  1954. <para>A <literal>RunAsManager</literal> interface is provided by Acegi
  1955. Security:</para>
  1956. <para><programlisting>public Authentication buildRunAs(Authentication authentication, Object object, ConfigAttributeDefinition config);
  1957. public boolean supports(ConfigAttribute attribute);
  1958. public boolean supports(Class clazz);</programlisting></para>
  1959. <para>The first method returns the <literal>Authentication</literal>
  1960. object that should replace the existing
  1961. <literal>Authentication</literal> object for the duration of the
  1962. method invocation. If the method returns <literal>null</literal>, it
  1963. indicates no replacement should be made. The second method is used by
  1964. the <literal>AbstractSecurityInterceptor</literal> as part of its
  1965. startup validation of configuration attributes. The
  1966. <literal>supports(Class)</literal> method is called by a security
  1967. interceptor implementation to ensure the configured
  1968. <literal>RunAsManager</literal> supports the type of secure object
  1969. that the security interceptor will present.</para>
  1970. <para>One concrete implementation of a <literal>RunAsManager</literal>
  1971. is provided with Acegi Security. The
  1972. <literal>RunAsManagerImpl</literal> class returns a replacement
  1973. <literal>RunAsUserToken</literal> if any
  1974. <literal>ConfigAttribute</literal> starts with
  1975. <literal>RUN_AS_</literal>. If any such
  1976. <literal>ConfigAttribute</literal> is found, the replacement
  1977. <literal>RunAsUserToken</literal> will contain the same principal,
  1978. credentials and granted authorities as the original
  1979. <literal>Authentication</literal> object, along with a new
  1980. <literal>GrantedAuthorityImpl</literal> for each
  1981. <literal>RUN_AS_</literal> <literal>ConfigAttribute</literal>. Each
  1982. new <literal>GrantedAuthorityImpl</literal> will be prefixed with
  1983. <literal>ROLE_</literal>, followed by the <literal>RUN_AS</literal>
  1984. <literal>ConfigAttribute</literal>. For example, a
  1985. <literal>RUN_AS_SERVER</literal> will result in the replacement
  1986. <literal>RunAsUserToken</literal> containing a
  1987. <literal>ROLE_RUN_AS_SERVER</literal> granted authority.</para>
  1988. <para>The replacement <literal>RunAsUserToken</literal> is just like
  1989. any other <literal>Authentication</literal> object. It needs to be
  1990. authenticated by the <literal>AuthenticationManager</literal>,
  1991. probably via delegation to a suitable
  1992. <literal>AuthenticationProvider</literal>. The
  1993. <literal>RunAsImplAuthenticationProvider</literal> performs such
  1994. authentication. It simply accepts as valid any
  1995. <literal>RunAsUserToken</literal> presented.</para>
  1996. <para>To ensure malicious code does not create a
  1997. <literal>RunAsUserToken</literal> and present it for guaranteed
  1998. acceptance by the <literal>RunAsImplAuthenticationProvider</literal>,
  1999. the hash of a key is stored in all generated tokens. The
  2000. <literal>RunAsManagerImpl</literal> and
  2001. <literal>RunAsImplAuthenticationProvider</literal> is created in the
  2002. bean context with the same key:</para>
  2003. <para><programlisting>
  2004. &lt;bean id="runAsManager" class="org.acegisecurity.runas.RunAsManagerImpl"&gt;
  2005. &lt;property name="key"&gt;&lt;value&gt;my_run_as_password&lt;/value&gt;&lt;/property&gt;
  2006. &lt;/bean&gt;
  2007. &lt;bean id="runAsAuthenticationProvider" class="org.acegisecurity.runas.RunAsImplAuthenticationProvider"&gt;
  2008. &lt;property name="key"&gt;&lt;value&gt;my_run_as_password&lt;/value&gt;&lt;/property&gt;
  2009. &lt;/bean&gt;
  2010. </programlisting></para>
  2011. <para>By using the same key, each <literal>RunAsUserToken</literal>
  2012. can be validated it was created by an approved
  2013. <literal>RunAsManagerImpl</literal>. The
  2014. <literal>RunAsUserToken</literal> is immutable after creation for
  2015. security reasons</para>
  2016. </sect1>
  2017. </chapter>
  2018. <chapter id="form">
  2019. <title>Form Authentication Mechanism</title>
  2020. <sect1 id="form-overview">
  2021. <title>Overview</title>
  2022. <para>HTTP Form Authentication involves using the
  2023. <literal>AuthenticationProcessingFilter</literal> to process a login
  2024. form. This is the most common way that application authenticate end
  2025. users. Form-based authentication is entirely compatible with the DAO
  2026. and JAAS authentication providers.</para>
  2027. </sect1>
  2028. <sect1 id="form-config">
  2029. <title>Configuration</title>
  2030. <para>The login form simply contains <literal>j_username</literal> and
  2031. <literal>j_password</literal> input fields, and posts to a URL that is
  2032. monitored by the filter (by default
  2033. <literal>j_acegi_security_check</literal>). The filter is defined in
  2034. <literal>web.xml</literal> behind a
  2035. <literal>FilterToBeanProxy</literal> as follows:</para>
  2036. <para><programlisting>&lt;filter&gt;
  2037. &lt;filter-name&gt;Acegi Authentication Processing Filter&lt;/filter-name&gt;
  2038. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  2039. &lt;init-param&gt;
  2040. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  2041. &lt;param-value&gt;org.acegisecurity.ui.webapp.AuthenticationProcessingFilter&lt;/param-value&gt;
  2042. &lt;/init-param&gt;
  2043. &lt;/filter&gt;
  2044. &lt;filter-mapping&gt;
  2045. &lt;filter-name&gt;Acegi Authentication Processing Filter&lt;/filter-name&gt;
  2046. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  2047. &lt;/filter-mapping&gt;</programlisting></para>
  2048. <para>For a discussion of <literal>FilterToBeanProxy</literal>, please
  2049. refer to the Filters section. The application context will need to
  2050. define the <literal>AuthenticationProcessingFilter</literal>:</para>
  2051. <para><programlisting>&lt;bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"&gt;
  2052. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2053. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/acegilogin.jsp?login_error=1&lt;/value&gt;&lt;/property&gt;
  2054. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;
  2055. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_security_check&lt;/value&gt;&lt;/property&gt;
  2056. &lt;/bean&gt; </programlisting></para>
  2057. <para>The configured <literal>AuthenticationManager</literal>
  2058. processes each authentication request. If authentication fails, the
  2059. browser will be redirected to the
  2060. <literal>authenticationFailureUrl</literal>. The
  2061. <literal>AuthenticationException</literal> will be placed into the
  2062. <literal>HttpSession</literal> attribute indicated by
  2063. <literal>AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY</literal>,
  2064. enabling a reason to be provided to the user on the error page.</para>
  2065. <para>If authentication is successful, the resulting
  2066. <literal>Authentication</literal> object will be placed into the
  2067. <literal>SecurityContextHolder</literal>.</para>
  2068. <para>Once the <literal>SecurityContextHolder</literal> has been
  2069. updated, the browser will need to be redirected to the target URL. The
  2070. target URL is usually indicated by the <literal>HttpSession</literal>
  2071. attribute specified by
  2072. <literal>AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL_KEY</literal>.
  2073. This attribute is automatically set by the
  2074. <literal>ExceptionTranslationFilter</literal> when an
  2075. <literal>AuthenticationException</literal> occurs, so that after login
  2076. is completed the user can return to what they were trying to access.
  2077. If for some reason the <literal>HttpSession</literal> does not
  2078. indicate the target URL, the browser will be redirected to the
  2079. <literal>defaultTargetUrl</literal> property.</para>
  2080. </sect1>
  2081. </chapter>
  2082. <chapter id="basic">
  2083. <title>BASIC Authentication Mechanism</title>
  2084. <sect1 id="basic-overview">
  2085. <title>Overview</title>
  2086. <para>Acegi Security provides a
  2087. <literal>BasicProcessingFilter</literal> which is capable of
  2088. processing basic authentication credentials presented in HTTP headers.
  2089. This can be used for authenticating calls made by Spring remoting
  2090. protocols (such as Hessian and Burlap), as well as normal user agents
  2091. (such as Internet Explorer and Navigator). The standard governing HTTP
  2092. Basic Authentication is defined by RFC 1945, Section 11, and the
  2093. <literal>BasicProcessingFilter</literal> conforms with this RFC. Basic
  2094. Authentication is an attractive approach to authentication, because it
  2095. is very widely deployed in user agents and implementation is extremely
  2096. simple (it's just a Base64 encoding of the username:password,
  2097. specified in a HTTP header).</para>
  2098. </sect1>
  2099. <sect1 id="basic-config">
  2100. <title>Configuration</title>
  2101. <para>To implement HTTP Basic Authentication, it is necessary to
  2102. define <literal>BasicProcessingFilter</literal> in the filter chain.
  2103. The application context will need to define the
  2104. <literal>BasicProcessingFilter</literal> and its required
  2105. collaborator:</para>
  2106. <para><programlisting>
  2107. &lt;bean id="basicProcessingFilter" class="org.acegisecurity.ui.basicauth.BasicProcessingFilter"&gt;
  2108. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2109. &lt;property name="authenticationEntryPoint"&gt;&lt;ref bean="authenticationEntryPoint"/&gt;&lt;/property&gt;
  2110. &lt;/bean&gt;
  2111. &lt;bean id="authenticationEntryPoint" class="org.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint"&gt;
  2112. &lt;property name="realmName"&gt;&lt;value&gt;Name Of Your Realm&lt;/value&gt;&lt;/property&gt;
  2113. &lt;/bean&gt;
  2114. </programlisting></para>
  2115. <para>The configured <literal>AuthenticationManager</literal>
  2116. processes each authentication request. If authentication fails, the
  2117. configured <literal>AuthenticationEntryPoint</literal> will be used to
  2118. retry the authentication process. Usually you will use the
  2119. <literal>BasicProcessingFilterEntryPoint</literal>, which returns a
  2120. 401 response with a suitable header to retry HTTP Basic
  2121. authentication. If authentication is successful, the resulting
  2122. <literal>Authentication</literal> object will be placed into the
  2123. <literal>SecurityContextHolder</literal>.</para>
  2124. <para>If the authentication event was successful, or authentication
  2125. was not attempted because the HTTP header did not contain a supported
  2126. authentication request, the filter chain will continue as normal. The
  2127. only time the filter chain will be interrupted is if authentication
  2128. fails and the <literal>AuthenticationEntryPoint</literal> is called,
  2129. as discussed in the previous paragraph</para>
  2130. </sect1>
  2131. </chapter>
  2132. <chapter id="digest">
  2133. <title>Digest Authentication</title>
  2134. <sect1 id="digest-overview">
  2135. <title>Overview</title>
  2136. <para>Acegi Security provides a
  2137. <literal>DigestProcessingFilter</literal> which is capable of
  2138. processing digest authentication credentials presented in HTTP
  2139. headers. Digest Authentication attempts to solve many of the
  2140. weaknesses of Basic authentication, specifically by ensuring
  2141. credentials are never sent in clear text across the wire. Many user
  2142. agents support Digest Authentication, including FireFox and Internet
  2143. Explorer. The standard governing HTTP Digest Authentication is defined
  2144. by RFC 2617, which updates an earlier version of the Digest
  2145. Authentication standard prescribed by RFC 2069. Most user agents
  2146. implement RFC 2617. Acegi Security
  2147. <literal>DigestProcessingFilter</literal> is compatible with the
  2148. "<literal>auth</literal>" quality of protection
  2149. (<literal>qop</literal>) prescribed by RFC 2617, which also provides
  2150. backward compatibility with RFC 2069. Digest Authentication is a
  2151. highly attractive option if you need to use unencrypted HTTP (ie no
  2152. TLS/HTTPS) and wish to maximise security of the authentication
  2153. process. Indeed Digest Authentication is a mandatory requirement for
  2154. the WebDAV protocol, as noted by RFC 2518 Section 17.1, so we should
  2155. expect to see it increasingly deployed and replacing Basic
  2156. Authentication.</para>
  2157. <para>Digest Authentication is definitely the most secure choice
  2158. between Form Authentication, Basic Authentication and Digest
  2159. Authentication, although extra security also means more complex user
  2160. agent implementations. Central to Digest Authentication is a "nonce".
  2161. This is a value the server generates. Acegi Security's nonce adopts
  2162. the following format:</para>
  2163. <para><programlisting>base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key))
  2164. expirationTime: The date and time when the nonce expires, expressed in milliseconds
  2165. key: A private key to prevent modification of the nonce token
  2166. </programlisting></para>
  2167. <para>The <literal>DigestProcessingFilterEntryPoint</literal> has a
  2168. property specifying the <literal>key</literal> used for generating the
  2169. nonce tokens, along with a <literal>nonceValiditySeconds</literal>
  2170. property for determining the expiration time (default 300, which
  2171. equals five minutes). Whist ever the nonce is valid, the digest is
  2172. computed by concatenating various strings including the username,
  2173. password, nonce, URI being requested, a client-generated nonce (merely
  2174. a random value which the user agent generates each request), the realm
  2175. name etc, then performing an MD5 hash. Both the server and user agent
  2176. perform this digest computation, resulting in different hash codes if
  2177. they disagree on an included value (eg password). In Acegi Security
  2178. implementation, if the server-generated nonce has merely expired (but
  2179. the digest was otherwise valid), the
  2180. <literal>DigestProcessingFilterEntryPoint</literal> will send a
  2181. <literal>"stale=true"</literal> header. This tells the user agent
  2182. there is no need to disturb the user (as the password and username etc
  2183. is correct), but simply to try again using a new nonce.</para>
  2184. <para>An appropriate value for
  2185. <literal>DigestProcessingFilterEntryPoint</literal>'s
  2186. <literal>nonceValiditySeconds</literal> parameter will depend on your
  2187. application. Extremely secure applications should note that an
  2188. intercepted authentication header can be used to impersonate the
  2189. principal until the <literal>expirationTime</literal> contained in the
  2190. nonce is reached. This is the key principle when selecting an
  2191. appropriate setting, but it would be unusual for immensely secure
  2192. applications to not be running over TLS/HTTPS in the first
  2193. instance.</para>
  2194. <para>Because of the more complex implementation of Digest
  2195. Authentication, there are often user agent issues. For example,
  2196. Internet Explorer fails to present an "<literal>opaque</literal>"
  2197. token on subsequent requests in the same session. Acegi Security
  2198. filters therefore encapsulate all state information into the
  2199. "<literal>nonce</literal>" token instead. In our testing, Acegi
  2200. Security implementation works reliably with FireFox and Internet
  2201. Explorer, correctly handling nonce timeouts etc.</para>
  2202. </sect1>
  2203. <sect1 id="digest-config">
  2204. <title>Configuration</title>
  2205. <para>Now that we've reviewed the theory, let's see how to use it. To
  2206. implement HTTP Digest Authentication, it is necessary to define
  2207. <literal>DigestProcessingFilter</literal> in the fitler chain. The
  2208. application context will need to define the
  2209. <literal>DigestProcessingFilter</literal> and its required
  2210. collaborators:</para>
  2211. <para><programlisting>
  2212. &lt;bean id="digestProcessingFilter" class="org.acegisecurity.ui.digestauth.DigestProcessingFilter"&gt;
  2213. &lt;property name="userDetailsService"&gt;&lt;ref local="jdbcDaoImpl"/&gt;&lt;/property&gt;
  2214. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="digestProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  2215. &lt;property name="userCache"&gt;&lt;ref local="userCache"/&gt;&lt;/property&gt;
  2216. &lt;/bean&gt;
  2217. &lt;bean id="digestProcessingFilterEntryPoint" class="org.acegisecurity.ui.digestauth.DigestProcessingFilterEntryPoint"&gt;
  2218. &lt;property name="realmName"&gt;&lt;value&gt;Contacts Realm via Digest Authentication&lt;/value&gt;&lt;/property&gt;
  2219. &lt;property name="key"&gt;&lt;value&gt;acegi&lt;/value&gt;&lt;/property&gt;
  2220. &lt;property name="nonceValiditySeconds"&gt;&lt;value&gt;10&lt;/value&gt;&lt;/property&gt;
  2221. &lt;/bean&gt;
  2222. </programlisting></para>
  2223. <para>The configured <literal>UserDetailsService</literal> is needed
  2224. because <literal>DigestProcessingFilter</literal> must have direct
  2225. access to the clear text password of a user. Digest Authentication
  2226. will NOT work if you are using encoded passwords in your DAO. The DAO
  2227. collaborator, along with the <literal>UserCache</literal>, are
  2228. typically shared directly with a
  2229. <literal>DaoAuthenticationProvider</literal>. The
  2230. <literal>authenticationEntryPoint</literal> property must be
  2231. <literal>DigestProcessingFilterEntryPoint</literal>, so that
  2232. <literal>DigestProcessingFilter</literal> can obtain the correct
  2233. <literal>realmName</literal> and <literal>key</literal> for digest
  2234. calculations.</para>
  2235. <para>Like <literal>BasicAuthenticationFilter</literal>, if
  2236. authentication is successful an <literal>Authentication</literal>
  2237. request token will be placed into the
  2238. <literal>SecurityContextHolder</literal>. If the authentication event
  2239. was successful, or authentication was not attempted because the HTTP
  2240. header did not contain a Digest Authentication request, the filter
  2241. chain will continue as normal. The only time the filter chain will be
  2242. interrupted is if authentication fails and the
  2243. <literal>AuthenticationEntryPoint</literal> is called, as discussed in
  2244. the previous paragraph.</para>
  2245. <para>Digest Authentication's RFC offers a range of additional
  2246. features to further increase security. For example, the nonce can be
  2247. changed on every request. Despite this, Acegi Security implementation
  2248. was designed to minimise the complexity of the implementation (and the
  2249. doubtless user agent incompatibilities that would emerge), and avoid
  2250. needing to store server-side state. You are invited to review RFC 2617
  2251. if you wish to explore these features in more detail. As far as we are
  2252. aware, Acegi Security implementation does comply with the minimum
  2253. standards of this RFC.</para>
  2254. </sect1>
  2255. </chapter>
  2256. <chapter id="anonymous">
  2257. <title>Anonymous Authentication</title>
  2258. <sect1 id="anonymous-overview">
  2259. <title>Overview</title>
  2260. <para>Particularly in the case of web request URI security, sometimes
  2261. it is more convenient to assign configuration attributes against every
  2262. possible secure object invocation. Put differently, sometimes it is
  2263. nice to say <literal>ROLE_SOMETHING</literal> is required by default
  2264. and only allow certain exceptions to this rule, such as for login,
  2265. logout and home pages of an application. There are also other
  2266. situations where anonymous authentication would be desired, such as
  2267. when an auditing interceptor queries the
  2268. <literal>SecurityContextHolder</literal> to identify which principal
  2269. was responsible for a given operation. Such classes can be authored
  2270. with more robustness if they know the
  2271. <literal>SecurityContextHolder</literal> always contains an
  2272. <literal>Authentication</literal> object, and never
  2273. <literal>null</literal>.</para>
  2274. </sect1>
  2275. <sect1 id="anonymous-config">
  2276. <title>Configuration</title>
  2277. <para>Acegi Security provides three classes that together provide an
  2278. anonymous authentication feature.
  2279. <literal>AnonymousAuthenticationToken</literal> is an implementation
  2280. of <literal>Authentication</literal>, and stores the
  2281. <literal>GrantedAuthority</literal>[]s which apply to the anonymous
  2282. principal. There is a corresponding
  2283. <literal>AnonymousAuthenticationProvider</literal>, which is chained
  2284. into the <literal>ProviderManager</literal> so that
  2285. <literal>AnonymousAuthenticationTokens</literal> are accepted.
  2286. Finally, there is an AnonymousProcessingFilter, which is chained after
  2287. the normal authentication mechanisms and automatically add an
  2288. <literal>AnonymousAuthenticationToken</literal> to the
  2289. <literal>SecurityContextHolder</literal> if there is no existing
  2290. <literal>Authentication</literal> held there. The definition of the
  2291. filter and authentication provider appears as follows:</para>
  2292. <para><programlisting>
  2293. &lt;bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter"&gt;
  2294. &lt;property name="key"&gt;&lt;value&gt;foobar&lt;/value&gt;&lt;/property&gt;
  2295. &lt;property name="userAttribute"&gt;&lt;value&gt;anonymousUser,ROLE_ANONYMOUS&lt;/value&gt;&lt;/property&gt;
  2296. &lt;/bean&gt;
  2297. &lt;bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider"&gt;
  2298. &lt;property name="key"&gt;&lt;value&gt;foobar&lt;/value&gt;&lt;/property&gt;
  2299. &lt;/bean&gt;
  2300. </programlisting></para>
  2301. <para>The <literal>key</literal> is shared between the filter and
  2302. authentication provider, so that tokens created by the former are
  2303. accepted by the latter. The <literal>userAttribute</literal> is
  2304. expressed in the form of
  2305. <literal>usernameInTheAuthenticationToken,grantedAuthority[,grantedAuthority]</literal>.
  2306. This is the same syntax as used after the equals sign for
  2307. <literal>InMemoryDaoImpl</literal>'s <literal>userMap</literal>
  2308. property.</para>
  2309. <para>As explained earlier, the benefit of anonymous authentication is
  2310. that all URI patterns can have security applied to them. For
  2311. example:</para>
  2312. <para><programlisting>
  2313. &lt;bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  2314. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  2315. &lt;property name="accessDecisionManager"&gt;&lt;ref local="httpRequestAccessDecisionManager"/&gt;&lt;/property&gt;
  2316. &lt;property name="objectDefinitionSource"&gt;
  2317. &lt;value&gt;
  2318. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  2319. PATTERN_TYPE_APACHE_ANT
  2320. /index.jsp=ROLE_ANONYMOUS,ROLE_USER
  2321. /hello.htm=ROLE_ANONYMOUS,ROLE_USER
  2322. /logoff.jsp=ROLE_ANONYMOUS,ROLE_USER
  2323. /acegilogin.jsp*=ROLE_ANONYMOUS,ROLE_USER
  2324. /**=ROLE_USER
  2325. &lt;/value&gt;
  2326. &lt;/property&gt;
  2327. &lt;/bean&gt;
  2328. </programlisting>Rounding out the anonymous authentication discussion
  2329. is the <literal>AuthenticationTrustResolver</literal> interface, with
  2330. its corresponding <literal>AuthenticationTrustResolverImpl</literal>
  2331. implementation. This interface provides an
  2332. <literal>isAnonymous(Authentication)</literal> method, which allows
  2333. interested classes to take into account this special type of
  2334. authentication status. The
  2335. <literal>ExceptionTranslationFilter</literal> uses this interface in
  2336. processing <literal>AccessDeniedException</literal>s. If an
  2337. <literal>AccessDeniedException</literal> is thrown, and the
  2338. authentication is of an anonymous type, instead of throwing a 403
  2339. (forbidden) response, the filter will instead commence the
  2340. <literal>AuthenticationEntryPoint</literal> so the principal can
  2341. authenticate properly. This is a necessary distinction, otherwise
  2342. principals would always be deemed "authenticated" and never be given
  2343. an opportunity to login via form, basic, digest or some other normal
  2344. authentication mechanism</para>
  2345. </sect1>
  2346. </chapter>
  2347. <chapter id="remember-me">
  2348. <title>Remember-Me Authentication</title>
  2349. <sect1 id="remember-me-overview">
  2350. <title>Overview</title>
  2351. <para>Remember-me authentication refers to web sites being able to
  2352. remember the identity of a principal between sessions. This is
  2353. typically accomplished by sending a cookie to the browser, with the
  2354. cookie being detected during future sessions and causing automated
  2355. login to take place. Acegi Security provides the necessary hooks so
  2356. that such operations can take place, along with providing a concrete
  2357. implementation that uses hashing to preserve the security of
  2358. cookie-based tokens.</para>
  2359. </sect1>
  2360. <sect1 id="remember-me-config">
  2361. <title>Configuration</title>
  2362. <para>Remember-me authentication is not used with basic
  2363. authentication, given it is often not used with
  2364. <literal>HttpSession</literal>s. Remember-me is used with
  2365. <literal>AuthenticationProcessingFilter</literal>, and is implemented
  2366. via hooks in the <literal>AbstractProcessingFilter</literal>
  2367. superclass. The hooks will invoke a concrete
  2368. <literal>RememberMeServices</literal> at the appropriate times. The
  2369. interface looks like this:</para>
  2370. <para><programlisting>public Authentication autoLogin(HttpServletRequest request, HttpServletResponse response);
  2371. public void loginFail(HttpServletRequest request, HttpServletResponse response);
  2372. public void loginSuccess(HttpServletRequest request, HttpServletResponse response, Authentication successfulAuthentication);</programlisting></para>
  2373. <para>Please refer to JavaDocs for a fuller discussion on what the
  2374. methods do, although note at this stage
  2375. <literal>AbstractProcessingFilter</literal> only calls the
  2376. <literal>loginFail()</literal> and <literal>loginSuccess()</literal>
  2377. methods. The <literal>autoLogin()</literal> method is called by
  2378. <literal>RememberMeProcessingFilter</literal> whenever the
  2379. <literal>SecurityContextHolder</literal> does not contain an
  2380. <literal>Authentication</literal>. This interface therefore provides
  2381. the underlaying remember-me implementation with sufficient
  2382. notification of authentication-related events, and delegates to the
  2383. implementation whenever a candidate web request might contain a cookie
  2384. and wish to be remembered.</para>
  2385. <para>This design allows any number of remember-me implementation
  2386. strategies. In the interests of simplicity and avoiding the need for
  2387. DAO implementations that specify write and create methods, Acegi
  2388. Security's only concrete implementation,
  2389. <literal>TokenBasedRememberMeServices</literal>, uses hashing to
  2390. achieve a useful remember-me strategy. In essence a cookie is sent to
  2391. the browser upon successful interactive authentication, with that
  2392. cookie being composed as follows:</para>
  2393. <para><programlisting>base64(username + ":" + expirationTime + ":" + md5Hex(username + ":" + expirationTime + ":" password + ":" + key))
  2394. username: As identifiable to TokenBasedRememberMeServices.getUserDetailsService()
  2395. password: That matches the relevant UserDetails retrieved from TokenBasedRememberMeServices.getUserDetailsService()
  2396. expirationTime: The date and time when the remember-me token expires, expressed in milliseconds
  2397. key: A private key to prevent modification of the remember-me token
  2398. </programlisting></para>
  2399. <para>As such the remember-me token is valid only for the period
  2400. specified, and provided that the username, password and key does not
  2401. change. Notably, this has a potential security issue in that a
  2402. captured remember-me token will be usable from any user agent until
  2403. such time as the token expires. This is the same issue as with digest
  2404. authentication. If a principal is aware a token has been captured,
  2405. they can easily change their password and immediately invalidate all
  2406. remember-me tokens on issue. However, if more significant security is
  2407. needed a rolling token approach should be used (this would require a
  2408. database) or remember-me services should simply not be used.</para>
  2409. <para><literal>TokenBasedRememberMeServices</literal> generates a
  2410. <literal>RememberMeAuthenticationToken</literal>, which is processed
  2411. by <literal>RememberMeAuthenticationProvider</literal>. A
  2412. <literal>key</literal> is shared between this authentication provider
  2413. and the <literal>TokenBasedRememberMeServices</literal>. In addition,
  2414. <literal>TokenBasedRememberMeServices</literal> requires A
  2415. UserDetailsService from which it can retrieve the username and
  2416. password for signature comparison purposes, and generate the
  2417. <literal>RememberMeAuthenticationToken</literal> to contain the
  2418. correct <literal>GrantedAuthority</literal>[]s. Some sort of logout
  2419. command should be provided by the application (typically via a JSP)
  2420. that invalidates the cookie upon user request. See the Contacts Sample
  2421. application's <literal>logout.jsp</literal> for an example.</para>
  2422. <para>The beans required in an application context to enable
  2423. remember-me services are as follows:</para>
  2424. <para><programlisting>
  2425. &lt;bean id="rememberMeProcessingFilter" class="org.acegisecurity.ui.rememberme.RememberMeProcessingFilter"&gt;
  2426. &lt;property name="rememberMeServices"&gt;&lt;ref local="rememberMeServices"/&gt;&lt;/property&gt;
  2427. &lt;/bean&gt;
  2428. &lt;bean id="rememberMeServices" class="org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices"&gt;
  2429. &lt;property name="userDetailsService"&gt;&lt;ref local="jdbcDaoImpl"/&gt;&lt;/property&gt;
  2430. &lt;property name="key"&gt;&lt;value&gt;springRocks&lt;/value&gt;&lt;/property&gt;
  2431. &lt;/bean&gt;
  2432. &lt;bean id="rememberMeAuthenticationProvider" class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider"&gt;
  2433. &lt;property name="key"&gt;&lt;value&gt;springRocks&lt;/value&gt;&lt;/property&gt;
  2434. &lt;/bean&gt;
  2435. </programlisting>Don't forget to add your
  2436. <literal>RememberMeServices</literal> implementation to your
  2437. <literal>AuthenticationProcessingFilter.setRememberMeServices()</literal>
  2438. property, include the
  2439. <literal>RememberMeAuthenticationProvider</literal> in your
  2440. <literal>AuthenticationManager.setProviders()</literal> list, and add
  2441. a call to <literal>RememberMeProcessingFilter</literal> into your
  2442. <literal>FilterChainProxy</literal> (typically immediately after your
  2443. <literal>AuthenticationProcessingFilter</literal>)</para>
  2444. </sect1>
  2445. </chapter>
  2446. <chapter id="x509">
  2447. <title>X509 Authentication</title>
  2448. <sect1 id="x509-overview">
  2449. <title>Overview</title>
  2450. <para>The most common use of X509 certificate authentication is in
  2451. verifying the identity of a server when using SSL, most commonly when
  2452. using HTTPS from a browser. The browser will automatically check that
  2453. the certificate presented by a server has been issued (ie digitally
  2454. signed) by one of a list of trusted certificate authorities which it
  2455. maintains.</para>
  2456. <para>You can also use SSL with <quote>mutual authentication</quote>;
  2457. the server will then request a valid certificate from the client as
  2458. part of the SSL handshake. The server will authenticate the client by
  2459. checking that it's certificate is signed by an acceptable authority.
  2460. If a valid certificate has been provided, it can be obtained through
  2461. the servlet API in an application. Acegi Security X509 module extracts
  2462. the certificate using a filter and passes it to the configured X509
  2463. authentication provider to allow any additional application-specific
  2464. checks to be applied. It also maps the certificate to an application
  2465. user and loads that user's set of granted authorities for use with the
  2466. standard Acegi Security infrastructure.</para>
  2467. <para>You should be familiar with using certificates and setting up
  2468. client authentication for your servlet container before attempting to
  2469. use it with Acegi Security. Most of the work is in creating and
  2470. installing suitable certificates and keys. For example, if you're
  2471. using Tomcat then read the instructions here <ulink
  2472. url="http://jakarta.apache.org/tomcat/tomcat-5.0-doc/ssl-howto.html"></ulink>.
  2473. It's important that you get this working before trying it out with
  2474. Acegi Security</para>
  2475. </sect1>
  2476. <sect1 id="x509-with-acegi">
  2477. <title>Using X509 with Acegi Security</title>
  2478. <para>With X509 authentication, there is no explicit login procedure
  2479. so the implementation is relatively simple; there is no need to
  2480. redirect requests in order to interact with the user. As a result,
  2481. some of the classes behave slightly differently from their equivalents
  2482. in other packages. For example, the default <quote>entry point</quote>
  2483. class, which is normally responsible for starting the authentication
  2484. process, is only invoked if the certificate is rejected and it always
  2485. returns an error to the user. With a suitable bean configuration, the
  2486. normal sequence of events is as follows <orderedlist>
  2487. <listitem>
  2488. <para>The <classname>X509ProcessingFilter</classname> extracts
  2489. the certificate from the request and uses it as the credentials
  2490. for an authentication request. The generated authentication
  2491. request is an <classname>X509AuthenticationToken</classname>.
  2492. The request is passed to the authentication manager.</para>
  2493. </listitem>
  2494. <listitem>
  2495. <para>The <classname>X509AuthenticationProvider</classname>
  2496. receives the token. Its main concern is to obtain the user
  2497. information (in particular the user's granted authorities) that
  2498. matches the certificate. It delegates this responsibility to an
  2499. <interfacename>X509AuthoritiesPopulator</interfacename>.</para>
  2500. </listitem>
  2501. <listitem>
  2502. <para>The populator's single method,
  2503. <methodname>getUserDetails(X509Certificate
  2504. userCertificate)</methodname> is invoked. Implementations should
  2505. return a <classname>UserDetails</classname> instance containing
  2506. the array of <classname>GrantedAuthority</classname> objects for
  2507. the user. This method can also choose to reject the certificate
  2508. (for example if it doesn't contain a matching user name). In
  2509. such cases it should throw a
  2510. <exceptionname>BadCredentialsException</exceptionname>. A
  2511. DAO-based implementation,
  2512. <classname>DaoX509AuthoritiesPopulator</classname>, is provided
  2513. which extracts the user's name from the subject <quote>common
  2514. name</quote> (CN) in the certificate. It also allows you to set
  2515. your own regular expression to match a different part of the
  2516. subject's distinguished name. A UserDetailsService is used to
  2517. load the user information.<!-- TODO: Give email matching as an example --></para>
  2518. </listitem>
  2519. <listitem>
  2520. <para>If everything has gone smoothly then there should be a
  2521. valid <classname>Authentication</classname> object in the secure
  2522. context and the invocation will procede as normal. If no
  2523. certificate was found, or the certificate was rejected, then the
  2524. <classname>ExceptionTranslationFilter</classname> will invoke
  2525. the <classname>X509ProcessingFilterEntryPoint</classname> which
  2526. returns a 403 error (forbidden) to the user.</para>
  2527. </listitem>
  2528. </orderedlist></para>
  2529. </sect1>
  2530. <sect1 id="x509-config">
  2531. <title>Configuration</title>
  2532. <para>There is a version of the <link
  2533. linkend="contacts-sample">Contacts Sample Application</link> which
  2534. uses X509. Copy the beans and filter setup from this as a starting
  2535. point for configuring your own application. A set of example
  2536. certificates is also included which you can use to configure your
  2537. server. These are <itemizedlist>
  2538. <listitem>
  2539. <para><filename>marissa.p12</filename>: A PKCS12 format file
  2540. containing the client key and certificate. These should be
  2541. installed in your browser. It maps to the user
  2542. <quote>marissa</quote> in the application.</para>
  2543. </listitem>
  2544. <listitem>
  2545. <para><filename>server.p12</filename>: The server certificate
  2546. and key for HTTPS connections.</para>
  2547. </listitem>
  2548. <listitem>
  2549. <para><filename>ca.jks</filename>: A Java keystore containing
  2550. the certificate for the authority which issued marissa's
  2551. certificate. This will be used by the container to validate
  2552. client certificates.</para>
  2553. </listitem>
  2554. </itemizedlist> For JBoss 3.2.7 (with Tomcat 5.0), the SSL
  2555. configuration in the <filename>server.xml</filename> file looks like
  2556. this <programlisting>
  2557. &lt;!-- SSL/TLS Connector configuration --&gt;
  2558. &lt;Connector port="8443" address="${jboss.bind.address}"
  2559. maxThreads="100" minSpareThreads="5" maxSpareThreads="15"
  2560. scheme="https" secure="true"
  2561. sslProtocol = "TLS"
  2562. clientAuth="true" keystoreFile="${jboss.server.home.dir}/conf/server.p12"
  2563. keystoreType="PKCS12" keystorePass="password"
  2564. truststoreFile="${jboss.server.home.dir}/conf/ca.jks"
  2565. truststoreType="JKS" truststorePass="password"
  2566. /&gt;
  2567. </programlisting><parameter>clientAuth</parameter> can also be set to
  2568. <parameter>want</parameter> if you still want SSL connections to
  2569. succeed even if the client doesn't provide a certificate. Obviously
  2570. these clients won't be able to access any objects secured by Acegi
  2571. Security (unless you use a non-X509 authentication mechanism, such as
  2572. BASIC authentication, to authenticate the user)</para>
  2573. </sect1>
  2574. </chapter>
  2575. <chapter id="ldap">
  2576. <title>LDAP Authentication</title>
  2577. <sect1 id="ldap-overview">
  2578. <title>Overview</title>
  2579. <para>LDAP is often used by organizations as a central repository for
  2580. user information and as an authentication service. It can also be used
  2581. to store the role information for application users.</para>
  2582. <para>There are many different scenarios for how an LDAP server may be
  2583. configured so Acegi LDAP provider is fully configurable. It uses
  2584. separate strategy interfaces for authentication and role retrieval and
  2585. provides default implementations which can be configured to handle a
  2586. wide range of situations.</para>
  2587. <para>You should be familiar with LDAP before trying to use it with
  2588. Acegi. The following link provides a good introduction to the concepts
  2589. involved and a guide to setting up a directory using the free LDAP
  2590. server OpenLDAP: <ulink
  2591. url="http://www.zytrax.com/books/ldap/"></ulink>. Some familiarity
  2592. with the JNDI APIs used to access LDAP from Java may also be useful.
  2593. We don't use any third-party LDAP libraries (Mozilla/Netscape, JLDAP
  2594. etc.) in the LDAP provider.</para>
  2595. </sect1>
  2596. <sect1 id="ldap-with-acegi">
  2597. <title>Using LDAP with Acegi Security</title>
  2598. <para>The main LDAP provider class is
  2599. <classname>org.acegisecurity.providers.ldap.LdapAuthenticationProvider</classname>.
  2600. This bean doesn't actually do much itself other than implement the
  2601. <methodname>retrieveUser</methodname> method required by its base
  2602. class,
  2603. <classname>AbstractUserDetailsAuthenticationProvider</classname>. It
  2604. delegates the work to two other beans, an
  2605. <interfacename>LdapAuthenticator</interfacename> and an
  2606. <interfacename>LdapAuthoritiesPopulator</interfacename> which are
  2607. responsible for authenticating the user and retrieving the user's set
  2608. of <interfacename>GrantedAuthority</interfacename>s
  2609. respectively.</para>
  2610. <sect2 id="ldap-ldap-authenticators">
  2611. <title>LdapAuthenticator Implementations</title>
  2612. <para>The authenticator is also responsible for retrieving any
  2613. required user attributes. This is because the permissions on the
  2614. attributes may depend on the type of authentication being used. For
  2615. example, if binding as the user, it may be necessary to read them
  2616. with the user's own permissions.</para>
  2617. <para>There are currently two authentication strategies supplied
  2618. with Acegi Security: <itemizedlist>
  2619. <listitem>
  2620. <para>Authentication directly to the LDAP server ("bind"
  2621. authentication).</para>
  2622. </listitem>
  2623. <listitem>
  2624. <para>Password comparison, where the password supplied by the
  2625. user is compared with the one stored in the repository. This
  2626. can either be done by retrieving the value of the password
  2627. attribute and checking it locally or by performing an LDAP
  2628. "compare" operation, where the supplied password is passed to
  2629. the server for comparison and the real password value is never
  2630. retrieved.</para>
  2631. </listitem>
  2632. </itemizedlist></para>
  2633. <sect3 id="ldap-ldap-authenticators-common">
  2634. <title>Common Functionality</title>
  2635. <para>Before it is possible to authenticate a user (by either
  2636. strategy), the distinguished name (DN) has to be obtained from the
  2637. login name supplied to the application. This can be done either by
  2638. simple pattern-matching (by setting the
  2639. <property>setUserDnPatterns</property> array property) or by
  2640. setting the <property>userSearch</property> property. For the DN
  2641. pattern-matching approach, a standard Java pattern format is used,
  2642. and the login name will be substituted for the parameter
  2643. <parameter>{0}</parameter>. The pattern should be relative to the
  2644. DN that the configured
  2645. <interfacename>InitialDirContextFactory</interfacename> will bind
  2646. to (see the section on <link
  2647. linkend="ldap-dircontextfactory">connecting to the LDAP
  2648. server</link> for more information on this). For example, if you
  2649. are using an LDAP server specified by the URL
  2650. <literal>ldap://monkeymachine.co.uk/dc=acegisecurity,dc=org</literal>,
  2651. and have a pattern <literal>uid={0},ou=greatapes</literal>, then a
  2652. login name of "gorilla" will map to a DN
  2653. <literal>uid=gorilla,ou=greatapes,dc=acegisecurity,dc=org</literal>.
  2654. Each configured DN pattern will be tried in turn until a match is
  2655. found. For information on using a search, see the section on <link
  2656. linkend="ldap-searchobjects">search objects</link> below. A
  2657. combination of the two approaches can also be used - the patterns
  2658. will be checked first and if no matching DN is found, the search
  2659. will be used.</para>
  2660. </sect3>
  2661. <sect3 id="ldap-ldap-authenticators-bind">
  2662. <title>BindAuthenticator</title>
  2663. <para>The class
  2664. <classname>org.acegisecurity.providers.ldap.authenticator.BindAuthenticator</classname>
  2665. implements the bind authentication strategy. It simply attempts to
  2666. bind as the user.</para>
  2667. </sect3>
  2668. <sect3 id="ldap-ldap-authenticators-password">
  2669. <title>PasswordComparisonAuthenticator</title>
  2670. <para>The class
  2671. <classname>org.acegisecurity.providers.ldap.authenticator.PasswordComparisonAuthenticator</classname>
  2672. implements the password comparison authentication strategy.</para>
  2673. </sect3>
  2674. <sect3 id="ldap-ldap-authenticators-active-directory">
  2675. <title>Active Directory Authentication</title>
  2676. <para>In addition to standard LDAP authentication (binding with a
  2677. DN), Active Directory has its own non-standard syntax for user
  2678. authentication.</para>
  2679. </sect3>
  2680. </sect2>
  2681. <sect2 id="ldap-dircontextfactory">
  2682. <title>Connecting to the LDAP Server</title>
  2683. <para>The beans discussed above have to be able to connect to the
  2684. server. They both have to be supplied with an
  2685. <interfacename>InitialDirContextFactory</interfacename> instance.
  2686. Unless you have special requirements, this will usually be a
  2687. <classname>DefaultInitialDirContextFactory</classname> bean, which
  2688. can be configured with the URL of your LDAP server and optionally
  2689. with the username and password of a "manager" user which will be
  2690. used by default when binding to the server (instead of binding
  2691. anonymously). It currently supports "simple" LDAP
  2692. authentication.</para>
  2693. <para><classname>DefaultInitialDirContextFactory</classname> uses
  2694. Sun's JNDI LDAP implementation by default (the one that comes with
  2695. the JDK). It also supports the built in connection pooling offered
  2696. by Sun's provider. Connections which are obtained either anonymously
  2697. or with the "manager" user's identity will be pooled automatically.
  2698. Connections obtained with a specific user's identity will not be
  2699. pooled. Connection pooling can be disabled completely by setting the
  2700. <property>useConnectionPool</property> property to false.</para>
  2701. <para>See the <ulink
  2702. url="http://acegisecurity.org/multiproject/acegi-security/xref/org/acegisecurity/providers/ldap/DefaultInitialDirContextFactory.html">class
  2703. Javadoc and source</ulink> for more information on this bean and its
  2704. properties.</para>
  2705. </sect2>
  2706. <sect2 id="ldap-searchobjects">
  2707. <title>LDAP Search Objects</title>
  2708. <para>Often more a more complicated strategy than simple DN-matching
  2709. is required to locate a user entry in the directory. This can be
  2710. encapsulated in an <interfacename>LdapUserSearch</interfacename>
  2711. instance which can be supplied to the authenticator implementations,
  2712. for example, to allow them to locate a user. The supplied
  2713. implementation is
  2714. <classname>FilterBasedLdapUserSearch</classname>.</para>
  2715. <sect3 id="ldap-searchobjects-filter">
  2716. <title
  2717. id="ldap-searchobjects-filter-based"><classname>FilterBasedLdapUserSearch</classname></title>
  2718. <para>This bean uses an LDAP filter to match the user object in
  2719. the directory. The process is explained in the Javadoc for the
  2720. corresponding search method on the <ulink
  2721. 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
  2722. DirContext class</ulink>. As explained there, the search filter
  2723. can be supplied with parameters. For this class, the only valid
  2724. parameter is <parameter>{0}</parameter> which will be replaced
  2725. with the user's login name.</para>
  2726. </sect3>
  2727. </sect2>
  2728. </sect1>
  2729. <sect1 id="ldap-config">
  2730. <title>Configuration</title>
  2731. <para>There is a version of the <link
  2732. linkend="contacts-sample">Contacts Sample Application</link> which
  2733. uses LDAP. You can copy the beans and filter setup from this as a
  2734. starting point for configuring your own application.</para>
  2735. <para>A typical configuration, using some of the beans we've discussed
  2736. above, might look like this: <programlisting>
  2737. &lt;bean id="initialDirContextFactory"
  2738. class="org.acegisecurity.providers.ldap.DefaultInitialDirContextFactory"&gt;
  2739. &lt;constructor-arg value="ldap://monkeymachine:389/dc=acegisecurity,dc=org"/&gt;
  2740. &lt;property name="managerDn"&gt;&lt;value&gt;cn=manager,dc=acegisecurity,dc=org&lt;/value&gt;&lt;/property&gt;
  2741. &lt;property name="managerPassword"&gt;&lt;value&gt;password&lt;/value&gt;&lt;/property&gt;
  2742. &lt;/bean&gt;
  2743. &lt;bean id="userSearch"
  2744. class="org.acegisecurity.providers.ldap.search.FilterBasedLdapUserSearch"&gt;
  2745. &lt;constructor-arg index="0"&gt;
  2746. &lt;value&gt;&lt;/value&gt;
  2747. &lt;/constructor-arg&gt;
  2748. &lt;constructor-arg index="1"&gt;
  2749. &lt;value&gt;(uid={0})&lt;/value&gt;
  2750. &lt;/constructor-arg&gt;
  2751. &lt;constructor-arg index="2"&gt;
  2752. &lt;ref local="initialDirContextFactory" /&gt;
  2753. &lt;/constructor-arg&gt;
  2754. &lt;property name="searchSubtree"&gt;
  2755. &lt;value&gt;true&lt;/value&gt;
  2756. &lt;/property&gt;
  2757. &lt;/bean&gt;
  2758. &lt;bean id="ldapAuthProvider"
  2759. class="org.acegisecurity.providers.ldap.LdapAuthenticationProvider"&gt;
  2760. &lt;constructor-arg&gt;
  2761. &lt;bean class="org.acegisecurity.providers.ldap.authenticator.BindAuthenticator"&gt;
  2762. &lt;constructor-arg&gt;&lt;ref local="initialDirContextFactory"/&gt;&lt;/constructor-arg&gt;
  2763. &lt;property name="userDnPatterns"&gt;&lt;list&gt;&lt;value&gt;uid={0},ou=people&lt;/value&gt;&lt;/list&gt;&lt;/property&gt;
  2764. &lt;/bean&gt;
  2765. &lt;/constructor-arg&gt;
  2766. &lt;constructor-arg&gt;
  2767. &lt;bean class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator"&gt;
  2768. &lt;constructor-arg&gt;&lt;ref local="initialDirContextFactory"/&gt;&lt;/constructor-arg&gt;
  2769. &lt;constructor-arg&gt;&lt;value&gt;ou=groups&lt;/value&gt;&lt;/constructor-arg&gt;
  2770. &lt;property name="groupRoleAttribute"&gt;&lt;value&gt;ou&lt;/value&gt;&lt;/property&gt;
  2771. &lt;/bean&gt;
  2772. &lt;/constructor-arg&gt;
  2773. &lt;/bean&gt;
  2774. </programlisting> This would set up the provider to access an LDAP
  2775. server with URL
  2776. <literal>ldap://monkeymachine:389/dc=acegisecurity,dc=org</literal>.
  2777. Authentication will be performed by attempting to bind with the DN
  2778. <literal>uid=&lt;user-login-name&gt;,ou=people,dc=acegisecurity,dc=org</literal>.
  2779. After successful authentication, roles will be assigned to the user by
  2780. searching under the DN
  2781. <literal>ou=groups,dc=acegisecurity,dc=org</literal> with the default
  2782. filter <literal>(member=&lt;user's-DN&gt;)</literal>. The role name
  2783. will be taken from the <quote>ou</quote> attribute of each
  2784. match.</para>
  2785. <para>We've also included the configuration for a user search object,
  2786. which uses the filter
  2787. <literal>(uid=&lt;user-login-name&gt;)</literal>. This could be used
  2788. instead of the DN-pattern (or in addition to it), by setting the
  2789. authenticator's <property>userSearch</property> property. The
  2790. authenticator would then call the search object to obtain the correct
  2791. user's DN before attempting to bind as this user.</para>
  2792. </sect1>
  2793. </chapter>
  2794. <chapter id="cas">
  2795. <title>CAS Authentication</title>
  2796. <sect1 id="cas-overview">
  2797. <title>Overview</title>
  2798. <para>JA-SIG produces an enterprise-wide single sign on system known
  2799. as CAS. Unlike other initiatives, JA-SIG's Central Authentication
  2800. Service is open source, widely used, simple to understand, platform
  2801. independent, and supports proxy capabilities. Acegi Security fully
  2802. supports CAS, and provides an easy migration path from
  2803. single-application deployments of Acegi Security through to
  2804. multiple-application deployments secured by an enterprise-wide CAS
  2805. server.</para>
  2806. <para>You can learn more about CAS at
  2807. <literal>http://www.ja-sig.org/products/cas/</literal>. You will need
  2808. to visit this URL to download the CAS Server files. Whilst Acegi
  2809. Security includes two CAS libraries in the "-with-dependencies" ZIP
  2810. file, you will still need the CAS Java Server Pages and
  2811. <literal>web.xml</literal> to customise and deploy your CAS
  2812. server.</para>
  2813. </sect1>
  2814. <sect1 id="cas-how-it-works">
  2815. <title>How CAS Works</title>
  2816. <para>Whilst the CAS web site above contains two documents that detail
  2817. the architecture of CAS, we present the general overview again here
  2818. within the context of Acegi Security. The following refers to both CAS
  2819. 2.0 (produced by Yale) and CAS 3.0 (produced by JA-SIG), being the
  2820. versions of CAS that Acegi Security supports.</para>
  2821. <para>Somewhere in your enterprise you will need to setup a CAS
  2822. server. The CAS server is simply a standard WAR file, so there isn't
  2823. anything difficult about setting up your server. Inside the WAR file
  2824. you will customise the login and other single sign on pages displayed
  2825. to users.</para>
  2826. <para>If you are deploying CAS 2.0, you will also need to specify in
  2827. the web.xml a <literal>PasswordHandler</literal>. The
  2828. <literal>PasswordHandler</literal> has a simple method that returns a
  2829. boolean as to whether a given username and password is valid. Your
  2830. <literal>PasswordHandler</literal> implementation will need to link
  2831. into some type of backend authentication repository, such as an LDAP
  2832. server or database.</para>
  2833. <para>If you are already running an existing CAS 2.0 server instance,
  2834. you will have already established a
  2835. <literal>PasswordHandler</literal>. If you do not already have a
  2836. <literal>PasswordHandler</literal>, you might prefer to use Acegi
  2837. Security <literal>CasPasswordHandler</literal> class. This class
  2838. delegates through to the standard Acegi Security
  2839. <literal>AuthenticationManager</literal>, enabling you to use a
  2840. security configuration you might already have in place. You do not
  2841. need to use the <literal>CasPasswordHandler</literal> class on your
  2842. CAS server if you do not wish. Acegi Security will function as a CAS
  2843. client successfully irrespective of the
  2844. <literal>PasswordHandler</literal> you've chosen for your CAS
  2845. server.</para>
  2846. <para>If you are deploying CAS 3.0, you will also need to specify an
  2847. <literal>AuthenticationHandler</literal> in the
  2848. deployerConfigContext.xml included with CAS. The
  2849. <literal>AuthenticationHandler</literal> has a simple method that
  2850. returns a boolean as to whether a given set of Credentials is valid.
  2851. Your <literal>AuthenticationHandler</literal> implementation will need
  2852. to link into some type of backend authentication repository, such as
  2853. an LDAP server or database. CAS itself includes numerous
  2854. <literal>AuthenticationHandler</literal>s out of the box to assist
  2855. with this.</para>
  2856. <para>If you are already running an existing CAS 3.0 server instance,
  2857. you will have already established an
  2858. <literal>AuthenticationHandler</literal>. If you do not already have
  2859. an <literal>AuthenticationHandler</literal>, you might prefer to use
  2860. Acegi Security <literal>CasAuthenticationHandler</literal> class. This
  2861. class delegates through to the standard Acegi Security
  2862. <literal>AuthenticationManager</literal>, enabling you to use a
  2863. security configuration you might already have in place. You do not
  2864. need to use the <literal>CasAuthenticationHandler</literal> class on
  2865. your CAS server if you do not wish. Acegi Security will function as a
  2866. CAS client successfully irrespective of the
  2867. <literal>AuthenticationHandler</literal> you've chosen for your CAS
  2868. server.</para>
  2869. <para>Apart from the CAS server itself, the other key player is of
  2870. course the secure web applications deployed throughout your
  2871. enterprise. These web applications are known as "services". There are
  2872. two types of services: standard services and proxy services. A proxy
  2873. service is able to request resources from other services on behalf of
  2874. the user. This will be explained more fully later.</para>
  2875. <para>Services can be developed in a large variety of languages, due
  2876. to CAS 2.0's very light XML-based protocol. The JA-SIG CAS home page
  2877. contains a clients archive which demonstrates CAS clients in Java,
  2878. Active Server Pages, Perl, Python and others. Naturally, Java support
  2879. is very strong given the CAS server is written in Java. You do not
  2880. need to use any of CAS' client classes in applications secured by
  2881. Acegi Security. This is handled transparently for you.</para>
  2882. <para>The basic interaction between a web browser, CAS server and an
  2883. Acegi Security for System Spring secured service is as follows:</para>
  2884. <orderedlist>
  2885. <listitem>
  2886. <para>The web user is browsing the service's public pages. CAS or
  2887. Acegi Security is not involved.</para>
  2888. </listitem>
  2889. <listitem>
  2890. <para>The user eventually requests a page that is either secure or
  2891. one of the beans it uses is secure. Acegi Security's
  2892. <literal>ExceptionTranslationFilter</literal> will detect the
  2893. <literal>AuthenticationException</literal>.</para>
  2894. </listitem>
  2895. <listitem>
  2896. <para>Because the user's <literal>Authentication</literal> object
  2897. (or lack thereof) caused an
  2898. <literal>AuthenticationException</literal>, the
  2899. <literal>ExceptionTranslationFilter</literal> will call the
  2900. configured <literal>AuthenticationEntryPoint</literal>. If using
  2901. CAS, this will be the
  2902. <literal>CasProcessingFilterEntryPoint</literal> class.</para>
  2903. </listitem>
  2904. <listitem>
  2905. <para>The <literal>CasProcessingFilterEntry</literal> point will
  2906. redirect the user's browser to the CAS server. It will also
  2907. indicate a <literal>service</literal> parameter, which is the
  2908. callback URL for Acegi Security service. For example, the URL to
  2909. which the browser is redirected might be
  2910. <literal>https://my.company.com/cas/login?service=https%3A%2F%2Fserver3.company.com%2Fwebapp%2Fj_acegi_cas_security_check</literal>.</para>
  2911. </listitem>
  2912. <listitem>
  2913. <para>After the user's browser redirects to CAS, they will be
  2914. prompted for their username and password. If the user presents a
  2915. session cookie which indicates they've previously logged on, they
  2916. will not be prompted to login again (there is an exception to this
  2917. procedure, which we'll cover later). CAS will use the
  2918. <literal>PasswordHandler</literal> (or
  2919. <literal>AuthenticationHandler</literal> if using CAS 3.0)
  2920. discussed above to decide whether the username and password is
  2921. valid.</para>
  2922. </listitem>
  2923. <listitem>
  2924. <para>Upon successful login, CAS will redirect the user's browser
  2925. back to the original service. It will also include a
  2926. <literal>ticket</literal> parameter, which is an opaque string
  2927. representing the "service ticket". Continuing our earlier example,
  2928. the URL the browser is redirected to might be
  2929. <literal>https://server3.company.com/webapp/j_acegi_cas_security_check?ticket=ST-0-ER94xMJmn6pha35CQRoZ</literal>.</para>
  2930. </listitem>
  2931. <listitem>
  2932. <para>Back in the service web application, the
  2933. <literal>CasProcessingFilter</literal> is always listening for
  2934. requests to <literal>/j_acegi_cas_security_check</literal> (this
  2935. is configurable, but we'll use the defaults in this introduction).
  2936. The processing filter will construct a
  2937. <literal>UsernamePasswordAuthenticationToken</literal>
  2938. representing the service ticket. The principal will be equal to
  2939. <literal>CasProcessingFilter.CAS_STATEFUL_IDENTIFIER</literal>,
  2940. whilst the credentials will be the service ticket opaque value.
  2941. This authentication request will then be handed to the configured
  2942. <literal>AuthenticationManager</literal>.</para>
  2943. </listitem>
  2944. <listitem>
  2945. <para>The <literal>AuthenticationManager</literal> implementation
  2946. will be the <literal>ProviderManager</literal>, which is in turn
  2947. configured with the <literal>CasAuthenticationProvider</literal>.
  2948. The <literal>CasAuthenticationProvider</literal> only responds to
  2949. <literal>UsernamePasswordAuthenticationToken</literal>s containing
  2950. the CAS-specific principal (such as
  2951. <literal>CasProcessingFilter.CAS_STATEFUL_IDENTIFIER</literal>)
  2952. and <literal>CasAuthenticationToken</literal>s (discussed
  2953. later).</para>
  2954. </listitem>
  2955. <listitem>
  2956. <para><literal>CasAuthenticationProvider</literal> will validate
  2957. the service ticket using a <literal>TicketValidator</literal>
  2958. implementation. Acegi Security includes one implementation, the
  2959. <literal>CasProxyTicketValidator</literal>. This implementation a
  2960. ticket validation class included in the CAS client library. The
  2961. <literal>CasProxyTicketValidator</literal> makes a HTTPS request
  2962. to the CAS server in order to validate the service ticket. The
  2963. <literal>CasProxyTicketValidator</literal> may also include a
  2964. proxy callback URL, which is included in this example:
  2965. <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>
  2966. </listitem>
  2967. <listitem>
  2968. <para>Back on the CAS server, the proxy validation request will be
  2969. received. If the presented service ticket matches the service URL
  2970. the ticket was issued to, CAS will provide an affirmative response
  2971. in XML indicating the username. If any proxy was involved in the
  2972. authentication (discussed below), the list of proxies is also
  2973. included in the XML response.</para>
  2974. </listitem>
  2975. <listitem>
  2976. <para>[OPTIONAL] If the request to the CAS validation service
  2977. included the proxy callback URL (in the <literal>pgtUrl</literal>
  2978. parameter), CAS will include a <literal>pgtIou</literal> string in
  2979. the XML response. This <literal>pgtIou</literal> represents a
  2980. proxy-granting ticket IOU. The CAS server will then create its own
  2981. HTTPS connection back to the <literal>pgtUrl</literal>. This is to
  2982. mutually authenticate the CAS server and the claimed service URL.
  2983. The HTTPS connection will be used to send a proxy granting ticket
  2984. to the original web application. For example,
  2985. <literal>https://server3.company.com/webapp/casProxy/receptor?pgtIou=PGTIOU-0-R0zlgrl4pdAQwBvJWO3vnNpevwqStbSGcq3vKB2SqSFFRnjPHt&amp;pgtId=PGT-1-si9YkkHLrtACBo64rmsi3v2nf7cpCResXg5MpESZFArbaZiOKH</literal>.
  2986. We suggest you use CAS' <literal>ProxyTicketReceptor</literal>
  2987. servlet to receive these proxy-granting tickets, if they are
  2988. required.</para>
  2989. </listitem>
  2990. <listitem>
  2991. <para>The <literal>CasProxyTicketValidator</literal> will parse
  2992. the XML received from the CAS server. It will return to the
  2993. <literal>CasAuthenticationProvider</literal> a
  2994. <literal>TicketResponse</literal>, which includes the username
  2995. (mandatory), proxy list (if any were involved), and proxy-granting
  2996. ticket IOU (if the proxy callback was requested).</para>
  2997. </listitem>
  2998. <listitem>
  2999. <para>Next <literal>CasAuthenticationProvider</literal> will call
  3000. a configured <literal>CasProxyDecider</literal>. The
  3001. <literal>CasProxyDecider</literal> indicates whether the proxy
  3002. list in the <literal>TicketResponse</literal> is acceptable to the
  3003. service. Several implementations are provided with Acegi Security
  3004. System: <literal>RejectProxyTickets</literal>,
  3005. <literal>AcceptAnyCasProxy</literal> and
  3006. <literal>NamedCasProxyDecider</literal>. These names are largely
  3007. self-explanatory, except <literal>NamedCasProxyDecider</literal>
  3008. which allows a <literal>List</literal> of trusted proxies to be
  3009. provided.</para>
  3010. </listitem>
  3011. <listitem>
  3012. <para><literal>CasAuthenticationProvider</literal> will next
  3013. request a <literal>CasAuthoritiesPopulator</literal> to advise the
  3014. <literal>GrantedAuthority</literal> objects that apply to the user
  3015. contained in the <literal>TicketResponse</literal>. Acegi Security
  3016. includes a <literal>DaoCasAuthoritiesPopulator</literal> which
  3017. simply uses the <literal>UserDetailsService</literal>
  3018. infrastructure to find the <literal>UserDetails</literal> and
  3019. their associated <literal>GrantedAuthority</literal>s. Note that
  3020. the password and enabled/disabled status of
  3021. <literal>UserDetails</literal> returned by the
  3022. <literal>UserDetailsService</literal> are ignored, as the CAS
  3023. server is responsible for authentication decisions.
  3024. <literal>DaoCasAuthoritiesPopulator</literal> is only concerned
  3025. with retrieving the <literal>GrantedAuthority</literal>s.</para>
  3026. </listitem>
  3027. <listitem>
  3028. <para>If there were no problems,
  3029. <literal>CasAuthenticationProvider</literal> constructs a
  3030. <literal>CasAuthenticationToken</literal> including the details
  3031. contained in the <literal>TicketResponse</literal> and the
  3032. <literal>GrantedAuthority</literal>s. The
  3033. <literal>CasAuthenticationToken</literal> contains the hash of a
  3034. key, so that the <literal>CasAuthenticationProvider</literal>
  3035. knows it created it.</para>
  3036. </listitem>
  3037. <listitem>
  3038. <para>Control then returns to
  3039. <literal>CasProcessingFilter</literal>, which places the created
  3040. <literal>CasAuthenticationToken</literal> into the
  3041. <literal>HttpSession</literal> attribute named
  3042. <literal>HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY</literal>.</para>
  3043. </listitem>
  3044. <listitem>
  3045. <para>The user's browser is redirected to the original page that
  3046. caused the <literal>AuthenticationException</literal>.</para>
  3047. </listitem>
  3048. <listitem>
  3049. <para>As the <literal>Authentication</literal> object is now in
  3050. the well-known location, it is handled like any other
  3051. authentication approach. Usually the
  3052. <literal>HttpSessionIntegrationFilter</literal> will be used to
  3053. associate the <literal>Authentication</literal> object with the
  3054. <literal>SecurityContextHolder</literal> for the duration of each
  3055. request.</para>
  3056. </listitem>
  3057. </orderedlist>
  3058. <para>It's good that you're still here! It might sound involved, but
  3059. you can relax as Acegi Security classes hide much of the complexity.
  3060. Let's now look at how this is configured</para>
  3061. </sect1>
  3062. <sect1 id="cas-server">
  3063. <title>Optional CAS Server Setup</title>
  3064. <para>Acegi Security can even act as the backend which a CAS version
  3065. 2.0 or 3.0 server utilises. The configuration approach is described
  3066. below. Of course, if you have an existing CAS environment you might
  3067. just like to use it instead.</para>
  3068. <sect2 id="cas-server-2">
  3069. <title>CAS Version 2.0</title>
  3070. <para>As mentioned above, Acegi Security includes a
  3071. <literal>PasswordHandler</literal> that bridges your existing
  3072. <literal>AuthenticationManager</literal> into CAS 2.0. You do not
  3073. need to use this <literal>PasswordHandler</literal> to use Acegi
  3074. Security on the client side (any CAS
  3075. <literal>PasswordHandler</literal> will do).</para>
  3076. <para>To install, you will need to download and extract the CAS
  3077. server archive. We used version 2.0.12. There will be a
  3078. <literal>/web</literal> directory in the root of the deployment.
  3079. Copy an <literal>applicationContext.xml</literal> containing your
  3080. <literal>AuthenticationManager</literal> as well as the
  3081. <literal>CasPasswordHandler</literal> into the
  3082. <literal>/web/WEB-INF</literal> directory. A sample
  3083. <literal>applicationContext.xml</literal> is included below:</para>
  3084. <programlisting>
  3085. &lt;bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl"&gt;
  3086. &lt;property name="userMap"&gt;
  3087. &lt;value&gt;
  3088. marissa=koala,ROLES_IGNORED_BY_CAS
  3089. dianne=emu,ROLES_IGNORED_BY_CAS
  3090. scott=wombat,ROLES_IGNORED_BY_CAS
  3091. peter=opal,disabled,ROLES_IGNORED_BY_CAS
  3092. &lt;/value&gt;
  3093. &lt;/property&gt;
  3094. &lt;/bean&gt;
  3095. &lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  3096. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3097. &lt;/bean&gt;
  3098. &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  3099. &lt;property name="providers"&gt;
  3100. &lt;list&gt;
  3101. &lt;ref bean="daoAuthenticationProvider"/&gt;
  3102. &lt;/list&gt;
  3103. &lt;/property&gt;
  3104. &lt;/bean&gt;
  3105. &lt;bean id="casPasswordHandler" class="org.acegisecurity.adapters.cas.CasPasswordHandler"&gt;
  3106. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  3107. &lt;/bean&gt;
  3108. </programlisting>
  3109. <para>Note the granted authorities are ignored by CAS because it has
  3110. no way of communicating the granted authorities to calling
  3111. applications. CAS is only concerned with username and passwords (and
  3112. the enabled/disabled status).</para>
  3113. <para>Next you will need to edit the existing
  3114. <literal>/web/WEB-INF/web.xml</literal> file. Add (or edit in the
  3115. case of the <literal>authHandler</literal> property) the following
  3116. lines:</para>
  3117. <para><programlisting>
  3118. &lt;context-param&gt;
  3119. &lt;param-name&gt;edu.yale.its.tp.cas.authHandler&lt;/param-name&gt;
  3120. &lt;param-value&gt;org.acegisecurity.adapters.cas.CasPasswordHandlerProxy&lt;/param-value&gt;
  3121. &lt;/context-param&gt;
  3122. &lt;context-param&gt;
  3123. &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
  3124. &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
  3125. &lt;/context-param&gt;
  3126. &lt;listener&gt;
  3127. &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  3128. &lt;/listener&gt;
  3129. </programlisting></para>
  3130. <para>Copy the <literal>spring.jar</literal> and
  3131. <literal>acegi-security.jar</literal> files into
  3132. <literal>/web/WEB-INF/lib</literal>. Now use the <literal>ant
  3133. dist</literal> task in the <literal>build.xml</literal> in the root
  3134. of the directory structure. This will create
  3135. <literal>/lib/cas.war</literal>, which is ready for deployment to
  3136. your servlet container.</para>
  3137. <para>Note CAS heavily relies on HTTPS. You can't even test the
  3138. system without a HTTPS certificate. Whilst you should refer to your
  3139. web container's documentation on setting up HTTPS, if you need some
  3140. additional help or a test certificate you might like to check the
  3141. <literal>samples/contacts/etc/ssl</literal> directory</para>
  3142. </sect2>
  3143. <sect2 id="cas-server-3">
  3144. <title>CAS Version 3.0</title>
  3145. <para>As mentioned above, Acegi Security includes an
  3146. <literal>AuthenticationHandler</literal> that bridges your existing
  3147. <literal>AuthenticationManager</literal> into CAS 3.0. You do not
  3148. need to use this <literal>AuthenticationHandler</literal> to use
  3149. Acegi Security on the client side (any CAS
  3150. <literal>AuthenticationHandler</literal> will do).</para>
  3151. <para>To install, you will need to download and extract the CAS
  3152. server archive. We used version 3.0.4. There will be a
  3153. <literal>/webapp</literal> directory in the root of the deployment.
  3154. Edit the an <literal>deployerConfigContext.xml</literal> so that it
  3155. contains your <literal>AuthenticationManager</literal> as well as
  3156. the <literal>CasAuthenticationHandler</literal>. A sample
  3157. <literal>applicationContext.xml</literal> is included below:</para>
  3158. <programlisting>
  3159. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  3160. &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  3161. &lt;beans&gt;
  3162. &lt;bean
  3163. id="authenticationManager"
  3164. class="org.jasig.cas.authentication.AuthenticationManagerImpl"&gt;
  3165. &lt;property name="credentialsToPrincipalResolvers"&gt;
  3166. &lt;list&gt;
  3167. &lt;bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" /&gt;
  3168. &lt;bean class="org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" /&gt;
  3169. &lt;/list&gt;
  3170. &lt;/property&gt;
  3171. &lt;property name="authenticationHandlers"&gt;
  3172. &lt;list&gt;
  3173. &lt;bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" /&gt;
  3174. &lt;bean class="org.acegisecurity.adapters.cas3.CasAuthenticationHandler"&gt;
  3175. &lt;property name="authenticationManager" ref="acegiAuthenticationManager" /&gt;
  3176. &lt;/bean&gt;
  3177. &lt;/list&gt;
  3178. &lt;/property&gt;
  3179. &lt;/bean&gt;
  3180. &lt;bean id="inMemoryDaoImpl" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl"&gt;
  3181. &lt;property name="userMap"&gt;
  3182. &lt;value&gt;
  3183. marissa=koala,ROLES_IGNORED_BY_CAS
  3184. dianne=emu,ROLES_IGNORED_BY_CAS
  3185. scott=wombat,ROLES_IGNORED_BY_CAS
  3186. peter=opal,disabled,ROLES_IGNORED_BY_CAS
  3187. &lt;/value&gt;
  3188. &lt;/property&gt;
  3189. &lt;/bean&gt;
  3190. &lt;bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"&gt;
  3191. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3192. &lt;/bean&gt;
  3193. &lt;bean id="acegiAuthenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  3194. &lt;property name="providers"&gt;
  3195. &lt;list&gt;
  3196. &lt;ref bean="daoAuthenticationProvider"/&gt;
  3197. &lt;/list&gt;
  3198. &lt;/property&gt;
  3199. &lt;/bean&gt;
  3200. &lt;/beans&gt;
  3201. </programlisting>
  3202. <para>Note the granted authorities are ignored by CAS because it has
  3203. no way of communicating the granted authorities to calling
  3204. applications. CAS is only concerned with username and passwords (and
  3205. the enabled/disabled status).</para>
  3206. <para>Copy Acegi<literal>-security.jar</literal> file into
  3207. <literal>/localPlugins/lib</literal>. Now use the <literal>ant
  3208. war</literal> task in the <literal>build.xml</literal> in the
  3209. /localPlugins directory. This will create
  3210. <literal>/localPlugins/target/cas.war</literal>, which is ready for
  3211. deployment to your servlet container.</para>
  3212. <para>Note CAS heavily relies on HTTPS. You can't even test the
  3213. system without a HTTPS certificate. Whilst you should refer to your
  3214. web container's documentation on setting up HTTPS, if you need some
  3215. additional help or a test certificate you might like to check the
  3216. CAS documentation on setting up SSL:
  3217. <literal>http://www.ja-sig.org/products/cas/server/ssl/index.html</literal></para>
  3218. </sect2>
  3219. </sect1>
  3220. <sect1 id="cas-client">
  3221. <title>Configuration of CAS Client</title>
  3222. <para>The web application side of CAS is made easy due to Acegi
  3223. Security. It is assumed you already know the basics of using Acegi
  3224. Security, so these are not covered again below. Only the CAS-specific
  3225. beans are mentioned.</para>
  3226. <para>You will need to add a <literal>ServiceProperties</literal> bean
  3227. to your application context. This represents your service:</para>
  3228. <para><programlisting>
  3229. &lt;bean id="serviceProperties" class="org.acegisecurity.ui.cas.ServiceProperties"&gt;
  3230. &lt;property name="service"&gt;&lt;value&gt;https://localhost:8443/contacts-cas/j_acegi_cas_security_check&lt;/value&gt;&lt;/property&gt;
  3231. &lt;property name="sendRenew"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  3232. &lt;/bean&gt;
  3233. </programlisting></para>
  3234. <para>The <literal>service</literal> must equal a URL that will be
  3235. monitored by the <literal>CasProcessingFilter</literal>. The
  3236. <literal>sendRenew</literal> defaults to false, but should be set to
  3237. true if your application is particularly sensitive. What this
  3238. parameter does is tell the CAS login service that a single sign on
  3239. login is unacceptable. Instead, the user will need to re-enter their
  3240. username and password in order to gain access to the service.</para>
  3241. <para>The following beans should be configured to commence the CAS
  3242. authentication process:</para>
  3243. <para><programlisting>
  3244. &lt;bean id="casProcessingFilter" class="org.acegisecurity.ui.cas.CasProcessingFilter"&gt;
  3245. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  3246. &lt;property name="authenticationFailureUrl"&gt;&lt;value&gt;/casfailed.jsp&lt;/value&gt;&lt;/property&gt;
  3247. &lt;property name="defaultTargetUrl"&gt;&lt;value&gt;/&lt;/value&gt;&lt;/property&gt;
  3248. &lt;property name="filterProcessesUrl"&gt;&lt;value&gt;/j_acegi_cas_security_check&lt;/value&gt;&lt;/property&gt;
  3249. &lt;/bean&gt;
  3250. &lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;
  3251. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="casProcessingFilterEntryPoint"/&gt;&lt;/property&gt;
  3252. &lt;/bean&gt;
  3253. &lt;bean id="casProcessingFilterEntryPoint" class="org.acegisecurity.ui.cas.CasProcessingFilterEntryPoint"&gt;
  3254. &lt;property name="loginUrl"&gt;&lt;value&gt;https://localhost:8443/cas/login&lt;/value&gt;&lt;/property&gt;
  3255. &lt;property name="serviceProperties"&gt;&lt;ref bean="serviceProperties"/&gt;&lt;/property&gt;
  3256. &lt;/bean&gt;
  3257. </programlisting></para>
  3258. <para>You will also need to add the
  3259. <literal>CasProcessingFilter</literal> to web.xml:</para>
  3260. <para><programlisting>
  3261. &lt;filter&gt;
  3262. &lt;filter-name&gt;Acegi CAS Processing Filter&lt;/filter-name&gt;
  3263. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  3264. &lt;init-param&gt;
  3265. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  3266. &lt;param-value&gt;org.acegisecurity.ui.cas.CasProcessingFilter&lt;/param-value&gt;
  3267. &lt;/init-param&gt;
  3268. &lt;/filter&gt;
  3269. &lt;filter-mapping&gt;
  3270. &lt;filter-name&gt;Acegi CAS Processing Filter&lt;/filter-name&gt;
  3271. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  3272. &lt;/filter-mapping&gt;
  3273. </programlisting></para>
  3274. <para>The <literal>CasProcessingFilter</literal> has very similar
  3275. properties to the <literal>AuthenticationProcessingFilter</literal>
  3276. (used for form-based logins). Each property is
  3277. self-explanatory.</para>
  3278. <para>For CAS to operate, the
  3279. <literal>ExceptionTranslationFilter</literal> must have its
  3280. <literal>authenticationEntryPoint</literal> property set to the
  3281. <literal>CasProcessingFilterEntryPoint</literal> bean.</para>
  3282. <para>The <literal>CasProcessingFilterEntryPoint</literal> must refer
  3283. to the <literal>ServiceProperties</literal> bean (discussed above),
  3284. which provides the URL to the enterprise's CAS login server. This is
  3285. where the user's browser will be redirected.</para>
  3286. <para>Next you need to add an <literal>AuthenticationManager</literal>
  3287. that uses <literal>CasAuthenticationProvider</literal> and its
  3288. collaborators:</para>
  3289. <para><programlisting>
  3290. &lt;bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"&gt;
  3291. &lt;property name="providers"&gt;
  3292. &lt;list&gt;
  3293. &lt;ref bean="casAuthenticationProvider"/&gt;
  3294. &lt;/list&gt;
  3295. &lt;/property&gt;
  3296. &lt;/bean&gt;
  3297. &lt;bean id="casAuthenticationProvider" class="org.acegisecurity.providers.cas.CasAuthenticationProvider"&gt;
  3298. &lt;property name="casAuthoritiesPopulator"&gt;&lt;ref bean="casAuthoritiesPopulator"/&gt;&lt;/property&gt;
  3299. &lt;property name="casProxyDecider"&gt;&lt;ref bean="casProxyDecider"/&gt;&lt;/property&gt;
  3300. &lt;property name="ticketValidator"&gt;&lt;ref bean="casProxyTicketValidator"/&gt;&lt;/property&gt;
  3301. &lt;property name="statelessTicketCache"&gt;&lt;ref bean="statelessTicketCache"/&gt;&lt;/property&gt;
  3302. &lt;property name="key"&gt;&lt;value&gt;my_password_for_this_auth_provider_only&lt;/value&gt;&lt;/property&gt;
  3303. &lt;/bean&gt;
  3304. &lt;bean id="casProxyTicketValidator" class="org.acegisecurity.providers.cas.ticketvalidator.CasProxyTicketValidator"&gt;
  3305. &lt;property name="casValidate"&gt;&lt;value&gt;https://localhost:8443/cas/proxyValidate&lt;/value&gt;&lt;/property&gt;
  3306. &lt;property name="proxyCallbackUrl"&gt;&lt;value&gt;https://localhost:8443/contacts-cas/casProxy/receptor&lt;/value&gt;&lt;/property&gt;
  3307. &lt;property name="serviceProperties"&gt;&lt;ref bean="serviceProperties"/&gt;&lt;/property&gt;
  3308. &lt;!-- &lt;property name="trustStore"&gt;&lt;value&gt;/some/path/to/your/lib/security/cacerts&lt;/value&gt;&lt;/property&gt; --&gt;
  3309. &lt;/bean&gt;
  3310. &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"&gt;
  3311. &lt;property name="configLocation"&gt;
  3312. &lt;value&gt;classpath:/ehcache-failsafe.xml&lt;/value&gt;
  3313. &lt;/property&gt;
  3314. &lt;/bean&gt;
  3315. &lt;bean id="ticketCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean"&gt;
  3316. &lt;property name="cacheManager"&gt;
  3317. &lt;ref local="cacheManager"/&gt;
  3318. &lt;/property&gt;
  3319. &lt;property name="cacheName"&gt;
  3320. &lt;value&gt;ticketCache&lt;/value&gt;
  3321. &lt;/property&gt;
  3322. &lt;/bean&gt;
  3323. &lt;bean id="statelessTicketCache" class="org.acegisecurity.providers.cas.cache.EhCacheBasedTicketCache"&gt;
  3324. &lt;property name="cache"&gt;&lt;ref local="ticketCacheBackend"/&gt;&lt;/property&gt;
  3325. &lt;/bean&gt;
  3326. &lt;bean id="casAuthoritiesPopulator" class="org.acegisecurity.providers.cas.populator.DaoCasAuthoritiesPopulator"&gt;
  3327. &lt;property name="userDetailsService"&gt;&lt;ref bean="inMemoryDaoImpl"/&gt;&lt;/property&gt;
  3328. &lt;/bean&gt;
  3329. &lt;bean id="casProxyDecider" class="org.acegisecurity.providers.cas.proxy.RejectProxyTickets"/&gt;
  3330. </programlisting></para>
  3331. <para>The beans are all reasonable self-explanatory if you refer back
  3332. to the "How CAS Works" section. Careful readers might notice one
  3333. surprise: the <literal>statelessTicketCache</literal> property of the
  3334. <literal>CasAuthenticationProvider</literal>. This is discussed in
  3335. detail in the "Advanced CAS Usage" section.</para>
  3336. <para>Note the <literal>CasProxyTicketValidator</literal> has a
  3337. remarked out <literal>trustStore</literal> property. This property
  3338. might be helpful if you experience HTTPS certificate issues. Also note
  3339. the <literal>proxyCallbackUrl</literal> is set so the service can
  3340. receive a proxy-granting ticket. As mentioned above, this is optional
  3341. and unnecessary if you do not require proxy-granting tickets. If you
  3342. do use this feature, you will need to configure a suitable servlet to
  3343. receive the proxy-granting tickets. We suggest you use CAS'
  3344. <literal>ProxyTicketReceptor</literal> by adding the following to your
  3345. web application's <literal>web.xml</literal>:</para>
  3346. <para><programlisting>
  3347. &lt;servlet&gt;
  3348. &lt;servlet-name&gt;casproxy&lt;/servlet-name&gt;
  3349. &lt;servlet-class&gt;edu.yale.its.tp.cas.proxy.ProxyTicketReceptor&lt;/servlet-class&gt;
  3350. &lt;/servlet&gt;
  3351. &lt;servlet-mapping&gt;
  3352. &lt;servlet-name&gt;casproxy&lt;/servlet-name&gt;
  3353. &lt;url-pattern&gt;/casProxy/*&lt;/url-pattern&gt;
  3354. &lt;/servlet-mapping&gt;
  3355. </programlisting></para>
  3356. <para>This completes the configuration of CAS. If you haven't made any
  3357. mistakes, your web application should happily work within the
  3358. framework of CAS single sign on. No other parts of Acegi Security need
  3359. to be concerned about the fact CAS handled authentication.</para>
  3360. <para>There is also a <literal>contacts-cas.war</literal> file in the
  3361. sample applications directory. This sample application uses the above
  3362. settings and can be deployed to see CAS in operation</para>
  3363. </sect1>
  3364. <sect1 id="cas-advanced">
  3365. <title>Advanced Issues</title>
  3366. <para>The <literal>CasAuthenticationProvider</literal> distinguishes
  3367. between stateful and stateless clients. A stateful client is
  3368. considered any that originates via the
  3369. <literal>CasProcessingFilter</literal>. A stateless client is any that
  3370. presents an authentication request via the
  3371. <literal>UsernamePasswordAuthenticationToken</literal> with a
  3372. principal equal to
  3373. <literal>CasProcessingFilter.CAS_STATELESS_IDENTIFIER</literal>.</para>
  3374. <para>Stateless clients are likely to be via remoting protocols such
  3375. as Hessian and Burlap. The <literal>BasicProcessingFilter</literal> is
  3376. still used in this case, but the remoting protocol client is expected
  3377. to present a username equal to the static string above, and a password
  3378. equal to a CAS service ticket. Clients should acquire a CAS service
  3379. ticket directly from the CAS server.</para>
  3380. <para>Because remoting protocols have no way of presenting themselves
  3381. within the context of a <literal>HttpSession</literal>, it isn't
  3382. possible to rely on the <literal>HttpSession</literal>'s
  3383. <literal>HttpSessionIntegrationFilter.ACEGI_SECURITY_AUTHENTICATION_KEY</literal>
  3384. attribute to locate the <literal>CasAuthenticationToken</literal>.
  3385. Furthermore, because the CAS server invalidates a service ticket after
  3386. it has been validated by the <literal>TicketValidator</literal>,
  3387. presenting the same service ticket on subsequent requests will not
  3388. work. It is similarly very difficult to obtain a proxy-granting ticket
  3389. for a remoting protocol client, as they are often deployed on client
  3390. machines which rarely have HTTPS URLs that would be accessible to the
  3391. CAS server.</para>
  3392. <para>One obvious option is to not use CAS at all for remoting
  3393. protocol clients. However, this would eliminate many of the desirable
  3394. features of CAS.</para>
  3395. <para>As a middle-ground, the
  3396. <literal>CasAuthenticationProvider</literal> uses a
  3397. <literal>StatelessTicketCache</literal>. This is used solely for
  3398. requests with a principal equal to
  3399. <literal>CasProcessingFilter.CAS_STATELESS_IDENTIFIER</literal>. What
  3400. happens is the <literal>CasAuthenticationProvider</literal> will store
  3401. the resulting <literal>CasAuthenticationToken</literal> in the
  3402. <literal>StatelessTicketCache</literal>, keyed on the service ticket.
  3403. Accordingly, remoting protocol clients can present the same service
  3404. ticket and the <literal>CasAuthenticationProvider</literal> will not
  3405. need to contact the CAS server for validation (aside from the first
  3406. request).</para>
  3407. <para>The other aspect of advanced CAS usage involves creating proxy
  3408. tickets from the proxy-granting ticket. As indicated above, we
  3409. recommend you use CAS' <literal>ProxyTicketReceptor</literal> to
  3410. receive these tickets. The <literal>ProxyTicketReceptor</literal>
  3411. provides a static method that enables you to obtain a proxy ticket by
  3412. presenting the proxy-granting IOU ticket. You can obtain the
  3413. proxy-granting IOU ticket by calling
  3414. <literal>CasAuthenticationToken.getProxyGrantingTicketIou()</literal>.</para>
  3415. <para>It is hoped you find CAS integration easy and useful with Acegi
  3416. Security classes. Welcome to enterprise-wide single sign on!</para>
  3417. </sect1>
  3418. </chapter>
  3419. <chapter id="ca">
  3420. <title>Container Adapter Authentication</title>
  3421. <sect1 id="ca-overview">
  3422. <title>Overview</title>
  3423. <para>Very early versions of Acegi Security exclusively used Container
  3424. Adapters for interfacing authentication with end users. Whilst this
  3425. worked well, it required considerable time to support multiple
  3426. container versions and the configuration itself was relatively
  3427. time-consuming for developers. For this reason the HTTP Form
  3428. Authentication and HTTP Basic Authentication approaches were
  3429. developed, and are today recommended for almost all
  3430. applications.</para>
  3431. <para>Container Adapters enable Acegi Security to integrate directly
  3432. with the containers used to host end user applications. This
  3433. integration means that applications can continue to leverage the
  3434. authentication and authorization capabilities built into containers
  3435. (such as <literal>isUserInRole()</literal> and form-based or basic
  3436. authentication), whilst benefiting from the enhanced security
  3437. interception capabilities provided by Acegi Security (it should be
  3438. noted that Acegi Security also offers
  3439. <literal>ContextHolderAwareRequestWrapper</literal> to deliver
  3440. <literal>isUserInRole()</literal> and similar Servlet Specification
  3441. compatibility methods).</para>
  3442. <para>The integration between a container and Acegi Security is
  3443. achieved through an adapter. The adapter provides a
  3444. container-compatible user authentication provider, and needs to return
  3445. a container-compatible user object.</para>
  3446. <para>The adapter is instantiated by the container and is defined in a
  3447. container-specific configuration file. The adapter then loads a Spring
  3448. application context which defines the normal authentication manager
  3449. settings, such as the authentication providers that can be used to
  3450. authenticate the request. The application context is usually named
  3451. <literal>acegisecurity.xml</literal> and is placed in a
  3452. container-specific location.</para>
  3453. <para>Acegi Security currently supports Jetty, Catalina (Tomcat),
  3454. JBoss and Resin. Additional container adapters can easily be
  3455. written</para>
  3456. </sect1>
  3457. <sect1 id="ca-adapter">
  3458. <title>Adapter Authentication Provider</title>
  3459. <para>As is always the case, the container adapter generated
  3460. <literal>Authentication</literal> object still needs to be
  3461. authenticated by an <literal>AuthenticationManager</literal> when
  3462. requested to do so by the
  3463. <literal>AbstractSecurityInterceptor</literal>. The
  3464. <literal>AuthenticationManager</literal> needs to be certain the
  3465. adapter-provided <literal>Authentication</literal> object is valid and
  3466. was actually authenticated by a trusted adapter.</para>
  3467. <para>Adapters create <literal>Authentication</literal> objects which
  3468. are immutable and implement the <literal>AuthByAdapter</literal>
  3469. interface. These objects store the hash of a key that is defined by
  3470. the adapter. This allows the <literal>Authentication</literal> object
  3471. to be validated by the <literal>AuthByAdapterProvider</literal>. This
  3472. authentication provider is defined as follows:</para>
  3473. <para><programlisting>&lt;bean id="authByAdapterProvider" class="org.acegisecurity.adapters.AuthByAdapterProvider"&gt;
  3474. &lt;property name="key"&gt;&lt;value&gt;my_password&lt;/value&gt;&lt;/property&gt;
  3475. &lt;/bean&gt; </programlisting></para>
  3476. <para>The key must match the key that is defined in the
  3477. container-specific configuration file that starts the adapter. The
  3478. <literal>AuthByAdapterProvider</literal> automatically accepts as
  3479. valid any <literal>AuthByAdapter</literal> implementation that returns
  3480. the expected hash of the key.</para>
  3481. <para>To reiterate, this means the adapter will perform the initial
  3482. authentication using providers such as
  3483. <literal>DaoAuthenticationProvider</literal>, returning an
  3484. <literal>AuthByAdapter</literal> instance that contains a hash code of
  3485. the key. Later, when an application calls a security interceptor
  3486. managed resource, the <literal>AuthByAdapter</literal> instance in the
  3487. <literal>SecurityContext</literal> in the
  3488. <literal>SecurityContextHolder</literal> will be tested by the
  3489. application's <literal>AuthByAdapterProvider</literal>. There is no
  3490. requirement for additional authentication providers such as
  3491. <literal>DaoAuthenticationProvider</literal> within the
  3492. application-specific application context, as the only type of
  3493. <literal>Authentication</literal> instance that will be presented by
  3494. the application is from the container adapter.</para>
  3495. <para>Classloader issues are frequent with containers and the use of
  3496. container adapters illustrates this further. Each container requires a
  3497. very specific configuration. The installation instructions are
  3498. provided below. Once installed, please take the time to try the sample
  3499. application to ensure your container adapter is properly
  3500. configured.</para>
  3501. <para>When using container adapters with the
  3502. <literal>DaoAuthenticationProvider</literal>, ensure you set its
  3503. <literal>forcePrincipalAsString</literal> property to
  3504. <literal>true</literal>.</para>
  3505. </sect1>
  3506. <sect1 id="ca-jetty">
  3507. <title>Jetty</title>
  3508. <para>The following was tested with Jetty 4.2.18.</para>
  3509. <para><literal>$JETTY_HOME</literal> refers to the root of your Jetty
  3510. installation.</para>
  3511. <para>Edit your <literal>$JETTY_HOME/etc/jetty.xml</literal> file so
  3512. the <literal>&lt;Configure class&gt;</literal> section has a new
  3513. <literal>addRealm</literal> call:</para>
  3514. <para><programlisting>
  3515. &lt;Call name="addRealm"&gt;
  3516. &lt;Arg&gt;
  3517. &lt;New class="org.acegisecurity.adapters.jetty.JettyAcegiUserRealm"&gt;
  3518. &lt;Arg&gt;Spring Powered Realm&lt;/Arg&gt;
  3519. &lt;Arg&gt;my_password&lt;/Arg&gt;
  3520. &lt;Arg&gt;etc/acegisecurity.xml&lt;/Arg&gt;
  3521. &lt;/New&gt;
  3522. &lt;/Arg&gt;
  3523. &lt;/Call&gt;
  3524. </programlisting></para>
  3525. <para>Copy <literal>acegisecurity.xml</literal> into
  3526. <literal>$JETTY_HOME/etc</literal>.</para>
  3527. <para>Copy the following files into
  3528. <literal>$JETTY_HOME/ext</literal>:<itemizedlist>
  3529. <listitem>
  3530. <para><literal>aopalliance.jar</literal></para>
  3531. </listitem>
  3532. <listitem>
  3533. <para><literal>commons-logging.jar</literal></para>
  3534. </listitem>
  3535. <listitem>
  3536. <para><literal>spring.jar</literal></para>
  3537. </listitem>
  3538. <listitem>
  3539. <para><literal>acegi-security-jetty-XX.jar</literal></para>
  3540. </listitem>
  3541. <listitem>
  3542. <para><literal>commons-codec.jar</literal></para>
  3543. </listitem>
  3544. <listitem>
  3545. <para><literal>burlap.jar</literal></para>
  3546. </listitem>
  3547. <listitem>
  3548. <para><literal>hessian.jar</literal></para>
  3549. </listitem>
  3550. </itemizedlist></para>
  3551. <para>None of the above JAR files (or
  3552. <literal>acegi-security-XX.jar</literal>) should be in your
  3553. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  3554. in your <literal>web.xml</literal> does matter with Jetty. The
  3555. <literal>web.xml</literal> must express the same
  3556. <literal>&lt;realm-name&gt;</literal> as your
  3557. <literal>jetty.xml</literal> (in the example above, "Spring Powered
  3558. Realm").</para>
  3559. </sect1>
  3560. <sect1 id="ca-jboss">
  3561. <title>JBoss</title>
  3562. <para>The following was tested with JBoss 3.2.6.</para>
  3563. <para><literal>$JBOSS_HOME</literal> refers to the root of your JBoss
  3564. installation.</para>
  3565. <para>There are two different ways of making spring context available
  3566. to the Jboss integration classes.</para>
  3567. <para>The first approach is by editing your
  3568. <literal>$JBOSS_HOME/server/your_config/conf/login-config.xml</literal>
  3569. file so that it contains a new entry under the
  3570. <literal>&lt;Policy&gt;</literal> section:</para>
  3571. <para><programlisting>
  3572. &lt;application-policy name = "SpringPoweredRealm"&gt;
  3573. &lt;authentication&gt;
  3574. &lt;login-module code = "org.acegisecurity.adapters.jboss.JbossAcegiLoginModule"
  3575. flag = "required"&gt;
  3576. &lt;module-option name = "appContextLocation"&gt;acegisecurity.xml&lt;/module-option&gt;
  3577. &lt;module-option name = "key"&gt;my_password&lt;/module-option&gt;
  3578. &lt;/login-module&gt;
  3579. &lt;/authentication&gt;
  3580. &lt;/application-policy&gt;
  3581. </programlisting></para>
  3582. <para>Copy <literal>acegisecurity.xml</literal> into
  3583. <literal>$JBOSS_HOME/server/your_config/conf</literal>.</para>
  3584. <para>In this configuration <literal>acegisecurity.xml</literal>
  3585. contains the spring context definition including all the
  3586. authentication manager beans. You have to bear in mind though, that
  3587. <literal>SecurityContext</literal> is created and destroyed on each
  3588. login request, so the login operation might become costly.
  3589. Alternatively, the second approach is to use Spring singleton
  3590. capabilities through
  3591. <literal>org.springframework.beans.factory.access.SingletonBeanFactoryLocator</literal>.
  3592. The required configuration for this approach is:</para>
  3593. <para><programlisting>
  3594. &lt;application-policy name = "SpringPoweredRealm"&gt;
  3595. &lt;authentication&gt;
  3596. &lt;login-module code = "org.acegisecurity.adapters.jboss.JbossAcegiLoginModule"
  3597. flag = "required"&gt;
  3598. &lt;module-option name = "singletonId"&gt;springRealm&lt;/module-option&gt;
  3599. &lt;module-option name = "key"&gt;my_password&lt;/module-option&gt;
  3600. &lt;module-option name = "authenticationManager"&gt;authenticationManager&lt;/module-option&gt;
  3601. &lt;/login-module&gt;
  3602. &lt;/authentication&gt;
  3603. &lt;/application-policy&gt;
  3604. </programlisting></para>
  3605. <para>In the above code fragment,
  3606. <literal>authenticationManager</literal> is a helper property that
  3607. defines the expected name of the
  3608. <literal>AuthenticationManager</literal> in case you have several
  3609. defined in the IoC container. The <literal>singletonId</literal>
  3610. property references a bean defined in a
  3611. <literal>beanRefFactory.xml</literal> file. This file needs to be
  3612. available from anywhere on the JBoss classpath, including
  3613. <literal>$JBOSS_HOME/server/your_config/conf</literal>. The
  3614. <literal>beanRefFactory.xml</literal> contains the following
  3615. declaration:</para>
  3616. <para><programlisting>
  3617. &lt;beans&gt;
  3618. &lt;bean id="springRealm" singleton="true" lazy-init="true" class="org.springframework.context.support.ClassPathXmlApplicationContext"&gt;
  3619. &lt;constructor-arg&gt;
  3620. &lt;list&gt;
  3621. &lt;value&gt;acegisecurity.xml&lt;/value&gt;
  3622. &lt;/list&gt;
  3623. &lt;/constructor-arg&gt;
  3624. &lt;/bean&gt;
  3625. &lt;/beans&gt;
  3626. </programlisting></para>
  3627. <para>Finally, irrespective of the configuration approach you need to
  3628. copy the following files into
  3629. <literal>$JBOSS_HOME/server/your_config/lib</literal>:<itemizedlist>
  3630. <listitem>
  3631. <para><literal>aopalliance.jar</literal></para>
  3632. </listitem>
  3633. <listitem>
  3634. <para><literal>spring.jar</literal></para>
  3635. </listitem>
  3636. <listitem>
  3637. <para><literal>acegi-security-jboss-XX.jar</literal></para>
  3638. </listitem>
  3639. <listitem>
  3640. <para><literal>commons-codec.jar</literal></para>
  3641. </listitem>
  3642. <listitem>
  3643. <para><literal>burlap.jar</literal></para>
  3644. </listitem>
  3645. <listitem>
  3646. <para><literal>hessian.jar</literal></para>
  3647. </listitem>
  3648. </itemizedlist></para>
  3649. <para>None of the above JAR files (or
  3650. <literal>acegi-security-XX.jar</literal>) should be in your
  3651. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  3652. in your <literal>web.xml</literal> does not matter with JBoss.
  3653. However, your web application's
  3654. <literal>WEB-INF/jboss-web.xml</literal> must express the same
  3655. <literal>&lt;security-domain&gt;</literal> as your
  3656. <literal>login-config.xml</literal>. For example, to match the above
  3657. example, your <literal>jboss-web.xml</literal> would look like
  3658. this:</para>
  3659. <para><programlisting>
  3660. &lt;jboss-web&gt;
  3661. &lt;security-domain&gt;java:/jaas/SpringPoweredRealm&lt;/security-domain&gt;
  3662. &lt;/jboss-web&gt;</programlisting></para>
  3663. <para>JBoss is a widely-used container adapter (mostly due to the need
  3664. to support legacy EJBs), so please let us know if you have any
  3665. difficulties.</para>
  3666. </sect1>
  3667. <sect1 id="ca-resin">
  3668. <title>Resin</title>
  3669. <para>The following was tested with Resin 3.0.6.</para>
  3670. <para><literal>$RESIN_HOME</literal> refers to the root of your Resin
  3671. installation.</para>
  3672. <para>Resin provides several ways to support the container adapter. In
  3673. the instructions below we have elected to maximise consistency with
  3674. other container adapter configurations. This will allow Resin users to
  3675. simply deploy the sample application and confirm correct
  3676. configuration. Developers comfortable with Resin are naturally able to
  3677. use its capabilities to package the JARs with the web application
  3678. itself, and/or support single sign-on.</para>
  3679. <para>Copy the following files into
  3680. <literal>$RESIN_HOME/lib</literal>:<itemizedlist>
  3681. <listitem>
  3682. <para><literal>aopalliance.jar</literal></para>
  3683. </listitem>
  3684. <listitem>
  3685. <para><literal>commons-logging.jar</literal></para>
  3686. </listitem>
  3687. <listitem>
  3688. <para><literal>spring.jar</literal></para>
  3689. </listitem>
  3690. <listitem>
  3691. <para><literal>acegi-security-resin-XX.jar</literal></para>
  3692. </listitem>
  3693. <listitem>
  3694. <para><literal>commons-codec.jar</literal></para>
  3695. </listitem>
  3696. <listitem>
  3697. <para><literal>burlap.jar</literal></para>
  3698. </listitem>
  3699. <listitem>
  3700. <para><literal>hessian.jar</literal></para>
  3701. </listitem>
  3702. </itemizedlist></para>
  3703. <para>Unlike the container-wide <literal>acegisecurity.xml</literal>
  3704. files used by other container adapters, each Resin web application
  3705. will contain its own
  3706. <literal>WEB-INF/resin-acegisecurity.xml</literal> file. Each web
  3707. application will also contain a <literal>resin-web.xml</literal> file
  3708. which Resin uses to start the container adapter:</para>
  3709. <para><programlisting>
  3710. &lt;web-app&gt;
  3711. &lt;authenticator&gt;
  3712. &lt;type&gt;org.acegisecurity.adapters.resin.ResinAcegiAuthenticator&lt;/type&gt;
  3713. &lt;init&gt;
  3714. &lt;app-context-location&gt;WEB-INF/resin-acegisecurity.xml&lt;/app-context-location&gt;
  3715. &lt;key&gt;my_password&lt;/key&gt;
  3716. &lt;/init&gt;
  3717. &lt;/authenticator&gt;
  3718. &lt;/web-app&gt;
  3719. </programlisting></para>
  3720. <para>With the basic configuration provided above, none of the JAR
  3721. files listed (or <literal>acegi-security-XX.jar</literal>) should be
  3722. in your application's <literal>WEB-INF/lib</literal>. The realm name
  3723. indicated in your <literal>web.xml</literal> does not matter with
  3724. Resin, as the relevant authentication class is indicated by the
  3725. <literal>&lt;authenticator&gt;</literal> setting</para>
  3726. </sect1>
  3727. <sect1 id="ca-tomcat">
  3728. <title>Tomcat</title>
  3729. <para>The following was tested with Jakarta Tomcat 4.1.30 and
  3730. 5.0.19.</para>
  3731. <para><literal>$CATALINA_HOME</literal> refers to the root of your
  3732. Catalina (Tomcat) installation.</para>
  3733. <para>Edit your <literal>$CATALINA_HOME/conf/server.xml</literal> file
  3734. so the <literal>&lt;Engine&gt;</literal> section contains only one
  3735. active <literal>&lt;Realm&gt;</literal> entry. An example realm
  3736. entry:</para>
  3737. <para><programlisting> &lt;Realm className="org.acegisecurity.adapters.catalina.CatalinaAcegiUserRealm"
  3738. appContextLocation="conf/acegisecurity.xml"
  3739. key="my_password" /&gt;</programlisting></para>
  3740. <para>Be sure to remove any other <literal>&lt;Realm&gt;</literal>
  3741. entry from your <literal>&lt;Engine&gt;</literal> section.</para>
  3742. <para>Copy <literal>acegisecurity.xml</literal> into
  3743. <literal>$CATALINA_HOME/conf</literal>.</para>
  3744. <para>Copy <literal>acegi-security-catalina-XX.jar</literal> into
  3745. <literal>$CATALINA_HOME/server/lib</literal>.</para>
  3746. <para>Copy the following files into
  3747. <literal>$CATALINA_HOME/common/lib</literal>:</para>
  3748. <itemizedlist>
  3749. <listitem>
  3750. <para><literal>aopalliance.jar</literal></para>
  3751. </listitem>
  3752. <listitem>
  3753. <para><literal>spring.jar</literal></para>
  3754. </listitem>
  3755. <listitem>
  3756. <para><literal>commons-codec.jar</literal></para>
  3757. </listitem>
  3758. <listitem>
  3759. <para><literal>burlap.jar</literal></para>
  3760. </listitem>
  3761. <listitem>
  3762. <para><literal>hessian.jar</literal></para>
  3763. </listitem>
  3764. </itemizedlist>
  3765. <para>None of the above JAR files (or
  3766. <literal>acegi-security-XX.jar</literal>) should be in your
  3767. application's <literal>WEB-INF/lib</literal>. The realm name indicated
  3768. in your <literal>web.xml</literal> does not matter with
  3769. Catalina.</para>
  3770. <para>We have received reports of problems using this Container
  3771. Adapter with Mac OS X. A work-around is to use a script such as
  3772. follows:</para>
  3773. <para><programlisting>#!/bin/sh
  3774. export CATALINA_HOME="/Library/Tomcat"
  3775. export JAVA_HOME="/Library/Java/Home"
  3776. cd /
  3777. $CATALINA_HOME/bin/startup.sh</programlisting></para>
  3778. <para>Finally, restart Tomcat.</para>
  3779. </sect1>
  3780. </chapter>
  3781. </part>
  3782. <part id="authorization">
  3783. <title>Authorization</title>
  3784. <partintro>
  3785. <para>The advanced authorization capabilities within Acegi Security
  3786. represent one of the most compelling reasons for its popularity.
  3787. Irrespective of how you choose to authenticate - whether using an Acegi
  3788. Security-provided mechanism and provider, or integrating with a
  3789. container or other non-Acegi Security authentication authority - you
  3790. will find the authorization services can be used within your application
  3791. in a consistent and simple way.</para>
  3792. <para>In this part we'll explore the different
  3793. <literal>AbstractSecurityInterceptor</literal> implementations, which
  3794. were introduced in Part I. We then move on to explore how to fine-tune
  3795. authorization through use of domain access control lists.</para>
  3796. </partintro>
  3797. <chapter id="authorization-common">
  3798. <title>Common Authorization Concepts</title>
  3799. <sect1 id="authorities">
  3800. <title>Authorities</title>
  3801. <para>As briefly mentioned in the Authentication section, all
  3802. <literal>Authentication</literal> implementations are required to
  3803. store an array of <literal>GrantedAuthority</literal> objects. These
  3804. represent the authorities that have been granted to the principal. The
  3805. <literal>GrantedAuthority</literal> objects are inserted into the
  3806. <literal>Authentication</literal> object by the
  3807. <literal>AuthenticationManager</literal> and are later read by
  3808. <literal>AccessDecisionManager</literal>s when making authorization
  3809. decisions.</para>
  3810. <para><literal>GrantedAuthority</literal> is an interface with only
  3811. one method:</para>
  3812. <para><programlisting>public String getAuthority();</programlisting></para>
  3813. <para>This method allows <literal>AccessDecisionManager</literal>s to
  3814. obtain a precise <literal>String</literal> representation of the
  3815. <literal>GrantedAuthority</literal>. By returning a representation as
  3816. a <literal>String</literal>, a <literal>GrantedAuthority</literal> can
  3817. be easily "read" by most <literal>AccessDecisionManager</literal>s. If
  3818. a <literal>GrantedAuthority</literal> cannot be precisely represented
  3819. as a <literal>String</literal>, the
  3820. <literal>GrantedAuthority</literal> is considered "complex" and
  3821. <literal>getAuthority()</literal> must return
  3822. <literal>null</literal>.</para>
  3823. <para>An example of a "complex" <literal>GrantedAuthority</literal>
  3824. would be an implementation that stores a list of operations and
  3825. authority thresholds that apply to different customer account numbers.
  3826. Representing this complex <literal>GrantedAuthority</literal> as a
  3827. <literal>String</literal> would be quite complex, and as a result the
  3828. <literal>getAuthority()</literal> method should return
  3829. <literal>null</literal>. This will indicate to any
  3830. <literal>AccessDecisionManager</literal> that it will need to
  3831. specifically support the <literal>GrantedAuthority</literal>
  3832. implementation in order to understand its contents.</para>
  3833. <para>Acegi Security includes one concrete
  3834. <literal>GrantedAuthority</literal> implementation,
  3835. <literal>GrantedAuthorityImpl</literal>. This allows any
  3836. user-specified <literal>String</literal> to be converted into a
  3837. <literal>GrantedAuthority</literal>. All
  3838. <literal>AuthenticationProvider</literal>s included with the security
  3839. architecture use <literal>GrantedAuthorityImpl</literal> to populate
  3840. the <literal>Authentication</literal> object.</para>
  3841. </sect1>
  3842. <sect1 id="pre-invocation">
  3843. <title>Pre-Invocation Handling</title>
  3844. <para>The <literal>AccessDecisionManager</literal> is called by the
  3845. <literal>AbstractSecurityInterceptor</literal> and is responsible for
  3846. making final access control decisions. The
  3847. <literal>AccessDecisionManager</literal> interface contains three
  3848. methods:</para>
  3849. <para><programlisting>public void decide(Authentication authentication, Object object, ConfigAttributeDefinition config) throws AccessDeniedException;
  3850. public boolean supports(ConfigAttribute attribute);
  3851. public boolean supports(Class clazz);</programlisting></para>
  3852. <para>As can be seen from the first method, the
  3853. <literal>AccessDecisionManager</literal> is passed via method
  3854. parameters all information that is likely to be of value in assessing
  3855. an authorization decision. In particular, passing the secure
  3856. <literal>Object</literal> enables those arguments contained in the
  3857. actual secure object invocation to be inspected. For example, let's
  3858. assume the secure object was a <literal>MethodInvocation</literal>. It
  3859. would be easy to query the <literal>MethodInvocation</literal> for any
  3860. <literal>Customer</literal> argument, and then implement some sort of
  3861. security logic in the <literal>AccessDecisionManager</literal> to
  3862. ensure the principal is permitted to operate on that customer.
  3863. Implementations are expected to throw an
  3864. <literal>AccessDeniedException</literal> if access is denied.</para>
  3865. <para>The <literal>supports(ConfigAttribute)</literal> method is
  3866. called by the <literal>AbstractSecurityInterceptor</literal> at
  3867. startup time to determine if the
  3868. <literal>AccessDecisionManager</literal> can process the passed
  3869. <literal>ConfigAttribute</literal>. The
  3870. <literal>supports(Class)</literal> method is called by a security
  3871. interceptor implementation to ensure the configured
  3872. <literal>AccessDecisionManager</literal> supports the type of secure
  3873. object that the security interceptor will present.</para>
  3874. <para>Whilst users can implement their own
  3875. <literal>AccessDecisionManager</literal> to control all aspects of
  3876. authorization, Acegi Security includes several
  3877. <literal>AccessDecisionManager</literal> implementations that are
  3878. based on voting. Figure 4 illustrates the relevant classes.</para>
  3879. <para><mediaobject>
  3880. <imageobject role="html">
  3881. <imagedata align="center"
  3882. fileref="images/AccessDecisionVoting.gif"
  3883. format="GIF" />
  3884. </imageobject>
  3885. <caption>
  3886. <para>Figure 4: Voting Decision Manager</para>
  3887. </caption>
  3888. </mediaobject></para>
  3889. <para>Using this approach, a series of
  3890. <literal>AccessDecisionVoter</literal> implementations are polled on
  3891. an authorization decision. The
  3892. <literal>AccessDecisionManager</literal> then decides whether or not
  3893. to throw an <literal>AccessDeniedException</literal> based on its
  3894. assessment of the votes.</para>
  3895. <para>The <literal>AccessDecisionVoter</literal> interface has three
  3896. methods:</para>
  3897. <para><programlisting>public int vote(Authentication authentication, Object object, ConfigAttributeDefinition config);
  3898. public boolean supports(ConfigAttribute attribute);
  3899. public boolean supports(Class clazz);</programlisting></para>
  3900. <para>Concrete implementations return an <literal>int</literal>, with
  3901. possible values being reflected in the
  3902. <literal>AccessDecisionVoter</literal> static fields
  3903. <literal>ACCESS_ABSTAIN</literal>, <literal>ACCESS_DENIED</literal>
  3904. and <literal>ACCESS_GRANTED</literal>. A voting implementation will
  3905. return <literal>ACCESS_ABSTAIN</literal> if it has no opinion on an
  3906. authorization decision. If it does have an opinion, it must return
  3907. either <literal>ACCESS_DENIED</literal> or
  3908. <literal>ACCESS_GRANTED</literal>.</para>
  3909. <para>There are three concrete
  3910. <literal>AccessDecisionManager</literal>s provided with Acegi Security
  3911. that tally the votes. The <literal>ConsensusBased</literal>
  3912. implementation will grant or deny access based on the consensus of
  3913. non-abstain votes. Properties are provided to control behavior in the
  3914. event of an equality of votes or if all votes are abstain. The
  3915. <literal>AffirmativeBased</literal> implementation will grant access
  3916. if one or more <literal>ACCESS_GRANTED</literal> votes were received
  3917. (ie a deny vote will be ignored, provided there was at least one grant
  3918. vote). Like the <literal>ConsensusBased</literal> implementation,
  3919. there is a parameter that controls the behavior if all voters abstain.
  3920. The <literal>UnanimousBased</literal> provider expects unanimous
  3921. <literal>ACCESS_GRANTED</literal> votes in order to grant access,
  3922. ignoring abstains. It will deny access if there is any
  3923. <literal>ACCESS_DENIED</literal> vote. Like the other implementations,
  3924. there is a parameter that controls the behaviour if all voters
  3925. abstain.</para>
  3926. <para>It is possible to implement a custom
  3927. <literal>AccessDecisionManager</literal> that tallies votes
  3928. differently. For example, votes from a particular
  3929. <literal>AccessDecisionVoter</literal> might receive additional
  3930. weighting, whilst a deny vote from a particular voter may have a veto
  3931. effect.</para>
  3932. <para>There are two concrete <literal>AccessDecisionVoter</literal>
  3933. implementations provided with Acegi Security. The
  3934. <literal>RoleVoter</literal> class will vote if any ConfigAttribute
  3935. begins with <literal>ROLE_</literal>. It will vote to grant access if
  3936. there is a <literal>GrantedAuthority</literal> which returns a
  3937. <literal>String</literal> representation (via the
  3938. <literal>getAuthority()</literal> method) exactly equal to one or more
  3939. <literal>ConfigAttributes</literal> starting with
  3940. <literal>ROLE_</literal>. If there is no exact match of any
  3941. <literal>ConfigAttribute</literal> starting with
  3942. <literal>ROLE_</literal>, the <literal>RoleVoter</literal> will vote
  3943. to deny access. If no <literal>ConfigAttribute</literal> begins with
  3944. <literal>ROLE_</literal>, the voter will abstain.
  3945. <literal>RoleVoter</literal> is case sensitive on comparisons as well
  3946. as the <literal>ROLE_</literal> prefix.</para>
  3947. <para><literal>BasicAclEntryVoter</literal> is the other concrete
  3948. voter included with Acegi Security. It integrates with Acegi
  3949. Security's <literal>AclManager</literal> (discussed later). This voter
  3950. is designed to have multiple instances in the same application
  3951. context, such as:</para>
  3952. <para><programlisting>&lt;bean id="aclContactReadVoter" class="org.acegisecurity.vote.BasicAclEntryVoter"&gt;
  3953. &lt;property name="processConfigAttribute"&gt;&lt;value&gt;ACL_CONTACT_READ&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.READ"/&gt;
  3960. &lt;/list&gt;
  3961. &lt;/property&gt;
  3962. &lt;/bean&gt;
  3963. &lt;bean id="aclContactDeleteVoter" class="org.acegisecurity.vote.BasicAclEntryVoter"&gt;
  3964. &lt;property name="processConfigAttribute"&gt;&lt;value&gt;ACL_CONTACT_DELETE&lt;/value&gt;&lt;/property&gt;
  3965. &lt;property name="processDomainObjectClass"&gt;&lt;value&gt;sample.contact.Contact&lt;/value&gt;&lt;/property&gt;
  3966. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  3967. &lt;property name="requirePermission"&gt;
  3968. &lt;list&gt;
  3969. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  3970. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.DELETE"/&gt;
  3971. &lt;/list&gt;
  3972. &lt;/property&gt;
  3973. &lt;/bean&gt; </programlisting></para>
  3974. <para>In the above example, you'd define
  3975. <literal>ACL_CONTACT_READ</literal> or
  3976. <literal>ACL_CONTACT_DELETE</literal> against some methods on a
  3977. <literal>MethodSecurityInterceptor</literal> or
  3978. <literal>AspectJSecurityInterceptor</literal>. When those methods are
  3979. invoked, the above applicable voter defined above would vote to grant
  3980. or deny access. The voter would look at the method invocation to
  3981. locate the first argument of type
  3982. <literal>sample.contact.Contact</literal>, and then pass that
  3983. <literal>Contact</literal> to the <literal>AclManager</literal>. The
  3984. <literal>AclManager</literal> will then return an access control list
  3985. (ACL) that applies to the current <literal>Authentication</literal>.
  3986. Assuming that ACL contains one of the listed
  3987. <literal>requirePermission</literal>s, the voter will vote to grant
  3988. access. If the ACL does not contain one of the permissions defined
  3989. against the voter, the voter will vote to deny access.
  3990. <literal>BasicAclEntryVoter</literal> is an important class as it
  3991. allows you to build truly complex applications with domain object
  3992. security entirely defined in the application context. If you're
  3993. interested in learning more about Acegi Security's ACL capabilities
  3994. and how best to apply them, please see the ACL and "After Invocation"
  3995. sections of this reference guide, and the Contacts sample
  3996. application.</para>
  3997. <para>It is also possible to implement a custom
  3998. <literal>AccessDecisionVoter</literal>. Several examples are provided
  3999. in Acegi Security unit tests, including
  4000. <literal>ContactSecurityVoter</literal> and
  4001. <literal>DenyVoter</literal>. The
  4002. <literal>ContactSecurityVoter</literal> abstains from voting decisions
  4003. where a <literal>CONTACT_OWNED_BY_CURRENT_USER</literal>
  4004. <literal>ConfigAttribute</literal> is not found. If voting, it queries
  4005. the <literal>MethodInvocation</literal> to extract the owner of the
  4006. <literal>Contact</literal> object that is subject of the method call.
  4007. It votes to grant access if the <literal>Contact</literal> owner
  4008. matches the principal presented in the
  4009. <literal>Authentication</literal> object. It could have just as easily
  4010. compared the <literal>Contact</literal> owner with some
  4011. <literal>GrantedAuthority</literal> the
  4012. <literal>Authentication</literal> object presented. All of this is
  4013. achieved with relatively few lines of code and demonstrates the
  4014. flexibility of the authorization model.</para>
  4015. <para>TODO: Remove references to the old ACL package when it's
  4016. deprecated, and have all references to the replacement package limited
  4017. to the chapter describing the new ACL implementation.</para>
  4018. </sect1>
  4019. <sect1 id="after-invocation">
  4020. <title>After Invocation Handling</title>
  4021. <para>Whilst the <literal>AccessDecisionManager</literal> is called by
  4022. the <literal>AbstractSecurityInterceptor</literal> before proceeding
  4023. with the secure object invocation, some applications need a way of
  4024. modifying the object actually returned by the secure object
  4025. invocation. Whilst you could easily implement your own AOP concern to
  4026. achieve this, Acegi Security provides a convenient hook that has
  4027. several concrete implementations that integrate with its ACL
  4028. capabilities.</para>
  4029. <para>Figure 5 illustrates Acegi Security's
  4030. <literal>AfterInvocationManager</literal> and its concrete
  4031. implementations.</para>
  4032. <para><mediaobject>
  4033. <imageobject role="html">
  4034. <imagedata align="center" fileref="images/AfterInvocation.gif"
  4035. format="GIF" />
  4036. </imageobject>
  4037. <caption>
  4038. <para>Figure 5: After Invocation Implementation</para>
  4039. </caption>
  4040. </mediaobject></para>
  4041. <para>Like many other parts of Acegi Security,
  4042. <literal>AfterInvocationManager</literal> has a single concrete
  4043. implementation, <literal>AfterInvocationProvider</literal>, which
  4044. polls a list of <literal>AfterInvocationProvider</literal>s. Each
  4045. <literal>AfterInvocationProvider</literal> is allowed to modify the
  4046. return object or throw an <literal>AccessDeniedException</literal>.
  4047. Indeed multiple providers can modify the object, as the result of the
  4048. previous provider is passed to the next in the list. Let's now
  4049. consider our ACL-aware implementations of
  4050. <literal>AfterInvocationProvider</literal>.</para>
  4051. <para>Please be aware that if you're using
  4052. <literal>AfterInvocationManager</literal>, you will still need
  4053. configuration attributes that allow the
  4054. <literal>MethodSecurityInterceptor</literal>'s
  4055. <literal>AccessDecisionManager</literal> to allow an operation. If
  4056. you're using the typical Acegi Security included
  4057. <literal>AccessDecisionManager</literal> implementations, having no
  4058. configuration attributes defined for a particular secure method
  4059. invocation will cause each <literal>AccessDecisionVoter</literal> to
  4060. abstain from voting. In turn, if the
  4061. <literal>AccessDecisionManager</literal> property
  4062. "<literal>allowIfAllAbstainDecisions</literal>" is
  4063. <literal>false</literal>, an <literal>AccessDeniedException</literal>
  4064. will be thrown. You may avoid this potential issue by either (i)
  4065. setting "<literal>allowIfAllAbstainDecisions</literal>" to
  4066. <literal>true</literal> (although this is generally not recommended)
  4067. or (ii) simply ensure that there is at least one configuration
  4068. attribute that an <literal>AccessDecisionVoter</literal> will vote to
  4069. grant access for. This latter (recommended) approach is usually
  4070. achieved through a <literal>ROLE_USER</literal> or
  4071. <literal>ROLE_AUTHENTICATED</literal> configuration attribute</para>
  4072. <sect2 id="after-invocation-acl-aware">
  4073. <title>ACL-Aware AfterInvocationProviders</title>
  4074. <para>TODO: This section will be removed when we deprecate the
  4075. existing ACL package. It should be discussed with the context of the
  4076. ACL implementation chapter instead.</para>
  4077. <para>A common services layer method we've all written at one stage
  4078. or another looks like this:</para>
  4079. <para><programlisting>public Contact getById(Integer id);</programlisting></para>
  4080. <para>Quite often, only principals with permission to read the
  4081. <literal>Contact</literal> should be allowed to obtain it. In this
  4082. situation the <literal>AccessDecisionManager</literal> approach
  4083. provided by the <literal>AbstractSecurityInterceptor</literal> will
  4084. not suffice. This is because the identity of the
  4085. <literal>Contact</literal> is all that is available before the
  4086. secure object is invoked. The
  4087. <literal>BasicAclAfterInvocationProvider</literal> delivers a
  4088. solution, and is configured as follows:</para>
  4089. <para><programlisting>&lt;bean id="afterAclRead" class="org.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationProvider"&gt;
  4090. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  4091. &lt;property name="requirePermission"&gt;
  4092. &lt;list&gt;
  4093. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  4094. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  4095. &lt;/list&gt;
  4096. &lt;/property&gt;
  4097. &lt;/bean&gt; </programlisting></para>
  4098. <para>In the above example, the <literal>Contact</literal> will be
  4099. retrieved and passed to the
  4100. <literal>BasicAclEntryAfterInvocationProvider</literal>. The
  4101. provider will thrown an <literal>AccessDeniedException</literal> if
  4102. one of the listed <literal>requirePermission</literal>s is not held
  4103. by the <literal>Authentication</literal>. The
  4104. <literal>BasicAclEntryAfterInvocationProvider</literal> queries the
  4105. <literal>AclManager</literal> to determine the ACL that applies for
  4106. this domain object to this <literal>Authentication</literal>.</para>
  4107. <para>Similar to the
  4108. <literal>BasicAclEntryAfterInvocationProvider</literal> is
  4109. <literal>BasicAclEntryAfterInvocationCollectionFilteringProvider</literal>.
  4110. It is designed to remove <literal>Collection</literal> or array
  4111. elements for which a principal does not have access. It never thrown
  4112. an <literal>AccessDeniedException</literal> - simply silently
  4113. removes the offending elements. The provider is configured as
  4114. follows:</para>
  4115. <para><programlisting>&lt;bean id="afterAclCollectionRead" class="org.acegisecurity.afterinvocation.BasicAclEntryAfterInvocationCollectionFilteringProvider"&gt;
  4116. &lt;property name="aclManager"&gt;&lt;ref local="aclManager"/&gt;&lt;/property&gt;
  4117. &lt;property name="requirePermission"&gt;
  4118. &lt;list&gt;
  4119. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.ADMINISTRATION"/&gt;
  4120. &lt;ref local="org.acegisecurity.acl.basic.SimpleAclEntry.READ"/&gt;
  4121. &lt;/list&gt;
  4122. &lt;/property&gt;
  4123. &lt;/bean&gt; </programlisting></para>
  4124. <para>As you can imagine, the returned <literal>Object</literal>
  4125. must be a <literal>Collection</literal> or array for this provider
  4126. to operate. It will remove any element if the
  4127. <literal>AclManager</literal> indicates the
  4128. <literal>Authentication</literal> does not hold one of the listed
  4129. <literal>requirePermission</literal>s.</para>
  4130. <para>The Contacts sample application demonstrates these two
  4131. <literal>AfterInvocationProvider</literal>s.</para>
  4132. </sect2>
  4133. </sect1>
  4134. <sect1 id="authorization-taglibs">
  4135. <title>Authorization Tag Libraries</title>
  4136. <para><literal>AuthorizeTag</literal> is used to include content if
  4137. the current principal holds certain
  4138. <literal>GrantedAuthority</literal>s.</para>
  4139. <para>The following JSP fragment illustrates how to use the
  4140. <literal>AuthorizeTag</literal>:</para>
  4141. <para><programlisting>&lt;authz:authorize ifAllGranted="ROLE_SUPERVISOR"&gt;
  4142. &lt;td&gt;
  4143. &lt;A HREF="del.htm?id=&lt;c:out value="${contact.id}"/&gt;"&gt;Del&lt;/A&gt;
  4144. &lt;/td&gt;
  4145. &lt;/authz:authorize&gt; </programlisting></para>
  4146. <para>This tag would cause the tag's body to be output if the
  4147. principal has been granted ROLE_SUPERVISOR.</para>
  4148. <para>The <literal>authz:authorize</literal> tag declares the
  4149. following attributes:</para>
  4150. <para><itemizedlist spacing="compact">
  4151. <listitem>
  4152. <para><literal>ifAllGranted</literal>: All the listed roles must
  4153. be granted for the tag to output its body.</para>
  4154. </listitem>
  4155. <listitem>
  4156. <para><literal>ifAnyGranted</literal>: Any of the listed roles
  4157. must be granted for the tag to output its body.</para>
  4158. </listitem>
  4159. <listitem>
  4160. <para><literal>ifNotGranted</literal>: None of the listed roles
  4161. must be granted for the tag to output its body.</para>
  4162. </listitem>
  4163. </itemizedlist></para>
  4164. <para>You'll note that in each attribute you can list multiple roles.
  4165. Simply separate the roles using a comma. The
  4166. <literal>authorize</literal> tag ignores whitespace in
  4167. attributes.</para>
  4168. <para>The tag library logically ANDs all of it's parameters together.
  4169. This means that if you combine two or more attributes, all attributes
  4170. must be true for the tag to output it's body. Don't add an
  4171. <literal>ifAllGranted="ROLE_SUPERVISOR"</literal>, followed by an
  4172. <literal>ifNotGranted="ROLE_SUPERVISOR"</literal>, or you'll be
  4173. surprised to never see the tag's body.</para>
  4174. <para>By requiring all attributes to return true, the authorize tag
  4175. allows you to create more complex authorization scenarios. For
  4176. example, you could declare an
  4177. <literal>ifAllGranted="ROLE_SUPERVISOR"</literal> and an
  4178. <literal>ifNotGranted="ROLE_NEWBIE_SUPERVISOR"</literal> in the same
  4179. tag, in order to prevent new supervisors from seeing the tag body.
  4180. However it would no doubt be simpler to use
  4181. <literal>ifAllGranted="ROLE_EXPERIENCED_SUPERVISOR"</literal> rather
  4182. than inserting NOT conditions into your design.</para>
  4183. <para>One last item: the tag verifies the authorizations in a specific
  4184. order: first <literal>ifNotGranted</literal>, then
  4185. <literal>ifAllGranted</literal>, and finally, <literal>if
  4186. AnyGranted</literal>.</para>
  4187. <para><literal>AclTag</literal> is used to include content if the
  4188. current principal has a ACL to the indicated domain object.</para>
  4189. <para>The following JSP fragment illustrates how to use the
  4190. <literal>AclTag</literal>:</para>
  4191. <para><programlisting>
  4192. &lt;authz:acl domainObject="${contact}" hasPermission="16,1"&gt;
  4193. &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;
  4194. &lt;/authz:acl&gt;
  4195. </programlisting></para>
  4196. <para>This tag would cause the tag's body to be output if the
  4197. principal holds either permission 16 or permission 1 for the "contact"
  4198. domain object. The numbers are actually integers that are used with
  4199. <literal>AbstractBasicAclEntry</literal> bit masking. Please refer to
  4200. the ACL section of this reference guide to understand more about the
  4201. ACL capabilities of Acegi Security</para>
  4202. </sect1>
  4203. </chapter>
  4204. <chapter id="secure-object-impls">
  4205. <title>Secure Object Implementations</title>
  4206. <sect1 id="aop-alliance">
  4207. <title>AOP Alliance (MethodInvocation) Security Interceptor</title>
  4208. <para>To secure <literal>MethodInvocation</literal>s, developers
  4209. simply add a properly configured
  4210. <literal>MethodSecurityInterceptor</literal> into the application
  4211. context. Next the beans requiring security are chained into the
  4212. interceptor. This chaining is accomplished using Spring’s
  4213. <literal>ProxyFactoryBean</literal> or
  4214. <literal>BeanNameAutoProxyCreator</literal>, as commonly used by many
  4215. other parts of Spring (refer to the sample application for examples).
  4216. Alternatively, Acegi Security provides a
  4217. <literal>MethodDefinitionSourceAdvisor</literal> which may be used
  4218. with Spring's <literal>DefaultAdvisorAutoProxyCreator</literal> to
  4219. automatically chain the security interceptor in front of any beans
  4220. defined against the <literal>MethodSecurityInterceptor</literal>. The
  4221. <literal>MethodSecurityInterceptor</literal> itself is configured as
  4222. follows:</para>
  4223. <programlisting>&lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  4224. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
  4225. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4226. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4227. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4228. &lt;property name="afterInvocationManager"&gt;&lt;ref bean="afterInvocationManager"/&gt;&lt;/property&gt;
  4229. &lt;property name="objectDefinitionSource"&gt;
  4230. &lt;value&gt;
  4231. org.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER
  4232. org.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER
  4233. &lt;/value&gt;
  4234. &lt;/property&gt;
  4235. &lt;/bean&gt; </programlisting>
  4236. <para>As shown above, the <literal>MethodSecurityInterceptor</literal>
  4237. is configured with a reference to an
  4238. <literal>AuthenticationManager</literal>,
  4239. <literal>AccessDecisionManager</literal> and
  4240. <literal>RunAsManager</literal>, which are each discussed in separate
  4241. sections below. In this case we've also defined an
  4242. <literal>AfterInvocationManager</literal>, although this is entirely
  4243. optional. The <literal>MethodSecurityInterceptor</literal> is also
  4244. configured with configuration attributes that apply to different
  4245. method signatures. A full discussion of configuration attributes is
  4246. provided in the High Level Design section of this document.</para>
  4247. <para>The <literal>MethodSecurityInterceptor</literal> can be
  4248. configured with configuration attributes in three ways. The first is
  4249. via a property editor and the application context, which is shown
  4250. above. The second is via defining the configuration attributes in your
  4251. source code using Jakarta Commons Attributes or Java 5 Annotations.
  4252. The third is via writing your own
  4253. <literal>ObjectDefinitionSource</literal>, although this is beyond the
  4254. scope of this document. Irrespective of the approach used, the
  4255. <literal>ObjectDefinitionSource</literal> is responsible for returning
  4256. a <literal>ConfigAttributeDefinition</literal> object that contains
  4257. all of the configuration attributes associated with a single secure
  4258. method.</para>
  4259. <para>It should be noted that the
  4260. <literal>MethodSecurityInterceptor.setObjectDefinitionSource()</literal>
  4261. method actually expects an instance of
  4262. <literal>MethodDefinitionSource</literal>. This is a marker interface
  4263. which subclasses <literal>ObjectDefinitionSource</literal>. It simply
  4264. denotes the <literal>ObjectDefinitionSource</literal> understands
  4265. <literal>MethodInvocation</literal>s. In the interests of simplicity
  4266. we'll continue to refer to the
  4267. <literal>MethodDefinitionSource</literal> as an
  4268. <literal>ObjectDefinitionSource</literal>, as the distinction is of
  4269. little relevance to most users of the
  4270. <literal>MethodSecurityInterceptor</literal>.</para>
  4271. <para>If using the application context property editor approach (as
  4272. shown above), commas are used to delimit the different configuration
  4273. attributes that apply to a given method pattern. Each configuration
  4274. attribute is assigned into its own <literal>SecurityConfig</literal>
  4275. object. The <literal>SecurityConfig</literal> object is discussed in
  4276. the High Level Design section.</para>
  4277. <para>If you are using the Jakarta Commons Attributes approach, your
  4278. bean context will be configured differently:</para>
  4279. <programlisting>&lt;bean id="attributes" class="org.springframework.metadata.commons.CommonsAttributes"/&gt;
  4280. &lt;bean id="objectDefinitionSource" class="org.acegisecurity.intercept.method.MethodDefinitionAttributes"&gt;
  4281. &lt;property name="attributes"&gt;&lt;ref local="attributes"/&gt;&lt;/property&gt;
  4282. &lt;/bean&gt;
  4283. &lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  4284. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  4285. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4286. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4287. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4288. &lt;property name="objectDefinitionSource"&gt;&lt;ref bean="objectDefinitionSource"/&gt;&lt;/property&gt;
  4289. &lt;/bean&gt; </programlisting>
  4290. <para>In addition, your source code will contain Jakarta Commons
  4291. Attributes tags that refer to a concrete implementation of
  4292. <literal>ConfigAttribute</literal>. The following example uses the
  4293. <literal>SecurityConfig</literal> implementation to represent the
  4294. configuration attributes, and results in the same security
  4295. configuration as provided by the property editor approach
  4296. above:</para>
  4297. <programlisting>public interface BankManager {
  4298. /**
  4299. * @@SecurityConfig("ROLE_SUPERVISOR")
  4300. * @@SecurityConfig("RUN_AS_SERVER")
  4301. */
  4302. public void deleteSomething(int id);
  4303. /**
  4304. * @@SecurityConfig("ROLE_SUPERVISOR")
  4305. * @@SecurityConfig("RUN_AS_SERVER")
  4306. */
  4307. public void deleteAnother(int id);
  4308. /**
  4309. * @@SecurityConfig("ROLE_TELLER")
  4310. * @@SecurityConfig("ROLE_SUPERVISOR")
  4311. * @@SecurityConfig("BANKSECURITY_CUSTOMER")
  4312. * @@SecurityConfig("RUN_AS_SERVER")
  4313. */
  4314. public float getBalance(int id);
  4315. }</programlisting>
  4316. <para>If you are using the Acegi Security Java 5 Annotations approach,
  4317. your bean context will be configured as follows:</para>
  4318. <programlisting>&lt;bean id="attributes" class="org.acegisecurity.annotation.SecurityAnnotationAttributes"/&gt;
  4319. &lt;bean id="objectDefinitionSource" class="org.acegisecurity.intercept.method.MethodDefinitionAttributes"&gt;
  4320. &lt;property name="attributes"&gt;&lt;ref local="attributes"/&gt;&lt;/property&gt;
  4321. &lt;/bean&gt;
  4322. &lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor"&gt;
  4323. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  4324. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4325. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4326. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4327. &lt;property name="objectDefinitionSource"&gt;&lt;ref bean="objectDefinitionSource"/&gt;&lt;/property&gt;
  4328. &lt;/bean&gt; </programlisting>
  4329. <para>In addition, your source code will contain Acegi Java 5 Security
  4330. Annotations that represent the <literal>ConfigAttribute</literal>. The
  4331. following example uses the <literal>@Secured</literal> annotations to
  4332. represent the configuration attributes, and results in the same
  4333. security configuration as provided by the property editor
  4334. approach:</para>
  4335. <programlisting>import org.acegisecurity.annotation.Secured;
  4336. public interface BankManager {
  4337. /**
  4338. * Delete something
  4339. */
  4340. @Secured({"ROLE_SUPERVISOR","RUN_AS_SERVER" })
  4341. public void deleteSomething(int id);
  4342. /**
  4343. * Delete another
  4344. */
  4345. @Secured({"ROLE_SUPERVISOR","RUN_AS_SERVER" })
  4346. public void deleteAnother(int id);
  4347. /**
  4348. * Get balance
  4349. */
  4350. @Secured({"ROLE_TELLER","ROLE_SUPERVISOR","BANKSECURITY_CUSTOMER","RUN_AS_SERVER" })
  4351. public float getBalance(int id);
  4352. }</programlisting>
  4353. <para>You might have noticed the
  4354. <literal>validateConfigAttributes</literal> property in the above
  4355. <literal>MethodSecurityInterceptor</literal> examples. When set to
  4356. <literal>true</literal> (the default), at startup time the
  4357. <literal>MethodSecurityInterceptor</literal> will evaluate if the
  4358. provided configuration attributes are valid. It does this by checking
  4359. each configuration attribute can be processed by either the
  4360. <literal>AccessDecisionManager</literal> or the
  4361. <literal>RunAsManager</literal>. If neither of these can process a
  4362. given configuration attribute, an exception is thrown. If using the
  4363. Jakarta Commons Attributes method of configuration, you should set
  4364. <literal>validateConfigAttributes</literal> to
  4365. <literal>false</literal>.</para>
  4366. <para>Please note that when using
  4367. <literal>BeanNameAutoProxyCreator</literal> to create the required
  4368. proxy for security, the configuration must contain the property
  4369. <literal>proxyTargetClass</literal> set to <literal>true</literal>.
  4370. Otherwise, the method passed to
  4371. <literal>MethodSecurityInterceptor.invoke</literal> is the proxy's
  4372. caller, not the proxy's target. Note that this introduces a
  4373. requirement on CGLIB. See an example of using
  4374. <literal>BeanNameAutoProxyCreator</literal> below:</para>
  4375. <programlisting>&lt;bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt;
  4376. &lt;property name="interceptorNames"&gt;
  4377. &lt;list&gt;&lt;value&gt;methodSecurityInterceptor&lt;/value&gt;&lt;/list&gt;
  4378. &lt;/property&gt;
  4379. &lt;property name="beanNames"&gt;
  4380. &lt;list&gt;&lt;value&gt;targetObjectName&lt;/value&gt;&lt;/list&gt;
  4381. &lt;/property&gt;
  4382. &lt;property name="proxyTargetClass" value="true"/&gt;
  4383. &lt;/bean&gt; </programlisting>
  4384. </sect1>
  4385. <sect1 id="aspectj">
  4386. <title>AspectJ (JoinPoint) Security Interceptor</title>
  4387. <para>The AspectJ security interceptor is very similar to the AOP
  4388. Alliance security interceptor discussed in the previous section.
  4389. Indeed we will only discuss the differences in this section.</para>
  4390. <para>The AspectJ interceptor is named
  4391. <literal>AspectJSecurityInterceptor</literal>. Unlike the AOP Alliance
  4392. security interceptor, which relies on the Spring application context
  4393. to weave in the security interceptor via proxying, the
  4394. <literal>AspectJSecurityInterceptor</literal> is weaved in via the
  4395. AspectJ compiler. It would not be uncommon to use both types of
  4396. security interceptors in the same application, with
  4397. <literal>AspectJSecurityInterceptor</literal> being used for domain
  4398. object instance security and the AOP Alliance
  4399. <literal>MethodSecurityInterceptor</literal> being used for services
  4400. layer security.</para>
  4401. <para>Let's first consider how the
  4402. <literal>AspectJSecurityInterceptor</literal> is configured in the
  4403. Spring application context:</para>
  4404. <programlisting>&lt;bean id="bankManagerSecurity" class="org.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor"&gt;
  4405. &lt;property name="validateConfigAttributes"&gt;&lt;value&gt;true&lt;/value&gt;&lt;/property&gt;
  4406. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4407. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4408. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4409. &lt;property name="afterInvocationManager"&gt;&lt;ref bean="afterInvocationManager"/&gt;&lt;/property&gt;
  4410. &lt;property name="objectDefinitionSource"&gt;
  4411. &lt;value&gt;
  4412. org.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER
  4413. org.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER
  4414. &lt;/value&gt;
  4415. &lt;/property&gt;
  4416. &lt;/bean&gt; </programlisting>
  4417. <para>As you can see, aside from the class name, the
  4418. <literal>AspectJSecurityInterceptor</literal> is exactly the same as
  4419. the AOP Alliance security interceptor. Indeed the two interceptors can
  4420. share the same <literal>objectDefinitionSource</literal>, as the
  4421. <literal>ObjectDefinitionSource</literal> works with
  4422. <literal>java.lang.reflect.Method</literal>s rather than an AOP
  4423. library-specific class. Of course, your access decisions have access
  4424. to the relevant AOP library-specific invocation (ie
  4425. <literal>MethodInvocation</literal> or <literal>JoinPoint</literal>)
  4426. and as such can consider a range of addition criteria when making
  4427. access decisions (such as method arguments).</para>
  4428. <para>Next you'll need to define an AspectJ <literal>aspect</literal>.
  4429. For example:</para>
  4430. <programlisting>package org.acegisecurity.samples.aspectj;
  4431. import org.acegisecurity.intercept.method.aspectj.AspectJSecurityInterceptor;
  4432. import org.acegisecurity.intercept.method.aspectj.AspectJCallback;
  4433. import org.springframework.beans.factory.InitializingBean;
  4434. public aspect DomainObjectInstanceSecurityAspect implements InitializingBean {
  4435. private AspectJSecurityInterceptor securityInterceptor;
  4436. pointcut domainObjectInstanceExecution(): target(PersistableEntity)
  4437. &amp;&amp; execution(public * *(..)) &amp;&amp; !within(DomainObjectInstanceSecurityAspect);
  4438. Object around(): domainObjectInstanceExecution() {
  4439. if (this.securityInterceptor != null) {
  4440. AspectJCallback callback = new AspectJCallback() {
  4441. public Object proceedWithObject() {
  4442. return proceed();
  4443. }
  4444. };
  4445. return this.securityInterceptor.invoke(thisJoinPoint, callback);
  4446. } else {
  4447. return proceed();
  4448. }
  4449. }
  4450. public AspectJSecurityInterceptor getSecurityInterceptor() {
  4451. return securityInterceptor;
  4452. }
  4453. public void setSecurityInterceptor(AspectJSecurityInterceptor securityInterceptor) {
  4454. this.securityInterceptor = securityInterceptor;
  4455. }
  4456. public void afterPropertiesSet() throws Exception {
  4457. if (this.securityInterceptor == null)
  4458. throw new IllegalArgumentException("securityInterceptor required");
  4459. }
  4460. }</programlisting>
  4461. <para>In the above example, the security interceptor will be applied
  4462. to every instance of <literal>PersistableEntity</literal>, which is an
  4463. abstract class not shown (you can use any other class or
  4464. <literal>pointcut</literal> expression you like). For those curious,
  4465. <literal>AspectJCallback</literal> is needed because the
  4466. <literal>proceed();</literal> statement has special meaning only
  4467. within an <literal>around()</literal> body. The
  4468. <literal>AspectJSecurityInterceptor</literal> calls this anonymous
  4469. <literal>AspectJCallback</literal> class when it wants the target
  4470. object to continue.</para>
  4471. <para>You will need to configure Spring to load the aspect and wire it
  4472. with the <literal>AspectJSecurityInterceptor</literal>. A bean
  4473. declaration which achieves this is shown below:</para>
  4474. <programlisting>
  4475. &lt;bean id="domainObjectInstanceSecurityAspect"
  4476. class="org.acegisecurity.samples.aspectj.DomainObjectInstanceSecurityAspect"
  4477. factory-method="aspectOf"&gt;
  4478. &lt;property name="securityInterceptor"&gt;&lt;ref bean="aspectJSecurityInterceptor"/&gt;&lt;/property&gt;
  4479. &lt;/bean&gt;
  4480. </programlisting>
  4481. <para>That's it! Now you can create your beans from anywhere within
  4482. your application, using whatever means you think fit (eg <literal>new
  4483. Person();</literal>) and they will have the security interceptor
  4484. applied.</para>
  4485. </sect1>
  4486. <sect1 id="filter-invocation-authorization">
  4487. <title>FilterInvocation Security Interceptor</title>
  4488. <para>To secure <literal>FilterInvocation</literal>s, developers need
  4489. to add a filter to their <literal>web.xml</literal> that delegates to
  4490. the <literal>FilterSecurityInterceptor</literal>. A typical
  4491. configuration example is provided below:</para>
  4492. <programlisting>&lt;filter&gt;
  4493. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  4494. &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;
  4495. &lt;init-param&gt;
  4496. &lt;param-name&gt;targetClass&lt;/param-name&gt;
  4497. &lt;param-value&gt;org.acegisecurity.intercept.web.FilterSecurityInterceptor&lt;/param-value&gt;
  4498. &lt;/init-param&gt;
  4499. &lt;/filter&gt;
  4500. &lt;filter-mapping&gt;
  4501. &lt;filter-name&gt;Acegi HTTP Request Security Filter&lt;/filter-name&gt;
  4502. &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  4503. &lt;/filter-mapping&gt;</programlisting>
  4504. <para>Notice that the filter is actually a
  4505. <literal>FilterToBeanProxy</literal>. Most of the filters used by
  4506. Acegi Security use this class. Refer to the Filters section to learn
  4507. more about this bean.</para>
  4508. <para>In the application context you will need to configure three
  4509. beans:</para>
  4510. <programlisting>&lt;bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter"&gt;
  4511. &lt;property name="authenticationEntryPoint"&gt;&lt;ref local="authenticationEntryPoint"/&gt;&lt;/property&gt;
  4512. &lt;/bean&gt;
  4513. &lt;bean id="authenticationEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"&gt;
  4514. &lt;property name="loginFormUrl"&gt;&lt;value&gt;/acegilogin.jsp&lt;/value&gt;&lt;/property&gt;
  4515. &lt;property name="forceHttps"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  4516. &lt;/bean&gt;
  4517. &lt;bean id="filterSecurityInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  4518. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4519. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4520. &lt;property name="objectDefinitionSource"&gt;
  4521. &lt;value&gt;
  4522. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  4523. \A/secure/super/.*\Z=ROLE_WE_DONT_HAVE
  4524. \A/secure/.*\Z=ROLE_SUPERVISOR,ROLE_TELLER
  4525. &lt;/value&gt;
  4526. &lt;/property&gt;
  4527. &lt;/bean&gt; </programlisting>
  4528. <para>The <classname>ExceptionTranslationFilter</classname> provides
  4529. the bridge between Java exceptions and HTTP responses. It is solely
  4530. concerned with maintaining the user interface. This filter does not do
  4531. any actual security enforcement. If an
  4532. <exceptionname>AuthenticationException</exceptionname> is detected,
  4533. the filter will call the AuthenticationEntryPoint to commence the
  4534. authentication process (e.g. a user login).</para>
  4535. <para>The <literal>AuthenticationEntryPoint</literal> will be called
  4536. if the user requests a secure HTTP resource but they are not
  4537. authenticated. The class handles presenting the appropriate response
  4538. to the user so that authentication can begin. Three concrete
  4539. implementations are provided with Acegi Security:
  4540. <literal>AuthenticationProcessingFilterEntryPoint</literal> for
  4541. commencing a form-based authentication,
  4542. <literal>BasicProcessingFilterEntryPoint</literal> for commencing a
  4543. HTTP Basic authentication process, and
  4544. <literal>CasProcessingFilterEntryPoint</literal> for commencing a
  4545. JA-SIG Central Authentication Service (CAS) login. The
  4546. <literal>AuthenticationProcessingFilterEntryPoint</literal> and
  4547. <literal>CasProcessingFilterEntryPoint</literal> have optional
  4548. properties related to forcing the use of HTTPS, so please refer to the
  4549. JavaDocs if you require this.</para>
  4550. <para><literal>FilterSecurityInterceptor</literal> is responsible for
  4551. handling the security of HTTP resources. Like any other security
  4552. interceptor, it requires a reference to an
  4553. <literal>AuthenticationManager</literal> and an
  4554. <literal>AccessDecisionManager</literal>, which are both discussed in
  4555. separate sections below. The
  4556. <literal>FilterSecurityInterceptor</literal> is also configured with
  4557. configuration attributes that apply to different HTTP URL requests. A
  4558. full discussion of configuration attributes is provided in the High
  4559. Level Design section of this document.</para>
  4560. <para>The <literal>FilterSecurityInterceptor</literal> can be
  4561. configured with configuration attributes in two ways. The first is via
  4562. a property editor and the application context, which is shown above.
  4563. The second is via writing your own
  4564. <literal>ObjectDefinitionSource</literal>, although this is beyond the
  4565. scope of this document. Irrespective of the approach used, the
  4566. <literal>ObjectDefinitionSource</literal> is responsible for returning
  4567. a <literal>ConfigAttributeDefinition</literal> object that contains
  4568. all of the configuration attributes associated with a single secure
  4569. HTTP URL.</para>
  4570. <para>It should be noted that the
  4571. <literal>FilterSecurityInterceptor.setObjectDefinitionSource()</literal>
  4572. method actually expects an instance of
  4573. <literal>FilterInvocationDefinitionSource</literal>. This is a marker
  4574. interface which subclasses <literal>ObjectDefinitionSource</literal>.
  4575. It simply denotes the <literal>ObjectDefinitionSource</literal>
  4576. understands <literal>FilterInvocation</literal>s. In the interests of
  4577. simplicity we'll continue to refer to the
  4578. <literal>FilterInvocationDefinitionSource</literal> as an
  4579. <literal>ObjectDefinitionSource</literal>, as the distinction is of
  4580. little relevance to most users of the
  4581. <literal>FilterSecurityInterceptor</literal>.</para>
  4582. <para>If using the application context property editor approach (as
  4583. shown above), commas are used to delimit the different configuration
  4584. attributes that apply to each HTTP URL. Each configuration attribute
  4585. is assigned into its own <literal>SecurityConfig</literal> object. The
  4586. <literal>SecurityConfig</literal> object is discussed in the High
  4587. Level Design section. The <literal>ObjectDefinitionSource</literal>
  4588. created by the property editor,
  4589. <literal>FilterInvocationDefinitionSource</literal>, matches
  4590. configuration attributes against <literal>FilterInvocations</literal>
  4591. based on expression evaluation of the request URL. Two standard
  4592. expression syntaxes are supported. The default is to treat all
  4593. expressions as regular expressions. Alternatively, the presence of a
  4594. <literal>PATTERN_TYPE_APACHE_ANT</literal> directive will cause all
  4595. expressions to be treated as Apache Ant paths. It is not possible to
  4596. mix expression syntaxes within the same definition. For example, the
  4597. earlier configuration could be generated using Apache Ant paths as
  4598. follows:</para>
  4599. <programlisting>&lt;bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor"&gt;
  4600. &lt;property name="authenticationManager"&gt;&lt;ref bean="authenticationManager"/&gt;&lt;/property&gt;
  4601. &lt;property name="accessDecisionManager"&gt;&lt;ref bean="accessDecisionManager"/&gt;&lt;/property&gt;
  4602. &lt;property name="runAsManager"&gt;&lt;ref bean="runAsManager"/&gt;&lt;/property&gt;
  4603. &lt;property name="objectDefinitionSource"&gt;
  4604. &lt;value&gt;
  4605. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  4606. PATTERN_TYPE_APACHE_ANT
  4607. /secure/super/**=ROLE_WE_DONT_HAVE
  4608. /secure/**=ROLE_SUPERVISOR,ROLE_TELLER
  4609. &lt;/value&gt;
  4610. &lt;/property&gt;
  4611. &lt;/bean&gt; </programlisting>
  4612. <para>Irrespective of the type of expression syntax used, expressions
  4613. are always evaluated in the order they are defined. Thus it is
  4614. important that more specific expressions are defined higher in the
  4615. list than less specific expressions. This is reflected in our example
  4616. above, where the more specific <literal>/secure/super/</literal>
  4617. pattern appears higher than the less specific
  4618. <literal>/secure/</literal> pattern. If they were reversed, the
  4619. <literal>/secure/</literal> pattern would always match and the
  4620. <literal>/secure/super/</literal> pattern would never be
  4621. evaluated.</para>
  4622. <para>The special keyword
  4623. <literal>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</literal> causes
  4624. the <literal>FilterInvocationDefinitionSource</literal> to
  4625. automatically convert a request URL to lowercase before comparison
  4626. against the expressions. Whilst by default the case of the request URL
  4627. is not converted, it is generally recommended to use
  4628. <literal>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</literal> and
  4629. write each expression assuming lowercase.</para>
  4630. <para>As with other security interceptors, the
  4631. <literal>validateConfigAttributes</literal> property is observed. When
  4632. set to <literal>true</literal> (the default), at startup time the
  4633. <literal>FilterSecurityInterceptor</literal> will evaluate if the
  4634. provided configuration attributes are valid. It does this by checking
  4635. each configuration attribute can be processed by either the
  4636. <literal>AccessDecisionManager</literal> or the
  4637. <literal>RunAsManager</literal>. If neither of these can process a
  4638. given configuration attribute, an exception is thrown.</para>
  4639. </sect1>
  4640. </chapter>
  4641. <chapter id="domain-acls">
  4642. <title>Domain Object Security</title>
  4643. <section id="domain-acls-overview">
  4644. <title>Overview</title>
  4645. <para>Complex applications often will find the need to define access
  4646. permissions not simply at a web request or method invocation level.
  4647. Instead, security decisions need to comprise both who
  4648. (<literal>Authentication</literal>), where
  4649. (<literal>MethodInvocation</literal>) and what
  4650. (<literal>SomeDomainObject</literal>). In other words, authorization
  4651. decisions also need to consider the actual domain object instance
  4652. subject of a method invocation.</para>
  4653. <para>Imagine you're designing an application for a pet clinic. There
  4654. will be two main groups of users of your Spring-based application:
  4655. staff of the pet clinic, as well as the pet clinic's customers. The
  4656. staff will have access to all of the data, whilst your customers will
  4657. only be able to see their own customer records. To make it a little
  4658. more interesting, your customers can allow other users to see their
  4659. customer records, such as their "puppy preschool "mentor or president
  4660. of their local "Pony Club". Using Acegi Security as the foundation,
  4661. you have several approaches that can be used:<orderedlist>
  4662. <listitem>
  4663. <para>Write your business methods to enforce the security. You
  4664. could consult a collection within the
  4665. <literal>Customer</literal> domain object instance to determine
  4666. which users have access. By using the
  4667. <literal>SecurityContextHolder.getContext().getAuthentication()</literal>,
  4668. you'll be able to access the <literal>Authentication</literal>
  4669. object.</para>
  4670. </listitem>
  4671. <listitem>
  4672. <para>Write an <literal>AccessDecisionVoter</literal> to enforce
  4673. the security from the <literal>GrantedAuthority[]</literal>s
  4674. stored in the <literal>Authentication</literal> object. This
  4675. would mean your <literal>AuthenticationManager</literal> would
  4676. need to populate the <literal>Authentication</literal> with
  4677. custom <literal>GrantedAuthority</literal>[]s representing each
  4678. of the <literal>Customer</literal> domain object instances the
  4679. principal has access to.</para>
  4680. </listitem>
  4681. <listitem>
  4682. <para>Write an <literal>AccessDecisionVoter</literal> to enforce
  4683. the security and open the target <literal>Customer</literal>
  4684. domain object directly. This would mean your voter needs access
  4685. to a DAO that allows it to retrieve the
  4686. <literal>Customer</literal> object. It would then access the
  4687. <literal>Customer</literal> object's collection of approved
  4688. users and make the appropriate decision.</para>
  4689. </listitem>
  4690. </orderedlist></para>
  4691. <para>Each one of these approaches is perfectly legitimate. However,
  4692. the first couples your authorization checking to your business code.
  4693. The main problems with this include the enhanced difficulty of unit
  4694. testing and the fact it would be more difficult to reuse the
  4695. <literal>Customer</literal> authorization logic elsewhere. Obtaining
  4696. the <literal>GrantedAuthority[]</literal>s from the
  4697. <literal>Authentication</literal> object is also fine, but will not
  4698. scale to large numbers of <literal>Customer</literal>s. If a user
  4699. might be able to access 5,000 <literal>Customer</literal>s (unlikely
  4700. in this case, but imagine if it were a popular vet for a large Pony
  4701. Club!) the amount of memory consumed and time required to construct
  4702. the <literal>Authentication</literal> object would be undesirable. The
  4703. final method, opening the <literal>Customer</literal> directly from
  4704. external code, is probably the best of the three. It achieves
  4705. separation of concerns, and doesn't misuse memory or CPU cycles, but
  4706. it is still inefficient in that both the
  4707. <literal>AccessDecisionVoter</literal> and the eventual business
  4708. method itself will perform a call to the DAO responsible for
  4709. retrieving the <literal>Customer</literal> object. Two accesses per
  4710. method invocation is clearly undesirable. In addition, with every
  4711. approach listed you'll need to write your own access control list
  4712. (ACL) persistence and business logic from scratch.</para>
  4713. <para>Fortunately, there is another alternative, which we'll talk
  4714. about below.</para>
  4715. </section>
  4716. <section id="domain-acls-basic">
  4717. <title>Basic ACL Package</title>
  4718. <para>Please note that our Basic ACL services are currently being
  4719. refactored. We expect release 1.1.0 will contain this new code.
  4720. Planned code is already in the Acegi Security Subversion sandbox, so
  4721. please check there if you have a new application requiring ACLs or are
  4722. in the planning stages. The Basic ACL services will be deprecated from
  4723. release 1.1.0.</para>
  4724. <para>The <literal>org.acegisecurity.acl</literal> package is very
  4725. simple, comprising only a handful of interfaces and a single class, as
  4726. shown in Figure 6. It provides the basic foundation for access control
  4727. list (ACL) lookups.</para>
  4728. <para><mediaobject>
  4729. <imageobject role="html">
  4730. <imagedata align="center" fileref="images/ACLSecurity.gif"
  4731. format="GIF" />
  4732. </imageobject>
  4733. <caption>
  4734. <para>Figure 6: Access Control List Manager</para>
  4735. </caption>
  4736. </mediaobject></para>
  4737. <para>The central interface is <literal>AclManager</literal>, which is
  4738. defined by two methods:</para>
  4739. <para><programlisting>public AclEntry[] getAcls(java.lang.Object domainInstance);
  4740. public AclEntry[] getAcls(java.lang.Object domainInstance, Authentication authentication);</programlisting></para>
  4741. <para><literal>AclManager</literal> is intended to be used as a
  4742. collaborator against your business objects, or, more desirably,
  4743. <literal>AccessDecisionVoter</literal>s. This means you use Spring's
  4744. normal <literal>ApplicationContext</literal> features to wire up your
  4745. <literal>AccessDecisionVoter</literal> (or business method) with an
  4746. <literal>AclManager</literal>. Consideration was given to placing the
  4747. ACL information in the <literal>ContextHolder</literal>, but it was
  4748. felt this would be inefficient both in terms of memory usage as well
  4749. as the time spent loading potentially unused ACL information. The
  4750. trade-off of needing to wire up a collaborator for those objects
  4751. requiring ACL information is rather minor, particularly in a
  4752. Spring-managed application.</para>
  4753. <para>The first method of the <literal>AclManager</literal> will
  4754. return all ACLs applying to the domain object instance passed to it.
  4755. The second method does the same, but only returns those ACLs which
  4756. apply to the passed <literal>Authentication</literal> object.</para>
  4757. <para>The <literal>AclEntry</literal> interface returned by
  4758. <literal>AclManager</literal> is merely a marker interface. You will
  4759. need to provide an implementation that reflects that ACL permissions
  4760. for your application.</para>
  4761. <para>Rounding out the <literal>org.acegisecurity.acl</literal>
  4762. package is an <literal>AclProviderManager</literal> class, with a
  4763. corresponding <literal>AclProvider</literal> interface.
  4764. <literal>AclProviderManager</literal> is a concrete implementation of
  4765. <literal>AclManager</literal>, which iterates through registered
  4766. <literal>AclProvider</literal>s. The first
  4767. <literal>AclProvider</literal> that indicates it can authoritatively
  4768. provide ACL information for the presented domain object instance will
  4769. be used. This is very similar to the
  4770. <literal>AuthenticationProvider</literal> interface used for
  4771. authentication.</para>
  4772. <para>With this background, let's now look at a usable ACL
  4773. implementation.</para>
  4774. <para>Acegi Security includes a production-quality ACL provider
  4775. implementation, which is shown in Figure 7.</para>
  4776. <para><mediaobject>
  4777. <imageobject role="html">
  4778. <imagedata align="center" fileref="images/BasicAclProvider.gif"
  4779. format="GIF" />
  4780. </imageobject>
  4781. <caption>
  4782. <para>Figure 7: Basic ACL Manager</para>
  4783. </caption>
  4784. </mediaobject></para>
  4785. <para>The implementation is based on integer masking, which is
  4786. commonly used for ACL permissions given its flexibility and speed.
  4787. Anyone who has used Unix's <literal>chmod</literal> command will know
  4788. all about this type of permission masking (eg <literal>chmod
  4789. 777</literal>). You'll find the classes and interfaces for the integer
  4790. masking ACL package under
  4791. <literal>org.acegisecurity.acl.basic</literal>.</para>
  4792. <para>Extending the <literal>AclEntry</literal> interface is a
  4793. <literal>BasicAclEntry</literal> interface, with the main methods
  4794. shown below:</para>
  4795. <para><programlisting>public AclObjectIdentity getAclObjectIdentity();
  4796. public AclObjectIdentity getAclObjectParentIdentity();
  4797. public int getMask();
  4798. public java.lang.Object getRecipient();</programlisting></para>
  4799. <para>As shown, each <literal>BasicAclEntry</literal> has four main
  4800. properties. The <literal>mask</literal> is the integer that represents
  4801. the permissions granted to the <literal>recipient</literal>. The
  4802. <literal>aclObjectIdentity</literal> is able to identify the domain
  4803. object instance for which the ACL applies, and the
  4804. <literal>aclObjectParentIdentity</literal> optionally specifies the
  4805. parent of the domain object instance. Multiple
  4806. <literal>BasicAclEntry</literal>s usually exist against a single
  4807. domain object instance, and as suggested by the parent identity
  4808. property, permissions granted higher in the object hierarchy will
  4809. trickle down and be inherited (unless blocked by integer zero).</para>
  4810. <para><literal>BasicAclEntry</literal> implementations typically
  4811. provide convenience methods, such as
  4812. <literal>isReadAllowed()</literal>, to avoid application classes
  4813. needing to perform bit masking themselves. The
  4814. <literal>SimpleAclEntry</literal> and
  4815. <literal>AbstractBasicAclEntry</literal> demonstrate and provide much
  4816. of this bit masking logic.</para>
  4817. <para>The <literal>AclObjectIdentity</literal> itself is merely a
  4818. marker interface, so you need to provide implementations for your
  4819. domain objects. However, the package does include a
  4820. <literal>NamedEntityObjectIdentity</literal> implementation which will
  4821. suit many needs. The <literal>NamedEntityObjectIdentity</literal>
  4822. identifies a given domain object instance by the classname of the
  4823. instance and the identity of the instance. A
  4824. <literal>NamedEntityObjectIdentity</literal> can be constructed
  4825. manually (by calling the constructor and providing the classname and
  4826. identity <literal>String</literal>s), or by passing in any domain
  4827. object that contains a <literal>getId()</literal> method.</para>
  4828. <para>The actual <literal>AclProvider</literal> implementation is
  4829. named <literal>BasicAclProvider</literal>. It has adopted a similar
  4830. design to that used by the authentication-related
  4831. <literal>DaoAuthenticationProvder</literal>. Specifically, you define
  4832. a <literal>BasicAclDao</literal> against the provider, so different
  4833. ACL repository types can be accessed in a pluggable manner. The
  4834. <literal>BasicAclProvider</literal> also supports pluggable cache
  4835. providers (with Acegi Security including an implementation that fronts
  4836. EH-CACHE).</para>
  4837. <para>The <literal>BasicAclDao</literal> interface is very simple to
  4838. implement:</para>
  4839. <para><programlisting>public BasicAclEntry[] getAcls(AclObjectIdentity aclObjectIdentity);</programlisting></para>
  4840. <para>A <literal>BasicAclDao</literal> implementation needs to
  4841. understand the presented <literal>AclObjectIdentity</literal> and how
  4842. it maps to a storage repository, find the relevant records, and create
  4843. appropriate <literal>BasicAclEntry</literal> objects and return
  4844. them.</para>
  4845. <para>Acegi Security includes a single <literal>BasicAclDao</literal>
  4846. implementation called <literal>JdbcDaoImpl</literal>. As implied by
  4847. the name, <literal>JdbcDaoImpl</literal> accesses ACL information from
  4848. a JDBC database. There is also an extended version of this DAO,
  4849. <literal>JdbcExtendedDaoImpl</literal>, which provides CRUD operations
  4850. on the JDBC database, although we won't discuss these features here.
  4851. The default database schema and some sample data will aid in
  4852. understanding its function:</para>
  4853. <para><programlisting>CREATE TABLE acl_object_identity (
  4854. id IDENTITY NOT NULL,
  4855. object_identity VARCHAR_IGNORECASE(250) NOT NULL,
  4856. parent_object INTEGER,
  4857. acl_class VARCHAR_IGNORECASE(250) NOT NULL,
  4858. CONSTRAINT unique_object_identity UNIQUE(object_identity),
  4859. FOREIGN KEY (parent_object) REFERENCES acl_object_identity(id)
  4860. );
  4861. CREATE TABLE acl_permission (
  4862. id IDENTITY NOT NULL,
  4863. acl_object_identity INTEGER NOT NULL,
  4864. recipient VARCHAR_IGNORECASE(100) NOT NULL,
  4865. mask INTEGER NOT NULL,
  4866. CONSTRAINT unique_recipient UNIQUE(acl_object_identity, recipient),
  4867. FOREIGN KEY (acl_object_identity) REFERENCES acl_object_identity(id)
  4868. );
  4869. INSERT INTO acl_object_identity VALUES (1, 'corp.DomainObject:1', null, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4870. INSERT INTO acl_object_identity VALUES (2, 'corp.DomainObject:2', 1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4871. INSERT INTO acl_object_identity VALUES (3, 'corp.DomainObject:3', 1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4872. INSERT INTO acl_object_identity VALUES (4, 'corp.DomainObject:4', 1, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4873. INSERT INTO acl_object_identity VALUES (5, 'corp.DomainObject:5', 3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4874. INSERT INTO acl_object_identity VALUES (6, 'corp.DomainObject:6', 3, 'org.acegisecurity.acl.basic.SimpleAclEntry');
  4875. INSERT INTO acl_permission VALUES (null, 1, 'ROLE_SUPERVISOR', 1);
  4876. INSERT INTO acl_permission VALUES (null, 2, 'ROLE_SUPERVISOR', 0);
  4877. INSERT INTO acl_permission VALUES (null, 2, 'marissa', 2);
  4878. INSERT INTO acl_permission VALUES (null, 3, 'scott', 14);
  4879. INSERT INTO acl_permission VALUES (null, 6, 'scott', 1);</programlisting></para>
  4880. <para>As can be seen, database-specific constraints are used
  4881. extensively to ensure the integrity of the ACL information. If you
  4882. need to use a different database (Hypersonic SQL statements are shown
  4883. above), you should try to implement equivalent constraints. The
  4884. equivalent Oracle configuration is:</para>
  4885. <para><programlisting>CREATE TABLE ACL_OBJECT_IDENTITY (
  4886. ID number(19,0) not null,
  4887. OBJECT_IDENTITY varchar2(255) NOT NULL,
  4888. PARENT_OBJECT number(19,0),
  4889. ACL_CLASS varchar2(255) NOT NULL,
  4890. primary key (ID)
  4891. );
  4892. ALTER TABLE ACL_OBJECT_IDENTITY ADD CONTRAINT FK_PARENT_OBJECT foreign key (ID) references ACL_OBJECT_IDENTITY
  4893. CREATE SEQUENCE ACL_OBJECT_IDENTITY_SEQ;
  4894. CREATE OR REPLACE TRIGGER ACL_OBJECT_IDENTITY_ID
  4895. BEFORE INSERT ON ACL_OBJECT_IDENTITY
  4896. FOR EACH ROW
  4897. BEGIN
  4898. SELECT ACL_OBJECT_IDENTITY_SEQ.NEXTVAL INTO :new.id FROM dual;
  4899. END;
  4900. CREATE TABLE ACL_PERMISSION (
  4901. ID number(19,0) not null,
  4902. ACL_OBJECT_IDENTITY number(19,0) NOT NULL,
  4903. RECIPIENT varchar2(255) NOT NULL,
  4904. MASK number(19,0) NOT NULL,
  4905. primary key (ID)
  4906. );
  4907. ALTER TABLE ACL_PERMISSION ADD CONTRAINT UNIQUE_ID_RECIPIENT unique (acl_object_identity, recipient);
  4908. CREATE SEQUENCE ACL_PERMISSION_SEQ;
  4909. CREATE OR REPLACE TRIGGER ACL_PERMISSION_ID
  4910. BEFORE INSERT ON ACL_PERMISSION
  4911. FOR EACH ROW
  4912. BEGIN
  4913. SELECT ACL_PERMISSION_SEQ.NEXTVAL INTO :new.id FROM dual;
  4914. END;
  4915. &lt;bean id="basicAclExtendedDao" class="org.acegisecurity.acl.basic.jdbc.JdbcExtendedDaoImpl"&gt;
  4916. &lt;property name="dataSource"&gt;
  4917. &lt;ref bean="dataSource"/&gt;
  4918. &lt;/property&gt;
  4919. &lt;property name="objectPropertiesQuery" value="${acegi.objectPropertiesQuery}"/&gt;
  4920. &lt;/bean&gt;
  4921. &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>
  4922. <para>The <literal>JdbcDaoImpl</literal> will only respond to requests
  4923. for <literal>NamedEntityObjectIdentity</literal>s. It converts such
  4924. identities into a single <literal>String</literal>, comprising
  4925. the<literal> NamedEntityObjectIdentity.getClassname()</literal> +
  4926. <literal>":"</literal> +
  4927. <literal>NamedEntityObjectIdentity.getId()</literal>. This yields the
  4928. type of <literal>object_identity</literal> values shown above. As
  4929. indicated by the sample data, each database row corresponds to a
  4930. single <literal>BasicAclEntry</literal>. As stated earlier and
  4931. demonstrated by <literal>corp.DomainObject:2</literal> in the above
  4932. sample data, each domain object instance will often have multiple
  4933. <literal>BasicAclEntry</literal>[]s.</para>
  4934. <para>As <literal>JdbcDaoImpl</literal> is required to return concrete
  4935. <literal>BasicAclEntry</literal> classes, it needs to know which
  4936. <literal>BasicAclEntry</literal> implementation it is to create and
  4937. populate. This is the role of the <literal>acl_class</literal> column.
  4938. <literal>JdbcDaoImpl</literal> will create the indicated class and set
  4939. its <literal>mask</literal>, <literal>recipient</literal>,
  4940. <literal>aclObjectIdentity</literal> and
  4941. <literal>aclObjectParentIdentity</literal> properties.</para>
  4942. <para>As you can probably tell from the sample data, the
  4943. <literal>parent_object_identity</literal> value can either be null or
  4944. in the same format as the <literal>object_identity</literal>. If
  4945. non-null, <literal>JdbcDaoImpl</literal> will create a
  4946. <literal>NamedEntityObjectIdentity</literal> to place inside the
  4947. returned <literal>BasicAclEntry</literal> class.</para>
  4948. <para>Returning to the <literal>BasicAclProvider</literal>, before it
  4949. can poll the <literal>BasicAclDao</literal> implementation it needs to
  4950. convert the domain object instance it was passed into an
  4951. <literal>AclObjectIdentity</literal>.
  4952. <literal>BasicAclProvider</literal> has a <literal>protected
  4953. AclObjectIdentity obtainIdentity(Object domainInstance)</literal>
  4954. method that is responsible for this. As a protected method, it enables
  4955. subclasses to easily override. The normal implementation checks
  4956. whether the passed domain object instance implements the
  4957. <literal>AclObjectIdentityAware</literal> interface, which is merely a
  4958. getter for an <literal>AclObjectIdentity</literal>. If the domain
  4959. object does implement this interface, that is the identity returned.
  4960. If the domain object does not implement this interface, the method
  4961. will attempt to create an <literal>AclObjectIdentity</literal> by
  4962. passing the domain object instance to the constructor of a class
  4963. defined by the
  4964. <literal>BasicAclProvider.getDefaultAclObjectIdentity()</literal>
  4965. method. By default the defined class is
  4966. <literal>NamedEntityObjectIdentity</literal>, which was described in
  4967. more detail above. Therefore, you will need to either (i) provide a
  4968. <literal>getId()</literal> method on your domain objects, (ii)
  4969. implement <literal>AclObjectIdentityAware</literal> on your domain
  4970. objects, (iii) provide an alternative
  4971. <literal>AclObjectIdentity</literal> implementation that will accept
  4972. your domain object in its constructor, or (iv) override the
  4973. <literal>obtainIdentity(Object)</literal> method.</para>
  4974. <para>Once the <literal>AclObjectIdentity</literal> of the domain
  4975. object instance is determined, the <literal>BasicAclProvider</literal>
  4976. will poll the DAO to obtain its <literal>BasicAclEntry</literal>[]s.
  4977. If any of the entries returned by the DAO indicate there is a parent,
  4978. that parent will be polled, and the process will repeat until there is
  4979. no further parent. The permissions assigned to a
  4980. <literal>recipient</literal> closest to the domain object instance
  4981. will always take priority and override any inherited permissions. From
  4982. the sample data above, the following inherited permissions would
  4983. apply:</para>
  4984. <para><programlisting>--- Mask integer 0 = no permissions
  4985. --- Mask integer 1 = administer
  4986. --- Mask integer 2 = read
  4987. --- Mask integer 6 = read and write permissions
  4988. --- Mask integer 14 = read and write and create permissions
  4989. ---------------------------------------------------------------------
  4990. --- *** INHERITED RIGHTS FOR DIFFERENT INSTANCES AND RECIPIENTS ***
  4991. --- INSTANCE RECIPIENT PERMISSION(S) (COMMENT #INSTANCE)
  4992. ---------------------------------------------------------------------
  4993. --- 1 ROLE_SUPERVISOR Administer
  4994. --- 2 ROLE_SUPERVISOR None (overrides parent #1)
  4995. --- marissa Read
  4996. --- 3 ROLE_SUPERVISOR Administer (from parent #1)
  4997. --- scott Read, Write, Create
  4998. --- 4 ROLE_SUPERVISOR Administer (from parent #1)
  4999. --- 5 ROLE_SUPERVISOR Administer (from parent #3)
  5000. --- scott Read, Write, Create (from parent #3)
  5001. --- 6 ROLE_SUPERVISOR Administer (from parent #3)
  5002. --- scott Administer (overrides parent #3)</programlisting></para>
  5003. <para>So the above explains how a domain object instance has its
  5004. <literal>AclObjectIdentity</literal> discovered, and the
  5005. <literal>BasicAclDao</literal> will be polled successively until an
  5006. array of inherited permissions is constructed for the domain object
  5007. instance. The final step is to determine the
  5008. <literal>BasicAclEntry</literal>[]s that are actually applicable to a
  5009. given <literal>Authentication</literal> object.</para>
  5010. <para>As you would recall, the <literal>AclManager</literal> (and all
  5011. delegates, up to and including <literal>BasicAclProvider</literal>)
  5012. provides a method which returns only those
  5013. <literal>BasicAclEntry</literal>[]s applying to a passed
  5014. <literal>Authentication</literal> object.
  5015. <literal>BasicAclProvider</literal> delivers this functionality by
  5016. delegating the filtering operation to an
  5017. <literal>EffectiveAclsResolver</literal> implementation. The default
  5018. implementation,
  5019. <literal>GrantedAuthorityEffectiveAclsResolver</literal>, will iterate
  5020. through the <literal>BasicAclEntry</literal>[]s and include only those
  5021. where the <literal>recipient</literal> is equal to either the
  5022. <literal>Authentication</literal>'s <literal>principal</literal> or
  5023. any of the <literal>Authentication</literal>'s
  5024. <literal>GrantedAuthority</literal>[]s. Please refer to the JavaDocs
  5025. for more information.</para>
  5026. <mediaobject>
  5027. <imageobject role="html">
  5028. <imagedata align="center" fileref="images/Permissions.gif"
  5029. format="GIF" />
  5030. </imageobject>
  5031. <caption>
  5032. <para>Figure 8: ACL Instantiation Approach</para>
  5033. </caption>
  5034. </mediaobject>
  5035. <para>The above figure explains the key relationships between objects
  5036. in the Basic ACL package.</para>
  5037. </section>
  5038. </chapter>
  5039. </part>
  5040. <part id="resources">
  5041. <title>Other Resources</title>
  5042. <partintro>
  5043. <para>In addition to this reference guide, a number of other resources
  5044. exist to help you learn how to use Acegi Security. These resources are
  5045. discussed in this section.</para>
  5046. </partintro>
  5047. <chapter id="sample-apps">
  5048. <title id="samples">Sample Applications</title>
  5049. <sect1 id="contacts-sample">
  5050. <title id="contacts">Contacts</title>
  5051. <para>Included with Acegi Security is a very simple application that
  5052. can demonstrate the basic security facilities provided by the system
  5053. (and confirm your Container Adapter is properly configured if you're
  5054. using one).</para>
  5055. <para>If you build from Subversion, the Contacts sample application
  5056. includes three deployable versions:
  5057. <literal>acegi-security-sample-contacts-filter.war</literal> is
  5058. configured with the HTTP Session Authentication approach.
  5059. Acegi<literal><literal>-security-sample-contacts-ca.war</literal></literal>
  5060. is configured to use a Container Adapter. Finally,
  5061. <literal>acegi-security-sample-contacts-cas.war</literal> is designed
  5062. to work with a JA-SIG CAS server. If you're just wanting to see how
  5063. the sample application works, please use
  5064. <literal><literal>acegi-security-sample-contacts-filter.war</literal></literal>
  5065. as it does not require special configuration of your container. This
  5066. is also the artifact included in official release ZIPs.</para>
  5067. <para>To deploy, simply copy the relevant WAR file from Acegi Security
  5068. distribution into your container’s <literal>webapps</literal>
  5069. directory.</para>
  5070. <para>After starting your container, check the application can load.
  5071. Visit
  5072. <literal>http://localhost:</literal><literal><literal>8080/</literal>acegi-security-sample-contacts-filter</literal>
  5073. (or whichever URL is appropriate for your web container and the WAR
  5074. you deployed). A random contact should be displayed. Click "Refresh"
  5075. several times and you will see different contacts. The business method
  5076. that provides this random contact is not secured.</para>
  5077. <para>Next, click "Debug". You will be prompted to authenticate, and a
  5078. series of usernames and passwords are suggested on that page. Simply
  5079. authenticate with any of these and view the resulting page. It should
  5080. contain a success message similar to the following:</para>
  5081. <blockquote>
  5082. <para>Context on SecurityContextHolder is of type:
  5083. org.acegisecurity.context.SecurityContextImpl</para>
  5084. <para>The Context implements SecurityContext.</para>
  5085. <para>Authentication object is of type:
  5086. org.acegisecurity.adapters.PrincipalAcegiUserToken</para>
  5087. <para>Authentication object as a String:
  5088. org.acegisecurity.adapters.PrincipalAcegiUserToken@e9a7c2: Username:
  5089. marissa; Password: [PROTECTED]; Authenticated: true; Granted
  5090. Authorities: ROLE_TELLER, ROLE_SUPERVISOR</para>
  5091. <para>Authentication object holds the following granted
  5092. authorities:</para>
  5093. <para>ROLE_TELLER (getAuthority(): ROLE_TELLER)</para>
  5094. <para>ROLE_SUPERVISOR (getAuthority(): ROLE_SUPERVISOR)</para>
  5095. <para>SUCCESS! Your [container adapter|web filter] appears to be
  5096. properly configured!</para>
  5097. </blockquote>
  5098. <para>If you receive a different message, and deployed
  5099. <literal>acegi-security-sample-contacts-ca.war</literal>, check you
  5100. have properly configured your Container Adapter as described elsewhere
  5101. in this reference guide.</para>
  5102. <para>Once you successfully receive the above message, return to the
  5103. sample application's home page and click "Manage". You can then try
  5104. out the application. Notice that only the contacts available to the
  5105. currently logged on user are displayed, and only users with
  5106. <literal>ROLE_SUPERVISOR</literal> are granted access to delete their
  5107. contacts. Behind the scenes, the
  5108. <literal>MethodSecurityInterceptor</literal> is securing the business
  5109. objects. If you're using
  5110. <literal><literal>acegi-security-sample-contacts-filter.war</literal></literal>
  5111. or <literal>acegi-security-sample-contacts-cas.war</literal>, the
  5112. <literal>FilterSecurityInterceptor</literal> is also securing the HTTP
  5113. requests. If using either of these WARs, be sure to try visiting
  5114. <literal>http://localhost:8080/contacts/secure/super</literal>, which
  5115. will demonstrate access being denied by the
  5116. <literal>FilterSecurityInterceptor</literal>. Note the sample
  5117. application enables you to modify the access control lists associated
  5118. with different contacts. Be sure to give this a try and understand how
  5119. it works by reviewing the sample application's application context XML
  5120. files.</para>
  5121. <para>The Contacts sample application also include a
  5122. <literal>client</literal> directory. Inside you will find a small
  5123. application that queries the backend business objects using several
  5124. web services protocols. This demonstrates how to use Acegi Security
  5125. for authentication with Spring remoting protocols. To try this client,
  5126. ensure your servlet container is still running the Contacts sample
  5127. application, and then execute <literal>client marissa koala</literal>.
  5128. The command-line parameters respectively represent the username to
  5129. use, and the password to use. Note that you may need to edit
  5130. <literal>client.properties</literal> to use a different target
  5131. URL.</para>
  5132. <para>Please note the sample application's <literal>client</literal>
  5133. does not currently support CAS. You can still give it a try, though,
  5134. if you're ambitious: try <literal>client _cas_stateless_
  5135. YOUR-SERVICE-TICKET-ID</literal>.</para>
  5136. </sect1>
  5137. <sect1 id="tutorial-sample">
  5138. <title>Tutorial Sample</title>
  5139. <para>Whilst the <link linkend="contacts-sample">Contacts
  5140. Sample</link> is quite advanced in that it illustrates the more
  5141. powerful features of domain object access control lists and so on,
  5142. sometimes you just want to start with a nice basic example. The
  5143. tutorial sample is intended to provide this for you.</para>
  5144. <para>The compiled tutorial is included in the distribution ZIP file,
  5145. ready to be deployed into your web container. Authentication is
  5146. handled by the <link
  5147. linkend="dao-provider">DaoAuthenticationProvider</link>, using the
  5148. <link linkend="in-memory-service">in-memory</link>
  5149. <literal>UserDetailsService</literal> that sources information from
  5150. the <literal>users.properties</literal> file located in the WAR's
  5151. <literal>/WEB-INF</literal> directory. The <link
  5152. linkend="form">form-based</link> authentication mechanism is used,
  5153. with the commonly-used <link linkend="remember-me">remember-me</link>
  5154. authentication provider used to automatically remember the login using
  5155. cookies.</para>
  5156. <para>In terms of authorization, to keep things simple we've
  5157. configured the tutorial to only perform some basic <link
  5158. linkend="filter-invocation-authorization">web filter
  5159. authorization</link>. We've wired two common <link
  5160. linkend="pre-invocation">pre-invocation access decision voters</link>,
  5161. being the <literal>RoleVoter</literal> and
  5162. <literal>AuthenticatedVoter</literal>, such that
  5163. <literal>ROLE_*</literal> configuration attributes and
  5164. <literal>IS_AUTHENTICATED_*</literal> configuration attributes may be
  5165. used. Of course, it's extremely easy to add in other providers, with
  5166. most users probably starting with some services-layer security using
  5167. <link linkend="aop-alliance">MethodSecurityInterceptor</link>.</para>
  5168. <para>We recommend you start with the tutorial sample, as the XML is
  5169. minimal and easy to follow. All of the needed <link
  5170. linkend="filters">filters</link> are configured properly, and using
  5171. best practise. Most importantly, you can easily this one XML file (and
  5172. its corresponding <literal>web.xml</literal> entries) to your existing
  5173. application. Only when this basic integration is achieved do we
  5174. suggest you attempt adding in method authorization or domain object
  5175. security.</para>
  5176. </sect1>
  5177. </chapter>
  5178. <chapter id="community">
  5179. <title>Community Support</title>
  5180. <sect1 id="jira">
  5181. <title>Use JIRA for Issue Tracking</title>
  5182. <para>Acegi Security uses JIRA to manage bug reports and enhancement
  5183. requests. If you find a bug, please log a report using JIRA. Do not
  5184. log it on the support forum, mailing list or by emailing the project's
  5185. developers. Such approaches are ad-hoc and we prefer to manage bugs
  5186. using a more formal process.</para>
  5187. <para>If possible, in your JIRA report please provide a JUnit test
  5188. that demonstrates any incorrect behaviour. Or, better yet, provide a
  5189. patch that corrects the issue. Similarly, enhancements are welcome to
  5190. be logged in JIRA, although we only accept commit enhancement requests
  5191. if you include corresponding unit tests. This is necessary to ensure
  5192. project test coverage is adequately maintained.</para>
  5193. <para>You can access JIRA at <ulink
  5194. url="http://opensource.atlassian.com/projects/spring/secure/BrowseProject.jspa?id=10040"></ulink>.</para>
  5195. </sect1>
  5196. <sect1 id="becoming-involved">
  5197. <title>Becoming Involved</title>
  5198. <para>We welcome you to become involved in Acegi Security project.
  5199. There are many ways of contributing, including reading the mailing
  5200. list and responding to questions from other people, writing new code,
  5201. improving existing code, assisting with documentation, developing
  5202. samples or tutorials, or simply making suggestions.</para>
  5203. <para>Please read our project policies web page that is available on
  5204. Acegi Security home page. This explains the path to become a
  5205. committer, and the administration approaches we use within the
  5206. project.</para>
  5207. </sect1>
  5208. <sect1 id="further-info">
  5209. <title>Further Information</title>
  5210. <para>Questions and comments on Acegi Security are welcome. Please use
  5211. the Spring Community Forum web site at <ulink
  5212. url="http://forum.springframework.org"></ulink> for all support
  5213. issues. Remember to use JIRA for bug reports, as explained above.
  5214. Everyone is also welcome to join the Acegisecurity-developer mailing
  5215. list and participate in design discussions. It's also a good way of
  5216. finding out what's happening with regard to release timing, and the
  5217. traffic volume is quite light. Finally, our project home page (where
  5218. you can obtain the latest release of the project and convenient links
  5219. to Subversion, JIRA, mailing lists, forums etc) is at <ulink
  5220. url="http://acegisecurity.org"></ulink>.</para>
  5221. </sect1>
  5222. </chapter>
  5223. </part>
  5224. </book>