rails 4 devise ldap_authenticatable current_user not set -
i'm new rails 4 , experimenting devise , ldap_authenticatable , see i'm not sure right. when authenticate active directory devise works fine , stores user in mysql database expected. however, seem lose user params , can't tell user authenticated. user_signed_in? returns false if hit login link message "already signed in" current_user nil , set_user fails because params(:id) nil. seems broken here i'm not sure norm far devise setting or keeping user params alive. ideas or helpful information? user model:
class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :ldap_authenticatable, :trackable, :validatable before_save :get_ldap_attrs def get_ldap_attrs self.firstname = devise::ldap::adapter.get_ldap_param(self.email, 'givenname') self.lastname = devise::ldap::adapter.get_ldap_param(self.email, 'sn') self.login = devise::ldap::adapter.get_ldap_param(self.email, 'samaccountname') self.email = devise::ldap::adapter.get_ldap_param(self.email,'mail').first self.studentid = devise::ldap::adapter.get_ldap_param(self.email, 'title') end end ---- ldap.yaml ## authorizations # uncomment out merging each environment you'd include. # can copy , paste tree (do not include "authorizations") each # environment if need different per enviornment. authorizations: &authorizations allow_unauthenticated_bind: false group_base: ou=groups,dc=kentshill,dc=org ## requires config.ldap_check_group_membership in devise.rb true # can have multiple values, must match authorized required_groups: # if group name given, membership checked against "uniquemember" #- ######################## #- ####################### # if array given, first element attribute check against, second group name #- ["moremembers", "cn=users,ou=groups,dc=test,dc=com"] ## requires config.ldap_check_attributes in devise.rb true ## can have multiple attributes , values, must match authorized require_attribute: objectclass: inetorgperson authorizationrole: postsadmin ## environment development: host: address port: 636 attribute: mail base: dn admin_user: fqn user privs admin_password: password ssl: true # <<: *authorizations test: host: localhost port: 3389 attribute: cn base: ou=people,dc=test,dc=com admin_user: cn=admin,dc=test,dc=com admin_password: admin_password ssl: simple_tls # <<: *authorizations production: host: localhost port: 636 attribute: cn base: ou=people,dc=test,dc=com admin_user: cn=admin,dc=test,dc=com admin_password: admin_password ssl: start_tls # <<: *authorizations ---------------- devise initializer # use hook configure devise mailer, warden hooks , forth. # many of these configuration options can set straight in model. devise.setup |config| # ==> ldap configuration config.ldap_logger = true config.ldap_create_user = true config.ldap_update_password = true #config.ldap_config = "#{rails.root}/config/ldap.yml" config.ldap_check_group_membership = false #config.ldap_check_group_membership_without_admin = false config.ldap_check_attributes = false config.ldap_use_admin_to_bind = true config.ldap_ad_group_check = false # secret key used devise. devise uses key generate # random tokens. changing key render invalid existing # confirmation, reset password , unlock tokens in database. # devise use `secret_key_base` on rails 4+ applications `secret_key` # default. can change below , use own secret key. # config.secret_key = 'ead157a98cc1402f93c717c537225a807971f381bdb51063b22d9979b39e0db385493e0d392999152597ce52baf327d97ffc9a59371ea3258cd8f5fc6d158b75' # ==> mailer configuration # configure e-mail address shown in devise::mailer, # note overwritten if use own mailer class # default "from" parameter. config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' # configure class responsible send e-mails. # config.mailer = 'devise::mailer' # ==> orm configuration # load , configure orm. supports :active_record (default) , # :mongoid (bson_ext recommended) default. other orms may # available additional gems. require 'devise/orm/active_record' config.ldap_auth_username_builder = proc.new() { |attribute, login, ldap| login } # config.warden |manager| # manager.default_strategies(:scope => :user).unshift :ldap_authenticatable # end # ==> configuration authentication mechanism # configure keys used when authenticating user. default # :email. can configure use [:username, :subdomain], # authenticating user, both parameters required. remember # parameters used when authenticating , not when retrieving # session. if need permissions, should implement in before filter. # can supply hash value boolean determining whether # or not authentication should aborted when value not present. config.authentication_keys = [:email] # configure parameters request object used authentication. each entry # given should request method , automatically passed # find_for_authentication method , considered in model lookup. instance, # if set :request_keys [:subdomain], :subdomain used on authentication. # same considerations mentioned authentication_keys apply request_keys. # config.request_keys = [] # configure authentication keys should case-insensitive. # these keys downcased upon creating or modifying user , when used # authenticate or find user. default :email. config.case_insensitive_keys = [:email] "config/initializers/devise.rb" 280l, 13721c
Comments
Post a Comment