Skip to content
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

Forces renew session actions to go through same auth pipeline as a br… #250

Merged
merged 1 commit into from
Sep 10, 2020
Merged
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
17 changes: 12 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,28 @@ def patron_info_response
end

def authenticate_user!
set_original_fullpath

return redirect_to root_url unless current_user?

# Go through auth (which happens at the root_url which is the SessionsController)
unless current_user?
set_original_fullpath
return redirect_to root_url
end

# So current_user is set, Warden has got a user for us. However, our session with Sirsi WS has not gone stale.
# We know it's stale because the ping returned something other than 200.
renew_session_token unless symphony_client.ping?(current_user)
end

# This is used in the scenario where a user is not known to Warden yet. The application will redirect the
# user back to this originally requested URL after the authentication has taken place.
def set_original_fullpath
session[:original_fullpath] = request.original_fullpath unless request.original_fullpath == '/'
end

# Things have gotten stale, clear user out by logging Warden out and send back through the authentication pipes.
def renew_session_token
request.env['warden'].logout

authenticate_webaccess
authenticate_user!
end

def item_details
Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/summaries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@
context 'with a stale session' do
let(:ping_response) { false }

before do
allow(controller).to receive(:current_user?).and_return(true, false)
end

it 'redirects to the application authentication mechanism' do
get(:index)

expect(response).to have_http_status '302'
expect(response).to redirect_to root_url
end
end
end
Expand Down