Skip to main content

How to integrate Spring Security in Grails

Points To Remember

Go to the Grails Spring Security Plugin and add the dependency in the BuildConfig.

Integrate Spring Security in Grails

Add the latest grails spring security plugin in the build config of the project. This will add spring security jars and classes that will be used to configure spring security in the project.
http://grails.org/plugin/spring-security-core
Now run the following command from the terminal.
grails s2-quickstart com.ekiras User Role
Here the syntax of the above command is
grails s2-quickstart {package} {user domain} {authority domain}
The above command will create three Domains in the project User, Role and UserRole. user domain will contain the user info, role domain will contain Authorities and UserRole will contain the user authority mappings.
It will also add the following settings to the Config.groovy

// Added by the Spring Security Core plugin:
grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.ekiras.User'
grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'com.ekiras.UserRole'
grails.plugin.springsecurity.authority.className = 'com.ekiras.Role'
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/': ['permitAll'],
'/index': ['permitAll'],
'/index.gsp': ['permitAll'],
'/assets/**': ['permitAll'],
'/**/js/**': ['permitAll'],
'/**/css/**': ['permitAll'],
'/**/images/**': ['permitAll'],
'/**/favicon.ico': ['permitAll']
]
It tells that the userDomain class authority class and user-authority join class. For other settings of the Spring security you can open the file DefaultSecurityConfig.groovy .

See the Default Password Encoders and Custom Password Encoders in Grails Spring Security.

Comments