【问题标题】:Grails REST Security - Expired PasswordGrails REST 安全性 - 密码过期
【发布时间】:2015-07-09 12:49:03
【问题描述】:

我有一个应用程序启动并运行,REST 身份验证工作,但现在想添加密码到期(这将通过石英作业在默认用户类上设置属性 - 布尔密码过期)

有人可以指出正确的方向来处理过期密码异常,返回类似 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 的新手,不知道如何做到这一点。

谢谢

【问题讨论】:

    标签: rest grails spring-security passwords


    【解决方案1】:

    想出了一个解决办法。

    供其他人参考:- 1) 禁用承载令牌支持(不确定是否需要,但它可以工作)

    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) {
    
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 2011-04-21
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 2011-04-21
      • 2011-07-11
      相关资源
      最近更新 更多