我有一个Grails Domain类,在保存到数据库之前,该类具有一些必需的预处理。此预处理是通过Grails服务方法完成的。
我们的Grails服务方法都受到必需的用户角色和Spring Security Service的保护。
我想从BootStrapDevelopment中预填充很多这些Domain类。
但是,我无法调用Service方法,因为BootStrapDevelopment没有所需的角色。
我已经搜索过,但是找不到如何强制BootStrapDevelopment使用特定角色。
任何帮助将非常感激。
谢谢。
请您参考如下方法:
创建特定的管理员用户并关联角色。然后将您的插入内容包装在SpringSecurityUtils.doWithAuth()中。对于您在闭包内部执行的所有操作,这将认为admin用户已通过身份验证。示例(不完整):
class BootStrapDevelopment {
def init = {
//after creating the user...
SpringSecurityUtils.doWithAuth("USERNAME") {
//create and save domains...
MyDomain myDomain = new MyDomain()
}
}
}




