<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Living to code</title>
	
	<link>http://livingtocode.com</link>
	<description />
	<lastBuildDate>Sun, 13 Dec 2009 10:34:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/LivingToCode" /><feedburner:info uri="livingtocode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>DTD calling home</title>
		<link>http://feedproxy.google.com/~r/LivingToCode/~3/EE0MsfBn4-I/</link>
		<comments>http://livingtocode.com/2009/12/dtd-calling-home/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 10:34:24 +0000</pubDate>
		<dc:creator>Christian Hang</dc:creator>
				<category><![CDATA[Technical Notes to Self]]></category>
		<category><![CDATA[DTD]]></category>
		<category><![CDATA[SAX]]></category>
		<category><![CDATA[Xerces]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://livingtocode.com/?p=102</guid>
		<description><![CDATA[Facing the entrance of the office, we have a monitor displaying several development related indicators, like recent build results, the last commit statistics and so forth. While walking into the office one morning, I noticed that the statuses [sic] of several of our overnight unit tests had changed to crimson red. Upon closer inspection it [...]]]></description>
			<content:encoded><![CDATA[<p>Facing the entrance of the office, we have a monitor displaying several development related indicators, like recent build results, the last commit statistics and so forth. While walking into the office one morning, I noticed that the statuses [<a href="http://www.merriam-webster.com/dictionary/status">sic</a>] of several of our overnight unit tests had changed to crimson red. Upon closer inspection it became clear, that all failed tests were related to parsing XML configuration files for <a href="http://struts.apache.org">Struts</a>.</p>
<p>Going through the logs showed each test case was throwing the same exception:</p>
<pre>
java.io.FileNotFoundException: http://struts.apache.org/dtds/struts-config_1_1.dtd
</pre>
<p>This originated inside a <a href="http://www.ibm.com/developerworks/xml/library/x-saxapi/">SAX</a> parser which was parsing several different <code>struts-config.xml</code> for those test cases. A simple text search revealed that the Struts configuration files all started with the following preamble:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE struts-config PUBLIC</span>
<span style="color: #00bbdd;">   &quot;-//Apache Software Foundation//DTD Struts Configuration 1.1//EN&quot;</span>
<span style="color: #00bbdd;">   &quot;http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd&quot;&gt;</span></pre></td></tr></table></div>

<p>That <code>DOCTYPE</code> declaration references an external DTD &#8211; given in the URL pointing to the Apache web site &#8211; which the SAX Parser tries to parse as well when it hits the declaration: it opens an HTTP connection in order to read the file. That operation failed, thus causing the test cases to fail as well. This actually raises two issues: Why was the parser not able to connect to the above URL (which is a valid server and document name) and why did it try to do so in the first place?</p>
<p>The first question was quickly dismissed, as the failure probably resulted from some network glitch which could not be reproduced, but the second one was rather alarming. The software tested by the unit tests is supposed to run in a rather restricted environment and should not establish any outbound network connections that are not explicitly requested by the user. So how come the Java <a href="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/SAXParser.html"><code>SAXParser</code></a> started to connect to remote web sites? The answer is simple: That’s what it’s supposed to do.</p>
<h3>Document Type Definitions</h3>
<p>XML has become the major data exchange format and even though shockingly many applications don&#8217;t seem to care, the provider and consumer of the XML should both have a clear understanding of how the document they create or parse should be structured. This was originally achieved through a document type definition (<a href="http://en.wikipedia.org/wiki/Document_Type_Definition">DTD</a>), which has been replaced with the more flexible <a href="http://www.w3.org/TR/xmlschema-1/">XML schema</a> language in recent years. </p>
<p>A DTD can appear inside the XML document it defines or in an external file, which is referenced through a document type declaration (DOCTYPE) as seen above. In both cases the DTD can contain the following information:</p>
<ul>
<li><strong>Element</strong> declarations: This defines the names of elements (tags) that can appear in the document, the content that can appear inside an element (text, nothing, other elements) and what kind of attributes an element can have (see next item)</li>
<li><strong>Attribute</strong> list declarations: This defines groups of attributes that can be assigned to elements, including what content each attribute can contain, if it&#8217;s optional or required and what default values are assigned</li>
<li><strong>Entity</strong> declarations: Entities can be thought of as place holders that should be replaced with other text. The most commonly known entities are the special character entities in HTML, e.g., <code>&amp;lt;</code> which is replaced by <code>&lt;</code>, but you can also define custom ones, for example that <code>&amp;company;</code> should be replaced with <i>Snake Oil International, Inc.</i></li>
<li><strong>Notation</strong> declarations: These allow to define formats of non-XML data, mostly using MIME-types, e.g., for images or other binary data that is referenced in the document and should be handled by the parsing application</li>
</ul>
<p>To parse the XML data correctly and present the document content to the application reading the XML, the parser needs to take the DTD into consideration. If the DTD defines that there is an implicit attribute on an element with a default value, that attribute should be reported to the application when encountering that type of element, even though the attribute might not exist in the document on that element. In the same way, entities should be expanded and replaced with the text they represent, as the application wouldn&#8217;t know what text to substitute for the entity.</p>
<p>Thus, the XML parser should parse an inline DTD or external reference to one if either one is encountered. This is also the default setting in a lot of SAX parsers, including <a href="http://xerces.apache.org/xerces-j/">Xerces</a>, which is used by our test cases. However, in some cases the application might not care about validating the XML or should at least not try to read external entities or document type definitions. </p>
<h3>Configuring the XML Parser</h3>
<p>In addition to loading external DTDs, there are a lot of other issues that you might want to configure for your XML parser: Should it validate the document as it parses it, or don&#8217;t care about the content? Are <a href="http://www.w3.org/TR/xml-names/">XML namespaces</a> important to you? If you do want to load external schema definitions, how do you want to resolve the URLs? These issues are called &#8220;features&#8221; in the Java XML APIs, they are identified through a URL and there are <a href="http://java.sun.com/javase/6/docs/api/org/xml/sax/package-summary.html#package_description">several standard features</a> every SAX compliant parser must support. In addition, the specific parser implementations provide extensions to that standard set, the one to turn of external DTD loading is available in the specific <a href="http://xerces.apache.org/xerces-j/features.html">Xerces feature list</a> and is called</p>
<pre>

http://apache.org/xml/features/nonvalidating/load-external-dtd
</pre>
<p>To deactivate this feature, you can tell the <a href="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html"><code>SAXParserFactory</code></a> directly:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">SAXParserFactory factory <span style="color: #339933;">=</span> SAXParserFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
factory.<span style="color: #006633;">setFeature</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://apache.org/xml/features/nonvalidating/load-external-dtd&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
SAXParser parser <span style="color: #339933;">=</span> factory.<span style="color: #006633;">newSAXParser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Alternatively, you can set it at the <a href="http://java.sun.com/javase/6/docs/api/org/xml/sax/XMLReader.html"><code>XMLReader</code></a> after the parser was created:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">SAXParser parser <span style="color: #339933;">=</span> SAXParserFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">newSAXParser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
saxParser.<span style="color: #006633;">getXMLReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setFeature</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://apache.org/xml/features/nonvalidating/load-external-dtd&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>These settings can also be applied to other XML related classes, like the <a href="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html"><code>DocumentBuilderFactory</code></a> as <a href="http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references/155874#155874">this stackoverflow.com post</a> describes.</p>
<p>These examples skip any exception handling etc., but should make the point clear where and how to set the settings.</p>
<p>Disabling the feature fixed our test cases and we reviewed all other places we handled XML to see if other features had to be adjusted as well. As mentioned above, deliberately not taking DTDs or XML schemas into consideration might ignore important implicit data inside the XML document, so it should always be verified if the failure to resolve the document definitions is just an annoyance that should be eliminated or a serious problem that needs to be addressed.</p>
<img src="http://feeds.feedburner.com/~r/LivingToCode/~4/EE0MsfBn4-I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://livingtocode.com/2009/12/dtd-calling-home/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://livingtocode.com/2009/12/dtd-calling-home/</feedburner:origLink></item>
		<item>
		<title>Grails, Acegi and the authority ROLE_ prefix</title>
		<link>http://feedproxy.google.com/~r/LivingToCode/~3/DyWa3db1fa0/</link>
		<comments>http://livingtocode.com/2009/11/grails-acegi-and-the-authority-role_-prefix/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 03:15:56 +0000</pubDate>
		<dc:creator>Christian Hang</dc:creator>
				<category><![CDATA[Technical Notes to Self]]></category>
		<category><![CDATA[Acegi Security]]></category>
		<category><![CDATA[Grails]]></category>

		<guid isPermaLink="false">http://livingtocode.com/?p=65</guid>
		<description><![CDATA[After spending way too much time figuring this one out, I am not sure if it&#8217;s an RTFM issue or if the Grails part of the documentation is incomplete/unclear about it. The story goes like this: I was trying to set up a simple Grails application that should include user authentication via LDAP against a [...]]]></description>
			<content:encoded><![CDATA[<p>After spending way too much time figuring this one out, I am not sure if it&#8217;s an RTFM issue or if the Grails part of the documentation is incomplete/unclear about it.</p>
<p>The story goes like this: I was trying to set up a simple <a href="http://grails.org">Grails</a> application that should include user authentication via LDAP against a number of roles stored in the application database. Fortunately, there is a convenient <a href="http://grails.org/plugin/acegi">plugin</a> available that makes <a href="http://www.acegisecurity.org">Acegi Security</a> available for Grails.</p>
<p>I had the business objects and logic pretty much done before I started with the authentication part &#8211; this is a small internal project, so it&#8217;s rather simple stuff &#8211; and as this was a quick rewrite of a legacy application, the users and roles already existed in the database. So I followed the <a href="http://grails.org/AcegiSecurity+Plugin+-+LDAP+Tutorial">appropriate tutorial</a> in the beginning and everything worked fine. The users and roles were mapped correctly and the LDAP connection worked out of the box as I was able to log in with an existing user (I haven&#8217;t been able to get the authentication through bind working yet, but that&#8217;s a separate issue).</p>
<p>I had defined two roles, i.e., <code>DEVELOPER</code> and <code>MANAGER</code>:</p>
<p><a href="http://livingtocode.com/wp-content/uploads/2009/11/grails_example_roles.png"><img src="http://livingtocode.com/wp-content/uploads/2009/11/grails_example_roles.png" alt="Roles in the database" title="Roles in the database" width="402" height="84" class="alignnone size-full wp-image-92" /></a></p>
<p>The configuration was straight forward as well, here is just the part of the <code>SecurityConfig.groovy</code> that affects the user and role mappings:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;">active <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">true</span>
loginUserDomainClass <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;User&quot;</span>
authorityDomainClass <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;Role&quot;</span>
<span style="color: #808080; font-style: italic;">//... some more stuff</span>
useLdap <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">true</span>
useControllerAnnotations <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">true</span>
ldapRetrieveGroupRoles <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">false</span>
ldapRetrieveDatabaseRoles <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">true</span></pre></td></tr></table></div>

<p>For testing purposes, one of the business object controllers was annotated to only accept the <code>MANAGER</code> role.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.grails.plugins.springsecurity.Secured</span>
&nbsp;
@Secured<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'MANAGER'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// THIS DOES NOT WORK</span>
<span style="color: #000000; font-weight: bold;">class</span> MyController <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">def</span> index <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #808080; font-style: italic;">// do something useful</span>
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>But even though the user authentication worked fine, I was not able to access the secured controller after login but would get the &#8220;<strong>Sorry, you&#8217;re not authorized to view this page</strong>&#8221; error message, even though the log showed that the user was granted the correct authorities: <code>Granted Authorities: MANAGER</code>.</p>
<p>I obviously noticed that in the examples all roles had the format <code>ROLE_XYZ</code> and it was mentioned that the roles retrieved through LDAP would be converted into that format automatically, but it didn&#8217;t seem to be a requirement. However, after fixing the setup accordingly, everything worked great:</p>
<p><a href="http://livingtocode.com/wp-content/uploads/2009/11/grails_example_roles_fixed.png"><img src="http://livingtocode.com/wp-content/uploads/2009/11/grails_example_roles_fixed.png" alt="Fixed roles in database" title="Fixed roles in database" width="370" height="83" class="alignnone size-full wp-image-94" /></a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.codehaus.groovy.grails.plugins.springsecurity.Secured</span>
&nbsp;
@Secured<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'ROLE_MANAGER'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// the ROLE_ prefix is a must</span>
<span style="color: #000000; font-weight: bold;">class</span> MyController <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">def</span> index <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #808080; font-style: italic;">// do something useful</span>
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<h3>Behind the scenes</h3>
<p>The requirement for the prefix originates from the default implementation of the <a href="http://static.springsource.org/spring-security/site/docs/2.0.x/apidocs/org/springframework/security/vote/AccessDecisionVoter.html"><code>AccessDecisionVoter</code></a> which is <a href="http://static.springsource.org/spring-security/site/docs/2.0.x/apidocs/org/springframework/security/vote/RoleVoter.html"><code>RoleVoter</code></a> inside the Spring Security code.</p>
<p>That implementation will compare the <code>ConfigAttribute</code>s in the session against the granted authorities. However, there might be attributes that are not roles and should not be considered for comparison &#8211; as that might introduce security vulnerabilities &#8211; so the voter is only taking the attributes into consideration that start with a certain prefix. The corresponding <a href="http://acegisecurity.svn.sourceforge.net/viewvc/acegisecurity/spring-security/tags/spring-security-parent-2.0.4/core/src/main/java/org/springframework/security/vote/RoleVoter.java?revision=3275&#038;view=markup">snippet from <code>RoleVoter.java</code></a> makes that pretty obvious:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>56
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> rolePrefix <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ROLE_&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>75
76
77
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>attribute.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> attribute.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">startsWith</span><span style="color: #009900;">&#40;</span>getRolePrefix<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>It is of course possible to provide a different implementation for <code>AccessDecisionVoter</code>. That class would not have to rely on a prefix, could use a completely different comparison or you could simply pass a different prefix, e.g., an empty String, to the <code>RoleVoter</code>, but I guess unless you have special requirements or cannot prefix your authority names for some odd reason, that shouldn&#8217;t be necessary. Looking at that implementation a couple of lines further down also makes it apparent that the authority names comparisons are case sensitive, another little gotcha to look out for. Some more details about the internals of how Acegi Security handles the authorization is covered in <a href="http://www.javaworld.com/javaworld/jw-10-2007/jw-10-acegi2.html?page=4">this JavaWorld article</a>.</p>
<p>I guess I would have been looking in the right direction earlier, had I created the roles through the generated interfaces instead of using a prepopulated database, as the forms generated by the Grails plugin don&#8217;t accept role names that do not contain <code>"ROLE"</code> in the authority name. Here is a snippet of the <a href="http://fisheye.codehaus.org/browse/grails-plugins/grails-acegi/tags/RELEASE_0_5_2/src/templates/manager/controllers/_UserController.groovy?r=HEAD#l139"><code>UserController</code> template</a> in the Acegi Security plugin 0.5.2:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>137
138
139
140
141
142
143
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">void</span> addRoles<span style="color: #66cc66;">&#40;</span>person<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> key <span style="color: #b1b100;">in</span> params.<span style="color: #006600;">keySet</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>key.<span style="color: #CC0099;">contains</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ROLE'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #ff0000;">'on'</span> <span style="color: #66cc66;">==</span> params.<span style="color: #663399;">get</span><span style="color: #66cc66;">&#40;</span>key<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0000ff;">$<span style="color: #66cc66;">&#123;</span>authorityClassName<span style="color: #66cc66;">&#125;</span></span>.<span style="color: #006600;">findByAuthority</span><span style="color: #66cc66;">&#40;</span>key<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">addToPeople</span><span style="color: #66cc66;">&#40;</span>person<span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Even though this code was probably added with good intentions, it has several major flaws:</p>
<ol>
<li>Any authority name not matching the requirement is <strong>silently dropped</strong> without any feedback</li>
<li>The <strong>constraint is not obvious</strong>, documented or explained in the UI</li>
<li>The check is <strong>semantically wrong</strong>, as the role name <code>"PAROLEE"</code> would be accepted as well &#8211; which would give developers working for the judicial system some headaches, I guess. Here, <code>key.startsWith('ROLE_')</code> would be an improvement</li>
</ol>
<p>Running into this issue would have been at least an indicator that the name can not be chosen arbitrarily. The documentation of the Spring Security classes involved is pretty straight forward, but the tutorials and manuals of the Grails plugin could be a little bit more obvious in that respect. I guess this is just another case of <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">leaky abstractions</a>.</p>
<img src="http://feeds.feedburner.com/~r/LivingToCode/~4/DyWa3db1fa0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://livingtocode.com/2009/11/grails-acegi-and-the-authority-role_-prefix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://livingtocode.com/2009/11/grails-acegi-and-the-authority-role_-prefix/</feedburner:origLink></item>
		<item>
		<title>The Ominous First Post</title>
		<link>http://feedproxy.google.com/~r/LivingToCode/~3/uaWIKF2xwMQ/</link>
		<comments>http://livingtocode.com/2009/10/the-ominous-first-post/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 08:44:45 +0000</pubDate>
		<dc:creator>Christian Hang</dc:creator>
				<category><![CDATA[Housekeeping]]></category>

		<guid isPermaLink="false">http://livingtocode.com/?p=5</guid>
		<description><![CDATA[The first step is always the hardest. Mustering that extra energy that&#8217;s necessary to get moving, which automatically leads to the realization that the decision to try something new has actually been made. This is especially true if you are trying something that you weren&#8217;t really convinced of not too long ago. I&#8217;ve been a [...]]]></description>
			<content:encoded><![CDATA[<p>The first step is always the hardest. Mustering that extra energy that&#8217;s necessary to get moving, which automatically leads to the realization that the decision to try something new has actually been made. This is especially true if you are trying something that you weren&#8217;t really convinced of not too long ago.</p>
<p>I&#8217;ve been a little bit skeptical about the whole blogosphere as a lot of it seemed like random noise that was large revolving around itself.  However, after stumbling over solutions to technical problems I was facing in posts that came up in Google and discovering the value of reading development related blogs for keeping up with current industry issues, I started to reconsider my point of view. There was suddenly an urge to chime into some of the discussions or to give back some fix suggestions for issues that I had to figure out myself.</p>
<h3>Opinions</h3>
<p>To dip my toes into the water I started an internal blog for the development team in the compay I work for. This was at first just intended to improve communication in the team, which worked out great. After some time, though, I caught myself putting more general thoughts into some posts which went beyond the character of internal communication. Some of these topics reflected current debates that were raised on popular programming blogs or in podcasts, which were picked up within our team and resulted in interesting discussions.</p>
<p>Some of the internal contributions made to those debate were quite intriguing, and I realized the value of getting feedback and the potential that a blog has as a medium. So part of the reason for putting up a public blog is to be able to participate in some of those distributed pondering of ideas and opinions. </p>
<p>Being a German software developer working in an international team in Taiwan with an English and Chinese speaking environment, there is of course also the faint hope that the rather uncommon circumstances of my professional life could provide some interesting insight to other people out there. I would currently consider that more a nice by-product than an integral part of the experiment, though.</p>
<h3>Technical notes to self</h3>
<p>Everything mentioned above about the exchange of ideas and participation in debates of course assumes that there is somebody actually reading what I am coming up with here. At this point, though, I am pretty sure that I am writing for nobody else but myself and Google &#8211; given that their algorithm deems anything here worthy of indexing. </p>
<p>As mentioned before, having a Google indexed scrap pad with notes of technical nature is the other major motivation for starting this experiment. For now I will consider the description of technical challenges and the solutions I&#8217;ve found as notes for myself, the blog simply serves as incentive to actually write them down which hopefully makes it easier to remember them or to find them more efficiently. If somebody finds them helpful, that&#8217;s even better. I could count that as good Karma as I would finally be able to give back to the hordes of software developers from whose posts and forum contributions I&#8217;ve profited so often before.</p>
<p>It seems like the first step has been made, there is now a real post that somewhat outlines the purpose of this blog and serves as a reminder to myself. Now, I &#8220;just&#8221; need to follow up with some real content &#8211; this feels a little bit like a new feature that is <i>almost</i> finished as the prototype works, it&#8217;s &#8220;just&#8221; the actual implementation that&#8217;s missing.</p>
<img src="http://feeds.feedburner.com/~r/LivingToCode/~4/uaWIKF2xwMQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://livingtocode.com/2009/10/the-ominous-first-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://livingtocode.com/2009/10/the-ominous-first-post/</feedburner:origLink></item>
	</channel>
</rss>

