Created
February 3, 2011 23:17
-
-
Save sahglie/810438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_var(text) | |
if text.include?(",") | |
return test.split(",") | |
elsif text.include?(",") | |
return test.split(";") | |
else | |
[text] | |
end | |
end | |
ldap_uids = parse_var(shib_uid) | |
user = ldap_uids.find { |uid| User.find_by_ldap_uid(uid) } | |
valid_shib_uid = user.try(:ldap_uid) | |
class Shib | |
class << self | |
def get_user(http_env_hash) | |
logger.debug("HTTP_SHIB_IDENTITY_PROVIDER : #{request.env['HTTP_SHIB_IDENTITY_PROVIDER'].inspect}") | |
logger.debug("request.env output:") | |
request.env.each { |k,v| logger.debug("#{k}: #{v}") } | |
shib_idp = http_env_hash['HTTP_SHIB_IDENTITY_PROVIDER'] # has a value like: "urn:mace:incommon:berkeley.edu" | |
# if campus = Campus.find_by_shibboleth_identity_provider(shib_idp) | |
ldap_uid = extract_attributes(http_env_hash['HTTP_UID']).first | |
eppn = extract_attributes(http_env_hash['HTTP_EPPN']).first | |
emails = extract_attributes(http_env_hash['HTTP_MAIL']) | |
if user = User.find_by_ldap_uid(ldap_uid) | |
user.eppn = eppn | |
user.save! | |
return user | |
end | |
return user if user = User.find_by_eppn(eppn) | |
if user = emails.find { |email| User.find_by_email(email) } | |
user.eppn = eppn | |
user.uid = ldap_uid | |
user.save! | |
user | |
end | |
end | |
## | |
# Some attributes may be multi-valued. Multi-valued attributes are | |
# delimited by "," or ";" | |
# | |
# @param [String] | |
# @return [Array<String>] | |
# | |
def extract_attributes(text) | |
if text.include?(",") | |
return test.split(",") | |
elsif text.include?(",") | |
return test.split(";") | |
else | |
[text] | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment