如何在使用 spring 安全核心插件登录 Grails 后重定向到页面

How to redirect to a page after login in Grails using spring security core plugin

我正在使用 Grails 2.1.1 和 spring-security-core 1.2.3.7。当我 运行 显示应用程序登录页面时,因为我已经显示了来自 url 映射的登录页面。但是当我登录时,它并没有重定向到主页。它停留在登录页面上。

这是我的 url 映射:

static mappings = {
    "/$controller/$action?/$id?"{
        constraints {
            // apply constraints here
        }
    }

    "/"(view:"/login/auth")
    "500"(view:'/error')
}

您可以像这样在 config.groovy 文件中输入默认成功 url

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

将所需的 controller / action 添加到您的 url 映射:

static mappings = {
    "/$controller/$action?/$id?"{
        constraints {
            // apply constraints here
        }
    }

    "/"(controller:"yourcontroller", action: "youraction)
    "500"(view:'/error')
}

如果 yourcontroller 中的 youraction 以任何方式受到保护,spring 安全将管理重定向到 auth 页面并在之后返回 youraction认证成功。