Skip to content

Fixes for #170 #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ resources/dev
.bundle
.vagrant
Vagrantfile
*.gem
18 changes: 15 additions & 3 deletions lib/casserver/cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ def generate_proxy_ticket(target_service, pgt)
pt
end

def generate_proxy_granting_ticket(pgt_url, st)
def generate_proxy_granting_ticket(pgt_url, st, validate_ssl = true, limit = 10)
$LOG.debug "Attempting to generate a proxy granting ticket for #{st}"
if limit <= 0
$LOG.warn "Generate proxy granting ticket limit has reached 0 and it will no longer be tried. This usually happens when there is an infinite redirect loop."
return nil
end

uri = URI.parse(pgt_url)
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
https.use_ssl = uri.scheme == "https"
https.verify_mode = OpenSSL::SSL::VERIFY_NONE unless validate_ssl

# Here's what's going on here:
#
Expand All @@ -99,11 +106,16 @@ def generate_proxy_granting_ticket(pgt_url, st)
# in-practice standard.
path += (uri.query.nil? || uri.query.empty? ? '?' : '&') + "pgtId=#{pgt.ticket}&pgtIou=#{pgt.iou}"

$LOG.debug "Making PGT callback to #{path}"
response = conn.request_get(path)
# TODO: follow redirects... 2.5.4 says that redirects MAY be followed
# NOTE: The following response codes are valid according to the JA-SIG implementation even without following redirects

if %w(200 202 301 302 304).include?(response.code)
if %w(301 302).include?(response.code) && response["Location"]
location = response["Location"].gsub("pgtId=#{pgt.ticket}&pgtIou=#{pgt.iou}", "").gsub(/\?$/, "")
$LOG.debug "PGT callback wants to redirect to #{location}. Following..."
generate_proxy_granting_ticket(location, st, validate_ssl, limit - 1)
elsif %w(200 202 304).include?(response.code)
# 3.4 (proxy-granting ticket IOU)
pgt.save!
$LOG.debug "PGT generated for pgt_url '#{pgt_url}': #{pgt.inspect}"
Expand Down
7 changes: 4 additions & 3 deletions lib/casserver/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def self.load_config_file(config_file)
end

config.merge! HashWithIndifferentAccess.new(YAML.load(config_file))
config[:validate_ssl] = true if config[:validate_ssl].nil?
set :server, config[:server] || 'webrick'
end

Expand Down Expand Up @@ -648,7 +649,7 @@ def self.init_database!
if @success
@username = st.username
if @pgt_url
pgt = generate_proxy_granting_ticket(@pgt_url, st)
pgt = generate_proxy_granting_ticket(@pgt_url, st, config[:validate_ssl])
@pgtiou = pgt.iou if pgt
end
@extra_attributes = st.granted_by_tgt.extra_attributes || {}
Expand Down Expand Up @@ -696,7 +697,7 @@ def self.init_database!
end

if @pgt_url
pgt = generate_proxy_granting_ticket(@pgt_url, t)
pgt = generate_proxy_granting_ticket(@pgt_url, t, config[:validate_ssl])
@pgtiou = pgt.iou if pgt
end

Expand Down Expand Up @@ -785,4 +786,4 @@ def authenticated_username
end
end
end
end
end
1 change: 0 additions & 1 deletion locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ label:

button:
login: "ANMELDEN"

2 changes: 1 addition & 1 deletion locales/zh_tw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ label:
central_login_title: "整合登入"

button:
login: "登入"
login: "登入"