Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

doc

  • Loading branch information...
commit 205be83b07b661f831d6548a58533231936d0a78 1 parent 949a999
@thomasfl authored
Showing with 86 additions and 0 deletions.
  1. +86 −0 examples/update_person_titles/ldap_util.rb
View
86 examples/update_person_titles/ldap_util.rb
@@ -0,0 +1,86 @@
+require 'rubygems'
+require 'ldap'
+
+# sudo gem install ruby-ldap
+# Returns realname from username
+def ldap_realname(username)
+
+ begin
+ # Workaround for bug in jruby-ldap-0.0.1:
+ LDAP::load_configuration()
+ rescue
+
+ end
+
+ ldap_host = 'ldap.uio.no'
+ conn = LDAP::Conn.new(ldap_host, LDAP::LDAP_PORT)
+ filter = "(uid=#{username})";
+ base_dn = "dc=uio,dc=no"
+
+ if conn.bound? then
+ conn.unbind()
+ end
+
+ ansatt = nil
+ conn.bind do
+
+ conn.search2("dc=uio,dc=no", LDAP::LDAP_SCOPE_SUBTREE,
+ "(uid=#{username})", nil, false, 0, 0).each do |entry|
+
+ brukernavn = entry.to_hash["uid"][0]
+ fornavn = entry.to_hash["givenName"][0]
+ etternavn = entry.to_hash["sn"][0]
+ # epost = entry.to_hash["mail"][0]
+ # adresse = entry.to_hash["postalAddress"][0]
+
+ return fornavn + " " + etternavn
+ end
+ end
+
+end
+
+def org_unit(id)
+
+ require 'pp'
+
+ begin
+ # Workaround for bug in jruby-ldap-0.0.1:
+ LDAP::load_configuration()
+ rescue
+
+ end
+
+ ldap_host = 'ldap.uio.no'
+ conn = LDAP::Conn.new(ldap_host, LDAP::LDAP_PORT)
+ filter = "(ou=#{id})";
+ base_dn = "dc=uio,dc=no"
+
+ if conn.bound? then
+ conn.unbind()
+ end
+
+ ansatt = nil
+ conn.bind do
+
+ # pp conn
+
+ conn.search2("dc=uio,dc=no", LDAP::LDAP_SCOPE_SUBTREE,
+ "(ou=#{id})", nil, false, 0, 0).each do |entry|
+
+ pp entry
+ pp entry.to_hash
+ return nil
+ brukernavn = entry.to_hash["uid"][0]
+ fornavn = entry.to_hash["givenName"][0]
+ etternavn = entry.to_hash["sn"][0]
+ # epost = entry.to_hash["mail"][0]
+ # adresse = entry.to_hash["postalAddress"][0]
+
+ return fornavn + " " + etternavn
+ end
+ end
+
+end
+
+org_unit("160000")
+
Please sign in to comment.
Something went wrong with that request. Please try again.