- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
您好,我需要在 Spring 安全登录表单中添加一个新的异常,除了我想要自己的错误消息(直到现在它显示“错误的登录名/密码”)之外,一切正常。
我已经覆盖了用户名密码身份验证过滤器的默认尝试身份验证方法:
@Ghi đè
public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response)
{
if (!myTest()) {
throw new CustomAuthenticationException("custom message");
}
}
我的异常(exception):
public class CustomAuthenticationException extends AuthenticationException {
public CustomAuthenticationException(final String message)
{
super(message);
}
public CustomAuthenticationException(final String message, final Throwable cause)
{
super(message, cause);
}
}
在我的 Controller 中,我在 SPRING_SECURITY_LAST_EXCEPTION 下看到我的异常,但错误消息总是来自错误的凭据,我该如何更改它?
Cảm ơn
câu trả lời hay nhất
您应该尝试LOCALIZING SPRING SECURITY MESSAGES。
尝试将这些行添加到您的 ApplicationContext.xml
中文件。其余的 Spring Security Bean 所在的位置。
你应该找到你的 spring 默认类
被存储。有你的myMessage
具有相同 CHÌA KHÓA
的文件s 和本地化 MESSAGE
秒。
messages.properties
在你的项目中。所以你需要做的就是拥有一个
MESSAGE
对于此属性文件中的每个键,都具有完全本地化的消息:
AbstractAccessDecisionManager.accessDenied= your message in any language
AbstractSecurityInterceptor.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 Security 自定义 AuthenticationException 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16759264/
我正在尝试连接到 SFTP 服务器。我有一个私钥和一个密码。我已经尝试阅读SO上的相关问题,但一直无法成功连接。 这是我试过的: pysftp.Connection(host=, username=,
我正在尝试为 ActiveDirectory 创建上下文(客户端和服务器都是 Windows),使用我的 Windows 凭据和 NTLM。 这是我的代码: public void func() {
是否有更简洁的方法来检查 javax.naming.AuthenticationException(或 spring)的主要失败原因? LDAP Wiki (Binding Errors) 中描述了不
INFO [client-001-job-3] o.j.s.s.impl.DataLoaderService - Using registration URL of http://localhost
我们将应用程序从 Spring & Hibernate 3.x 升级到 4.x。问题是 AuthenticationException.getAuthentication() 现在已被弃用。任何人都可
我正在尝试创建一个 AuthenticationException 的异常子类,如下所示: public class RegistrationNotCompleteException extends
这是极少数情况之一,几乎不可能重现,但我见过这种情况发生了 20 次中有 4 次。 这是我的 open_session 方法: def open_session: self.session =
我在使用 Paramiko(版本 1.7.6-2)ssh 客户端连接到设备时遇到问题: $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56
我正在使用 MailKit 尝试通过 SMTP 通过交换服务器发送电子邮件,但当我尝试连接时出现以下错误: An exception of type 'System.Security.Authenti
我正在尝试过滤在我的应用程序中进行用户身份验证期间引发的 AuthenticationException。我知道这些不能用 @ControllerAdvice 和 @ExceptionHandler
我在一个项目中使用 Spring MVC 和 Spring Security,并用它实现一个登录表单。我遇到了一种奇怪的行为,这是我没有预料到的,我想知道是否有办法避免它。 当登录表单上出现身份验证错
当我尝试通过客户端连接 Hazelcast 服务器时,出现以下异常。 com.hazelcast.client.AuthenticationException: Invalid credentials
我正在尝试使用 Java 类 AuthenticationService 进行露天身份验证。这是代码: public void Authenticate() throws Authentication
我正在尝试使用 PushSharp 向我的应用程序发送推送通知。我有两个 Apple 帐户...一个是普通帐户,另一个是企业帐户。我在正常帐户上有一个开发人员证书可以使用,但我的开发和分发证书都无法在
我正在尝试使用 JAVA GSSAPI 执行 NTLM 绑定(bind)。 我收到此错误: javax.naming.AuthenticationException: GSSAPI [Root exc
我一直在使用 Kubernetes .net 客户端库版本来从容器内访问 Kubernetes api。今天我从客户端库版本 1.6.11 更新到 4.0.21 但这破坏了客户端身份验证的某些部分。
import paramiko host='x.x.x.x' port=22 username='root' password='password' cmd='dmidecode > a' ssh=p
我正在尝试定义一个默认入口点来处理AuthenticationException。 这是我的配置: @Override protected void configure(HttpSecurity ht
我在使用纯 Java 通过 ldap 连接到 Active Directory 时遇到问题。 如果 displayName 以 ,(逗号,例如“, name”)开头,我会得到一个 javax.nami
您好,我需要在 Spring 安全登录表单中添加一个新的异常,除了我想要自己的错误消息(直到现在它显示“错误的登录名/密码”)之外,一切正常。 我已经覆盖了用户名密码身份验证过滤器的默认尝试身份验证方
Tôi là một lập trình viên xuất sắc, rất giỏi!