(window.webpackJsonp=window.webpackJsonp||[]).push([[176],{600:function(e,t,o){"use strict";o.r(t);var i=o(56),s=Object(i.a)({},(function(){var e=this,t=e.$createElement,o=e._self._c||t;return o("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[o("h1",{attrs:{id:"localization"}},[o("a",{staticClass:"header-anchor",attrs:{href:"#localization"}},[e._v("#")]),e._v(" Localization")]),e._v(" "),o("p",[e._v("If you need to support other locales, everything you need to know is contained in this section.")]),e._v(" "),o("p",[e._v("All exception messages can be localized, including messages related to authentication failures and access being denied (authorization failures).\nExceptions and logging messages that are focused on developers or system deplopers (including incorrect attributes, interface contract violations, using incorrect constructors, startup time validation, debug-level logging) are not localized and instead are hard-coded in English within Spring Security’s code.")]),e._v(" "),o("p",[e._v("Shipping in the "),o("code",[e._v("spring-security-core-xx.jar")]),e._v(" you will find an "),o("code",[e._v("org.springframework.security")]),e._v(" package that in turn contains a "),o("code",[e._v("messages.properties")]),e._v(" file, as well as localized versions for some common languages.\nThis should be referred to by your "),o("code",[e._v("ApplicationContext")]),e._v(", as Spring Security classes implement Spring’s "),o("code",[e._v("MessageSourceAware")]),e._v(" interface and expect the message resolver to be dependency injected at application context startup time.\nUsually all you need to do is register a bean inside your application context to refer to the messages.\nAn example is shown below:")]),e._v(" "),o("div",{staticClass:"language- extra-class"},[o("pre",{pre:!0,attrs:{class:"language-text"}},[o("code",[e._v('\n\n\n')])])]),o("p",[e._v("The "),o("code",[e._v("messages.properties")]),e._v(" is named in accordance with standard resource bundles and represents the default language supported by Spring Security messages.\nThis default file is in English.")]),e._v(" "),o("p",[e._v("If you wish to customize the "),o("code",[e._v("messages.properties")]),e._v(" file, or support other languages, you should copy the file, rename it accordingly, and register it inside the above bean definition.\nThere are not a large number of message keys inside this file, so localization should not be considered a major initiative.\nIf 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 "),o("code",[e._v("messages.properties")]),e._v(".")]),e._v(" "),o("p",[e._v("Spring Security relies on Spring’s localization support in order to actually lookup the appropriate message.\nIn order for this to work, you have to make sure that the locale from the incoming request is stored in Spring’s "),o("code",[e._v("org.springframework.context.i18n.LocaleContextHolder")]),e._v(".\nSpring MVC’s "),o("code",[e._v("DispatcherServlet")]),e._v(" does this for your application automatically, but since Spring Security’s filters are invoked before this, the "),o("code",[e._v("LocaleContextHolder")]),e._v(" needs to be set up to contain the correct "),o("code",[e._v("Locale")]),e._v(" before the filters are called.\nYou can either do this in a filter yourself (which must come before the Spring Security filters in "),o("code",[e._v("web.xml")]),e._v(") or you can use Spring’s "),o("code",[e._v("RequestContextFilter")]),e._v(".\nPlease refer to the Spring Framework documentation for further details on using localization with Spring.")]),e._v(" "),o("p",[e._v('The "contacts" sample application is set up to use localized messages.')])])}),[],!1,null,null,null);t.default=s.exports}}]);