<?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>OCPsoft</title>
	<atom:link href="http://ocpsoft.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://ocpsoft.org</link>
	<description></description>
	<lastBuildDate>Fri, 24 May 2013 13:26:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Migrating from PrettyFaces to Rewrite &#8211; Simplicity meets power</title>
		<link>http://ocpsoft.org/java/migrating-from-prettyfaces-to-rewrite-simplicity-meets-power/</link>
		<comments>http://ocpsoft.org/java/migrating-from-prettyfaces-to-rewrite-simplicity-meets-power/#comments</comments>
		<pubDate>Sat, 04 May 2013 17:04:32 +0000</pubDate>
		<dc:creator>Daniel Sachse</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=3966</guid>
		<description><![CDATA[Hi Java web-developers. I hope you are already familiar with PrettyFaces. If not, I will give you a very short introduction taken from the project documentation: PrettyFaces is: &#8220;The open-source /url/#{rewriting} solution for Servlet, JSF, and Java EE, including features such as: page-load actions, seamless integration with faces navigation, dynamic view-id assignment, managed parameter parsing, [...]]]></description>
				<content:encoded><![CDATA[

Hi Java web-developers. I hope you are already familiar with <a href='http://ocpsoft.org/prettyfaces/'>PrettyFaces</a>. If not, I will give you a very short introduction taken from the project documentation:


<h3>PrettyFaces is:</h3>
<p><em>&#8220;The open-source <strong>/url/#{rewriting}</strong> solution for Servlet, JSF, and Java EE, including features such as: page-load actions, seamless integration with faces navigation, dynamic view-id assignment, managed parameter parsing, and configuration-free compatibility with other web frameworks.&#8221;</em></p>

<p>
<a href='http://ocpsoft.org/rewrite/'>Rewrite</a>, on the other hand, is a URL-rewriting framework built for extendability, for use with any web-framework or pure Servlet itself, and is used for the core of PrettyFaces &#8220;4.0&#8243; &#8211; bringing the best of both worlds&#8230; so that sounds very cool thus far, but what do we want to achieve with it? Why would we use either of these frameworks?</p><span id="more-3966"></span>


<h3>Just compare these two URLs:</h3>
<p>
Very ugly one : 

<div class='snippit'><pre lang='' class='prettyprint'>http://www.example.com/blog.html?author=w0mbat&amp;amp;post_id=23&amp;amp;year=2012</pre></div>

A very pretty one : 
<div class='snippit'><pre lang='' class='prettyprint'>http://www.example.com/blog/w0mbat/2012/23</pre></div>

<p>This is something that both PrettyFaces and Rewrite can accomplish for us, but what if, for example, we wanted to intercept all URLs and require a login? This is where PrettyFaces can no longer help us, but rewrite is ready to come to our aid!


<h2>Why migrate?</h2>

<p>PrettyFaces itself is really great but the configuration is not runtime dynamic. There is a feature called &#8220;DynaView&#8221;, which can be used to determine the page to display for a given URL-mapping at runtime, but it is fairly limited and is difficult to use when things get hairy. To achieve some level of dynamism, one can implement what is called a &#8220;RewriteProcessor,&#8221; but it&#8217;s basically all manual coding; there are no dynamic rules that one would need to e.g. display a login page for every requested URL if the user is not logged in. 

<p>This is only one of many cool features that <a href='http://ocpsoft.org/rewrite/'>Rewrite</a> offers in comparison to PrettyFaces.


<div class='warn alert'> <div>In this post we are going to migrate a PrettyFaces project which is NOT annotation based. We just use the pretty-config.xml to map everything.</div> </div>


<h2 class="toc">Part 1 : Stock-taking</h2>


<p>I created a small JEE 6 sample webapp with <a title="JBoss Forge" href="http://jboss.org/forge" target="_blank">JBoss Forge</a> which you can fork or <a href="https://github.com/w0mbat/PrettyMigration" title="Github" target="_blank">clone from Github</a> if you want. This application will show us several things:

<p><ul>
	<li>a small pom.xml with only a few dependencies</li>
	<li>an XHTML template to be DRY</li>
	<li>four pages: index, about, profile, login</li>
	<li>a WEB-INF/pretty-config.xml</li>
</ul>

<p>We will start with our pretty-config.xml shown below:

<script type='text/javascript'>jQuery(window).load(function(){prettyPrint();});</script><div class='snippit'><div class='snippit-filename'>WEB-INF/pretty-config.xml<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_1_total_'>&lt;pretty-config xmlns=&quot;http://ocpsoft.com/prettyfaces/3.3.2&quot; 
               xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
               xsi:schemaLocation=&quot;http://ocpsoft.com/prettyfaces/3.3.2 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.2.xsd&quot;&gt;
	&lt;url-mapping id=&quot;home&quot;&gt; 
		&lt;pattern value=&quot;/&quot; /&gt; 
		&lt;view-id value=&quot;/index.xhtml&quot; /&gt;
	&lt;/url-mapping&gt;
	
	&lt;url-mapping id=&quot;about&quot;&gt; 
		&lt;pattern value=&quot;/About&quot; /&gt;
		&lt;view-id value=&quot;/about.xhtml&quot; /&gt;
	&lt;/url-mapping&gt;
	
	&lt;url-mapping id=&quot;profile&quot;&gt; 
		&lt;pattern value=&quot;/Profile&quot; /&gt;
		&lt;view-id value=&quot;/profile.xhtml&quot; /&gt;
	&lt;/url-mapping&gt;
&lt;/pretty-config&gt;</pre></div>

<p>This file just maps / to index.xhtml, /About to about.xhtml and /Profile to profile.xhtml. The pages just have links to each other, to provide some sort of interaction. Nothing too special <img src="http://ocpsoft.org/wp-includes/images/smilies/icon_wink.gif?1628ff" alt=';)' class='wp-smiley' /> 

<p>Below you can see some content of the index.xhtml to get an idea of how the navigation with PrettyFaces works:

<div class='snippit'><div class='snippit-filename'>/src/main/webapp/index.xhtml<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_2_total_'>&lt;ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
				xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
				xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
				xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
				template=&quot;/WEB-INF/templates/default.xhtml&quot;&gt;
				
	&lt;ui:define name=&quot;links&quot;&gt;
		&lt;h:link outcome=&quot;pretty:about&quot; value=&quot;About&quot;/&gt;
		&lt;h:outputText value=&quot;	&quot; /&gt;
		&lt;h:link outcome=&quot;pretty:profile&quot; value=&quot;Profile&quot;/&gt;
	&lt;/ui:define&gt;							
&lt;/ui:composition&gt;</pre></div>

<p>All the other files(web.xml, faces-config.xml,..) are pretty straight forward and you can check them out via Github.

<h2 class="toc">Part 2 : Migration</h2>

<p>The easiest way to migrate to Rewrite, is simply to use the Rewrite PrettyFaces compatibility module. Remove any PrettyFaces dependencies that you may have in your project, then include the following dependencies.

First we will have to change the pom to exclude PrettyFaces and include Rewrite:
<div class='snippit'><div class='snippit-filename'>/pom.xml<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_3_total_'>&lt;dependency&gt;
	&lt;groupId&gt;org.ocpsoft.rewrite&lt;/groupId&gt;
	&lt;artifactId&gt;rewrite-servlet&lt;/artifactId&gt;
	&lt;version&gt;2.0.0.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
   &lt;groupId&gt;org.ocpsoft.rewrite&lt;/groupId&gt;
   &lt;artifactId&gt;rewrite-config-prettyfaces&lt;/artifactId&gt;
   &lt;version&gt;2.0.0.Final&lt;/version&gt;
&lt;/dependency&gt;</pre></div>

<p>That&#8217;s it! You&#8217;re done. You&#8217;d now using PrettyFaces with Rewrite core, but since you probably want to know a little bit more about how to use the power of <a href='http://ocpsoft.org/rewrite/'>Rewrite</a>, let&#8217;s continue and learn how to replace our PrettyFaces configuration with Rewrite completely. We&#8217;ll also learn a few tricks that Rewrite can help us with.

<h3>Migrating the configuration</h3>

<p>First, delete your <code>pretty-config.xml</code>, but keep it somewhere you can look at while you move the functionality over to Rewrite.

<p>Now, we need to create several ConfigurationProvider classes. These classes have to extend <code>org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider</code> (for servlet environments.) A ConfigurationProvider has a method which returns a priority and a method which returns the Configuration. Have a look at the <code>AccessRewriteConfiguration</code> below:

<div class='snippit'><div class='snippit-filename'>at.w0mb.prettyMigration.rewrite.AccessRewriteConfiguration<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_4_total_'>package at.w0mb.prettyMigration.rewrite;

import javax.servlet.ServletContext;

import org.ocpsoft.rewrite.bind.El;
import org.ocpsoft.rewrite.config.*;
import org.ocpsoft.rewrite.servlet.config.*;

public class AccessRewriteConfiguration extends HttpConfigurationProvider {
	@Override
	public Configuration getConfiguration(final ServletContext context) {
		return ConfigurationBuilder.begin()
				.addRule(Join.path(&quot;/&quot;).to(&quot;/index.xhtml&quot;))
				.addRule(Join.path(&quot;/about&quot;).to(&quot;/about.xhtml&quot;))
				.addRule(Join.path(&quot;/profile&quot;).to(&quot;/profile.xhtml&quot;))
				.addRule(Join.path(&quot;/login&quot;).to(&quot;/login.xhtml&quot;))

				// Authentication
				.defineRule()
				.when(Direction.isInbound().and(Path.matches(&quot;/logout&quot;)))
				.perform(Invoke.binding(El.retrievalMethod(&quot;identity.logout&quot;))
						.and(Redirect.temporary(context
							.getContextPath() + &quot;/&quot;)));
	}

	@Override
	public int priority() {
		return 10;
	}
}</pre></div>

<p>With this Configuration, we mainly implemented what we saw earlier in the <code>pretty-config.xml</code>; but we have also defined a &#8216;virtual&#8217; URL that doesn´t map to an <code>*.xhtml</code> file, but rather, invokes a bean method that performs the logout and redirects to <code>/</code>.

<p><strong>Question</strong>:<em> What happens if we try to invoke the application now?!? No idea? Ok.</em>
<p><strong><em>Answer</em></strong>: <em>We will get error messages because JSF cannot find any mappings for our ourcomes e.g. pretty:about, pretty:profile, &#8230;</em>

<p>So what do we need to do now? We have to do the mapping ourselves in the faces-config.xml:

<div class='snippit'><div class='snippit-filename'>WEB-INF/faces-config.xml<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_5_total_'>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;faces-config xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
   xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd&quot;
   version=&quot;2.0&quot;&gt;
   
   &lt;navigation-rule&gt;
		&lt;from-view-id&gt;*&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;pretty:home&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/index.xhtml&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;
	
	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;*&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;pretty:about&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/about.xhtml&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;
	
	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;*&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;pretty:profile&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/profile.xhtml&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;
&lt;/faces-config&gt;</pre></div>

<p>The application would nearly work now as we have written it. But how about the login? We will define another <code>ConfigurationProvider</code> as shown below. 

<p>First, though, we will need to add another dependency to our POM. This will enable us to <code>@Inject</code> our <code>Identity</code> object directly into the configuration. The <a href="https://github.com/ocpsoft/rewrite/tree/master/integration-cdi" target="_blank">rewrite-integration-cdi</a> extension module, enriches our rewrite configuration objects with CDI support, and gives us access to the Unified Expression Language (not shown.)

<div class='snippit'><div class='snippit-filename'>Exhibit 5<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_6_total_'>&lt;dependency&gt;
	&lt;groupId&gt;org.ocpsoft.rewrite&lt;/groupId&gt;
	&lt;artifactId&gt;rewrite-integration-cdi&lt;/artifactId&gt;
	&lt;version&gt;2.0.0.Final&lt;/version&gt;
&lt;/dependency&gt;</pre></div>

<div class='snippit'><div class='snippit-filename'>at.w0mb.prettyMigration.rewrite.LoginInterceptor<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_7_total_'>package at.w0mb.prettyMigration.rewrite;

import javax.inject.Inject;
import javax.servlet.ServletContext;

import at.w0mb.prettyMigration.Identity;

import org.ocpsoft.rewrite.config.*;
import org.ocpsoft.rewrite.servlet.config.*;

public class LoginInterceptor extends HttpConfigurationProvider {

	@Inject
	private Identity identity;

	@Override
	public Configuration getConfiguration(ServletContext arg0) {
		ConfigurationBuilder config = ConfigurationBuilder.begin();

		if (!identity.isLoggedIn()) {
			return config
					.defineRule()
					.when(DispatchType.isRequest().and(Direction.isInbound())
					.and(Resources.excluded()))
					.perform(Forward.to(&quot;/login&quot;))
					.addRule(Join.path(&quot;/login&quot;).to(&quot;/login.xhtml&quot;));
		}

		return config;
	}

	@Override
	public int priority() {
		return 0;
	}
}</pre></div>

<p>As a final step, we have to tell Rewrite which <code>ConfigurationProvider</code> classes to use at runtime:
<div class='snippit'><div class='snippit-filename'>META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_8_total_'>at.w0mb.prettyMigration.rewrite.LoginInterceptor
at.w0mb.prettyMigration.rewrite.AccessRewriteConfiguration</pre></div>

<h2 class="toc">Part 3 : Conclusion</h2>
<p>We are now able to call our application under http://localhost:8080/prettyMigration and we will see our login page. This page gets displayed no matter which URL we will call. After clicking on &#8216;login&#8217; we will be &#8216;logged in &#8216; and redirected to the index page. Once we open http://localhost:8080/prettyMigration/logout, we are &#8216;logged out&#8217; and we will again see the login page.

<p>You can grab this project <a href="https://github.com/w0mbat/PrettyMigration" title="Github" target="_blank">from Github</a>. The project was build and tested on <a href="http://www.jboss.org/jbossas" title="JBoss AS 7.1" target="_blank">JBoss 7.1</a>, in my opinion the fastest and most advanced application server on the market.

<div class='tip alert'> <div>I hope you liked my first post on this blog and if you have any comments/questions/improvements, please just post a comment here or contact me!</div> </div><div class="featured" style="text-align: justify; margin-top: 15px;">
	<div class="inside">
		<table cellspacing="15px">
			<tbody>
				<tr valign="top">
					<td><img style="margin-top: 0px;"
						src="http://www.w0mb.at/resources/gfx/w0mbat.jpg"
						alt="Daniel Sachse" title="Daniel Sachse"
						class="alignleft size-thumbnail wp-image-373"></td>
					<td>
						<h3>About the author:</h3>
						<p>
							<a href="http://www.w0mb.at" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.w0mb.at']);" target="_blank"> Daniel 'w0mbat' Sachse</a>
								is a Senior Software Engineer and IT Consultant and works as a Freelancer at his own company called <a href="http://www.wombatsoftware.de/"
								onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.wombatsoftware.de/']);"
								target="_blank">Wombat Software Technologies</a>. He mainly works on Java EE Web Applications as a Developer or Architect but also gives IT Training in this area. He also contributes to
								<a href="http://jboss.org/forge" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://jboss.org/forge']);" target="_blank">JBoss Forge</a>
								and some of its plugins. This blog represents his personal thoughts and perspectives, not necessarily those of his customers.
						</p>
						<p>
						Daniel is also member of the 'JSR 346: Contexts and Dependency Injection for JavaTM EE 1.1 ' expert group.
						</p>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/java/migrating-from-prettyfaces-to-rewrite-simplicity-meets-power/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Set up an anti-spam filter for your website with mod_security and fail2ban</title>
		<link>http://ocpsoft.org/opensource/antispam-filter-with-modsecurity-and-fail2ban/</link>
		<comments>http://ocpsoft.org/opensource/antispam-filter-with-modsecurity-and-fail2ban/#comments</comments>
		<pubDate>Wed, 03 Apr 2013 15:27:25 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=17680</guid>
		<description><![CDATA[Frequently spammers target products such as wordpress, web forum software, phpMyAdmin, and other common tools used by hobbyist and professional website administrators. Whether you are hosting your own blog, or running a website for your company or more, it can be difficult to deal with the increasing amount of malicious web traffic seen on a [...]]]></description>
				<content:encoded><![CDATA[
<a href="http://ocpsoft.org/wp-content/uploads/2013/04/Screen-Shot-2013-04-08-at-11.31.03-AM.png?1628ff" data-lightboxplus="lightbox[17680]" title="Set up an anti-spam filter for your website with mod_security and fail2ban"><img src="http://ocpsoft.org/wp-content/uploads/2013/04/Screen-Shot-2013-04-08-at-11.31.03-AM-300x269.png?1628ff" alt="top apache2 cpu usage" width="300" height="269" class="pull-right size-medium wp-image-17695" /></a>
<p>
Frequently spammers target products such as wordpress, web forum software, phpMyAdmin, and other common tools used by hobbyist and professional website administrators.
<p>Whether you are hosting your own blog, or running a website for your company or more, it can be difficult to deal with the increasing amount of malicious web traffic seen on a daily basis, while still allowing friendly crawlers such as Google, Yahoo, and MSN search engines.
<p>
This harmful and wasteful traffic may damage your system or simply waste its resources, slowing down the site for your more welcome users. If this sounds familiar to you, but your page hits don&#8217;t seem to add up, then you may want to consider taking some of the measures outlined below in order to secure your site from harmful hacks and sluggish spam.
<p>
<span id="more-17680"></span>

<h2 class="toc">Get set up</h2>

<p>
First things first, of course &#8211; installation is where we begin. mod_security and fail2ban are not new technologies, so we will be turning to some existing tutorials for our first getting started steps. We will then continue to tweak these tools to allow traffic from search engines and friendly crawlers.

There is a <a href="http://www.thefanclub.co.za/how-to/how-install-apache2-modsecurity-and-modevasive-ubuntu-1204-lts-server" target="_blank">fantastic tutorial on how to set up mod_security</a> over here at thefanclub.co, which I highly recommend using if you are on a debian/ubuntu system.

<p>If you are on Fedora, RHEL, or CentOS (eww), then the setup is a little bit simpler <a href="http://www.cyberciti.biz/faq/rhel-fedora-centos-httpd-mod_security-configuration/" target="_blank">for mod_security</a> and <a href="http://www.tecmint.com/install-fail2ban-on-rhel-centos-fedora/" target="_blank">for fail2ban</a>; however, you will still want to <a href="https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project" target="_blank">install the OWASP mod_security core rule set</a> (crs).

<div class='tip alert'> <div>You should definitely <a href="https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project" target="_blank">install the OWASP mod_security core rule set</a> unless you simply want to <a href="http://www.modsecurity.org/documentation/modsecurity-apache/1.9.3/html-multipage/04-rules.html" target="_blank">write your own rules</a>.</div> </div>

Once you have installed and configured mod_security, and installed fail2ban, you will need to <a href="http://www.fail2ban.org/wiki/index.php/HOWTO_fail2ban_with_ModSecurity2.5" target="_blank">configure fail2ban to read the mod_security audit file</a>. Once completed, you are ready to start tweaking!

<div class='error alert'> <div>
<strong>CRITICAL:</strong> Add your current IP address or IP range to the fail2ban whitelist or YOU COULD BE LOCKED OUT OF YOUR SYSTEM. See, &#8220;<a href="http://www.fail2ban.org/wiki/index.php/Whitelist" target="_blank">using the fail2ban whitelist</a>.&#8221;
</div> </div>

Now restart Apache HTTPd and let&#8217;s get started.

<div class='command alert'> <pre>/etc/init.d/apache2 restart</pre> </div>

<h2 class="toc">Tweaking mod_security to allow googlebot, yahoo, and msn</h2>

There are a few things that we do NOT want to do with mod_security, and the first of which is block search engine&#8217;s crawlers when they try to access our site. Their log entries will look like the example below, which creates a difficult situation. Because the IP address is informationally logged in a format that fail2ban will later pick up and try to block, we will need to find a way to prevent logging, or tell fain2ban NOT to block it.

<div class='command alert'> <pre>--7f70c037-A--
[08/Apr/2013:10:43:17 --0400] UWLXhH8AAAEAAHFfJ@QAAAAD 66.249.73.107 46478 67.23.9.184 80
--7f70c037-B--
GET /not-there HTTP/1.1
Host: ocpsoft.org
Connection: Keep-alive
Accept: */*
From: googlebot(at)googlebot.com
User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Accept-Encoding: gzip,deflate

--7f70c037-F--
HTTP/1.1 404 Not Found
X-Powered-By: PHP/5.3.10-1ubuntu3.4
X-Pingback: http://ocpsoft.org/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 5986
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

--7f70c037-H--
Message: Warning. Pattern match &quot;(?:(?:gsa-crawler \\(enterprise; s4-e9lj2b82fjjaa; me\\@mycompany\\.com|adsbot-google \\(\\+http:\\/\\/www\\.google\\.com\\/adsbot\\.html)\\)|\\b(?:google(?:-sitemaps|bot)|mediapartners-google)\\b)&quot; at REQUEST_HEADERS:User-Agent. [file &quot;/etc/modsecurity/activated_rules/modsecurity_crs_55_marketing.conf&quot;] [line &quot;22&quot;] [id &quot;910006&quot;] [rev &quot;2.2.5&quot;] [msg &quot;Google robot activity&quot;] [severity &quot;INFO&quot;]
Apache-Handler: application/x-httpd-php
Stopwatch: 1365432196888162 1004514 (- - -)
Stopwatch2: 1365432196888162 1004514; combined=6736, p1=442, p2=6031, p3=0, p4=0, p5=261, sr=163, sw=2, l=0, gc=0
Producer: ModSecurity for Apache/2.6.3 (http://www.modsecurity.org/); OWASP_CRS/2.2.5.
Server: Apache/2.2.22 (Ubuntu)

--7f70c037-Z--</pre> </div>

As we can see in the example above, mod_security is logging when crawlers visit our website and experience 404 errors (and other problems.) This means that any time googlebot or another crawler is logged in such a manner, they will be banned, even though the traffic is valid. That&#8217;s not good, so we can take an arguably risky step to modify the mod_security configuration to allow our crawling friends.
<p>

Replace the rule action <code>block</code> with the action <code>pass</code>. This tells mod_security not to immediately block a request where something looking like a search bot is involved, but rather keep adding up the attack score until it reaches the threshold.

<div class='warn alert'> <div><strong>NOTE:</strong> This may actually be somewhat bad for security, however, since it is possible to fake the criteria on which these rules match. Spammers may actually masquerade as googlebot and friends! But this still enables mod_security to block the request using its attack score mechanism, while preventing log scraping tools such as fail2ban from blocking the IP addresses of the crawler &#8211; perfection has not yet been achieved. </div> </div>

<div class='snippit'><div class='snippit-filename'>/etc/modsecurity/activated_rules/modsecurity_crs_55_marketing.conf<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_9_total_'># ---------------------------------------------------------------
# Core ModSecurity Rule Set ver.2.2.5
# Copyright (C) 2006-2012 Trustwave All rights reserved.
#
# The OWASP ModSecurity Core Rule Set is distributed under 
# Apache Software License (ASL) version 2
# Please see the enclosed LICENCE file for full details.
# ---------------------------------------------------------------


# These rules do not have a security importance, but shows other benefits of 
# monitoring and logging HTTP transactions.
# --

SecRule REQUEST_HEADERS:User-Agent &quot;msn(?:bot|ptc)&quot; \
        &quot;phase:2,rev:'2.2.5',t:none,t:lowercase,pass,msg:'MSN robot activity',id:'910008',severity:'6'&quot;

SecRule REQUEST_HEADERS:User-Agent &quot;\byahoo(?:-(?:mmcrawler|blogs)|! slurp)\b&quot; \
        &quot;phase:2,rev:'2.2.5',t:none,t:lowercase,pass,msg:'Yahoo robot activity',id:'910007',severity:'6'&quot;

SecRule REQUEST_HEADERS:User-Agent &quot;(?:(?:gsa-crawler \(enterprise; s4-e9lj2b82fjjaa; me\@mycompany\.com|adsbot-google \(\+http:\/\/www\.google\.com\/adsbot\.html)\)|\b(?:google(?:-sitemaps|bot)|mediapartners-google)\b)&quot; \
        &quot;phase:2,rev:'2.2.5',t:none,t:lowercase,pass,msg:'Google robot activity',id:'910006',severity:'6'&quot;</pre></div>

<h2 class="toc">Look for other problems</h2>

You will also want to review the audit log and make sure that things look normal. If you are seeing a lot of outbound errors, it&#8217;s possible that you&#8217;ve been hacked. What is more likely, however, is that you have a bug in your web application and it is simply not playing nice with HTTP; you may not be completely standards compliant:

<div class='command alert'> <pre>Found a match for 'Message: Warning. Match of &quot;rx (&lt;meta.*?(content|value)=\&quot;text/html;\\s?charset=utf-8|&lt;\\?xml.*?encoding=\&quot;utf-8\&quot;)&quot; against &quot;RESPONSE_BODY&quot; required. [file &quot;/etc/modsecurity/activated_rules/modsecurity_crs_55_application_defects.conf&quot;] [line &quot;36&quot;] [id &quot;981222&quot;] [msg &quot;[Watcher Check]  The charset specified was not utf-8 in the HTTP Content-Type header nor the HTML content's meta tag.&quot;] [data &quot;Content-Type Response Header: application/xml&quot;] [tag &quot;WASCTC/WASC-15&quot;] [tag &quot;MISCONFIGURATION&quot;] [tag &quot;http://websecuritytool.codeplex.com/wikipage?title=Checks#charset-not-utf8&quot;]
' but no valid date/time found for 'Message: Warning. Match of &quot;rx (&lt;meta.*?(content|value)=\&quot;text/html;\\s?charset=utf-8|&lt;\\?xml.*?encoding=\&quot;utf-8\&quot;)&quot; against &quot;RESPONSE_BODY&quot; required. [file &quot;/etc/modsecurity/activated_rules/modsecurity_crs_55_application_defects.conf&quot;] [line &quot;36&quot;] [id &quot;981222&quot;] [msg &quot;[Watcher Check]  The charset specified was not utf-8 in the HTTP Content-Type header nor the HTML content's meta tag.&quot;] [data &quot;Content-Type Response Header: application/xml&quot;] [tag &quot;WASCTC/WASC-15&quot;] [tag &quot;MISCONFIGURATION&quot;] [tag &quot;http://websecuritytool.codeplex.com/wikipage?title=Checks#charset-not-utf8&quot;]</pre> </div>

<h2 class="toc">Tweaking fail2ban</h2>
<p>
When configuring fail2ban, you can test a failregex and ignoreregex patterns (as specified in our <code>filter.d/modsec.conf</code>) against the mod_security logfile before activating the fail2ban mod_security filter:

<div class='command alert'> <pre>fail2ban-regex /var/log/apache2/modsec_audit.log &quot;FAIL_REGEX&quot; &quot;IGNORE_REGEX&quot;
fail2ban-regex /var/log/apache2/modsec_audit.log &quot;\[.*?\]\s[\w-]*\s&lt;HOST&gt;\s&quot; &quot;\[.*?\]\s[\w-]*\s&lt;HOST&gt;\s&quot;</pre> </div>


<h2 class="toc">Recovering from fail2ban &#8211; Unblocking an IP address</h2>

From time to time, you may sometimes need to un-ban an IP address, in which case, you&#8217;ll want this handy command, which tells IPtables to dump out a list of all current rules and blocked IPs to the console:

<div class='command alert'> <pre>iptables -L -n</pre> </div>

<div class='snippit'><pre lang='' class='prettyprint'>user@server ~ $ sudo iptables -L -n
[sudo] password for lb3: 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
fail2ban-ModSec  tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
fail2ban-ssh  tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 22

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain fail2ban-ModSec (1 references)
target     prot opt source               destination         
DROP       all  --  77.87.228.68         0.0.0.0/0           
DROP       all  --  213.80.214.171       0.0.0.0/0           
DROP       all  --  70.37.73.28          0.0.0.0/0           
DROP       all  --  2.91.50.184          0.0.0.0/0     

Chain fail2ban-ssh (1 references)
target     prot opt source               destination         
RETURN     all  --  0.0.0.0/0            0.0.0.0/0           
user@server ~ $</pre></div>

We can see that fail2ban is placing its rules in the iptables group <code>fail2ban-ModSec</code>. This is going to be important later, so write this down.

You may then want to extract the IP address from this list so you can pass it to a command line by line:

<div class='command alert'> <pre>iptables -L -n | grep DROP | sed 's/.*[^-]--\s\+\([0-9\.]\+\)\s\+.*$/\1/g'</pre> </div>

And finally, we can pass it to the <code>xargs</code> command and perform the unbanning.

<div class='command alert'> <pre>iptables -L -n | grep DROP | sed 's/.*[^-]--\s\+\([0-9\.]\+\)\s\+.*$/\1/g' | xargs -i{} iptables -D fail2ban-ModSec -s {} -j DROP</pre> </div>

<h2 class="toc">Conclusion</h2>
<p>Please feel free to post comments, improvements, or extensions to this article. I hope that you now have a grasp on some of the fundamental principals of securing the website, while still allowing friendly traffic, but there is obviously a world of work to be done here to achieve a tolerant yet secure rule set.

<p>Again, I recommend making sure that your whitelists are set up BEFORE you turn any of these features on. But once you do flip the switch, you should be happy with a faster, cleaner server.

<p>This only scratches the surface of web application security, of which there are many types, from the server all the way to the application, but the more layers you can get that still work together for users nicely, the better. If you are interested in <a href="http://ocpsoft.org/opensource/secure-your-applications-url-based-attacks-are-real-and-dangerous/">Java application level security</a>, I have a few more posts on that topic. <a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/opensource/antispam-filter-with-modsecurity-and-fail2ban/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Google OAuth2 with Java</title>
		<link>http://ocpsoft.org/java/setting-up-google-oauth2-with-java/</link>
		<comments>http://ocpsoft.org/java/setting-up-google-oauth2-with-java/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 02:03:44 +0000</pubDate>
		<dc:creator>Matyas Danter</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5357</guid>
		<description><![CDATA[For all of you who are trying to figure out how to integrate with Google&#8217;s single sign-on functionality (like I&#8217;ve done for my own startup at tripgather.com), this article might be for you. I&#8217;ve taken the liberty of condensing all of the actual logic required to perform OAuth Google login, and provided it as a [...]]]></description>
				<content:encoded><![CDATA[
<img src="http://ocpsoft.org/wp-content/uploads/2013/02/oauth_logo.png?1628ff" alt="oauth_logo" width="300" height="298" class="pull-right size-full wp-image-5431" style="margin-left: 15px; margin-bottom: 15px;" />

<p>For all of you who are trying to figure out how to integrate with Google&#8217;s single sign-on functionality (like I&#8217;ve done for my own startup at <a href="http://tripgather.com" target="_blank">tripgather.com</a>), this article might be for you. I&#8217;ve taken the liberty of condensing all of the actual logic required to perform OAuth Google login, and provided it as a class and a JSP (seen below). In order to follow along better, I suggest cloning the <a href="http://github.com/mdanter/OAuth2v1" target="_blank">example GitHub repository</a>, and deploying to the application to your <a href="http://jboss.org/jbossas">server of choice</a>.</p>
<span id="more-5357"></span>

<h2 class="toc">Assumptions</h2>

<ul>
	<li>Familiarity with object oriented programming, Java, Maven, and Java EE</li>
	<li>An IDE, it helps if you are comfortable using one (i.e. Eclipse)</li>
	<li>Java application server listening on localhost:8080</li>
</ul>

<h2 class="toc">Prerequisites</h2>

<a href="http://ocpsoft.org/wp-content/uploads/2013/02/1google_oauth_access.png?1628ff" data-lightboxplus="lightbox[5357]" title="Setting up Google OAuth2 with Java"><img src="http://ocpsoft.org/wp-content/uploads/2013/02/1google_oauth_access-300x281.png?1628ff" alt="1google_oauth_access" width="300" height="281" class="pull-right size-medium wp-image-5361" style="margin: 15px; margin-right: 0px; margin-top: 0px;" /></a>

<ul>
	<li>Google API Access credentials (Client ID, Client Secret). Set it up here <a href='https://code.google.com/apis/console/'>https://code.google.com/apis/console/</a>
	</li>
	<li>Set up allowed Redirect URIs at <strong>Google API &rarr; API Access</strong>. Input: <code>http://localhost:8080/OAuth2v1/index.jsp</code></li>
	<li>The <a href="http://github.com/mdanter/OAuth2v1/" >source code</a> referenced in this article from GitHub.</li>
	<li>A positive outlook on life.</li>
</ul>

<p>Please use the link above to set up API Access Credentials. When you are finished, you will see a similar page to the one below. Use your Client ID/Secret from this page to replace the values of the String constants in <code>GoogleAuthHelper.java</code>.</p>


<h2 class="toc">Usage</h2>

<ol>
	<li>Add Client ID, and Client Secret parameters to <code>GoogleAuthHelper.java</code></li>
	<li>Compile the project:<div class='command alert'> <pre>$ mvn clean install</pre> </div></li>
<li>Deploy war to application server</li>
	<li>Browse to: <a href="http://localhost:8080/OAuth2v1/">http://localhost:8080/OAuth2v1/</a></li>
	<li>Click <b>&quot;log in with google&quot;</b> on top of the page</li>
</ol>


<h3 class="toc">1. Add Client ID and Secret</h3>
<p>Replace the constants following constant values in <code>GoogleAuthHelper.java</code> with the values provided to you by Google API Access.</p>


<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Please provide a value for the CLIENT_ID constant before proceeding, set this up at https://code.google.com/apis/console/
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> CLIENT_ID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;YOUR ID HERE&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Please provide a value for the CLIENT_SECRET constant before proceeding, set this up at https://code.google.com/apis/console/
 */</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> CLIENT_SECRET <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SUPER SECRET SAUCE&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>





<h3 class="toc">2, 3, &amp; 4. Compile the Project, Deploy the WAR, Open that Browser</h3>
<p>This is a Maven based project, so issue a Maven install command to build the project and assemble the war file from the root of the project (where the pom.xml file is located).</p>

<div class='command alert'> <pre>$ mvn clean install</pre> </div>

<p>When Maven is finished creating the web archive, deploy it to your favorite server and navigate to <a href="http://localhost:8080/OAuth2v1/">http://localhost:8080/OAuth2v1/</a></p>


<a href="http://ocpsoft.org/wp-content/uploads/2013/02/2click_auth.png?1628ff" data-lightboxplus="lightbox[5357]" title="Setting up Google OAuth2 with Java"><img src="http://ocpsoft.org/wp-content/uploads/2013/02/2click_auth-300x226.png?1628ff" alt="2click_auth" width="300" height="226" class="pull-right size-medium wp-image-5362" /></a>

<h3 class="toc">5. Click <b>&quot;log in with google&quot;</b></h3>

<p>Now that your app server is running, the application is deployed, and your web browser is pointed at the application&#8217;s context root, you will see a page similar to the one below. I double dog dare you to click that log in button. You know you want to.</p>

<div class="clearer"></div>

<div class='warn alert'> <div>
<a href="http://ocpsoft.org/wp-content/uploads/2013/02/3result.png?1628ff" data-lightboxplus="lightbox[5357]" title="Setting up Google OAuth2 with Java"><img src="http://ocpsoft.org/wp-content/uploads/2013/02/3result-300x261.png?1628ff" alt="3result" width="300" height="261" class="pull-right size-medium wp-image-5363" style="margin-left: 15px;" /></a>
<h4>After successful authentication you will see the page below, but there are a few important things to notice:</h4>

	<ol>
		<li>The URL changed, now it contains two request parameters, <b>state</b>,
			and <b>code</b>.
		</li>
		<li>The page contains JSON output of your google account&#8217;s profile
			information.</li>
	</ol>
<div class="clearer"></div>
</div> </div>


<h2 class="toc">Source Code</h2>

<p>The authentication is possible thanks to the <code>GoogleAuthorizationCodeFlow</code> class. This class uses the Builder pattern to provide most of its functionality. GoogleAuthHelper&#8217;s no-argument constructor initializes the Flow using your client ID, secret, and other constants. The <code>buildLoginUrl()</code> method constructs the Google authentication URL based on the <code>CALLBACK_URI</code> and returns it as a Java String. This <code>CALLBACK_URI</code> must match one of the redirect URIs that you set up at Google&#8217;s API Access page. Upon successful authentication, OAuth2 will redirect you to <code>CALLBACK_URI</code>, and append the <b>state</b> and <b>code</b> GET request parameters to it. Please note, that the state request parameter is only to help differentiate authentication providers (i.e. Facebook OAuth, Google OAuth, or your own custom OAuth provider). </p>

<p>We need to use the <b>code</b> GET request parameter as the input for the 	<code>getUserInfoJson(String authCode)</code> method. If all is well, this method will return a JSON encoded Google profile as a Java String.</p>

<h4>Here is the basic code that you can snip into your project:</h4>

<div class='snippit'><div class='snippit-filename'>index.jsp<a href='https://github.com/mdanter/OAuth2v1/blob/master/src/main/webapp/index.jsp' target='_blank' class='snippit-file' style='float:right;'>View Complete File</a><div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_10_total_'>&lt;%
/*
 * The GoogleAuthHelper handles all the heavy lifting, and contains all &quot;secrets&quot;
 * required for constructing a google login url.
 */
final GoogleAuthHelper helper = new GoogleAuthHelper();
if (request.getParameter(&quot;code&quot;) == null
	|| request.getParameter(&quot;state&quot;) == null) {
	/*
	 * initial visit to the page
	 */
	out.println(&quot;&lt;a href='&quot; + helper.buildLoginUrl() + &quot;'&gt;log in with google&lt;/a&gt;&quot;);

} else if (request.getParameter(&quot;code&quot;) != null &amp;&amp; request.getParameter(&quot;state&quot;).equals(&quot;google&quot;)) {

	/*
	 * Executes after google redirects to the callback url.
	 * Please note that the state request parameter is for convenience to differentiate
	 * between authentication methods (ex. facebook oauth, google oauth, twitter, in-house).
	 * 
	 * GoogleAuthHelper()#getUserInfoJson(String) method returns a String containing
	 * the json representation of the authenticated user's information. 
	 * At this point you should parse and persist the info.
	 */

	out.println(helper.getUserInfoJson(request.getParameter(&quot;code&quot;)));
}
%&gt;</pre></div>

<div class='snippit'><div class='snippit-filename'>GoogleAuthHelper.java<a href='https://github.com/mdanter/OAuth2v1/blob/master/src/main/java/com/danter/google/auth/GoogleAuthHelper.java' target='_blank' class='snippit-file' style='float:right;'>View Complete File</a><div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_11_total_'>public final class GoogleAuthHelper {

	/**
	 * Please provide a value for the CLIENT_ID constant before proceeding, set this up at https://code.google.com/apis/console/
	 */
	private static final String CLIENT_ID = &quot;YOUR ID HERE&quot;;
	/**
	 * Please provide a value for the CLIENT_SECRET constant before proceeding, set this up at https://code.google.com/apis/console/
	 */
	private static final String CLIENT_SECRET = &quot;SUPER SECRET SAUCE&quot;;

	/**
	 * Callback URI that google will redirect to after successful authentication
	 */
	private static final String CALLBACK_URI = &quot;http://localhost:8080/OAuth2v1/index.jsp&quot;;
	
	// start google authentication constants
	private static final Iterable&lt;String&gt; SCOPE = Arrays.asList(&quot;https://www.googleapis.com/auth/userinfo.profile;https://www.googleapis.com/auth/userinfo.email&quot;.split(&quot;;&quot;));
	private static final String USER_INFO_URL = &quot;https://www.googleapis.com/oauth2/v1/userinfo&quot;;
	private static final JsonFactory JSON_FACTORY = new JacksonFactory();
	private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
	// end google authentication constants
	
	
	private final GoogleAuthorizationCodeFlow flow;
	
	/**
	 * Constructor initializes the Google Authorization Code Flow with CLIENT ID, SECRET, and SCOPE 
	 */
	public GoogleAuthHelper() {
		flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT,
				JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, SCOPE).build();
	}

	/**
	 * Builds a login URL based on client ID, secret, callback URI, and scope 
	 */
	public String buildLoginUrl() {
		
		final GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
		
		return url.setRedirectUri(CALLBACK_URI).setState(&quot;google&quot;).build();
	}
	
	/**
	 * Expects an Authentication Code, and makes an authenticated request for the user's profile information
	 * @return JSON formatted user profile information
	 * @param authCode authentication code provided by google
	 */
	public String getUserInfoJson(final String authCode) throws IOException {

		final GoogleTokenResponse response = flow.newTokenRequest(authCode).setRedirectUri(CALLBACK_URI).execute();
		final Credential credential = flow.createAndStoreCredential(response, null);
		final HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential);
		// Make an authenticated request
		final GenericUrl url = new GenericUrl(USER_INFO_URL);
		final HttpRequest request = requestFactory.buildGetRequest(url);
		request.getHeaders().setContentType(&quot;application/json&quot;);
		final String jsonIdentity = request.execute().parseAsString();

		return jsonIdentity;

	}
}</pre></div>

<h2 class="toc">Next Steps</h2>
<p>If you haven&#8217;t already <a href="https://github.com/mdanter/OAuth2v1" target="_blank">downloaded the code</a> and run it, I suggest you do that before bringing it into your codebase. There are a few Maven dependencies <a href="https://github.com/mdanter/OAuth2v1/blob/master/pom.xml" target="_blank">in the POM</a> that you will need to include.</p>

<p>From here on, you may parse this information using <a href="http://jackson.codehaus.org/" target="_blank">Jackson</a>, and persist it to a database or other data store. These are the basic building blocks with which you should be able to &#8220;get the stuff done.&#8221;</p>

<h3 class="toc">Resources and Links</h3>
<ul>
	<li><a href="http://github.com/mdanter/OAuth2v1">The code on GitHub</a></li>
	<li><a href="https://code.google.com/p/google-api-java-client/wiki/OAuth2">Google APIs Client Library for Java</a></li>
	<li><a href="https://developers.google.com/accounts/docs/OAuth2#libraries">Using OAuth 2.0 to Access Google APIs</a></li>
</ul>

<a name=\"Matyas\"></a><div class=\"box-shadow signature\">

<h3 class=\"signature-header\">About the author:</h3>
<p><a href=\"http://twitter.com/mdanter\" target=\"_blank\">Matyas Danter</a> is a Senior Associate at LiquidHub currently working at a large financial institution as a Production Support Specialist. He is interested in cryptography, software development awesomeness, and enterprise web applications.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/java/setting-up-google-oauth2-with-java/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaScript is the new Perl</title>
		<link>http://ocpsoft.org/opensource/javascript-is-the-new-perl/</link>
		<comments>http://ocpsoft.org/opensource/javascript-is-the-new-perl/#comments</comments>
		<pubDate>Fri, 04 Jan 2013 18:32:49 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[OpenSource]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5231</guid>
		<description><![CDATA[I don&#8217;t think we will see a &#8220;winner&#8221; of the browser-language wars any time soon, but there will be a winner. JavaScript hype is still through the roof, and with the discovery of a dynamic language in the browser actually works decently between late browsers, people are thoroughly excited; however, I&#8217;d akin this to people [...]]]></description>
				<content:encoded><![CDATA[<center><div class="box-rounded" style="background: white; padding: 15px;"><img src="http://ocpsoft.org/wp-content/uploads/2013/01/perl_logo-272x300.gif?1628ff" alt="perl_logo" width="272" height="300" class="aligncenter size-medium wp-image-5236" />
<img src="http://ocpsoft.org/wp-content/uploads/2013/01/javascript_logo_unofficial-300x300.png?1628ff" alt="javascript_logo_unofficial" width="300" height="300" class="aligncenter size-medium wp-image-5253" /></div></center>
<hr/>
<p>I don&#8217;t think we will see a &#8220;winner&#8221; of the browser-language wars any time soon, but there will be a winner. JavaScript hype is still through the roof, and with the discovery of a dynamic language in the browser actually works decently between late browsers, people are thoroughly excited; however, I&#8217;d akin this to people discovering Perl during the advent of C and C++. Does it work? Yes. Is it pretty? Not by a long shot.</p>

<p>Don&#8217;t get me wrong, I love Perl &#8211; I think it&#8217;s an incredibly powerful and fun language that now suffers from the bad reputation it acquired before gaining true object-oriented features &#8211; but, those who hate Perl hate it because it&#8217;s &#8220;too hard to maintain&#8221; and too &#8220;strange.&#8221; So if you want to talk about a strange language, look at JavaScript &#8211; it’s like Perl times ten. At least Perl has a consistent type inferencing and enforceable namespacing! (I think you&#8217;d have a hard time arguing that enforceable namespacing is a bad thing&#8230; global variable collisions can result in some pretty nasty bugs, particularly because it is easy to never see the downstream impact.)</p>

<p>Point being? As someone who has already gone through several language hypes and paradigm shifts in Computer Science (even in my relatively short 14 year experience,) JavaScript is a lot like Perl &#8211; extremely powerful, but a potential maintenance nightmare if one is not extremely diligent &#8211; and while I do like both languages, JavaScript just waiting for the next technology to come around and make it look like Perl does today: pervasive, but lacking enterprise adoption on large applications.</p>
<span id="more-5231"></span>

<div class='tip alert'> <div>
Follow the author on Twitter: <a href="http://twitter.com/lincolnthree"> @lincolnthree </a>
</div> </div>

<h3>Let&#8217;s take a moment to talk about Perl.</h3>

<p>Perl was never as popular as JavaScript has become lately, partly because we never had a reason to popularize Perl in startup culture &#8211; where a teenager in his bedroom can make the next twitter craze &#8211; and partly because technology was just not as hot or nearly as pervasive back then.</p>

<p>If you look at the current trends, Perl is actually being replaced on a fairly large scale by Python and Ruby (other dynamic languages,) which, depending on <a href="http://blogs.computerworld.com/15460/perl_vs_php_vs_ruby" target="_blank">who you ask</a>, solve some of the maintenance problems and complaints that people have of Perl, and JavaScript is very likely to go through the same life-cycle &#8211; to be <a href="http://jaxenter.com/douglas-crockford-java-was-a-colossal-failure-javascript-is-succeeding-because-it-works-45928.html" target="_blank">superseded by Dart</a>, or maybe a non-backwards compatible mode of <a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts" target="_blank">ECMAScript</a>. In the mean time, to work around some of these issues, JavaScript is still being used much like an Assembly language. (GWT, CoffeeScript, TypeScript all compile to JavaScript.)</p>

<h3>Now where is JavaScript?</h3>

<p>We are seeing a similar explosion of packages (libraries), like Perl did, which led to the development of CPAN (you could akin this to the jQuery plugin ecosystem, which is neither as formal, reliable, nor as convenient or automated.) There’s a similar explosion of JavaScript implementations on server side and in other languages, leading to issues with compatibility and runtime bugs. If you tried to use ActiveState Perl on windows, or JavaScript via Rhino in Java, then you know what I am talking about. This is improving now, but so has it also improved in Perl, which compared to JavaScript was far more stable.</p>

<p>Still don&#8217;t believe that JavaScript is the new Perl? jQuery and NodeJS modules, likened to a very distributed collection of Perl modules, are the glue that holds together the JavaScript ecosystem, provides browser compatibility, and it admittedly does a pretty good job; however, sooner or later, the lack of language constructs like truly enforceable namespace boundaries, and the general mess created when teams get a little bit bigger is going to set in. This is seen over and over as the new wave of developers comes into corporate life: Larger companies try out new technologies all the time, then decide it&#8217;s costing measurably, and switch back to a stack that is resilient enough to withstand sloppy code.</p>

<p>We are even seeing a re-emergence of age-old discussions on, “<a href="http://addyosmani.com/largescalejavascript/" target="_blank">how to effectively architect large-scale applications</a>”, and how to keep from falling into the same pit of snakes that’s been around for years &#8211; snakes that are now very long in the tooth. These are thoughts and principles apply to any programming language, really, Perl, Python, Java included &#8211; so if you think the revival of this discussion will produce different results for JavaScript, then I think you are forgetting human nature.</p>

<p>We ARE inherently lazy and most of us will ignore nearly any best practice or principle once “that deadline” gets too close. Nobody ever goes back to fix their mistakes once the project ends, or once they get rolled onto a new team. Java has been the only modern language to show moderate survivability when exposed to corporate laziness.</p>

<h3>“So if JavaScript is doomed to become the next Perl like you say it is, then what do we do in the mean-time?”</h3>

<p>We do what we have been doing all along, because these are necessary steps for advancement. We continue to invest both in JavaScript, but also in technologies like <a href="https://docs.jboss.org/author/display/ERRAI/Errai+UI" target="_blank">Errai and GWT</a> &#8211; two technologies whos’ growth echoes of an early 2000’s Java.</p>

<p>We should be mindful of the fact that while JavaScript is HOT right now, it does actually have programmatic and strategic shortcomings that must not be forgotten, ignored, or &#8220;shooed&#8221; under the carpet. If you show me a long-term maintainable solution for JavaScript that enforces the team/feature barrier and holds up against &#8220;corporate meltdown,&#8221; due to incompetence and laziness as application size increases, then I&#8217;d be willing to entertain the idea of using it for a bigger project.</p>

<p>Keep trying the latest frameworks and cool UI plugins; keep trying to bridge the server-browser impedance mismatch; find what works and what does not &#8211; JavaScript is not going away. We still have Perl apps out there, and whatever replaces JavaScript as a dynamic language (think ECMAScript 6, unless a non-backwards compatibility mode is introduced) will probably be viewed similarly to Python or Ruby vs. Perl today. Backwards compatibility will be a problem for ECMAScript because it is necessary to enforce these constraints; it is not enough just make them &#8220;available.&#8221;</p>

<p>Still, you don&#8217;t see that many big Python and Ruby shops either (<a href="http://curiousprogrammer.wordpress.com/2011/01/31/why-did-google-choose-python/" target="_blank">Google is an exception</a>,) so unless ECMAScript offers some of the same safety features of Java, it will probably end up much like Python and Ruby &#8211; “A little better.” In all reality, though, there is a big part of the JavaScript -> Perl/Python/Ruby comparison that we&#8217;ve omitted from the story to this point.</p>

<center><img src="http://ocpsoft.org/wp-content/uploads/2013/01/java_logo-300x184.jpeg?1628ff" alt="java_logo" width="300" height="184" class="aligncenter size-medium wp-image-5252" /></center>

<h3>Java.</h3>

<p>Java has eclipsed most dynamic languages in the corporation. We see new statically typed dynamic languages on the JVM practically every day to provide some more programmatic sugar and flexibility, but on bigger projects, Java is king. Now apply this to the JavaScript picture and you get a slightly different flavor of the same result. Not only are we seeing experiments replacing JavaScript with a similar dynamic language (Dart, <a href="http://coffeescript.org/" target="_blank">CoffeeScript</a>, or maybe just some necessary enhancements to JavaScript itself,) but in order to support large projects, we are also likely to see a type-safe revolution in the browser as well.</p>

<p>GWT is a good start, but progress has been slow &#8211; just like Java was back in 2002. We&#8217;ve waited 10 years to see Java turn into the actually very useful and extremely powerful technology that it is today. Without a doubt, Java has the largest ecosystem of shared libraries in any programming ecosystem. Java has seen ubiquitous corporate adoption. Java is taught at most colleges and universities, and while you might try to make the point that &#8220;Python is being favored over Java&#8221; in some schools now, this is really not because of its technical capability, but more about <a href="http://thinkingdigitally.com/archive/the-case-for-replacing-java-with-python-in-education/ " target="_blank">teaching a more general set of programming knowledge</a> that may or may not actually be useful in a business environment. Functional programming, variable interpolation, and the lack of a separate compile step make Python an appealing educational tool, certainly when combined with a shell language interpreter. This does not change what we use in the enterprise, in our daily jobs.</p>

<p>For example. When I graduated with my BS in Computer Science, before moving to Red Hat, I worked first at one of the top 5 American mutual fund companies; a big bank. I was tasked with something that nobody else had been able to do before, using Java, and I said, &#8220;Okay fine, I can do this easily in Perl.&#8221; So I did it.</p>

<h3>Success? Or something else?</h3>

<p>The result was a nice pat on the back for figuring it out &#8211; it was even deployed to production, but since I had left the team shortly before the release, nobody could figure out how to make changes to my scripts, didn’t think to come ask me when environmental changes caused a failure, and it got abandoned and re-written in Java. Was that a good reason to abandon Perl as a solution? Definitely not, but there&#8217;s a lot to be said for using a technology that is safe, using a technology that enforces &#8216;some&#8217; good practices (&#8220;training wheels&#8221; of type-safety), and using a technology that is well known among the industry. This will be the reality for JavaScript and its corporate replacement, unless it can catch up soon.</p>

<p>In the end, JavaScript is good for us, just like Perl. It pushes us to do better, pushes us to think outside the box, and pushes us to think twice about what we have been doing in the past. It certainly has its place, we can’t ignore it, and we must acknowledge that it is very good at what it does; but, like Perl and Python, it&#8217;s not the end of the line. Until we get our hands on the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts" target="_blank">still evolving ECMAScript 6</a>, which may alleviate JavaScript&#8217;s enterprise problems, we still haven&#8217;t seen our &#8220;Java of the browser&#8221; yet, except wait, yes we have. It&#8217;s <a href="https://docs.jboss.org/author/display/ERRAI/Errai+UI" target="_blank">Errai and GWT</a>.</p>

<p>See you in 10 years, JavaScript. Until then, I&#8217;m going to practice my <a href="http://ocpsoft.org/opensource/guide-to-regular-expressions-in-java-part-1/" title="Guide to Regular Expressions in Java (Part 1)" target="_blank">Regular Expressions</a>.</p>
<a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/opensource/javascript-is-the-new-perl/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>2013 Holiday technology recap and predictions</title>
		<link>http://ocpsoft.org/opensource/2013-holiday-technology-recap-and-predictions/</link>
		<comments>http://ocpsoft.org/opensource/2013-holiday-technology-recap-and-predictions/#comments</comments>
		<pubDate>Mon, 24 Dec 2012 22:23:31 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[OpenSource]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5221</guid>
		<description><![CDATA[Happy holidays, I hope everyone is relaxing and having a great time with their families and loved ones. To help see out the last year, and ring in the new one, I&#8217;ve prepared a (hopefully relaxing) article on some trends we&#8217;ve seen in 2012, and what that could mean for us in the next year [...]]]></description>
				<content:encoded><![CDATA[<img src="http://ocpsoft.org/wp-content/uploads/2012/12/christmas_wreath.png?1628ff" alt="christmas_wreath" width="128" height="128" style="float: right; margin-left: 15px; margin-bottom: 15px;"  /><p>Happy holidays, I hope everyone is relaxing and having a great time with their families and loved ones. To help see out the last year, and ring in the new one, I&#8217;ve prepared a (hopefully relaxing) article on some trends we&#8217;ve seen in 2012, and what that could mean for us in the next year and years to come. So if you want to take a break from the holiday din, then head over to JAXEnter and <a href="http://jaxenter.com/guest-post-how-i-m-preparing-for-the-trends-of-2013-by-lincoln-baxter-iii-45930.html" target="_blank">check out my article</a>. The technologies I discuss are <a href="http://ocpsoft.org/rewrite/" title="Rewrite">Rewrite</a>, OCPsoft&#8217;s own, and <a href="http://jboss.org/errai" target="_blank">Errai</a>, by Red Hat.</p>

<p>Be safe, and I&#8217;ll see you all in the new year,
~Lincoln</p><a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/opensource/2013-holiday-technology-recap-and-predictions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[announcement] Guide to translate PrettyTime to your native language</title>
		<link>http://ocpsoft.org/opensource/announcement-guide-to-translate-prettytime-to-your-native-language/</link>
		<comments>http://ocpsoft.org/opensource/announcement-guide-to-translate-prettytime-to-your-native-language/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 23:06:11 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[PrettyTime]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5171</guid>
		<description><![CDATA[If you&#8217;ve ever looked for social-style date formatting for Java, to create timestamps like, &#8220;2 minutes from now&#8221; or &#8220;3 months ago,&#8221; PrettyTime is probably the tool you&#8217;ve ended up with, and as you might know, it supports over 25 languages and dialects &#8211; a great number to be sure. But what happens when you [...]]]></description>
				<content:encoded><![CDATA[<a style="float:right; margin-left: 15px;" href="http://ocpsoft.org/prettytime/"><img src="http://ocpsoft.org/wp-content/uploads/2012/04/prettytime-center-compressed.png?1628ff" alt="" title="Try prettytime."/></a></center>

<p style="text-align: justify;">If you&#8217;ve ever looked for social-style date formatting for Java, to create timestamps like, &#8220;2 minutes from now&#8221; or &#8220;3 months ago,&#8221; <a href='http://ocpsoft.org/prettytime/'>PrettyTime</a> is probably the tool you&#8217;ve ended up with, and as you might know, it supports over 25 languages and dialects &#8211; a great number to be sure. But what happens when you come across one of the over 4500 living languages that are not supported?
</p><p>
Well, then it&#8217;s time to do some translation, and in order to help you manage this task, we&#8217;ve created a guide to help you get through as quickly and easily as possible. When you&#8217;re done, you might even want to submit your translation back to us so that everyone else can benefit from your hard work. The guide covers this, too.

It takes only a minute or so to <a href="http://ocpsoft.org/prettytime/translate-for-your-language/">read the guide</a> and get started! Let us know how you do.<a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/opensource/announcement-guide-to-translate-prettytime-to-your-native-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[video] GWT and Errai UI Quickstart</title>
		<link>http://ocpsoft.org/jboss/video-gwt-and-errai-ui-quickstart/</link>
		<comments>http://ocpsoft.org/jboss/video-gwt-and-errai-ui-quickstart/#comments</comments>
		<pubDate>Fri, 02 Nov 2012 17:20:55 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5122</guid>
		<description><![CDATA[I wish I had a magic GWT + Errai quickstart tutorial for you. But in fact, I do! Check out this video, and the tutorial below, to start your adventure with client side HTML5 templating in GWT! Get started Check out this code using GIT: https://github.com/lincolnthree/errai-ui-demo To build and deploy, simply cd errai-ui-demo and run [...]]]></description>
				<content:encoded><![CDATA[I wish I had a magic GWT + Errai quickstart tutorial for you. But in fact, I do! Check out this video, and the tutorial below, to start your adventure with client side HTML5 templating in GWT!<p>

<center><iframe src="http://player.vimeo.com/video/44141164?title=0&amp;byline=0&amp;portrait=0&amp;badge=0" width="500" height="313" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></center>

<span id="more-5122"></span>
<h3>Get started</h3>
Check out this code using <a href="http://git-scm.com" target="_blank">GIT</a>: <a href="https://github.com/lincolnthree/errai-ui-demo" target="_blank">https://github.com/lincolnthree/errai-ui-demo</a><p>

To build and deploy, simply <code>cd errai-ui-demo</code> and run <code>mvn clean install</code>. The resulting artifact will be in the target directory, and you can deploy this directly to <a href="http://www.jboss.org/jbossas/downloads/" target="_blank">JBoss AS 7.1</a>.<p>

<h3>Import into IDE and delploy</h3>
To work on the project in an IDE, I would recommend Eclipse with JBoss Tools (available in the <a href="http://marketplace.eclipse.org/content/jboss-tools-indigo" target="_blank">eclipse marketplace</a>,) or JBoss Developer Studio 5. The first thing you will need to do is import the project, then you will still need to run <code>mvn clean install</code> if you have not done so already &#8211; this builds the initial GWT javascript payload for Eclipse to push out with the exploded deployment, then deploy it to JBoss AS 7.1 and start the server. Once it is there, you can return to the command line and type, <code>mvn gwt:run</code>, which will launch GWT dev-mode.<p>

<h3>Run Dev-mode</h3>
Once dev-mode comes online, you can access the application at <a href="http://localhost:8080/errai-ui-demo/?gwt.codesvr=127.0.0.1:9997" target="_blank">http://localhost:8080/errai-ui-demo/?gwt.codesvr=127.0.0.1:9997</a><p>

<h3>Hack on the code</h3>
You can make modifications to </code>*.client</code> packages and sub-packages while the server is running, and refresh the page to see your changes.<p>

Additional documentation about Errai and Errai UI is available here: <a href="https://docs.jboss.org/author/display/ERRAI/Errai+UI" target="_blank">https://docs.jboss.org/author/display/ERRAI/Errai+UI</a><p><a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/jboss/video-gwt-and-errai-ui-quickstart/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[podcast] Lincoln Baxter and Kito Mann on Java</title>
		<link>http://ocpsoft.org/java/podcast-lincoln-baxter-and-kito-mann-on-java/</link>
		<comments>http://ocpsoft.org/java/podcast-lincoln-baxter-and-kito-mann-on-java/#comments</comments>
		<pubDate>Mon, 08 Oct 2012 15:15:09 +0000</pubDate>
		<dc:creator>Team</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5106</guid>
		<description><![CDATA[Join Lincoln Baxter of OCPsoft and Kito Mann of Virtua, Inc. as they discuss several emerging projects in Java. The transcript and MP3 can be found at Virtua&#8217;s site. This podcast was recorded at JAXConf in San Francisco, 2012.]]></description>
				<content:encoded><![CDATA[Join Lincoln Baxter of OCPsoft and Kito Mann of Virtua, Inc. as they discuss several emerging projects in Java. The transcript and <a href="http://content.jsfcentral.com/documents/35702/35731/JSF+Central+Episode+27+-+Lincoln+Baxter.mp3" target="_blank">MP3</a> can be found at <a href="http://content.jsfcentral.com/c/journal/view_article_content?cmd=view&#038;groupId=35702&#038;articleId=50548" target="_blank">Virtua&#8217;s site</a>. This podcast was recorded at JAXConf in San Francisco, 2012.<p/>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/java/podcast-lincoln-baxter-and-kito-mann-on-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://content.jsfcentral.com/documents/35702/35731/JSF+Central+Episode+27+-+Lincoln+Baxter.mp3" length="35073563" type="audio/mpeg" />
		</item>
		<item>
		<title>How to @Inject Enum values into CDI beans</title>
		<link>http://ocpsoft.org/java/how-to-inject-enum-values-into-cdi-beans/</link>
		<comments>http://ocpsoft.org/java/how-to-inject-enum-values-into-cdi-beans/#comments</comments>
		<pubDate>Wed, 19 Sep 2012 17:52:50 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=5023</guid>
		<description><![CDATA[I was recently asked how to Inject a Java Enum into a bean constructor using CDI. This turns out to be a fairly interesting situation, because enums are not usually available for Injection. The first attempt As much as we would hope for this to work, it does not. Enums are not beans because they [...]]]></description>
				<content:encoded><![CDATA[<p>I was recently asked how to Inject a Java Enum into a bean constructor using CDI. This turns out to be a fairly interesting situation, because enums are not usually available for Injection.
<span id="more-5023"></span>

<h3>The first attempt</h3>

<p>As much as we would hope for this to work, it does not. Enums are not beans because they have no default constructor (hence CDI does not know how to construct them,) and there is no standard way to resolve which enumerated value should be injected by default (Unless there is only one value, but this is still not supported due to the lack of default constructor.)

<div class='snippit'><div class='snippit-filename'>Injecting an enum with a single value does not work.<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_12_total_'>public class InjectedObject {
   private MyEnum e;

   @Inject
   public InjectedObject(MyEnum e) {
      this.e = e;
   }
   
   public MyEnum getValue() {
      return e;
   }

   /**
    * Our enum
    */
   public enum MyEnum {
      ONE
   }
}</pre></div>


<h3>This will result in a deployment failure</h3>


<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [MyEnum] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public org.example.InjectedObject(MyEnum)]
	at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:365)
	at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:297)
	at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:157)
	at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:184)
	at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:470)
	at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:74)
	at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:72)
	at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
	at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	... 1 more</pre></td></tr></table></div>






<h1>The solution</h1>
<p>We must turn to producer methods in order to make this possible. It takes just a little bit of code, but it is possible, and very easy! The reason this works is because <b>any</b> value may be injected if it resolves to a unique set of qualifiers and types. You could even inject a <code>java.lang.String</code> using this technique. 

<div class='snippit'><div class='snippit-filename'>Using @Produces to to inject an enum in CDI.<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_13_total_'>/**
 * @author &lt;a href=&quot;mailto:lincolnbaxter@gmail.com&quot;&gt;Lincoln Baxter, III&lt;/a&gt;
 */
public class InjectedObject
{
   private MyEnum e;

   @Inject
   public InjectedObject(MyEnum e)
   {
      this.e = e;
   }

   public MyEnum getValue()
   {
      return e;
   }

   /**
    * A producer is required in order to {@link Inject} an Enum
    */
   @Produces
   public static MyEnum getEnum()
   {
      return MyEnum.THREE;
   }

   /**
    * Our enum
    */
   public enum MyEnum
   {
      ONE, TWO, THREE
   }

}</pre></div>

<p>And there you have it! A perfectly functional method of injecting enum values in CDI. You will, however, need to make sure you know which type of enum you want to inject, and if you need multiple types, then you&#8217;ll need to create qualifiers for each value. 

<h3>You could also use the built-in @Named qualifier</h3>

<p>The <code>@Named</code> qualifier is a built in qualifying type that allows unique qualifiers to be created using String values.

<div class='snippit'><div class='snippit-filename'>Using the @Named qualifier to inject arbitrary values of the same type<div class='clearer'></div></div><pre class='prettyprint' id='code_snippit_14_total_'>/**
 * @author &lt;a href=&quot;mailto:lincolnbaxter@gmail.com&quot;&gt;Lincoln Baxter, III&lt;/a&gt;
 */
public class InjectedObject
{
   private MyEnum e1;
   private MyEnum e2;

   @Inject
   public InjectedObject(@Named(&quot;ONE&quot;) MyEnum e1, @Named(&quot;TWO&quot;) MyEnum e2)
   {
      this.e1 = e1;
      this.e2 = e2;
   }

   public MyEnum getValue1()
   {
      return e1;
   }

   public MyEnum getValue2()
   {
      return e2;
   }

   /**
    * A producer is required in order to {@link Inject} an Enum
    */
   @Produces
   @Named(&quot;ONE&quot;)
   public static MyEnum getEnumOne()
   {
      return MyEnum.ONE;
   }

   @Produces
   @Named(&quot;TWO&quot;)
   public static MyEnum getEnumTwo()
   {
      return MyEnum.TWO;
   }

   /**
    * Our enum
    */
   public enum MyEnum
   {
      ONE, TWO, THREE
   }

}</pre></div>

<p>We would not, however, be able to <code>@Inject @Named("THREE") MyEnum e</code> because we have not declared a producer with such a qualifier!<a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/java/how-to-inject-enum-values-into-cdi-beans/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New tutorial: Regular expressions</title>
		<link>http://ocpsoft.org/opensource/new-tutorial-regular-expressions/</link>
		<comments>http://ocpsoft.org/opensource/new-tutorial-regular-expressions/#comments</comments>
		<pubDate>Tue, 18 Sep 2012 18:21:47 +0000</pubDate>
		<dc:creator>Lincoln Baxter III</dc:creator>
				<category><![CDATA[OpenSource]]></category>

		<guid isPermaLink="false">http://ocpsoft.org/?p=4996</guid>
		<description><![CDATA[Do you love regular expressions as much as I do? Well even if you don&#8217;t, I am pleased to announce a new tutorial: &#8220;OCPsoft&#8217;s guide to Regular Expressions.&#8221; As part of an ongoing initiative to promote awareness of regular expressions, and how they are used both as a general technology, but also specifically as applied [...]]]></description>
				<content:encoded><![CDATA[<img src="http://ocpsoft.org/wp-content/uploads/2012/09/IMG_20120918_002559-300x212.jpg?1628ff" alt="" title="IMG_20120918_002559" width="300" height="212" class="pull-right" style="margin-left: 15px; margin-bottom: 15px;" /><p>Do you love regular expressions as much as I do?

<p>Well even if you don&#8217;t, I am pleased to announce a new tutorial: &#8220;OCPsoft&#8217;s guide to <a href='http://ocpsoft.org/tutorials/regular-expressions/'>Regular Expressions</a>.&#8221; As part of an ongoing initiative to promote awareness of regular expressions, and how they are used both as a general technology, but also specifically as applied to the Java programming language, we will be continuing to add new example-based guides to this course.

<p>Please feel free to post questions and comments if there are topics or specific problems that you would like to see addressed. We will do our best to answer your questions and share the knowledge!

<p>Check out <a href='http://ocpsoft.org/tutorials/regular-expressions/'>the tutorial</a>.

<p>Enjoy!<br/>
~Lincoln<a name="lincoln"></a><div class="author">

<img class="author-photo" src="http://ocpsoft.com/wp-content/uploads/2012/02/IMG_8886_modified1.jpg" alt="Lincoln Baxter, III" title="Lincoln Baxter, III" />

<h3>About the author:</h3>
<p><a href="http://twitter.com/lincolnthree" target="_blank"> Lincoln Baxter, III</a> is a Senior Software Engineer at <a href="http://redhat.com" target="_blank">Red Hat</a>, working on <a href="http://jboss.org" target="_blank">JBoss</a> open-source projects; most notably as project lead for <a href="http://jboss.org/forge">JBoss Forge</a>. This blog represents his personal thoughts and perspectives, not necessarily those of his employer.</p>

<p>He is a founder of <a href="http://twitter.com/ocpsoft" target="_blank" title="Simple Software">OCPsoft</a>, the author of <a href="http://ocpsoft.org/prettyfaces/"  title="URLRewriteFilter | Java | JSF | JSF2 | Pretty URL | REST">PrettyFaces</a> and <a href="http://ocpsoft.org/rewrite/" title="URLRewriteFilter | Java | Servlet | Pretty URL | REST">Rewrite</a>, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also the author of <a href="http://ocpsoft.org/prettytime/"  title="Java Timestamp | Format | Elapsed | Social Time">PrettyTime</a>, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals.</p>

</div>        ]]></content:encoded>
			<wfw:commentRss>http://ocpsoft.org/opensource/new-tutorial-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic
Database Caching 8/27 queries in 0.087 seconds using disk: basic
Object Caching 37249/37304 objects using disk: basic

 Served from: ocpsoft.org @ 2013-05-24 11:17:33 by W3 Total Cache -->