嗨,我需要在Spring安全登录表单中添加一个新的异常,除了我想要自己的错误消息之外,一切都很完美(直到现在它显示“错误的登录/密码”).
我从用户名密码验证过滤器覆盖默认尝试验证方法:
@OverrIDepublic Authentication attemptAuthentication(final httpServletRequest request,final httpServletResponse response){if (!mytest()) {throw new CustomAuthenticationException("custom message");}}
我的例外:
public class CustomAuthenticationException extends AuthenticationException { public CustomAuthenticationException(final String message) { super(message); } public CustomAuthenticationException(final String message,final Throwable cause) { super(message,cause); }}
在我的控制器中,我在SPRING_Security_LAST_EXCEPTION下看到了我的异常,但错误消息始终是来自坏凭证的消息,我怎么能改变它?
谢谢
最佳答案您应该尝试LOCAliZING SPRING Security MESSAGES.尝试将这些行添加到ApplicationContext.xml文件中.春天安全豆的其余部分在哪里.
你应该找到你的春季默认类< KEY,MESSAGE>存储.让myMessage文件具有相同的KEY和本地化的MESSAGE.
根据您的评论,您的项目中有一个messages.propertIEs.因此,您需要做的就是为此属性文件中的每个密钥设置一个MESSAGE,以获得完全本地化的消息:
AbstractAccessDecisionManager.accessDenIEd= your message in any languageAbstractSecurityInterceptor.authenticationNotFound=AbstractUserDetailsAuthenticationProvIDer.badCredentials=AbstractUserDetailsAuthenticationProvIDer.credentialsExpired=AbstractUserDetailsAuthenticationProvIDer.Disabled=AbstractUserDetailsAuthenticationProvIDer.expired=AbstractUserDetailsAuthenticationProvIDer.locked=AbstractUserDetailsAuthenticationProvIDer.onlySupports=AccountStatusUserDetailsChecker.credentialsExpired=AccountStatusUserDetailsChecker.Disabled=AccountStatusUserDetailsChecker.expired=AccountStatusUserDetailsChecker.locked=AclEntryAfterInvocationProvIDer.nopermission=AnonymousAuthenticationProvIDer.incorrectKey=BindAuthenticator.badCredentials=BindAuthenticator.emptyPassword=CasAuthenticationProvIDer.incorrectKey=CasAuthenticationProvIDer.noServiceTicket=ConcurrentSessionControlStrategy.exceededAllowed=DigestAuthenticationFilter.incorrectRealm=DigestAuthenticationFilter.incorrectResponse=DigestAuthenticationFilter.missingAuth=DigestAuthenticationFilter.missingMandatory=DigestAuthenticationFilter.nonceCompromised=DigestAuthenticationFilter.nonceEnCoding=DigestAuthenticationFilter.nonceExpired=DigestAuthenticationFilter.nonceNotNumeric=DigestAuthenticationFilter.nonceNottwoTokens=DigestAuthenticationFilter.usernameNotFound=JdbcdaoImpl.noAuthority=JdbcdaoImpl.notFound=LdapAuthenticationProvIDer.badCredentials=LdapAuthenticationProvIDer.credentialsExpired=LdapAuthenticationProvIDer.Disabled=LdapAuthenticationProvIDer.expired=LdapAuthenticationProvIDer.locked=LdapAuthenticationProvIDer.emptyUsername=LdapAuthenticationProvIDer.onlySupports=PasswordComparisonAuthenticator.badCredentials=PersistentTokenBasedRememberMeServices.cookieStolen=ProvIDerManager.provIDerNotFound=RememberMeAuthenticationProvIDer.incorrectKey=RunAsImplAuthenticationProvIDer.incorrectKey=SubjectDnX509PrincipalExtractor.noMatching=SwitchUserFilter.noCurrentUser=SwitchUserFilter.noOriginalAuthentication=
总结 以上是内存溢出为你收集整理的java – Spring安全性自定义AuthenticationException消息全部内容,希望文章能够帮你解决java – Spring安全性自定义AuthenticationException消息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)