Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## in environment.rb
- # For ActiveLDAP control.
- if ENV['rrvcldap']
- require RAILS_ROOT + "/lib/rrvcldap.rb"
- require "password"
- ldapuser = ENV['ldapuser'] ? ENV['ldapuser'] : ENV['USER']
- ldappass = Proc.new { Password.get("Ldap Password for #{ldapuser}: ") }
- ActiveLDAP::Base.connect(
- :host => 'ldap.example.com',
- :port => 636,
- :method => :ssl,
- :base => 'dc=rapidreporting,dc=com',
- :bind_format => "uid=#{ldapuser},ou=People,dc=rapidreporting,dc=com",
- :user => ldapuser,
- :password_block => ldappass,
- :allow_anonymous => false,
- :try_sasl => false
- )
- end
- ## in lib/rrvcldap.rb
- require "rubygems"
- require_gem "ruby-activeldap"
- class LdapGroup < ActiveLDAP::Base
- ldap_mapping :prefix => 'ou=Group', :classes => ['top', 'posixGroup']
- belongs_to :primary_members, :class_name => 'LdapUser', :foreign_key => 'gidNumber',:local_key => 'gidNumber'
- has_many :members, :class_name => 'LdapUser', :local_key => 'memberUid'
- end
- require "base64"
- require "md5"
- require "digest/sha1"
- class LdapUser < ActiveLDAP::Base
- ldap_mapping :dnattr => 'uid', :prefix => 'ou=People', :classes => ['top', 'posixAccount']
- belongs_to :groups, :class_name => 'LdapGroup', :foreign_key => 'memberUid'
- def change_password(newpass)
- salt = [Array.new(6){rand(256).chr}.join].pack("m")[0..7]; # 2^48 combos
- self.userPassword = "{SSHA}" + Base64.encode64(Digest::SHA1.new(newpass.chomp + salt).digest + salt).chomp
- end
- end
- ## User model
- require RAILS_ROOT + "/lib/rrvcldap.rb"
- require_gem "ruby-activeldap"
- require "common_extensions" unless Object.const_defined?("RRVCErrors")
- # this model expects a certain database layout and its based on the name/login pattern.
- class RRVCUser
- include RRVCErrors
- def self.authenticate(login, pass)
- # turn User into Dc::User
- case self.to_s
- when "RRVCUser"
- ActiveLDAP::Base.connect(
- :host => 'darkone.rapidreporting.com',
- :port => 636,
- :base => 'dc=rapidreporting,dc=com',
- :bind_format => "uid=#{login},ou=People,dc=rapidreporting,dc=com",
- :user => login,
- :password_block => Proc.new { pass },
- :allow_anonymous => false,
- :try_sasl => false
- )
- LdapUser.new(login)
- end
- rescue ActiveLDAP::AuthenticationError
- false
- end
- end
Add Comment
Please, Sign In to add comment