Grailsアプリケーションでspring-security-core:2.0.0を使用しています。しかし、認証に成功した後でも、「このページを表示する権限がありません」というメッセージがページに表示されます。私はROLE_ADMINとしてログインしました。役割に応じて2つのページにリダイレクトしたいと思います。管理者の役割のために私は管理ページに行き、ユーザー役割のためには私はユーザーページに行きたいと思う。ここでspring-security-coreの認証の問題:2.0.0
は私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")
}
}