Thursday, June 23, 2011

Implementing account creation in Apache Rave

Apache Rave ( is an Apache Incubator project to build a Web portal and services on top of Google's OpenSocial and W3C's Widget specifications.  We're writing Rave from scratch using the Spring (version 3) framework.  These are notes on adding a basic user registration feature. The code described below is open source and will soon be in Rave's SVN.  I'll assume general familiarity with Spring.  If not, check out Rave's source code and walk through it.  The notes below will tell you were to look, but I won't include all the code.

Rave's user management is built around the following classes:

  1. User:  this is a data model class that represents a user (name, password, etc).  Spring (and JPA) manage the object-relational mappings between User objects and the relational database storage.
  2. UserService:  this is an interface that allows you to interact with the User data model.
  3. UserRepository: this is an interface that allows you to interact with the backend database. We use JPA for object-relational mapping.
  4. DefaultUserService: this implements the UserService interface and interacts with the UserRepository (and thus the JpaUserRepository).
  5. JpaUserRepository:  this implements the UserRepository interface and provides access to the javax.persistence.EntityManager, which handles the database persistence.
There are similar classes and interfaces for Rave's widget, page, and region data models.  Spring of course handles all the dependency injection (makes sure DefaultUserService has an instance of the UserRepository implementation, for example).  JPA takes care of the crud.

We'll now need to implement two pieces of code: an account registration form (newaccount.jsp) and a Spring controller class to intercept our form actions (  The registration form and associated action URL both need to be accessed by unauthenticated users, so we modify Rave's applicationContext-security.xml file accordingly (see Rave code for full example).

NewAccountController needs to do three things: get access to the UserService implementation (Spring injects this), create a new User object, and use the UserService to insert the new User object into the repository.  Once a user is registered, NewAccountController redirects to the login page.

This is pretty basic functionality, and there's a lot left to do. As an Apache Software Foundation incubator project, Rave is not only open source but community driven.  If you want to participate, checkout the code from SVN, create an account on Rave's Jira system (, create issues and submit patches.  Frequent contributors can become full project members.  

No comments: