Git Product home page Git Product logo

activeldap's Introduction

ActiveLdap

A ruby library for object-oriented LDAP interface.

Description

'ActiveLdap' is a ruby library which provides a clean objected oriented interface to LDAP library. It was inspired by ActiveRecord. This is not nearly as clean or as flexible as ActiveRecord, but it is still trivial to define new objects and manipulate them with minimal difficulty.

For example and usage - read the document.

Prerequisites

Ruby interpreter

See the above links for installation.

LDAP client

JRuby doesn't need to install new library because JRuby has builtin LDAP support. Ruby users need one of them:

See the above links for installation.

Active Model

A toolkit for building modeling frameworks like Active Record and Active Resource.

Rails

See Rails (doc/text/rails.textile in the repository and on GitHub) page for Rails integration.

License

This program is free software; you can redistribute it and/or modify it. It is dual licensed under Ruby's license and under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

Please see the file LICENSE for the terms of the license.

Thanks

This list may not be correct. If you notice mistakes of this list, please point out.

  • Dick Davies
  • Nathan Kinder
  • Patrick Cole
  • Google Inc.
  • Nobody: Bug reports and API improveent ideas.
  • James Hughes: Bug reports and advices and documentations.
  • Buzz Chopra: Documentations.
  • Christoph Lipp:
    • Bug reports.
    • Tell us character escape syntax.
  • Jeff Hall: Bug reports.
  • Ernie Miller: Bug reports and advices.
  • Daniel Pfile: Patches.
  • Jacob Wilkins: Bug reports.
  • Ace Suares:
    • Bug reports.
    • Nederlands translations.
  • Iain Pople: Bug reports and API improvement ideas.
  • Kevin McCarthy: Patches.
  • Perry Smith: Patches, bug reports and indications.
  • Marc Dequènes: API suggestions.
  • Jeremy Pruitt: Bug reports.
  • Bodaniel Jeanes:
    • A suggestion for behavior on simple bind with empty password.
    • Bug reports.
  • Naoto Morishima: Bug reports.
  • David Morton:
    • An API improvement idea.
    • Bug reports.
  • Lennon Day-Reynolds: Bug reports.
  • Tilo: A bug report.
  • Matt Mencel: Bug reports.
  • CultureSpy:
    • Bug reports.
    • Bug fixes.
  • gwarf12: A bug report.
  • Baptiste Grenier: API improvement ideas.
  • Richard 3 Nicholas: API improvement ideas.
  • Kazuhiro NISHIYAMA: A bug report.
  • Grzegorz Marszałek: A bug report.
  • しまさわらさん: A suggesetion.
  • Ted Lepich: A suggestion.
  • danger1986: A suggestion.
  • michael.j.konopka: Bug reports.
  • ingersoll: A suggestion.
  • Alexey.Chebotar: Bug reports.
  • ery.lee: A bug report.
  • id:dicdak: A bug report.
  • Raiko Mitsu: A bug report.
  • Kazuaki Takase: Documents in Japanese.
  • Tim Hermans: A bug report.
  • Joe Francis: A suggestion.
  • Tiago Fernandes: Bug reports.
  • achemze: A suggestion.
  • George Montana Harkin: A suggestion.
  • Marc Dequènes: Bug reports.
  • [email protected]: A bug report.
  • Hideyuki Yasuda: Bug reports.
  • zachwily: A bug report.
  • [email protected]: A bug report.
  • Tim Hermans: A bug report.
  • Anthony M. Martinez: Helped SASL options support
  • ilusi0n.x: A bug report.
  • projekttabla: A suggestion.
  • christian.pennaforte: A bug report.
  • planetmcd: A bug report.
  • spoidar: Rails 3 support.
  • Kris Wehner: Rails 2.3.8 support.
  • Ryan Tandy:
    • A test bug fix.
    • Rails 3 support.
  • rbq: A bug report.
  • Narihiro Nakamura: Rails 3 support.
  • Hidetoshi Yoshimoto: Rails 3 support.
  • warden: A bug report.
  • bklier: A bug fix.
  • Craig White: Bug reports.

activeldap's People

Contributors

adamwhittingham avatar authornari avatar bearded avatar belltailjp avatar dependabot[bot] avatar dklotz avatar f-3r avatar fmbiete avatar h-lame avatar harlemsquirrel avatar hide24 avatar j-verz avatar jpiotro3 avatar kaz-t avatar kou avatar mperrando avatar nengxu avatar olleolleolle avatar pdf avatar pmarchi avatar rabbitt avatar redpig avatar sailesh avatar silex avatar simi avatar ursm avatar voxik avatar weicheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activeldap's Issues

Question: ActiveLDAP + RAILS + Puma - Initialize the connections

Hi,

I'm using Puma as my rails server, in a clustered mode (processes + threads). I would like to have the ldap connection stablished before the first petition, so I followed Puma instructions for that, and added the ActiveLdap bit

# config/puma.rb
on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
    Rails.logger.info "New worker, DB connections is done, we will connect to LDAP"
    BaseLdap.setup_connection
  end
end

Where BaseLdap is like this

class BaseLdap < ActiveLdap::Base
    self.abstract_class = true
end

I'm not seeing the "Bound to ldap:" after that info line, but after the first request. Am I missing something?

BaseLdap.allow_concurrency = true would help?

Thanks

cannot load such file -- dl/win32

I'm running Rails 3.2, and whenever I try to require this gem using require "active_ldap/railtie" before the application is initialized (MyApp::Application.initialize!) I get the following error whenever I try to start Rails (rails console, rails generate, etc):

c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- dl/win32 (LoadError)
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/locale-2.0.5/lib/locale/driver/win32.rb:16:in `<top (required)>'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `block in require'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:251:in `require'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/locale-2.0.5/lib/locale.rb:32:in `require_driver'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/locale-2.0.5/lib/locale.rb:74:in `init'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/locale-2.0.5/lib/locale.rb:90:in `driver_module'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/locale-2.0.5/lib/locale.rb:178:in `current'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/gettext-2.2.1/lib/gettext/runtime/textdomain_manager.rb:100:in `translate_singluar_message'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/gettext-2.2.1/lib/gettext.rb:130:in `gettext'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.1.2/lib/active_ldap/railtie.rb:16:in `block (2 levels) in <class:Railtie>'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.1.2/lib/active_ldap/railtie.rb:15:in `class_eval'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.1.2/lib/active_ldap/railtie.rb:15:in `block in <class:Railtie>'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from C:/Documents and Settings/user/My Documents/my_app/config/environment.rb:5:in `<top (required)>'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:103:in `require'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:40:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

ActiveLdap::ObjectClassError: unknown objectClass in LDAP server: top, costCenter

Hi,

I'm getting an error as shown below when using #find on a model class:

Loading development environment (Rails 3.1.3)
 :001 > Costcenter.find "112345"
ActiveLdap::ObjectClassError: unknown objectClass in LDAP server: top, costCenter
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/object_class.rb:69:in `assert_valid_object_class_value'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/object_class.rb:44:in `assert_object_classes'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/object_class.rb:29:in `replace_class'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/base.rb:1066:in `initialize_by_ldap_data'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/base.rb:610:in `block in instantiate'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/base.rb:609:in `instance_eval'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/base.rb:609:in `instantiate'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/callbacks.rb:38:in `instantiate_with_callbacks'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:286:in `block in find_every'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:285:in `collect'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:285:in `find_every'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:258:in `find_initial'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:325:in `find_one'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:312:in `find_from_dns'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/bundler/gems/activeldap-80298afb50d6/lib/active_ldap/operations.rb:231:in `find'
    from (irb):1
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
    from /Users/pasc/.rvm/gems/ruby-1.9.3-p0@invoice_receipt_ldap_admin/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>' :002 > exit

This is my model class:

class Costcenter < ActiveLdap::Base
  ldap_mapping :dn_attribute => "cn",
               :prefix => "ou=costcenters",
               :classes => ["top", "costCenter"]

  has_many :cc_managers, :class_name=> "LdapUser", :wrap => "ccManager", :primary_key => "dn"
end

This is parts of my ldap schema defining costCenter class:

attributetype ( 1.3.6.1.4.1.4203.666.1.94.1
        NAME 'ccName'
          DESC 'Der Name der Kostenstelle'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
    SINGLE-VALUE )

attributetype ( 1.3.6.1.4.1.4203.666.1.95
    NAME 'ccManager'
    DESC 'Kostenstellenverantwortliche(r)'
    SUP uniqueMember )

attributetype ( 1.3.6.1.4.1.4203.666.1.98
    NAME 'taxable'
    DESC 'Ist diese Kostenstelle steuerpflichtig? (pflichtig, frei, gemischt)'
    SYNTAX  1.3.6.1.4.1.1466.115.121.1.15
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
    SINGLE-VALUE
    )

# costCenter
objectclass ( 1.3.6.1.4.1.4203.666.1.101 NAME 'costCenter'
        DESC 'Eine Kostenstelle'
    SUP top STRUCTURAL
        MUST ( ccName $ cn $ taxable )
    MAY ( ccManager )
    )

I have tried everything to no avail.
With the net-ldap gem (latest and trunk 0.2.20110317223538 from https://github.com/RoryO/ruby-net-ldap.git) I get the error as given above.
With the ruby-ldap gem I get "abort trap" hard ruby lockups with webrick as well as with thin (webrick problems are known obviously). It's happening with activeldap trunk and latest.
The rest of my environment is:

OpenLDAP-Server in CentOS is openldap-servers.i386 0:2.3.43-12.el5_7.10

% ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
% rails -v
Rails 3.1.3

on OSX 10.7.2

I don't know what's happening here, the stuff is simple enough so it should work, right?

Thanks,

Paul

ldap.yml is not read under Rails 4.0.2

I'm trying to use activeldap with Rails v4.0.2. However, Rails fails to establish a connection to the LDAP server. I guess its not reading the ldap.yml file. Do I need to add a custom initializer to get activeldap to work with Rails 4.0.2?

Remove the color scheme in log messages

In lib/active_ldap/log_subscriber.rb, there is some 'beautiful' color scheme with odd/even lines for the log messages. However, LDAP is only one element of the system (eg., Rails). Generally developers would like to use consistent color scheme across all elements of the system. Unfortunately, this LDAP-specific color scheme would contradict with the consistency in color.

I have to monkey patch to disable this LDAP-specific color scheme:

module ActiveLdap
  class LogSubscriber < ActiveSupport::LogSubscriber
    # Monkey patch to disable the color scheme of LDAP log messages.
    def log_info(event)
      self.class.runtime += event.duration
      return unless logger.debug?

      payload = event.payload
      name = 'LDAP: %s (%.1fms)' % [payload[:name], event.duration]
      info = payload[:info].inspect

      debug "#{name}: #{info}"
    end
  end
end

Please remove this LDAP-specific color scheme, and let the developers to decide system-wide color scheme in log messages. Thanks.

I will submit a pull request for this issue too.

Rails 3.2.1 Support

Hello.
I know it's an edge case, but I thought I'd get a ball rolling:
upgrading my internal apps to Rails 3.2.1 ran into this ( everything works in rails 3.1.11)

I can bundle just fine, but when I try to rails c, I get

          C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require': cannot load such file --   active_ldap/railtie (LoadError)
       from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
       from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
       from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
       from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
       from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
       from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
    from D:/Projects/Web/rex.ajrintl.com/rex3/config/application.rb:7:in `<top (required)>'
    from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:39:in `require'
    from C:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:39:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

If I go to irb:

 require 'active_ldap/railtie'
 Gem::LoadError: Unable to activate railties-3.2.1, because activesupport-3.1.3 conflicts with activesupport (= 3.2.1)

to_json method not working or not implemented?

irb(main):002:0> a = User.first.to_json
=> "[[\"objectClass\",[\"evolutionPerson\",\"inetOrgPerson\",\"mozillaAbPersonAlpha\",\"organizationalPerson\",\"person\",\"posixAccount\",\"sambaSamAccount\",\"shadowAccount\",\"top\"]],[\"uid\",\"testacc\"] ....

This is probably not the output it should be right?
I am willing to implement this method if you give me some advice where to start.

Callback not invoked

I am using before_save callback to salt password before saving it to LDAP. However the callback function is never used.

Code example:

class User < ActiveLdap::Base
  ldap_mapping dn_attribute: "uid",
           prefix: "ou=users",
           classes: ["top", "person", "simpleSecurityObject", "pwdPolicy", "organizationalPerson", "inetOrgPerson", "bidMigratable", "bidAuthenticable"]

  attr_accessor :password

  alias_attribute :login, :uid
  alias_attribute :email, :mail
  alias_attribute :first_name, :cn
  alias_attribute :last_name, :sn

  before_save :set_password

  private

  def set_password
    self.userPassword = ActiveLdap::userPassword.ssha(self.password)
    require 'pry'; binding.pry
  end
end

Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.1)
actionpack (= 4.0.1)
mail (> 2.5.4)
actionpack (4.0.1)
activesupport (= 4.0.1)
builder (
> 3.1.0)
erubis (> 2.7.0)
rack (
> 1.5.2)
rack-test (> 0.6.2)
activeldap (4.0.1)
activemodel (
> 4.0.0)
gettext
gettext_i18n_rails
locale
activeldap-fabrication (1.0.1)
activeldap
fabrication
activemodel (4.0.1)
activesupport (= 4.0.1)
builder (> 3.1.0)
activerecord (4.0.1)
activemodel (= 4.0.1)
activerecord-deprecated_finders (
> 1.0.2)
activesupport (= 4.0.1)
arel (> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.1)
i18n (
> 0.6, >= 0.6.4)
minitest (> 4.2)
multi_json (
> 1.3)
thread_safe (> 0.1)
tzinfo (
> 0.3.37)
arel (4.0.1)
atomic (1.1.14)
better_errors (1.0.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.1.4)
coderay (1.0.9)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.3)
columnize (0.3.6)
debug_inspector (0.0.2)
debugger (1.6.2)
columnize (>= 0.3.1)
debugger-linecache (> 1.2.0)
debugger-ruby_core_source (
> 1.2.3)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.3)
diff-lcs (1.2.5)
erubis (2.7.0)
execjs (2.0.2)
fabrication (2.9.3)
fast_gettext (0.8.0)
gettext (3.0.2)
locale (>= 2.0.5)
text
gettext_i18n_rails (1.0.1)
fast_gettext (>= 0.4.8)
hike (1.2.3)
i18n (0.6.5)
jbuilder (1.5.2)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
libv8 (3.16.14.3)
locale (2.0.9)
mail (2.5.4)
mime-types (> 1.16)
treetop (
> 1.4.8)
method_source (0.8.2)
mime-types (1.25)
minitest (4.7.5)
multi_json (1.8.2)
polyglot (0.3.3)
pry (0.9.12.2)
coderay (> 1.0.5)
method_source (
> 0.8)
slop (> 3.4)
pry-debugger (0.2.2)
debugger (
> 1.3)
pry (> 0.9.10)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.1)
actionmailer (= 4.0.1)
actionpack (= 4.0.1)
activerecord (= 4.0.1)
activesupport (= 4.0.1)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.1)
sprockets-rails (
> 2.0.0)
railties (4.0.1)
actionpack (= 4.0.1)
activesupport (= 4.0.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.0)
rdoc (3.12.2)
json (> 1.4)
ref (1.0.5)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
rspec-rails (2.14.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (
> 2.14.0)
rspec-expectations (> 2.14.0)
rspec-mocks (
> 2.14.0)
ruby-ldap (0.9.16)
sass (3.2.12)
sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sprockets-rails (> 2.0.0)
sdoc (0.3.20)
json (>= 1.1.3)
rdoc (
> 3.10)
slop (3.4.6)
sprockets (2.10.0)
hike (> 1.2)
multi_json (
> 1.0)
rack (> 1.0)
tilt (
> 1.1, != 1.3.0)
sprockets-rails (2.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (> 2.8)
sqlite3 (1.3.8)
text (1.2.3)
therubyracer (0.12.0)
libv8 (
> 3.16.14.0)
ref
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (1.3.0)
coffee-rails
tzinfo (0.3.38)
uglifier (2.3.0)
execjs (>= 0.3.0)
json (>= 1.8.0)

PLATFORMS
ruby

DEPENDENCIES
activeldap
activeldap-fabrication
better_errors
binding_of_caller
coffee-rails (> 4.0.0)
fabrication
jbuilder (
> 1.2)
jquery-rails
pry
pry-debugger
rails (= 4.0.1)
rspec-rails (> 2.0)
ruby-ldap
sass-rails (
> 4.0.0)
sdoc
sqlite3
therubyracer
turbolinks
uglifier (>= 1.3.0)

Rails Resource Routing

I have this route:

resources :users

resources :groups do
  resources :users
end

These models:

user.rb:

class User < ActiveLdap::Base

[...]

belongs_to :groups,
           :many => 'memberUid',
           :class_name => 'Group',
           :foreign_key => 'uid'

[...]

end

group.rb:

class Group < ActiveLdap::Base

[...]

has_many :users,
             :wrap => "memberUid",
             :class_name => "User",
             :primary_key => 'uid'


[...]

end

The following works:

g = Group.first
g.users.map{|member| member.id}
=> ["aborisov", "akoenig"]
g.users.first
=> #<User objectClass:<evolutionPerson, ...

When I now request a route like /groups/x/users it will return every user which is saved within the LDAP tree and not only the ones that are assigned to group x.
What do I have to do in order to get nested routes working?

Issue using form_for helpers

Hi all,

is it possible that there are some bugs using the RESTful form_for helpers in rails?

My routes look like

Someapp::Application.routes.draw do
  resources :objects
end

which generates the following routes

object_index GET    /objects(.:format)                     {:action=>"index", :controller=>"objects"}
                   POST /objects(.:format)                     {:action=>"create", :controller=>"objects"}
  new_object GET    /objects/new(.:format)              {:action=>"new", :controller=>"objects"}
   edit_object GET    /objects/:id/edit(.:format)         {:action=>"edit", :controller=>"objects"}
          object GET    /objects/:id(.:format)                {:action=>"show", :controller=>"objects"}
                   PUT     /objects/:id(.:format)                 {:action=>"update", :controller=>"objects"}
            DELETE      /objects/:id(.:format)                 {:action=>"destroy", :controller=>"objects"}

In my view templates I'm using code like

<%= form_for @object do |f| %>
  [...]
<% end %>

which behaves not as expected. For newly created objects

@object = Object.new

the form should be submitted to the controllers 'create' action, but it gives an error message like

No route matches {:action=>"show", :controller=>"objects", :format=>nil, :id=>#<Object objectClass:<top, person, inetOrgPerson, organizationalPerson>[...]>}

and if @object is not new, ie a record fetched from the directory

@object = Object.find('something')

it should submit the form to the 'update' action - but actually it just says

No route matches [POST] "/users/test"

(which is in deed the correct path, but the HTML verb should be PUT instead of POST)

Can anyone confirm that behaviour or even give me a hint how to work around that without the need to write to completely seperate forms for the new and edit actions?

Re
Ben

RuntimeError: Circular dependency detected while autoloading constant Base

Long story short, that was the error that allowed me to embark on the "fix" below, for running ActiveLdap with Rails 4.rc2 and Ruby 2.0.0-p195. After loading the ActiveLdap gem and doing a simple .find - the error in the title would be presented.

👍 Also confirmed that what I updated is working with Rails 4 final release (6/25/13).

superscott/activeldap@activeldap:master...master

The main changes were, ActiveModel::MassAssignmentSecurity deprecation, and the .send command for the Callbacks.

I'm not doing a pull request (yet), for a few reasons A.) I'm still pretty new with ruby/rails and I'm pretty sure I'm missing something and B.) I can't run the tests against my LDAP server so I can't be 100% sure that this code is correct.

Let me know what else you need from me, if anything. Thanks.

Test suite is missing files

The al-test-utils.rb is missing in gem. The test suite should be either complete and executable or should not be present at all.

Thank you.

"after_initialize" callback doesn't run.

Hi,

I've tried following code:

require 'active_ldap'

ActiveLdap::Base.setup_connection base: "dc=example,dc=local",
    bind_dn: "cn=Manager,ou=Users,dc=example,dc=local",
    password: "manager_password"

class LdapUser < ActiveLdap::Base
  ldap_mapping :prefix => "ou=Users",
               :dn_attribute => "cn",
               :classes => ['inetOrgPerson']

  after_initialize :init

  def init
    puts "after_initialize!"
  end
end

user = LdapUser.new
#=> #<LdapUser objectClass:<inetOrgPerson>...>

I expect to run "init" method after LdapUser#initialize, but it doesn't run. why?

Other callbacks works correctly.
(ex. before_save, after_save, before_create, after_create, etc.)

Thanks.

ldap.yml not loaded automatically with rails 3.1.3 + Jruby 1.6.5.1

Hi, I Have a ldap.yml below and class Person(ActiveLdap::Base). If I call straight Person.exists?(username) then it complains that cannot connect to LDAP server. But If explicitly do the following setup_connection in code then it works. Please let know what is the correct procedure to load properly from ldap.yml file, as I do not want to setup_connection in the code. Thanks

ActiveLdap::Base.setup_connection :host => 192.168.1.140,
                                                :port => 1389,
                                                :base =>  dc=test,dc=org,
                                                :bind_dn => cn=Directory Manager,
                                                :password => 123,
                                                :allow_anonymous => false

{code}
development:

host: 192.168.1.140
port: 1389
base: dc=test,dc=org
bind_dn: cn=Directory Manager
password: 123
allow_anonymous: false

test:
host: 192.168.1.140
port: 1389
base: dc=test,dc=org
bind_dn: cn=Directory Manager
password: 123
allow_anonymous: false

production:
host: 192.168.1.140
port: 1389
base: dc=test,dc=org
bind_dn: cn=Directory Manager
password: 123
allow_anonymous: false

{code}

Strange Errors When Using .add_class Method

I want to add a schema-class to every existing user.

This works

> a = User.find('name')
> a.add_class('classname')
> a.save
=> true

This does not

> User.all.each{ |u|
>   u.add_class('classname')
>   u.save
> }
=> ActiveLdap::LdapError::InvalidSyntax: Invalid syntax
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/ldap_ext.rb:102:in `assert_error_code'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/ldap.rb:181:in `rescue in execute'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/ldap.rb:177:in `execute'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/ldap.rb:148:in `block in modify'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/base.rb:224:in `block in modify'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/base.rb:271:in `block in operation'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/ldap.rb:187:in `do_in_timeout'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/base.rb:317:in `with_timeout'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/base.rb:270:in `operation'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/base.rb:222:in `modify'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/adapter/ldap.rb:140:in `modify'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/operations.rb:560:in `modify_entry'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/persistence.rb:58:in `block in update'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/base.rb:1516:in `prepare_data_for_saving'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/persistence.rb:56:in `update'
    ... 3 levels...
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/callbacks.rb:68:in `update'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/persistence.rb:43:in `create_or_update'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/callbacks.rb:60:in `block in create_or_update'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:399:in `_run_save_callbacks'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/callbacks.rb:60:in `create_or_update'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/persistence.rb:33:in `save'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activeldap-3.1.1/lib/active_ldap/validations.rb:44:in `save'
    from (irb):18:in `block in irb_binding'
    from (irb):15:in `each'
    from (irb):15
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
    from /home/martin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'

Any ideas why?

stack level to deep. ActiveLdap 1.2.4

I'm trying to get activesambaldap work with rails 2.3.14
There was an issue with bindtextdomain:
http://rubyforge.org/tracker/index.php?func=detail&aid=29610&group_id=2570&atid=9875

Now I've error:

SystemStackError (stack level too deep):
activeldap (1.2.4) lib/active_ldap/action_controller/ldap_benchmarking.rb:44:in view_runtime_without_active_ldap' activeldap (1.2.4) lib/active_ldap/action_controller/ldap_benchmarking.rb:44:inview_runtime'

when i'm launching my rails 2.3.14 app.

Document how to use allow_concurrency

I tried using activeldap with sidekiq but it failed with the same openssl error as in #85. I tried to setup allow_concurrency for the connection but could not find the right place to call (first place I tried was ActiveLdap::Base). It would be useful to document this API in the tutorial.

"invalid byte sequence in UTF-8" on save when using krb5

this is a bit of a doozy to reproduce...

I have an OpenLDAP instance set up as the backend for krb5-kdc (similar to this: https://help.ubuntu.com/10.04/serverguide/kerberos-ldap.html).

here's the kerberos5.schema: http://sprunge.neoice.net/UFii

if I have a User with krbPrincipalAux and krbTicketPolicyAux objectClasses, the attribute krbPrincipalKey is full of binary data that is used in Kerberos authentication. attempting to .save() this User results in ActiveLdap blowing up with:

ArgumentError: invalid byte sequence in UTF-8
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/attributes.rb:19:in `==='
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/attributes.rb:19:in `blank_value?'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/attributes.rb:17:in `block in blank_value?'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/attributes.rb:17:in `each'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/attributes.rb:17:in `all?'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/attributes.rb:17:in `blank_value?'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/validations.rb:178:in `block in validate_ldap_values'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/validations.rb:172:in `each'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/validations.rb:172:in `validate_ldap_values'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:427:in `_run__936904584488302551__validate__callbacks'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:80:in `run_callbacks'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activemodel-4.0.1/lib/active_model/validations.rb:373:in `run_validations!'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activemodel-4.0.1/lib/active_model/validations/callbacks.rb:106:in `block in run_validations!'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:373:in `_run__936904584488302551__validation__callbacks'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activesupport-4.0.1/lib/active_support/callbacks.rb:80:in `run_callbacks'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activemodel-4.0.1/lib/active_model/validations/callbacks.rb:106:in `run_validations!'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activemodel-4.0.1/lib/active_model/validations.rb:314:in `valid?'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/validations.rb:39:in `valid?'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/activeldap-4.0.1/lib/active_ldap/validations.rb:44:in `save'
    from (irb):18
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/railties-4.0.1/lib/rails/commands/console.rb:90:in `start'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/railties-4.0.1/lib/rails/commands/console.rb:9:in `start'
    from /home/neoice/intranet/vendor/cache/ruby/1.9.1/gems/railties-4.0.1/lib/rails/commands.rb:62:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>

removing these attributes with kadmin delprinc results in an object that can be saved.

Issue with active_connections caching

I'm not sure if this is as intended, but I ran into a problem today while working some more on my centralized password administration app (which is using ActiveLdap).

Here's the situation:

ldap.yml defines a connection with full read/write privileges to LDAP
LdapUser is a Rails model that inherits from ActiveLdap::Base (and gets those connection settings from ldap.yml)

If used in a clean state, searching for an object and setting its password works just fine.

If #bind is called on an instance of LdapUser to check if the user can log in, subsequent password changes are blocked due to permissions errors.

I spent the afternoon digging through the code, and I believe the issue is this:

bind calls the instance version of #connection

connection checks for an active connection (in class.active_connections, keyed on its own DN) and creates one if it doesn't exist. Any objects with a matching DN will now use this connection.

Any subsequent searches for that same LDAP entry will result in the same DN, using that connection rather than the default connection for any actions called on the object. So, when I attempt to update the password and run #save on the object, it attempts to set the password with the connection bound with the limited permissions of that user rather than the more powerful permissions in the ldap.yml file.

What made it a doozy to track down was that, since this DN-keyed connection is stored in a class variable in ActiveLdap::Base, even if I create a new class, inheriting from ActiveLdap, with different credentials, as soon as I search for that same user, the DN's will match, and I'll end up with the same restricted permissions.

The workaround for me is to call #remove_connection after binding, which will revert me back to the ldap.yml defaults stored in my LdapUser's default connection.

Here's some basic test code to demonstrate what happens:

require 'active_ldap'  #=> true
A = Class.new(ActiveLdap::Base)
B = Class.new(ActiveLdap::Base)
A.setup_connection(
    host: 'REMOVED', 
    port: 636, 
    method: :ssl, 
    base: 'REMOVED', 
    bind_dn: 'REMOVED',
    password: 'REMOVED', 
    allow_anonymous: false
)
B.setup_connection(
    host: 'REMOVED', 
    port: 636, 
    method: :ssl, 
    base: 'REMOVED', 
    bind_dn: 'REMOVED',
    password: 'REMOVED', 
    allow_anonymous: false
)
a = A.find(attribute: 'samaccountname', value: 'testfaculty')
b = B.find(attribute: 'samaccountname', value: 'testfaculty');
A.active_connections.each {|k,v| puts "#{k}: #{v.object_id}" } #=> A: 51876468     B: 48300876
puts "a: #{a.connection.object_id}" #=> a: 51876468
puts "b: #{b.connection.object_id}" #=> b: 48300876
puts b.bind('Friday!') #=> true
A.active_connections.each {|k,v| puts "#{k}: #{v.object_id}" } #=> A: 51876468     B: 48300876     cn=testfaculty,...: 59020176
puts "a: #{a.connection.object_id}" #=> a: 59020176
puts "b: #{b.connection.object_id}" #=> b: 59020176
b.remove_connection
puts "a: #{a.connection.object_id}" #=> a: 51876468
puts "b: #{b.connection.object_id}" #=> b: 48300876

Would there be benefit to solving the problem by using a combination of the DN and current object name as the key in the active_connections hash? This way, individual classes could maintain their own caches without interfering with each other?

TypeError using activeldap with ruby 2.0.0p247, Rails 4.0.0, ruby-ldap 0.9.15

Hi everyone,

I try to use activeldap with the gems mentioned in the title. When following the tutorial to test the installation (https://github.com/activeldap/activeldap/blob/master/doc/text/tutorial.textile) I run into the following error:

~/Rails Workspace/ADeditor$ irb -rubygems
2.0.0p247 :001 > require 'active_ldap'
TypeError: superclass mismatch for class DateTime
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/date.rb:3:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/core_ext/date/calculations.rb:1:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/core_ext/date.rb:2:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/core_ext.rb:3:in `block in <top (required)>'
        from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/core_ext.rb:1:in `each'
        from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/core_ext.rb:1:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/activeldap-4.0.1/lib/active_ldap.rb:3:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:110:in `rescue in require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:35:in `require'
        from (irb):1

Is this a known issue? I'm a Ruby-beginner, so I'm not sure if it's my fault ;-)

Kind regards
Tobias

Testing connection / How to query LDAP

Hey,

I am currently trying to write a Rails app to manage all our users which are saved in LDAP.

development:                                                                    
    host: some.domain.com                                                       
    port: 4444                                                                    
    base: removed                                                                
    bind_dn: removed                                            
    password: removed

Problem is that I have no idea how I could test if this connection is set up properly.
I created some modules with the rails generate scripts that contain an ldap mapping

class Account < ActiveLdap::Base
 ldap_mapping :dn_attribute => "uid",
              :prefix => "ou=Accounts",
              :classes => ["top",
                        "shadowAccount",
                        "sambaSamAccount",
                        "posixAccount",
                        "person",
                        "organizationalPerson",
                        "mozillaAbPersonAlpha",
                        "inetOrgPerson",
                        "evolutionPerson",
                        "personalvw"
                        ]
end

Launching "rails c" then and typing "Account.exists?("existing_uid") never returns...

Are there any good ways to test the connection settings and retrieve some LDAP entries (just for testing purposes)?

Cheers & Thanks

logging?

Hi there,

Is it somehow possible to log queries?
Wireshark is not an option as I can only connect via ssl to our server...

I've got a belongs_to association that doesn't return anything, so I wanted to debug...

Thanks a lot,
Christoph

"zombie" connections

Hi,

I'm have an issue with cached connections because, after a few minutes, these connections doesn't work anymore.

If I try to reuse a connection that hasn't been used for a couple of minutes, my Rails instance (server or console) just freezes with no message at all (no LDAP log, no error).

The problem occurs with net-ldap and ruby-ldap. The only difference is that with ruby-ldap, I can CTRL+C the instance. With net-ldap, I have to kill -9 it.

I've found a solution for http requests by calling ActiveLdap::Base.clear_active_connections! in an after_action callback in my application controller, but this is not very clean and not applicable in the console.

Is there a way to set some kind of max age to cached connections, so that they're not reused if they're too old ?

Thanks !

path po cound not be found

I updated ActiveLDAP in my Sinatra app and it pulled in the fast_gettext Gem, which throws:

fast_gettext-0.5.8/lib/fast_gettext/translation_repository/base.rb:36:in `find_files_in_locale_folders': path po cound not be found! (RuntimeError)

It works if I create a ./po directory in my app. Since there is a dir called po in the ActiveLDAP sources I believe there is something wrong with the configuration within ActiveLDAP and fast_gettext is pointed to the wrong path.

When using :method => :ssl error message wrong number of arguments (3 for 0..2) appears

When I try to connect to AD via ssl & GSSAPI using this setup_coonection:
irb(main):033:0> ActiveLdap::Base.setup_connection(
irb(main):034:1* :host => 'test-AD.emea.test.com',
irb(main):035:1* :port => 389,
irb(main):036:1* :method => :ssl,
irb(main):037:1* :base => 'DC=emea,DC=test,DC=com',
irb(main):037:1* :bind_dn =>"CN=ADuser,OU=UsersGeneric,OU=IT,OU=City,OU=AdminUnits,DC=emea,DC=test,DC=com",
irb(main):039:1* :allow_anonymous => false,
irb(main):040:1* :try_sasl => true,
irb(main):041:1* :sasl_mechanisms => "GSSAPI",
irb(main):041:1* :sasl_options => {:authzid =>"dn:CN=ADuser,OU=UsersGeneric,OU=IT,OU=City,OU=AdminUnits,DC=emea,DC=test,DC=com"},
irb(main):043:1* :sasl_quiet => false
irb(main):044:1> )
=> nil
set the mapping:

irb(main):046:0* class Group < ActiveLdap::Base
irb(main):047:1> ldap_mapping
irb(main):048:1> end

The error is the following:
Reconnect to server failed: wrong number of arguments (3 for 0..2)
Reconnect to server failed backtrace:
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/ldap.rb:28:in initialize' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/ldap.rb:28:innew'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/ldap.rb:28:in connect' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/ldap.rb:58:inblock (2 levels) in connect'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:665:in block in log' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activesuppo rt-3.2.8/lib/active_support/notifications/instrumenter.rb:20:ininstrument'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:662:in log' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/ldap.rb:58:inblock in connect'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:52:in connect' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/ldap.rb:54:inconnect'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:582:in block in reconnect' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/base.rb:574:inloop'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:574:in reconnect' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/base.rb:611:inblock in reconnect_if_need'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/timeout.rb:54:in tim eout' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/ldap.rb:187:indo_in_timeout'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:317:in with_timeout' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/base.rb:610:inreconnect_if_need'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/adapter/base.rb:268:in operation' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/adapter/base.rb:118:inschema'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/connection.rb:165:in schema' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/object_class.rb:10:inblock in classes'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/object_class.rb:9:in collect' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap- 3.2.2/lib/active_ldap/object_class.rb:9:inclasses'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/gems/1.9.1/gems/activeldap-
3.2.2/lib/active_ldap/base.rb:497:in inspect' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/inspector.rb:86:i nblock in module:IRB'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/inspector.rb:30:i
n call' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/inspector.rb:30:i ninspect_value'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/context.rb:260:in
inspect_last_value' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:311:inoutput
_value'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:160:in block (2 levels) in eval_input' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:273:insignal
_status'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:156:in block in eval_input' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:243:i nblock (2 levels) in each_top_level_statement'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229:i
n loop' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:229:i nblock in each_top_level_statement'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228:i
n catch' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb/ruby-lex.rb:228:i neach_top_level_statement'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:155:in eval_i nput' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:70:inblock i
n start'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:69:in catch' C:/Users/test_user/.pik/rubies/Ruby-193-p194/lib/ruby/1.9.1/irb.rb:69:instart'
C:/Users/test_user/.pik/rubies/Ruby-193-p194/bin/irb:12:in `

'

It seems that the error is caused by the ssl encryption ( :method => :ssl ). Tried to trace it but did not yet succeed.

version of ruby: ruby 1.9.3p194 (2012-04-20) [i386-mingw32]
version of the activeldap gem is (3.2.2)

Thank you for any tips.

Migration not created when using railtie

Hello,

This might be a minor issue or even a misunderstanding, but I have problem that when i use

gem 'activeldap', :require => 'active_ldap/railtie'

in my gem file, following command

rails generate scaffold Thing name:string ...

will not not create migration file but all other scaffold files are created.
When using this line in Gemfile it works properly and migration is created:

gem 'activeldap'

But then activeldap is not working properly as the model and ldap.yml is not loaded.

Can anyone help?

Also the generator is saying "invoke active_ldap" on first line instead of "invoke active_record".

Thank you

DN attribute (uid) isn't set while adding new user in directory

While adding new user in directory I get error

<User objectClass:, must:, may:<>, objectClass: ["top"]>'s DN >attribute (uid) isn't set

Is there any thing I missed, please help me.
My model

class LdapUser < ActiveLdap::Base
ldap_mapping dn_attribute: "uid",
prefix: "ou=Users"
end

Large groups not working (over 1500 members)

Hello,

A bit older issue (already reported here - http://rubyforge.org/forum/forum.php?thread_id=45720&forum_id=1641) happened to me when listing group with over 1500 members.

Testing code:

require 'active_ldap'

ActiveLdap::Base.setup_connection(
  :host => 'ZZZ ad server ZZZ', 
  :port => 389, 
  :base => 'dc=ZZZ', 
  :bind_dn => 'ZZZ AD account ZZZ',
  :password => 'ZZZ',
  :allow_anonymous => false
)

class AdUser < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'cn', :prefix => 'dc=ZZZ', :classes => ['user'] 
  has_many :groups, :class_name => 'AdGroup', :wrap => "memberOf", :primary_key => 'dn'
end

class AdGroup < ActiveLdap::Base 
  ldap_mapping :dn_attribute => 'cn', :prefix => 'dc=ZZZ', :classes => ['group'] 
  has_many :members, :class_name => "AdUser", :wrap => "member", :primary_key => 'dn'
end

result = AdGroup.find(:all, :attribute => 'cn', :value => 'ZZZ Group with less than 1500 members ZZZ')
puts result.length
puts result[0].members[0]

result = AdGroup.find(:all, :attribute => 'cn', :value => 'ZZZ Group with over 1500 members ZZZ')
puts result.length
puts result[0].members[0]

And the result:

C:\Data>ruby -v
ruby 1.9.3p194 (2012-04-20) [i386-mingw32]

C:\Data>gem list |grep ldap
activeldap (3.2.2)
ruby-ldap (0.9.11 x86-mingw32)

C:\Data>rails -v
Rails 3.2.7

C:\Data>ruby "AD error.rb"
1
version: 1
dn:: Y249QVk4OVdVLE9VPVVzZXJzLE9VPUNaLGRjPWV1cm9wZSxkYz1pbnRyYW5ldA==
accountExpires: 9223372036854775807
badPasswordTime: 129894857663704260
badPwdCount: 0
c: ZZ
cn: ZZZZZZ
< .. text removed .. >

1
C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/distinguished_name.rb:20:in `initialize': invalid distinguished name (DN) to parse: 
{"range=0-1499"=>[CN=ZZZZZ,OU=Users,OU=ZZ,DC=ZZZZZZ,DC=ZZZZZZZ, CN=YYYY,OU=Removed Users,OU=ZZ,DC=ZZZZZZ,DC=ZZZZZZ, 
CN=MMMM,OU=Removed Users,OU=ZZ,DC=ZZZZZZ,DC=ZZZZZZ,
CN=NNNNN,OU=Users,OU=ZZ,DC=ZZZZZZ
< .. large text removed .. >
OU=ZZ,DC=ZZZZ,DC=ZZZZZ, CN=DDDDDD,OU=Group ailboxes,OU=ZZ,DC=ZZZZZ,DC=ZZZZZZ]} 
(ActiveLdap::DistinguishedNameInputInvalid)
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/distinguished_name.rb:163:in `new'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/distinguished_name.rb:163:in `parse'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/association/has_many_utils.rb:18:in `block in collect_targets'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/association/has_many_utils.rb:14:in `collect'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/association/has_many_utils.rb:14:in `collect_targets'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/association/has_many_wrap.rb:42:in `find_target'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/association/proxy.rb:83:in `load_target'
        from C:/Data/Devel/RubyStack/ruby/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/association/proxy.rb:58:in `method_missing'
        from AD error.rb:28:in `<main>'

Sensitive parts of code and output were removed due to company policy.

What I can estimate at my level is that at some point the LDAP server returns data in unexpected format resulting in HASH of arrays of members instead of just array or members. Currently I am not able to provide fix due insufficient knowledge of code structure (and no time to learn it).

May also be inner issue of ruby-ldap, in that case sorry for bothering.

Any suggestion or patch is welcome and can be tested.

Thank you
Borland

Unable to add users to roles - help please!

I have a simple LDAP directory with roles and users.
ou=Roles
+cn=ROLE_MANAGER
--roleOccupant = DN_OF_A_USER
--roleOccupant = DN_OF_ANOTHER_USER

ou=Users
+uid=tuser
--cn=Test User
--sn=User
--mail=[email protected]

I have created the follwoing extension classes:

#ldap_role.rb
class LdapRole < ActiveLdap::Base
  ldap_mapping :dn_attribute => "cn",
               :prefix => "ou=Roles",
               :classes => ["organizationalRole"]

  has_many :roleOccupants,
           :wrap => "roleOccupant",
           :class_name => "LdapUser"
end

#ldap_user.rb
class LdapUser < ActiveLdap::Base
  ldap_mapping :dn_attribute => "uid",
               :prefix => "ou=Users",
               :classes => ["organizationalPerson", "person", "inetOrgPerson", "extensibleObject", "uidObject"]

   belongs_to :ldap_roles,
              :class_name => "LdapRole",
              :many => 'roleOccupant'
end

I can lookup a user just fine:

user = LdapUser.find("tuser")

I can lookup a role fine:

managerRole = LdapRole.find("ROLE_MANAGER")

But when I try to either add a user to a role:

managerRole.roleOccupants << user

or add a role to the user:

user.ldap_roles = [managerRole]

I get this error:

ActiveLdap::DistinguishedNameInvalid: tuser is invalid distinguished name (DN): attribute value is missing

I am almost certain that this is in how I have setup my belongs_to and/or has_many in my classes, but I have tried EVERYTHING that I can think of or have found online. PLEASE HELP !?! :)

TypeError when creating a new entry

Hi there!

Overall, this gem works like a charm, this is great work! :)

However, when creating a new entry linked to another model via a :belongs_to relationship, I'm faced with a TypeError "can't convert true into Integer".

Editing an existing relationship is okay, but creating a new one pulls the aforementioned error.

This is the culprit, nothing fancy here, and the given array contains the values I want to insert into my models.

@group.members = group_params[:members]

When repeating the same steps from the Rails console (Ruby 1.9.3 and Rails 4.0.0), I get the following:

irb(main):003:0> group.members = [ 'anpop', 'joraf']
TypeError: can't convert String into Integer
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/has_many_wrap.rb:16:in `[]'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/has_many_wrap.rb:16:in `insert_entry'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/has_many_wrap.rb:67:in `block in add_entries'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/has_many_wrap.rb:65:in `each'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/has_many_wrap.rb:65:in `add_entries'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/collection.rb:19:in `<<'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/association/collection.rb:59:in `replace'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/activeldap-4.0.1/lib/active_ldap/associations.rb:172:in `members='
    from (irb):3
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
    from /home/apognu/.rvm/gems/ruby-1.9.3-p448/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Any ideas? Thanks for your help.

Regards, A.

Stop overriding config.app_generators.orm with :active_ldap.

Related to this line: https://github.com/activeldap/activeldap/blob/master/lib/active_ldap/railtie.rb#L9.

I don't know what's best practice for using ActiveLDAP, but it will be nice to at least mention, that orm generators are overridden. I'm using ActiveLDAP with ActiveRecord and this line prevented me to generate migration and ActiveRecord model for example. It is easy to rewrite it back to :activerecord in config/application.rb for example.

So the final question is: Is ActiveLDAP commonly used as a ActiveRecord replacement and is that line good default?

Help: Diagnosing Connection Problems

Okay, so I'm not really sure whether this is an issue with ActiveLdap or if I'm just doing something wrong but here's my problem:

I followed the instructions for getting ActiveLdap working with Rails, but now I am getting the following error whenever I try to access my ActiveLdap User model:

irb(main):001:0> User.all
ActiveLdap::ConnectionError: Giving up trying to reconnect to LDAP server.
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:597:in `block in reconnect'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:574:in `loop'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:574:in `reconnect'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:611:in `block in reconnect_if_need'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/timeout_stub.rb:6:in `alarm'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:333:in `do_in_timeout'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:317:in `with_timeout'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:610:in `reconnect_if_need'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:268:in `operation'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:167:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/net_ldap.rb:66:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:70:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:294:in `find_every'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:237:in `find'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:261:in `all'
        from (irb):1
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

This error message isn't very helpful, since it only tells me that ActiveLdap is having connection problems, it doesn't say why or give me any specifics.

If I call User.all again, I get a different error message for some reason:

irb(main):002:0> User.all
NoMethodError: undefined method `zero?' for #<Net::LDAP::PDU:0x30938e8>
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/net_ldap.rb:154:in `execute'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/net_ldap.rb:78:in `block in search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:168:in `block in search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:271:in `block in operation'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/timeout_stub.rb:6:in `alarm'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:333:in `do_in_timeout'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:317:in `with_timeout'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:270:in `operation'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/base.rb:167:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/adapter/net_ldap.rb:66:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:70:in `search'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:294:in `find_every'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:237:in `find'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeldap-3.2.2/lib/active_ldap/operations.rb:261:in `all'
        from (irb):2
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
        from c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'irb(main):003:0>

This is really odd behavior, and it seems more like an issue with ActiveLdap than the previous error message. (Or perhaps it's an issue with net-ldap?) Here's some other relevant information about my setup:

$ rails -v
Rails 3.2.12
$ ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

config/ldap.yml

development:
  host: 172.19.200.103
  port: 389
  method: :plain
  base: OU=Company Name (1001),DC=subdomain,DC=company,DC=com
  bind_dn: cn=LDAP BIND,ou=SPECIAL PURPOSE USERS AND GROUPS,dc=subdomain,dc=company,dc=com
  password: secretpassword
class User < ActiveLdap::Base
  ldap_mapping dn_attribute: "uid",
               prefix: "CN=Person,CN=Schema,CN=Configuration,ou=Users",
               classes: ["person"]
end

Also, the following code works just fine using just net-ldap (without ActiveLdap):

Net::LDAP.new(
    :host => '172.19.200.103',
    :port => 389,
    :auth => {
      :method => :simple,
      :username => "cn=LDAP BIND,ou=SPECIAL PURPOSE USERS AND GROUPS,dc=subdomain,dc=company,dc=com",
      :password => "secretpassword"
    }
  ).search(
      base: "OU=Company Name (1001),DC=subdomain,DC=company,DC=com",
      attributes: ['employeeID', 'displayName', 'mail'],
      filter: Net::LDAP::Filter.present("employeeID") & Net::LDAP::Filter.eq("objectClass", "person"),
      return_result:true
  )

Do you believe that I've found some sort of bug? Or am I just doing something wrong?

remove_class didn't work expected

# user class as in examples
user = User.new('qq')

# add new objectClass
user.add_class('inetOrgPerson')
# and it's attribute
user.givenname = 'name'

puts user.to_ldif # output
# version: 1
# dn: uid=qq...
# givenName: name
# objectClass: inetOrgPerson
# objectClass: person
# objectClass: posixAccount
# uid: qq

# removing just added objectClass
user.remove_class('inetOrgPerson')
puts user.to_ldif # output
# version: 1
# dn:: dWlkPXFxLG91PVBlb3BsZSxkYz1pbmYsZGM9dWcsZGM9ZWR1LGRjPXBs
# givenName: name
# objectClass: person
# objectClass: posixAccount
# uid: qq

objectClass: inetOrgPerson disapeared but givenName is still there which causes ObjectClassViolation when try to save

Disabled / Active attribute for a user object and time conversion issue?

Hello.

This is more of a questions then issue, but I can't find answer anywhere else. I should also mention that I'm working against Active Directory running on Windows 2003

  1. Which attribute should I check to see if the account is disabled or enabled?
    I've seen people recommending to use userAccountControl or pwd_account_locked_time - but the first attribute returns unexpected values and the second doesn't work for me.

  2. What format are all the time attributes in? How can I convert them to proper time?
    I thought they were just epoch - but apparently they are not. any idea?

Thank you

Suggestion for tutorial

I found that with Rails 3.1, the cleanest way to get ActiveLdap to load was to insert the following line into the Gemfile:

gem 'activeldap', :require => 'active_ldap/railtie'

Since railtie will include the rest of active_ldap, the whole system seems to get loaded up just fine. This seemed cleaner than adding a require line to application.rb.

ActiveLdap::UserPassword.valid? returns wrong result for encrypted password with long salt

Since RFC 3112 does not specify the length of salt, some implementations generates a very long string for salt.

ActiveLdap::UserPassword.valid? returns wrong result for it.

See below.

# sample encrypted password: 
#    algorithm: SSHA
#    salt: '60c5e35e-0dd1-4ba2-9629-de88208b1ffa'
#    password: 'hogehoge'
password = '{SSHA}Xv6pjZRomceAhB9T63biXDYoEKY2MGM1ZTM1ZS0wZGQxLTRiYTItOTYyOS1kZTg4MjA4YjFmZmE='

p ActiveLdap::UserPassword.valid?('hogehoge', password)
#=> false (wrong result)
p ActiveLdap::UserPassword.ssha('hogehoge', '60c5e35e-0dd1-4ba2-9629-de88208b1ffa')
#=> "{SSHA}Xv6pjZRomceAhB9T63biXDYoEKY2MGM1ZTM1ZS0wZGQxLTRiYTItOTYyOS1k\nZTg4MjA4YjFmZmE=" (contains unnecessary "\n")

I'll submit pull-request for this problem.

activeldap should not set Gettext.default_available_locales

Currently activeldap set Gettext.default_available_locales in get_text_support.rb. With FastGettext this means that no other translations will be considered, and as a consequence my Rails application no longer can use its 'nl' translations. After commenting out the three Gettext lines in that file my app works again as expected, although I must admin I have not tested the activeldap translations since I currently have no need for them.

As far as I understand FastGettext the settings in get_text_support.rb should not be done anyway because FastGettext only supports a single text domain, and additional domains should be put together using :chain in the main application.

cut down initialize time

Please consider patch inlined below. The boost for initialization in my test case is something like 20%.

The main idea is to go around hooked setter and slow respond_to? method. The bonus is remove of find_every from dirty module, because we are no longer dirtying when initializing.

diff --git a/lib/active_ldap/base.rb b/lib/active_ldap/base.rb
index 4c22d90..89661cf 100644
--- a/lib/active_ldap/base.rb
+++ b/lib/active_ldap/base.rb
@@ -1065,10 +1065,25 @@ module ActiveLdap
       classes, attributes = extract_object_class(attributes)
       self.classes = classes
       self.dn = dn
-      self.attributes = attributes
+      initialize_attributes(attributes)
       yield self if block_given?
     end

+    def initialize_attributes(attributes)
+      _schema = _local_entry_attribute = nil
+      targets = sanitize_for_mass_assignment(attributes)
+      targets.each do |key, value|
+        unless have_attribute?(key)
+          _schema ||= schema
+          attribute = _schema.attribute(key)
+          _local_entry_attribute ||= local_entry_attribute
+          _local_entry_attribute.register(attribute)
+        end
+        set_attribute(key, value)
+      end
+    end
+    private :initialize_attributes
+
     def instantiate(args)
       dn, attributes, options = args
       options ||= {}
diff --git a/lib/active_ldap/attribute_methods/dirty.rb b/lib/active_ldap/attribute_methods/dirty.rb
index 735e273..49e464b 100644
--- a/lib/active_ldap/attribute_methods/dirty.rb
+++ b/lib/active_ldap/attribute_methods/dirty.rb
@@ -28,16 +28,6 @@ module ActiveLdap
         end
       end

-      module ClassMethods
-        # dirty/clear hack
-        # only place that we can ovveride and hook to clear the new record
-        def find_every(options)
-          super.each do |result|
-            result.changed_attributes.clear
-          end
-        end
-      end
-
     protected
       def attribute=(attr, val)
         attribute_will_change!(attr) unless val == get_attribute(attr)

Unable to move entry in tree

Hi,

I want to implement a feature where user can move an entry around in the tree by editing an entry and selecting a new parent from a collection containing the other entries.

The DN of the entry being modified is DN: cn=dev,cn=hyperdrive,ou=Resources,dc=mantor,dc=org

But I'm getting the following error:

Failed to delete LDAP entry: <cn=dev,ou=Resources,dc=mantor,dc=org>: No such entry: ldap://127.0.0.1

when trying to update the entry using update_attributes[:params], with parent being a key in the params hash, holding the name of the selected new parent.

My System subclass has the following ldap_mapping:

class System < ActiveLdap::Base
    ldap_mapping  :dn_attribute => "cn",
                  :prefix => "ou=Resources",
                  :classes => %w[top device extensibleObject]
    alias_attribute :name, :cn

Any idea as if I should use something else or do something differently ?

I'm using openldap-2.4.31 on ubuntu-12.10 and the net-ldap (0.3.1) and activeldap (3.2.2) gems along with rails-3.2.10.

Thanks,

Attributes that match method names

I ran into an interesting issue today while trying out ActiveLdap with our AD server. We have added a custom "children" attribute to our employee records to allow us to enter names and birthdates for our employees' kids.

The issue is that when ActiveLdap::Base#attributes= gets called to insert the results of an LDAP search, it attempts to send the value to children=, which already exists, having been imported from ActiveLdap::Associations.

I dug through the code, but I didn't find any easy solution that wouldn't require some discussions regarding how to handle such cases -- would it be appropriate to automatically rename the attribute in the schema and the object to avoid conflict? Would it be appropriate to raise an exception when a conflicting name is detected? Should the developer be allowed to specify a mapping of conflicting names to new names in such cases?

Your thoughts?

double attribute "uid=uid=myuser" in has_many-relation

Hi!

I've got a strange error and I can't figure out what's going on there, so some help is appreciated:

Two Models:

class LdapUser < ActiveLdap::Base  
  ldap_mapping :dn_attribute => "uid",
               :prefix => "ou=users",
               :classes  => ['top', 'inetOrgPerson']
  belongs_to :groups, :class_name => 'LdapGroup', :many => 'uniqueMember', :primary_key => "dn"
end

class LdapGroup < ActiveLdap::Base
    ldap_mapping :dn_attribute => 'cn',
                 :prefix => 'ou=groups', :classes => ['top', 'groupOfUniqueNames'],
                 :scope => :one               
    has_many :members, :class_name => "LdapUser", :wrap => "uniqueMember"
end

The Ldap-Tree looks like this:
dc=my,dc=local
--ou=users
----uid=myuser
--ou=groups
----cn=mygroup, uniqueMember: "uid=myuser,ou=users,dc=my,dc=local"

Very basic indeed.

When I do LdapUser.first.groups.first everything is fine.
But LdapGroup.first.members.first returns an Ldap-Object, where only uid is set.

In the logs you see the faulty filter-condition:
{:limit=>nil, :scope=>:sub, :base=>"ou=users,dc=my,dc=local", :filter=>"(&(|(uid=uid=myuser,ou=users,dc=my,dc=local))(&(objectClass=inetOrgPerson)))", :attributes=>[]}

I think this somehow is connected with this issue: When I leave out "inetOrgPerson" (which requires uid), a ActiveLdap::UnknownAttribute-Exception with "uid is unknown attribute" is thrown.

My Guess is: ActiveLdap doesn't expect that the complete dn (uid=myuser,ou=users,dc=my,dc=local) is saved in uniqueMember, but that's just the way my directory is.

Has anyone a clue how to fix this?

Thanks in advance!

colides with ActiveModel::MassAssignmentSecurity naming

activeldap can't be currently used with ActiveModel::MassAssignmentSecurity

how to reproduce:

  include ActiveModel::MassAssignmentSecurity
end

both classes are defining class.protected_attributes method, which makes it impossible to find/mass assign attributes

Gem.available? called from activeldap-3.1.0/lib/active_ldap/connection.rb:214

activeldap-3.1.0 produces this deprecation warning on rails 3.1.x

.NOTE: Gem.available? is deprecated, use Specification::find_by_name. It will be removed on or after 2011-11-01.
Gem.available? called from /Users/xxxx/.rvm/gems/ruby-1.9.2-p290@xxxx/gems/activeldap-3.1.0/lib/active_ldap/connection.rb:214.

Regards

save! doesn't return "true" if nothing bad happens

When trying to use save! (expecting an exception to be raised if something bad happens), the return is unfortunately not "true", but rather, "nil":

irb(main):022:0> user.ldap_user.givenName
=> "John"
irb(main):023:0> ldapuser.givenName = "Jeff"
=> "Jeff"
irb(main):024:0> ldapuser.save!
=> nil
irb(main):025:0> user.ldap_user.givenName
=> "Jeff"

I'm pretty sure this should return "true" and not "nil". I am using 3.1.1

Not sure if it still does this in newer versions, but I am on Centos5 with old ruby and can't really update because of the ruby-ldap dependencies.

rails 3.0.x support ?

The current Activeldap Gemfile has gem 'activemodel', '~> 3.1.0.rc4' which makes it impossible to use with Rails 3.0.x. In the Readme, you simply state a dependency on ActiveRecord/ActiveModel without specifying a version.

Is this a firm dependency on 3.1.x, or would it be okay to ease the specified requirements ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.