Created
May 13, 2014 19:02
-
-
Save jeffjohnson9046/52309896df450a003dd5 to your computer and use it in GitHub Desktop.
Bypass LDAP Authentication in Rails When Using Devise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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