Skip to content

Commit

Permalink
Merge pull request #2501 from pulibrary/add-logging
Browse files Browse the repository at this point in the history
Add logging for patron controller authorization
  • Loading branch information
christinach authored Oct 3, 2024
2 parents 0e2193e + 4192912 commit 7c4a9cc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/controllers/patron_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,22 @@ def patron_group
end

def protect
Rails.logger.info("Incoming patron request: IP is #{request.remote_ip}, User signed in is #{user_signed_in?}")
if user_signed_in?
deny_access unless current_user.catalog_admin?
else
ips = Rails.application.config.ip_allowlist
deny_access if ips.exclude?(request.remote_ip)
Rails.logger.info("Is IP address excluded from the allow list?: #{ips.exclude?(request.remote_ip)}")
if ips.exclude?(request.remote_ip)
deny_access
Rails.logger.info("Denied patron request: IP #{request.remote_ip} is not in the list: #{ips.join(', ')}")
headers = {}.tap do |envs|
request.headers.each do |key, value|
envs[key] = value if key.downcase.starts_with?('http')
end
end
Rails.logger.info("Headers of the request: #{headers}")
end
end
end

Expand Down

0 comments on commit 7c4a9cc

Please sign in to comment.