Spring Security(三十一):9.6 Localization(本地化)
Spring Security supports localization of exception messages that end users are likely to see. If your application is designed for English-speaking users, you don’t need to do anything as by default all Security messages are in English. If you need to support other locales, everything you need to know is contained in this section.
spring-security-core-xx.jar
you will find an org.springframework.security
package that in turn contains a messages.properties
file, as well as localized versions for some common languages. This should be referred to by your ApplicationContext
, as Spring Security classes implement Spring’s MessageSourceAware
interface and expect the message resolver to be dependency injected at application context startup time. Usually all you need to do is register a bean inside your application context to refer to the messages. An example is shown below:<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:org/springframework/security/messages"/>
</bean>
The messages.properties
is named in accordance with standard resource bundles and represents the default language supported by Spring Security messages. This default file is in English.
messages.properties
file, or support other languages, you should copy the file, rename it accordingly, and register it inside the above bean definition. There are not a large number of message keys inside this file, so localization should not be considered a major initiative. If you do perform localization of this file, please consider sharing your work with the community by logging a JIRA task and attaching your appropriately-named localized version of messages.properties
.org.springframework.context.i18n.LocaleContextHolder
. Spring MVC’s DispatcherServlet
does this for your application automatically, but since Spring Security’s filters are invoked before this, the LocaleContextHolder
needs to be set up to contain the correct Locale
before the filters are called. You can either do this in a filter yourself (which must come before the Spring Security filters in web.xml
) or you can use Spring’s RequestContextFilter
. Please refer to the Spring Framework documentation for further details on using localization with Spring.Spring Security(三十一):9.6 Localization(本地化)的更多相关文章
- Spring Security(05)——异常信息本地化
Spring Security支持将展现给终端用户看的异常信息本地化,这些信息包括认证失败.访问被拒绝等.而对于展现给开发者看的异常信息和日志信息(如配置错误)则是不能够进行本地化的,它们是以英文硬编 ...
- Spring Security(三) —— 核心配置解读
摘要: 原创出处 https://www.cnkirito.moe/spring-security-3/ 「老徐」欢迎转载,保留摘要,谢谢! 3 核心配置解读 上一篇文章<Spring Secu ...
- Spring Security(十一):4. Samples and Guides (Start Here)
If you are looking to get started with Spring Security, the best place to start is our Sample Applic ...
- Spring Security三种认证
Spring Security: 1.用户名+密码认证 2.手机号+短信认证 Spring Social: 1.第三方认证, QQ登录等 Spring Security OAuth: 1.把认证之后的 ...
- Spring Security 教程 大牛的教程
https://www.iteye.com/blog/elim-2247073 Spring Security 教程 Spring Security(20)——整合Cas Spring Securit ...
- SpringBoot + Spring Security 学习笔记(三)实现图片验证码认证
整体实现逻辑 前端在登录页面时,自动从后台获取最新的验证码图片 服务器接收获取生成验证码请求,生成验证码和对应的图片,图片响应回前端,验证码保存一份到服务器的 session 中 前端用户登录时携带当 ...
- Spring Security(三十二):10. Core Services
Now that we have a high-level overview of the Spring Security architecture and its core classes, let ...
- Spring Security(三十):9.5 Access-Control (Authorization) in Spring Security
The main interface responsible for making access-control decisions in Spring Security is the AccessD ...
- 朱晔和你聊Spring系列S1E10:强大且复杂的Spring Security(含OAuth2三角色+三模式完整例子)
Spring Security功能多,组件抽象程度高,配置方式多样,导致了Spring Security强大且复杂的特性.Spring Security的学习成本几乎是Spring家族中最高的,Spr ...
随机推荐
- SpringBoot是如何动起来的
SpringBoot是如何动起来的 程序入口 SpringApplication.run(BeautyApplication.class, args); 执行此方法来加载整个SpringBoot的环境 ...
- 教你MySQL Binlog实用攻略
本文由云+社区发表 1.概述 binlog是Mysql sever层维护的一种二进制日志,与innodb引擎中的redo/undo log是完全不同的日志:其主要是用来记录对mysql数据更新或潜在发 ...
- LeetCode数组解题模板
一.模板以及题目分类 1.头尾指针向中间逼近 ; ; while (pos1<pos2) { //判断条件 //pos更改条件 if (nums[pos1]<nums[pos2]) pos ...
- .Net Core 实践 - 使用log4net记录日志(1)
demo地址:https://github.com/PuzzledAlien/log4net_demo 准备 log4net 最新版本是2.0.8 VS2017 .Net Core 2.2 测试电脑配 ...
- 初识 MongoDB,MongoDB 的安装运行
1. MongoDB 非关系型数据库 MongoDB是一个基于分布式文件存储的数据库,由C++语言编写.目的是为WEB应用提供扩展的高性能的数据存储解决方案.MongoDB是一个介于关系型数据库和 ...
- Go中局部全局变量的区分
这是可能也许是容易混淆滴,先上1个例子: package main import "fmt" var nickname = "大虾" func main() { ...
- .NET和Java之争
这几天连续有多篇文章(详细文章列表在<.NET和Java之争一点随想>和<由优劣语言之争引起的思考>有写)诋毁.NET,这类文章我十几年前就看得多了,只不过十几年前是C和C++ ...
- linux c ---raise 使用范例的代码
把做工程过程中比较好的代码片段收藏起来,下面代码内容是关于linux c ---raise 使用范例的代码,希望对各位有所用途. #include <sys/types.h> #inclu ...
- 如何在linux下使用sudo命令不用输入密码
用过linux的小伙伴可能都知道,每次使用sudo的时候需要输入密码,这样很耽误事,那么接下来我会教大家如何去设置 一.1.输入su root进入root模式 2.输入visudo会打开/etc/su ...
- 牛客网:java入门实现遍历目录
项目介绍 遍历目录是操作文件时的一个常见需求.比如写一个程序,需要找到并处理指定目录下的所有JS文件时,就需要遍历整个目录.该项目教会你如何使用流式编程和lambda表达式,帮助你进一步熟悉java8 ...