Class: OmniAuth::LDAP::Adaptor
- Inherits:
-
Object
- Object
- OmniAuth::LDAP::Adaptor
- Defined in:
- lib/omniauth-ldap/adaptor.rb
Defined Under Namespace
Classes: AuthenticationError, ConfigurationError, ConnectionError, LdapError
Constant Summary collapse
- VALID_ADAPTER_CONFIGURATION_KEYS =
[:host, :port, :method, :bind_dn, :password, :try_sasl, :sasl_mechanisms, :uid, :base, :allow_anonymous]
- MUST_HAVE_KEYS =
[:host, :port, :method, :uid, :base]
- METHOD =
{ :ssl => :simple_tls, :tls => :start_tls, :plain => nil, }
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#bind_dn ⇒ Object
Returns the value of attribute bind_dn.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#password ⇒ Object
Returns the value of attribute password.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Instance Method Summary collapse
-
#bind_as(args = {}) ⇒ Object
:base => “dc=yourcompany, dc=com”, :filter => “(mail=#user)”, :password => psw.
-
#initialize(configuration = {}) ⇒ Adaptor
constructor
A new instance of Adaptor.
Constructor Details
#initialize(configuration = {}) ⇒ Adaptor
Returns a new instance of Adaptor.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/omniauth-ldap/adaptor.rb', line 30 def initialize(configuration={}) @configuration = configuration.dup @configuration[:allow_anonymous] ||= false @logger = @configuration.delete(:logger) = [] MUST_HAVE_KEYS.each do |name| << name if configuration[name].nil? end raise ArgumentError.new(.join(",") +" MUST be provided") unless .empty? VALID_ADAPTER_CONFIGURATION_KEYS.each do |name| instance_variable_set("@#{name}", configuration[name]) end method = ensure_method(@method) config = { :host => @host, :port => @port, :encryption => method, :base => @base } @uri = construct_uri(@host, @port, @method != :plain) @bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple) @auth = sasl_auths({:username => @bind_dn, :password => @password}).first if @bind_method == :sasl @auth ||= { :method => @bind_method, :username => @bind_dn, :password => @password } config[:auth] = @auth @connection = Net::LDAP.new(config) end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
28 29 30 |
# File 'lib/omniauth-ldap/adaptor.rb', line 28 def auth @auth end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
28 29 30 |
# File 'lib/omniauth-ldap/adaptor.rb', line 28 def base @base end |
#bind_dn ⇒ Object
Returns the value of attribute bind_dn.
27 28 29 |
# File 'lib/omniauth-ldap/adaptor.rb', line 27 def bind_dn @bind_dn end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
28 29 30 |
# File 'lib/omniauth-ldap/adaptor.rb', line 28 def connection @connection end |
#password ⇒ Object
Returns the value of attribute password.
27 28 29 |
# File 'lib/omniauth-ldap/adaptor.rb', line 27 def password @password end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
28 29 30 |
# File 'lib/omniauth-ldap/adaptor.rb', line 28 def uid @uid end |
Instance Method Details
#bind_as(args = {}) ⇒ Object
:base => “dc=yourcompany, dc=com”, :filter => “(mail=#user)”, :password => psw
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/omniauth-ldap/adaptor.rb', line 66 def bind_as(args = {}) result = false @connection.open do |me| rs = me.search args if rs and rs.first and dn = rs.first.dn password = args[:password] method = args[:method] || @method password = password.call if password.respond_to?(:call) if method == 'sasl' result = rs.first if me.bind(sasl_auths({:username => dn, :password => password}).first) else result = rs.first if me.bind(:method => :simple, :username => dn, :password => password) end end end result end |