<?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"
	>

<channel>
	<title>anorakgirl's blog</title>
	<atom:link href="http://blog.anorakgirl.co.uk/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.anorakgirl.co.uk</link>
	<description>what I found out</description>
	<pubDate>Tue, 03 Aug 2010 20:32:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>MySQL, ERROR 1366 and Windows cmd prompt</title>
		<link>http://blog.anorakgirl.co.uk/?p=149</link>
		<comments>http://blog.anorakgirl.co.uk/?p=149#comments</comments>
		<pubDate>Tue, 03 Aug 2010 20:31:45 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[database]]></category>

		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=149</guid>
		<description><![CDATA[I have been trying to restore a database backup onto my laptop.
The source database used Character Set UTF8, so I created a local database with the same character set. The database contained several unusual characters such as â and é, so I was careful to choose the same character set.
I opened a command prompt and tried to [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trying to restore a database backup onto my laptop.</p>
<p>The source database used Character Set UTF8, so I created a local database with the same character set. The database contained several unusual characters such as â and é, so I was careful to choose the same character set.</p>
<p>I opened a command prompt and tried to load the backup at the command line:</p>
<pre>D:\backup&gt; mysql -u user -ppassword mydb &lt; backup.sql</pre>
<p>I got the error:</p>
<pre>ERROR 1366 (HY000) at line 21364: Incorrect string value:
 '\xC1guas ...' for column 'address2' at row 1</pre>
<p>I checked my.ini, and as far as I could see, everything was set to UTF8.</p>
<p>A quick internet search located this MySQL bug report: <a href="http://bugs.mysql.com/bug.php?id=30131">http://bugs.mysql.com/bug.php?id=30131</a></p>
<p>The work around to set the code page did not seem to work for me.</p>
<p>So I tried loading the backup using a GUI interface to MySQL instead (I use the free <a href="http://www.dbtools.com.br/EN/dbmanagerpro/">DBManager from DbTools</a>). And the backup loaded fine! So definitely some odd behaviour from the Windows Command prompt.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=149</wfw:commentRss>
		</item>
		<item>
		<title>maven, junit, cobertura and BeanCreationException</title>
		<link>http://blog.anorakgirl.co.uk/?p=143</link>
		<comments>http://blog.anorakgirl.co.uk/?p=143#comments</comments>
		<pubDate>Mon, 11 Jan 2010 13:43:51 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[cobertura]]></category>

		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=143</guid>
		<description><![CDATA[I have a set of junit tests for my project. When I run them with mvn test they run fine and pass.
However, when I ran them with mvn cobertura:cobertura, they failed with the following error:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.anorakgirl.MyTest': Autowiring of fields failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.anorakgirl.MyService com.anorakgirl.MyTest.myService;
nested exception is [...]]]></description>
			<content:encoded><![CDATA[<p>I have a set of junit tests for my project. When I run them with <strong>mvn test</strong> they run fine and pass.</p>
<p>However, when I ran them with mvn cobertura:cobertura, they failed with the following error:</p>
<pre>org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.anorakgirl.MyTest': Autowiring of fields failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.anorakgirl.MyService com.anorakgirl.MyTest.myService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No unique bean of type [com.anorakgirl.MyService] is defined:
Unsatisfied dependency of type [class com.anorakgirl.MyService]:
expected at least 1 matching bean</pre>
<p>After some googling, this is the problem. The ServiceObject was annotated with @Autowire. Spring autowires by type. I have only one class of type &#8216;com.anorakgirl.MyService&#8217;. So when run with junit this works fine. However, cobertura changes the type of the MyService class during Instrumentation, so Spring no longer recognises it as type MyService, and so cannot Autowire.</p>
<p>There are two possible answers:</p>
<p><strong>The easy answer (what I did)</strong></p>
<p>In your test application context add the line:</p>
<pre>&lt;aop:config proxy-target-class="true"/&gt;</pre>
<p><strong>The other answer (what I read about)</strong></p>
<p>Make sure the classes that you want to autowire all implement interfaces. Then autowire the interface rather than the implementation. The Cobertura class will still implement the same interface and therefore can still be autowired.</p>
<p>I didn&#8217;t try this as my service classes do not have interfaces and I can&#8217;t be bothered to go through and add them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=143</wfw:commentRss>
		</item>
		<item>
		<title>save MySQL!</title>
		<link>http://blog.anorakgirl.co.uk/?p=141</link>
		<comments>http://blog.anorakgirl.co.uk/?p=141#comments</comments>
		<pubDate>Mon, 04 Jan 2010 10:06:22 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[database]]></category>

		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=141</guid>
		<description><![CDATA[http://www.helpmysql.org
]]></description>
			<content:encoded><![CDATA[<p><a title="Save MySQL" href="http://www.helpmysql.org">http://www.</a><a title="Save MySQL" href="http://www.helpmysql.org">helpmysql</a><a title="Save MySQL" href="http://www.helpmysql.org">.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=141</wfw:commentRss>
		</item>
		<item>
		<title>Developing a Plone Product Part 2</title>
		<link>http://blog.anorakgirl.co.uk/?p=114</link>
		<comments>http://blog.anorakgirl.co.uk/?p=114#comments</comments>
		<pubDate>Wed, 04 Nov 2009 21:46:16 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[Plone]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=114</guid>
		<description><![CDATA[Next I want to add a Portlet which will display any items of the new content type which are in the current folder.
Creating a Plone Portlet
First step seems easy:
cd src/anorakgirl.mycontent
paster addcontent portlet
and then answer the easy questions. This creates a some files in the portlets folder of the product. However, when I restart Plone, I [...]]]></description>
			<content:encoded><![CDATA[<p>Next I want to add a Portlet which will display any items of the new content type which are in the current folder.</p>
<h4>Creating a Plone Portlet</h4>
<p>First step seems easy:</p>
<pre>cd src/anorakgirl.mycontent
paster addcontent portlet</pre>
<p>and then answer the easy questions. This creates a some files in the portlets folder of the product. However, when I restart Plone, I get this error:</p>
<pre>ZopeXMLConfigurationError: File 
"c:\plone\src\anorakgirl.mycontent\anorakgirl\mycontent\portlets\configure.zcml", line 12.2-21.8]
ImportError: cannot import name QuotesPortletMessageFactory</pre>
<p>I fixed this by commenting out the line below from portlets/mycontentportlet.py - who knows if this matters!</p>
<pre>#from anorakgirl.mycontent.portlets import MyContentPortletMessageFactory as _</pre>
<p>Plone now restarts, and I can add the MyContentPortlet via &#8216;Manage Portlets&#8217;. However, it doesn&#8217;t do anything yet.</p>
<p>To make it show the first &#8216;MyContent&#8217; item from the current folder, I modified portlets/mycontentportlet.py as follows. Please note that this code is shamelessly copied from <a title="Professional Plone Development by Martin Aspeli" href="http://www.packtpub.com/Professional-Plone-web-applications-CMS">Professional Plone Development by Martin Aspeli</a>.</p>
<pre>from zope import schema
from zope.component import getMultiAdapter
from zope.formlib import form
from zope.interface import implements
from plone.app.portlets.portlets import base
from plone.memoize.instance import memoize
from plone.portlets.interfaces import IPortletDataProvider
from DateTime import DateTime
from Acquisition import aq_inner
from Products.CMFCore.interfaces import ICatalogTool
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFCore.utils import getToolByName

from anorakgirl.mycontent.interfaces import IMyContent

#from anorakgirl.mycontent.portlets import MyContentPortletMessageFactory as _

class IMyContentPortlet(IPortletDataProvider):
    """A portlet

    It inherits from IPortletDataProvider because for this portlet, the
    data that is being rendered and the portlet assignment itself are the
    same.
    """

class Assignment(base.Assignment):
    """Portlet assignment.

    This is what is actually managed through the portlets UI and associated
    with columns.
    """

    implements(IMyContentPortlet)

    def __init__(self):
        pass

    @property
    def title(self):
        """This property is used to give the title of the portlet in the
        "manage portlets" screen.
        """
        return "MyContent Portlet"

class Renderer(base.Renderer):
	"""Portlet renderer.

	This is registered in configure.zcml. The referenced page template is
	rendered, and the implicit variable 'view' will refer to an instance
	of this class. Other methods can be added and referenced in the template.
	"""

	render = ViewPageTemplateFile('mycontentportlet.pt')

	@property
	def available(self):
		return len(self._data()) &gt; 0

	def mycontent_list(self):
		for brain in self._data():
			mycontent = brain.getObject()

			yield dict(title=mycontent.title,
				description=mycontent.description,
				author=mycontent.author,
				details=mycontent.details)

	@memoize
	def _data(self):
		context = aq_inner(self.context)
		limit = 1
		query = dict(object_provides = IMyContent.__identifier__)
		if self.context.isPrincipiaFolderish:
			query['path'] = '/'.join(context.getPhysicalPath())

		if not self.context.isPrincipiaFolderish:
			parent = context.aq_parent
			query['path'] = '/'.join(parent.getPhysicalPath())</pre>
<pre>		catalog = getToolByName(context, 'portal_catalog')
		results = catalog(query)
		mycontents = []

		mycontents = results[:limit]
		return mycontents

# NOTE: If this portlet does not have any configurable parameters, you can
# inherit from NullAddForm and remove the form_fields variable.

class AddForm(base.AddForm):
    """Portlet add form.

    This is registered in configure.zcml. The form_fields variable tells
    zope.formlib which fields to display. The create() method actually
    constructs the assignment that is being added.
    """
    form_fields = form.Fields(IMyContentPortlet)

    def create(self, data):
        return Assignment(**data)

# NOTE: IF this portlet does not have any configurable parameters, you can
# remove this class definition and delete the editview attribute from the
# &lt;plone:portlet /&gt; registration in configure.zcml

class EditForm(base.EditForm):
    """Portlet edit form.

    This is registered with configure.zcml. The form_fields variable tells
    zope.formlib which fields to display.
    """
    form_fields = form.Fields(IMyContentPortlet)</pre>
<p>Really all that I changed from the paster generated content was the imports and the Render method.</p>
<p>I also amended the template file mycontentportlet.pt to show the data returned by the Render method:</p>
<pre>&lt;dl class="portlet portletMyContentPortlet"
    i18n:domain="anorakgirl.mycontent.portlets"&gt;
    &lt;dd class="portletItem odd"&gt;

        &lt;div tal:define="items view/mycontent_list"&gt;
             &lt;ul&gt;
                 &lt;li tal:repeat="item items"&gt;
                 &lt;span tal:content="item/details"/&gt;
                 &lt;br/&gt;&lt;b tal:content="item/author"&gt;&lt;/b&gt;&lt;/li&gt;
             &lt;/ul&gt;
            &lt;/div&gt;
    &lt;/dd&gt;
&lt;/dl&gt;</pre>
<p>Because paster amended the xml files in the profiles folder ( to register the new portlet) not only do you need to restart Plone, you need to reinstall the product to get the Portlet to show up. I&#8217;m doing this using the Setup &gt; Add-on products page, but this may not be the best way?</p>
<p>You should now be able to add the Portlet using Manage Portlets. If you add it at the root, and the rest of the site is set to inherit parent portlets, then the portlet should show up in any folder in which you add a &#8216;MyContent&#8217; item.</p>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=114</wfw:commentRss>
		</item>
		<item>
		<title>Developing a Plone product part 1</title>
		<link>http://blog.anorakgirl.co.uk/?p=109</link>
		<comments>http://blog.anorakgirl.co.uk/?p=109#comments</comments>
		<pubDate>Mon, 02 Nov 2009 21:10:20 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[Plone]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=109</guid>
		<description><![CDATA[I have to say, I am used to being able to pick up a new tool or environment and start digging behind the scenes without becoming too bewildered, but Plone has not been like that at all. I am very impressed at the front end, but there&#8217;s always something extra required. Python is new to [...]]]></description>
			<content:encoded><![CDATA[<p>I have to say, I am used to being able to pick up a new tool or environment and start digging behind the scenes without becoming <em>too </em>bewildered, but Plone has not been like that at all. I am very impressed at the front end, but there&#8217;s always something extra required. Python is new to me, and I am struggling with the terminology and so on.</p>
<p>So, I am going to record my progress in creating a Plone product. I am currently using Plone 3.2.2, developing on Windows but will be deploying on Linux.</p>
<h4>Useful things I learned so far</h4>
<p>#Run plone in the foreground, so that you can see the output and restart easily</p>
<pre>C:\Plone&gt;bin\plonectl.exe fg</pre>
<p>#If you change a .py or .zcml file, you need to restart Plone to see your changes</p>
<p>#Changes to .pt files should show up immediately in foreground mode</p>
<p>#Changes to .xml files mean the product must be uninstalled and reinstalled  (I think via the front end Setup &gt; Add-on products page is fine)</p>
<h4>My planned product</h4>
<p>I want the site users (Editors/Contributers) to be able to add content into the right hand column, without giving them Manager rights. My plan is this:</p>
<p>1. Create a new content type for this content.  This will simply have a few custom fields, and should not appear in navigation by default (this tutorial).</p>
<p>2. Create a portlet which displays any items of the new content type in the current folder. The portlet will be added at root level and carry through the site, so users simply add the new right hand content where they want it. If the users want specific right hand content for a single page, they would put the page in its own folder. (see next tutorial)</p>
<h4>Getting Started</h4>
<p>I am using paster to create the skeleton of my product. This creates a directory structure with all the required files. It is easiest if paster is in your path.  So, in the src directory:</p>
<pre>paster create -t archetype anorakgirl.mycontent</pre>
<p>And answer the questions that follow:</p>
<pre>Enter title (The title of the project) ['Plone Example']: Anorakgirl MyContent Project
Enter namespace_package (Namespace package (like plone)) ['plone']: anorakgirl
Enter package (The package contained namespace package (like example)) ['example']: mycontent
...</pre>
<p>Use paster to add the actual contentype</p>
<pre>cd anorakgirl.mycontent
paster addcontent contenttype</pre>
<p>Then use paster again to add some fields to the content type.</p>
<pre>paster addcontent atschema</pre>
<p>Again answer the questions. The module name in this case will be mycontent. Repeat the above to add whatever fields you need. Note that you get Title and Description for free, so don&#8217;t add those.</p>
<p>You&#8217;ve now done enough to see the product in action. So</p>
<h4>Adding the product to the build environment</h4>
<p>Add the following lines to buildout.cfg</p>
<pre>[buildout]
...</pre>
<pre>develop =
   src/anorakgirl.mycontent</pre>
<pre>[instance]
...</pre>
<pre>eggs =  
   ...
   anorakgirl.mycontent</pre>
<pre>zcml =
   ...
   anorakgirl.mycontent</pre>
<p>Run buildout.</p>
<p>Start plone (in foreground mode).</p>
<p>Login as an Administrator. Go to Site Setup &gt; Add-on Products. The product should be listed under products to install. Install it.</p>
<p>Your new content type should appear on the Add New menu. The edit form should have all the fields you added. The standard view won&#8217;t be very pretty but that&#8217;s a job for another tutorial&#8230;</p>
<h4>Next Time: creating a Plone portlet to display the new Content Type&#8230;</h4>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=109</wfw:commentRss>
		</item>
		<item>
		<title>Compiling mnogosearch with MySQL support &#038; PHP extension on 64bit Centos5</title>
		<link>http://blog.anorakgirl.co.uk/?p=105</link>
		<comments>http://blog.anorakgirl.co.uk/?p=105#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:35:57 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[database]]></category>

		<category><![CDATA[mnogosearch]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=105</guid>
		<description><![CDATA[We just got a new dedicated server, running Centos 5.  I&#8217;ve just been moving some php websites which use the mnogosearch extension, and finally cracked it.
The main problem I was getting was:
/usr/bin/ld: cannot find -lmysqlclient
Here is a rough outline of what I had to do:
Install Mysql development

yum install mysql-devel

Download &#38; build mnogosearch

wget http://www.mnogosearch.org/Download/mnogosearch-3.3.8.tar.gz
edit &#8220;configure&#8221; script [...]]]></description>
			<content:encoded><![CDATA[<p>We just got a new dedicated server, running Centos 5.  I&#8217;ve just been moving some php websites which use the mnogosearch extension, and finally cracked it.</p>
<p>The main problem I was getting was:</p>
<pre>/usr/bin/ld: cannot find -lmysqlclient</pre>
<p>Here is a rough outline of what I had to do:</p>
<p><strong>Install Mysql development</strong></p>
<ol>
<li>yum install mysql-devel</li>
</ol>
<p><strong>Download &amp; build mnogosearch</strong></p>
<ol>
<li>wget http://www.mnogosearch.org/Download/mnogosearch-3.3.8.tar.gz</li>
<li>edit &#8220;configure&#8221; script so that MYSQL_LIBDIR=/usr/lib64/mysql</li>
<li>install.pl choosing appropriate options (I chose yes for build shared libraries)</li>
<li>make</li>
<li>make install</li>
</ol>
<p><strong>Build PHP extension </strong></p>
<ol>
<li>cd mnogosearch-3.3.8/php</li>
<li>follow instructions in  README file here</li>
<li>service httpd restart</li>
</ol>
<p>(I tried to get it working with PostgreSQL support too, but kept getting &#8220;/usr/bin/ld: cannot find -lpq&#8221;. The fix for setting the library path in the configure file didn&#8217;t seem to work in this case, but I didn&#8217;t try too hard.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=105</wfw:commentRss>
		</item>
		<item>
		<title>Tomcat Error listenerStart</title>
		<link>http://blog.anorakgirl.co.uk/?p=102</link>
		<comments>http://blog.anorakgirl.co.uk/?p=102#comments</comments>
		<pubDate>Mon, 06 Jul 2009 09:30:37 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[log4j]]></category>

		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=102</guid>
		<description><![CDATA[I&#8217;m sure I&#8217;m not the only one who has battled with this startup error:
4985 [main] ERROR org.apache.catalina.core.StandardContext  - Error listenerStart
4985 [main] ERROR org.apache.catalina.core.StandardContext  - Context [/mycontext] startup failed due to previous errors
The problem is getting the real cause of the problem to appear in the log. I&#8217;ve had this problem various times in the past [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure I&#8217;m not the only one who has battled with this startup error:</p>
<p>4985 [main] ERROR org.apache.catalina.core.StandardContext  - Error listenerStart<br />
4985 [main] ERROR org.apache.catalina.core.StandardContext  - Context [/mycontext] startup failed due to previous errors</p>
<p>The problem is getting the real cause of the problem to appear in the log. I&#8217;ve had this problem various times in the past (must be repeating the same mistakes). Today&#8217;s answer was simple:</p>
<ol>
<li>Remove log4j.jar from myapp/WEB-INF/lib (it is already in Tomcat/common/lib)</li>
<li>Restart app.</li>
<li>Debug using the reams of useful error messages which suddenly appear in the output.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=102</wfw:commentRss>
		</item>
		<item>
		<title>Dynarch DHTML Calendar IE7 positioning problem</title>
		<link>http://blog.anorakgirl.co.uk/?p=84</link>
		<comments>http://blog.anorakgirl.co.uk/?p=84#comments</comments>
		<pubDate>Thu, 23 Apr 2009 19:25:14 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[HTML]]></category>

		<category><![CDATA[dhtml]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=84</guid>
		<description><![CDATA[My husband wants me to post this, in case it helps anyone to find the patch&#8230;
We&#8217;ve both used the Dynarch DHTML Calendar in projects over the years. And had been quietly ignoring the fact it has problems in Internet Explorer 7. The calendar displays in the wrong position when you are in Standards Compliance Mode [...]]]></description>
			<content:encoded><![CDATA[<p>My husband wants me to post this, in case it helps anyone to find the patch&#8230;</p>
<p>We&#8217;ve both used the <a title="Dynarch DHTML Calendar" href="http://www.dynarch.com/projects/calendar/">Dynarch DHTML Calendar</a> in projects over the years. And had been quietly ignoring the fact it has problems in Internet Explorer 7. The calendar displays in the wrong position when you are in Standards Compliance Mode (using a proper doctype).</p>
<p>Well&#8230; there&#8217;s a patch, here:<br />
<img src="file:///C:/DOCUME%7E1/tamsin/LOCALS%7E1/Temp/moz-screenshot-19.jpg" alt="" /><a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1679433&amp;group_id=75569&amp;atid=544287">http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1679433&amp;group_id=75569&amp;atid=544287</a></p>
<p>So there you go.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=84</wfw:commentRss>
		</item>
		<item>
		<title>Spring Security: Method Level Security with JSF so far&#8230;</title>
		<link>http://blog.anorakgirl.co.uk/?p=80</link>
		<comments>http://blog.anorakgirl.co.uk/?p=80#comments</comments>
		<pubDate>Thu, 09 Apr 2009 20:46:22 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=80</guid>
		<description><![CDATA[My personal Gotcha&#8217;s in case they are of use to anyone else:
1. Ensure you have compatible versions of Spring and Spring Security. I am using Sping Security 2.0.4 and Spring 2.5.6. Originally my Spring was a slightly older version (2.5) and I got the following error:
java.lang.NoSuchMethodError:
org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary
I fixed this by upgrading to the latest Spring. I [...]]]></description>
			<content:encoded><![CDATA[<p>My personal Gotcha&#8217;s in case they are of use to anyone else:</p>
<p>1. Ensure you have compatible versions of Spring and Spring Security. I am using Sping Security 2.0.4 and Spring 2.5.6. Originally my Spring was a slightly older version (2.5) and I got the following error:</p>
<pre>java.lang.NoSuchMethodError:
org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary</pre>
<p>I fixed this by upgrading to the latest Spring. I think the problem was resolved in Spring 2.5.2 and relates to this bug: <a href="http://jira.springframework.org/browse/SPR-4459">http://jira.springframework.org/browse/SPR-4459</a></p>
<p>2. Make sure the methods you are securing are actually in Spring Managed beans, doh! My @Secured annoration was being ignored entirely, and it took me ages to realise why - some of my beans are still in faces config files, so Spring has no way of knowing about them. Moving the beans into the Spring configuration fixed the problem straight away.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=80</wfw:commentRss>
		</item>
		<item>
		<title>Spring Security 2.0: NTLM filter with custom UserDetailsService</title>
		<link>http://blog.anorakgirl.co.uk/?p=68</link>
		<comments>http://blog.anorakgirl.co.uk/?p=68#comments</comments>
		<pubDate>Thu, 09 Apr 2009 20:03:16 +0000</pubDate>
		<dc:creator>anorakgirl</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[ntlm]]></category>

		<category><![CDATA[security]]></category>

		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.anorakgirl.co.uk/?p=68</guid>
		<description><![CDATA[I used this blog to get started: http://blog.mediasoft.be/ntlm-with-spring-security-20/

My Application-context is pretty much as per the Spring 2.0 configuration at the bottom of the post, with the following changes:

Different properties for the ntlm filter
servlet-api-provision=&#8221;false&#8221; on the &#60;security:http&#62; tag
Addition of custom UserDetailsService.

The full config is below:
&#60;security:authentication-manager alias="_authenticationManager" /&#62;

    &#60;bean id="authenticationProvider"
     class="com.mydomain.security.UserDetailsAuthenticationProvider"&#62;
        &#60;security:custom-authentication-provider [...]]]></description>
			<content:encoded><![CDATA[<p>I used this blog to get started: <a href="http://blog.mediasoft.be/ntlm-with-spring-security-20/">http://blog.mediasoft.be/ntlm-with-spring-security-20/</a></p>
<p><img src="file:///C:/DOCUME~1/tamsin/LOCALS~1/Temp/moz-screenshot-17.jpg" alt="" /></p>
<p>My Application-context is pretty much as per the Spring 2.0 configuration at the bottom of the post, with the following changes:</p>
<ul>
<li>Different properties for the ntlm filter</li>
<li>servlet-api-provision=&#8221;false&#8221; on the &lt;security:http&gt; tag</li>
<li>Addition of custom UserDetailsService.</li>
</ul>
<p>The full config is below:</p>
<pre>&lt;security:authentication-manager alias="_authenticationManager" /&gt;

    &lt;bean id="authenticationProvider"
     class="com.mydomain.security.UserDetailsAuthenticationProvider"&gt;
        &lt;security:custom-authentication-provider /&gt;
        &lt;property name="userDetailsService" ref="userDetailsService" /&gt;
    &lt;/bean&gt;

    &lt;bean id="userDetailsService" class="com.mydomain.security.UserDetailsServiceImpl"&gt;
        &lt;property name="daoUser" ref="daoUser" /&gt;
    &lt;/bean&gt;

    &lt;bean id="ntlmFilter" class="org.springframework.security.ui.ntlm.NtlmProcessingFilter"&gt;
        &lt;security:custom-filter position="NTLM_FILTER" /&gt;
        &lt;property name="stripDomain" value="true" /&gt;
        &lt;property name="defaultDomain" value="mydomain.com" /&gt;
        &lt;property name="domainController" value="mycontroller" /&gt;
        &lt;property name="authenticationManager" ref="_authenticationManager" /&gt;
    &lt;/bean&gt;

    &lt;bean id="ntlmEntryPoint"
     class="org.springframework.security.ui.ntlm.NtlmProcessingFilterEntryPoint"&gt;
        &lt;property name="authenticationFailureUrl" value="/denied.xhtml" /&gt;
    &lt;/bean&gt;

    &lt;bean id="exceptionTranslationFilter"
     class="org.springframework.security.ui.ExceptionTranslationFilter"&gt;
        &lt;property name="authenticationEntryPoint" ref="ntlmEntryPoint" /&gt;
    &lt;/bean&gt;

    &lt;security:http access-denied-page="/denied.xhtml"
     entry-point-ref="ntlmEntryPoint" servlet-api-provision="false"&gt;
        &lt;security:intercept-url pattern="/denied.xhtml" filters="none" /&gt;
        &lt;security:intercept-url pattern="/**" access="ROLE_USER" /&gt;
    &lt;/security:http&gt;</pre>
<p>My UserDetailsAuthenticationProvider is exactly as per the blog.</p>
<p>My UserDetails Service is below. Note that the UserDetails created should have blank password. This confused me for a bit.</p>
<pre>public class UserDetailsServiceImpl implements UserDetailsService {
	private UserDAO daoUser;
	private static Logger log = Logger.getLogger(UserDetailsService.class);

	public UserDAO getDaoUser() {
		return daoUser;
	}

	public void setDaoUser(UserDAO daoUser) {
		this.daoUser = daoUser;
	}

	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {

		MyUser user;

		try {
			user = daoUser.getUser(username);
		} catch (DAOException ex) {
			throw new DataRetrievalFailureException(ex.getMessage());
		}

        if (user != null) {

            ArrayList&lt;GrantedAuthority&gt; ga = new ArrayList&lt;GrantedAuthority&gt;();
            ga.add(new GrantedAuthorityImpl("ROLE_USER"));
            GrantedAuthority[] grantedAuthorities = new GrantedAuthority[ga.size()];
            ga.toArray(grantedAuthorities);

            UserDetailsImpl ud = new UserDetailsImpl(username, "", true, grantedAuthorities, user);
            return ud;
        } else {
            throw new UsernameNotFoundException("Username Not Found");
	}
}</pre>
<p>My UserDetailsImpl simply extends <em>org.springframework.security.userdetails.User</em> and has an additional field for my &#8216;MyUser&#8217;</p>
<pre>public class UserDetailsImpl extends org.springframework.security.userdetails.User {

	private static final long serialVersionUID = 1584153957347843760L;

	private MyUser user;

	public UserDetailsImpl(String username, String password, boolean enabled,
			 GrantedAuthority[] authorities, MyUser user)
			throws IllegalArgumentException {
		super(username, password, enabled, true, true,
				true, authorities);
		this.user = user;
	}

	public MyUser getUser() {
		return user;
	}

	public void setUser(MyUser user) {
		this.user = user;
	}
}</pre>
<p>And that seems to work. Now I am trying to enable method level security, so more to come soon&#8230;</p>
<p><img src="file:///C:/DOCUME~1/tamsin/LOCALS~1/Temp/moz-screenshot-18.jpg" alt="" /><img src="file:///C:/DOCUME~1/tamsin/LOCALS~1/Temp/moz-screenshot-16.jpg" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anorakgirl.co.uk/?feed=rss2&amp;p=68</wfw:commentRss>
		</item>
	</channel>
</rss>
