Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring security核心grails未登录_Grails_Spring Security - Fatal编程技术网

spring security核心grails未登录

spring security核心grails未登录,grails,spring-security,Grails,Spring Security,安装了SpringSecurityCore作为插件,然后进行了quickstart 这是我的用户域类 package auth class User { def springSecurityService String username String password boolean enabled boolean accountExpired boolean accountLocked boolean passwordExpired static

安装了SpringSecurityCore作为插件,然后进行了quickstart

这是我的用户域类

package auth
class User {
   def springSecurityService
   String username
   String password
   boolean enabled
   boolean accountExpired
   boolean accountLocked
   boolean passwordExpired
   static mapping = {
          // password is a keyword in some sql dialects, so quote with backticks
          // password is stored as 44-char base64 hashed value
       password column: '`password`', length: 64
   }
   static constraints = {
       username blank: false, size: 1..50, unique: true
       password blank: false, size: 8..100
   }


   Set getAuthorities() {
      UserRole.findAllByUser(this).collect { it.role } as Set
   }

   def beforeInsert() {
     encodePassword()
   }

   def beforeUpdate() {
      if (isDirty('password')) {
        encodePassword()
      }
   }

   protected encodePassword() {
        password = springSecurityService.encodePassword(password, username)
   }
}
还有我的胸带,groovy是

class BootStrap {

  def init = { servletContext ->

    auth.User james = new auth.User(username: 'test', enabled: true, password: 'password')
    james.save()
    if (james.hasErrors())
    {
        println("he has errors")
    }


    println("we made it! ")
}

   def destroy = {
   }
}

但当我登录时,它总是说“对不起,我们找不到使用该用户名和密码的用户”。有什么想法吗?

您能验证该用户是否已实际引导到数据库中吗

如果是这样的话,我就遇到了类似的问题,Tomcat错误地缓存了一些数据

以下是我所做的:

  • 阻止雄猫
  • 删除了Tomcat临时目录中的所有文件
  • 重新启动的雄猫
  • 在那之后,它工作得很好


    让我知道这是否有用。

    另外,我已经有一段时间没有从头构建Grails站点了,但我想我记得一些在线说明存在问题。SpringSecurity可能正在为您编码密码,因此当您这样做时,它将被双重编码

    尝试删除对密码进行编码的行

    password = springSecurityService.encodePassword(password, username)
    

    这是因为您在对密码进行编码时正在使用

    password = springSecurityService.encodePassword(password, username)
    
    我不知道如何加盐,因此不能给你太多的指导

    但是,如果您对密码进行编码时没有添加盐分,那么您的代码就可以工作,只需在编码密码时删除用户名即可,请尝试以下操作

    password = springSecurityService.encodePassword(password)
    

    希望这能有所帮助。

    如果您在
    BootStrap.groovy
    中创建用户,请尝试更改:

    def adminUser = User.findByUsername('admin') ?: new User(
        username: 'admin',
        password: springSecurityService.encodePassword('admin'),
        enabled: true).save(failOnError: true)
    
    为此:

    def adminUser = User.findByUsername('admin') ?: new User(
        username: 'admin',
        password: 'admin',
        enabled: true).save(failOnError: true)
    

    问题是您使用了两次编码密码,一次在域中,一次在构造函数的参数中。

    所以我使用intellij和tomcat插件。还使用内存中的数据库。这仅仅是删除和添加tomcat插件吗?不,我不这么认为。但是,另一个人问了一个类似的问题,说清理项目有帮助:尝试了这个,得到了同样的结果:(