我有一个应用程序启动并运行 REST 身份验证,但现在想添加密码到期(这将通过 quartz 作业在默认用户类上设置属性 - bool 密码过期)
有人可以指出我正确的方向来处理过期密码异常,返回类似 403 的内容,以指示在前端输入新密码而不是 401。
我在日志中看到以下内容:
DEBUG userdetails.DefaultPostAuthenticationChecks - User account credentials have expired
DEBUG rest.RestAuthenticationFilter - Authentication failed: User credentials have expired
DEBUG bearer.BearerTokenAuthenticationFailureHandler - Sending status code 401 and header WWW-Authenticate: Bearer
假设我必须在某个地方覆盖一个方法,但我是 grails 的新手,不知道如何做到这一点。
谢谢
最佳答案
想出了一个解决办法。
供其他人引用:-
1)禁用承载 token 支持(不确定是否需要,但它的工作)
grails.plugin.springsecurity.rest.token.validation.useBearerToken = false
grails.plugin.springsecurity.rest.token.validation.headerName = 'X-Auth-Token'
2)创建一个实现的新类
class CustomRestAuthenticationFailureHandler implements AuthenticationFailureHandler {@
Override
void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
def statuscode = HttpServletResponse.SC_FORBIDDEN
...
// do something based on the exception message and change the status or add a message to response.body
}
3)将bean添加到resources.groovy
beans = {
restAuthenticationFailureHandler(CustomRestAuthenticationFailureHandler) {
}
}
关于rest - Grails REST 安全性 - 密码过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29957203/