acegi.xml 265 KB

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