Class: AvdtLdap
- Inherits:
-
Object
- Object
- AvdtLdap
- Defined in:
- lib/avdt_ldap/avdt_ldap.rb
Class Attribute Summary collapse
-
.configuration ⇒ Object
Adds configuration ability to the gem.
Instance Attribute Summary collapse
-
#directories ⇒ Object
Returns the value of attribute directories.
-
#include_default ⇒ Object
Returns the value of attribute include_default.
-
#user_attributes ⇒ Object
Returns the value of attribute user_attributes.
-
#user_location ⇒ Object
Returns the value of attribute user_location.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ AvdtLdap
constructor
Loads ldap configuration file and sets up the object’s parameters.
-
#valid?(login, password) ⇒ Boolean
Checks for user’s existance on specified directories.
Constructor Details
#initialize(args = {}) ⇒ AvdtLdap
Loads ldap configuration file and sets up the object’s parameters
61 62 63 64 65 66 67 68 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 61 def initialize(args = {}) if File.exist?(AvdtLdap.configuration.ldap_config_file) @LDAP = YAML.load_file(AvdtLdap.configuration.ldap_config_file).symbolize_keys! else raise "AvdtLdap: File #{AvdtLdap.configuration.ldap_config_file} not found, maybe you forgot to define it ?" end @directories = args[:directories] || @LDAP[env].keys end |
Class Attribute Details
.configuration ⇒ Object
Adds configuration ability to the gem
106 107 108 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 106 def configuration @configuration end |
Instance Attribute Details
#directories ⇒ Object
Returns the value of attribute directories.
58 59 60 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 58 def directories @directories end |
#include_default ⇒ Object
Returns the value of attribute include_default.
58 59 60 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 58 def include_default @include_default end |
#user_attributes ⇒ Object
Returns the value of attribute user_attributes.
58 59 60 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 58 def user_attributes @user_attributes end |
#user_location ⇒ Object
Returns the value of attribute user_location.
58 59 60 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 58 def user_location @user_location end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
110 111 112 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 110 def self.configure yield(configuration) end |
Instance Method Details
#valid?(login, password) ⇒ Boolean
Checks for user’s existance on specified directories. Just pass “login” and “password” parameters to chech if a user resides on one of the directories. After this method calling, if the user is authenticated, his (directory) attributes are availaible.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/avdt_ldap/avdt_ldap.rb', line 74 def valid? login, password @directories.each do |ldap| ldap = ldap.to_sym unless @LDAP[env][ldap].nil? conn = connection(ldap) conn.authenticate("#{attribute(ldap)}=#{login.to_s},#{base(ldap)}", password.to_s) begin # if bind => OK if conn.bind logger.info("Authenticated #{login.to_s} by #{host(ldap)}") if logger @user_attributes = conn.search(:base => base(ldap),:filter => Net::LDAP::Filter.eq(attribute(ldap),login.to_s)).first.each do |k,v| class_eval "attr_reader :#{k}" self.instance_variable_set "@#{k}".to_sym, v end @user_location = ldap return true else logger.info("Error attempting to authenticate #{login.to_s} by #{host(ldap)}: #{conn.get_operation_result.code} #{conn.get_operation_result.message}") if logger end rescue Net::LDAP::LdapError => error logger.info("Error attempting to authenticate #{login.to_s} by #{host(ldap)}: #{error.message}") if logger return false end else logger.info "ERROR ! \"#{ldap}\" directory data are missing in ldap.yml" if logger raise Net::LDAP::LdapError, "\"#{ldap}\" directory data are missing in ldap.yml" end end false end |