<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>tmro &#187; Spring</title>
	<atom:link href="http://www.tmro.net/category/software/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tmro.net</link>
	<description>Mobilise your business</description>
	<lastBuildDate>Tue, 01 Jun 2010 08:55:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Applying Acegi Security (SpringSecurity) to an existing JavaEE ap</title>
		<link>http://www.tmro.net/2008/04/applying-acegi-security-springsecurity-to-an-existing-javaee-ap/</link>
		<comments>http://www.tmro.net/2008/04/applying-acegi-security-springsecurity-to-an-existing-javaee-ap/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 23:25:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Acegi]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=69</guid>
		<description><![CDATA[So I have a JavaEE application and I have to make sure that I use Acegi (called Spring Security or SS from here on) properly. I will try to go ]]></description>
			<content:encoded><![CDATA[<p>So I have a JavaEE application and I have to make sure that I use Acegi (called Spring Security or SS from here on) properly. I will try to go through all the steps that are required to implement SS in an existing Spring based application. I will not delve into the details of putting together a Spring Framework based application and I will not provide in-depth details of the implementation.<br id="v072"> <br id="w3ps"> First of all here are the assumptions:<br id="qllb"> 1. You understand what the differences between Authentication and Authorisation are.<br id="cgl4"> 2. You know what Form, Basic, Digest, LDAP Authentication mean.<br id="uhsb"> 3. You know what Annotations are and you are not in the mood to argue XML configurations vs. Annotations<br id="j-bl"> 4. I am not responsible if the information you found here has not solved your problem <img src='http://www.tmro.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> <br id="s-8."> <br id="r3ln"> So let&#8217;s just say that there is no security in place and we need to plug SS in.<br id="r2of"> <br id="ubla"><br />
<h3 id="lxfz">   <b id="xq_p">1. Adding Spring Security to the project</b> </h3>
<p id="lxfz">   <span id="ya2j">- copy the acegi-security-xxx.jar to your lib folder (this depends on how you have configured your project)</span> <span id="smmi">or just include it in your build path.</span> </p>
<p id="lxfz">   <span id="smmi">- create a new xml file (i will call it ss.xml) where </span><span id="zy6g">to put all the configuration information or copy one from the SS distribution</span> </p>
<p id="lxfz">   &#8211; import this file in your spring configuration xml (or point to it in your web.xml where you configure the contextConfigLocation) </p>
<p id="lxfz">   &#8211; in the web.xml configure the Acegi Filter Chain Proxy. Then make sure the FilterToBeanProxy&#8217;s class points to the org.acegisecurity.util.FilterChainProxy (should you use FilterToBean you&#8217;ll end up writing lots and lots of xml to define the filters, but it&#8217;s your choice). </p>
<p id="lxfz">   &#8211; while in the web.xml define a filter-mapping for the URIs that you want to secure. How about /* ?<br id="jqzo"> </p>
<p id="lxfz">   <br id="wabc"> </p>
<p id="lxfz">   All done with the web.xml You should have something like this: </p>
<p id="lxfz">   <span id="mwa0"><b id="cqy3">    [...]</b></span><br id="kk7g"> </p>
<p id="lxfz">   <b id="hf44">    &lt;context-param&gt;<br id="so.n">           &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;<br id="ma8i">           &lt;param-value&gt;/WEB-INF/classes/spring-core.xml, /WEB-INF/classes/ss.xml&lt;/param-value&gt;<br id="qn9l">       &lt;/context-param&gt;<br id="e7-x">          <br id="tccq">       &lt;filter&gt;<br id="at:q">           &lt;filter-name&gt;Acegi Filter Chain Proxy&lt;/filter-name&gt;<br id="ne:q">           &lt;filter-class&gt;org.acegisecurity.util.FilterToBeanProxy&lt;/filter-class&gt;<br id="q0zb">           &lt;init-param&gt;<br id="a3ps">               &lt;param-name&gt;targetClass&lt;/param-name&gt;<br id="y4f2">               &lt;param-value&gt;org.acegisecurity.util.FilterChainProxy&lt;/param-value&gt;<br id="d55g">           &lt;/init-param&gt;<br id="oj6n">       &lt;/filter&gt;<br id="t133">         <br id="p640">       &lt;filter-mapping&gt;<br id="q72c">         &lt;filter-name&gt;Acegi Filter Chain Proxy&lt;/filter-name&gt;<br id="m:0v">         &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br id="xqv-">       &lt;/filter-mapping&gt;</b> </p>
<p id="lxfz">   <span id="rgu4"><b id="pt38">    [...]</b></span><br id="eq_h"> </p>
<p id="lxfz">   <br id="rf5-"> </p>
<p id="lxfz">   &#8211; move to the ss.xml file that i pointed to above and configure the filter. I will have different filters for web services and for the rest of the application. The order is very important so make sure you put the more specific rules first. I will also put some stuff in /notsecured that will just not be protected.<br id="ek55"> </p>
<pre class="programlisting" id="iuzs" style="font-family: Verdana;"><b id="vc::">    &lt;bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy"&gt;<br id="kqzc">        &lt;property name="filterInvocationDefinitionSource"&gt;<br id="n1.t">            &lt;value&gt;<br id="saye">              CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON<br id="te7.">              PATTERN_TYPE_APACHE_ANT<br id="krsp">              /webServices/**=httpSessionContextIntegrationFilterWithASCFalse,basicProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor<br id="tnrk">              /notsecured/**=#NONE#<br id="o4ls">              /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor<br id="ciqm">            &lt;/value&gt;<br id="cr4-">        &lt;/property&gt;<br id="ijsa">    &lt;/bean&gt;</b></pre>
<pre class="programlisting" id="a.xx"></pre>
<p id="lxfz">Just a few comments on what we have above: the <span id="k8dk"><i id="ibko">authenticationProcessingFilter</i></span> could be used to audit the logon attempts as it provides <span id="bq._"><i id="bn6l">onSuccessfuAuthentication</i></span> and <span id="bcmv"><i id="jyj1">onUnsuccessfulAuthentication</i></span> methods. The <span id="j4-t"><i id="q4_d">exceptionTranslationFilter</i></span> is responsible for detecting security exceptions thrown by the <span id="xlih"><i id="gof0">AbstractSecurityInterceptor</i></span>.The <span id="j_sg"><i id="syfx">filterInvocationInterceptor</i></span> is needed to check web URIs.</p>
<p id="lxfz"><br id="ng7a"></p>
<p id="lxfz">- now it&#8217;s time to configure the <span id="x2-y"><i id="o6_.">authenticationProcessingFilter</i></span>. Here is what it should end up looking like:</p>
<p id="lxfz"><span id="s6m3"><b id="ey0w">    &lt;bean id=&#8221;authenticationProcessingFilter&#8221; class=&#8221;class.that.implements.AuthenticationProcessingFilter&#8221;&gt;</b></span><br id="sn.i" style="font-weight: bold;"><span id="buoy"><b id="nf92">        &lt;property name=&#8221;authenticationManager&#8221;&gt;</b></span></p>
<p id="lxfz"><span id="a7xm"><b id="nk9l">            &lt;ref bean=&#8221;authenticationManager&#8221;/&gt;</b></span></p>
<p id="lxfz"><span id="ky1-"><b id="ur.k">        &lt;/property&gt;</b></span><br id="mfk7" style="font-weight: bold;"><span id="lt36"><b id="dc8m">        &lt;property name=&#8221;authenticationFailureUrl&#8221;&gt;</b></span></p>
<p id="lxfz"><span id="lt36"><b id="jlkx">            &lt;value&gt;/logon.jsp?tryagain=true&lt;/value&gt;</b></span></p>
<p id="lxfz"><span id="lt36"><b id="ltee">        &lt;/property&gt;</b></span><br id="juls" style="font-weight: bold;"><span id="hy1c"><b id="jkn4">        &lt;property name=&#8221;filterProcessesUrl&#8221;&gt;</b></span></p>
<p id="lxfz"><span id="hy1c"><b id="pw9h">            &lt;value&gt;/j_acegi_security_check&lt;/value&gt;</b></span></p>
<p id="lxfz"><span id="hy1c"><b id="ib4-">        &lt;/property&gt;</b></span><br id="cppk" style="font-weight: bold;"><span id="e.y0"><b id="r740">        &lt;property name=&#8221;defaultTargetUrl&#8221;&gt;</b></span></p>
<p id="lxfz"><span id="e.y0"><b id="ti47">            &lt;value&gt;/admin/home.html&lt;/value&gt;</b></span></p>
<p id="lxfz"><span id="e.y0"><b id="h6_7">        &lt;/property&gt;</b></span><br id="d_2n" style="font-weight: bold;"><span id="kdfi"><b id="jwed">        &lt;property name=&#8221;alwaysUseDefaultTargetUrl&#8221;&gt;</b></span></p>
<p id="lxfz"><span id="kdfi"><b id="mkxr">            &lt;value&gt;true&lt;/value&gt;</b></span></p>
<p id="lxfz"><span id="kdfi"><b id="i5v6">        &lt;/property&gt;</b></span><br id="r6on" style="font-weight: bold;"><span id="i47q"><b id="f7-g">    &lt;/bean&gt;</b></span><br id="cvkf"></p>
<p id="lxfz"><br id="jzgn"></p>
<p id="lxfz">So let&#8217;s look at the properties, one at a time. </p>
<p id="lxfz"><br id="tpn."></p>
<p id="lxfz">    First the class that implements the processing filter can be any the AuthenticationProcessingFilter itself or your own class that extends it. You would extend it to be able to do stuff when something goes wrong for example. <br id="o7qe"></p>
<p id="lxfz">    The <span id="tjnb"><i id="mjcx">authenticationManager</i></span> is responsible with delegating to <span id="q75b">its list of </span><span id="q75b"><i id="j8ee">AuthenticationPr<br />
oviders</i></span> to check an Authentication request. It can also be configured with a <span id="ekz0"><i id="tdll">ConcurrentSessionController</i></span> that manages how many session one user can have at a time.</p>
<p id="lxfz">     The <span id="pipd"><i id="e2-1">authenticationFailureUrl</i></span> points to where the user will be redirected to in the event of an authentication failure. The request parameter <span id="yl:e"><i id="vqz0">tryagain</i></span> is there to let you do some processing in the logon page.</p>
<p id="lxfz">    The <span id="hy1c"><i id="re98">filterProcessesUrl </i></span><span id="hy1c">is represents the URL that this filter responds to. In this example you can see the default value.</span></p>
<p id="lxfz">    The <span id="kh0_"><i id="o6f3">defaultTargetUrl</i></span> points to the URL that follows a successful authentication (unless the HttpSession attribute called ACEGI_SAVED_REQUEST_KEY points to somewhere else). Fully qualified URLs can be used too.</p>
<p id="lxfz">    The <span id="jjp0"><i id="yhzh">alwaysUseDefaultTargetUrl</i></span> just overrides the ACEGI_SAVED_REQUEST_KEY. Event if this key exists the redirect will still be made to the default target URL.<br id="e86x"></p>
<p id="lxfz"> <span id="hy1c"><br id="jh6r"></span></p>
<p id="lxfz">- it&#8217;s now time to configure the AuthenticationProvider (used by the <span id="c-j5"><i id="fs8v">authenticationManager</i></span> above).<br id="ryoh"></p>
<p id="lxfz"><br id="a59e"></p>
<p id="lxfz">    There are quite a few options here: DAO Authentication Provider, JAAS, Run-As, Form, Basic, Digest, Remember Me, LDAP, X509, CAS, Container Adapter, etc. I will only talk about the DAO Authentication Provider here. An authentication provider is basically a class that can process a specific Authentication implementation. The provider will use a a <span id="etb4"><i id="coel">userDetailsService</i></span> to retrieve the <span id="exuo"><i id="tmdg">UserDetails</i></span> object via the <span id="j-73"><i id="o:c9">loadUserByUsername(String username)</i></span> call. <br id="xh45"></p>
<p id="lxfz">    The official documen<font id="m2q3" style="font-family: Verdana;" size="2">tations says: &#8220;<span class="Apple-style-span" id="eken" style="border-collapse: separate; color: rgb(0, 0, 0); font-size: 16px; font-variant: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><font id="f48b" size="2"><b id="wzfw">The returned</b> <code class="literal" id="ax5b" style="font-family: Verdana;"><b id="juyt"><i id="exls">UserDetails</i></b></code> <b id="wu0y">is an interface that provides getters that guarantee non-null provision of basic authentication information such as the username, password, granted authorities and whether the user is enabled or disabled</b></font>&#8220;. <font id="whau" size="2">So basically</font></span><font id="qp34" size="2"> the <span id="xo:e"><i id="q7lw">UserDetails</i></span> object is what you all you need <img src='http://www.tmro.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </font><br id="blso"></font></p>
<p id="lxfz"><font id="m2q3" style="font-family: Verdana;" size="2">    Yo</font><font id="u0r8" size="2">u </font>need not do anything to this <span id="q2a5"><i id="am_p">DAOAuthenticationProvider</i></span> unless you have specific needs. let&#8217;s have a look at how the configuration looks like:</p>
<p id="lxfz"><br id="xg19"></p>
<p id="lxfz"><span id="teu4"><b id="q6x9">    [...]</b></span><br id="r1ex"></p>
<p id="lxfz"><span id="cd:e"><b id="n_aa">    &lt;bean id=&#8221;daoAuthenticationProvider&#8221; class=&#8221;org.acegisecurity.providers.dao.DaoAuthenticationProvider&#8221;&gt;</b></span><br id="ds_o" style="font-weight: bold;"><span id="fnf2"><b id="c2p3">          &lt;property name=&#8221;userDetailsService&#8221;&gt;&lt;ref bean=&#8221;jdbcDaoService&#8221;/&gt;&lt;/property&gt; </b></span><br id="zxep" style="font-weight: bold;"><span id="fljs"><b id="g:::">          &lt;property name=&#8221;saltSource&#8221;&gt;&lt;ref bean=&#8221;saltSource&#8221;/&gt;&lt;/property&gt;</b></span><br id="o-r-" style="font-weight: bold;"><span id="yrfn"><b id="q:56">          &lt;property name=&#8221;passwordEncoder&#8221;&gt;&lt;ref bean=&#8221;passwordEncoder&#8221;/&gt;&lt;/property&gt;</b></span><br id="lmg5" style="font-weight: bold;"><span id="trz1"><b id="w9nr">    &lt;/bean&gt;</b></span><br id="w.:8"></p>
<p id="lxfz"><span id="pxvr"><b id="g70_">    [...]</b></span><br id="dmpk"></p>
<p id="lxfz"><br id="cblw"></p>
<p id="lxfz">    The <span id="u.hn"><i id="zk:r">userDetailsService</i></span> points to a bean that is configured to retireve user details from a database. A default database structure is available but you can override the <span id="e8sp"><i id="eidy">usersByUsernameQuery</i></span> and the <span id="h8w."><i id="j.70">authoritiesByUsernameQuery</i></span> if you need to. Typically this should be enough:</p>
<p id="lxfz"><b id="xais">    [...]<br id="lp6z"></b></p>
<p id="lxfz"><b id="g8.:">    &lt;bean id=&#8221;jdbcDaoImpl&#8221; class=&#8221;org.acegisecurity.userdetails.jdbc.JdbcDaoImpl&#8221;&gt;</b></p>
<p id="lxfz"><b id="pq7x">        &lt;property name=&#8221;dataSource&#8221;&gt;</b></p>
<p id="lxfz"><b id="m5.-">            &lt;ref bean=&#8221;dataSource&#8221;/&gt;</b></p>
<p id="lxfz"><b id="fxk1">        &lt;/property&gt;</b></p>
<p id="lxfz"><b id="k-5v">    &lt;/bean&gt;<br id="gnum"></b></p>
<p id="lxfz"><span id="qpbo"><b id="e3q5">    [...]</b></span><br id="f7x0"></p>
<p id="lxfz">I will not explain how to configure a dataSource here.</p>
<p id="lxfz"><br id="eo9e"></p>
<p id="lxfz">    The <span id="q-ei"><i id="bh1-">saltSource</i></span> is just some salt that you can add to the passwords, while the <span id="i.da"><i id="josi">passwordEncoder</i></span> (e.g. <span id="i1x6"><i id="vw3-">Md5PasswordEncoder</i></span>) is used to encode and decode the passwords in the <span id="rsqv"><i id="ylc8">UserDetails</i></span> object returned by the <span id="z2ie"><i id="wqf2">UserDetailsService</i></span>.</p>
<p id="lxfz"><br id="bg5j"></p>
<h3 id="lxfz">2. The logon.jsp<br id="xng4"></h3>
<p id="lxfz">When a resource that is protected is accessed, the exceptionTranslationFilter will use the <span id="hh5h"><i id="zs8.">authenticationEntryPoint</i></span> to load the logon form (assuming that is how we configured it). So in the ss.xml there should be something like this:</p>
<p id="lxfz"><b id="urao">    [...]<br id="przh"></b></p>
<p id="lxfz"><b id="bg41">   &lt;bean id=&#8221;exceptionTranslationFilter&#8221; class=&#8221;org.acegisecurity.ui.ExceptionTranslationFilter&#8221;&gt;<br id="pjdx">      &lt;property name=&#8221;authenticationEntryPoint&#8221;&gt;&lt;ref local=&#8221;authenticationFilterEntryPoint&#8221;/&gt;&lt;/property&gt;<br id="kh4d">   &lt;/bean&gt;<br id="xwnm"></b></p>
<p id="lxfz"><b id="wh59">   &lt;bean id=&#8221;authenticationFilterEntryPoint&#8221; class=&#8221;org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint&#8221;&gt;<br id="dzsh">        &lt;property name=&#8221;loginFormUrl&#8221;&gt;<br id="cyeh">            &lt;value&gt;/logon.jsp&lt;/value&gt;<br id="vgfu">        &lt;/property&gt;<br id="v9ur">        &lt;property name=&#8221;forceHttps&#8221;&gt;<br id="zuxf">            &lt;value&gt;false&lt;/value&gt;<br id="m6lu">        &lt;/property&gt;<br id="p7d4">    &lt;/bean&gt;<br id="rcn9"></b></p>
<p id="lxfz"><span id="b5nd"><b id="ye08">    [...]</b></span><br id="cjn_"></p>
<p id="lxfz"><br id="lxme"></p>
<p id="lxfz">Now these beans look quite obvious. Let me know if you want more details on this.</p>
<p id="lxfz"><br id="w5m0"></p>
<p id="lxfz">The logon.jsp page itself will be built around the form. Here is a simplistic approach:</p>
<p id="lxfz"><b id="zq05">    &lt;form action=&#8221;j_acegi_security_check&#8221; method=&#8221;POST&#8221;&gt;</b></p>
<p id="lxfz"><b id="agxm">        &lt;input type=&#8221;text&#8221; id=&#8221;j_username&#8221; name=&#8221;j_username&#8221;&gt;</b></p>
<p id="lxfz"><b id="zg_4">        &lt;br /&gt;</b></p>
<p id="lxfz"><b id="i2dt">        &lt;input type=&#8221;password&#8221; name=&#8221;j_password&#8221;&gt;</b></p>
<p id="lxfz"><b id="pgs4">        &lt;br /&gt;</b></p>
<p id="lxfz"><b id="d9xn">        &lt;input type=&#8221;submit&#8221; class=&#8221;button&#8221; value=&#8221;Logon&#8221;/&gt;<br id="whsc"></b></p>
<p id="lxfz"><span id="ywc1"><b id="anq9">    &lt;/form&gt;</b></span><br id="wurz"></p>
<p id="lxfz"><br id="oguu"></p>
<p id="lxfz">When the form is submitted, Spring Securit<br />
y will intercept and process it.</p>
<p><br id="m.rf">
<p id="lxfz"><br id="dvfi"></p>
<h3 id="ofz0">3. Controlling the JSP output<br id="h49s"></h3>
<p>This is where the authorization tag libraries come into play. SS&#8217;s (lol) authorization tag lib is called <span id="m.ga"><b id="l4kw">authz</b></span> and you can find it in the <span id="kxcx"><b id="t:03">&gt;../acegi-security-x.x.x.jar/META-INF/authz.tld <br id="yudq"></b></span>The <span id="zf-d"><b id="abxh">A</b></span><span id="tmn_"><b id="v1v-">uthorize</b></span><span id="inm0"><b id="olzr">Tag</b></span> declares three attributes: <span id="f:3c"><b id="b-l.">ifNotGranted, ifAllGranted, ifAnyGranted</b></span>. This is also the order in which they are verified. With any of the tags you can specifiy a list of comma separated ROLEs (the whitespaces are ignored). Here&#8217;s an example taken from Ben Alex&#8217;s <a href="http://www.acegisecurity.org/guide/springsecurity.html#authorization-taglibs" id="xz30" target="_blank" title="guide">guide</a>:<br id="e5sl"><span id="bv4w"><b id="gc:l">&lt;authz:authorize ifAllGranted=&#8221;ROLE_SUPERVISOR&#8221;&gt;</b></span><br id="kspl" style="font-weight: bold;"><span id="pirl"><b id="m7sj">    &lt;td&gt;</b></span><br id="h985" style="font-weight: bold;"><span id="ovey"><b id="z0:j">        &lt;A HREF=&#8221;del.htm?id=&lt;c:out value=&#8221;${contact.id}&#8221;/&gt;&#8221;&gt;Del&lt;/A&gt;</b></span><br id="s1vy" style="font-weight: bold;"><span id="zrp6"><b id="ymh8">    &lt;/td&gt;</b></span><br id="kxys" style="font-weight: bold;"><span id="eq9a"><b id="mga5">&lt;/authz:authorize&gt;</b></span>Basically, if the principal (remember the <span id="i_kf"><i id="p04m">UserDetails</i></span> ?) doesn&#8217;t have the ROLE_SUPERVISOR then the user won&#8217;t even see the Del anchor. So, with the ifAllGranted all roles must be granted to this principal, with ifAnyGranted at least one role must be granted while with the ifNotGranted none of the roles should be granted in order to output the code enclosed by this auth:authorize tag.<br id="rob7"><br id="yb8n">I will only mention that SS also provides support for Access Control Lists via authz:accesscontrollist. Please see the official documentation for more details.<br id="tmlc"><br id="ts9o"><br />
<h3 id="hsw2">4. Secure Object Implementations</h3>
<p id="lxfz">Securing the front end is not always (okay never) enough. The better way of making sure that the business objects are not available to un-authenticated users. To protect them SS uses something called <span id="x98y"><i id="amuq">MethodSecurityInterceptor</i></span>.<font id="t-_1" size="2"><br id="ezma"></font></p>
<p id="lxfz">    <span id="y5.l"><b id="lsao">&lt;bean id=&#8221;</b></span><span id="a3_3" style="font-family: Verdana;"><b id="vxt1">bankManagerSecurity</b></span><span id="q:tu"><b id="h-us">&#8221; class=&#8221;org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor&#8221;&gt;</b></span><br id="lsc7" style="font-weight: bold;"></p>
<p id="lxfz"><b id="agv1">        &lt;property name=&#8221;validateConfigAttributes&#8221;&gt;</b></p>
<p id="lxfz"><b id="qyb2">            &lt;value&gt;true&lt;/value&gt;</b></p>
<p id="lxfz"><b id="gshq">        &lt;/property&gt;<br id="aqfa"></b></p>
<p id="lxfz"><b id="s88q">        &lt;property name=&#8221;authenticationManager&#8221;&gt;</b></p>
<p id="lxfz"><b id="i7jh">            &lt;ref bean=&#8221;authenticationManager&#8221;/&gt;</b></p>
<p id="lxfz"><b id="dlhi">        &lt;/property&gt;<br id="pmhh"></b></p>
<p id="lxfz"><b id="dnkm">        &lt;property name=&#8221;accessDecisionManager&#8221;&gt;</b></p>
<p id="lxfz"><b id="an0y">            &lt;ref bean=&#8221;accessDecisionManager&#8221;/&gt;</b></p>
<p id="lxfz"><b id="s44.">        &lt;/property&gt;<br id="a0bi"></b></p>
<p id="lxfz"><b id="ok:s">        &lt;property name=&#8221;runAsManager&#8221;&gt;</b></p>
<p id="lxfz"><b id="jc66">            &lt;ref bean=&#8221;runAsManager&#8221;/&gt;</b></p>
<p id="lxfz"><b id="sddl">        &lt;/property&gt;<br id="otsv"></b></p>
<p id="lxfz"><b id="r.8-">        &lt;property name=&#8221;objectDefinitionSource&#8221;&gt;<br id="obbc"></b></p>
<p id="lxfz"><b id="eo:e">            &lt;value&gt;</b></p>
<p id="lxfz"><b id="a7uw">                org.acegisecurity.context.BankManager.delete*=ROLE_SUPERVISOR,RUN_AS_SERVER<br id="k.q_"></b></p>
<p id="lxfz"><b id="vvtz">                org.acegisecurity.context.BankManager.getBalance=ROLE_TELLER,ROLE_SUPERVISOR,BANKSECURITY_CUSTOMER,RUN_AS_SERVER</b></p>
<p id="lxfz"><b id="aonz">            &lt;/value&gt;<br id="sh0i"></b></p>
<p id="lxfz"><b id="a5:_">        &lt;/property&gt;<br id="qxsl"></b></p>
<p id="lxfz"><b id="z1oz">    &lt;/bean&gt;</b></p>
<p><br id="nkuh">
<p id="lxfz"><br id="yt.j"></p>
<p id="lxfz">The important thing to look at in this example is the <span id="ksfo"><i id="tnf-">objectDefinitionSource</i></span>. There are three ways to define with method invocations will be intercepted and checked. <br id="iizo"></p>
<p id="lxfz">1. Using a property editor</p>
<p id="lxfz">2. Using Jakarta Commons Attributes (you know, the @@SecurityConfig(&#8220;&#8221;ROLE_DUMB&#8221;) syntax&#8230;)</p>
<p id="lxfz">3. Using Java Annotations (where you will make full use of the @Secured annotation).</p>
<p id="lxfz"><br id="wa8x"></p>
<p id="lxfz">Here is the example from the official documentation for using java 5 style annotations:</p>
<p style="font-family: Verdana;" id="lxfz"><span id="nei6" style="font-family: Verdana;"><font id="tngp" size="2"><br id="r5jz"></font></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="nei6" style="font-family: Verdana;"><span id="i.8f"><b id="ss5y">    &lt;bean id=&#8221;attributes&#8221; class=&#8221;org.acegisecurity.annotation.SecurityAnnotationAttributes&#8221;/&gt;</b></span></span><span id="b082" style="font-family: Verdana;"><br id="w96g"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="b082" style="font-family: Verdana;"><b id="qs14">    &lt;bean id=&#8221;objectDefinitionSource&#8221; class=&#8221;org.acegisecurity.intercept.method.MethodDefinitionAttributes&#8221;&gt;</b></span><span id="lhm." style="font-family: Verdana;"><br id="njrz"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="lhm." style="font-family: Verdana;"><b id="rifw">        &lt;property name=&#8221;attributes&#8221;&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="lhm." style="font-family: Verdana;"><b id="cupx">            &lt;ref local=&#8221;attributes&#8221;/&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="lhm." style="font-family: Verdana;"><b id="mb0w">        &lt;/property&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz">    <font id="k9uj" size="2"><span id="oqo8" style="font-family: Verdana;"><b id="l:pn">&lt;/bean&gt;</b></span></font><span id="y_-o" style="font-family: Verdana;"><br id="gvqz"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="y_-o" style="font-family: Verdana;"><b id="qg_1">    &lt;bean id=&#8221;bankManagerSecurity&#8221; class=&#8221;org.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor&#8221;&gt;</b></span><span id="p55k" style="font-family: Verdana;"><br id="plxp"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="p55k" style="font-family: Verdana;"><b id="gp9b">        &lt;property name=&#8221;validateConfigAttributes&#8221;&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="p55k" style="font-family: Verdana;"><b id="rz95">            &lt;value&gt;false&lt;/value&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="p55k" style="font-family: Verdana;"><b id="xdlw">        &lt;/property&gt;</b></span><span id="rr61" style="font-family: Verdana;"><br id="lteq"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="rr61" style="font-family: Verdana;"><b id="k41f">        &lt;property name=&#8221;authenticationManager&#8221;&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="rr61" style="font-family: Verdana;"><b id="nwuv">            &lt;ref bean=&#8221;authenticationManager&#8221;/&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="rr61" style="font-family: Verdana;"><b id="izj4">        &lt;/property&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz">        <span id="hf05" style="font-family: Verdana;"><b id="zhf-">&lt;property name=&#8221;accessDecisionManager&#8221;&gt;</b></span></p>
<p style="font-family: Verdana<br />
;" id="lxfz"><span id="hf05" style="font-family: Verdana;"><b id="tor2">            &lt;ref bean=&#8221;accessDecisionManager&#8221;/&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="hf05" style="font-family: Verdana;"><b id="d_om">        &lt;/property&gt;</b></span><span id="d0q5" style="font-family: Verdana;"><br id="v9ne"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="d0q5" style="font-family: Verdana;"><b id="s2m7">        &lt;property name=&#8221;runAsManager&#8221;&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="d0q5" style="font-family: Verdana;"><b id="mgz3">            &lt;ref bean=&#8221;runAsManager&#8221;/&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="d0q5" style="font-family: Verdana;"><b id="j0tz">        &lt;/property&gt;</b></span><span id="cxmz" style="font-family: Verdana;"><br id="g1wp"></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="cxmz" style="font-family: Verdana;"><b id="tg2o">        &lt;property name=&#8221;objectDefinitionSource&#8221;&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="cxmz" style="font-family: Verdana;"><b id="kv6t">            &lt;ref bean=&#8221;objectDefinitionSource&#8221;/&gt;</b></span></p>
<p style="font-family: Verdana;" id="lxfz"><span id="cxmz" style="font-family: Verdana;"><b id="no7-">        &lt;/property&gt;</b></span><font id="x0cb" size="2"><span id="y_ba" style="font-family: Verdana;"><font id="z6:p" size="2"><br id="t0du"></font></span></font></p>
<p style="font-family: Verdana;" id="lxfz"><font id="x0cb" size="2"><span id="y_ba" style="font-family: Verdana;"><font id="z6:p" size="2"><b id="y6dh">    &lt;/bean&gt;</b></font></span></font></p>
<p style="font-family: Verdana;" id="lxfz"><font id="yjcu" size="3"><br id="yhdd"></font></p>
<p id="lxfz"><span id="sjev" class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 16px; font-variant: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">
<pre id="i5j4" class="programlisting"><font id="bp9a" size="3"><span id="s9yh" style="font-family: Verdana;"><b id="wwtz">    import org.acegisecurity.annotation.Secured;</b></span><br id="f92l" style="font-family: Verdana;"><br id="u0yl" style="font-family: Verdana;"><span id="wjgi" style="font-family: Verdana;"><b id="eo97">    public interface BankManager {</b></span><br id="qly." style="font-family: Verdana;"><br id="kn67" style="font-family: Verdana;"><span id="apra" style="font-family: Verdana;"><b id="tkh5">        /**</b></span><br id="j:um" style="font-family: Verdana;"><span id="i:5s" style="font-family: Verdana;"><b id="pdft">         * Delete something</b></span><br id="outu" style="font-family: Verdana;"><span id="yppr" style="font-family: Verdana;"><b id="we.k">         */</b></span><br id="b8sp" style="font-family: Verdana;"><span id="k_xg" style="font-family: Verdana;"><b id="er9:">        @Secured({"ROLE_SUPERVISOR","RUN_AS_SERVER" })</b></span><br id="b:k9" style="font-family: Verdana;"><span id="icd8" style="font-family: Verdana;"><b id="iu34">        public void deleteSomething(int id);</b></span><br id="kfft" style="font-family: Verdana;"><br id="c8jl" style="font-family: Verdana;"><span id="atff" style="font-family: Verdana;"><b id="gp0t">       /**</b></span><br id="ajoe" style="font-family: Verdana;"><span id="v3c5" style="font-family: Verdana;"><b id="g2xw">         * Delete another</b></span><br id="dvpa" style="font-family: Verdana;"><span id="r78l" style="font-family: Verdana;"><b id="y.30">         */</b></span><br id="drym" style="font-family: Verdana;"><span id="t-ip" style="font-family: Verdana;"><b id="q66-">        @Secured({"ROLE_SUPERVISOR","RUN_AS_SERVER" })</b></span><br id="sciv" style="font-family: Verdana;"><span id="ku.8" style="font-family: Verdana;"><b id="xcqn">        public void deleteAnother(int id);</b></span><br id="d7qc" style="font-family: Verdana;"><span id="rzko" style="font-family: Verdana;"><b id="ay34">    }</b></span></font><font id="jfcn" size="2"><span id="e4p3" class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Verdana; font-size: 16px; font-variant: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><br id="sl1h"><font id="v_d-" size="3"><br id="zgw7"></font><font style="font-family: Verdana;" id="eld." size="2">Please note that when using <code style="font-family: Verdana;" id="kfa3" class="literal"><i id="ql_-">BeanNameAutoProxyCreator</i></code> to create the required proxy for security, the configuration must contain the property <code style="font-family: Verdana;" id="uwal" class="literal"><i id="t564">proxyTargetClass</i></code> set to <code style="font-family: Verdana;" id="se99" class="literal"><i id="nuo0">true</i></code>. Otherwise, the method passed to <code style="font-family: Verdana;" id="s7ya" class="literal"><i id="e:in">MethodSecurityInterceptor.invoke</i></code> is the proxy's caller, not the proxy's target.</font></span></font><br id="zq_k"><br id="rs3y"><font id="h4by" size="3"><span id="o3s3" style="font-family: Verdana;">If you want to hear the whole story, make sure you visit </span><a style="font-family: Verdana;" href="http://acegisecurity.org/guide/springsecurity.html" id="f67u" target="_blank" title="Open the guide in a new window.">Acegi Security Guide</a><span id="ys4e" style="font-family: Verdana;">. Ben Alex has done a great job documenting this framework, the API's are not too bad either, with just a few DOCUMENT ME exceptions <img src='http://www.tmro.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></font></pre>
<p></span></p>
<p id="lxfz">Cheers&#8230;<br id="ci4o"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2008/04/applying-acegi-security-springsecurity-to-an-existing-javaee-ap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Certification</title>
		<link>http://www.tmro.net/2008/01/spring-certification/</link>
		<comments>http://www.tmro.net/2008/01/spring-certification/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 19:47:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=55</guid>
		<description><![CDATA[Today I attended a presentation on Spring Certification. Woke up at 5:50 am so don&#39;t be surprised if I forgot something! So if you are interested in getting a Spring ]]></description>
			<content:encoded><![CDATA[<p>Today I attended a presentation on Spring Certification. Woke up at 5:50 am so don&#39;t be surprised if I forgot something!</p>
<p>So if you are interested in getting a Spring Certification (from SpringSource the former Interface 21) here is what you need to know: </p>
<p>The SFPC (Spring Framework Professional Certificate):<br />- consists of 50 non-weighted multiple choice questions<br />- covers 10 topic areas<br />- lasts 88 minutes<br />- you pass if you score over 75% <br />- you&#39;ll get the result and the hardcopy on the spot at the test centre and a softcopy of result via email </p>
<p>Costs:<br />- free for those who attended Spring Courses until January 1st 2008<br />- free for grandfathered candidates (successful Spring product solution completed before January 1st 2008 or have added value to the Spring Community before January 1st 2008 ) <br />- USD150 or Eur125 for everyone else</p>
<p>Don&#39;t fail or you&#39;ll be locked out for 30 days <img src='http://www.tmro.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Throughout the year 2008, SpringSource will also be offering the following certifications:
<ul>
<li>SpringSource Web Professional (S2WP)</li>
<li>SpringSource AOP Professional (S2AP)</li>
<li>SpringSource Integration Professional (S2IP)</li>
<li>SpringSource Management and Monitoring Professional (S2MP)</li>
</ul>
<p> Useful links:<br /><a href="http://www.pearsonvue.com/">www.pearsonvue.com/SpringSource</a><br /><a href="http://www.springsource.com/certification">www.springsource.com/certification</a><br />email: certifications at springsource .com </p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2008/01/spring-certification/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
