#grails #spring-security
#grails #spring-безопасность
Вопрос:
Я получаю следующую ошибку
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
Комментарии:
1. Вы на 100% уверены, что ADMIN_ROLE была создана правильно?
2. Я отредактировал свой пост. Я включил скриншот моей базы данных
Ответ №1:
С настройками по умолчанию плагина Spring security в Grails имена ролей должны начинаться с префикса "ROLE_"
, поэтому переименуйте свой ADMIN_ROLE
в ROLE_ADMIN
и USER_ROLE
в ROLE_USER
.
В этом сообщении на форуме объясняется, почему это работает так по умолчанию, и как вы можете настроить его по-другому, если требуется.