我可以创建两种不同类型的secuser,例如secuser和enduser,SecRole和EndRole
将为我的医院的管理员和医生以及最终用户提供我的安全和 secret 服务,将为我的医院项目的最终用户提供我的安全和 secret 服务
我有secuser和secrole表,但是当我使用s2-quickstart命令创建enduser和endrole时,便能够获取域类,而我没有覆盖我的登录和注销 Controller ,现在无法在其中创建最终用户对象endrole对象我的行李箱带
class BootStrap {
def springSecurityService
def init = { servletContext ->
/*
def userRole = EndRole.findByAuthority('ROLE_USER') ?: new EndRole(authority: 'ROLE_USER').save(failOnError: true)
def endadminUser = EndUser.findByUsername('endadmin') ?: new EndUser(
username: 'endadmin',
password:'endadmin',enabled: true).save(failOnError: true)
if (!endadminUser.authorities.contains(userRole)) {
EndUserEndRole.create endadminUser, userRole
}
*/
def x= new EndRole(authority: 'ROLE_USER')
println(" new fresh "+x.authority)
}
def destroy = {
}
}
最佳答案
您可以根据需要拥有任意数量的用户,但是要支持该用户,您将需要一个自定义UserDetailsService
。这是很常见的事情,因此在文档中有一节专门针对它。请参阅http://grails-plugins.github.com/grails-spring-security-core/docs/manual/中的“11自定义UserDetailsService”部分
我不确定您为什么认为您需要多个角色类。只需为管理员和医生创建一个具有不同角色名称的SecRole
实例,例如new SecRole(authority: 'ROLE_DOCTOR').save()
,new SecRole(authority: 'ROLE_ADMIN').save()
。
您可能根本不需要其他用户类(至少出于安全性考虑-出于非安全性原因,您可能需要支持不同的属性)。只需创建SecUser
实例并授予它们所需的任何角色(使用EndUserEndRole.create
),即ROLE_DOCTOR或ROLE_ADMIN。
帮自己一个忙,阅读插件文档,以及http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity.html上的Spring Security文档-如果您不满意如何保护网站的安全性,那么这些东西对于实现来说太重要了。
关于grails - Grails Spring Security SecUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014278/