zoukankan      html  css  js  c++  java
  • Spring Security 国际化 让人蛋疼的 坏的凭证

    错误信息报出一个“坏的凭证”,根本就让人看不懂。

    还是看英文的好。

    Spring Security支持异常信息的国际化,最终用户希望看到这些信息。 如果你的应用被设计成给讲英语的用户的,你不需要做任何事情, 因为默认情况下Spring Security的信息都是引用的。 

    所有的异常信息都支持国际化,包括验证失败和访问被拒绝的相关信息(授权失败)。 应该被开发者和系统开发者关注(包括不正确的属性,接口契约,使用非法构造方法, 开始时间校验,调试级日志等等)的异常和日志没有被国际化,而是使用英语硬编码到 Spring Security的代码中。 

    找到国际化文件 
    从spring-security-core-xx.jar中,你可以找到 org.springframework.security包下,包含了一些 messages.properties文件,我们找到 

    messages_zh_CN.properties 并拷贝到 resources 目录下 

    配置国际化文件 
    这应该引用到你的 ApplicationContext中,因为Spring Security的类 都实现了spring的MessageSourceAware接口, 期待的信息处理器会在application context启动的时候注入进来。 通常所有你需要做的就是在你的application context中注册一个bean来引用这些信息。 

    在 application context 中配置 

    <bean id="messageSource" 
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
    <property name="basename" value="classpath:messages"/> 
    </bean> 

    messages.properties是按照标准资源束命名的, 里边包括了Spring security所使用的默认语言的信息。 默认的文件是英文的。如果你没有注册一个信息源,Spring Security也会正常工作, 并使用硬编码的英文版本的信息。 

    修改相应国际化文件 

    ...........badCredentials=\u574f\u7684\u51ed\u8bc1 

    默认的badCredentials翻译为 "坏的凭证" 我们将其修改为 "账号或密码不正确" 

    替换所有的 \u574f\u7684\u51ed\u8bc1为 \u8d26\u53f7\u6216\u5bc6\u7801\u4e0d\u6b63\u786e



    再附上英对中的翻译,不过说真的,还不如看英文原版


    Spring Security 国际化文件 messages_zh_CN.properties 中文解释
    Spring Security 国际化文件 messages_zh_CN.properties 中文解释 

    AbstractAccessDecisionManager.accessDenied = 不允许访问 
    AbstractSecurityInterceptor.authenticationNotFound = 未在SecurityContext中查找到认证对象 
    AbstractUserDetailsAuthenticationProvider.badCredentials = 坏的凭证 
    AbstractUserDetailsAuthenticationProvider.credentialsExpired = 用户凭证已过期 
    AbstractUserDetailsAuthenticationProvider.disabled = 用户已失效 
    AbstractUserDetailsAuthenticationProvider.expired = 用户帐号已过期 
    AbstractUserDetailsAuthenticationProvider.locked = 用户帐号已被锁定 
    AbstractUserDetailsAuthenticationProvider.onlySupports = 仅仅支持UsernamePasswordAuthenticationToken 
    AnonymousAuthenticationProvider.incorrectKey = 展示的AnonymousAuthenticationToken不含有预期的key 
    AuthByAdapterProvider.incorrectKey = 展示的AuthByAdapter实现不含有预期的key 
    BasicAclEntryAfterInvocationProvider.insufficientPermission = Authentication对象({0})确实含有ACL权限,但并不是目标领域对象所要求的({1}) 
    BasicAclEntryAfterInvocationProvider.noPermission = 给定的Authentication对象({0})根本无权操控领域对象({1}) 
    BindAuthenticator.badCredentials = 坏的凭证 
    BindAuthenticator.failedToLoadAttributes = 坏的凭证 
    CasAuthenticationProvider.incorrectKey = 展示的CasAuthenticationToken不含有预期的key 
    CasAuthenticationProvider.noServiceTicket = 未能够正确提供待验证的CAS服务票根 
    ConcurrentSessionControllerImpl.exceededAllowed = 已经超过了当前主体({0})被允许的最大会话数量 
    DaoX509AuthoritiesPopulator.noMatching = 未在subjectDN: {0}中找到匹配的模式 
    DefaultIntitalDirContextFactory.badCredentials = 坏的凭证 
    DefaultIntitalDirContextFactory.communicationFailure = 不能够连接到LDAP服务器 
    DefaultIntitalDirContextFactory.unexpectedException = 由于未预期异常而不能够获得InitialDirContext 
    DigestProcessingFilter.incorrectRealm = 响应结果中的Realm名字({0})同系统指定的Realm名字({1})不吻合 
    DigestProcessingFilter.incorrectResponse = 错误的响应结果 
    DigestProcessingFilter.missingAuth = 遗漏了针对'auth' QOP的、必须给定的摘要取值; 接收到的头信息为{0} 
    DigestProcessingFilter.missingMandatory = 遗漏了必须给定的摘要取值; 接收到的头信息为{0} 
    DigestProcessingFilter.nonceCompromised = Nonce令牌已经存在问题了,{0} 
    DigestProcessingFilter.nonceEncoding = Nonce未经过Base64编码; 相应的nonce取值为 {0} 
    DigestProcessingFilter.nonceExpired = Nonce已经过期/超时 
    DigestProcessingFilter.nonceNotNumeric = Nonce令牌的第1部分应该是数字,但结果却是{0} 
    DigestProcessingFilter.nonceNotTwoTokens = Nonce应该由两部分取值构成,但结果却是{0} 
    DigestProcessingFilter.usernameNotFound = 用户名{0}未找到 
    JdbcDaoImpl.noAuthority = 没有为用户{0}指定角色 
    JdbcDaoImpl.notFound = 未找到用户{0} 
    LdapAuthenticationProvider.emptyPassword = 坏的凭证 
    LdapAuthenticationProvider.emptyUsername = 用户名不允许为空 
    NamedCasProxyDecider.untrusted = 代理({0})不受信任 
    PasswordComparisonAuthenticator.badCredentials = 坏的凭证 
    ProviderManager.providerNotFound = 未查找到针对{0}的AuthenticationProvider 
    RejectProxyTickets.reject = Proxy票根被拒绝 
    RememberMeAuthenticationProvider.incorrectKey = 展示RememberMeAuthenticationToken不含有预期的key 
    RunAsImplAuthenticationProvider.incorrectKey = 展示的RunAsUserToken不含有预期的key 
    SwitchUserProcessingFilter.credentialsExpired = 用户凭证已过期 
    SwitchUserProcessingFilter.disabled = 用户已失效 
    SwitchUserProcessingFilter.expired = 用户帐号已过期 
    SwitchUserProcessingFilter.locked = 用户帐号已被锁定 
    SwitchUserProcessingFilter.noCurrentUser = 不存在当前用户 
    SwitchUserProcessingFilter.noOriginalAuthentication = 不能够查找到原先的已认证对象 
    SwitchUserProcessingFilter.usernameNotFound = 用户名{0}未找到 
    UserDetailsService.credentialsExpired = 用户凭证已过期 
    UserDetailsService.disabled = 用户已失效 
    UserDetailsService.expired = 用户帐号已过期 
    UserDetailsService.locked = 用户帐号已被锁定 
    X509AuthenticationProvider.certificateNull = 未提供证书 

  • 相关阅读:
    Verdi 看波形常用快捷操作
    Tensorflow系列——Saver的用法
    Verilog-分频器
    (原创)列主元Gauss消去法的通用程序
    冒泡排序算法
    ADC 与实际电压值的关系
    直流耦合 交流耦合 耦合
    当前不会命中断点,源代码与原始版本不同
    示波器触发
    在头文件#pragma comment(lib,"glaux.lib");编译器提示waring C4081: 应输入“newline“
  • 原文地址:https://www.cnblogs.com/xiaowangba/p/6314495.html
Copyright © 2011-2022 走看看