- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 Grails 3.3.2 与 mongoDB 插件 (v6.1.4) 和 Spring Security Core 插件 (v3.2.0) 一起使用。
我有以下 UserPasswordEncoderListener
使用以下 persistenceEvent 方法:
@Override
protected void onPersistenceEvent(AbstractPersistenceEvent event) {
if (event.entityObject instanceof User) {
User u = (event.entityObject as User)
if (u.password && (event.eventType == EventType.PreInsert || (event.eventType == EventType.PreUpdate && u.hasChanged('password')))) {
event.getEntityAccess().setProperty("password", encodePassword(u.password))
}
}
}
hasChanged
每次我保存具有
的用户对象时,调用总是返回 true没有更新 导致已经编码的密码被重新编码,从而破坏了身份验证。
hasChanged
错误地返回真。
hasChanged
通过在 groovy 控制台中运行以下命令在其他地方正常运行:
def user = User.findByEmail("user@email.com")
println "Result: "+ user.hasChanged('password')
Result: false
.
userPasswordEncoderListener(UserPasswordEncoderListener,ref('mongoDatastore'))
最佳答案
您是否尝试过使用 isDirty()
而不是 hasChanged()
在你的听众中?
例如:
package com.mycompany.myapp
import grails.plugin.springsecurity.SpringSecurityService
import org.grails.datastore.mapping.engine.event.AbstractPersistenceEvent
import org.grails.datastore.mapping.engine.event.PreInsertEvent
import org.grails.datastore.mapping.engine.event.PreUpdateEvent
import org.springframework.beans.factory.annotation.Autowired
import grails.events.annotation.gorm.Listener
import groovy.transform.CompileStatic
@CompileStatic
class UserPasswordEncoderListener {
@Autowired
SpringSecurityService springSecurityService
@Listener(User)
void onPreInsertEvent(PreInsertEvent event) {
encodePasswordForEvent(event)
}
@Listener(User)
void onPreUpdateEvent(PreUpdateEvent event) {
encodePasswordForEvent(event)
}
private void encodePasswordForEvent(AbstractPersistenceEvent event) {
if (event.entityObject instanceof User) {
User u = event.entityObject as User
if (u.password && ((event instanceof PreInsertEvent) || (event instanceof PreUpdateEvent && u.isDirty('password')))) {
event.getEntityAccess().setProperty('password', encodePassword(u.password))
}
}
}
private String encodePassword(String password) {
springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
}
关于Grails MongoDB 脏检查在 Spring Security 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49692911/
Android 似乎真的不喜欢invalidate (Rect dirty),它用于仅使 Canvas 的一部分无效。当我使 Canvas 的一部分(下面以绿色显示)无效并且需要同时重绘 Canvas
来自 Leoliger 2ed 的 Git 版本控制, After you commit the addition of the new file into the repository, git s
我使用基本的 Valgrind 工具时出现了意外行为。对于基本 block 的每个 Put 语句,我使用以下方法注册一个脏助手unsafeIRDirty_0_N。问题是脏助手被调用的次数比预期的多,例
我想知道是否有人可以告诉我 hibernate 脏 session 是什么?我似乎遇到了一个问题,条件查询在不应该执行插入时执行了插入。我相信这与脏 session 有关,但在不真正了解脏 sessi
我正在尝试构建一个用于通用添加标签的 ADF 映射数据流 - 其目的是查看特定列中的值并将其替换为标签。我已经有了如下所示的数据集(表 B): enter image description here
我需要在刷新所有更改的实体之前编写一些业务逻辑。我尝试过的解决方案之一是 IPreUpdateEventListener。但是这个事件监听器已经将对象非规范化为键值。我需要在非规范化甚至刷新之前的一些
基于此help link我能够实现颜色更改,但在此解决方案中,它将颜色应用于整行,这不是我想要的。 我想更改唯一编辑过的单元格的颜色。如果有人有任何想法,请分享。谢谢。 最佳答案 这是一个带有您想要的
我想做什么? 我正在尝试反编译一个 apk 文件,修改它并重新编译它。 我的工作环境是什么? root@l0calh0st:~/Desktop/APKS/Projects# uname -a Linu
“ps”和“top”等工具报告各种内存使用情况,例如 VM 大小和驻留集大小。但是,这些都不是“真正的”内存使用情况: 程序代码在同一程序的多个实例之间共享。 共享库程序代码在使用该库的所有进程之间共
Martin Fowler说我们应该在添加新功能之前进行重构(假设原始程序结构不佳)。 所以我们都想重构这个脏代码库,这是肯定的。我们还知道,如果没有单元测试代码,就很容易引入细微的错误。 但这是一个
在开始开发一些实验性的东西之前,我创建了一个新分支。我通常会忘记这一点(这不是问题),但现在我事先做了。 从那以后,我更新了 3 个文件。 在 2 中只是我不想提交到安全分支的实验性更改。 在 1 中
这是代码的精简版本: gridDataSource = new kendo.data.DataSource({ batch: true, transport: {
内容: 我正在使用azure广告构建一个简单的登录应用程序,该应用程序可以正常登录并获取 token ,然后可以重定向到下一页,但是在重定向之前会引发错误 错误: The following _Typ
我想将我的摘要字段设置为 body 字段的清理版本,但前提是用户不提供他们自己的摘要,即。 params[:document][:summary] 为空。 如果我创建一个新记录,这似乎工作正常,如果我
我正在使用乐观锁定来防止人们在竞争条件下覆盖彼此的变化。 因为我从 5.1 升级了 Rails至 5.2 ,我的规范坏了,我将其追溯到 changes 中的事实。数组,与文件上传相关的更改不再Uplo
我似乎无法解决这个问题,所以如果有人可以帮助我,请您坚持一下! import 'dart:async'; import 'dart:convert'; import 'package:http/htt
我是一名优秀的程序员,十分优秀!