Skip to content

Commit

Permalink
Merge pull request #15321 from hennevogel/refactoring/proxy_mode
Browse files Browse the repository at this point in the history
Introduces Configuration.proxy_auth_mode_enabled?
  • Loading branch information
hennevogel committed Dec 6, 2023
2 parents 6f52bc4 + d796a2c commit 1879487
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/person_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def internal_register
note = xml.elements['/unregisteredperson/note'].text if xml.elements['/unregisteredperson/note']
status = xml.elements['/unregisteredperson/state'].text if xml.elements['/unregisteredperson/status']

if authenticator.proxy_mode?
if ::Configuration.proxy_auth_mode_enabled?
raise ErrRegisterSave, 'Missing iChain header' if request.env['HTTP_X_USERNAME'].blank?

login = request.env['HTTP_X_USERNAME']
Expand Down
10 changes: 3 additions & 7 deletions src/api/app/helpers/authentication_protocol_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ def kerberos_mode?
CONFIG['kerberos_mode']
end

def proxy_mode?
CONFIG['proxy_auth_mode'] == :on
end

def can_sign_up?
return CONFIG['proxy_auth_register_page'].present? if proxy_mode?
return CONFIG['proxy_auth_register_page'].present? if ::Configuration.proxy_auth_mode_enabled?

can_register?
end
Expand All @@ -26,15 +22,15 @@ def can_register?
end

def log_in_params
if proxy_mode?
if ::Configuration.proxy_auth_mode_enabled?
{ url: CONFIG['proxy_auth_login_page'], options: { method: :post, enctype: 'application/x-www-form-urlencoded' } }
else
{ url: session_path, options: { method: :post } }
end
end

def sign_up_params
return { url: CONFIG['proxy_auth_register_page'] } if proxy_mode?
return { url: CONFIG['proxy_auth_register_page'] } if ::Configuration.proxy_auth_mode_enabled?

{ url: signup_path }
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/webui/webui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def feature_css_class
def sign_up_link(css_class: nil)
return unless can_sign_up?

if proxy_mode?
if ::Configuration.proxy_auth_mode_enabled?
link_to(sign_up_params[:url], class: css_class) do
link_content('Sign Up', css_class, 'fa-user-plus')
end
Expand Down
6 changes: 1 addition & 5 deletions src/api/app/lib/authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ def initialize(request, session, response)
@user_permissions = nil
end

def proxy_mode?
CONFIG['proxy_auth_mode'] == :on || CONFIG['ichain_mode'] == :on
end

def extract_user
if proxy_mode?
if ::Configuration.proxy_auth_mode_enabled?
extract_proxy_user
else
extract_auth_user
Expand Down
4 changes: 4 additions & 0 deletions src/api/app/models/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def ldap_enabled?
CONFIG['ldap_mode'] == :on
end

def proxy_auth_mode_enabled?
CONFIG['proxy_auth_mode'] == :on || CONFIG['ichain_mode'] == :on
end

def amqp_namespace
CONFIG['amqp_namespace'] || 'opensuse.obs'
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/layouts/webui/_login_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.h2.text-center.py-2 Log In
= form_tag(log_in_params[:url], log_in_params[:options]) do
- if proxy_mode?
- if ::Configuration.proxy_auth_mode_enabled?
= hidden_field_tag(:context, 'default')
= hidden_field_tag(:proxypath, 'reserve')
= hidden_field_tag(:message, 'Please log in')
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/layouts/webui/_top_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
= render partial: 'layouts/webui/top_navigation_nobody'

- if User.possibly_nobody.is_nobody? && !kerberos_mode?
- if !proxy_mode? && can_sign_up?
- if !::Configuration.proxy_auth_mode_enabled? && can_sign_up?
= render partial: 'layouts/webui/sign_up_modal'
= render partial: 'layouts/webui/login_modal'
2 changes: 1 addition & 1 deletion src/api/app/views/webui/session/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- button_css ||= ''

= form_tag(log_in_params[:url], log_in_params[:options]) do
- if proxy_mode?
- if ::Configuration.proxy_auth_mode_enabled?
= hidden_field_tag(:context, 'default')
= hidden_field_tag(:proxypath, 'reserve')
= hidden_field_tag(:message, 'Please log in')
Expand Down

0 comments on commit 1879487

Please sign in to comment.