Grails Spring Security Core Plugin - 添加Flash消息到登录页面 [英] Grails Spring Security Core Plugin - adding flash message to login page

查看:111
本文介绍了Grails Spring Security Core Plugin - 添加Flash消息到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

  @Secured([ 'IS_AUTHENTICATED_REMEMBERED'])

如果用户没有登录,这会导致操作重定向到我的登录页面一旦他们登录,他们就会被重定向到原来的行为。



在这种情况下,如何向登录页面添加flash消息,即

  flash.message =您必须登录才能提交新闻报道

为了澄清,我只希望在尝试访问此特定操作后用户被重定向到登录页面时显示消息。其他操作不会触发该消息。

解决方案




  1. 从动作中远程注释

  2. 在动作开始处添加以下代码(新闻并提交相关内容
    $ b

      if(!springSecurityService.isLoggedIn()){
    flash.message =You必须登录才能提交新闻报道。
    重定向(controller:login,action:auth,params:[spring-security-redirect:/ news / submit])
    }



    $ li $ <$ p $> < input type ='hidden'name ='spring-security-redirect'value ='$ {params ['spring-security-redirect']}'/>



I am using the Grails Spring Security Core Plugin to secure a certain action using the following annotation.

@Secured(['IS_AUTHENTICATED_REMEMBERED'])

This causes the action to redirect to my login page if the user is not logged in. Once they are logged in they are then redirected to the original action.

How can I add a flash message to the login page in this scenario, i.e.

flash.message = "You must be logged in to submit a news story"

To clarify, I would only want the message to be displayed if the user was redirected to the login page after attempting to access this specific action. Other actions would not trigger the message.

解决方案

I have solved this as follows.

  1. Remote the annotation from the action.
  2. Add the following code at the beginning of the action (news and submit being the relevant controller and action respectively).

    if (!springSecurityService.isLoggedIn()) {
        flash.message = "You must be logged in to submit a news story."
        redirect(controller:"login", action: "auth", params:["spring-security-redirect" : "/news/submit"])
    }
    

  3. Add the following to the login form.

    <input type='hidden' name='spring-security-redirect' value='${params['spring-security-redirect']}'/>
    

这篇关于Grails Spring Security Core Plugin - 添加Flash消息到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆