Permalink
Browse files

fixes examples

  • Loading branch information...
1 parent 817333a commit 11adb1a14ed66eb6571fb25cefbb73666f829ee0 @mkristian committed Feb 8, 2011
Showing with 20 additions and 97 deletions.
  1. +6 −8 README.txt
  2. +0 −75 example/identity_map.rb
  3. +14 −14 example/posix.rb
View
@@ -46,8 +46,6 @@ or
see 'example/posix.rb' for user/group setup works with default installation of openldap on ubuntu (just change your password as needed in the code)
-the 'example/identity_map.rb' shows the usage of identity maps, see also below.
-
== FEATURES/PROBLEMS:
* the net-ldap has some issues with not closing the connections when an exception/error got raised, with limit the search result to 126 entries which gets fixed by making consecutives searches and collect the result.
@@ -62,7 +60,7 @@ there are three parts which makes the DN of a model, the base from the ldap conn
class User
include DataMapper::Resource
- property :id, Serial, :field => "uidnumber"
+ property :id, Serial, :field => "uidNumber"
dn_prefix { |user| "uid=#{user.login}"}
treebase "ou=people"
end
@@ -77,7 +75,7 @@ for example the ldap posixGroup has more attributes than the model class, it nee
class Group
include DataMapper::Resource
- property :id, Serial, :field => "gidnumber"
+ property :id, Serial, :field => "gidNumber"
property :name, String, :field => "cn"
dn_prefix { |group| "cn=#{group.name}" }
treebase "ou=groups"
@@ -169,8 +167,8 @@ staying with posix example there the groups has a memberuid attribute BUT unlike
class GroupUser
include DataMapper::Resource
- property :memberuid, String, :key => true
- property :gidnumber, Integer, :key => true
+ property :memberUid, String, :key => true
+ property :gidNumber, Integer, :key => true
dn_prefix { |group_user| "cn=#{group_user.group.name}" }
treebase "ou=groups"
ldap_properties do |group_user|
@@ -187,14 +185,14 @@ let's say your LDAP has multiple email values for a users then you can define yo
class User
include DataMapper::Resource
- property :id, Serial, :field => "uidnumber"
+ property :id, Serial, :field => "uidNumber"
property :login, String, :field => "uid", :unique_index => true
property :mail, LdapArray
dn_prefix { |user| "uid=#{user.login}"}
treebase "ou=people"
ldap_properties do |user|
- properties = { :objectclass => ["inetOrgPerson", "posixAccount", "shadowAccount"], :loginshell => "/bin/bash", :gidnumber => "10000" }
+ properties = { :objectclass => ["inetOrgPerson", "posixAccount", "shadowAccount"], :loginshell => "/bin/bash", :gidNumber => "10000" }
properties
end
end
@@ -1,75 +0,0 @@
-require 'example/posix.rb'
-
-USER_REPO = :default
-
-class User
-
- def self.ddefault_repository_name
- USER_REPO
- end
-
- def self.repository_name
- USER_REPO
- end
-
- def authenticate(pwd)
- require 'base64'
- Base64.encode64(Digest::SHA1.digest(pwd)).gsub(/\n/, '') == attribute_get(:hashed_password)[5,1000]
- end
-end
-
-class GroupUser
-
- def self.ddefault_repository_name
- USER_REPO
- end
-
- def self.repository_name
- USER_REPO
- end
-
-end
-
-class Group
-
- def self.ddefault_repository_name
- USER_REPO
- end
-
- def self.repository_name
- USER_REPO
- end
-
-end
-
-require 'adapters/memory_adapter'
-DATA_REPO=:store
-DataMapper.setup(DATA_REPO, {:adapter => 'memory'})
-
-class Item
- include DataMapper::Resource
- property :id, Serial
-end
-
-
-DataMapper.repository(USER_REPO) do |repository|
- repository.adapter.open_ldap_connection do
- DataMapper.repository(DATA_REPO) do
- root = User.first(:login => 'root') || User.create(:id => 0, :login => :root, :name => 'root', :password => 'none') if root.nil?
- admin = Group.first(:name => 'admin') || Group.create(:name => 'admin')
- root.groups << admin
-
- p DataMapper.repository(USER_REPO).identity_map(User)
-
- p DataMapper.repository(USER_REPO).identity_map(Group)
-
- p root.authenticate('none')
-
- p root.groups
-
- (1..10).each {Item.create}
-
- p DataMapper.repository(DATA_REPO).identity_map(Item)
- end
- end
-end
View
@@ -1,19 +1,19 @@
require 'pathname'
require 'rubygems'
-require 'slf4r/logging_logger'
-gem 'data_objects' , "0.9.11"
+require 'slf4r/logger'
+require 'slf4r/ruby_logger'
require 'dm-core'
$LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
-Logging.init :debug, :info, :warn, :error
+# Logging.init :debug, :info, :warn, :error
-appender = Logging::Appender.stdout
-appender.layout = Logging::Layouts::Pattern.new(:pattern => "%d [%-l] (%c) %m\n")
-logger = Logging::Logger.new(:root)
-logger.add_appenders(appender)
-logger.level = :debug
-logger.info "initialized logger . . ."
+# appender = Logging::Appender.stdout
+# appender.layout = Logging::Layouts::Pattern.new(:pattern => "%d [%-l] (%c) %m\n")
+# logger = Logging::Logger.new(:root)
+# logger.add_appenders(appender)
+# logger.level = :debug
+# logger.info "initialized logger . . ."
dummy = true #uncomment this to use dummy, i.e. a database instead of ldap
dummy = false # uncomment this to use ldap
@@ -49,9 +49,9 @@ def con.open
class User
include DataMapper::Resource
- property :id, Serial, :field => "uidnumber"
+ property :id, Serial, :field => "uidNumber"
property :login, String, :field => "uid"
- property :hashed_password, String, :field => "userpassword", :access => :private
+ property :hashed_password, String, :field => "userPassword"
property :name, String, :field => "cn"
has n, :group_users, :child_key => [:memberuid]
@@ -99,7 +99,7 @@ def password=(password)
class Group
include DataMapper::Resource
include Slf4r::Logger
- property :id, Serial, :field => "gidnumber"
+ property :id, Serial, :field => "gidNumber"
property :name, String, :field => "cn"
dn_prefix { |group| "cn=#{group.name}" }
@@ -145,8 +145,8 @@ class GroupUser
ldap_properties do |group_user|
{:cn=>"#{group_user.group.name}", :objectclass => "posixGroup"}
end
- property :memberuid, String, :key => true#, :field => "memberuid"
- property :gidnumber, Integer, :key => true#, :field => "gidnumber"
+ property :memberuid, String, :key => true#, :field => "memberUid"
+ property :gidnumber, Integer, :key => true#, :field => "gidNumber"
def group
Group.get!(gidnumber)

0 comments on commit 11adb1a

Please sign in to comment.