Spring MVC along with Spring Security 3.1 maven archetype

In a previous post I posted an article on a Spring MVC (with Apache Tiles) maven archetype project and I explained how to initiate such a Maven project using the supplied archetype.

In this post, I come with a new archetype that allows you initiate, via a single command line, a maven web project that is configured to use Spring MVC 3.1.4 along with Spring Security. Knowing how it can be sometimes painful to configure such a project and to overcome dependencies issues (version conflicts, missing dependencies issues and configuration issues), I wanted to share that with you.

The project is configured to use:

  • Spring MVC 3.1.4
  • Spring Security 3.1.4
  • Apache Tiles 2.2.2
  • Servlets API 2.5 (as provided)
  • jstl 1.2

The project comes up with the following configuration:

  1. Spring MVC is configured to Intercept /spring context requests: locate the file spring-servlet.xml
  2. Spring security is configured with two users, a regular user role user and an admin role user: locate the file spring-security.xml, it contains the two users logins and passwords
  3. (JSP) Tiles pages (view parts) are in the WEB-INF/jsp: users folder contains user role jsp pages and admin folder contains admin role jsp pages
  4. As examples, two servlets are pre-configured for each of the two users: the AdminPage1Controller.java and the Page1Controller.java
  5. The sidebar menu.jsp contains an example on how to filter content so that some content is only displayed when admin is connected

In order to use the archetype to initiate such a new maven project:

  1. Download the archetype maven project here and install it to your local repository using the following command
    mvn install:install-file -Dfile=springmvc3.1-security-archetype-1.0.0.jar -DgroupId=com.michir.projects -DartifactId=springmvc3.1-security-archetype -Dversion=1.0.0 -Dpackaging=jar -DgeneratePom=true [-DlocalRepositoryPath=[path to your local repository]]
    
  2. Once installed, generate your Spring MVC – Security project using the following maven command
    mvn archetype:generate -DarchetypeGroupId=com.michir.projects -DarchetypeArtifactId=springmvc3.1-security-archetype -DarchetypeVersion=1.0.0 -DgroupId=com.mycompany -DartifactId=myproject -Dversion=1.0.0-SNAPSHOT
    

It’s done … import your project into your favorite IDE as a maven project, compile and install on your favorite Web Application server and enjoy!

Advertisements

2 thoughts on “Spring MVC along with Spring Security 3.1 maven archetype”

    1. Hi,
      Sorry for this late response …
      Yes you can integrate Spring Security within you Apache tiles application as Spring Security relies on Java EE web Filters, configured in the web.xml file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s