【问题标题】:Store strategy name in the Rails 3 log for Warden在 Rails 3 日志中为 Warden 存储策略名称
【发布时间】:2012-01-26 09:18:56
【问题描述】:

我们正在使用 Warden 进行身份验证,并且我们有很多策略,很难追踪哪一个成功了。而是放置像

这样的行

Rails.logger.debug "Authenticated with SSO" if user

对于每个策略,我想在某处放置一个简单的行来记录策略消息。它在 Warden 的某个地方可用,因为它存储了成功的消息:

success!(username, message)

如何做到这一点?放置这条线的最佳位置是什么?

我想我需要一个回调或类似的东西:

https://github.com/hassox/warden/wiki/Callbacks

【问题讨论】:

    标签: ruby-on-rails warden


    【解决方案1】:

    知道了:

    Warden::Manager.after_authentication do |user,auth,opts|
      user = user.username if user.respond_to? :username
      message = auth.winning_strategy.message
      Rails.logger.info "User #{user} authenticated: #{auth.winning_strategy.message}"
    end
    

    在策略中:

    success!(u, "with LDAP")
    

    例如。这行得通。

    【讨论】:

      猜你喜欢
      • 2022-08-04
      • 2021-04-04
      • 2021-10-18
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多