Skip to content

Commit

Permalink
Audit log when login fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jlledom committed Sep 10, 2024
1 parent 4ea6e2d commit ca21bb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/provider/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def create
else
new
flash.now[:error] ||= strategy&.error_message
attempted_cred = auth_params.fetch(:username, nil) || sso_params.fetch(:token, nil)
AuditLogService.call("Login attempt failed: #{domain_account.external_admin_domain} - #{attempted_cred}")
render :action => :new
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ def create
self.current_user = @user
create_user_session!
flash[:notice] = @strategy.new_user_created? ? 'Signed up successfully' : 'Signed in successfully'

AuditLogService.call("Signed in: #{current_user.id}/#{current_user.username} #{current_user.first_name} #{current_user.last_name}")

redirect_back_or_default(@strategy.redirect_to_on_successful_login)
elsif @strategy.redirects_to_signup?
@strategy.on_signup(session)

redirect_to @strategy.signup_path(params), notice: 'Successfully authenticated, please complete the signup form'
else
attempted_cred = auth_strategy_is_internal? ? params.fetch(:username, nil) : params.fetch(:token, nil)
AuditLogService.call("Login attempt failed: #{request.internal_host} - #{attempted_cred}")

render_login_error(@strategy.error_message)
end
end

def destroy
user = current_user
logout_killing_session!
destroy_user_session!

AuditLogService.call("Signed out: #{user.id}/#{user.username} #{user.first_name} #{user.last_name}")

redirect_to root_url, notice: "You have been logged out."
end

Expand Down

0 comments on commit ca21bb0

Please sign in to comment.