Spring中的spring security core断言错误

时间:2014-01-10 05:20:08

标签: spring grails

我收到以下错误

   Error 2014-01-10 10:35:26,420 [localhost-startStop-1] ERROR context.GrailsContextLoader  -           Error initializing the application: Assertion failed: 

   assert SecUserSecRole.count() == 1
                  |       |
                  0       false

   Message: Assertion failed: 

   assert SecUserSecRole.count() == 1
                  |       |
                  0       false

以下是我的BootStrap类::

class BootStrap {

def springSecurityService
def init = { servletContext ->

    //def userRole= SecRole.findByAuthority("ROLE_USER") ?: new SecRole(authority : "ROLE_USER").save()
    //def adminRole= SecRole.findByAuthority("ROLE_ADMIN") ?: new SecRole(authority : "ROLE_ADMIN").save()
    def adminRole = new SecRole(authority: 'ROLE_ADMIN').save(flush: true)
    def userRole = new SecRole(authority: 'ROLE_USER').save(flush: true)

//  def testUser = new SecUser(username: username, enabled: true, password: springSecurityService.encodePassword("password"))
/// testUser.save(flush: true)

    //SecUserSecRole.create testUser, adminRole, true
    def testUser = new SecUser(username: 'admin', enabled: true, password: 'admin')
    testUser.save(flush: true)

    SecUserSecRole.create testUser, adminRole, true

    assert SecUser.count() == 1
    assert SecRole.count() == 2
    assert SecUserSecRole.count() == 1
}
def destroy = {
 }
}

Plz帮助

0 个答案:

没有答案