User authentication by both ldap and database

China☆狼群 提交于 2019-12-10 15:36:19

问题


We are planing to build a Rails application which utilizes both LDAP and database authentication ways.

we plan to take devise and devise_ldap_authenticatable to accomplish that.

The authlogic maybe like this, internal use complete the authentication by LDAP, however, external user have to sign up for the first time, and then app could take the database authentication.

I search by google, Devise and devise_ldap_authenticatable can't work in combined way, anybody here has similar usage, or some other way to achieve that?

thanks in advance.


回答1:


I find some valuable link here, however, we have to use different models.

https://groups.google.com/forum/#!topic/plataformatec-devise/-Fnr3LWXxBg




回答2:


I have implemented dual authentication in the following way.

 session_controller.rb

def create

 if (params[:log]=="local")   
           self.resource = warden.authenticate!(:database_authenticatable)

              sign_in(resource_name, resource)
                      yield resource if block_given?
                          respond_with resource, location: after_sign_in_path_for(resource)


                 else

                       
                                   self.resource = warden.authenticate!(:ldap_authenticatable)

                              sign_in(resource_name, resource)
                      yield resource if block_given?
                          respond_with resource, location: after_sign_in_path_for(resource)
                       end

  end

user.rb

  class User < ActiveRecord::Base
      
      devise :ldap_authenticatable, 
:database_authenticatable,:registerable,
            :recoverable, :rememberable, :trackable, :validatable
       

 

**and view devise/sessions/new.html.erb**


<%= form_for(:user, :url => session_path(:user)) do |f| %>
  <div class="form-inputs">
 <%= f.text_field :username ,:placeholder => "Login id"  %><br> <br>
  <%= f.password_field :password,:placeholder => "Password"  %>




   <label for="check_box_type">Login Server </label><%= select_tag :log, options_for_select([ [" Domain Server","domain"],["Local Server", "local"]])%>


  <%= f.submit 'Sign in' %>

Here according to the user input (login server :local/domain] it will login.



来源:https://stackoverflow.com/questions/17464548/user-authentication-by-both-ldap-and-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!