【发布时间】:2016-12-22 17:24:07
【问题描述】:
我在我的 Grails 应用程序中使用 spring-security-core:2.0.0。但即使在成功验证后,页面也会显示一条消息“对不起,您无权查看此页面。”我以 ROLE_ADMIN 登录,我想根据角色重定向到两个页面。对于管理员角色,我需要进入管理页面,对于用户角色,我需要进入用户页面。
这是我的 UrlMappings.groovy
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
/* get "/"(controller:"book", action:"index")
get "/books/create"(controller:"book", action:"create")
post "/books"(controller:"book", action:"save")
get "/books/$id"(controller:"book", action:"show")
get "/books/$id/edit"(controller:"book", action:"edit")
put "/books/$id"(controller:"book", action:"update")
delete "/books/$id"(controller:"book", action:"delete")
*/
"/"(view:'auth',controller:'login')
"/admin"(view:'adminPage')
"500"(view:'/error')
}
}
LoginController.groovy
package com.standout.utilityapplication
import grails.plugin.springsecurity.annotation.Secured
class LoginController {
def springSecurityService
@Secured(['ROLE_ADMIN', 'ROLE_USER'])
def index() {
println "INDEX PAGE RENDER FROM MY CONTROLLER";
def roles = springSecurityService.getPrincipal().getAuthorities()
println roles;
if(roles.toString().contains("ROLE_ADMIN"))
{
println "admin"
redirect(uri: "/admin")
}
else
{
println "not admin"
redirect(uri: "/dataentry")
}
}
@Secured('ROLE_USER')
def nonadmin()
{
println("===notadmin")
}
@Secured('ROLE_ADMIN')
def admin()
{
println("====admin")
}
}
【问题讨论】:
标签: grails