<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Spring in Practice &#187; security</title>
	<atom:link href="http://springinpractice.com/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://springinpractice.com</link>
	<description>Willie Wheeler&#039;s Spring blog</description>
	<lastBuildDate>Sun, 22 Jan 2012 07:11:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='springinpractice.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Spring in Practice &#187; security</title>
		<link>http://springinpractice.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://springinpractice.com/osd.xml" title="Spring in Practice" />
	<atom:link rel='hub' href='http://springinpractice.com/?pushpress=hub'/>
		<item>
		<title>Quick tip: Spring Security role-based authorization and permissions</title>
		<link>http://springinpractice.com/2010/10/27/quick-tip-spring-security-role-based-authorization-and-permissions/</link>
		<comments>http://springinpractice.com/2010/10/27/quick-tip-spring-security-role-based-authorization-and-permissions/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 08:40:13 +0000</pubDate>
		<dc:creator>Willie Wheeler</dc:creator>
				<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[authorization]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[roles]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://springinpractice.com/?p=424</guid>
		<description><![CDATA[The problem: hardcoded role-based authorization One of the challenges around using Spring Security is that the examples&#8212;both in the documentation &#8230;<p><a href="http://springinpractice.com/2010/10/27/quick-tip-spring-security-role-based-authorization-and-permissions/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=springinpractice.com&amp;blog=4620434&amp;post=424&amp;subd=springinpractice&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>The problem: hardcoded role-based authorization</h3>
<p>One of the challenges around using Spring Security is that the examples&mdash;both in the documentation and on the web&mdash;tend to promote an overly-simple approach to role-based authorization, hardcoding roles in the source in a non-configurable fashion. For example:</p>
<pre style="margin:20px 0;">
@PreAuthorize("hasRole('facultyMember')")
public Newsletter getFacultyNews() { ... }
</pre>
<p>(Assume for the sake of example that ACL-based authorization is overkill for the method in question. The user either has permission to read faculty newsletters or not.)</p>
<p>The problem is that when we decide to make a change&mdash;for example, maybe teaching assistants should be allowed to read the faculty newsletters too&mdash;we have to go into the code to make a change:</p>
<pre style="margin:20px 0;">
@PreAuthorize("hasRole('facultyMember') or hasRole('teachingAssistant')")
public Newsletter getFacultyNews() { ... }
</pre>
<p>For domain object security there&#8217;s no problem because the permissions are cleanly separated from roles. We can map associate individual permissions on domain objects with users and roles as we wish. So the code contains annotations like</p>
<pre style="margin:20px 0;">
@PreAuthorize("hasPermission(#message, write)")
public void editMessage(Message message) { ... }
</pre>
<p>and all is good. We probably won&#8217;t need to change the relationship between the permission and the method itself; we&#8217;ll only need to change who (which users/roles) actually has the write permission on the message in question, and we can do that in the database. So that is nice, and we want the same thing for role-based authorization.</p>
<h3>Solution: use granted authorities to model <i>permissions</i>, not roles</h3>
<p>Here we assume an authentication source that models the desired relationship between users, roles and permissions. The typical relationship would be a many-many relationship between users and roles, and a many-many relationship between roles and permissions. For example:</p>
<p><img src="http://springinpractice.s3.amazonaws.com/springsecurity/refcard106/sample_user_schema.png" alt="Sample custom user schema" /></p>
<p>It would be possible to have a direct relationship between users and permissions too (say to allow for the assignment of fine-grained permissions to specific users in addition to assigning roles), if that were desired.</p>
<p>The schema can be part of some standard authentication source or it can be a custom <code>UserDetailsService</code>; it doesn&#8217;t matter.</p>
<p>At the end of the day we need to transform our user representation into a <code>UserDetails</code>, and the trick is to map <i>permissions</i>&mdash;not roles&mdash;to <code>GrantedAuthority</code> objects to support the <code>getAuthorities()</code> contract on the <code>UserDetails</code> interface. We still have roles, but they matter only insofar as they help to bundle permissions up into convenient packages. The <code>UserDetails</code> implementation will probably expose the roles, but the <code>UserDetails</code> interface simply exposes the permissions (not the roles) via the <code>getAuthorities()</code> method.</p>
<p>It&#8217;s really that simple, and the final result is that we can avoid hardcoding roles in the code:</p>
<pre style="margin:20px 0;">
@PreAuthorize("hasRole('PERM_READ_FACULTY_NEWS')")
public Newsletter getFacultyNews() { ... }
</pre>
<p>As an aside, the predicate name <code>hasRole</code> rather than <code>hasAuthority</code> is a minor annoyance since permissions aren&#8217;t roles. The backing check is against a <code>GrantedAuthority</code> and so <code>hasRole()</code> seems to reflect either the intended or the typical use of <code>GrantedAuthority</code>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/springinpractice.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/springinpractice.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/springinpractice.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/springinpractice.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/springinpractice.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/springinpractice.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/springinpractice.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/springinpractice.wordpress.com/424/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=springinpractice.com&amp;blog=4620434&amp;post=424&amp;subd=springinpractice&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://springinpractice.com/2010/10/27/quick-tip-spring-security-role-based-authorization-and-permissions/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b0a72ae61c5c74a51fe46cf66599b6c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">williewheeler</media:title>
		</media:content>

		<media:content url="http://springinpractice.s3.amazonaws.com/springsecurity/refcard106/sample_user_schema.png" medium="image">
			<media:title type="html">Sample custom user schema</media:title>
		</media:content>
	</item>
		<item>
		<title>Article on Spring Security 2: Hashing and salting passwords</title>
		<link>http://springinpractice.com/2008/10/11/article-on-spring-security-2-hashing-and-salting-passwords/</link>
		<comments>http://springinpractice.com/2008/10/11/article-on-spring-security-2-hashing-and-salting-passwords/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 06:33:22 +0000</pubDate>
		<dc:creator>Willie Wheeler</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[hashing]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[salt]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Spring Security]]></category>

		<guid isPermaLink="false">http://springinpractice.wordpress.com/?p=124</guid>
		<description><![CDATA[One of the things that I&#8217;ve discovered during the writing of this book is 600 pages sounds a lot bigger &#8230;<p><a href="http://springinpractice.com/2008/10/11/article-on-spring-security-2-hashing-and-salting-passwords/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=springinpractice.com&amp;blog=4620434&amp;post=124&amp;subd=springinpractice&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the things that I&#8217;ve discovered during the writing of this book is 600 pages sounds a lot bigger than it actually is. In writing about Spring Security 2, John and I have been forced to be pretty selective about the recipes that we include. There just isn&#8217;t enough room to cover it all.</p>
<p>One of the casualties was a recipe I wrote about using Spring Security 2 to hash and salt passwords. I&#8217;d already written a general article on hashing and salting passwords on my website, but I also wrote one on using Spring Security 2 specifically. But it just didn&#8217;t fit into our chapters.</p>
<p>It wasn&#8217;t for naught, though. It&#8217;s a perfectly good recipe, so I just put it on my website so people can see what kind of information they might expect to find in the book.</p>
<p>Here it is. Hope you enjoy it!</p>
<p><a href="http://wheelersoftware.com/articles/spring-security-hash-salt-passwords.html">http://wheelersoftware.com/articles/spring-security-hash-salt-passwords.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/springinpractice.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/springinpractice.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/springinpractice.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/springinpractice.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/springinpractice.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/springinpractice.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/springinpractice.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/springinpractice.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=springinpractice.com&amp;blog=4620434&amp;post=124&amp;subd=springinpractice&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://springinpractice.com/2008/10/11/article-on-spring-security-2-hashing-and-salting-passwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b0a72ae61c5c74a51fe46cf66599b6c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">williewheeler</media:title>
		</media:content>
	</item>
		<item>
		<title>Excerpt: Login and remember-me discussion</title>
		<link>http://springinpractice.com/2008/09/06/login-remember-me/</link>
		<comments>http://springinpractice.com/2008/09/06/login-remember-me/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 22:37:16 +0000</pubDate>
		<dc:creator>Willie Wheeler</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[openid]]></category>
		<category><![CDATA[passwords]]></category>
		<category><![CDATA[remember-me]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Spring Security]]></category>
		<category><![CDATA[sso]]></category>

		<guid isPermaLink="false">http://springinpractice.wordpress.com/?p=82</guid>
		<description><![CDATA[Spring in Practice centers on using Spring to implement technical solutions to common problems, but it&#8217;s also important for developers &#8230;<p><a href="http://springinpractice.com/2008/09/06/login-remember-me/">Continue reading &#187;</a></p><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=springinpractice.com&amp;blog=4620434&amp;post=82&amp;subd=springinpractice&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="attachment_85" class="wp-caption alignright" style="width: 250px"><a href="http://www.flickr.com/photos/bike/2635107055/"><img class="size-full wp-image-85" title="Human retina" src="http://springinpractice.files.wordpress.com/2008/09/retina.jpg?w=529" alt=""   /></a><p class="wp-caption-text">A healthy human retina. Our book doesn&#039;t go into biometric authentication but this is a cool photo anyway.</p></div>
<p><em><a href="http://www.manning.com/wheeler/">Spring in Practice</a></em> centers on using Spring to implement technical solutions to common problems, but it&#8217;s also important for developers to understand the problem they&#8217;re trying to solve before implementing a solution. In the book we work pretty hard to provide that understanding.</p>
<p>Here&#8217;s an except from the discussion section for a recipe on implementing login forms and remember-me authentication using Spring Security. While discussion sections might treat the problem, the solution or both, this particular discussion digs a little deeper some security/usability tradeoffs to consider when implementing username/password and remember-me authentication.</p>
<blockquote>
<h3>Discussion</h3>
<p>In the background we briefly mentioned that username/password logins are only one approach to authentication. While other authentication mechanisms are commercially available—for example, there are laptops with thumbprint scanners—for most web-based applications, username/password combinations are the most practical approach. It&#8217;s simply unrealistic to assume that general web users will have card readers, key fobs, biometric scanners and so forth. Such assumptions may be more plausible in controlled environments.</p>
<p>It&#8217;s useful to understand some of the drawbacks of username/password authentication. The main drawback is that in general, the stronger a user&#8217;s password is, the harder it is to remember. That in turn increases the chance that the user will either write it down somewhere or else use it for multiple websites, both of which increase the chance that the password will be compromised. Password reuse is problematic partly because a shared password is distributed across many systems (which can be dangerous if that password is not properly managed; see recipes 4.3 and 4.5), and partly because the damage is not limited in the event that the shared password is compromised.</p>
<p>People have devised different approaches to dealing with parts of this problem. One approach is called single sign-on (SSO), and it works nicely in homogeneous computing environments such as corporate intranets. The idea is that the environment (rather than the application) provides for centralized authentication and then that authentication is shared with the applications in that environment. Another approach is the relatively recent OpenID standard, which differs from SSO in being decentralized. With OpenID, a user picks a participating site to be an authentication provider, and then other participating sites use that provider to authenticate the user. This is different than SSO in that with OpenID, different sites require separate logins. While neither SSO nor OpenID does much to limit the damage when a password is compromised (though a password could be reset from a single location), they do have the benefit that they prevent password fatigue without distributing the password across multiple systems.</p>
<p>Remember-me authentication also highlights the tradeoff between security and usability. It&#8217;s important to recognize that we&#8217;re really authenticating the browser rather than the user. Because there are various scenarios in which there&#8217;s a many-to-one relationship between users and browsers (for example, a shared public machine, the family computer, a computer in somebody&#8217;s unlocked office), we should treat remember-me authentication as not-entirely-convincing. One good approach is to give a remember-me user access to low-risk functionality, but to force a login if the user tries to access higher-risk functionality. Amazon uses exactly this technique: remember-me users can see product recommendations, but to buy something they have to log in.</p>
<p>The upshot is this: add login forms and remember-me to your app only if it makes sense to do so. In some cases it would make even more sense to use SSO, auto-provision the accounts, externalize your authentication with OpenID, and so on. Just because Spring Security makes it easy to add a login form and remember-me doesn&#8217;t mean that you should. If you include remember-me in particular, keep in mind the design issues we just discussed.</p>
<p>Now that we&#8217;ve seen how to create a basic, unstyled login form, it&#8217;s time to get to work on making it look better. The next recipe will show you how.</p></blockquote>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/springinpractice.wordpress.com/82/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/springinpractice.wordpress.com/82/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/springinpractice.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/springinpractice.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/springinpractice.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/springinpractice.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/springinpractice.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/springinpractice.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/springinpractice.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/springinpractice.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=springinpractice.com&amp;blog=4620434&amp;post=82&amp;subd=springinpractice&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://springinpractice.com/2008/09/06/login-remember-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b0a72ae61c5c74a51fe46cf66599b6c5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">williewheeler</media:title>
		</media:content>

		<media:content url="http://springinpractice.files.wordpress.com/2008/09/retina.jpg" medium="image">
			<media:title type="html">Human retina</media:title>
		</media:content>
	</item>
	</channel>
</rss>
