best grammar app

Grails MongoDB Spring Security Getting Started

Submitted by Abhishek on Tue, 2013-09-17 17:38
mongodb.org/grails.org

I ran into issues getting my grails project setup for use with MongoDB and Spring Security for a Rules and BPM project - NumaHub. There are few articles (like this one from ET) which talk about it, and helped me get started with the exercise (as well as the article). But I kept on running into issues again and again. Finally I was able to get that up and running. I am sharing what I did and hope it is helpful for everyone.

For this article, I am using Spring Source Tools Suite. However, it should work well with command line Grails as well. If you are running from command line, do add “grails” before each issued command.

Step 1: Create a New Project

To create a new project, I started with

File -> New -> Grails Project

image

Added the name – NumaHub and hit 'Finish'.

Step 2: Install Plugin MongoDb

Then I installed MongoDB plugin:

install-plugin mongodb

A confirmation(see the screenshot below) was displayed, after the successful installation:

Loading Grails 2.2.3
| Environment set to development.....
| Warning The install-plugin command is deprecated and may be removed from a future
version of Grails.Plugin dependencies should be expressed in 
grails-app/conf/BuildConfig.groovy.
See http://grails.org/doc/2.2.x/guide/conf.html#pluginDependencies.
| Resolving plugin mongodb. Please wait...
| Installing zip mongodb-1.3.0.zip.....
| Installed plugin mongodb-1.3.0.....
| Plugin installed.

Step 3: Uninstall Plugin Hibernate

As I wanted to use only MongoDb, I got rid of Hibernate using the command given below:

uninstall-plugin hibernate

A confirmation was displayed:

Loading Grails 2.2.3
| Environment set to development.....
| Uninstalled plugin [hibernate]

Also, to remove it from your BuildConfig.groovy, I commented the line below the plugins:

        // runtime":hibernate:$grailsVersion"

Step 4: Install Plugin Spring Security Core

To install Spring Security, issue the command as given below:

install-plugin spring-security-core

Step 5: Run the QuickStart Command

I ran the s2-quickstart command to setup my Users and Roles:

s2-quickstart com.numahub User Role

This created the User and Role classes that I needed.

Step 6: Configure the User, Role and UserRole class

The Classes needed some changes, especially around how MongoDB handles Identities. Grails automatically assigns identities which are integer values, however a normal insert in MongoDB creates it as a BSON Object.

To make it work, I added object id into all out classes:

ObjectId id

Here are the three classes I created:

packagecom.numahub

importorg.bson.types.ObjectId;

class Role {
	ObjectIdid
	String authority

	staticmapping = {
		cachetrue
	}

	staticconstraints = {
		authority blank: false, unique: true
	}
}
packagecom.numahub

importorg.apache.commons.lang.builder.HashCodeBuilder
importorg.bson.types.ObjectId;

classUserRole implements Serializable {
	ObjectId id
	User user
…..

For the User class, I added a few more fields – Email, FirstName and LastName.


Abhishek Mishra
Good experience in working with BPM technologies like Savvion, JBPM. Founder and Chief Editor of BPMGeek.com. Founder of Savvion Business Manager Mobility Framework Savmobify| View my BPMGeek Profile
|
best grammar app

About BPMGeek

BPMGeek is an initiative to collaborate and communicate with the growing Business process management community out there. The goal is to help developers connect with experts, ask questions, post their learning and get understanding of BPM Concepts. Often tool specific knowledge of niche areas end up developers perplexed and confused - especially when there are very less number of resources available. We will be coming up several several new features. Have a look at our Roadmap here

BPMGeek is an independent entity not associated with any Product. All BPM product professionals are invited to contribute. The Logos and Names used across the site belong to their respective owners. The viewpoints mentioned by Individual contributors are their own. BPMgeek cannot be held liable for any issues arising out of it.


BPMgeek is promoting the Nounshoun English Grammar App - developed by Constellation Software.