acegi.xml 314 KB

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