我们的身份验证域对象 Operator,在其上启用了 bool 值。
当我们将此设置为 false 时,SpringSecurity + grails 会神奇地使登录尝试失败,并显示消息“对不起,您的帐户已禁用”。
我们想记录这样的尝试。据推测,有某种监听器或处理程序不需要我们实现逻辑(即 grails 只是通知我们用户被拒绝,而不是我们现在必须决定是否应该拒绝用户)。
我们已经记录了失败的密码检查,如果它们因为登录尝试次数过多而失败 - 我们不希望它捕获这些事件,只是由于 enabled == false
而被拒绝.
最佳答案
是的,您可以轻松实现。首先修改你的Config.groovy
以便它可以重定向到登录失败时的特定操作:
grails.plugin.springsecurity.failureHandler.defaultFailureUrl = "/login/authfail"
// For AJAX based authentication
grails.plugin.springsecurity.failureHandler.ajaxAuthFailUrl = "/login/authfail"
现在定义一个
LoginController
有行动authfail
如下:def authfail() {
String msg = ""
Exception exception = session[WebAttributes.AUTHENTICATION_EXCEPTION]
// print the kind of message you want either due to account locked, enabled = false, password expired = true and others
log.debug "User login failed due to [${exception?.message}]"
if (exception) {
if (exception instanceof AccountExpiredException) {
msg = g.message(code: "springSecurity.errors.login.expired")
} else if (exception instanceof CredentialsExpiredException) {
msg = g.message(code: "springSecurity.errors.login.passwordExpired")
} else if (exception instanceof DisabledException) {
msg = g.message(code: "springSecurity.errors.login.disabled")
} else if (exception instanceof LockedException) {
msg = g.message(code: "springSecurity.errors.login.locked")
} else {
msg = g.message(code: "springSecurity.errors.login.fail")
}
}
// redirect or respond acccordingly
}
关于grails - SpringSecurity,如何记录由于启用==假而失败的尝试,grails 2.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32561627/