lib/acs/ldap/connector.rb in acs-ldap-0.2.1 vs lib/acs/ldap/connector.rb in acs-ldap-0.2.2
- old
+ new
@@ -106,27 +106,35 @@
def get_connection
if @connected
@ldap
else
- connect
+ @ldap = connect
end
+ @ldap
end
protected
# get_connection should be used
def connect
logger.debug "LDAP connect"
if ! @connected
logger.debug "Binding to ldap..."
@ldap = Net::LDAP.new(ldap_params)
- if @ldap.bind
- logger.debug "Connection succeed"
- @connected = true
- else
+ begin
+ if @ldap.bind
+ logger.debug "Connection succeed"
+ @connected = true
+ else
+ @connected = false
+ @ldap = nil
+ logger.debug "Connection failed"
+ end
+ rescue Net::LDAP::Error => e
+ logger.error "Connection refused '#{e.inspect}'"
@connected = false
- logger.debug "Connection failed"
+ @ldap = nil
end
@ldap
else
@logger.debug "LDAP already connected"
nil