¿Qué es ActiveLdap?
"Ruby/ActiveLdap provides an object oriented interface to LDAP. This library was inspired by ActiveRecord (both the concept and the library). It maps LDAP entries to Ruby objects with LDAP attribute accessors exposed as methods dynamically assigned based on your LDAP schema and each object’s objectClasses."
Es en esta página (www.activeldap.com) dónde podemos encontrar 2 minitutoriales interesantes:
- Installing Ruby/ActiveLdap on Ubuntu Dapper 6.06 LTS or Feisty 7.04
A Sample Application with ActiveLDAP
lib/authenticate_ldap_system:
module AuthenticateLdapSystem
protected
def is_logged_in?
@logged_in_user = LdapUser.find(:all,:attribute => 'uid', :value => session[:user]) if session[:user]
end
def logged_in_user
return @logged_in_user if is_logged_in?
end
def logged_in_user=(user)
if !user.nil?
session[:user] = user.uid
@logged_in_user = user
end
end
def self.included(base)
base.send :helper_method, :is_logged_in?, :logged_in_user
end
def login_required
unless is_logged_in?
flash[:error] = 'Debe estar autenticado para realizar esta acción.'
redirect_to :controller => 'account', :action => 'login'
end
end
end
controllers/application.rb:
class ApplicationController < secret =""> 'd3ae1ee162786bf4a3ad4fbcabdb4019'
# Hacemos que las contraseñas no salgan en claro en los logs
filter_parameter_logging "password"
# Incluimos nuestro sistema de autenticación
include AuthenticateLdapSystem
end
controllers/login_controller.rb:
class LoginController < logged_in_user =" LdapUser.authenticate(params[:user][:username]," action =""> 'login'
end
end
def logout
if request.post?
reset_session
flash[:notice] = 'Acaba de dejar la zona segura.'
end
redirect_to index_url
end
end
model/ldap_user.rb:
class LdapUser < dn_attribute =""> "uid",
:prefix => "ou=Usuarios",
:classes => ['top'],
:scope => :one
belongs_to :blog, :class => 'Blog', :foreign_key => 'uid'
def self.authenticate(username, password)
ActiveLdap::Base.establish_connection(
:host => "ldap.ejemplo.com",
:port => 389,
:base => "dc=ejemplo",
:bind_dn => "uid=#{username},ou=usuarios,dc=ejemplo",
:password_block => Proc.new { password },
:allow_anonymous => false)
LdapUser.find(:first,:attribute => 'uid', :value => username)
rescue ActiveLdap::AuthenticationError
return null
end
end
1 comentario:
Hola,
I think blogspot messed up your code postings. In the class lines, I think a bunch of stuff after and including the first '<' went missing. Any chance you could fix or repost? I'd like to see your full code examples.
Matt
Publicar un comentario