<?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>Paul Szulc's Blog</title>
	<atom:link href="http://paulszulc.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulszulc.wordpress.com</link>
	<description>... towards better code, tests and architecture</description>
	<lastBuildDate>Thu, 05 Jan 2012 07:51:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='paulszulc.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Paul Szulc's Blog</title>
		<link>http://paulszulc.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://paulszulc.wordpress.com/osd.xml" title="Paul Szulc&#039;s Blog" />
	<atom:link rel='hub' href='http://paulszulc.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Changing my blog&#8230; AGAIN?</title>
		<link>http://paulszulc.wordpress.com/2010/08/02/changing-my-blog-again/</link>
		<comments>http://paulszulc.wordpress.com/2010/08/02/changing-my-blog-again/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 17:47:19 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=855</guid>
		<description><![CDATA[Well, it&#8217;s true, I&#8217;m moving to new site: http://www.paulszulc.com To tell the long story short: I&#8217;m moving my blog to new domain www.paulszulc.com. If you read my RSS please change subscription, since I won&#8217;t be posting any new stuff here (and I will eventually close this blog on wordpress.com, so it won&#8217;t get confusing). Note [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=855&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s true, I&#8217;m moving to new site: <a href="http://www.paulszulc.com">http://www.paulszulc.com</a></p>
<p>To tell the long story short: I&#8217;m moving my blog to new domain <a title="http://www.paulszulc.com" href="http://www.paulszulc.com">www.paulszulc.com</a>. If you read my RSS please change subscription, since I won&#8217;t be posting any new stuff here (and I will eventually close this blog on wordpress.com, so it won&#8217;t get confusing). Note also that in upcoming weeks I will import most of post from this blog to the new one.</p>
<p>And that simply it. Please refer to the new address from now on. For those of you who are wondering why I move from wordpress.com, please read on.</p>
<p>You still here <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ? Cool! You may know that it&#8217;s been more than a year since I started this blog. It was actually a continuation of previous one, that I was maintaining in Polish language. Nevertheless I&#8217;ve switched to English completely and after more then one year of blogging, I can honestly say that I don&#8217;t regret this at all. The people I met from all around the world, the thoughts we exchanged (not always agreeing with each other <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> &#8230; well experience have been great. I&#8217;ve started in May 2009 with 600 visits per month to reach average 6000 per month a year later.</p>
<p><a href="http://paulszulc.files.wordpress.com/2010/08/views.png"><img class="aligncenter size-medium wp-image-856" title="views" src="http://paulszulc.files.wordpress.com/2010/08/views.png?w=300&#038;h=127" alt="" width="300" height="127" /></a></p>
<p>For some it might be impressive, for some it may not. For me it was a reward, that my writing actually has some value. So why do I move then? Well honestly two things were cause of the change</p>
<p>1. with somehow growing popularity <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I wanted to bring my blog to another level (by buying domain <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )</p>
<p>2. beside that I just simply wanted to have better control of my blog, which wordpress.com unfortunately wasn&#8217;t giving me enough.</p>
<p>And that is simply it! See you next time on <a href="http://www.paulszulc.com">http://www.paulszulc.com</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/855/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=855&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/08/02/changing-my-blog-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>

		<media:content url="http://paulszulc.files.wordpress.com/2010/08/views.png?w=300" medium="image">
			<media:title type="html">views</media:title>
		</media:content>
	</item>
		<item>
		<title>JRE Exploit happened!</title>
		<link>http://paulszulc.wordpress.com/2010/04/11/jre-exploit-happened/</link>
		<comments>http://paulszulc.wordpress.com/2010/04/11/jre-exploit-happened/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 12:37:41 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=844</guid>
		<description><![CDATA[Tavis Ormand discovered the bug inside Java Web Start. Critical bug that exists inside Java Runtime Environment allows to remotely run code on any machine with Java 6.0 with update 10 or later. In practice anyone can be attacked by simply entering specially designed page. To explain how the exploit can work, you need to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=844&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://seclists.org/fulldisclosure/2010/Apr/119" target="_blank">Tavis Ormand</a> discovered the bug inside Java Web Start. Critical bug that exists inside Java Runtime Environment allows to remotely run code on any machine with Java 6.0 with update 10 or later. In practice anyone can be attacked by simply entering specially designed page.</p>
<p>To explain how the exploit can work, you need to know that ever since 1.6.10 Sun has distributed an NPAPI plugin (for firefox, chrome ect.) and ActiveX control (for Internet Explorer) called &#8220;Java Deployment Toolkit&#8221; that simplifies distributing applications to the end user by Web Start. The launch() method of this toolkit accepts url as a parameter, however this parameter is poorly validated, thus allowing passing arbitrary parameters. This parameter is later on passed to javaws, allowing to run any code on attacked machine.</p>
<p>Tavis Ormand created a <a href="http://lock.cmpxchg8b.com/bb5eafbc6c6e67e11c4afc88b4e1dd22/testcase.html" target="_blank">Proof of Concept</a> application to show exploit in use. Source of this PoC was <a href="http://www.exploit-db.com/download/12122" target="_blank">published</a> by Ruben Santamart. Currently there is no fix for the bug and according to Tavis Ormand, Oracle/Sun is not planning to do it quickly:</p>
<blockquote><p>Sun has been informed about this vulnerability, however, they informed me they do not consider this vulnerability to be of high enough priority to break their quarterly patch cycle.</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/844/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/844/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/844/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/844/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/844/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/844/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/844/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/844/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=844&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/04/11/jre-exploit-happened/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing Liferay with MySQL, CAS and openLDAP on Ubuntu (part 3)</title>
		<link>http://paulszulc.wordpress.com/2010/04/08/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-3/</link>
		<comments>http://paulszulc.wordpress.com/2010/04/08/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-3/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 08:47:25 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=798</guid>
		<description><![CDATA[This is third part of of article &#8220;Installing Liferay with MySQL, CAS and openLDAP on Ubuntu&#8221;. 5. Installing and configuring CAS The easiest way to integrate CAS with openLDAP is to build CAS using Maven.  Created war file will contain all needed dependencies and all properties will be set inside configuration files.  Before we move [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=798&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This is third part of of article <a href="../2010/01/19/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-1/" target="_self">&#8220;Installing Liferay with MySQL, CAS and openLDAP on Ubuntu&#8221;</a>.</em></p>
<h1>5. Installing and configuring CAS</h1>
<p>The easiest way to integrate CAS with openLDAP is to build CAS using Maven.  Created war file will contain all needed dependencies and all properties will be set inside configuration files.  Before we move on you need to first download CAS sources and unpack it somewhere in your file system (for example /home/user/Downloads/cas). We will refer to this folder (or to the path of this folder) as CAS_SOURCE further in this tutorial.</p>
<h2>5.1 Configuration of dependencies and properties</h2>
<p>1. Go to folder $CAS_SOURCE/cas-server-webapp and in file pom.xml add</p>
<p><pre class="brush: xml;">
&lt;dependency&gt;
     &lt;groupId&gt;${project.groupId}&lt;/groupId&gt;
     &lt;artifactId&gt;cas-server-support-ldap&lt;/artifactId&gt;
     &lt;version&gt;${project.version}&lt;/version&gt;
&lt;/dependency&gt;
</pre></p>
<p>2. Go to folder $CAS_SOURCE/cas-server-webapp/src/main/webapp/WEB-INF and open file deployerConfigContext.xml</p>
<p>3. In file deployerConfigContext.xml inside bean authenticationManager comment out SimpleTestUsernamePasswordAuthenticationHandler</p>
<p><pre class="brush: xml;">
&lt;!--
&lt;bean
class=&quot;org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler&quot; /&gt;
--&gt;
</pre></p>
<p>4. Add FastBindLdapAuthenticationHandler inside authenticationManager bean (where SimpleTestUsernamePasswordAuthenticationHandler used to be)</p>
<p><pre class="brush: xml;">
&lt;bean
class=&quot;org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler&quot;&gt;
  &lt;property name=&quot;filter&quot; value=&quot;uid=%u,ou=people,dc=it,dc=mycompany,dc=com&quot; /&gt;
  &lt;property name=&quot;contextSource&quot; ref=&quot;contextSource&quot; /&gt;
&lt;/bean&gt;
</pre></p>
<p>5. Add new bean called contextSource</p>
<p><pre class="brush: xml;">
&lt;bean id=&quot;contextSource&quot; class=&quot;org.springframework.ldap.core.support.LdapContextSource&quot;&gt;
        &lt;property name=&quot;pooled&quot; value=&quot;true&quot;/&gt;
        &lt;property name=&quot;urls&quot;&gt;
            &lt;list&gt;
                &lt;value&gt;ldap://localhost/&lt;/value&gt;
            &lt;/list&gt;
        &lt;/property&gt;
        &lt;property name=&quot;userDn&quot; value=&quot;cn=admin,dc=it,dc=mycompany,dc=com&quot;/&gt;
        &lt;property name=&quot;password&quot; value=&quot;asdfgh&quot;/&gt;
        &lt;property name=&quot;baseEnvironmentProperties&quot;&gt;
            &lt;map&gt;
                &lt;entry&gt;
                    &lt;key&gt;
                        &lt;value&gt;java.naming.security.authentication&lt;/value&gt;
                    &lt;/key&gt;
                    &lt;value&gt;simple&lt;/value&gt;
                &lt;/entry&gt;
            &lt;/map&gt;
        &lt;/property&gt;
&lt;/bean&gt;
</pre></p>
<h2>5.2 Building CAS war file</h2>
<p>Building CAS war file actually requires only modules cas-server-core, cas-server-webapp and cas-server-support-ldap, however you can always build all components (somemodules simply won&#8217;t be used). For me personally, this is much quicker way. So all you really need to do now is to open your command line, go to $CAS_SOURCE folder and type</p>
<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } --><em>mvn -Dmaven.test.skip=true clean install</em></p>
<p>Created war file (called cas.war) can be found inside folder  $CAS_SOURCE/cas-server-webapp/target.  Now all you need to do is to deploy this file in tomcat. Just copy it to folder LIFERAY_ROOT/tomcat/webapps/ .</p>
<h1>6. Integrating Liferay with CAS and with openLDAP</h1>
<h2>6.1 Integrating Liferay with CAS</h2>
<p>1. Start Liferay</p>
<p>2. Log into admin account (at this point Liferay is not integrated with CAS yet)<br />
login: test@liferay.com<br />
haslo: test</p>
<p>3. Go to Control Panel -&gt; Settings -&gt; Authentication -&gt; CAS</p>
<p>4. Select values &#8216;Enabled&#8217; and  &#8216;Import from LDAP&#8217;<br />
[x] Enabled<br />
[x] Import from LDAP</p>
<p>5. In default values change cas-web into cas and localhost into your server&#8217;s DNS name (for this tutorial it will be it.mycompany.com) &#8211; or leave it localhost if you don&#8217;thave DNS name for your server.</p>
<p>6. In field  &#8220;Server Name&#8221; enter DNS name &#8211; it.mycompany.com:443</p>
<p>7. In field &#8220;Service URL&#8221; enter path to the service &#8211; https://it.mycompany.com:443/c/portal/login</p>
<h2>6.2 Integrating Liferay with openLDAP</h2>
<p>1. Go to Control Panel -&gt; Settings -&gt; Authentication -&gt; LDAP<br />
2. Select &#8216;Enabled&#8217; option<br />
3. Select openLDAP<br />
4. Values</p>
<p><em>Connection: </em><br />
base provider: ldap://localhost:389<br />
base dn: dc=it,dc=mycompany,dc=com<br />
principal: cn=admin,dc=it,dc=mycompany,dc=com<br />
password: asdfgh<br />
(test connection)</p>
<p><em>Users: </em><br />
Authentication Search Filter: (uid=@screen_name@)<br />
Import Search Filter: (objectClass=uidObject)<br />
Screen Name: uid<br />
Password: userPassword<br />
Email Address: email<br />
Full Name:<br />
First Name: name<br />
Last Name: sn<br />
Job Title: &#8212; leave it empty<br />
Group: member</p>
<p><em>Groups: </em><br />
Import Search Filter: (objectClass=groupOfNames)<br />
Group Name: cn<br />
Description: description<br />
User: member<br />
(test connection)</p>
<p>5. In Import/Export:</p>
<p>Import Enabled: [x]<br />
Import on Startup Enabled: [x]<br />
Import Interval: any value e.g. 5 minutes<br />
Export Enabled: [ ]</p>
<p>6. Go to Control Panel -&gt; Settings -&gt; Authentication → General and change &#8220;How do users authenticate?&#8221; to &#8220;By Screen Name&#8221;</p>
<p>7. Accept changes by clicking &#8220;Save&#8221; button</p>
<p>After importing users and groups you need to give  group &#8220;admins&#8221; a role &#8220;Administrator&#8221;. Go to Control Panel → Roles → Administrator → Assign Members → User Groups. Select group „admins” and click &#8220;Update Associations&#8221;.</p>
<p><strong>Part 4 is coming soon&#8230;.</strong></p>
<p><strong><a href="../2010/01/23/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-2/" target="_self"></a></strong></p>
<p><em>Reference:</em></p>
<p>[CAS1] <a href="http://www.jasig.org/cas/">http://www.jasig.org/cas/</a> &#8211;  CAS official site<br />
[CAS2] <a href="http://en.wikipedia.org/wiki/Central_Authentication_Service">http://en.wikipedia.org/wiki/Central_Authentication_Service</a> &#8211; what wikipedia knows<br />
[CAS3] <a href="http://www.ja-sig.org/wiki/display/CAS/Home">http://www.ja-sig.org/wiki/display/CAS/Home</a> &#8211; CAS official wiki</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/798/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/798/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/798/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=798&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/04/08/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing Liferay with MySQL, CAS and openLDAP on Ubuntu (part 2)</title>
		<link>http://paulszulc.wordpress.com/2010/01/23/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-2/</link>
		<comments>http://paulszulc.wordpress.com/2010/01/23/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-2/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 11:49:40 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[How-to tutorials]]></category>
		<category><![CDATA[liferay]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[openLDAP]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=778</guid>
		<description><![CDATA[This is second part of of article &#8220;Installing Liferay with MySQL, CAS and openLDAP on Ubuntu&#8221;. 2. Installing and configuring MySQL To install MySQL you simply run command: sudo apt­ get install mysql­-server Now that we have MySQL installed we can download sql script (that generates schema) and unzip it: wget http://downloads.sourceforge.net/lportal/liferay-portal-sql-5.2.3.zip unzip ./liferay-portal-sql-5.2.3.zip Next [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=778&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><em>This is second part of of article <a href="http://paulszulc.wordpress.com/2010/01/19/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-1/" target="_self">&#8220;Installing Liferay with MySQL, CAS and openLDAP on Ubuntu&#8221;</a>.<br />
</em></p>
<h2>2. Installing and configuring MySQL</h2>
<p>To install MySQL you simply run command:</p>
<p><em>sudo apt­ get install mysql­-server</em></p>
<p>Now that we have MySQL installed we can download sql script (that generates schema) and unzip it:</p>
<p><em>wget http://downloads.sourceforge.net/lportal/liferay-portal-sql-5.2.3.zip</em></p>
<p><em>unzip ./liferay-portal-sql-5.2.3.zip</em></p>
<p>Next you need to enter MySQL shell</p>
<p><em>mysql -u root -p</em></p>
<p>and create new database for Liferay</p>
<p><em>create database lportal character set utf8;<br />
create user &#8216;lportal&#8217;@'localhost&#8217; identified by &#8216;lportal123&#8242;;<br />
grant all privileges on lportal.* to &#8216;lportal&#8217;@'localhost&#8217;;<br />
flush privileges;</em></p>
<p>After entering portal database:</p>
<p><em>use lportal;</em></p>
<p>we can generate basic schema:</p>
<p><em>source </em><em>liferay-portal-sql-5.2.3</em><em>/portal-minimal/portal-minimal-mysql.sql</em></p>
<p>Now we have MySQL installed with database configured for Liferay portal.</p>
<h2>3. Installing Liferay portal</h2>
<p>Before we move on you need to first download Liferay 5.2.3 zip archive and unpack it somewhere in your file system (for example /home/user/liferay/). We will refer to this folder (or to the path of this folder) as LIFERAY_ROOT further in this tutorial.</p>
<p>Add rights to make tomcat runable:</p>
<p><em>chmod ­R +x LIFERAY_ROOT/tomcat/bin</em></p>
<p>Then you need to delete sample data. Liferay (since version 5.2) comes with so-called &#8220;sample data&#8221;, which must be removed before we move on. Delete :</p>
<ul>
<li><em>folder LIFERAY_ROOT/tomcat/webapps/sevencogs­hook</em></li>
<li><em>folder LIFERAY_ROOT/tomcat/webapps/sevencogs­theme</em></li>
<li><em>folder LIFERAY_ROOT/tomcat/webapps/wol­portlet</em></li>
<li><em>file LIFERAY_ROOT/data/hsql/lportal.properties</em></li>
<li><em>file LIFERAY_ROOT/data/hsql/lportal.script</em></li>
</ul>
<p>Now you need to only bind your Liferay portal with MySQL database your created earlier. To do that open file <em>LIFERAY_ROOT\tomcat\webapps\ROOT\WEB­-INF\classes\portal­ext.properties</em> for edition and enter lines below:</p>
<p><em>jdbc.default.driverClassName=com.mysql.jdbc.Driver<br />
jdbc.default.url=jdbc:mysql://localhost/lportal?<br />
useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false<br />
jdbc.default.username=lportal<br />
jdbc.default.password=lportal123</em></p>
<p>Now you have properly installed and configured Liferay portal.</p>
<h2>4. Configuring SSL</h2>
<p>Authentication to your portal should be done using secure connection. That&#8217;s why you need to enable SSL in your tomcat. First you need to generate certificate for your server. To do that run JDK tool called keytool:</p>
<p><em>keytool -­genkey ­-alias tomcat -­keypass asdfgh ­-keyalg RSA</em></p>
<p>notice that for this tutorial keypass (in other words password) will be &#8216;asdfgh&#8217;. Keytool will ask you few questions, but only one is really important. When asked &#8220;What is your first and last name?&#8221; you must answer with the DNS name of your server. If you are following this tutorial on your private computer (that do not have DNS name) then provide &#8216;localhost&#8217; answer. Other questions are irrelevant and you can answer with default values (just keep pressing ENTER).</p>
<p>Now that you have your certificate generated, you can export it to .cert file. Run keytool again:</p>
<p><em>keytool ­-export ­-alias tomcat ­-keypass asdfgh ­-file server.cert</em></p>
<p>At the end you need to add your certificate to JDK&#8217;s keystore:</p>
<p><em>keytool ­-import ­-alias tomcat ­-file server.cert ­-keypass asdfgh ­-keystore $JAVA_HOME/jre/lib/security/cacerts</em></p>
<p>You will be asked for JDK&#8217;s keystore pass. By default this password is &#8216;changeit&#8217;.</p>
<p>Now all you need to do is simply enable SSL in your tomcat. In LIFERAY_ROOT/tomcat/conf/sertver.xml add new connector:</p>
<p><em>&lt;Connector port=&#8221;8443&#8243; protocol=&#8221;HTTP/1.1&#8243; SSLEnabled=&#8221;true&#8221;<br />
maxThreads=&#8221;150&#8243; scheme=&#8221;https&#8221; secure=&#8221;true&#8221;<br />
clientAuth=&#8221;false&#8221; sslProtocol=&#8221;TLS&#8221; keystorePass=&#8221;asdfgh&#8221;/&gt;</em></p>
<p>Congratulations. You have now enabled SSL in your tomcat.</p>
<p><a href="http://paulszulc.wordpress.com/2010/04/08/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-3/" target="_self"><strong>Go to Part 3 of this tutorial</strong></a></p>
<p><em>Reference:</em></p>
<p>[1] &#8211; <a href="www.liferay.com" target="_blank">Liferay portal page</a></p>
<p>[2] &#8211; <a href="http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html" target="_blank">Tomcat SSL configuration How-to</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/778/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/778/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/778/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/778/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/778/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/778/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/778/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/778/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=778&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/01/23/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing Liferay with MySQL, CAS and openLDAP on Ubuntu (part 1)</title>
		<link>http://paulszulc.wordpress.com/2010/01/19/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-1/</link>
		<comments>http://paulszulc.wordpress.com/2010/01/19/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-1/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 22:05:01 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[How-to tutorials]]></category>
		<category><![CDATA[CAS]]></category>
		<category><![CDATA[liferay]]></category>
		<category><![CDATA[openLDAP]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=729</guid>
		<description><![CDATA[Recently I&#8217;ve been asked to deploy a portal infrastructure into one of the Polish corporations. The task was to bind together Liferay (portal with MySQL as internal database) with CAS (single sign-on authentication) and openLDAP (directory for holding user specific data like login, password, email etc.). The general idea was that every user&#8217;s information should [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=729&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been asked to deploy a portal infrastructure into one of the Polish corporations. The task was to bind together Liferay (portal with MySQL as internal database) with CAS (single sign-on authentication) and openLDAP (directory for holding user specific data like login, password, email etc.).</p>
<p>The general idea was that every user&#8217;s information should be  held inside openLDAP. Liferay portal would delegate authentication to CAS web application where user&#8217;s login action would be authenticated against data from openLDAP. Because Liferay keeps its internal database, portal needs to periodically check openLDAP to see whether any data changed and update if needed.</p>
<p><a href="http://paulszulc.files.wordpress.com/2010/01/portal-idea.png"><img class="aligncenter size-medium wp-image-769" title="portal-idea" src="http://paulszulc.files.wordpress.com/2010/01/portal-idea.png?w=300&#038;h=202" alt="" width="300" height="202" /></a></p>
<p>Because the whole idea was kind of new for me, I had to do a small research before I got my hands dirty. On Internet I found many tutorials how to integrate Liferay with CAS, CAS with openLDAP and Liferay with openLDAP. Some of them worked, some not, some were simply obsolete. Moreover there was not one single tutorial to show how to bind all these technologies together. This post tries to fills this gap.</p>
<p>This post will be divided into four parts. Liferay version was 5.2.3 used with CAS 3.3. Installation and deployment was done on Linux Debian and on Ubuntu Linux (9.04).</p>
<h2>1. Installing openLDAP</h2>
<p><em><strong>Warning: </strong>This will not run on Ubuntu 9.10! There were some changes done in Ubuntu that made installation of openLDAP really hard task. Ubuntu 9.04 is recommended.</em></p>
<p>To run installation you should simply run command below:</p>
<p><em>sudo apt­-get install slapd ldap­-utils</em></p>
<p>During installation you will be asked for administrator password. For purpose of this document this password will be &#8216;asdfgh&#8217;.</p>
<p>After installation ends, you should run configuration program:</p>
<p><em>sudo dpkg­-reconfigure slapd</em></p>
<p>You will then need to answer few questions:</p>
<p><em>a) If you enable this option, no initial configuration or database will be created for you. Omit<br />
OpenLDAP server configuration?</em></p>
<p>Choose: No</p>
<p><em>b) The DNS domain name is used to construct the base DN of the LDAP directory. For example,<br />
&#8216;foo.example.org&#8217; will create the directory with &#8216;dc=foo, dc=example, dc=org&#8217; as base DN.</em></p>
<p>You need to enter name base DN, which normally is just simply the DNS domain name.<br />
For  it.mycompany.com DN would be dc=it,dc=mycompany,dc=com</p>
<p><em>c) Please enter the name of the organization to use in the base DN of your LDAP directory. </em></p>
<p>Simply your organisation name. Can be anything.<br />
<em>d) The HDB backend is recommended. HDB and BDB use similar storage formats, but HDB adds<br />
support for subtree enames. Both support the same configuration options.<br />
In either case, you should review the resulting database configuration for your needs.<br />
See/usr/share/doc/slapd/README.DB_CONFIG.gz for more details. </em></p>
<p>Choose: No</p>
<p><em>e) Do you want the database to be removed when slapd is purged?</em></p>
<p>Choose: No</p>
<p><em>f) Please enter the password for the admin entry in your LDAP directory.</em></p>
<p>Any, for this document it&#8217;s &#8216;asdfgh&#8217;<br />
<em>g) The obsolete LDAPv2 protocol is disabled by default in slapd. Programs and users should<br />
upgrade to LDAPv3. If you have old programs which can&#8217;t use LDAPv3, you should select this<br />
option and &#8216;olcAllows: bind_v2&#8242; will be added to your cn=config directory. </em></p>
<p>Choose: No</p>
<p>Now to create simple structure that holds users and their groups, we run command:</p>
<p><em>ldapadd ­x ­D cn=admin,dc=it,dc=mycompany,dc=com ­W ­f ldap_data_set.ldif</em></p>
<p>where ldap_data_set.ldif looks like this:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- ldap_data_set.ldif &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>dn: ou=groups,dc=it,dc=mycompany,dc=com<br />
objectClass: organizationalUnit<br />
objectClass: top<br />
description: grupy<br />
ou: groups</p>
<p>dn: ou=people,dc=it,dc=mycompany,dc=com<br />
objectClass: organizationalUnit<br />
objectClass: top<br />
ou: people</p>
<p>dn: cn=admins,ou=groups,dc=it,dc=mycompany,dc=com<br />
objectClass: extensibleObject<br />
objectClass: groupOfNames<br />
objectClass: top<br />
cn: admins<br />
description: admins group<br />
member: uid=jdoe,ou=people,dc=it,dc=mycompany,dc=com</p>
<p>dn: cn=programmers,ou=groups,dc=it,dc=mycompany,dc=com<br />
objectClass: extensibleObject<br />
objectClass: groupOfNames<br />
objectClass: top<br />
cn: programmers<br />
description: programisci hudsona<br />
member: uid=kmoe,ou=people,dc=it,dc=mycompany,dc=com<br />
member: uid=jhudson,ou=people,dc=it,dc=mycompany,dc=com</p>
<p>dn: uid=jdoe,ou=people,dc=it,dc=mycompany,dc=com<br />
objectClass: account<br />
objectClass: extensibleObject<br />
objectClass: uidObject<br />
objectClass: userSecurityInformation<br />
objectClass: top<br />
email: jdoe@mycompany.com<br />
member: cn=admins,ou=groups,dc=it,dc=mycompany,dc=com<br />
name: John<br />
sn: Doe<br />
uid: jdoe<br />
userPassword: {MD5}ICy5YqxZB1uWSwcVLSNLcA==</p>
<p>dn: uid=kmoe,ou=people,dc=it,dc=mycompany,dc=com<br />
objectClass: account<br />
objectClass: extensibleObject<br />
objectClass: uidObject<br />
objectClass: userSecurityInformation<br />
objectClass: top<br />
email: kmoe@mycompany.com<br />
member: cn=programmers,ou=groups,dc=it,dc=mycompany,dc=com<br />
name: Kate<br />
sn: Moe<br />
uid: kmoe<br />
userPassword: {MD5}ICy5YqxZB1uWSwcVLSNLcA==</p>
<p>dn: uid=jhudson,ou=people,dc=it,dc=mycompany,dc=com<br />
objectClass: account<br />
objectClass: extensibleObject<br />
objectClass: uidObject<br />
objectClass: userSecurityInformation<br />
objectClass: top<br />
email: jhudson@mycompany.com<br />
member: cn=programmers,ou=groups,dc=it,dc=mycompany,dc=com<br />
name: Jane<br />
sn: Hudson<br />
uid: jhudson<br />
userPassword: {MD5}ICy5YqxZB1uWSwcVLSNLcA==</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;-end of ldap_data_set.ldif &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>This will create structure described below:</p>
<p>it.mycompany.com<br />
|<br />
|­­­ groups</p>
<p>|       |    admins</p>
<p>|       |    programmers<br />
|<br />
|­­­ people</p>
<p>|       |   jdoe</p>
<p>|       |   kmoe</p>
<p>|       |   jhudson</p>
<p>Every user has password: &#8217;123&#8242;.</p>
<p>And that&#8217;s simply it. We now have openLDAP installed with some user data in it.</p>
<p><strong><a href="http://paulszulc.wordpress.com/2010/01/23/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-2/" target="_self">Go to Part 2 of this tutorial</a><br />
</strong></p>
<p><em>Reference:</em></p>
<p>[ldap1] &#8211; <a href="https://help.ubuntu.com/9.04/serverguide/C/openldap-server.html">https://help.ubuntu.com/9.04/serverguide/C/openldap-server.html</a> -&gt; official Ubuntu tutorial<br />
[ldap2] &#8211; <a href="https://help.ubuntu.com/community/OpenLDAPServer">https://help.ubuntu.com/community/OpenLDAPServer</a> -&gt; older version of [ldap1]<br />
[ldap3] &#8211; <a href="http://docs.sun.com/source/816-6400-10/lmodify.html">http://docs.sun.com/source/816-6400-10/lmodify.html</a> -  SUN&#8217;s documentation -  ldapmodify<br />
[ldap4] &#8211; <a href="http://docs.sun.com/source/816-6400-10/lsearch.html">http://docs.sun.com/source/816-6400-10/lsearch.html</a> &#8211; SUN&#8217;s documentation -<br />
ldapsearch</p>
<p><strong><br />
</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/729/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/729/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/729/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/729/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/729/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/729/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/729/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/729/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=729&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/01/19/installing-liferay-with-mysql-cas-and-openldap-on-ubuntu-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>

		<media:content url="http://paulszulc.files.wordpress.com/2010/01/portal-idea.png?w=300" medium="image">
			<media:title type="html">portal-idea</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Killers #003 &#8211; ? is the question</title>
		<link>http://paulszulc.wordpress.com/2010/01/13/java-killers-003-is-the-question/</link>
		<comments>http://paulszulc.wordpress.com/2010/01/13/java-killers-003-is-the-question/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 08:22:59 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Java Killers]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=679</guid>
		<description><![CDATA[Post has bean moved to http://www.paulszulc.com/2010/java-killers-is-the-question/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=679&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Post has bean moved to <a href="http://www.paulszulc.com/2010/java-killers-is-the-question/">http://www.paulszulc.com/2010/java-killers-is-the-question/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/679/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/679/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/679/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=679&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/01/13/java-killers-003-is-the-question/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>
	</item>
		<item>
		<title>JPA 2.0 and Spring 3.0 with Maven</title>
		<link>http://paulszulc.wordpress.com/2010/01/09/jpa-2-0-and-spring-3-0-with-maven/</link>
		<comments>http://paulszulc.wordpress.com/2010/01/09/jpa-2-0-and-spring-3-0-with-maven/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 17:50:16 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jpa2.0]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring3.0]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=744</guid>
		<description><![CDATA[I&#8217;m currently updating WicketCool to use Spring 3.0, JPA2.0 and latest Wicket. Here is a short summary of my research, a quick tutorial showing how to jump into Spring3.0 + JPA2.0 development using Maven. 1. Dependencies a) Spring To use 3.0 release of the Spring framework you can&#8217;t no longer add one dependency as you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=744&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently updating <a href="http://code.google.com/p/wicketcool/" target="_blank">WicketCool</a> to use Spring 3.0, JPA2.0 and latest Wicket. Here is a short summary of my research, a quick tutorial showing how to jump into Spring3.0 + JPA2.0 development using Maven.</p>
<p>1. Dependencies</p>
<p>a) Spring</p>
<p>To use 3.0 release of the Spring framework you can&#8217;t no longer add one dependency as you used to do it</p>
<p><pre class="brush: xml;">
&lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring&lt;/artifactId&gt;
   &lt;version&gt;2.5.6&lt;/version&gt;
&lt;/dependency&gt;
</pre></p>
<p>This will no longer work. Spring framework is divided into 20 modules:</p>
<p><a href="http://paulszulc.files.wordpress.com/2010/01/spring-overview.png"><img class="aligncenter size-medium wp-image-745" title="spring-overview" src="http://paulszulc.files.wordpress.com/2010/01/spring-overview.png?w=300&#038;h=231" alt="" width="300" height="231" /></a></p>
<p>If you create web appliactions, you will probably need modules listed below:</p>
<ol>
<li>all from Core Container: Beans, Core, Context and Expression Language</li>
<li>AOP</li>
<li>from Data Access/Integration: Transactions, ORM</li>
<li>from Web: Web (even if you don&#8217;t use SpringMVC, you still might consider OpenEntityManagerInViewFilter which is inside Web module</li>
<li>Test</li>
</ol>
<p>Thus set of dependencies that you need to include in your pom.xml are:</p>
<p><pre class="brush: xml;">
&lt;properties&gt;
 &lt;spring.version&gt;3.0.0.RELEASE&lt;/spring.version&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
   &lt;version&gt;${spring.version}&lt;/version&gt;
 &lt;/dependency&gt;
&lt;/dependecies&gt;
</pre></p>
<p>b) JPA 2.0</p>
<p>Now that we have Spring dependencies sorted out, we can look at the JPA2.0.  We must remember that JPA itself is only standard, thus when setting dependencies we are really choosing the provider. I could go with Hibernate or EclipseLink. Hibernate is still in beta state and EclispeLink is a reference implementation of the standard, so I thought that EclipseLink is a good way to go. However after <a href="http://paulszulc.wordpress.com/2010/01/07/jpa2-0-banned-in-poland/" target="_self">recent discoveries </a>(which took me quite some to figure out by the way), I thought I will stick with the Hibernate&#8217;s beta.</p>
<p>What is new in Hibernate&#8217;s recent release is that you no longer need to define dependencies to core, annotations, commons-annotations ect. It is now only one, single dependency.  Second dependency is the API of the standard.</p>
<p><pre class="brush: xml;">
&lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.hibernate.java-persistence&lt;/groupId&gt;
    &lt;artifactId&gt;jpa-api&lt;/artifactId&gt;
    &lt;version&gt;2.0-cr-1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
    &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
    &lt;version&gt;3.5.0-Beta-2&lt;/version&gt;
  &lt;/dependency&gt;
&lt;/dependencies&gt;
</pre></p>
<p>You might also need to add JBoss repository:</p>
<p><pre class="brush: xml;">
&lt;repositories&gt;
 &lt;repository&gt;
   &lt;id&gt;JBoss Repo&lt;/id&gt;
   &lt;url&gt;http://repository.jboss.com/maven2&lt;/url&gt;
 &lt;/repository&gt;
&lt;/repositories&gt;
</pre></p>
<p>2. Configuration</p>
<p>The simples application context configuration file can look like this:</p>
<p><pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
 xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
 xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
 xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
 xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd  http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd&quot;&gt;

 &lt;!-- holding properties for database connectivity /--&gt;
   &lt;context:property-placeholder location=&quot;classpath:jdbc.properties&quot;/&gt;
   &lt;!-- enabling annotation driven configuration /--&gt;
&lt;context:annotation-config/&gt;
&lt;context:component-scan base-package=&quot;wcpackage&quot;/&gt;
   &lt;tx:annotation-driven transaction-manager=&quot;transactionManager&quot;/&gt;

    &lt;bean
       class=&quot;org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor&quot;/&gt;

    &lt;bean id=&quot;dataSource&quot;
       class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;
       p:driverClassName=&quot;${jdbc.driverClassName}&quot; p:url=&quot;${jdbc.url}&quot;/&gt;

    &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;
       p:entityManagerFactory-ref=&quot;entityManagerFactory&quot;/&gt;

    &lt;bean id=&quot;entityManagerFactory&quot;
       class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;
       p:dataSource-ref=&quot;dataSource&quot;
       p:jpaVendorAdapter-ref=&quot;jpaAdapter&quot;&gt;
       &lt;property name=&quot;loadTimeWeaver&quot;&gt;
          &lt;bean
             class=&quot;org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver&quot;/&gt;
        &lt;/property&gt;
        &lt;property name=&quot;persistenceUnitName&quot; value=&quot;wctemplatePU&quot;&gt;&lt;/property&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;jpaAdapter&quot;
         class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot;
         p:database=&quot;${jpa.database}&quot;
         p:showSql=&quot;${jpa.showSql}&quot;/&gt;
&lt;/beans&gt;
</pre></p>
<p>Given that wcpackage is a root package for component scan and wctemplatePU is name of the persistent unit.<br />
Now all we need to do is to define persistence unit in META-INF/persistence.xml</p>
<p><pre class="brush: xml;">
&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence&quot;&gt;

	&lt;persistence-unit name=&quot;wctemplatePU&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;
		&lt;properties&gt;
			&lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;validate&quot; /&gt;
		&lt;/properties&gt;
	&lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre></p>
<p>And that is basically it. You have Spring configuration and now can use EntityManager in your services classes.</p>
<p><pre class="brush: java;">
@Repository(value = &quot;userDAO&quot;)
public class UserDefaultDAO implements UserDAO {

    @PersistenceContext
    private EntityManager entityManager;
</pre></p>
<p>Injected EntityManager will be with transaction-scoped persistence context, resource_local transaction type (meaning transactions used from database not JTA). Hope everything is comprehensive. If you have any questions, please let me know.</p>
<p><strong>See also:</strong></p>
<ol>
<li><a href="http://paulszulc.wordpress.com/2010/01/04/a-proper-way-for-jpa-entities-instantiation/" target="_self">A proper way for JPA entities instantiation</a></li>
</ol>
<div id="_mcePaste" style="overflow:hidden;position:absolute;left:-10000px;top:3405px;width:1px;height:1px;">ale macie fajnie</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/744/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/744/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/744/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/744/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/744/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/744/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/744/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/744/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=744&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/01/09/jpa-2-0-and-spring-3-0-with-maven/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>

		<media:content url="http://paulszulc.files.wordpress.com/2010/01/spring-overview.png?w=300" medium="image">
			<media:title type="html">spring-overview</media:title>
		</media:content>
	</item>
		<item>
		<title>JPA2.0 banned in Poland!</title>
		<link>http://paulszulc.wordpress.com/2010/01/07/jpa2-0-banned-in-poland/</link>
		<comments>http://paulszulc.wordpress.com/2010/01/07/jpa2-0-banned-in-poland/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 19:38:15 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[eclipselink]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jpa2.0]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=731</guid>
		<description><![CDATA[Yeah really! So I thought it&#8217;s time to play a little bit with the brand new JPA2.0 specification. I tried the Hibernate vendor, but since its implementation is still in beta and was throwing more exceptions then I thought a beta should throw, I thought I would give an EclipseLink a try. Eclipse Link is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=731&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://paulszulc.files.wordpress.com/2010/01/owl.jpg"><img class="alignleft size-thumbnail wp-image-732" title="owl" src="http://paulszulc.files.wordpress.com/2010/01/owl.jpg?w=150&#038;h=139" alt="" width="150" height="139" /></a>Yeah really! So I thought it&#8217;s time to play a little bit with the brand new JPA2.0 specification. I tried the Hibernate vendor, but since its implementation is still in beta and was throwing more exceptions then I thought a beta should throw, I thought I would give an EclipseLink a try.</p>
<p>Eclipse Link is a former Toplink and now (ever since given back to the community) a reference implementation of JPA standard. Reading <a href="http://wiki.eclipse.org/EclipseLink/Maven" target="_blank">this site</a> I learned that to get started with the EclipseLink using Maven, you need to add one dependency:</p>
<p><pre class="brush: xml;">
&lt;dependency&gt;
  &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
  &lt;artifactId&gt;eclipselink&lt;/artifactId&gt;
  &lt;version&gt;2.0.0&lt;/version&gt;
  &lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
</pre></p>
<p>But Eclipse Link is still not in the main repo1 repository, so you have to add Eclipse repo information to your pom.xml.</p>
<p><pre class="brush: xml;">
&lt;repository&gt;
   &lt;id&gt;EclipseLink Repo&lt;/id&gt;
   &lt;url&gt;http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo&lt;/url&gt;
&lt;/repository&gt;
</pre></p>
<p>And here where the fun begins. If you open repository link (<a href="http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo" target="_blank">http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</a>) in your browser  it will redirect you to a nearest mirror near you. Well, for people living in Poland this mirror is <a href="http://ftp.man.poznan.pl/eclipse/rt/eclipselink/maven.repo/" target="_blank">http://ftp.man.poznan.pl/eclipse/rt/eclipselink/maven.repo/</a>. The problem is that polish mirror not only lacks the 2.0.0 final implementation, but also you can find eclipse link in 2.0.0-SNAPSHOT version catalogue, but the content of the catalogue will be empty (it has metadata but no jars!). All that is there is just milestonses, nothing else.</p>
<p>So dear readers, EclipseLink JPA2.0 is banned in Poland. It&#8217;s official <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Thanks to the <a href="http://old.nabble.com/-OT--qucik-help-with-eclipse-maven-repo-td27064778.html" target="_blank">Wicket User Group</a> we can work around this ban, using Belgium mirror repository http://eclipse.a3-system.be/rt/eclipselink/maven.repo. So this should work in your pom.xml:</p>
<p><pre class="brush: xml;">
&lt;repository&gt;
   &lt;id&gt;EclipseLink Repo&lt;/id&gt;
   &lt;url&gt;http://eclipse.a3-system.be/rt/eclipselink/maven.repo&lt;/url&gt;
&lt;/repository&gt;
</pre></p>
<p>Funny, isn&#8217;t it? <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/731/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/731/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/731/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=731&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/01/07/jpa2-0-banned-in-poland/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>

		<media:content url="http://paulszulc.files.wordpress.com/2010/01/owl.jpg?w=150" medium="image">
			<media:title type="html">owl</media:title>
		</media:content>
	</item>
		<item>
		<title>A proper way for JPA entities instantiation</title>
		<link>http://paulszulc.wordpress.com/2010/01/04/a-proper-way-for-jpa-entities-instantiation/</link>
		<comments>http://paulszulc.wordpress.com/2010/01/04/a-proper-way-for-jpa-entities-instantiation/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 09:39:12 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[testability]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=13</guid>
		<description><![CDATA[If you read Misko Hevery&#8217;s blog you should be pretty much familiar with term testable code (and if you don&#8217;t know Misko&#8217;s blog then I strongly encourage you to visit his site). Misko divides objects into two main types: service objects and value objects. Each service object provides some set functionalities defined in application logic. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=13&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you read <a href="http://misko.hevery.com" target="_blank">Misko Hevery&#8217;s blog</a> you should be pretty much familiar with  term testable code (and if you don&#8217;t know  Misko&#8217;s blog then I strongly encourage you to visit his site). Misko divides objects into two main types:  service objects and value objects. Each service object provides some set functionalities defined in application logic. Value objects are leafs of the objects&#8217; collaboration graph. They usually encapsulate the data, that is manipulated by services. In other words, in most cases they are the model objects, the nouns that you use to describe the application logic. If you use any ORM technology (like Hibernate or Toplink) value objects will most likely be the entities of your application. And on creating the entities I would like to focus in this post. All examples will be for JPA2.0 entities, since this is standard, but the rules can be easily applied to any other ORM solution. Before we move on to the main topic, which is entities instantiation, lets take a look on how service objects are created.</p>
<p>Most of you probably know that for service instantiation we use dependency injection, which makes code maintainable, testable and more declarative. I suspect that most of you guys know about it, but for all non-believers, I&#8217;ve created this very simple example for consideration:</p>
<p><pre class="brush: java;">
public class UserService implements IUserService {
 @Inject
 private IUserDao dao;

 @Inject
 private IFacebookWS facebook;

 public User logIn(String login, String password) {

   User user = dao.findByLoginAndPassword(login,password);
   if(user == null) {
     return User.GUEST;
   }
   return user;
 }

}
</pre></p>
<p>We have those three service classes (and equivalent interfaces): UserDAO for database connection,   FacebookWS for communication with facebook webservice and finally UserService that binds the application logic. I use dependency injection so I don&#8217;t create any instances of my service classes explicitly. This separation of concerns (separation of usage and instantiation of given class) makes my code more declarative.  You, as a other programmer of my team, see that UserService uses UserDAO and FacebookWS, but don&#8217;t know how those dependencies are instantiated. And you shouldn&#8217;t really care, all that is important is that UserService depends on dao and webservice object.</p>
<p>Thanks to Dependency Injection my tests are now easy to write and easy to read:</p>
<p><pre class="brush: java;">

@Test
public void shouldReturnGuestUserForIncorrectPassword() {

 // given
 IUserService service = new UserService();

 IUserDAO dao = mock(IUserDAO.class);
 when(dao.findByLogin(&quot;someLogin&quot;).thenReturn(null));
 inject(service, &quot;dao&quot;, dao);

 // when
 User returnedUser = service.logIn(&quot;someLogin&quot;,
                                   &quot;wrongPassword&quot;);

 // then
 assertEquals(User.GUEST, returnedUser);

}
</pre></p>
<p>Why (beside the fact that I&#8217;m using <a href="http://paulszulc.wordpress.com/2009/05/23/test-template-you-should-always-use/">BDD template given-when-then</a>) tests are easy to read? Important thing is that you (as some other developer of my development team) when looking just at my test, see that to perform logIn action, only IUserDAO dependency is mocked and injected to tested UserService class.</p>
<p><pre class="brush: java;">
 inject(service, &quot;dao&quot;, dao);
</pre></p>
<p>This way test is documenting the class its testing. You clearly see that to perform logIn action, facebook web service is not needed. In general to understand how some method works, you can first look at created tests for given class and then (if still needed) check out the implementation. I guarantee that reading tests and implementation is far more comprehensive then just reading implementation.</p>
<p>You might say that to understand how logIn works you wouldn&#8217;t need really tests. Remember however that this example is trivial. Imagine class with larger set of dependencies. Self-documenting, easy to read tests, might be really really helpful for maintaining code (especially if the code is one year old and it was developed by someone who is no longer hired in your company).</p>
<p>Secondly, why tests are easy to write? Imagine for example what would happen if I didn&#8217;t use DI and I was just instantiating dao and service object in a constructor?</p>
<p><pre class="brush: java;">

public class UserService implements IUserService {

 private IUserDAO dao;
 private IFacebookWS facebook;

 public UserService() {
   dao = new UserDAO();
   facebook = new FacebookWS();
 }
</pre></p>
<p>How I could then mock any of those dependencies? One could say, that I would just simply inject the mock object after constructor. But what if for example when instantiating UserDAO, the dao object is connecting to data base? How would you prevent it from happening in your tests? I believe you couldn&#8217;t do it.</p>
<p>Ok, so we use DI for service objects, but what about the value objects? And more importantly what about entities? For the given example, how do we create User objects? The rule of thumb is to just simply use constructors when instantiating value objects. This should not be really a suprise. Value objects are fundamentals of your application, as they mostly just gather domain specific information. They are leafs in the objects relation graph, thus they will most likely be never mocked.</p>
<p>So (following this rule) in our example, User class should looked more or less something like this:</p>
<p><pre class="brush: java;">
@Entity
public class User {

 @Id
 private String login;
 @Column(nullable = false)
 private String password;
 private String facebookLogin;
 private String facebookPassoword;

 public User(String login,
             String password,
             String facebookLogin,
             String facebookPassword) {
   this.login = login;
   this.password = password;
   this.facebookLogin = facebookLogin;
   this.facebookPassword = facebookPassword;
  }
 }
</pre></p>
<p>Everything works fine, even despite the fact in my personal opinion calling new User(&#8220;someName&#8221;,&#8221;somePassowrd&#8221;, &#8220;someOtherName&#8221;, &#8220;someOtherPassword&#8221;) becomes hardly readable and maintainable. However implementation is still valid. But what shall we do if we get a new requirement for our application:</p>
<p><pre class="brush: java;">
@Test
public void shouldDefaultFacebookValuesEqualsEquvalentNormalValues() {
 // given
 String login = &quot;a&quot;;
 String password = &quot;b&quot;;

 // when
 User user = User(login,password);

 // then
 assertEquals(user.getLogin(), user.getFacebookLogin());
 assertEquals(user.getPassowrd(), user.getFacebookPassword());
}
</pre></p>
<p>In other words we say that login and password are obligatory in object instantiation, but facebook login and password are not &#8211; if not present during initialization, facebook login and password are same as normal login and password.<br />
So what should we do to implement those requirements? Well I hope non of you think to do it like this:</p>
<p><pre class="brush: java;">
@Entity
public class User {
 @Id
 private String login;
 @Column(nullable = false)
 private String password;
 private String facebookLogin;
 private String facebookPassoword;

 public User(String login,
             String password,
             String facebookLogin,
             String facebookPassword) {
   this.login = login;
   this.password = password;
   this.facebookLogin = facebookLogin;
   this.facebookPassword = facebookPassword;
  }

 public User(String login,
             String password) {
   this.login = login;
   this.password = password;
   this.facebookLogin = login;
   this.facebookPassword = password;
  }
}
</pre></p>
<p>You can clearly see the code duplication. Maintaining this code would turn into a nightmare in no time. A rather well-known solution is to implement something that some programmers call &#8220;telescoping constructor pattern&#8221; (name I first encountered in Joshua Bloch &#8220;Effective Java&#8221;) . For our scenario this patter would look like this:</p>
<p><pre class="brush: java;">
@Entity
public class User {
 @Id
 private String login;
 @Column(nullable = false)
 private String password;
 private String facebookLogin;
 private String facebookPassoword;

 public User(String login,
             String password) {
   this(login, password, login);
 }
 public User(String login,
             String password,
             String facebookLogin) {
   this(login, password, facebookLogin, password);
 }
 public User(String login,
            String password,
            String facebookLogin,
            String facebookPassword) {
   this.login = login;
   this.password = password;
   this.facebookLogin = facebookLogin;
   this.facebookPassword = facebookPassword;
 }
}
</pre></p>
<p>You define constructor with minimal set of parameters (meaning parameters obligatory to object initialization). Then you continue on extending other constructors with parameters until you reach the constructor that defines them all. This works fine for small set of parameters, but can quickly turn into horror when number of parameters grows and so the vast number of possible constructors.</p>
<p>Another solution would be to go with the JavaBeans pattern.</p>
<p><pre class="brush: java;">
@Entity
public class User {
 @Id
 private String login;
 @Column(nullable = false)
 private String password;
 private String facebookLogin;
 private String facebookPassoword;

 public User() {
 }

 public void setLogin(String login) {
   this.login = login;
 }

 public void setPassword(String password) {
   this.password = password;
 }

 public void setFacebookLogin(String facebookLogin) {
   this.facebookLogin = facebookLogin;
 }

 public void setFacebookPassword(String facebookPassword) {
   this.facebookPassword = facebookPassword;
 }
}
</pre></p>
<p>You create object without any parameters and use set methods to define appropriate values. Solution works fine with any number of parameters and is wildly use by many developers. In fact I&#8217;ve seen it almost in every second project I ever worked on. Since every single IDE gives automatic setter and getter generation, most developers follow this simple pattern:</p>
<p>1. create entity class in they favourite IDE (e.g User )<br />
2. define all needed attributes as private fields (e.g login, password, facebookLogin, facebookPassword)<br />
3. auto-generate getters and setters</p>
<p>This pattern is quick when creating entity classes, but it has its flaws. The fact that it generates a lot of code that you might never really need (from time to time check your code on how many getters you have that are never really use, you might get surprised), already makes it a no-no. But it has one more and a lot bigger disadvantage: it allows you to create entity object, that does not have all the obligatory fields set. Example:</p>
<p><pre class="brush: java;">
User user = new User();
user.setLogin(&quot;john&quot;);
user.setFacebookLogin(&quot;jhawk&quot;);
user.setFacebookPassword(&quot;12345&quot;);

userDao.persist(user);
}
</pre></p>
<p>Assuming that userDao.persist(User) calls EntitManager&#8217;s persist method, running the code above will throw an exception by the JPA provider, since not-nullable password field was never set.</p>
<p>Ok, so what can we do about it? Joshua Blooch gives fine example of builder pattern.</p>
<blockquote><p>Instead of making the desired object directly, the client calls a constructor (or static factory) with all of the required parameters and gets a builder object. Then the client calls setter-like methods on the builder object to set each optional parameter of interest. Finally, the client calls a parameterless build method to generate the object, which is immutable. The builder is a static member class of the class it builds.</p></blockquote>
<p>This works fine for value objects that are immutable (meaning once set, their state is never changed). Consider the example below:</p>
<p><pre class="brush: java;">
public class Coffee {
 private final CoffeType type;
 private final int cupSize;
 private final boolean hasMilk;

 public static class Builder {
   public CoffeeType type;
   public int cupSize;
   public boolean hasMilk;

   public Builder(CoffeeType type, int cupSize) {
      this.type = type;
      this.cupSize = cupSize;
      hasMilk = false;
   }

   public Builder withMilk() {
      hasMilk = true;
      return this;
   }

   public Coffee build() {
     return new Coffee(this);
   }
 }

 private Coffee(Builder builder) {
   this.type = builder.type;
   this.cupSize = builder.cupSize;
   this.hasMilk = builder.hasMilk;
 }
}
</pre></p>
<p>Reading the code above you can clearly see that coffee type and cup size are obligatory and whether coffee should or shouldn&#8217;t have milk is not mandatory field. Creating Coffee could look more or less like this:</p>
<p><pre class="brush: java;">
Coffee coffee = new Coffee.Builder(CoffeeType.Expresso, 3).withMilk().build();
}
</pre></p>
<p>Of course using this pattern for value object that has two parameters would be an exaggeration. J. Blooch says:</p>
<blockquote><p>In summary, the Builder pattern is a good choice when designing classes whose constructors or static factories would have more than a handful of parameters, especially if most of those parameters are optional.</p></blockquote>
<p>The problem is that entities are not immutable by nature. So the question still remains, how can we construct entity classes? What I really like to do is combine JavaBeans pattern and Builder pattern when creating entities. For all entity attributes I create private fields, those that are obligatory become parameters for the public constructor. Since JPA requires that each entity has a parameter-less constructor, I create one, but I give him protected access level, so in most cases it won&#8217;t be accessible from client code. I create setter methods for all fields that require them at the moment and incrementally add them whenever needed. So our User example would look more or less like this:</p>
<p><pre class="brush: java;">
@Entity
public class User {
 @Id
 private String login;
 @Column(nullable = false)
 private String password;
 private String facebookLogin;
 private String facebookPassoword;

 protected User() { }

 public User(String login, String password) {
   this.login = login;
   this.password = password;
 }

 public void setFacebookLogin(String facebookLogin) {
   this.facebookLogin = facebookLogin;
 }

 public void setFacebookPassword(String facebookPassword) {
   this.facebookPassword = facebookPassword;
 }
}
</pre></p>
<p>And if I would like to stick with all previously mentioned in this posts requirements, we could slightly enhance the constructor to look like this:</p>
<p><pre class="brush: java;">
 public User(String login, String password) {
   this.login = login;
   this.password = password;
   this.facebookLogin = login;
   this.facebookPassword = password;
 }
</pre></p>
<p>Now instantiating User class requires two parameters (login and password). You gain flexibility of JavaBeans, with security of the Builder pattern. Of course this is only hybrid of this two solutions, so it is still possible to create malformed entity (instantiated with obligatory values and then set them again to nulls with setter methods), but this is less likely to happen. You gain on readability, since quick look on constructor parameters gives you notion of all obligatory attributes.</p>
<p>You can also combine this solution with JSR-303 validation and unit testes, solution that can shield you from creating malformed entities&#8230; But this is probably topic for another post.</p>
<p>But I wonder how you create your entity classes. Do you know any other ways to create entity classes so their instantiation is safe, readable and maintainable?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=13&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2010/01/04/a-proper-way-for-jpa-entities-instantiation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Killers #002 &#8211; Add me, check me</title>
		<link>http://paulszulc.wordpress.com/2009/12/31/java-killers-002-add-me-check-me/</link>
		<comments>http://paulszulc.wordpress.com/2009/12/31/java-killers-002-add-me-check-me/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 11:40:54 +0000</pubDate>
		<dc:creator>paulszulc</dc:creator>
				<category><![CDATA[Java Killers]]></category>

		<guid isPermaLink="false">http://paulszulc.wordpress.com/?p=531</guid>
		<description><![CDATA[Post moved to http://www.paulszulc.com/2009/java-killers-2-add-me-check-me/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=531&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Post moved to <a href="http://www.paulszulc.com/2009/java-killers-2-add-me-check-me/">http://www.paulszulc.com/2009/java-killers-2-add-me-check-me/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/paulszulc.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/paulszulc.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/paulszulc.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/paulszulc.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/paulszulc.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/paulszulc.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/paulszulc.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/paulszulc.wordpress.com/531/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=paulszulc.wordpress.com&amp;blog=7715753&amp;post=531&amp;subd=paulszulc&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://paulszulc.wordpress.com/2009/12/31/java-killers-002-add-me-check-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5ebf8203db3d8589d0f935bd932ddec7?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">paulszulc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
