抱歉,我们无法找到具有该用户名和密码的用户。 (Grails-Spring安全核心) [英] Sorry, we were not able to find a user with that username and password. (Grails-Spring Security Core)

查看:209
本文介绍了抱歉,我们无法找到具有该用户名和密码的用户。 (Grails-Spring安全核心)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Grails新手,尝试使用Spring Security Core插件为用​​户分配角色。我为我的项目调用了MyProject。

在为我的模型生成控制器和视图后,在 Config.groovy ,我已经设置了必要的登录以访问/ userMyProject /:

  grails.plugin.springsecurity.controllerAnnotations.staticRules = [
'/ userMyProject / **':['ROLE_ADMIN']
]



<然后在 BootStrap.groovy 中自动创建一些用户和角色:

  def init = {servletContext  - > 
def role1 = new Role();
role1.setAuthority(ROLE_ADMIN)
role1.save();

def user1 = new UserMyProject();
// ...分配名称,用户名,密码...
user1.save();

new UserMyProjectRole(userCwitter:user1,role:role1).save();
}

但是当我进入我的 UserMyProjectController 页面,它正确地打开登录页面,但总是大声抱歉,我们无法找到具有该用户名和密码的用户。当我能够在我的数据库中看到它时。

感谢您的帮助。

解决方案



  // ...分配姓名,用户名,密码... 

您是否在编码密码(1.2版之前)?

  def springSecurityService 
...
springSecurityService.encodePassword('password')

有关如何 setup使用Grails实现Spring安全性



编辑:



你确定用户被保存在数据库中吗?添加 save(flush:true,failOnError:true)并在数据库中检查用户是否在这里。


I'm new to Grails and trying to use Spring Security Core plugin to assign roles to users. I called my project "MyProject".

After having generated controllers and views for my models, in Config.groovy, I've set a required login in order to access /userMyProject/ :

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
    '/userMyProject/**':               ['ROLE_ADMIN']
]

Then in BootStrap.groovy I create automatically some users and roles :

def init = { servletContext ->
    def role1 = new Role();
    role1.setAuthority("ROLE_ADMIN")
    role1.save();

    def user1 = new UserMyProject();
    // ... assigning name, username, password...
    user1.save();

    new UserMyProjectRole(userCwitter:user1, role:role1).save();
}

But then when I go to my UserMyProjectController page, it correctly opens the login page but always yells Sorry, we were not able to find a user with that username and password. when I'm able to see it in my DB.

Thanks for your help.

解决方案

In the part:

// ... assigning name, username, password...

Are you encoding the password (before version 1.2)?

def springSecurityService
...
springSecurityService.encodePassword('password')

A good reference on how to setup Spring security with Grails.

Edit:

Are you sure the user got saved in th DB? Add save(flush: true, failOnError: true) and check in the DB if your user is here.

这篇关于抱歉,我们无法找到具有该用户名和密码的用户。 (Grails-Spring安全核心)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆