ruby-on-railsbefore-filterrubycas

Use more than one before_filter


I want to use two filters in application_controller so, if the first filter fail:

before_filter CASClient::Frameworks::Rails::Filter

try it with the second:

before_filter :hmac_filter

The idea is when someone tries to enter to the REST service through a web client, the petition must be filtered with the rubycas client filter and if someone tries to enter with, for example, a client that use CURL, with the first filter should fail, but the second must be applied given the adequate parameters. I could use a sequence of curl petitions with the first filter activated for authenticate and gain a session cookie, but is not the idea, I must to use hmac_filter. Neither I can modify hmac_filter.

Any idea or suggestion will be appreciated. Thanks

EDIT

Maybe it wasn't the best solution, but at last this was my implementation:

before_filter :choose_auth

def choose_auth
  params[:hmac_auth] ? hmac_filter : CASClient::Frameworks::Rails::Filter.filter self
end

Solution

  • Before filters run before processing any web requests at all, so I don't think that this is going to help your situation. You need to handle this type of thing at the action level.