Module: AuthenticatesRpi::ActMethods
- Defined in:
- lib/authenticates_rpi.rb
Overview
This module gets mixed-in to ActionController::Base
Instance Method Summary collapse
Instance Method Details
#authenticate_rpi(user_class, opts = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/authenticates_rpi.rb', line 5 def authenticate_rpi ( user_class, opts={} ) include InstanceMethods # logger.info "----------------------------------------------" # logger.info "autheticates_rpi mixed in ( on Rails " + # Rails::VERSION::STRING + " )" #Username field is required; used to look up the value from CAS. username_field = opts[:username_field] || "username" #Fields that we'll fill in from LDAP, in addition to username_field fullname_field = opts[:fullname_field] || nil firstname_field = opts[:firstname_field] || nil lastname_field = opts[:lastname_field] || nil email_field = opts[:email_field] || nil #Admin field is optional if the site has admins. If none specified, #all users recieve false for admin_logged_in. admin_field = opts[:admin_field] autoadd = opts[:autoadd_users] || false sudo_enabled = opts[:sudo_enabled] || false ldap_address = opts[:ldap_address] || nil ldap_port = opts[:ldap_port] || 389 ldap_dn = opts[:ldap_dn] || nil ldap_username_field = opts[:ldap_username_field] || 'uid' ldap_email_field = opts[:ldap_email_field] || 'mailAlternateAddress' #Argument Validation #TODO: proper exceptions to raise, not just runtime junk unless user_class.instance_of?(Class) raise 'user_class must be a class' end unless user_class.new.respond_to?(username_field) raise 'username_field: no such method "' + username_field + '" on class ' + user_class.name end unless admin_field.nil? || user_class.new.respond_to?(admin_field) raise 'admin_field: no such method "' + admin_field + '" on class ' + user_class.name end #Argument Storage write_inheritable_attribute :user_class, user_class write_inheritable_attribute :username_field, username_field write_inheritable_attribute :fullname_field, fullname_field write_inheritable_attribute :firstname_field, firstname_field write_inheritable_attribute :email_field, email_field write_inheritable_attribute :lastname_field, lastname_field write_inheritable_attribute :admin_field, admin_field write_inheritable_attribute :autoadd_users, autoadd write_inheritable_attribute :sudo_enabled, sudo_enabled write_inheritable_attribute :ldap_address, ldap_address write_inheritable_attribute :ldap_port, ldap_port write_inheritable_attribute :ldap_dn, ldap_dn write_inheritable_attribute :ldap_username_field, ldap_username_field write_inheritable_attribute :ldap_email_field, ldap_email_field class_inheritable_reader :user_class, :username_field, :fullname_field, :firstname_field, :lastname_field, :admin_field, :autoadd_users, :ldap_address, :ldap_port, :ldap_dn, :ldap_username_field, :sudo_enabled, :email_field, :ldap_email_field end |