Facebook Connect Login with Spring Security

Kadir Pekel already described a procedure to integrate Facebook Connect in a blog entry. So just a quick summary on my experiences:

Dependency on Facebook Java API

Add a dependency to the Facebook Java API. Easy done with Maven:

Spring Security Facebook

Download the code for spring-security-facebook and either integrate that into your project or build it into an own jar.

Spring Config and HTML

The only missing thing is to configure the Facebook Security code in the Spring configuration files and the according HTML code.

  • Adjust the Spring Config to have an additional authentication provider.
  • The Facebook On-Login function must redirect to the configured authentication URL, e.g. /j_spring_security_facebook.

Details on adding these things can be found in my description on Multiple Authentication Providers.

How to: Spring Webflow 2 and Spring Security 3

There have been recent discussions in the Spring Framework group to make Spring Security 3 working with Spring Webflow 2. Enabling it is quite easy when working with Maven, however due to refactoring not all Spring Webflow classes are working (or actually resulting in a ClassNotFoundException).

Add dependency of Spring Webflow and Spring Security with Maven

And the following dependencies (in addition to the spring framework dependencies or whatever you require):

Setup Spring Security

Setup Spring Security as you would set it up usually. For example start with something like this:

Webflow setup and custom class

Your webflow setup might be similar to the following:

And exactly this securityFlowExecutionListener is the problem, as it will run into a runtime error due to classes that could not be found. So the solution for that is quite simple. First define the securityFlowExecutionListener as a reference to a custom bean:

The easiest is to copy the class org.springframework.webflow.security.SecurityFlowExecutionListener and adjust it accordingly so it compiles. For example, take the version from the Spring Jira Issue.