From graf0 at post.pl Thu Jul 3 13:00:00 2008 From: graf0 at post.pl (=?ISO-8859-2?Q?Grzegorz_Marsza=B3ek?=) Date: Thu, 3 Jul 2008 19:00:00 +0200 Subject: [Ruby-activeldap-discuss] question about connections in rails Message-ID: Hello! I'm writing small web ui for ldap management. All access control is done by ldap server - so I need to bind as particular user and use this connection for all queries. From what I know, one instance of rails servs only one request at time - so one method to do that is to call ActiveLdap::Base.establish_connection (or rebind?) each time page is accessed. But this creates two problems: 1. I need to remember somewhere (session?) bind_dn and clear text password... 2. I would create a lot connection do ldap server (possible performance issues) But I'm run out of ideas how I could be done in some other way... And I'd use some help :) Thanks --- Grzegorz Marsza?ek graf0 at post.pl From kou at cozmixng.org Thu Jul 3 21:23:08 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Fri, 4 Jul 2008 10:23:08 +0900 Subject: [Ruby-activeldap-discuss] question about connections in rails In-Reply-To: References: Message-ID: Hi, 2008/7/4 Grzegorz Marsza?ek : > I'm writing small web ui for ldap management. All access control is done by > ldap server - so I need to bind as particular user and use this connection > for all queries. ActiveLdap::Base#bind isn't enough? LDAP connection will be kept on production environment. Thanks, -- kou From baptiste.grenier at healthgrid.org Tue Jul 8 11:35:08 2008 From: baptiste.grenier at healthgrid.org (Baptiste Grenier) Date: Tue, 8 Jul 2008 17:35:08 +0200 Subject: [Ruby-activeldap-discuss] SystemStackError 'stack level too deep' when using trunk Message-ID: <20080708153507.GB15513@healthgrid.org> Hello, Due to the availability of :except for to_xml, I'm trying to use ActiveLdap trunk in my Rails 2.1.0 application. (before I was using activeldap gem 1.0.1) Everything seems to work in the console, I can use find for groups and users. But now whem I try to access my views I get this error (with or without using an xml output)(Here it is for https://accountsws.test.plop.org/groups, but it does not work better for the show action or for the user model): ---------------8<---------------------------------------------------- SystemStackError in GroupsController#index stack level too deep vendor/activeldap-trunk/lib/active_ldap/connection.rb:160:in `reset_runtime' vendor/plugins/active_ldap/init.rb:40:in `render_without_active_ldap_benchmark' vendor/plugins/active_ldap/init.rb:41:in `render_without_active_ldap_benchmark' vendor/activeldap-trunk/lib/active_ldap/action_controller/ldap_benchmarking.rb:15:in `render' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:131:in `custom' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:156:in `call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:156:in `respond' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `each' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:154:in `respond' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/mime_responds.rb:107:in `respond_to' app/controllers/groups_controller.rb:30:in `show' app/controllers/application.rb:23:in `if_found' app/controllers/groups_controller.rb:28:in `show' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch' /usr/lib/ruby/1.8/thread.rb:135:in `synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi' /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:103:in `process_request' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:153:in `with_signal_handler' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:101:in `process_request' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:78:in `process_each_request' /usr/lib/ruby/1.8/fcgi.rb:612:in `each_cgi' /usr/lib/ruby/1.8/fcgi.rb:609:in `each' /usr/lib/ruby/1.8/fcgi.rb:609:in `each_cgi' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:77:in `process_each_request' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:76:in `catch' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:76:in `process_each_request' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:50:in `process!' /usr/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:24:in `process!' public/dispatch.fcgi:24 ---------------8<---------------------------------------------------- I'm working on a debian etch, with Rails 2.1.0, apache 2 and fcgi and with ActiveLdap trunk installed like this: ---------------8<---------------------------------------------------- svn co http://ruby-activeldap.googlecode.com/svn/trunk vendor/activeldap-trunk config/environment.rb: ... Rails::Initializer.run do |config| ... config.load_paths += %W(#{RAILS_ROOT}/vendor/activeldap-trunk/lib) config.plugin_paths += %W(#{RAILS_ROOT}/vendor/activeldap-trunk/rails/plugin) ... end ... ---------------8<---------------------------------------------------- I did try to use trunk with both ActiveLdap gem uninstalled and installed, but without any success. If I switch back to the 1.0.1 gem, it works as expected. I did try to remove the has_many clause from the Group model, but it changes nothing. I'm starting to implement a RESTful WebService for accessing an OpenLDAP directory so I did disable ActiveRecord, and turn off sessions. Here are some parts of the code: app/models/group.rb: ---------------8<---------------------------------------------------- class Group < ActiveLdap::Base ldap_mapping :dn_attribute => "ou", :prefix => '', :classes => ['top', 'groupOfNames'] has_many :members, :class => 'User', :primary_key => 'dn', # User#dn :foreign_key => 'member' # Group#member end ---------------8<---------------------------------------------------- app/models/user.rb: ---------------8<---------------------------------------------------- class User < ActiveLdap::Base ldap_mapping :dn_attribute => "cn", :prefix => 'ou=people', :scope => :one, :classes => ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'hgPerson'] has_many :groups, :class => 'Group', :primary_key => 'member', # Group#member :foreign_key => 'dn' # User#dn validates_presence_of :cn, :dn, :displayName, :gender, :uid, :userPassword, :st, :mail, :o, :hgPersonUid validates_length_of :userPassword, :within => 4..40 before_validation :check_fields before_save :encrypt_password # Returns a choosen field instead of the ID when object is used as a param def to_param hgPersonUid if self.hgPersonUid end private (...) end ---------------8<---------------------------------------------------- app/controllers/application.rb: ---------------8<---------------------------------------------------- class ApplicationController < ActionController::Base helper :all # include all helpers, all the time # turn off session management for all actions. session :off # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session store #protect_from_forgery # :secret => 'cfd30ef7ec07536794d97776a6147705' # A wrapper for actions which require the client to have named a valid # object. # Sends a 404 response code if the client named a nonexistent object def if_found(obj) if obj yield if block_given? else render :nothing => true, :status => "404 Not Found" return false end end # Set @authenticated_user if the user provides valid credentials def authenticate if not remote_user.empty? @authenticated_user = nil @authenticated_user = User.find(:attribute => 'uid', :value => remote_user) # Ensure the user exists as the remote_user could be cached by ldap # apache module if not @authenticated_user.nil? @is_admin = is_admin? return true end end render :nothing => true, :status => "403 Forbidden" return false end # Check if the user is in the admin group def is_admin? if @authenticated_user then @authenticated_user.groups.include?(Group.find('admins')) else return false end end # Ensure that the connected user is allowed to access def only_owner_or_admins if not (@authenticated_user.hgPersonUid.to_s == params[:id]) || @is_admin then render :nothing => true, :status => "403 Forbidden" return false end end # Either REMOTE_USER and REDIRECT_REMOTE_USER could be set def remote_user request.env['REDIRECT_REMOTE_USER'] || request.env['REMOTE_USER'] end end ---------------8<---------------------------------------------------- app/controllers/groups_controller.rb: ---------------8<---------------------------------------------------- class GroupsController < ApplicationController # All actions require to be authenticated prepend_before_filter :authenticate, :except => [ :create ] before_filter :only_owner_or_admins, :except => [ :create, :index ] # GET /groups # Lists all groups if the authenticated user is_admin def index if @is_admin then @groups = Group.find(:all) end if_found @groups do @title = "Groups list" respond_to do |format| format.html # index.html.erb format.xml { render :xml => @groups.to_xml } end end end # GET /groups/{cn} # a group details def show if @is_admin then @group = Group.find(:attribute => 'cn', :value => params[:id]) end if_found @group do @title = "Group details: #{@group.cn}" respond_to do |format| format.html # show.html.erb format.xml { render :xml => @group.to_xml } end end end end ---------------8<---------------------------------------------------- app/views/groups/index.html.erb: ---------------8<---------------------------------------------------- <% if @groups.nil? or @groups.empty? -%>

<%= "No group." -%>

<% else -%>
    <% @groups.each do |group| -%>
  • <%= link_to h(group.cn), group_url(group), :class => 'group' -%>
  • <% end -%>
<% end -%> ---------------8<---------------------------------------------------- I did some search about the "stack level too deep" message but I did not find anything helpful. So if anybody has an idea... :) Best regards, Baptiste -- Baptiste Grenier | PGP: 0x069112E2 HealthGrid SysAdmin http://healthgrid.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From kou at cozmixng.org Thu Jul 10 07:19:26 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Thu, 10 Jul 2008 20:19:26 +0900 (JST) Subject: [Ruby-activeldap-discuss] SystemStackError 'stack level too deep' when using trunk In-Reply-To: <20080708153507.GB15513@healthgrid.org> References: <20080708153507.GB15513@healthgrid.org> Message-ID: <20080710.201926.321689434133353194.kou@cozmixng.org> Hi, In <20080708153507.GB15513 at healthgrid.org> "[Ruby-activeldap-discuss] SystemStackError 'stack level too deep' when using trunk" on Tue, 8 Jul 2008 17:35:08 +0200, Baptiste Grenier wrote: > But now whem I try to access my views I get this error (with or without using > an xml output)(Here it is for https://accountsws.test.plop.org/groups, but it > does not work better for the show action or for the user model): > vendor/plugins/active_ldap/init.rb:40:in `render_without_active_ldap_benchmark' > vendor/plugins/active_ldap/init.rb:41:in `render_without_active_ldap_benchmark' Please remove vendor/plugins/active_ldap/. Thanks, -- kou From baptiste.grenier at healthgrid.org Thu Jul 10 08:32:24 2008 From: baptiste.grenier at healthgrid.org (Baptiste Grenier) Date: Thu, 10 Jul 2008 14:32:24 +0200 Subject: [Ruby-activeldap-discuss] SystemStackError 'stack level too deep' when using trunk In-Reply-To: <20080710.201926.321689434133353194.kou@cozmixng.org> References: <20080708153507.GB15513@healthgrid.org> <20080710.201926.321689434133353194.kou@cozmixng.org> Message-ID: <20080710123223.GA20223@healthgrid.org> Le 10/07/08 ? 13:23, Kouhei Sutou t?l?scripta : > Hi, Hi, > Please remove vendor/plugins/active_ldap/. Thank you, of course it did the trick! I can believe I did such a stupid mistake, I will have to relearn how to read ;) > Thanks, Thanks again for your responsiveness, it's awesome and realy helpful. :) Baptiste -- Baptiste Grenier | PGP: 0x069112E2 HealthGrid SysAdmin http://healthgrid.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From baptiste.grenier at healthgrid.org Thu Jul 10 13:17:51 2008 From: baptiste.grenier at healthgrid.org (Baptiste Grenier) Date: Thu, 10 Jul 2008 19:17:51 +0200 Subject: [Ruby-activeldap-discuss] More on to_xml and ActiveResource Message-ID: <20080710171750.GA3287@healthgrid.org> Hello all, As said here[1] I have some problems getting ActiveLdap and ActiveResource play together. Koutou did modify the to_xml in order to be able to handle multivalued attributes, but now the problem seems to be on the ActiveResource side. So I did create a ticket[2] on the Ruby On Rails bugrack about the way ActiveResource handles (more exactly does not handles) multivalued attributes. Perhaps could we get some helpful tips, advices or changes from the ActiveResource developpers. :) What does everybody think about this? How do you think thoes things should be handled? Regards, Baptiste Ref: [1]- http://code.google.com/p/ruby-activeldap/issues/detail?id=6 [2]- http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/596-activeresource-should-handle-multivalued-attributes -- Baptiste Grenier | PGP: 0x069112E2 HealthGrid SysAdmin http://healthgrid.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: From NICHOLR3 at uk.ibm.com Mon Jul 14 08:26:25 2008 From: NICHOLR3 at uk.ibm.com (Richard 3 Nicholas) Date: Mon, 14 Jul 2008 13:26:25 +0100 Subject: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... In-Reply-To: <20080625.204221.220301508518464392.kou@cozmixng.org> Message-ID: I'm trying to read active directory, which unfortunately stores "never" as 1st Jan 1601... I added a puts value.to_yaml command straight after def type_cast( value ) in GeneralizedTime in syntaxes.rb >> c=Computer.find("D0034536") --- !str:Net::BER::BerIdentifiedString str: 20080624134415.0Z "@ber_identifier": 4 --- !str:Net::BER::BerIdentifiedString str: 16010101000001.0Z "@ber_identifier": 4 ArgumentError: argument out of range from c:/ruby/lib/ruby/1.8/time.rb:180:in `utc' from c:/ruby/lib/ruby/1.8/time.rb:180:in `make_time' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/sc ema/syntaxes.rb:191:in `send' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/sc ema/syntaxes.rb:191:in `type_cast' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/sc ema.rb:316:in `type_cast' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/sc ema.rb:462:in `send' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/sc ema.rb:462:in `send_to_syntax' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/sc ema.rb:412:in `type_cast' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:1093:in `type_cast' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:1090:in `type_cast' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:1089:in `collect' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:1089:in `type_cast' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:1073:in `get_attribute' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:963:in `inspect_attribute' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:953:in `inspect' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:952:in `collect' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ba e.rb:952:in `inspect' from c:/ruby/lib/ruby/1.8/irb.rb:298:in `output_value' from c:/ruby/lib/ruby/1.8/irb.rb:151:in `eval_input' from c:/ruby/lib/ruby/1.8/irb.rb:259:in `signal_status' from c:/ruby/lib/ruby/1.8/irb.rb:147:in `eval_input' from c:/ruby/lib/ruby/1.8/irb.rb:146:in `eval_input' from c:/ruby/lib/ruby/1.8/irb.rb:70:in `start' from c:/ruby/lib/ruby/1.8/irb.rb:69:in `catch' from c:/ruby/lib/ruby/1.8/irb.rb:69:in `start' I think that the problem is that Time cannot cope with dates before 1970.... >> DateTime.parse("16010101000001.0Z") => Mon, 01 Jan 1601 00:00:01 +0000 >> Time.parse("19720101000001.0Z") => Sat Jan 01 00:00:01 +0000 1972 >> Time.parse("19500101000001.0Z") ArgumentError: argument out of range from c:/ruby/lib/ruby/1.8/time.rb:184:in `local' from c:/ruby/lib/ruby/1.8/time.rb:184:in `make_time' from c:/ruby/lib/ruby/1.8/time.rb:243:in `parse' from (irb):5 I'm currently kludging round the problem by this ugly hack.... def type_cast(value) return value if value.nil? or value.is_a?(Time) match_data = FORMAT.match(value) if match_data required_components = match_data.to_a[1, 6] return value if required_components.any?(&:nil?) year, month, day, hour, minute, second = required_components.collect(&:to_i) fraction = match_data[-2] fraction = fraction.to_f if fraction time_zone = match_data[-1] if year >= 1970 Time.send(:make_time, year, month, day, hour, minute, second, fraction, time_zone, Time.now) else nil end else value end end Is there a better way round the problem? Thanks, Richard. Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU -------------- next part -------------- An HTML attachment was scrubbed... URL: From mortonda at dgrmm.net Mon Jul 14 12:58:27 2008 From: mortonda at dgrmm.net (David Morton) Date: Mon, 14 Jul 2008 11:58:27 -0500 Subject: [Ruby-activeldap-discuss] Return only select attributes? In-Reply-To: References: <594938406.381671214329781498.JavaMail.root@zcs8.wiu.edu> Message-ID: <0F2E3498-DA5B-4A74-90D8-133A1E137BDF@dgrmm.net> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jun 24, 2008, at 1:03 PM, Perry Smith wrote: > Ahh. find(:all, ... returns an array. > > find(:first, ... or find(username) returns the actual element. > Yes, this is my biggest grump with activeldap. searching the database can return an array, a single value, or nil. And all require different handling. I'd rather always assume an array which can be empty, have one value, or many values. It makes the handling code much more sane. David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFIe4WzUy30ODPkzl0RAq2LAKCU3+m+ewppmjom89ZMrM8B9bovngCgr6UK 8Ee4L4GWtiYyK7cC3Obe5ig= =lXg0 -----END PGP SIGNATURE----- From NICHOLR3 at uk.ibm.com Mon Jul 14 13:50:40 2008 From: NICHOLR3 at uk.ibm.com (Richard 3 Nicholas) Date: Mon, 14 Jul 2008 18:50:40 +0100 Subject: [Ruby-activeldap-discuss] Return only select attributes? In-Reply-To: <0F2E3498-DA5B-4A74-90D8-133A1E137BDF@dgrmm.net> Message-ID: I'm not sure that this is so much a problem with ActiveLDAP as with LDAP in general. Pretty much every language's LDAP implementation has this problem due to the fact that some attributes are defined as being multi valued. The good news is that Ruby can deal with "it might be an array" much more neatly than most other languages. David Morton Sent by: ruby-activeldap-discuss-bounces at rubyforge.org 14/07/2008 17:58 Please respond to ruby-activeldap-discuss at rubyforge.org To ruby-activeldap-discuss at rubyforge.org cc Subject Re: [Ruby-activeldap-discuss] Return only select attributes? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jun 24, 2008, at 1:03 PM, Perry Smith wrote: > Ahh. find(:all, ... returns an array. > > find(:first, ... or find(username) returns the actual element. > Yes, this is my biggest grump with activeldap. searching the database can return an array, a single value, or nil. And all require different handling. I'd rather always assume an array which can be empty, have one value, or many values. It makes the handling code much more sane. David Morton Maia Mailguard http://www.maiamailguard.com mortonda at dgrmm.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (Darwin) iD8DBQFIe4WzUy30ODPkzl0RAq2LAKCU3+m+ewppmjom89ZMrM8B9bovngCgr6UK 8Ee4L4GWtiYyK7cC3Obe5ig= =lXg0 -----END PGP SIGNATURE----- _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU -------------- next part -------------- An HTML attachment was scrubbed... URL: From pedzsan at gmail.com Mon Jul 14 16:05:00 2008 From: pedzsan at gmail.com (Perry Smith) Date: Mon, 14 Jul 2008 15:05:00 -0500 Subject: [Ruby-activeldap-discuss] Return only select attributes? In-Reply-To: <0F2E3498-DA5B-4A74-90D8-133A1E137BDF@dgrmm.net> References: <594938406.381671214329781498.JavaMail.root@zcs8.wiu.edu> <0F2E3498-DA5B-4A74-90D8-133A1E137BDF@dgrmm.net> Message-ID: On Jul 14, 2008, at 11:58 AM, David Morton wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > On Jun 24, 2008, at 1:03 PM, Perry Smith wrote: > >> Ahh. find(:all, ... returns an array. >> >> find(:first, ... or find(username) returns the actual element. >> > > Yes, this is my biggest grump with activeldap. searching the > database can return an array, a single value, or nil. And all > require different handling. I'd rather always assume an array which > can be empty, have one value, or many values. It makes the handling > code much more sane. Probably ActiveLDAP does that because that is how ActiveRecord does it. But, if it is not intuitive to you, don't use it. I think you can use select and it always returns the same thing (an array) -- I'm talking a bit through my hat because I haven't done it but I'm pretty sure that is the case. Good luck, pedz From kou at cozmixng.org Tue Jul 15 07:59:40 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 15 Jul 2008 20:59:40 +0900 (JST) Subject: [Ruby-activeldap-discuss] Return only select attributes? In-Reply-To: <0F2E3498-DA5B-4A74-90D8-133A1E137BDF@dgrmm.net> References: <594938406.381671214329781498.JavaMail.root@zcs8.wiu.edu> <0F2E3498-DA5B-4A74-90D8-133A1E137BDF@dgrmm.net> Message-ID: <20080715.205940.653026525707333288.kou@cozmixng.org> Hi, In <0F2E3498-DA5B-4A74-90D8-133A1E137BDF at dgrmm.net> "Re: [Ruby-activeldap-discuss] Return only select attributes?" on Mon, 14 Jul 2008 11:58:27 -0500, David Morton wrote: > > Ahh. find(:all, ... returns an array. > > > > find(:first, ... or find(username) returns the actual element. > > > > Yes, this is my biggest grump with activeldap. searching the database > can return an array, a single value, or nil. And all require > different handling. I'd rather always assume an array which can be > empty, have one value, or many values. It makes the handling code > much more sane. You can always use find(:all). Thanks, -- kou From kou at cozmixng.org Tue Jul 15 08:15:39 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 15 Jul 2008 21:15:39 +0900 (JST) Subject: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... In-Reply-To: References: <20080625.204221.220301508518464392.kou@cozmixng.org> Message-ID: <20080715.211539.519459540419520216.kou@cozmixng.org> Hi, In "Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time..." on Mon, 14 Jul 2008 13:26:25 +0100, Richard 3 Nicholas wrote: > I'm trying to read active directory, which unfortunately stores "never" as 1st > Jan 1601... I added a puts value.to_yaml command straight after def > type_cast( value ) in GeneralizedTime in syntaxes.rb > >> DateTime.parse("16010101000001.0Z") > => Mon, 01 Jan 1601 00:00:01 +0000 > >> Time.parse("19720101000001.0Z") > => Sat Jan 01 00:00:01 +0000 1972 > >> Time.parse("19500101000001.0Z") > ArgumentError: argument out of range > from c:/ruby/lib/ruby/1.8/time.rb:184:in `local' > from c:/ruby/lib/ruby/1.8/time.rb:184:in `make_time' > from c:/ruby/lib/ruby/1.8/time.rb:243:in `parse' > from (irb):5 This works on my environment: irb(main):001:0> Time.parse("16010101000001.0Z") => Mon Jan 01 00:00:01 UTC 1601 > I'm currently kludging round the problem by this ugly hack.... > > def type_cast(value) > return value if value.nil? or value.is_a?(Time) > match_data = FORMAT.match(value) > if match_data > required_components = match_data.to_a[1, 6] > return value if required_components.any?(&:nil?) > year, month, day, hour, minute, second = > required_components.collect(&:to_i) > fraction = match_data[-2] > fraction = fraction.to_f if fraction > time_zone = match_data[-1] > if year >= 1970 > Time.send(:make_time, > year, month, day, hour, minute, second, fraction, > time_zone, Time.now) > else > nil > end > else > value > end > end It seems that it's not good idea using nil as fallback value. What about Time.at(0)? Thanks, -- kou From NICHOLR3 at uk.ibm.com Tue Jul 15 08:30:31 2008 From: NICHOLR3 at uk.ibm.com (Richard 3 Nicholas) Date: Tue, 15 Jul 2008 13:30:31 +0100 Subject: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... In-Reply-To: <20080715.211539.519459540419520216.kou@cozmixng.org> Message-ID: Point taken about time.at(0). I'm running Ruby 1.8.5, so I'll try upgrading first.... Kouhei Sutou Sent by: ruby-activeldap-discuss-bounces at rubyforge.org 15/07/2008 13:15 Please respond to ruby-activeldap-discuss at rubyforge.org To ruby-activeldap-discuss at rubyforge.org cc Subject Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... Hi, In "Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time..." on Mon, 14 Jul 2008 13:26:25 +0100, Richard 3 Nicholas wrote: > I'm trying to read active directory, which unfortunately stores "never" as 1st > Jan 1601... I added a puts value.to_yaml command straight after def > type_cast( value ) in GeneralizedTime in syntaxes.rb > >> DateTime.parse("16010101000001.0Z") > => Mon, 01 Jan 1601 00:00:01 +0000 > >> Time.parse("19720101000001.0Z") > => Sat Jan 01 00:00:01 +0000 1972 > >> Time.parse("19500101000001.0Z") > ArgumentError: argument out of range > from c:/ruby/lib/ruby/1.8/time.rb:184:in `local' > from c:/ruby/lib/ruby/1.8/time.rb:184:in `make_time' > from c:/ruby/lib/ruby/1.8/time.rb:243:in `parse' > from (irb):5 This works on my environment: irb(main):001:0> Time.parse("16010101000001.0Z") => Mon Jan 01 00:00:01 UTC 1601 > I'm currently kludging round the problem by this ugly hack.... > > def type_cast(value) > return value if value.nil? or value.is_a?(Time) > match_data = FORMAT.match(value) > if match_data > required_components = match_data.to_a[1, 6] > return value if required_components.any?(&:nil?) > year, month, day, hour, minute, second = > required_components.collect(&:to_i) > fraction = match_data[-2] > fraction = fraction.to_f if fraction > time_zone = match_data[-1] > if year >= 1970 > Time.send(:make_time, > year, month, day, hour, minute, second, fraction, > time_zone, Time.now) > else > nil > end > else > value > end > end It seems that it's not good idea using nil as fallback value. What about Time.at(0)? Thanks, -- kou _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU -------------- next part -------------- An HTML attachment was scrubbed... URL: From NICHOLR3 at uk.ibm.com Wed Jul 16 05:39:40 2008 From: NICHOLR3 at uk.ibm.com (Richard 3 Nicholas) Date: Wed, 16 Jul 2008 10:39:40 +0100 Subject: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... In-Reply-To: Message-ID: Ruby 1.8.6 doesn't fix it. I had a look at "The Rails Way" by Obie Fernandez and this mentions that the Time class only supports dates after 1970, so I don't think this is unique to my implementation. Thanks, Richard. Richard 3 Nicholas/UK/Contr/IBM at IBMGB Sent by: ruby-activeldap-discuss-bounces at rubyforge.org 15/07/2008 13:30 Please respond to ruby-activeldap-discuss at rubyforge.org To ruby-activeldap-discuss at rubyforge.org cc Subject Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... Point taken about time.at(0). I'm running Ruby 1.8.5, so I'll try upgrading first.... Kouhei Sutou Sent by: ruby-activeldap-discuss-bounces at rubyforge.org 15/07/2008 13:15 Please respond to ruby-activeldap-discuss at rubyforge.org To ruby-activeldap-discuss at rubyforge.org cc Subject Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... Hi, In "Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time..." on Mon, 14 Jul 2008 13:26:25 +0100, Richard 3 Nicholas wrote: > I'm trying to read active directory, which unfortunately stores "never" as 1st > Jan 1601... I added a puts value.to_yaml command straight after def > type_cast( value ) in GeneralizedTime in syntaxes.rb > >> DateTime.parse("16010101000001.0Z") > => Mon, 01 Jan 1601 00:00:01 +0000 > >> Time.parse("19720101000001.0Z") > => Sat Jan 01 00:00:01 +0000 1972 > >> Time.parse("19500101000001.0Z") > ArgumentError: argument out of range > from c:/ruby/lib/ruby/1.8/time.rb:184:in `local' > from c:/ruby/lib/ruby/1.8/time.rb:184:in `make_time' > from c:/ruby/lib/ruby/1.8/time.rb:243:in `parse' > from (irb):5 This works on my environment: irb(main):001:0> Time.parse("16010101000001.0Z") => Mon Jan 01 00:00:01 UTC 1601 > I'm currently kludging round the problem by this ugly hack.... > > def type_cast(value) > return value if value.nil? or value.is_a?(Time) > match_data = FORMAT.match(value) > if match_data > required_components = match_data.to_a[1, 6] > return value if required_components.any?(&:nil?) > year, month, day, hour, minute, second = > required_components.collect(&:to_i) > fraction = match_data[-2] > fraction = fraction.to_f if fraction > time_zone = match_data[-1] > if year >= 1970 > Time.send(:make_time, > year, month, day, hour, minute, second, fraction, > time_zone, Time.now) > else > nil > end > else > value > end > end It seems that it's not good idea using nil as fallback value. What about Time.at(0)? Thanks, -- kou _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU -------------- next part -------------- An HTML attachment was scrubbed... URL: From kou at cozmixng.org Wed Jul 16 08:12:36 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Wed, 16 Jul 2008 21:12:36 +0900 (JST) Subject: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... In-Reply-To: References: Message-ID: <20080716.211236.195066307596263738.kou@cozmixng.org> Hi, In "Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time..." on Wed, 16 Jul 2008 10:39:40 +0100, Richard 3 Nicholas wrote: > Ruby 1.8.6 doesn't fix it. I had a look at "The Rails Way" by Obie Fernandez > and this mentions that the Time class only supports dates after 1970, so I > don't think this is unique to my implementation. On some platform (not Windows) we can handle times before 1970. OK. I've committed your request in trunk. I used Time.at(0) as fallback value. Thanks, -- kou From NICHOLR3 at uk.ibm.com Wed Jul 16 08:33:27 2008 From: NICHOLR3 at uk.ibm.com (Richard 3 Nicholas) Date: Wed, 16 Jul 2008 13:33:27 +0100 Subject: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... In-Reply-To: <20080716.211236.195066307596263738.kou@cozmixng.org> Message-ID: Whoa! I don't really think my sample code is suitable for trunk. It was a kludge I used to get ActiveLDAP up and running quickly. A better fix would be to have the option of using datetime as an optional vehicle for holding LDAP times.. Kouhei Sutou Sent by: ruby-activeldap-discuss-bounces at rubyforge.org 16/07/2008 13:12 Please respond to ruby-activeldap-discuss at rubyforge.org To ruby-activeldap-discuss at rubyforge.org cc Subject Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time... Hi, In "Re: [Ruby-activeldap-discuss] ActiveLDAP treating DateTime LDAP values as Time..." on Wed, 16 Jul 2008 10:39:40 +0100, Richard 3 Nicholas wrote: > Ruby 1.8.6 doesn't fix it. I had a look at "The Rails Way" by Obie Fernandez > and this mentions that the Time class only supports dates after 1970, so I > don't think this is unique to my implementation. On some platform (not Windows) we can handle times before 1970. OK. I've committed your request in trunk. I used Time.at(0) as fallback value. Thanks, -- kou _______________________________________________ Ruby-activeldap-discuss mailing list Ruby-activeldap-discuss at rubyforge.org http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU -------------- next part -------------- An HTML attachment was scrubbed... URL: From NICHOLR3 at uk.ibm.com Wed Jul 16 13:16:20 2008 From: NICHOLR3 at uk.ibm.com (Richard 3 Nicholas) Date: Wed, 16 Jul 2008 18:16:20 +0100 Subject: [Ruby-activeldap-discuss] I'm having fun with ActiveLdap::DistinguishedName class... In-Reply-To: Message-ID: I want to move an object from its current container into a sub container (ou=toBeDeleted) and this would seem to be the way to do it... modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={}) now, I have the dn. The new rdn, would be "cn=old cn", so that isn't a problem. delete_old_rdn is true, so that isn't a problem. The issue is new_superior. I need to take the cn off the front of the DN, and replace it with the new OU. I thought it would be great to make use of activeLdap's DistinguishedName handler to save me the problem of rolling my own DistinguishedName parser. ActiveLdap::DistinguishedName.parse( my_object.dn ) does just what I'd expect. I can then look at the .rdns value and use strip to get rid of the cn on the end. I can add { "ou" => "toBeDeleted" } to the start of the array, but then I can't get the resultant array of hashes back into an ActiveLdap::DistinguishedName type and from there back into a string. >> arr => [{"CN"=>"Computers"}, {"dc"=>"ads"}, {"dc"=>"blah"}, {"dc"=>"com"}] >> newdn.rdns = arr NoMethodError: undefined method `rdns=' for # from (irb):74 >> >> ActiveLdap::DistinguishedName.new(arr) => #"Computers"}, {"dc"=>"ads"}, {"dc"=>"blah"}, {"dc"=>"com"}]]> >> ActiveLdap::DistinguishedName.new(arr).to_s NoMethodError: undefined method `upcase' for {"CN"=>"Computers"}:Hash from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:227:in `to_s' from (irb):76:in `sort_by' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:226:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:226:in `sort_by' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:226:in `to_s' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:225:in `collect' from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:225:in `to_s' from (irb):76 >> The reason that the second method fails is rdns ends up wrapped in another array. The following change would fix the problem, but the behaviour of ActiveLdap::DistinguishedName.new( ["cn","anything"] ) would change.... file: distinguished_name.rb def initialize(*rdns) if rdns.size == 1 and rdns[0].is_a?(Array) rdns = rdns[0] end @rdns = rdns.collect do |rdn| if rdn.is_a?(Array) and rdn.size == 2 {rdn[0] => rdn[1]} else rdn end end end Is there any really easy way to make the parser do what I want? Unless stated otherwise above: IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU -------------- next part -------------- An HTML attachment was scrubbed... URL: From kou at cozmixng.org Fri Jul 25 23:10:23 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 26 Jul 2008 12:10:23 +0900 (JST) Subject: [Ruby-activeldap-discuss] I'm having fun with ActiveLdap::DistinguishedName class... In-Reply-To: References: Message-ID: <20080726.121023.123339447357719132.kou@cozmixng.org> Hi, I'm sorry for my late response. In "[Ruby-activeldap-discuss] I'm having fun with ActiveLdap::DistinguishedName class..." on Wed, 16 Jul 2008 18:16:20 +0100, Richard 3 Nicholas wrote: > >> arr > => [{"CN"=>"Computers"}, {"dc"=>"ads"}, {"dc"=>"blah"}, {"dc"=>"com"}] > >> newdn.rdns = arr > NoMethodError: undefined method `rdns=' for # > > from (irb):74 > >> > > >> ActiveLdap::DistinguishedName.new(arr) > => #"Computers"}, {"dc" > =>"ads"}, {"dc"=>"blah"}, {"dc"=>"com"}]]> > >> ActiveLdap::DistinguishedName.new(arr).to_s > NoMethodError: undefined method `upcase' for {"CN"=>"Computers"}:Hash > from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/ > Is there any really easy way to make the parser do what I want? What about the following? ActiveLdap::DistinguishedName.new(*arr).to_s Thanks, -- kou From nicholas.e.hubbard at gmail.com Wed Jul 30 22:08:40 2008 From: nicholas.e.hubbard at gmail.com (Nicholas E. Hubbard) Date: Wed, 30 Jul 2008 21:08:40 -0500 Subject: [Ruby-activeldap-discuss] Sorting LDAP Objects Message-ID: <181ad80f0807301908oaff4a5cmfb72d6fa32c6e273@mail.gmail.com> Hey Guys, I have an array of objects coming back from LDAP, but there is currently no way to sort them. I have added the following code to all my classes, but thought this might be a good addition to go into the ActiveLdap::Base class. It will sort by what the dn_attribute is set to in the ldap_mapping for each class. def <=>(other) dn_attr = self.dn_attribute self.attributes[dn_attr] <=> other.attributes[dn_attr] end Nicholas -------------- next part -------------- An HTML attachment was scrubbed... URL: From gsslist+rbldap at anthropohedron.net Wed Jul 30 22:16:20 2008 From: gsslist+rbldap at anthropohedron.net (Gregory Seidman) Date: Wed, 30 Jul 2008 22:16:20 -0400 Subject: [Ruby-activeldap-discuss] Sorting LDAP Objects In-Reply-To: <181ad80f0807301908oaff4a5cmfb72d6fa32c6e273@mail.gmail.com> References: <181ad80f0807301908oaff4a5cmfb72d6fa32c6e273@mail.gmail.com> Message-ID: <20080731021617.GA22305@anthropohedron.net> On Wed, Jul 30, 2008 at 09:08:40PM -0500, Nicholas E. Hubbard wrote: > I have an array of objects coming back from LDAP, but there is currently > no way to sort them. I have added the following code to all my classes, > but thought this might be a good addition to go into the ActiveLdap::Base > class. > > It will sort by what the dn_attribute is set to in the ldap_mapping for > each class. > > def <=>(other) > dn_attr = self.dn_attribute > self.attributes[dn_attr] <=> other.attributes[dn_attr] > end This is what sort_by is for: some_array.sort_by { |obj| obj.attributes[obj.dn_attribute] } You may want to do the following: ActiveLdap::DnProc = lambda { |obj| obj.attributes[obj.dn_attribute] } ...so that you can... some_array.sort_by(&ActiveLdap::DnProc) > Nicholas --Greg