Module: DRbService::LDAPAuthentication::ClassMethods

Defined in:
lib/drbservice/ldapauth.rb

Overview

Methods added to including classes when LDAPAuthentication is mixed in.

Constant Summary collapse

DEFAULT_SEARCH =

The default attributes of a search

{
  :filter => 'uid=%s',
  :base   => nil,
  :scope  => :sub,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ Object

Extension callback -- add the necessary class instance variables to extended modules.



25
26
27
28
29
30
31
# File 'lib/drbservice/ldapauth.rb', line 25

def self::extended( mod )
  super
  mod.instance_variable_set( :@ldap_uri, nil )
  mod.instance_variable_set( :@ldap_dn, nil )
  mod.instance_variable_set( :@ldap_dn_search, DEFAULT_SEARCH.dup )
  mod.instance_variable_set( :@ldap_authz_callback, nil )
end

Instance Method Details

#ldap_authz_callback(callable = nil, &block) ⇒ Object

Register a function to call when the user successfully binds to the directory to check for authorization. It will be called with the Treequel::Branch of the bound user and the Treequel::Directory they are bound to. Returning true from this function will cause authorization to succeed, while returning a false value causes it to fail.



68
69
70
71
72
73
74
75
76
# File 'lib/drbservice/ldapauth.rb', line 68

def ldap_authz_callback( callable=nil, &block )
  if callable
    @ldap_authz_callback = callable
  elsif block
    @ldap_authz_callback = block
  end

  return @ldap_authz_callback
end

#ldap_dn(pattern = nil) ⇒ Object

Set the pattern to use when creating the DN to use when binding.



42
43
44
45
# File 'lib/drbservice/ldapauth.rb', line 42

def ldap_dn( pattern=nil )
  @ldap_dn = pattern if pattern
  return @ldap_dn
end

#ldap_dn_search(filter = nil, options = {}) ⇒ Object

Set a filter that is used when searching for an account to bind as.



50
51
52
53
54
55
56
57
58
59
# File 'lib/drbservice/ldapauth.rb', line 50

def ldap_dn_search( filter=nil, options={} )
  if filter
    @ldap_dn_search ||= {}
    @ldap_dn_search[:filter] = filter
    @ldap_dn_search[:base] = options[:base] if options[:base]
    @ldap_dn_search[:scope] = options[:scope] if options[:scope]
  end

  return @ldap_dn_search
end

#ldap_uri(uri = nil) ⇒ Object

Set the URI of the LDAP server to bind to for authentication



35
36
37
38
# File 'lib/drbservice/ldapauth.rb', line 35

def ldap_uri( uri=nil )
  @ldap_uri = uri if uri
  return @ldap_uri
end