acegi.xml 313 KB

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