Grails Spring Security: redirect after login success/failure

南笙酒味 提交于 2019-11-28 18:25:40
Burt Beckwith

You're basically describing how it currently works except for re-displaying login details, which is straightforward.

When you click a secured link and aren't logged in, a SavedRequest is stored in the session to keep track of where you were trying to go. After a successful login, this object is inspected and the redirect is built from it. If you go directly to the login page there's no saved info, so it redirects to a default location. By default it's the root of the app ('/') but it's configurable, e.g.

grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/home'

To get the previously entered login name to re-display, use the SPRING_SECURITY_LAST_USERNAME session key in auth.gsp:

<input type='text' class='text_' name='j_username' id='username'
       value="${session['SPRING_SECURITY_LAST_USERNAME']}" />

What worked for me is putting the following line in Config.groovy

grails.plugin.springsecurity.successHandler.defaultTargetUrl = 'controllerName/actionName'

The thing that is changed is grails.plugin not grails.plugins (notice no 's' after 'plugin')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!