directory-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Neubauer" <>
Subject Fwd: How to make a WAR application in JRuby against LDAP for user registration
Date Wed, 23 May 2007 18:30:57 GMT
Hi all,
Andreas made up a small JRuby app to register users, think this is
pretty amazing!

Just for your information.


---------- Forwarded message ----------
From: Andreas Ronge <>

1. install jruby,
2. Check/Update environment vars:
   set JAVA_HOME (or just have "java" executable in PATH)
   add $JRUBY_HOME/bin to PATH
3. install rails: gem install rails
4. install ldap ruby library: gem install ruby-net-ldap
5. create a rails project: rails demo
6. cd demo
7. create a controller: jruby script/generate controller UserAdmin
8. edit the app/controllers/upser_admin_controller:
require 'rubygems'
require 'net/ldap'

class UserAdminController < ApplicationController
        def registration

        def add_user
                @username = params[:username]
                pwd = params[:password]
                ldap =
       = 'localhost'
                ldap.port = 10389
                ldap.auth "uid=admin,ou=system", "secret"

                dn = "uid=#@username,ou=users,ou=system"
                attributes = {
                        :cn => @username,
                        :objectclass => ["top", "person",
"inetorgperson", "organizationalPerson"],
                        :sn => @username

                success = ldap.add(:dn => dn, :attributes => attributes)
                puts "Success #{success}"


9. create rhtml files:
                <title>Signed Up</title>

                <h1>You have now registered with username <%=@username%></h1>



                <h3>Please enter user name and password</h3>
                <% form_tag(:action => :add_user) do %>
                  <%= text_field_tag :username %>
                  <%= password_field_tag :password %>
                  <%=submit_tag 'Add'%>
                <% end %>

10. test it in WEBrick: jruby script/server
You can now add a user in the ldap by filling in the html form at

11. configure which gems should be included in the WAR file
you need to tell which gems should be packed in the WAR file by adding
file config/war.rb:
add_gem 'ruby-net-ldap'

12. create WAR
rake war:standalone:create

13. run it in jetty
rake war:standalone:run

View raw message