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

<channel>
	<title>hugomonteiro.net &#187; Internet</title>
	<atom:link href="http://hugomonteiro.net/category/internet/feed/" rel="self" type="application/rss+xml" />
	<link>http://hugomonteiro.net</link>
	<description>&#34;When two men in business always agree, one of them is unnecessary.&#34; - William Wrigley Jr.</description>
	<lastBuildDate>Wed, 14 Dec 2011 00:12:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Client Certificates and Play!</title>
		<link>http://hugomonteiro.net/2011/09/30/client-certificates-and-play/</link>
		<comments>http://hugomonteiro.net/2011/09/30/client-certificates-and-play/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 23:09:20 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[certificates]]></category>
		<category><![CDATA[keytool]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=409</guid>
		<description><![CDATA[Sometimes we need the authentication of the client. That means, for instance, if you want to limit the access to your web application, from the people who has the right certificate. This is possible, using client certificates, which are installed inside the browser, and the user without this certificate cannot access the web application. To [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need the authentication of the client. That means, for instance, if you want to limit the access to your web application, from the people who has the right certificate.<br />
This is possible, using client certificates, which are installed inside the browser, and the user without this certificate cannot access the web application.</p>
<p>To create client certificates, you need to check if you have <em><a title="openssl" href="http://www.openssl.org/">openssl</a></em> installed. After this verification, you need to find where the auxiliary command CA and/or CA.pl is installed. On my Mac  it&#8217;s located in &#8220;<em>/System/Library/OpenSSL/misc/CA.pl</em>&#8220;.</p>
<p><strong>1. First, we need to create a Certificate Authority (CA): </strong></p>
<pre>$ CA.pl -newca</pre>
<p>After pressing enter, and following some instructions, a new folder &#8220;<em>demoCA</em>&#8221; is created with our newly created Certificate Authority.</p>
<p><strong>2. Create a certificate signing request:</strong></p>
<pre>$ CA.pl -newreq</pre>
<p>Follow the instructions to create the certificate signing request. Two files will be created: &#8220;Request is in <em>newreq.pem</em>, private key is in <em>newkey.pem</em>&#8220;.</p>
<p><strong>3. Sign it with the CA:</strong></p>
<pre>$ CA.pl -sign</pre>
<p>The signed certificate <em>newcert.pem</em> is generated.</p>
<p><strong>4. Create a client certificate that our user will install in his browser:</strong></p>
<pre>$ openssl pkcs12 -export -inkey newkey.pem \
           -in newcert.pem -out clientCertificate.p12</pre>
<p>As we can see, we use the private key <em>newkey.pem</em> and the CA signed certificate to create the client certificate.</p>
<p>Now that we have all the certificates created we need to use a tool to save our Certificate Authority that will be verified when someone asks for authorization with a certificate. I prefer to use the &#8220;<em>keytool</em>&#8220;. Verify that you have <em>keytool</em> command available before you begin:</p>
<p><strong>5. Create a keystore:</strong></p>
<pre>$ keytool -genkey -keystore truststore.jks</pre>
<p><strong>6. Add CA to keystore</strong></p>
<pre>$ keytool -import -trustcacerts -alias "my CA" \
                -file demoCA/cacert.pem -keystore truststore.jks</pre>
<p><strong>7. Configure Play! Framework:</strong></p>
<p>Add to the  <em>application.conf </em>file, the keystore configurations:</p>
<pre>play.netty.clientAuth=need
keystore.algorithm=jks
keystore.file=conf/truststore.jks
keystore.password=mykeystorepassword</pre>
<p><strong>Conclusions:</strong></p>
<p>Inside the keystore, there is the Certificate Authority that will be verified when the client tries to comunicate with the server, using a certificate signed by the CA. This is very helpful if you want to build a web application that is in the Internet, and you just want the people from inside the company to access to it. Off course, the disadvantage of this approach is that if your user steals the certificate, he also can access the application everywhere.</p>
<p><strong>References:</strong></p>
<ul>
<li><a href="http://www.playframework.org/documentation/1.2.3/configuration#play.netty.clientAuth">http://www.playframework.org/documentation/1.2.3/configuration#play.netty.clientAuth</a></li>
<li><a title="http://www.ipsec-howto.org/x595.html" href="http://www.ipsec-howto.org/x595.html">http://www.ipsec-howto.org/x595.html</a></li>
<li><a title="http://shib.kuleuven.be/docs/ssl_commands.shtml" href="http://shib.kuleuven.be/docs/ssl_commands.shtml">http://shib.kuleuven.be/docs/ssl_commands.shtml</a></li>
<li><a title="http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication" href="http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication">http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2011/09/30/client-certificates-and-play/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Deploying PlayFramework Apps in JBoss</title>
		<link>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/</link>
		<comments>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 17:19:57 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=352</guid>
		<description><![CDATA[After you created your web application you need to create the WAR file that will insert the framework and other dependent libs inside the folder that you specify: play war myapp -o myapp.war Now to deploy on JBoss, you need to do some changes on your WAR file: Create a file called jboss-web.xml in the [...]]]></description>
			<content:encoded><![CDATA[<p>After you created your web application you need to create the WAR file that will insert the framework and other dependent libs inside the folder that you specify:</p>
<pre>play war myapp -o myapp.war
</pre>
<p>Now to deploy on <a href="http://www.jboss.com/">JBoss</a>, you need to do some changes on your WAR file:</p>
<ul>
<li>Create a file called<strong><em> <strong>jboss</strong>-web.xml </em></strong>in the myapp.war/WEB-INF/ directory container the  following:</li>
</ul>
<pre class="brush: xml;" >
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;&nbsp;?&gt;
&lt;!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd"&gt;
<jboss-web>
<class-loading java2ClassLoadingCompliance="false">
<loader-repository>
com.example:archive=myapp.war
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</class-loading>
</jboss-web>
</pre>
<ul>
<li>Download hibernate-validator and hibernate annotation using the compatibility matrix (<a title="Hibernate Compatibility Matrix" href="http://74.125.77.132/search?q=cache:Q9VmeUcio1MJ:https://www.hibernate.org/6.html+https://www.hibernate.org/6.html%23A3&amp;cd=1&amp;hl=nl&amp;ct=clnk&amp;gl=nl&amp;client=safari">Hibernate Compatibility Matrix</a>).  Play is using hibernate core 3.3.2 GA. Once you are done, place the  relevant jars in the myapp.war/WEB-INF/lib directory. You should end up with:
<ul>
<li>hibernate-annotations.jar</li>
<li>hibernate-entitymanager.jar</li>
<li>hibernate-validator.jar</li>
<li>hibernate-commons-annotations.jar</li>
<li>hibernate-search-3.1.1.GA.jar</li>
<li>hibernate3.jar (Do not overwrite this library, as Play! has a modified version of it)</li>
</ul>
</li>
<li>Now that we&#8217;re prepared for WAR, you need to move your application to the deployment folder of JBoss. The default folder for it is: <em>jboss_home/server/default/deploy </em>(jboss_home == folder of jboss). There are some things you need to be aware of:<em><br />
</em></p>
<ol>
<li>Use a superior java version in JBoss to avoid class version errors</li>
<li>Verify that the WAR folder has the necessary permissions. In my case I needed to make a &#8220;<em>chown -R jboss myapp.war</em>&#8221; where jboss is the user that controls the jboss application server</li>
<li>Do a &#8220;<em>tail -f jboss_home/server/default/log/server.log</em>&#8221; to see if your application is being deployed. You&#8217;ve an Administration Console in <em>http://yourserverip:8080</em></li>
<li>Don&#8217;t change your routes file at runtime<em>. Stop the war, change routes and then start the war (in the administration console I said before)<br />
</em></li>
</ol>
</li>
<li>Now you should have your application working. You can access to your app at: <em>http://yourserverip:8080/myapp.war</em></li>
<li><strong>This tutorial was tested in JBoss 5.0.1</strong><em><br />
</em></li>
</ul>
<p>Thanks to <a href="http://www.twitter.com/nicolasleroux">Nicolas Leroux</a> from <a href="http://lunatech.com">lunatech.com</a> for helping me to create this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/04/01/deploying-playframework-apps-in-jboss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send file to user using views</title>
		<link>http://hugomonteiro.net/2010/03/16/send-a-file-to-user-using-a-view-with-play-framework/</link>
		<comments>http://hugomonteiro.net/2010/03/16/send-a-file-to-user-using-a-view-with-play-framework/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 15:36:19 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[send]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=333</guid>
		<description><![CDATA[There are some simple steps to send a file to the user of your web application using the Play Framework: 1. After the controller is created (what I do is to copy the controller  &#8220;Application&#8221; and do a refactor rename to the name I want). Create a file named MyController (what I do is to [...]]]></description>
			<content:encoded><![CDATA[<p>There are some simple steps to send a file to the user of your web application using the <a href="http://www.playframework.org/">Play Framework</a>:</p>
<p>1. After the controller is created (what I do is to copy the controller  &#8220;Application&#8221; and do a refactor rename to the name I want).</p>
<ol>
<li>Create a file named MyController (what I do is to copy the controller  &#8220;Application&#8221; and do a rename to the name I want &#8211; in this case i chose the name MyController)</li>
<li>After this, you need to create a folder with the same name of the controller (in this case: MyController) &#8211; app/views/MyController</li>
<li>Now in the controller, you&#8217;ve to create an index method, where you&#8217;ll output data for the user, for instance:
<ol>
<li>
<pre>public static void index() {
    List users = User.all().fetch();
    render(users);
}</pre>
</li>
<li> Now you need to create a method that will create the file, or get the file somewhere:
<pre>public static void generateMyDocument() {
       File f = new File("myFile.xls");
       //now you've to edit the file, in this is case is an excel file,
       //so you can edit using a library like <a href="http://jexcelapi.sourceforge.net/">JExcelAPI</a></pre>
<pre>       //set the header with the size of the file
       response.setHeader("Content-Length", String.valueOf(f.length()));
       //set the content type, in this case is a microsoft excel
       response.contentType = "application/ms-excel";
       //send the file to the user
       renderBinary(f);
       //after I send the file, I want to return to the same page (index())
       index();
}</pre>
</li>
</ol>
</li>
<li>Now we need to create a view, inside that folder we just created (create an index.html file):
<ul>
<li>
<pre>&lt;a href="@{generateMyDocument()}"&gt;Download file&lt;/a&gt;</pre>
<p>We are calling the method from the controller. First we have the folder with the same name that will route directly to the method of the controller.Off course that we could do this:</li>
<pre>      &lt;a href="@{MyController.generateMyDocument()}"&gt;Download file&lt;/a&gt;</pre>
<p>And that&#8217;s it. The magic on the <a href="http://www.playframework.org">Play Framework</a> is done .</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/03/16/send-a-file-to-user-using-a-view-with-play-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security tips for a web developer</title>
		<link>http://hugomonteiro.net/2010/03/13/security-tips-for-a-web-developer-specially-using-the-playframework/</link>
		<comments>http://hugomonteiro.net/2010/03/13/security-tips-for-a-web-developer-specially-using-the-playframework/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 11:24:15 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=293</guid>
		<description><![CDATA[Every web application has two sides. The client side and the server side. Everything on the client side can be changed, and most of the security problems happens when you trust in the client. With a simple proxy (like webscarab) you can edit the fields that were validated using javascript. That&#8217;s why you always need [...]]]></description>
			<content:encoded><![CDATA[<p>Every web application has two sides. The client side and the server side. Everything on the client side can be changed, and most of the security problems happens when you trust in the client. With a simple proxy (like <a href="http://www.owasp.org/index.php/Category:OWASP_WebScarab_Project">webscarab</a>) you can edit the fields that were validated using javascript. That&#8217;s why you always need to validate the data on the server side. <a href="http://www.playframework.org/">Play Framework</a> has grown to be a great framework for this, giving advantages such as using annotations to control the type of data that came from the client side.</p>
<p>So, a great way to think out of box is to use those validation features inside the model, that every good MVC Framework has, and don&#8217;t trust to much on using hidden fields in the HTML that when changed can affect other users inside the web application. For instance, if you have an hidden field that has the id of the user, and if I change that, I can change others users data.</p>
<p><strong>So, in conclusion:<br />
</strong></p>
<ul>
<li>You can use cookies and sessions to know which user is authenticated (inside the model you can have the stuff he can do on the web application)</li>
<li>Don&#8217;t trust in the client side. Use always server and client validation</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/03/13/security-tips-for-a-web-developer-specially-using-the-playframework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Play Framework + Oracle = EASY!</title>
		<link>http://hugomonteiro.net/2010/01/28/oracle-play-framework-easy/</link>
		<comments>http://hugomonteiro.net/2010/01/28/oracle-play-framework-easy/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 12:18:02 +0000</pubDate>
		<dc:creator>Hugo Monteiro</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[en]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://hugomonteiro.net/?p=277</guid>
		<description><![CDATA[To configure your oracle database using the play framework you need to follow the following steps: Choose the JAR with the drivers according to your oracle&#8217;s database version and put in the lib/ directory of your web application Configure your application.conf file,  located inside the conf/ directory In the JPA Configuration Section you have to [...]]]></description>
			<content:encoded><![CDATA[<p>To configure your oracle database using the <a href="http://www.playframework.org/">play framework</a> you need to follow the following steps:</p>
<ol>
<li>Choose the <a href="http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html">JAR</a> with the drivers according to your oracle&#8217;s database version and put in the <em>lib/</em> directory of your web application</li>
<li>Configure your application.conf file,  located inside the <em>conf/</em> directory
<ul>
<li>In the JPA Configuration Section you have to choose the <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-optional-dialects">JPA (Hibernate) dialect</a>. In my case I was working with oracle10g so i had to insert in the configuration file:
<ul>
<li>
<pre>jpa.dialect=org.hibernate.dialect.Oracle10gDialect</pre>
</li>
</ul>
</li>
<li>Now you just need to add the following lines, according to your database (including username and password).
<ul>
<li>
<pre>db.url=jdbc:oracle:thin:@yourdatabaseserver:1521:dbname
db.driver=oracle.jdbc.driver.OracleDriver
db.user=yourusername
db.pass=yourpassword</pre>
</li>
</ul>
</li>
</ul>
</li>
<li>Now you just need to restart the server. He adds the database drivers automatically to the classpath of the project.</li>
<li>If you want, you can generate <a href="http://www.netbeans.org">Netbeans</a> or <a href="http://www.eclipse.org">Eclipse</a> projects, so you can open this projects with everything configured.</li>
</ol>
<p>Really easy with no XMLs!</p>
]]></content:encoded>
			<wfw:commentRss>http://hugomonteiro.net/2010/01/28/oracle-play-framework-easy/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

