Spring Security with Grails to secure Grails controller
Let's apply Spring Security to Grails controller. The scenario is that the user will access the Grails application and will be provided with a link to log in. On successful authentication, the user will be provided with links which he can access. The links are visible only to the logged in user.
Getting ready
For demonstration purposes we will create the following:
A simple Grails controller:
myfirstapp
A
MyFirstController
controller which will be secured with Spring SecurityModify
index.gsp
How to do it…
The following steps are taken for integrating Spring Security with Grails to secure Grails Controller:
Go to
myfirstapp\grails-app\views
.You will see the
index.gsp
file, rename it toindex.gsp_backup
. I have copied the styles fromindex.gsp_backup
.Create a new
index.gsp
file, edit the file as shown:<!DOCTYPE html> <html> <head> </head> <body> <h1>Welcome to Grails</h1> <sec:ifLoggedIn...