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

RequestAttributes form

Oliver Günther300ec603383e
diff --git a/modules/auth_saml/app/components/saml/providers/sections/request_attributes_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_component.html.erb
new file mode 100644
index 00000000000..8cf99919e83
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_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.requested_attributes") }
+ end
+
+ grid.with_area(:description) do
+ render(Primer::Beta::Text.new(tag: :p, font_size: :small, color: :subtle)) do
+ t("saml.providers.section_texts.requested_attributes")
+ 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: :requested_attributes),
+ aria: { label: I18n.t(:label_edit) }
+ )
+ )
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/auth_saml/app/components/saml/providers/sections/request_attributes_component.rb b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_component.rb
new file mode 100644
index 00000000000..69548e99d33
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_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 RequestAttributesComponent < 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/request_attributes_form_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_form_component.html.erb
new file mode 100644
index 00000000000..1149272abb5
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_form_component.html.erb
@@ -0,0 +1,24 @@
+<%=
+ primer_form_with(
+ model: provider,
+ url: saml_provider_path(provider, state: :mapping),
+ 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.requested_attributes")
+ end
+ end
+
+ flex.with_row do
+ render(Saml::Providers::RequestAttributesForm.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/request_attributes_form_component.rb b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_form_component.rb
new file mode 100644
index 00000000000..52e02e7b28c
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/sections/request_attributes_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 RequestAttributesFormComponent < 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 51252bd0b95..ae7efeec42c 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
@@ -47,5 +47,12 @@
render(Saml::Providers::Sections::MappingComponent.new(provider))
end
end
+ component.with_row(scheme: :default) do
+ if edit_state == :requested_attributes
+ render(Saml::Providers::Sections::RequestAttributesFormComponent.new(provider))
+ else
+ render(Saml::Providers::Sections::RequestAttributesComponent.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 58c76e1c9d4..f66dcadc793 100644
--- a/modules/auth_saml/app/constants/saml/defaults.rb
+++ b/modules/auth_saml/app/constants/saml/defaults.rb
@@ -32,12 +32,18 @@ module Saml
module Defaults
NAME_IDENTIFIER_FORMAT = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
- NAME_IDENTIFIER_FORMATS = [
- "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
- "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
- "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
- "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"
- ]
+ NAME_IDENTIFIER_FORMATS = %w[
+ urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
+ urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
+ urn:oasis:names:tc:SAML:2.0:nameid-format:persistent
+ urn:oasis:names:tc:SAML:2.0:nameid-format:transient
+ ].freeze
+
+ ATTRIBUTE_FORMATS = %w[
+ urn:oasis:names:tc:SAML:2.0:attrname-format:basic
+ urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified
+ urn:oasis:names:tc:SAML:2.0:attrname-format:uri
+ ].freeze
MAIL_MAPPING = <<~STR
mail
@@ -59,33 +65,12 @@ module Saml
STR
LASTNAME_MAPPING = <<~STR
+ sn
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 = [
- {
- "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
- }
- ].freeze
end
end
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rb
index 575cec37668..5041fc0c871 100644
--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -156,7 +156,11 @@ module Saml
.require(:saml_provider)
.permit(:display_name, :sp_entity_id, :idp_sso_service_url, :idp_slo_service_url, :idp_cert,
:name_identifier_format, :limit_self_registration,
- :mapping_login, :mapping_mail, :mapping_firstname, :mapping_lastname, :mapping_uid)
+ :mapping_login, :mapping_mail, :mapping_firstname, :mapping_lastname, :mapping_uid,
+ :requested_login_attribute, :requested_mail_attribute, :requested_firstname_attribute,
+ :requested_lastname_attribute, :requested_uid_attribute,
+ :requested_login_format, :requested_mail_format, :requested_firstname_format,
+ :requested_lastname_format, :requested_uid_format)
end
def find_provider
diff --git a/modules/auth_saml/app/forms/saml/providers/mapping_form.rb b/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
index 7f449a6c10f..833db7a51ed 100644
--- a/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
+++ b/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
@@ -32,7 +32,7 @@ module Saml
form do |f|
f.text_area(
name: :mapping_login,
- label: I18n.t("activemodel.attributes.saml/provider.mapping_login"),
+ label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:login)),
caption: I18n.t("saml.instructions.mapping_login"),
required: true,
rows: 8,
@@ -40,7 +40,7 @@ module Saml
)
f.text_area(
name: :mapping_mail,
- label: I18n.t("activemodel.attributes.saml/provider.mapping_mail"),
+ label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:mail)),
caption: I18n.t("saml.instructions.mapping_mail"),
required: true,
rows: 8,
@@ -48,7 +48,7 @@ module Saml
)
f.text_area(
name: :mapping_firstname,
- label: I18n.t("activemodel.attributes.saml/provider.mapping_firstname"),
+ label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:first_name)),
caption: I18n.t("saml.instructions.mapping_firstname"),
required: true,
rows: 8,
@@ -56,7 +56,7 @@ module Saml
)
f.text_area(
name: :mapping_lastname,
- label: I18n.t("activemodel.attributes.saml/provider.mapping_lastname"),
+ label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:last_name)),
caption: I18n.t("saml.instructions.mapping_lastname"),
required: true,
rows: 8,
@@ -64,7 +64,7 @@ module Saml
)
f.text_field(
name: :mapping_uid,
- label: I18n.t("activemodel.attributes.saml/provider.mapping_uid"),
+ label: I18n.t("saml.providers.label_mapping_for", attribute: I18n.t("saml.providers.label_uid")),
caption: I18n.t("saml.instructions.mapping_uid"),
rows: 8,
required: false,
diff --git a/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb b/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb
new file mode 100644
index 00000000000..b5c9b97f445
--- /dev/null
+++ b/modules/auth_saml/app/forms/saml/providers/request_attributes_form.rb
@@ -0,0 +1,75 @@
+#-- 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 RequestAttributesForm < ApplicationForm
+ include Redmine::I18n
+
+ form do |f|
+ %i[login mail firstname lastname uid].each do |attribute|
+ f.group do |form_group|
+ uid = attribute == :uid
+ label = uid ? I18n.t("saml.providers.label_uid") : User.human_attribute_name(attribute)
+ form_group.text_field(
+ name: :"requested_#{attribute}_attribute",
+ label: I18n.t("saml.providers.label_requested_attribute_for", attribute: label),
+ required: !uid,
+ caption: uid ? I18n.t("saml.instructions.request_uid") : nil,
+ input_width: :large
+ )
+
+ form_group.select_list(
+ name: :"requested_#{attribute}_format",
+ label: I18n.t("activemodel.attributes.saml/provider.format"),
+ input_width: :large,
+ caption: link_translate(
+ "saml.instructions.documentation_link",
+ links: {
+ docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:saml][:href]
+ },
+ target: "_blank"
+ )
+ ) do |list|
+ Saml::Defaults::ATTRIBUTE_FORMATS.each do |format|
+ list.option(label: format, value: format)
+ end
+ end
+ end
+
+ f.separator unless attribute == :uid
+ end
+ 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 2f67640ad8e..c56b90f6db7 100644
--- a/modules/auth_saml/app/models/saml/provider.rb
+++ b/modules/auth_saml/app/models/saml/provider.rb
@@ -21,7 +21,17 @@ module Saml
store_attribute :options, :mapping_lastname, :string
store_attribute :options, :mapping_uid, :string
- store_attribute :options, :request_attributes, :json
+ store_attribute :options, :requested_login_attribute, :string
+ store_attribute :options, :requested_mail_attribute, :string
+ store_attribute :options, :requested_firstname_attribute, :string
+ store_attribute :options, :requested_lastname_attribute, :string
+ store_attribute :options, :requested_uid_attribute, :string
+
+ store_attribute :options, :requested_login_format, :string
+ store_attribute :options, :requested_mail_format, :string
+ store_attribute :options, :requested_firstname_format, :string
+ store_attribute :options, :requested_lastname_format, :string
+ store_attribute :options, :requested_uid_format, :string
attr_accessor :readonly
diff --git a/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
index fbd7b418714..9e08db9f2b8 100644
--- a/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
+++ b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
@@ -41,6 +41,7 @@ module Saml
model.change_by_system do
set_default_creator
set_default_mapping
+ set_default_requested_attributes
set_issuer
set_name_identifier_format
end
@@ -73,7 +74,18 @@ module Saml
model.mapping_mail ||= Saml::Defaults::MAIL_MAPPING
model.mapping_firstname ||= Saml::Defaults::FIRSTNAME_MAPPING
model.mapping_lastname ||= Saml::Defaults::LASTNAME_MAPPING
- model.request_attributes ||= Saml::Defaults::REQUESTED_ATTRIBUTES
+ end
+
+ def set_default_requested_attributes
+ model.requested_login_attribute ||= Saml::Defaults::MAIL_MAPPING.split("\n").first
+ model.requested_mail_attribute ||= Saml::Defaults::MAIL_MAPPING.split("\n").first
+ model.requested_firstname_attribute ||= Saml::Defaults::FIRSTNAME_MAPPING.split("\n").first
+ model.requested_lastname_attribute ||= Saml::Defaults::LASTNAME_MAPPING.split("\n").first
+
+ model.requested_login_format ||= Saml::Defaults::ATTRIBUTE_FORMATS.first
+ model.requested_mail_format ||= Saml::Defaults::ATTRIBUTE_FORMATS.first
+ model.requested_firstname_format ||= Saml::Defaults::ATTRIBUTE_FORMATS.first
+ model.requested_lastname_format ||= Saml::Defaults::ATTRIBUTE_FORMATS.first
end
def set_issuer
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index 3616686a665..4043a5398bb 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -13,11 +13,7 @@ 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"
+ format: "Format"
saml:
menu_title: SAML providers
info:
@@ -37,10 +33,14 @@ en:
label_configuration_details: "Identity provider endpoints and certificates"
label_add_new: New SAML identity provider
label_edit: Edit SAML identity provider %{name}
+ label_uid: Internal user id
label_mapping: Mapping
+ label_mapping_for: "Mapping for: %{attribute}"
+ label_requested_attribute_for: "Requested attribute for: %{attribute}"
no_results_table: No SAML identity providers have been defined yet.
plural: SAML identity providers
singular: SAML identity provider
+ requested_attributes: Requested attributes
attribute_mapping: Attribute mapping
attribute_mapping_text: >
The following fields control which attributes provided by the SAML identity provider
@@ -61,6 +61,7 @@ en:
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."
+ requested_attributes: "Define the set of attributes to be requested in the SAML request sent to your identity provider."
settings:
metadata_checkbox: "I have metadata (optional)"
metadata_url: "Metadata URL"
@@ -104,3 +105,10 @@ en:
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
+ request_uid: >
+ SAML attribute to request for the internal user ID. By default, the name_id will be used for this field.
+ requested_attributes: >
+ These attributes are added to the SAML request XML to communicate to the identity provider which attributes OpenProject requires.
+ requested_format: >
+ The format of the requested attribute. This is used to specify the format of the attribute in the SAML request.
+ Please see [documentation on configuring requested attributes](docs_url) for more information.