Detecting Debian SSO client certificates for login
This commit is contained in:
parent
0790310b01
commit
52ff0be45a
1 changed files with 34 additions and 1 deletions
|
|
@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
|
|||
# Do not mention passwords in the log file
|
||||
# filter_parameter_logging :password
|
||||
|
||||
before_action :get_current_users_screenshots
|
||||
before_action :get_current_users_screenshots, :debian_sso
|
||||
|
||||
# Query for packages that were uploaded by the current user.
|
||||
# As AAA is not yet implemented it means looking for uploads
|
||||
|
|
@ -17,4 +17,37 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
# If the visitor presents a valid SSL client certificate from Debian SSO
|
||||
# then the frontend web server will send a certain request header.
|
||||
# Log the user in and welcome them.
|
||||
def debian_sso
|
||||
# Only run if the user is not yet logged in
|
||||
if not user_signed_in?
|
||||
if debian_sso_dn = request.env['HTTP_X_DEBIAN_SSO_DN']
|
||||
debian_sso_dn =~ /\/CN=(.+)/
|
||||
debian_email = $1
|
||||
|
||||
@user = User.where(provider: 'debian-sso', email: debian_email).first_or_create do |user|
|
||||
user.provider = 'debian-sso'
|
||||
user.email = debian_email
|
||||
user.name = debian_email
|
||||
# Set a random password
|
||||
user.password = Devise.friendly_token[0,20]
|
||||
end
|
||||
|
||||
if @user.persisted?
|
||||
flash[:notice] = 'You are logged in through the Debian SSO'
|
||||
sign_in_and_redirect @user, :event => :authentication
|
||||
else
|
||||
redirect_to root_path, alert: @user.errors.full_messages.join("\n")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Define where the user is redirected to after a successful login.
|
||||
def after_sign_in_path_for(resource)
|
||||
my_welcome_path
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue