Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

SAML Ui

Oliver Günther76386c79edb3
diff --git a/modules/auth_saml/app/components/saml/providers/row_component.rb b/modules/auth_saml/app/components/saml/providers/row_component.rb
new file mode 100644
index 00000000000..5fc382a8e1b
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/row_component.rb
@@ -0,0 +1,40 @@
+module Saml
+ module Providers
+ class RowComponent < ::RowComponent
+ def provider
+ model
+ end
+
+ def name
+ link_to(
+ provider.display_name || provider.name,
+ url_for(action: :edit, id: provider.id)
+ )
+ end
+
+ def button_links
+ [edit_link, delete_link].compact
+ end
+
+ def edit_link
+ link_to(
+ helpers.op_icon('icon icon-edit button--link'),
+ url_for(action: :edit, id: provider.id),
+ title: t(:button_edit)
+ )
+ end
+
+ def delete_link
+ return if provider.readonly
+
+ link_to(
+ helpers.op_icon('icon icon-delete button--link'),
+ url_for(action: :destroy, id: provider.id),
+ method: :delete,
+ data: { confirm: I18n.t(:text_are_you_sure) },
+ title: t(:button_delete)
+ )
+ end
+ end
+ end
+end
diff --git a/modules/auth_saml/app/components/saml/providers/table_component.rb b/modules/auth_saml/app/components/saml/providers/table_component.rb
new file mode 100644
index 00000000000..9cb15f87c87
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/table_component.rb
@@ -0,0 +1,25 @@
+module Saml
+ module Providers
+ class TableComponent < ::TableComponent
+ columns :name
+
+ def initial_sort
+ %i[id asc]
+ end
+
+ def sortable?
+ false
+ end
+
+ def empty_row_message
+ I18n.t 'saml.providers.no_results_table'
+ end
+
+ def headers
+ [
+ ['name', { caption: I18n.t('attributes.name') }]
+ ]
+ end
+ end
+ end
+end
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rb
new file mode 100644
index 00000000000..9dd7ed85118
--- /dev/null
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -0,0 +1,85 @@
+module Saml
+ class ProvidersController < ::ApplicationController
+ layout 'admin'
+ menu_item :plugin_saml
+
+ before_action :require_admin
+ before_action :check_ee
+ before_action :find_provider, only: %i[edit update destroy]
+
+ def index; end
+
+ def new
+ @provider = ::Saml::Provider.new(defaults)
+ end
+
+ def create
+ @provider = ::Saml::Provider.new(create_params)
+
+ if @provider.save
+ flash[:notice] = I18n.t(:notice_successful_create)
+ redirect_to action: :index
+ else
+ render action: :new
+ end
+ end
+
+ def edit; end
+
+ def update
+ @provider = ::OpenIDConnect::Provider.initialize_with(
+ update_params.merge("name" => params[:id])
+ )
+ if @provider.save
+ flash[:notice] = I18n.t(:notice_successful_update)
+ redirect_to action: :index
+ else
+ render action: :edit
+ end
+ end
+
+ def destroy
+ if @provider.destroy
+ flash[:notice] = I18n.t(:notice_successful_delete)
+ else
+ flash[:error] = I18n.t(:error_failed_to_delete_entry)
+ end
+
+ redirect_to action: :index
+ end
+
+ private
+
+ def defaults
+ {
+ }
+ end
+
+ def check_ee
+ unless EnterpriseToken.allows_to?(:openid_providers)
+ render template: '/saml/providers/upsale'
+ false
+ end
+ end
+
+ def create_params
+ params.require(:openid_connect_provider).permit(:name, :display_name, :identifier, :secret, :limit_self_registration)
+ end
+
+ def update_params
+ params.require(:openid_connect_provider).permit(:display_name, :identifier, :secret, :limit_self_registration)
+ end
+
+ def find_provider
+ @provider = providers.find { |provider| provider.id.to_s == params[:id].to_s }
+ if @provider.nil?
+ render_404
+ end
+ end
+
+ def providers
+ @providers ||= OpenProject::AuthSaml.providers
+ end
+ helper_method :providers
+ end
+end
diff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rb
new file mode 100644
index 00000000000..e7e75bf7f7d
--- /dev/null
+++ b/modules/auth_saml/app/models/saml/provider.rb
@@ -0,0 +1,144 @@
+module Saml
+ class Provider < OpenStruct
+ DEFAULT_NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'.freeze
+
+ include ActiveModel::Validations
+ include ActiveModel::Conversion
+
+ attr_accessor :name, :readonly
+ validates_presence_of :name, :display_name
+
+ def initialize(name, attributes = {}, readonly: false)
+ self.name = name
+ self.readonly = readonly
+ super(attributes)
+
+ set_default_attributes(attributes)
+ end
+
+ def id
+ name
+ end
+
+ def sp_entity_id
+ super.presence || issuer.presence || url_helpers.root_url
+ end
+
+ def attribute_statements
+ super.presence || {}
+ end
+
+ %w[login email first_name last_name].each do |accessor|
+ define_method("#{accessor}_mapping") do
+ value = attribute_statements[accessor]
+ warn value
+ if value.is_a?(Array)
+ value.join(', ')
+ else
+ value
+ end
+ end
+
+ define_method("#{accessor}_mapping=") do |newval|
+ parsed = newval.split(/\s*,\s*/)
+ attribute_statements[accessor] = parsed
+ end
+ end
+
+ def new_record?
+ !persisted?
+ end
+
+ def persisted?
+ uuid.present?
+ end
+
+ def limit_self_registration?
+ limit_self_registration
+ end
+
+ def save
+ return false unless valid?
+
+ Setting.plugin_openproject_auth_saml = setting_with_provider
+
+ true
+ end
+
+ def destroy
+ Setting.plugin_openproject_auth_saml = setting_without_provider
+
+ true
+ end
+
+ def setting_with_provider
+ setting.deep_merge "providers" => { name => to_h.stringify_keys }
+ end
+
+ def to_h
+ super
+ .reverse_merge(uuid: SecureRandom.uuid)
+ .merge(derived_attributes)
+ end
+
+ def setting_without_provider
+ setting.tap do |s|
+ s["providers"].delete_if { |_, config| config['id'] == id }
+ end
+ end
+
+ def setting
+ Hash(Setting.plugin_openproject_auth_saml).tap do |h|
+ h["providers"] ||= Hash.new
+ end
+ end
+
+ private
+
+ def set_default_attributes(attributes)
+ self.limit_self_registration = attributes.fetch(:limit_self_registration, false)
+ self.name_identifier_format = attributes.fetch(:name_identifier_format, DEFAULT_NAME_IDENTIFIER_FORMAT)
+ self.issuer = attributes.fetch(:issuer, url_helpers.root_url)
+ self.request_attributes = attributes.fetch(:request_attributes, default_request_attributes)
+ end
+
+ def default_request_attributes
+ [
+ {
+ "name" => "mail",
+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
+ "friendly_name" => "Email address",
+ "is_required" => true
+ },
+ {
+ "name" => "givenName",
+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
+ "friendly_name" => "Given name",
+ "is_required" => true
+ },
+ {
+ "name" => "sn",
+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
+ "friendly_name" => "Family name",
+ "is_required" => true
+ },
+ {
+ "name" => "uid",
+ "name_format" => "urn:oasis:names:tc:SAML:2.0:attrname-format:basic",
+ "friendly_name" => "Stable unique ID / login of the user",
+ "is_required" => true
+ }
+ ]
+ end
+
+ def derived_attributes
+ {
+ assertion_consumer_service_url: url_helpers.root_url.join("/auth/#{name}/callback")
+ }
+ end
+
+ def url_helpers
+ @url_helpers ||= OpenProject::StaticRouting::StaticUrlHelpers.new
+ end
+ end
+end
diff --git a/modules/auth_saml/app/views/saml/providers/_form.html.erb b/modules/auth_saml/app/views/saml/providers/_form.html.erb
new file mode 100644
index 00000000000..296d0d79bb2
--- /dev/null
+++ b/modules/auth_saml/app/views/saml/providers/_form.html.erb
@@ -0,0 +1,110 @@
+<fieldset class="form--fieldset">
+ <div class="form--field -required">
+ <%= f.text_field :name, required: true, disable: f.object.persisted?, container_class: '-middle' %>
+ </div>
+
+ <div class="form--field -required">
+ <%= f.text_field :display_name, required: true, container_class: '-middle' %>
+ </div>
+
+ <div class="form--field">
+ <%= f.text_field :sp_entity_id, required: false, container_class: '-middle' %>
+ </div>
+
+ <div class="form--field -required">
+ <%= f.text_field :idp_sso_target_url, required: true, container_class: '-xwide' %>
+ </div>
+
+ <div class="form--field">
+ <%= f.text_field :idp_slo_target_url, required: false, container_class: '-xwide' %>
+ </div>
+
+ <div class="form--field">
+ <%= f.text_field :idp_cert_fingerprint,
+ required: false,
+ container_class: '-xwide' %>
+ </div>
+
+ <div class="form--field">
+ <%= f.text_area :idp_cert, required: false, rows: 10, columns: 20, container_class: '-xwide' %>
+ </div>
+
+ <div class="form--field">
+ <%= f.check_box :limit_self_registration, required: false, container_class: '-middle' %>
+ <div class="form--field-instructions">
+ <%= I18n.t('openid_connect.setting_instructions.limit_self_registration') %>
+ </div>
+ </div>
+
+ <div class="form--field">
+ <%= f.text_field :name_identifier_format, required: false, container_class: '-xwide' %>
+ </div>
+</fieldset>
+
+<fieldset class="form--fieldset">
+ <legend class="form--fieldset-legend"><%= t('saml.providers.attribute_mapping') %></legend>
+ <p><%= t 'saml.providers.attribute_mapping_text' %></p>
+
+ <div class="form--field -required">
+ <%= f.text_field 'login_mapping',
+ required: true,
+ size: 20,
+ container_class: '-middle' %>
+ <span class="form--field-instructions">
+ <%= t('ldap_auth_sources.attribute_texts.login_map') %>
+ </span>
+ </div>
+ <div class="form--field">
+ <%= f.text_field 'first_name_mapping',
+ size: 20,
+ container_class: '-middle' %>
+ <span class="form--field-instructions">
+ <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: ApplicationRecord.human_attribute_name(:firstname)) %>
+ </span>
+ </div>
+ <div class="form--field">
+ <%= f.text_field 'last_name_mapping',
+ size: 20,
+ container_class: '-middle' %>
+ <span class="form--field-instructions">
+ <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: ApplicationRecord.human_attribute_name(:lastname)) %>
+ </span>
+ </div>
+ <div class="form--field">
+ <%= f.text_field 'email_mapping',
+ size: 20,
+ placeholder: 'mail',
+ container_class: '-middle' %>
+ <span class="form--field-instructions">
+ <%= t('ldap_auth_sources.attribute_texts.generic_map', attribute: ApplicationRecord.human_attribute_name(:mail)) %>
+ </span>
+ </div>
+</fieldset>
+
+<fieldset class="form--fieldset">
+ <legend class="form--fieldset-legend"><%= t('saml.providers.request_attributes.title') %></legend>
+ <p><%= t 'saml.providers.request_attributes.legend' %></p>
+
+ <% @provider.request_attributes.each do |request| %>
+ <% base_key = "saml_request_#{request['name']}" %>
+ <div class="form--field -required">
+ <%= styled_label_tag "#{base_key}_name", t('saml.providers.requested_attributes.name') %>
+ <div class="form--field-container">
+ <%= text_field_tag 'saml_provider[request_attributes][][name]',
+ request['name'],
+ id: "#{base_key}_name"
+ %>
+ </div>
+ </div>
+ <div class="form--field -required">
+ <%= styled_label_tag "#{base_key}_format", t('saml.providers.requested_attributes.format') %>
+ <div class="form--field-container">
+ <%= text_field_tag 'saml_provider[request_attributes][][name_format]',
+ request['name_format'],
+ id: "#{base_key}_format"
+ %>
+ </div>
+ </div>
+ <hr/>
+ <% end %>
+</fieldset>
diff --git a/modules/auth_saml/app/views/saml/providers/edit.html.erb b/modules/auth_saml/app/views/saml/providers/edit.html.erb
new file mode 100644
index 00000000000..25d092111a5
--- /dev/null
+++ b/modules/auth_saml/app/views/saml/providers/edit.html.erb
@@ -0,0 +1,19 @@
+<% page_title = t('saml.providers.label_edit', name: @provider.name) %>
+<% local_assigns[:additional_breadcrumb] = @provider.name %>
+
+<% html_title(t(:label_administration), page_title) -%>
+
+<%= toolbar title: page_title %>
+
+<%= error_messages_for @provider %>
+
+<%= @provider.assertion_consumer_service_url %>
+
+<%= labelled_tabular_form_for @provider,
+ html: { class: 'form', autocomplete: 'off' } do |f| %>
+ <%= render partial: "form", locals: { f: f } %>
+ <p>
+ <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %>
+ <%= link_to t(:button_cancel), { action: :index }, class: 'button -with-icon icon-cancel' %>
+ </p>
+<% end %>
diff --git a/modules/auth_saml/app/views/saml/providers/index.html.erb b/modules/auth_saml/app/views/saml/providers/index.html.erb
new file mode 100644
index 00000000000..c25b47bf504
--- /dev/null
+++ b/modules/auth_saml/app/views/saml/providers/index.html.erb
@@ -0,0 +1,18 @@
+<% html_title t(:label_administration), t('saml.providers.plural') %>
+
+<%= render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { t('saml.providers.plural') }
+ header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
+ t('saml.providers.plural')])
+ header.with_action_button(scheme: :primary,
+ aria: { label: t('saml.providers.label_add_new') },
+ mobile_icon: :plus,
+ mobile_label: t('saml.providers.label_add_new'),
+ tag: :a,
+ href: new_saml_provider_path) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t('saml.providers.singular')
+ end
+end %>
+
+<%= render ::Saml::Providers::TableComponent.new(rows: providers) %>
diff --git a/modules/auth_saml/app/views/saml/providers/new.html.erb b/modules/auth_saml/app/views/saml/providers/new.html.erb
new file mode 100644
index 00000000000..50ae9f727d3
--- /dev/null
+++ b/modules/auth_saml/app/views/saml/providers/new.html.erb
@@ -0,0 +1,15 @@
+<% html_title(t(:label_administration), t('saml.providers.label_add_new')) -%>
+<% local_assigns[:additional_breadcrumb] = t('saml.providers.label_add_new') %>
+
+<%= toolbar title: t('saml.providers.label_add_new') %>
+
+<%= error_messages_for @provider %>
+
+<%= labelled_tabular_form_for @provider,
+ html: { class: 'form', autocomplete: 'off' } do |f| %>
+ <%= render partial: "form", locals: { f: f } %>
+ <p>
+ <%= styled_button_tag t(:button_create), class: '-highlight -with-icon icon-checkmark' %>
+ <%= link_to t(:button_cancel), { action: :index }, class: 'button -with-icon icon-cancel' %>
+ </p>
+<% end %>
diff --git a/modules/auth_saml/app/views/saml/providers/upsale.html.erb b/modules/auth_saml/app/views/saml/providers/upsale.html.erb
new file mode 100644
index 00000000000..5a3b6742c1d
--- /dev/null
+++ b/modules/auth_saml/app/views/saml/providers/upsale.html.erb
@@ -0,0 +1,9 @@
+<% html_title(t(:label_administration), t('saml.providers.plural')) -%>
+
+<%= render template: 'common/upsale',
+ locals: {
+ feature_title: t('saml.providers.plural'),
+ feature_description: t('saml.providers.upsale.description'),
+ feature_reference: 'enterprise-openid-connect',
+ feature_image: 'enterprise/open-id-providers.jpg' # TODO
+ } %>
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
new file mode 100644
index 00000000000..5121b7a28ca
--- /dev/null
+++ b/modules/auth_saml/config/locales/en.yml
@@ -0,0 +1,33 @@
+en:
+ activemodel:
+ attributes:
+ saml/provider:
+ name: Name
+ display_name: Display name
+ identifier: Identifier
+ secret: Secret
+ scope: Scope
+ limit_self_registration: Limit self registration
+ sp_entity_id: Service entity ID
+ saml:
+ menu_title: SAML providers
+ providers:
+ label_add_new: Add a new SAML provider
+ label_edit: Edit SAML provider %{name}
+ no_results_table: No providers have been defined yet.
+ plural: SAML providers
+ singular: SAML provider
+ attribute_mapping: Attribute mapping
+ attribute_mapping_text: >
+ The following fields control which attributes provided by the SAML identity provider
+ are used to provide user attributes in OpenProject
+ upsale:
+ description: Connect OpenProject to a SAML identity provider
+ request_attributes:
+ title: 'Requested attributes'
+ legend: 'These attributes are added to the SAML XML metadata to signify to the identify provider which attributes OpenProject requires.'
+ name: 'Requested attribute key'
+ format: 'Attribute format'
+ setting_instructions:
+ limit_self_registration: >
+ If enabled users can only register using this provider if the self registration setting allows for it.
diff --git a/modules/auth_saml/config/routes.rb b/modules/auth_saml/config/routes.rb
new file mode 100644
index 00000000000..5e26b8ceaee
--- /dev/null
+++ b/modules/auth_saml/config/routes.rb
@@ -0,0 +1,7 @@
+Rails.application.routes.draw do
+ scope :admin do
+ namespace :saml do
+ resources :providers, only: %i[index new create edit update destroy]
+ end
+ end
+end
diff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
index 09f680d1cc3..202b64e4887 100644
--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb
+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
@@ -3,20 +3,19 @@ module OpenProject
module AuthSaml
def self.configuration
RequestStore.fetch(:openproject_omniauth_saml_provider) do
- @saml_settings ||= load_global_settings!
- @saml_settings.deep_merge(settings_from_db)
+ global_configuration.deep_merge(settings_from_db)
end
end
def self.reload_configuration!
- @saml_settings = nil
+ @global_configuration = nil
RequestStore.delete :openproject_omniauth_saml_provider
end
##
# Loads the settings once to avoid accessing the file in each request
- def self.load_global_settings!
- Hash(settings_from_config || settings_from_yaml).with_indifferent_access
+ def self.global_configuration
+ @global_configuration ||= Hash(settings_from_config || settings_from_yaml).with_indifferent_access
end
def self.settings_from_db
@@ -25,6 +24,13 @@ module OpenProject
value.is_a?(Hash) ? value : {}
end
+ def self.providers
+ configuration.map do |name, config|
+ readonly = global_configuration.keys.include?(name)
+ ::Saml::Provider.new(name, config, readonly:)
+ end
+ end
+
def self.settings_from_config
if OpenProject::Configuration["saml"].present?
Rails.logger.info("[auth_saml] Registering saml integration from configuration.yml")
@@ -50,7 +56,14 @@ module OpenProject
register "openproject-auth_saml",
author_url: "https://github.com/finnlabs/openproject-auth_saml",
bundled: true,
- settings: { default: { "providers" => nil } }
+ settings: { default: { "providers" => nil } } do
+ menu :admin_menu,
+ :plugin_saml,
+ :saml_providers_path,
+ parent: :authentication,
+ caption: ->(*) { I18n.t('saml.menu_title') },
+ enterprise_feature: 'openid_providers'
+ end
assets %w(
auth_saml/**