Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize Grails Spring Security Core 2 login / logout controller and views?

I am using the new Grails Spring Security Core 2.0 plugin and am wondering how i can customize the login view and the LoginController/LogoutController?

The previous versions of the plugin generated these files but now it seems that I have to copy them from the plugin to my project. Is this the correct approach?

And if so, can I put the copied controllers and views into another package then the original ones. IntelliJ seems to dislike having the same artifacts in the same package.

like image 539
Marco Avatar asked Nov 15 '13 13:11

Marco


3 Answers

Another option would be to use a remote link which by default uses the "post" method

    <g:remoteLink class="logout" controller="logout">${message(code: 'springSecurity.logout.link')}</g:remoteLink>
like image 21
luismy Avatar answered Nov 12 '22 22:11

luismy


By default in version 2.0 logouts are only allowed via POST requests. To change this to allow GET requests add the following to your Config.groovy file.

grails.plugin.springsecurity.logout.postOnly = false

Once you have that set you can link directly to logout controller in order to logout

<g:link controller="logout">logout</g:link>

If you want to find more info on what else was changed in version 2 look to the What's New in Version 2.0 documentation

like image 106
lIllII Avatar answered Nov 12 '22 21:11

lIllII


I don't think any of the above answers actually answer the question.

If you want to override the controllers and the views in your web-app then yes copy them up into your web-app. You can even give them a different package hierarchy if you wish as the spring-security-core plugin seems to reference them by URL and yours would replace them.

This works because controllers and views declared in the main web-app take precedence over those that are in the plugins.

However if you are doing this in another plugin thats when things get a bit tricky. See this questiona and answer for a solution to that problem

like image 41
DJOodle Avatar answered Nov 12 '22 23:11

DJOodle