Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Add capability to add optional suffix to username #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/casino/ldap_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class CASino::LDAPAuthenticator
DEFAULT_USERNAME_ATTRIBUTE = 'uid'
DEFAULT_USERNAME_SUFFIX = ''

# @param [Hash] options
def initialize(options)
Expand Down Expand Up @@ -59,7 +60,7 @@ def load_user_data_with_connection(username, ldap)

def user_data(user)
{
username: user[username_attribute].first,
username: user[username_attribute].first.chomp(username_suffix),
extra_attributes: extra_attributes(user)
}
end
Expand All @@ -68,8 +69,12 @@ def username_attribute
@options[:username_attribute] || DEFAULT_USERNAME_ATTRIBUTE
end

def username_suffix
@options[:username_suffix] || DEFAULT_USERNAME_SUFFIX
end

def user_filter(username)
filter = Net::LDAP::Filter.eq(username_attribute, username)
filter = Net::LDAP::Filter.eq(username_attribute, username + username_suffix)
unless @options[:filter].nil?
filter &= Net::LDAP::Filter.construct(@options[:filter])
end
Expand Down