2011-09-25 30 views
2

我创建了自己的守望者战略,使用Devise。它与Devise :: Strategies :: DatabaseAuthenticatable非常相似,实际上它从它继承并重新实现了身份验证!移除守望者战略 - 如何确保原始devise_authenticable策略不见了

我的问题是,我想确保最初的devise_authenticable Warden战略不复存在。这并不在Warden会尝试的策略列表中,因为它实际上是一个安全问题。那可能吗?

回答

3

根据我的人工检查和测试,这在devise.rb初始化达到的目标:

config.warden do |manager| 
    strategies = manager.default_strategies(:scope => :user) 
    strategies[strategies.index(:database_authenticatable)] = :alternative_strategy 
end 

而且战略得以实施这种方式(不是这个问题的一部分,但我发现相互矛盾的信息了有这一个是使用Rails 3.1为我工作的人,设计1.4.7和1.0.5舍监):

class AlternativeStrategy < Devise::Strategies::Authenticatable 
    def authenticate! 
    end 
end 
Warden::Strategies.add(:alternative_strategy, AlternativeStrategy) 
+0

到目前为止,它似乎工作正常。 – Pablo

0

我只是实现这一点。设计将尝试列表中的每个策略,直到一个成功。

对我来说,我并没有替换:database_authenticatable策略,而是将我的策略添加到列表的开头,并弹出:database_authenticatable off在现有列表的末尾。

config.warden do |manager| 
    # Exiles::Devise::Strategies::BySite implemented in lib/. It matches the stub in Pablo's answer 
    manager.strategies.add(:by_site_auth, Exiles::Devise::Strategies::BySite) 

    # add my strategy to the beginning of the list. 
    manager.default_strategies(:scope => :user).unshift :by_site_auth 

    # remove the default database_authenticatable strategy from the list 
    manager.default_strategies(:scope => :user).pop 
end