Skip to content

Instantly share code, notes, and snippets.

@jeffjohnson9046
Created May 13, 2014 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffjohnson9046/52309896df450a003dd5 to your computer and use it in GitHub Desktop.
Save jeffjohnson9046/52309896df450a003dd5 to your computer and use it in GitHub Desktop.
Bypass LDAP Authentication in Rails When Using Devise
# Add the Warden strategy contained in local_override.rb into the devise.rb file. The devise.rb should also be in the config/intializers directory.
Devise.setup do |config|
config.warden do |manager|
manager.default_strategies(:scope => :user).unshift :local_override
end
# Other devise configuration...
end
# Create a new authentication strategy for Warden. This file should go in config/initializers.
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
def authenticate!
if params[:user]
user = # Set the user to some mock/existing user account that has the privileges you require, e.g. User.find_by_ad_account("jjohnson3")
success!(user)
# user = User.find_by_email(params[:user][:email])
# if user && user.encrypted_password == params[:user][:password]
# success!(user)
# else
# fail
# end
else
fail
end
end
end
end
end
Warden::Strategies.add(:local_override, Devise::Strategies::LocalOverride)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment