2014-06-20 44 views
3

我收到以下錯誤給予只能訪問用戶與權限USER_ROLE

Class 
org.springframework.expression.spel.SpelEvaluationException 
Message 
EL1008E:(pos 0): Field or property 'ADMIN_ROLE' cannot be found on object of type 'org.springframework.security.web.access.expression.WebSecurityExpressionRoot' 

我試圖訪問視圖My.GSP,我登錄的USER_ROLE

-

import org.springframework.dao.DataIntegrityViolationException 
import grails.plugin.springsecurity.annotation.Secured 

class MyController { 

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"] 

    @Secured(['ADMIN_ROLE','USER_ROLE']) 
    def index() { 
     redirect(action: "list", params: params) 
    } 
    @Secured(['USER_ROLE']) 
    def list(Integer max) { 
     params.max = Math.min(max ?: 10, 100) 
     [patientInstanceList: Patient.list(params), patientInstanceTotal: Patient.count()] 
    } 
    @Secured(['USER_ROLE']) 
    def create() { 
     [patientInstance: new Patient(params)] 
    } 
    @Secured(['USER_ROLE']) 
    def save() { 
     def patientInstance = new Patient(params) 
     if (!patientInstance.save(flush: true)) { 
      render(view: "create", model: [patientInstance: patientInstance]) 
      return 
     } 

     flash.message = message(code: 'default.created.message', args: [message(code: 'patient.label', default: 'Patient'), patientInstance.id]) 
     redirect(action: "show", id: patientInstance.id) 
    } 

DB

enter image description here

enter image description here

+0

您是否100%確定ADMIN_ROLE已正確創建? –

+0

我編輯了我的帖子。我包含了我的數據庫的屏幕截圖 – Illep

回答

5

隨着Grails的角色名春季安全插件的默認設置必須以前綴"ROLE_",所以重命名ADMIN_ROLEROLE_ADMINUSER_ROLEROLE_USER

This forum post解釋了默認情況下它的工作原理,以及如何根據需要對其進行不同配置。

相關問題