java - 从 DTO 映射到实体时如何对密码进行编码?
问题描述
在 Spring Boot App 中,我想UserDTO
使用 Orika Mapper 将一个简单的(登录、密码)映射到一个用户实体。我不知道如何PasswordEncoder.encode
在映射时对密码调用方法进行编码。我应该使用不同的映射器吗?
解决方案
在映射到实体之前,您可以使用 Spring5 的默认编码器,其工作原理如下
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication()
.withUser("user")
.password("password")
.roles("USER");
}
有关更多详细信息,您可以在此处查看https://www.baeldung.com/spring-security-5-default-password-encoder
推荐阅读
- python - 在 Python 中计算归一化吉布斯熵
- macos - 如何为mac安装mysql核心转储符号文件?
- python - 如何将 worldpay 支付网关与 django 应用程序集成?
- python - 如何使用 python (matplotlib) 绘制 3d 极坐标矢量场
- r - 使用R将月份名称转换为日期
- huggingface-transformers - 使用 T5 预训练模型的抽象文本摘要
- reactjs - ReactJS - 基于 api 调用响应的受保护路由
- mysql - 错误“无法链接/包含 C 库 'zstd'”在 Mac Big Sur 上安装 DBD::mysql - MacPorts MySQL
- c# - 通过 WPF 中的 libvlc 转换后缺少 mp4 的文件属性
- java - 首次使用 Swing 实现 MVC 设计模式