因此,我剛開始學習Grails,我試圖將Spring Security REST插件合併到我的應用程序中,除了彈簧安全內核正在工作之外,還安裝了插件。在我的REST客戶端中,當我點擊「api/login」時,我能夠獲得一個訪問令牌,它說我有角色「ROLE_ADMIN」,但是當我嘗試使用它時,我一直得到403 Forbidden 。在郵遞員,我使用的REST客戶端,我有我的授權標題「承載{key}」,我的網址是「http://localhost:8080/test/api/secret」,它給出了403錯誤。我正在嘗試設置log4j日誌記錄來查看其他任何問題,但是有誰知道我應該查看哪些內容,對此將不勝感激。我在下面提供了我的類,如果這有幫助的話,我通常使用默認值,例如UrlMappings。Grails Spring Security Rest - 403 Forbidden
RandomController.groovy
package test
import grails.plugin.springsecurity.annotation.Secured
@Secured(['IS_AUTHENTICATED_ANONYMOUSLY'])
class MyController {
@Secured(['ROLE_ADMIN'])
def secret() {
render "You have ACCESS!!!"
}
}
BootStrap.groovy中
class BootStrap {
def init = { servletContext ->
def adminRole = new SecRole(authority: 'ROLE_ADMIN').save(flush: true)
def testUser = new SecUser(username: 'bob', password: 'test')
testUser.save(flush: true)
SecUserSecRole.create testUser, adminRole, true
}
def destroy = {
}
}
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/$controller/$action?/$id?(.$format)?"{
constraints {
// apply constraints here
}
}
"/api/$controller/$action?/$id?(.$format)?"{ constraints { // apply constraints here
} }
"/"(view:"/index")
"500"(view:'/error')
}
}