如图显示,输入错误密码,提示为英文

springsecurity包下有自带的语言资源包

我们通过自定义messageSource,返回中文的配置文件

//security中文提示信息配置类
@Configuration
public class ReloadMessageConfig {@Bean //加载中文认证提示信息public ReloadableResourceBundleMessageSource messageSource(){ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();//加载org/springframework/security包下的中文提示信息 配置文件messageSource.setBasename("classpath:org/springframework/security/messages_zh_CN");return messageSource;}
}

${param.error}判断是否有提示信息
${session?.SPRING_SECURITY_LAST_EXCEPTION?.message}获取提示信息内容

login.html

<!--登录错误提示信息-->
<div class="error_tip" th:if="${param.error}"><span th:text="${session?.SPRING_SECURITY_LAST_EXCEPTION?.message}" class="help-block" style="color:red;"></span>
</div>

最后测试

分析

在 spring-security-core-5.0.7.RELEASE.jar 的 org.springframework.security 包下,有一组名为 messages[_language_country].properties 的配置文件。

messages_zh_CN.properties 内容如下:

AbstractAccessDecisionManager.accessDenied=不允许访问
AbstractLdapAuthenticationProvider.emptyPassword=坏的凭证
AbstractSecurityInterceptor.authenticationNotFound=未在SecurityContext中查找到认证对象
AbstractUserDetailsAuthenticationProvider.badCredentials=坏的凭证
AbstractUserDetailsAuthenticationProvider.credentialsExpired=用户凭证已过期
AbstractUserDetailsAuthenticationProvider.disabled=用户已失效
AbstractUserDetailsAuthenticationProvider.expired=用户帐号已过期
AbstractUserDetailsAuthenticationProvider.locked=用户帐号已被锁定
AbstractUserDetailsAuthenticationProvider.onlySupports=仅仅支持UsernamePasswordAuthenticationToken
AccountStatusUserDetailsChecker.credentialsExpired=用户凭证已过期
AccountStatusUserDetailsChecker.disabled=用户已失效
AccountStatusUserDetailsChecker.expired=用户帐号已过期
AccountStatusUserDetailsChecker.locked=用户帐号已被锁定
AclEntryAfterInvocationProvider.noPermission=给定的Authentication对象({0})根本无权操控领域对象({1})
AnonymousAuthenticationProvider.incorrectKey=展示的AnonymousAuthenticationToken不含有预期的key
BindAuthenticator.badCredentials=坏的凭证
BindAuthenticator.emptyPassword=坏的凭证
CasAuthenticationProvider.incorrectKey=展示的CasAuthenticationToken不含有预期的key
CasAuthenticationProvider.noServiceTicket=未能够正确提供待验证的CAS服务票根
ConcurrentSessionControlAuthenticationStrategy.exceededAllowed=已经超过了当前主体({0})被允许的最大会话数量
DigestAuthenticationFilter.incorrectRealm=响应结果中的Realm名字({0})同系统指定的Realm名字({1})不吻合
DigestAuthenticationFilter.incorrectResponse=错误的响应结果
DigestAuthenticationFilter.missingAuth=遗漏了针对'auth' QOP的、必须给定的摘要取值; 接收到的头信息为{0}
DigestAuthenticationFilter.missingMandatory=遗漏了必须给定的摘要取值; 接收到的头信息为{0}
DigestAuthenticationFilter.nonceCompromised=Nonce令牌已经存在问题了,{0}
DigestAuthenticationFilter.nonceEncoding=Nonce未经过Base64编码; 相应的nonce取值为 {0}
DigestAuthenticationFilter.nonceExpired=Nonce已经过期/超时
DigestAuthenticationFilter.nonceNotNumeric=Nonce令牌的第1部分应该是数字,但结果却是{0}
DigestAuthenticationFilter.nonceNotTwoTokens=Nonce应该由两部分取值构成,但结果却是{0}
DigestAuthenticationFilter.usernameNotFound=用户名{0}未找到
JdbcDaoImpl.noAuthority=没有为用户{0}指定角色
JdbcDaoImpl.notFound=未找到用户{0}
LdapAuthenticationProvider.badCredentials=坏的凭证
LdapAuthenticationProvider.credentialsExpired=用户凭证已过期
LdapAuthenticationProvider.disabled=用户已失效
LdapAuthenticationProvider.expired=用户帐号已过期
LdapAuthenticationProvider.locked=用户帐号已被锁定
LdapAuthenticationProvider.emptyUsername=用户名不允许为空
LdapAuthenticationProvider.onlySupports=仅仅支持UsernamePasswordAuthenticationToken
PasswordComparisonAuthenticator.badCredentials=坏的凭证
#PersistentTokenBasedRememberMeServices.cookieStolen=Invalid remember-me token (Series/token) mismatch. Implies previous cookie theft attack.
ProviderManager.providerNotFound=未查找到针对{0}的AuthenticationProvider
RememberMeAuthenticationProvider.incorrectKey=展示RememberMeAuthenticationToken不含有预期的key
RunAsImplAuthenticationProvider.incorrectKey=展示的RunAsUserToken不含有预期的key
SubjectDnX509PrincipalExtractor.noMatching=未在subjectDN\: {0}中找到匹配的模式
SwitchUserFilter.noCurrentUser=不存在当前用户
SwitchUserFilter.noOriginalAuthentication=不能够查找到原先的已认证对象

附上链接: 定制 Spring Security 错误提示信息

springboot集成 security 更改中英文提示信息相关推荐

  1. SpringBoot集成security(1)|(security入门)

    SpringBoot集成security(1)|(security入门) 文章目录 SpringBoot集成security(1)|(security入门) @[TOC] 前言 一.Spring Se ...

  2. springboot集成security

    接着上一篇( springboot 集成mybatis)继续搞,接下来集成security 首先还是添加pom依赖 <dependency><groupId>org.sprin ...

  3. springboot md5加密_SpringSecurity入门-SpringBoot集成SpringSecurity

    前言 至今Java能够如此的火爆Spring做出了很大的贡献,它的出现让Java程序的编写更为简单灵活,而Spring如今也形成了自己的生态圈,今天咱们探讨的是Spring旗下的一个款认证工具:Spr ...

  4. SpringBoot集成Spring Security —— 第二章自动登录

    文章目录 一.修改login.html 二.两种实现方式 2.1 Cookie 存储 2.2 数据库存储 2.2.1 基本原理 2.2.2 代码实现 三.运行程序 在上一章:SpringBoot集成S ...

  5. SpringBoot集成Spring Security(二)注册 、密码加密、修改密码

    SpringBoot集成Spring Security(一)登录注销 写在前面 上一节创建了项目并且利用Spring Security完成了登录注销功能,这里继续说一下注册.密码加密和找回密码,代码注 ...

  6. SpringBoot集成Spring Security(一)登录注销

    同个人网站 https://www.serendipper-x.cn/,欢迎访问 ! SpringBoot集成Spring Security(二)注册 .密码加密.修改密码 写在前面 Spring S ...

  7. SpringBoot集成Spring Security(2)——自动登录

    在上一章:SpringBoot集成Spring Security(1)--入门程序中,我们实现了入门程序,本篇为该程序加上自动登录的功能. 文章目录 一.修改login.html 二.两种实现方式 2 ...

  8. springboot集成Spring Security oauth2(八)

    由于公司项目需要,进行SpringBoot集成Spring Security oauth2,几乎搜寻网上所有大神的案例,苦苦不能理解,不能完全OK. 以下是借鉴各大神的代码,终于demo完工,请欣赏 ...

  9. SpringBoot 集成 Spring Security

    Spring Security Spring Security是一个功能强大且高度可定制的身份验证和访问控制框架.它实际上是保护基于spring的应用程序的标准. Spring Security是一个 ...

最新文章

  1. 用etree解析xml_用python3教你任意Html主内容提取
  2. js练习--贪吃蛇(转)
  3. SAP License:一位在ERP行业从业九年的经验总结
  4. keep-alive + vuex + mint + Infinite scroll 保存分页列表数据
  5. 【初赛】「程序填空」题答v1.0
  6. Java进阶之路,Java程序员职业发展规划
  7. python蒙特卡洛求定积分_蒙特卡洛定积分(一)
  8. html5制作涂鸦板,HTML5实现涂鸦板
  9. 创始人李卉:麦客CRM2.0核心逻辑及其背后的思考
  10. win10打开红警卡死的解决方法--win10专业版
  11. vscode中文注释斜体修改
  12. Ubuntu 16.04 查看软件包的命令技巧
  13. java发送图片_Java发送邮件(图片、附件、HTML)
  14. cross-request插件下载
  15. 后台SpringBoot + Mybatis开发遇到的一些坑
  16. javascript设计模式(javascript设计模式与开发实践读书笔记)
  17. 【我的Android进阶之旅】 Android Studio 使用小技巧:快速Close Others其他的文件
  18. 杨晓峰-java核心技术36讲(学习笔记)- 第1讲 | 谈谈你对Java平台的理解?
  19. 酷栈云桌面开启“3+2”混合办公新趋势
  20. 2017年3月26日考试总结

热门文章

  1. yocto 基本概念
  2. 阿里云服务器如何初始化云盘(跟换系统)?初始化云盘和跟换操作系统的区别?
  3. python + opencv 创建简单渐变色
  4. 《股票魔法师》第3-5章读书分享
  5. cxxxxx和xxxxx.h的区别
  6. 2020年书法落款_2020鼠年书法落款怎么写?
  7. 线程和协程详解-python
  8. DM36x Rate Control Modes
  9. 【数据挖掘】关联规则之Galois Closure Based Approach(基于Galois闭包的方法)
  10. 一文搞懂 Cocos Creator 3.0 坐标转换原理