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

Mapping form

Oliver Güntherd2700a44b4d4
diff --git a/modules/auth_saml/app/components/saml/providers/sections/mapping_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/mapping_component.html.erb
new file mode 100644
index 00000000000..11c93ab2f2f
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/mapping_component.html.erb
@@ -0,0 +1,31 @@
+<%=
+ grid_layout('op-saml-view-row', tag: :div, align_items: :center) do |grid|
+ grid.with_area(:title, mr: 3) do
+ concat render(Primer::Beta::Text.new(font_weight: :bold)) { t("saml.providers.label_mapping") }
+ end
+
+ grid.with_area(:description) do
+ render(Primer::Beta::Text.new(tag: :p, font_size: :small, color: :subtle)) do
+ t("saml.providers.section_texts.mapping")
+ end
+ end
+
+ if provider.persisted?
+ grid.with_area(:action) do
+ flex_layout(justify_content: :flex_end) do |icons_container|
+ icons_container.with_column do
+ render(
+ Primer::Beta::IconButton.new(
+ icon: :pencil,
+ tag: :a,
+ scheme: :invisible,
+ href: edit_saml_provider_path(provider, edit_state: :mapping),
+ aria: { label: I18n.t(:label_edit) }
+ )
+ )
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/auth_saml/app/components/saml/providers/sections/mapping_component.rb b/modules/auth_saml/app/components/saml/providers/sections/mapping_component.rb
new file mode 100644
index 00000000000..ceaeb06c8d8
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/mapping_component.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+#
+module Saml::Providers::Sections
+ class MappingComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :provider
+
+ def initialize(provider)
+ @provider = provider
+ end
+ end
+end
diff --git a/modules/auth_saml/app/components/saml/providers/sections/mapping_form_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/mapping_form_component.html.erb
new file mode 100644
index 00000000000..b2a6258a191
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/mapping_form_component.html.erb
@@ -0,0 +1,24 @@
+<%=
+ primer_form_with(
+ model: provider,
+ url: saml_provider_path(provider, state: :configuration),
+ method: :put
+ ) do |form|
+ flex_layout do |flex|
+ flex.with_row do
+ render(Primer::Beta::Text.new(tag: :p, mb: 4, font_size: :small)) do
+ t("saml.instructions.mapping")
+ end
+ end
+
+ flex.with_row do
+ render(Saml::Providers::MappingForm.new(form, provider:))
+ end
+
+ flex.with_row(mt: 4) do
+ render(Saml::Providers::SubmitOrCancelForm.new(form,
+ provider:))
+ end
+ end
+ end
+%>
diff --git a/modules/auth_saml/app/components/saml/providers/sections/mapping_form_component.rb b/modules/auth_saml/app/components/saml/providers/sections/mapping_form_component.rb
new file mode 100644
index 00000000000..bb6ebe1d1e6
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/mapping_form_component.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+#
+module Saml::Providers::Sections
+ class MappingFormComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :provider
+
+ def initialize(provider)
+ @provider = provider
+ end
+ end
+end
diff --git a/modules/auth_saml/app/components/saml/providers/view_component.html.erb b/modules/auth_saml/app/components/saml/providers/view_component.html.erb
index ac1ee941d60..51252bd0b95 100644
--- a/modules/auth_saml/app/components/saml/providers/view_component.html.erb
+++ b/modules/auth_saml/app/components/saml/providers/view_component.html.erb
@@ -35,5 +35,17 @@
render(Saml::Providers::Sections::ConfigurationComponent.new(provider))
end
end
+
+ component.with_row(scheme: :neutral, color: :muted) do
+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.attributes') }
+ end
+
+ component.with_row(scheme: :default) do
+ if edit_state == :mapping
+ render(Saml::Providers::Sections::MappingFormComponent.new(provider))
+ else
+ render(Saml::Providers::Sections::MappingComponent.new(provider))
+ end
+ end
end
%>
diff --git a/modules/auth_saml/app/constants/saml/defaults.rb b/modules/auth_saml/app/constants/saml/defaults.rb
index b6bd3eb35ff..58c76e1c9d4 100644
--- a/modules/auth_saml/app/constants/saml/defaults.rb
+++ b/modules/auth_saml/app/constants/saml/defaults.rb
@@ -39,14 +39,33 @@ module Saml
"urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
]
- MAIL_MAPPING = %w[mail email Email emailAddress emailaddress
- urn:oid:0.9.2342.19200300.100.1.3 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress].freeze
+ MAIL_MAPPING = <<~STR
+ mail
+ email
+ Email
+ emailAddress
+ emailaddress
+ urn:oid:0.9.2342.19200300.100.1.3
+ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
+ STR
- FIRSTNAME_MAPPING = %w[givenName givenname given_name given_name
- urn:oid:2.5.4.42 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname].freeze
+ FIRSTNAME_MAPPING = <<~STR
+ givenName
+ givenname
+ given_name
+ given_name
+ urn:oid:2.5.4.42
+ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname
+ STR
- LASTNAME_MAPPING = %w[surname sur_name sn
- urn:oid:2.5.4.4 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname].freeze
+ LASTNAME_MAPPING = <<~STR
+ surname
+ sur_name
+ sn
+ given_name
+ urn:oid:2.5.4.4
+ http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname
+ STR
REQUESTED_ATTRIBUTES = [
{
diff --git a/modules/auth_saml/app/forms/saml/providers/mapping_form.rb b/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
new file mode 100644
index 00000000000..5a0202a4f21
--- /dev/null
+++ b/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
@@ -0,0 +1,81 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module Saml
+ module Providers
+ class MappingForm < ApplicationForm
+ form do |f|
+ f.text_area(
+ name: :mapping_login,
+ label: I18n.t("activemodel.attributes.saml/provider.mapping_login"),
+ caption: I18n.t("saml.instructions.mapping_login"),
+ required: true,
+ rows: 8,
+ input_width: :large
+ )
+ f.text_area(
+ name: :mapping_mail,
+ label: I18n.t("activemodel.attributes.saml/provider.mapping_mail"),
+ caption: I18n.t("saml.instructions.mapping_mail"),
+ required: true,
+ rows: 8,
+ input_width: :large
+ )
+ f.text_area(
+ name: :mapping_firstname,
+ label: I18n.t("activemodel.attributes.saml/provider.mapping_firstname"),
+ caption: I18n.t("saml.instructions.mapping_firstname"),
+ required: true,
+ rows: 8,
+ input_width: :large
+ )
+ f.text_area(
+ name: :mapping_lastname,
+ label: I18n.t("activemodel.attributes.saml/provider.mapping_lastname"),
+ caption: I18n.t("saml.instructions.mapping_lastname"),
+ required: true,
+ rows: 8,
+ input_width: :large
+ )
+ f.text_field(
+ name: :mapping_uid,
+ label: I18n.t("activemodel.attributes.saml/provider.mapping_uid"),
+ caption: I18n.t("saml.instructions.mapping_uid"),
+ rows: 8,
+ required: true,
+ input_width: :large
+ )
+ end
+
+ def initialize(provider:)
+ super()
+ @provider = provider
+ end
+ end
+ end
+end
diff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rb
index 82c629915f3..2f67640ad8e 100644
--- a/modules/auth_saml/app/models/saml/provider.rb
+++ b/modules/auth_saml/app/models/saml/provider.rb
@@ -15,11 +15,11 @@ module Saml
store_attribute :options, :idp_cert, :string
store_attribute :options, :idp_cert_fingerprint, :string
- store_attribute :options, :mapping_login, :json
- store_attribute :options, :mapping_mail, :json
- store_attribute :options, :mapping_firstname, :json
- store_attribute :options, :mapping_lastname, :json
- store_attribute :options, :mapping_uid, :json
+ store_attribute :options, :mapping_login, :string
+ store_attribute :options, :mapping_mail, :string
+ store_attribute :options, :mapping_firstname, :string
+ store_attribute :options, :mapping_lastname, :string
+ store_attribute :options, :mapping_uid, :string
store_attribute :options, :request_attributes, :json
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index d58290f4f18..3616686a665 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -13,6 +13,11 @@ en:
idp_sso_service_url: Identity provider login endpoint
idp_slo_service_url: Identity provider logout endpoint
idp_cert: Public certificate of identity provider
+ mapping_login: "Login mapping"
+ mapping_mail: "Email mapping"
+ mapping_firstname: "First name mapping"
+ mapping_lastname: "Last name mapping"
+ mapping_uid: "Mapping for internal user ID"
saml:
menu_title: SAML providers
info:
@@ -32,6 +37,7 @@ en:
label_configuration_details: "Identity provider endpoints and certificates"
label_add_new: New SAML identity provider
label_edit: Edit SAML identity provider %{name}
+ label_mapping: Mapping
no_results_table: No SAML identity providers have been defined yet.
plural: SAML identity providers
singular: SAML identity provider
@@ -48,11 +54,13 @@ en:
format: 'Attribute format'
section_headers:
configuration: "Primary configuration"
+ attributes: "Attributes"
section_texts:
display_name: "Configure the display name of the SAML provider."
metadata: "Pre-fill configuration using a metadata URL or by pasting metadata XML"
metadata_form: "If your identity provider has a metadata endpoint or XML download, add it below to pre-fill configuration."
configuration: "Configure the endpoint URLs for the identity provider, certificates, and further SAML options."
+ mapping: "Manually adjust the mapping between the SAML response and user attributes in OpenProject."
settings:
metadata_checkbox: "I have metadata (optional)"
metadata_url: "Metadata URL"
@@ -82,3 +90,17 @@ en:
sp_metadata_endpoint: >
This is the URL where the OpenProject SAML metadata is available.
Optionally use it to configure your identity provider.
+ mapping: >
+ Configure the mapping between the SAML response and user attributes in OpenProject.
+ You can configure multiple attribute names to look for. OpenProject will choose the first available attribute
+ from the SAML response.
+ mapping_login: >
+ SAML attributes from the response used for the login.
+ mapping_mail: >
+ SAML attributes from the response used for the email of the user.
+ mapping_firstname: >
+ SAML attributes from the response used for the given name.
+ mapping_lastname: >
+ SAML attributes from the response used for the last name.
+ mapping_uid: >
+ SAML attribute to use for the internal user ID. Leave empty to use the name_id attribute instead