From MR-Mencel at wiu.edu Fri Dec 7 16:48:48 2007 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Fri, 7 Dec 2007 15:48:48 -0600 (CST) Subject: [Ruby-activeldap-discuss] How do I list the values of all attributes? In-Reply-To: <20071201.102441.1992089962.kou@cozmixng.org> Message-ID: <1246945931.163801197064128395.JavaMail.root@zcs5.wiu.edu> OK...I got it figured out now and this works... user = User.find(uid) user.attributes.each do |attr, value| puts "#{attr}: #{value}" end This returns all attribute/value pairs and works great. I love it that multi-valued attributes are automatically stuck into an array...beautiful. Is there a way now to just retrieve the value of a specific attribute? I've tried a couple different combinations of the following... puts user.attribute("cn") puts user.attributes("cn") But I always get an error. Is there no function for just returning the "displayName" for example? Otherwise I have to stick some code in the user.attributes.each loop above to assign these as I parse through all of the attributes.... user.attributes.each do |attr, value| if attr == 'displayName' userDisplayName = value elseif attr == 'cn' userCn = value etc....... end It would be nice to be able to just reach into the user object to find the value for one attribute at a time. Probably there is...I'm just not doing it correctly. Thanks, Matt ----- Original Message ----- From: "Kouhei Sutou" To: ruby-activeldap-discuss at rubyforge.org Sent: Friday, November 30, 2007 7:24:41 PM (GMT-0600) America/Chicago Subject: Re: [Ruby-activeldap-discuss] How do I list the values of all attributes? Hi, In <125278062.3283221196445700478.JavaMail.root at zcs5.wiu.edu> "Re: [Ruby-activeldap-discuss] How do I list the values of all attributes?" on Fri, 30 Nov 2007 12:01:40 -0600 (CST), Matt Mencel wrote: > Here's the bind results. Doesn't look like it is trying to search for any user or return any attributes. Do I need to do a search to pull the LDAP data into the User object? Yes. Use User.find. Thanks, -- kou _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss From kou at cozmixng.org Fri Dec 7 20:36:57 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 08 Dec 2007 10:36:57 +0900 (JST) Subject: [Ruby-activeldap-discuss] How do I list the values of all attributes? In-Reply-To: <1246945931.163801197064128395.JavaMail.root@zcs5.wiu.edu> References: <20071201.102441.1992089962.kou@cozmixng.org> <1246945931.163801197064128395.JavaMail.root@zcs5.wiu.edu> Message-ID: <20071208.103657.1149280051.kou@cozmixng.org> Hi, > But I always get an error. Is there no function for just returning the "displayName" for example? Otherwise I have to stick some code in the user.attributes.each loop above to assign these as I parse through all of the attributes.... user.display_name Thanks, -- kou From MR-Mencel at wiu.edu Fri Dec 7 23:56:38 2007 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Fri, 7 Dec 2007 22:56:38 -0600 (CST) Subject: [Ruby-activeldap-discuss] How do I list the values of all attributes? In-Reply-To: <761951049.193681197089794522.JavaMail.root@zcs5.wiu.edu> Message-ID: <501133904.193701197089798635.JavaMail.root@zcs5.wiu.edu> What about custom attributes? We have a lot of custom attributes in our directory....for example one called... wiuRegisteredStar So from your example it would be... user.wiu_registered_star or does this not work if we use custom attributes? I'll have to try testing this later... I can't get to my dev system right now. Thanks, Matt ----- Original Message ----- From: "Kouhei Sutou" To: ruby-activeldap-discuss at rubyforge.org Sent: Friday, December 7, 2007 7:36:57 PM (GMT-0600) America/Chicago Subject: Re: [Ruby-activeldap-discuss] How do I list the values of all attributes? Hi, > But I always get an error. Is there no function for just returning the "displayName" for example? Otherwise I have to stick some code in the user.attributes.each loop above to assign these as I parse through all of the attributes.... user.display_name Thanks, -- kou _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss From MR-Mencel at wiu.edu Mon Dec 10 12:20:21 2007 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Mon, 10 Dec 2007 11:20:21 -0600 (CST) Subject: [Ruby-activeldap-discuss] How do I list the values of all attributes? In-Reply-To: <501133904.193701197089798635.JavaMail.root@zcs5.wiu.edu> Message-ID: <1429105469.328241197307221961.JavaMail.root@zcs5.wiu.edu> Awesome....this works as you indicated... user.wiu_registered_star Wonderful!! Just a side note...and suggestion for the mailing list. Can you make it so that when we hit "Reply" in our mail client, it makes it a reply to the list, and not a reply to the original sender. Currently I have to choose "Reply-All", then cut the list address out of the CC line and paste it into the TO line. There should be a list config setting that controls this. Thanks, Matt ----- Original Message ----- From: "Matt Mencel" To: ruby-activeldap-discuss at rubyforge.org Sent: Friday, December 7, 2007 10:56:38 PM (GMT-0600) America/Chicago Subject: Re: [Ruby-activeldap-discuss] How do I list the values of all attributes? What about custom attributes? We have a lot of custom attributes in our directory....for example one called... wiuRegisteredStar So from your example it would be... user.wiu_registered_star or does this not work if we use custom attributes? I'll have to try testing this later... I can't get to my dev system right now. Thanks, Matt ----- Original Message ----- From: "Kouhei Sutou" To: ruby-activeldap-discuss at rubyforge.org Sent: Friday, December 7, 2007 7:36:57 PM (GMT-0600) America/Chicago Subject: Re: [Ruby-activeldap-discuss] How do I list the values of all attributes? Hi, > But I always get an error. Is there no function for just returning the "displayName" for example? Otherwise I have to stick some code in the user.attributes.each loop above to assign these as I parse through all of the attributes.... user.display_name Thanks, -- kou _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss From davide.vaghetti at unipi.it Tue Dec 11 03:15:30 2007 From: davide.vaghetti at unipi.it (Davide Vaghetti) Date: Tue, 11 Dec 2007 09:15:30 +0100 Subject: [Ruby-activeldap-discuss] How do I list the values of all attributes? In-Reply-To: <1429105469.328241197307221961.JavaMail.root@zcs5.wiu.edu> References: <1429105469.328241197307221961.JavaMail.root@zcs5.wiu.edu> Message-ID: <475E4722.7030900@unipi.it> Matt Mencel wrote: > Awesome....this works as you indicated... > > user.wiu_registered_star > > Wonderful!! > > Just a side note...and suggestion for the mailing list. Can you make it so that when we hit "Reply" in our mail client, it makes it a reply to the list, and not a reply to the original sender. Currently I have to choose "Reply-All", then cut the list address out of the CC line and paste it into the TO line. There should be a list config setting that controls this. > In my mailman version the option is "Explicit Reply-To: header." in the General Options. bye davide -- Davide Vaghetti Centro SerRA - University of Pisa NOC From ipople at unimelb.edu.au Sun Dec 16 21:37:13 2007 From: ipople at unimelb.edu.au (Iain Pople) Date: Mon, 17 Dec 2007 13:37:13 +1100 Subject: [Ruby-activeldap-discuss] can't change DN Message-ID: <4765E0D9.1020808@unimelb.edu.au> Hi, I have an ActiveLDAP object as follows: class Host < ActiveLdap::Base ldap_mapping :dn_attribute => 'unimelbipreghost', :prefix => 'ou=Resources', :classes => ['top', 'unimelbipreghostdata'], :scope => :sub end I have found that I can't change the DN of this object: >> host = Host.find("host.unimelb.edu.au") >> host.unimelbipreghost = "newhost.unimelb.edu.au" >> host.save ActiveLdap::LdapError::NoSuchObject: No such object from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/ldap_ext.rb:66:in `assert_error_code' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/ldap.rb:142:in `execute' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/ldap.rb:121:in `modify' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/base.rb:184:in `modify' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/base.rb:202:in `operation' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/timeout.rb:15:in `call' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/timeout.rb:15:in `alarm' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/base.rb:237:in `with_timeout' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/ldap.rb:149:in `with_timeout' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/base.rb:201:in `operation' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/base.rb:183:in `modify' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/adapter/ldap.rb:120:in `modify' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/base.rb:430:in `modify' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/base.rb:1497:in `update_without_callbacks' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/base.rb:1462:in `prepare_data_for_saving' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/base.rb:1493:in `update_without_callbacks' from /usr/local/ruby-1.8.6/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/callbacks.rb:267:in `update' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/base.rb:1443:in `create_or_update_without_callbacks' from /usr/local/ruby-1.8.6/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/callbacks.rb:242:in `create_or_update' from /usr/local/ruby-1.8.6/lib/ruby/site_ruby/1.8/active_ldap/base.rb:892:in `save_without_validation' from /usr/local/ruby-1.8.6/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/validations.rb:752:in `save' From kou at cozmixng.org Mon Dec 17 06:47:10 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Mon, 17 Dec 2007 20:47:10 +0900 (JST) Subject: [Ruby-activeldap-discuss] can't change DN In-Reply-To: <4765E0D9.1020808@unimelb.edu.au> References: <4765E0D9.1020808@unimelb.edu.au> Message-ID: <20071217.204710.876124214793141471.kou@cozmixng.org> Hi, In <4765E0D9.1020808 at unimelb.edu.au> "[Ruby-activeldap-discuss] can't change DN" on Mon, 17 Dec 2007 13:37:13 +1100, Iain Pople wrote: > I have found that I can't change the DN of this object: > > >> host = Host.find("host.unimelb.edu.au") > >> host.unimelbipreghost = "newhost.unimelb.edu.au" > >> host.save Modifying RDN is supported in trunk: Host.modify_rdn_entry(host.dn, "newhost.unimelb.edu.au", true, nil) But the API isn't stable yet. I'll change the API. Thanks, -- kou From ipople at unimelb.edu.au Mon Dec 17 18:22:43 2007 From: ipople at unimelb.edu.au (Iain Pople) Date: Tue, 18 Dec 2007 10:22:43 +1100 Subject: [Ruby-activeldap-discuss] can't change DN In-Reply-To: <20071217.204710.876124214793141471.kou@cozmixng.org> References: <4765E0D9.1020808@unimelb.edu.au> <20071217.204710.876124214793141471.kou@cozmixng.org> Message-ID: <476704C3.3040107@unimelb.edu.au> Ok. It doesn't look like this is supported in 0.90 ? Although there does seem to be a method modrdn on the object itself. i.e. host.modrdn( ??? ) Kouhei Sutou wrote: > Hi, > > In <4765E0D9.1020808 at unimelb.edu.au> > "[Ruby-activeldap-discuss] can't change DN" on Mon, 17 Dec 2007 13:37:13 +1100, > Iain Pople wrote: > >> I have found that I can't change the DN of this object: >> >> >> host = Host.find("host.unimelb.edu.au") >> >> host.unimelbipreghost = "newhost.unimelb.edu.au" >> >> host.save > > Modifying RDN is supported in trunk: > > Host.modify_rdn_entry(host.dn, "newhost.unimelb.edu.au", true, nil) > > But the API isn't stable yet. I'll change the API. > > > Thanks, > -- > kou > _______________________________________________ > Ruby-activeldap-discuss mailing list > Ruby-activeldap-discuss at rubyforge.org > http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss -- Iain Pople Systems Interface Technical Lead University of Melbourne (p) 8344 3522 From kou at cozmixng.org Mon Dec 17 18:37:26 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 18 Dec 2007 08:37:26 +0900 (JST) Subject: [Ruby-activeldap-discuss] can't change DN In-Reply-To: <476704C3.3040107@unimelb.edu.au> References: <4765E0D9.1020808@unimelb.edu.au> <20071217.204710.876124214793141471.kou@cozmixng.org> <476704C3.3040107@unimelb.edu.au> Message-ID: <20071218.083726.52326764695020820.kou@cozmixng.org> Hi, > Ok. It doesn't look like this is supported in 0.90 ? This change will be in 0.9.1. > Although there does > seem to be a method modrdn on the object itself. > > i.e. > > host.modrdn( ??? ) Yes. I'll use #rename and #copy not #modrdn. Thanks, -- kou From me at bjeanes.com Wed Dec 19 22:15:13 2007 From: me at bjeanes.com (Bodaniel Jeanes) Date: Thu, 20 Dec 2007 13:15:13 +1000 Subject: [Ruby-activeldap-discuss] Establish_connection behaviour Message-ID: I have been trying to figure out the best way to authenticate against LDAP using the ActiveLdap library. Unfortunately the information in http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateViaLdap is evidently very outdated. I have been trying to use establish_connection to try to do the same thing but there are some things that make it hard. Namely, establish_connection returns nil instead of a boolean and I can't get it to return an AuthenticationError no matter what bogus credentials I pass. At first I thought that even if it is failing islently it's ok because I can just call "connected?". Of course that presents new problems. Observe: is-dev$ script/console Loading development environment (Rails 2.0.1) >> User.connected? => false >> User.establish_connection => nil >> User.connected? => false >> User.find("bjeanes"); nil #this is custom overriden #find (see below) => nil >> User.connected? => true It seems that calling establish_connection (with or without options) does not change the connected state. As far as I can tell, it does nothing except return nil. I've been trolling through the ActiveLdap source trying to see how calling find (which calls find_every, then search, then some other search then i got lost) starts the connection when one doesn't exist but can't emulate this in my own code. Most methods used I can't access (bind, connect, disconnect!) anyway. Even if i could do the connected? check to see if a new bind was successful, i would have to drop any existing connections (something i also can't seem to force), then bind, check status, and restore the configuration-based connection. Here is my User model for reference (i've changed the find method just to make it more convenient for me since other than authentication, it will primarily be used for a staff directory [User.find("bjeanes").title :-)]) class User < ActiveLdap::Base ldap_mapping :dn_attribute => "cn", :prefix => "OU=Cutting Edge", :classes => ['top','user','person'], :scope => :sub def self.find(*args) return super(args) if args.length > 1 or args.first.class == Symbol attribute = case args.first.class.to_s # for some reason it never matches if it compares classes when "Fixnum": "uSNCreated" when "String": "sAMAccountName" else return nil end super(:first, :attribute => attribute, :value => args.first.to_s) # make sure it's a string end # was hoping establish_connection would raise an error here that could be rescued, # or actually CHANGED the connection state: def self.login(user,pass) establish_connection(:bind_dn => user, :password => pass) return connected? rescue false end end Any ideas? Using version 0.9.0 From jlehman at admin.usf.edu Wed Dec 19 22:16:11 2007 From: jlehman at admin.usf.edu (Jason Lehman) Date: Wed, 19 Dec 2007 22:16:11 -0500 Subject: [Ruby-activeldap-discuss] uninitialized constant ActiveLdap::Base::Reloadable Message-ID: I am receiving the following error: uninitialized constant ActiveLdap::Base::Reloadable When I do a "irb require 'active_ldap'". This started occuring after upgrading to Rails 2.0. Is there a way to fix this? Thanks for any help. From jeremypruitt at mac.com Thu Dec 20 05:18:29 2007 From: jeremypruitt at mac.com (Jeremy Pruitt) Date: Thu, 20 Dec 2007 02:18:29 -0800 Subject: [Ruby-activeldap-discuss] Trouble with has_many in my Group model Message-ID: I have looked over threads and tutorials on activeldap in search for an answer to my problem, and while it is probably very simple and right in front of me I am at the point where I need to ask for some help. Thanks in advance for any assistance you can provide. :) First off, here's my Group model: class AuthLdapGroup < ActiveLdap::Base ldap_mapping :dn_attribute => "cn", :prefix => "ou=groups", :classes => ["groupOfNames", "authorizationGroup"] has_many :members, :class => 'AuthLdapUser', :wrap => 'member', :primary_key => 'dn' end And here's my User model: class AuthLdapUser < ActiveLdap::Base ldap_mapping :dn_attribute => "uid", :prefix => "ou=people", :classes => ["inetOrgPerson"], :scope => :sub belongs_to :groups, :class => 'AuthLdapGroup', :many => 'member', :foreign_key => 'dn' end And here is where I grab a Group object in my controller: @group = AuthLdapGroup.find(params[:permalink]) And here is how I use it in my view: <% @group.members.each do |member| %> <%= member.to_s %> <% end %> Obviously to_s isn't necessarily the most appropriate method, but it shouldn't break things and the error is happening on the "@group.members.each do |member|" line anyway. This is the error I'm getting when I access the show page: '#"authldapplaceholder"}, {"ou"=>"people"}, {"dc"=>"foobar"}, {"dc"=>"net"}]>' must be either nil, DN value as String or Array or attributes as Hash Things work well, otherwise. I can list all groups, I can list all users, I can list all groups for a given user, but I can't seem to list all users in a given group. I should also note that my schema is similar to one mentioned in a previous thread in that the "members" of a group are actually DNs of users and not their usernames. For instance here's a dump of part of a group: dn: - authGroupName=eng-friends-sales,ou=authorizationgroups,ou=groups,dc=foobar,dc=net cn: - eng-friends-sales authGroupName: - eng-friends-sales member: - uid=authldapplaceholder,ou=people,dc=foobar,dc=net - uid=pesposito,ou=people,dc=foobar,dc=net - uid=borr,ou=people,dc=foobar,dc=net Just to be clear, I am not using the net_ldap adapter, which seemed to cause problems for the person in the thread I mentioned above. Any help is much appreciated as I really like working with activeldap. From kou at cozmixng.org Thu Dec 27 09:09:43 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Thu, 27 Dec 2007 23:09:43 +0900 (JST) Subject: [Ruby-activeldap-discuss] Establish_connection behaviour In-Reply-To: References: Message-ID: <20071227.230943.969981366266496128.kou@cozmixng.org> Hi, In "[Ruby-activeldap-discuss] Establish_connection behaviour" on Thu, 20 Dec 2007 13:15:13 +1000, "Bodaniel Jeanes" wrote: > I have been trying to figure out the best way to authenticate against > LDAP using the ActiveLdap library. Unfortunately the information in > http://wiki.rubyonrails.org/rails/pages/HowtoAuthenticateViaLdap is > evidently very outdated. I have been trying to use > establish_connection to try to do the same thing but there are some > things that make it hard. See an example Rails application: http://ruby-activeldap.googlecode.com/svn/trunk/examples/al-admin/app/models/ldap_user.rb There is ActiveLdap::Base#bind for your propose since 0.9.0. Before 0.9.0, ActiveLdap::Base.establish_connection and/or ActiveLdap::Base#establish_connection are used for that. Thanks, -- kou From kou at cozmixng.org Thu Dec 27 09:23:55 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Thu, 27 Dec 2007 23:23:55 +0900 (JST) Subject: [Ruby-activeldap-discuss] uninitialized constant ActiveLdap::Base::Reloadable In-Reply-To: References: Message-ID: <20071227.232355.172152087921162837.kou@cozmixng.org> Hi, In "[Ruby-activeldap-discuss] uninitialized constant ActiveLdap::Base::Reloadable" on Wed, 19 Dec 2007 22:16:11 -0500, Jason Lehman wrote: > I am receiving the following error: > uninitialized constant ActiveLdap::Base::Reloadable > > When I do a "irb require 'active_ldap'". This started occuring after > upgrading to Rails 2.0. Is there a way to fix this? What version are you using? 0.9.0 should work with ActiveSupport 2.0. Thanks, -- kou From kou at cozmixng.org Thu Dec 27 09:37:42 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Thu, 27 Dec 2007 23:37:42 +0900 (JST) Subject: [Ruby-activeldap-discuss] Trouble with has_many in my Group model In-Reply-To: References: Message-ID: <20071227.233742.232442779035061334.kou@cozmixng.org> Hi, In "[Ruby-activeldap-discuss] Trouble with has_many in my Group model" on Thu, 20 Dec 2007 02:18:29 -0800, Jeremy Pruitt wrote: > <% @group.members.each do |member| %> > <%= member.to_s %> > <% end %> > > Obviously to_s isn't necessarily the most appropriate method, but it shouldn't break things and the error is happening on the "@group.members.each do |member|" line anyway. This is the error I'm getting when I access the show page: > > '#"authldapplaceholder"}, {"ou"=>"people"}, {"dc"=>"foobar"}, {"dc"=>"net"}]>' must be either nil, DN value as String or Array or attributes as Hash I see the problem and cause. I'll fix this tomorrow. Thanks, -- kou From kou at cozmixng.org Thu Dec 27 22:30:25 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Fri, 28 Dec 2007 12:30:25 +0900 (JST) Subject: [Ruby-activeldap-discuss] Trouble with has_many in my Group model In-Reply-To: <20071227.233742.232442779035061334.kou@cozmixng.org> References: <20071227.233742.232442779035061334.kou@cozmixng.org> Message-ID: <20071228.123025.741303881773787601.kou@cozmixng.org> Hi, In <20071227.233742.232442779035061334.kou at cozmixng.org> "Re: [Ruby-activeldap-discuss] Trouble with has_many in my Group model" on Thu, 27 Dec 2007 23:37:42 +0900 (JST), Kouhei Sutou wrote: > > <% @group.members.each do |member| %> > > <%= member.to_s %> > > <% end %> > > > > Obviously to_s isn't necessarily the most appropriate method, but it shouldn't break things and the error is happening on the "@group.members.each do |member|" line anyway. This is the error I'm getting when I access the show page: > > > > '#"authldapplaceholder"}, {"ou"=>"people"}, {"dc"=>"foobar"}, {"dc"=>"net"}]>' must be either nil, DN value as String or Array or attributes as Hash > > I see the problem and cause. I'll fix this tomorrow. I've fixed in trunk. Thanks, -- kou From mortonda at dgrmm.net Fri Dec 28 12:50:31 2007 From: mortonda at dgrmm.net (David Morton) Date: Fri, 28 Dec 2007 11:50:31 -0600 Subject: [Ruby-activeldap-discuss] error starting out Message-ID: <47753767.9060300@dgrmm.net> I'm running on OSX, I updated my gems to 1.0.1 and activeldap to 0.9.0, and rails to 2.0.2 Just doing the simple example, I get: /Library/Ruby/Gems/1.8/gems/activeldap-0.9.0/lib/active_ldap.rb:924: warning: already initialized constant VERSION LoadError: Expected /Library/Ruby/Gems/1.8/gems/activeldap-0.9.0/lib/active_ldap.rb to define ActiveLDAP from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:249:in `load_missing_constant' from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing' from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in `const_missing' from (irb):2 any ideas? From kou at cozmixng.org Fri Dec 28 21:51:56 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 29 Dec 2007 11:51:56 +0900 (JST) Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <47753767.9060300@dgrmm.net> References: <47753767.9060300@dgrmm.net> Message-ID: <20071229.115156.513469899591057364.kou@cozmixng.org> Hi, In <47753767.9060300 at dgrmm.net> "[Ruby-activeldap-discuss] error starting out" on Fri, 28 Dec 2007 11:50:31 -0600, David Morton wrote: > I'm running on OSX, I updated my gems to 1.0.1 and activeldap to 0.9.0, > and rails to 2.0.2 > > Just doing the simple example, I get: > > > /Library/Ruby/Gems/1.8/gems/activeldap-0.9.0/lib/active_ldap.rb:924: > warning: already initialized constant VERSION > LoadError: Expected > /Library/Ruby/Gems/1.8/gems/activeldap-0.9.0/lib/active_ldap.rb to > define ActiveLDAP Are you using ActiveLDAP::XXX not ActiveLdap::XXX? We're using ActiveLdap since 0.8.0 because there was big API changes. Thanks, -- kou From mortonda at dgrmm.net Fri Dec 28 22:09:19 2007 From: mortonda at dgrmm.net (David Morton) Date: Fri, 28 Dec 2007 21:09:19 -0600 Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <20071229.115156.513469899591057364.kou@cozmixng.org> References: <47753767.9060300@dgrmm.net> <20071229.115156.513469899591057364.kou@cozmixng.org> Message-ID: <4775BA5F.9090104@dgrmm.net> Kouhei Sutou wrote: > Hi, > > In <47753767.9060300 at dgrmm.net> > "[Ruby-activeldap-discuss] error starting out" on Fri, 28 Dec 2007 11:50:31 -0600, > David Morton wrote: > > >> I'm running on OSX, I updated my gems to 1.0.1 and activeldap to 0.9.0, >> and rails to 2.0.2 >> >> Just doing the simple example, I get: >> >> >> /Library/Ruby/Gems/1.8/gems/activeldap-0.9.0/lib/active_ldap.rb:924: >> warning: already initialized constant VERSION >> LoadError: Expected >> /Library/Ruby/Gems/1.8/gems/activeldap-0.9.0/lib/active_ldap.rb to >> define ActiveLDAP >> > > Are you using ActiveLDAP::XXX not ActiveLdap::XXX? > > We're using ActiveLdap since 0.8.0 because there was big API > changes. > > > Ah that was part of it. I tried both ways and had errors. With ActiveLdap, I can almost get it to work, but it doesn't like the scope indentifier: :scope => LDAP::LDAP_SCOPE_SUBTREE It says NameError: uninitialized constant SentUser::LDAP From kou at cozmixng.org Fri Dec 28 22:17:55 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 29 Dec 2007 12:17:55 +0900 (JST) Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <4775BA5F.9090104@dgrmm.net> References: <47753767.9060300@dgrmm.net> <20071229.115156.513469899591057364.kou@cozmixng.org> <4775BA5F.9090104@dgrmm.net> Message-ID: <20071229.121755.218917596155147934.kou@cozmixng.org> Hi, In <4775BA5F.9090104 at dgrmm.net> "Re: [Ruby-activeldap-discuss] error starting out" on Fri, 28 Dec 2007 21:09:19 -0600, David Morton wrote: > :scope => LDAP::LDAP_SCOPE_SUBTREE Use :sub instead of LDAP::LDAP_SCOPE_SUBTREE. Thanks, -- kou From mortonda at dgrmm.net Sat Dec 29 01:46:41 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 00:46:41 -0600 Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <20071229.121755.218917596155147934.kou@cozmixng.org> References: <47753767.9060300@dgrmm.net> <20071229.115156.513469899591057364.kou@cozmixng.org> <4775BA5F.9090104@dgrmm.net> <20071229.121755.218917596155147934.kou@cozmixng.org> Message-ID: <4775ED51.4090009@dgrmm.net> Kouhei Sutou wrote: > Hi, > > In <4775BA5F.9090104 at dgrmm.net> > "Re: [Ruby-activeldap-discuss] error starting out" on Fri, 28 Dec 2007 21:09:19 -0600, > David Morton wrote: > > >> :scope => LDAP::LDAP_SCOPE_SUBTREE >> > > Use :sub instead of LDAP::LDAP_SCOPE_SUBTREE. > Ok, that works. The documentation on the main activeldap.rb page needs to be updated. I finally got some info out of the directory - I had to adapt to some API changes. I last worked with activeLdap a year ago, it seems a lot has changed since then. One question now. I have a hierarchy of data, so there's obviously a has_many relation as you go down each branch in the tree. I have belongs_to working to go up the tree, but has_many is giving me fits. There's no "list" of members in the subtree, it just needs to match all the submembers. All sub members should have an attribute that indicates they belong to the group (which is how the belongs_to works). How do I specify it? The docs seem to say: class Group < ActiveLdap::Base ... has_many :users, :class_name => "User", :primary_key => "gidNumber", # User#gidNumber :foreign_key => "gidNumber" # Group#gidNumber end This assumes that both the Group and all of its users have a common gidNumber. However, I can't seem to get it to work. From kou at cozmixng.org Sat Dec 29 01:55:07 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 29 Dec 2007 15:55:07 +0900 (JST) Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <4775ED51.4090009@dgrmm.net> References: <4775BA5F.9090104@dgrmm.net> <20071229.121755.218917596155147934.kou@cozmixng.org> <4775ED51.4090009@dgrmm.net> Message-ID: <20071229.155507.678048105737763737.kou@cozmixng.org> Hi, In <4775ED51.4090009 at dgrmm.net> "Re: [Ruby-activeldap-discuss] error starting out" on Sat, 29 Dec 2007 00:46:41 -0600, David Morton wrote: > >> :scope => LDAP::LDAP_SCOPE_SUBTREE > >> > > > > Use :sub instead of LDAP::LDAP_SCOPE_SUBTREE. > > > > Ok, that works. The documentation on the main activeldap.rb page needs > to be updated. Where? If you give us a patch, I'll apply the patch. > One question now. > > I have a hierarchy of data, so there's obviously a has_many relation as > you go down each branch in the tree. > > I have belongs_to working to go up the tree, but has_many is giving me > fits. There's no "list" of members in the subtree, it just needs to > match all the submembers. All sub members should have an attribute that > indicates they belong to the group (which is how the belongs_to works). > How do I specify it? The docs seem to say: Could you show us an example situation with sample data? Thanks, -- kou From mortonda at dgrmm.net Sat Dec 29 02:29:47 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 01:29:47 -0600 Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <20071229.155507.678048105737763737.kou@cozmixng.org> References: <4775BA5F.9090104@dgrmm.net> <20071229.121755.218917596155147934.kou@cozmixng.org> <4775ED51.4090009@dgrmm.net> <20071229.155507.678048105737763737.kou@cozmixng.org> Message-ID: <4775F76B.2090702@dgrmm.net> Kouhei Sutou wrote: > >> >> I have a hierarchy of data, so there's obviously a has_many relation as >> you go down each branch in the tree. >> >> I have belongs_to working to go up the tree, but has_many is giving me >> fits. There's no "list" of members in the subtree, it just needs to >> match all the submembers. All sub members should have an attribute that >> indicates they belong to the group (which is how the belongs_to works). >> How do I specify it? The docs seem to say: >> > > Could you show us an example situation with sample data? > > (I'm reading docs from: http://ruby-activeldap.rubyforge.org/doc/) Well, here's a contrived example similar to what I'm doing: (assume ldap schema has been created and is working... I haven't actually tested this code, but it's very similar) dn: group=test, dc=example,dc=com objectClass: group group: test dn: user=user1,group=test,dc=example,dc=com objectClass: user user: user1 group: test dn: user=user2group=test,dc=example,dc=com objectClass: user user: user2 group: test class User < ActiveLdap::Base ldap_mapping :dn_attribute => 'user', :prefix => '', :classes => ['user'] belongs_to :group, :class => 'Group', :many => 'group', :foreign_key => 'group' end class Group < ActiveLdap::Base ldap_mapping :dn_attribute => 'group', :prefix => '', :classes => ['group'] has_many :users, :class => 'User', :primary_key => 'group', :foreign_key => 'group' end So I should be able to do something crazy like: >> puts User.find(:first).group[0].users[0].group[0].group test >> puts User.find(:first).group[0].users[1].user user2 >> As it is, I get nil or empty errors. In the ldap debug log, I'm seeing some weird searches: (&(group=group=test,dc=example,dc=com)(objectClass=user)) So I think it's generating the filter wrong... I just can't quite wrap my head around the associations class magic yet. From kou at cozmixng.org Sat Dec 29 07:52:28 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 29 Dec 2007 21:52:28 +0900 (JST) Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <4775F76B.2090702@dgrmm.net> References: <4775ED51.4090009@dgrmm.net> <20071229.155507.678048105737763737.kou@cozmixng.org> <4775F76B.2090702@dgrmm.net> Message-ID: <20071229.215228.83341388756467387.kou@cozmixng.org> Hi, In <4775F76B.2090702 at dgrmm.net> "Re: [Ruby-activeldap-discuss] error starting out" on Sat, 29 Dec 2007 01:29:47 -0600, David Morton wrote: > >> I have a hierarchy of data, so there's obviously a has_many relation as > >> you go down each branch in the tree. > >> > >> I have belongs_to working to go up the tree, but has_many is giving me > >> fits. There's no "list" of members in the subtree, it just needs to > >> match all the submembers. All sub members should have an attribute that > >> indicates they belong to the group (which is how the belongs_to works). > >> How do I specify it? The docs seem to say: > >> > > > > Could you show us an example situation with sample data? > > > > > (I'm reading docs from: http://ruby-activeldap.rubyforge.org/doc/) Thanks. I've updated. > Well, here's a contrived example similar to what I'm doing: (assume ldap > schema has been created and is working... I haven't actually tested this > code, but it's very similar) > class User < ActiveLdap::Base > ldap_mapping :dn_attribute => 'user', :prefix => '', :classes => ['user'] > belongs_to :group, :class => 'Group', :many => 'group', :foreign_key > => 'group' > end > As it is, I get nil or empty errors. In the ldap debug log, I'm seeing > some weird searches: > > (&(group=group=test,dc=example,dc=com)(objectClass=user)) Thanks for showing. What about that? (group -> groups) class User < ActiveLdap::Base ... belongs_to :groups, :class => 'Group', :many => 'group', :foreign_key => 'group' end Thanks, -- kou From mortonda at dgrmm.net Sat Dec 29 08:49:04 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 07:49:04 -0600 Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <20071229.215228.83341388756467387.kou@cozmixng.org> References: <4775ED51.4090009@dgrmm.net> <20071229.155507.678048105737763737.kou@cozmixng.org> <4775F76B.2090702@dgrmm.net> <20071229.215228.83341388756467387.kou@cozmixng.org> Message-ID: <47765050.2020808@dgrmm.net> Kouhei Sutou wrote: > >> As it is, I get nil or empty errors. In the ldap debug log, I'm seeing >> some weird searches: >> >> (&(group=group=test,dc=example,dc=com)(objectClass=user)) >> > > Thanks for showing. What about that? (group -> groups) > > class User < ActiveLdap::Base > ... > belongs_to :groups, :class => 'Group', :many => 'group', :foreign_key => 'group' > end > The belongs_to part worked ok, it's the has_many that I can't figure out... From mortonda at dgrmm.net Sat Dec 29 09:41:59 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 08:41:59 -0600 Subject: [Ruby-activeldap-discuss] error starting out In-Reply-To: <4775F76B.2090702@dgrmm.net> References: <4775BA5F.9090104@dgrmm.net> <20071229.121755.218917596155147934.kou@cozmixng.org> <4775ED51.4090009@dgrmm.net> <20071229.155507.678048105737763737.kou@cozmixng.org> <4775F76B.2090702@dgrmm.net> Message-ID: <47765CB7.8030000@dgrmm.net> David Morton wrote: > > As it is, I get nil or empty errors. In the ldap debug log, I'm seeing > some weird searches: > > (&(group=group=test,dc=example,dc=com)(objectClass=user)) > > So I think it's generating the filter wrong... I just can't quite wrap > my head around the associations class magic yet. > I also just noticed, that if the attribute "group" above is changed to "myGroup" throughout my example, the query has a funny caps: (&(myGroup=mygroup=test,dc=example,dc=com)(objectClass=user)) ahhhhh I found it. I had a typo in my ldap_mapping call, in the dn_attribute. It didn't exist, so it was throwing the dn_attribute in there instead of the key I was looking for. When I fixed the typo, the query looks correct: (&(myGroup=test)(objectClass=user) From mortonda at dgrmm.net Sat Dec 29 11:14:54 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 10:14:54 -0600 Subject: [Ruby-activeldap-discuss] using multiple credentials Message-ID: <4776727E.5040203@dgrmm.net> I need to re-bind on every request depending on the user logged in - the ldap server has acls to help limit the data available per login. a year ago, this was how I achieved it; it doesn't work now - so how do I store that connection now? ActiveLdap::Base.establish_connection( ... ) @@con=ActiveLdap::Base.connection #save master connection, used to look up login info begin # set user_dn ... get password #requires some ldap searches via master conenction ActiveLdap::Base.bind( :host => HOST, :base => BASEDN, :bind_dn => "%s", :user => user_dn, :password_block => Proc.new { password }, :allow_anonymous => false ) session[:dn] = user_dn session[:pass] = password #... rescue #connection failed, bad login flash[:message] = "login failure: #$!" flash[:username] = username flash[:password] = password ActiveLDAP::Base.connection=@@con #restore master connection redirect_to(:action => "index") and return false return end ActiveLdap::Base.connection=@@con #restore master connection #redirect to application main page Then a before filter binds on every request, storing the master connection every time, and restoring it after the request is done. From kou at cozmixng.org Sat Dec 29 20:45:59 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sun, 30 Dec 2007 10:45:59 +0900 (JST) Subject: [Ruby-activeldap-discuss] using multiple credentials In-Reply-To: <4776727E.5040203@dgrmm.net> References: <4776727E.5040203@dgrmm.net> Message-ID: <20071230.104559.1040217551023407791.kou@cozmixng.org> Hi, In <4776727E.5040203 at dgrmm.net> "[Ruby-activeldap-discuss] using multiple credentials" on Sat, 29 Dec 2007 10:14:54 -0600, David Morton wrote: > I need to re-bind on every request depending on the user logged in - the > ldap server has acls to help limit the data available per login. a year > ago, this was how I achieved it; it doesn't work now - so how do I > store that connection now? AL Admin(*) is a sample Rails application for that. (*) http://ruby-activeldap.googlecode.com/svn/trunk/examples/al-admin/ LdapUser(*) will help you. (*) http://ruby-activeldap.googlecode.com/svn/trunk/examples/al-admin/app/models/ldap_user.rb Thanks, -- kou From mortonda at dgrmm.net Sat Dec 29 22:12:43 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 21:12:43 -0600 Subject: [Ruby-activeldap-discuss] using multiple credentials In-Reply-To: <20071230.104559.1040217551023407791.kou@cozmixng.org> References: <4776727E.5040203@dgrmm.net> <20071230.104559.1040217551023407791.kou@cozmixng.org> Message-ID: <47770CAB.8090705@dgrmm.net> Kouhei Sutou wrote: > Hi, > > In <4776727E.5040203 at dgrmm.net> > "[Ruby-activeldap-discuss] using multiple credentials" on Sat, 29 Dec 2007 10:14:54 -0600, > David Morton wrote: > > >> I need to re-bind on every request depending on the user logged in - the >> ldap server has acls to help limit the data available per login. a year >> ago, this was how I achieved it; it doesn't work now - so how do I >> store that connection now? >> > > AL Admin(*) is a sample Rails application for that. > (*) http://ruby-activeldap.googlecode.com/svn/trunk/examples/al-admin/ > > LdapUser(*) will help you. > > (*) http://ruby-activeldap.googlecode.com/svn/trunk/examples/al-admin/app/models/ldap_user.rb > > Well, it's not what I was doing, but it's probably a better way to do it. From mortonda at dgrmm.net Sat Dec 29 23:54:50 2007 From: mortonda at dgrmm.net (David Morton) Date: Sat, 29 Dec 2007 22:54:50 -0600 Subject: [Ruby-activeldap-discuss] changing objectClass Message-ID: <4777249A.7090708@dgrmm.net> I can get an array of the objectClass elements by: @user User.find(:first) @user.classes but I can't seem to figure out how to modify that array. I used to do: @user.object_class << "someNewObjectClass" @user.object_class -= ['someOtherObjectClass'] but the -= operation results in an error now. How do I modify the objectClass array? From kou at cozmixng.org Sun Dec 30 00:19:17 2007 From: kou at cozmixng.org (Kouhei Sutou) Date: Sun, 30 Dec 2007 14:19:17 +0900 (JST) Subject: [Ruby-activeldap-discuss] changing objectClass In-Reply-To: <4777249A.7090708@dgrmm.net> References: <4777249A.7090708@dgrmm.net> Message-ID: <20071230.141917.484212973538244078.kou@cozmixng.org> Hi, In <4777249A.7090708 at dgrmm.net> "[Ruby-activeldap-discuss] changing objectClass" on Sat, 29 Dec 2007 22:54:50 -0600, David Morton wrote: > I can get an array of the objectClass elements by: > > @user User.find(:first) > @user.classes > > > but I can't seem to figure out how to modify that array. I used to do: > > @user.object_class << "someNewObjectClass" > @user.object_class -= ['someOtherObjectClass'] > > > but the -= operation results in an error now. How do I modify the > objectClass array? Use #add_class, #remove_class or #replace_class. Thanks, -- kou From mortonda at dgrmm.net Sun Dec 30 10:49:11 2007 From: mortonda at dgrmm.net (David Morton) Date: Sun, 30 Dec 2007 09:49:11 -0600 Subject: [Ruby-activeldap-discuss] adding ActiveLdap::DistinguishedName to a record Message-ID: <4777BDF7.7020909@dgrmm.net> I have a field that has dn's in it, which is evidently getting converted to ActiveLdap::DistinguishedName It won't let me update the field though. params['client'].each do |attr,value| if @client.attribute_names.include?(attr) if value.respond_to?("-") value -= [""] end @client.send("#{attr}=",value) end end This ends up with an error on fields with a dn syntax From mortonda at dgrmm.net Sun Dec 30 23:00:26 2007 From: mortonda at dgrmm.net (David Morton) Date: Sun, 30 Dec 2007 22:00:26 -0600 Subject: [Ruby-activeldap-discuss] adding ActiveLdap::DistinguishedName to a record In-Reply-To: <4777BDF7.7020909@dgrmm.net> References: <4777BDF7.7020909@dgrmm.net> Message-ID: <4778695A.5060805@dgrmm.net> David Morton wrote: > I have a field that has dn's in it, which is evidently getting converted > to ActiveLdap::DistinguishedName > > It won't let me update the field though. > > > params['client'].each do |attr,value| > > if @client.attribute_names.include?(attr) > if value.respond_to?("-") > value -= [""] > end > @client.send("#{attr}=",value) > end > end > > This ends up with an error on fields with a dn syntax nevermind, it was one of my own validations that doesn't understand the objects - wa previously expecting a string.