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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
metadata
Oliver Güntherc5753084cb09
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rbindex 9dd7ed85118..54d6a1521fe 100644--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb@@ -1,6 +1,6 @@module Samlclass ProvidersController < ::ApplicationController- layout 'admin'+ layout "admin"menu_item :plugin_samlbefore_action :require_admin@@ -10,11 +10,21 @@ module Samldef index; enddef new- @provider = ::Saml::Provider.new(defaults)+ @provider = ::Saml::Provider.new(name: "saml")+ end++ def import+ @provider = ::Saml::Provider.new(name: import_params[:name])++ if import_params[:metadata_url].present?+ import_metadata+ end++ render action: :editenddef create- @provider = ::Saml::Provider.new(create_params)+ @provider = ::Saml::Provider.new(**create_params)if @provider.saveflash[:notice] = I18n.t(:notice_successful_create)@@ -51,23 +61,39 @@ module Samlprivatedef defaults- {- }+ {}enddef check_eeunless EnterpriseToken.allows_to?(:openid_providers)- render template: '/saml/providers/upsale'+ render template: "/saml/providers/upsale"falseendend+ def import_params+ params.require(:saml_provider).permit(:name, :metadata_url)+ end++ def import_metadata+ call = Saml::MetadataParserService+ .new(user: User.current)+ .parse_url(import_params[:metadata_url])++ if call.success?+ flash[:notice] = I18n.t("saml.metadata_parser.success")+ @provider = ::Saml::Provider.new(**call.result.merge(name: import_params[:name]))+ else+ flash[:error] = call.message+ end+ end+def create_params- params.require(:openid_connect_provider).permit(:name, :display_name, :identifier, :secret, :limit_self_registration)+ params.require(:saml_provider).permit(:name, :display_name, :identifier, :secret, :limit_self_registration)enddef update_params- params.require(:openid_connect_provider).permit(:display_name, :identifier, :secret, :limit_self_registration)+ params.require(:saml_provider).permit(:display_name, :identifier, :secret, :limit_self_registration)enddef find_providerdiff --git a/modules/auth_saml/app/forms/saml/providers/metadata_url_form.rb b/modules/auth_saml/app/forms/saml/providers/metadata_url_form.rbnew file mode 100644index 00000000000..ad700d621ef--- /dev/null+++ b/modules/auth_saml/app/forms/saml/providers/metadata_url_form.rb@@ -0,0 +1,43 @@+#-- 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 MetadataUrlForm < ApplicationForm+ form do |f|+ f.text_field(+ name: :metadata_url,+ label: I18n.t("saml.settings.metadata_url"),+ required: false,+ caption: I18n.t("saml.setting_instructions.metadata_url"),+ input_width: :medium+ )+ end+ end+ end+enddiff --git a/modules/auth_saml/app/forms/saml/providers/provider_name_input_form.rb b/modules/auth_saml/app/forms/saml/providers/name_input_form.rbsimilarity index 79%rename from modules/auth_saml/app/forms/saml/providers/provider_name_input_form.rbrename to modules/auth_saml/app/forms/saml/providers/name_input_form.rbindex e8ed28a62d1..0782f1c53da 100644--- a/modules/auth_saml/app/forms/saml/providers/provider_name_input_form.rb+++ b/modules/auth_saml/app/forms/saml/providers/name_input_form.rb@@ -28,15 +28,14 @@module Samlmodule Providers- class ProviderNameInputForm < ApplicationForm- form do |storage_form|- storage_form.text_field(+ class NameInputForm < ApplicationForm+ form do |f|+ f.text_field(name: :name,- label: I18n.t("activerecord.attributes.storages/storage.name"),+ label: I18n.t("activemodel.attributes.saml/provider.name"),required: true,- caption: I18n.t("storages.instructions.name"),- placeholder: I18n.t("storages.label_file_storage"),- input_width: :large+ caption: I18n.t("saml.setting_instructions.name"),+ input_width: :medium)endenddiff --git a/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rb b/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rbnew file mode 100644index 00000000000..ad53b6c74bd--- /dev/null+++ b/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rb@@ -0,0 +1,67 @@+#-- 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 SubmitOrCancelForm < ApplicationForm+ form do |buttons|+ buttons.group(layout: :horizontal) do |button_group|+ button_group.submit(**@submit_button_options)+ button_group.button(**@cancel_button_options)+ end+ end++ def initialize(submit_button_options: {}, cancel_button_options: {})+ super()+ @submit_button_options = default_submit_button_options.merge(submit_button_options)+ @cancel_button_options = default_cancel_button_options.merge(cancel_button_options)+ end++ private++ def default_submit_button_options+ {+ name: :submit,+ scheme: :primary,+ label: I18n.t(:button_continue),+ disabled: false+ }+ end++ def default_cancel_button_options+ {+ name: :cancel,+ scheme: :default,+ tag: :a,+ href: OpenProject::StaticRouting::StaticRouter.new.url_helpers.saml_providers_path,+ label: I18n.t("button_cancel")+ }+ end+ end+ end+enddiff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rbindex e7e75bf7f7d..9a7592247e9 100644--- a/modules/auth_saml/app/models/saml/provider.rb+++ b/modules/auth_saml/app/models/saml/provider.rb@@ -5,11 +5,10 @@ module Samlinclude ActiveModel::Validationsinclude ActiveModel::Conversion- attr_accessor :name, :readonly+ attr_accessor :readonlyvalidates_presence_of :name, :display_name- def initialize(name, attributes = {}, readonly: false)- self.name = name+ def initialize(readonly: false, **attributes)self.readonly = readonlysuper(attributes)diff --git a/modules/auth_saml/app/services/saml/metadata_parser_service.rb b/modules/auth_saml/app/services/saml/metadata_parser_service.rbnew file mode 100644index 00000000000..1186204679a--- /dev/null+++ b/modules/auth_saml/app/services/saml/metadata_parser_service.rb@@ -0,0 +1,61 @@+#-- 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+ class MetadataParserService+ attr_reader :user++ def initialize(user:)+ @user = user+ end++ def parse_url(url)+ validate_url!(url)+ parse_remote_metadata(url)+ rescue URI::InvalidURIError+ ServiceResult.failure(message: I18n.t('saml.metadata_parser.invalid_url'))+ rescue OneLogin::RubySaml::HttpError => e+ ServiceResult.failure(message: I18n.t('saml.metadata_parser.error', error: e.message))+ rescue StandardError => e+ OpenProject.logger.error(e)+ ServiceResult.failure(message: I18n.t('saml.metadata_parser.error', error: e.class.name))+ end++ def parse_remote_metadata(metadata_url)+ idp_metadata_parser = OneLogin::RubySaml::IdpMetadataParser.new+ result = idp_metadata_parser.parse_remote_to_hash(metadata_url)++ ServiceResult.success(result:)+ end++ def validate_url!(url)+ uri = URI.parse(url)+ raise URI::InvalidURIError unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)+ end+ end+enddiff --git a/modules/auth_saml/app/views/saml/providers/_form.html.erb b/modules/auth_saml/app/views/saml/providers/_form.html.erbindex 296d0d79bb2..2573404127b 100644--- a/modules/auth_saml/app/views/saml/providers/_form.html.erb+++ b/modules/auth_saml/app/views/saml/providers/_form.html.erb@@ -12,11 +12,11 @@</div><div class="form--field -required">- <%= f.text_field :idp_sso_target_url, required: true, container_class: '-xwide' %>+ <%= f.text_field :idp_sso_service_url, required: true, container_class: '-xwide' %></div><div class="form--field">- <%= f.text_field :idp_slo_target_url, required: false, container_class: '-xwide' %>+ <%= f.text_field :idp_slo_service_url, required: false, container_class: '-xwide' %></div><div class="form--field">diff --git a/modules/auth_saml/app/views/saml/providers/index.html.erb b/modules/auth_saml/app/views/saml/providers/index.html.erbindex c25b47bf504..79ec7749387 100644--- a/modules/auth_saml/app/views/saml/providers/index.html.erb+++ b/modules/auth_saml/app/views/saml/providers/index.html.erb@@ -1,18 +1,24 @@<% 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')+<%=+ content_for :content_header do+ 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+ endend-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.erbindex 50ae9f727d3..2a7e3bcf7b6 100644--- a/modules/auth_saml/app/views/saml/providers/new.html.erb+++ b/modules/auth_saml/app/views/saml/providers/new.html.erb@@ -5,11 +5,29 @@<%= 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>++<%=+ primer_form_with(+ model: @provider,+ url: { action: :import },+ method: :post+ ) do |form| %>++ <%=+ render(Primer::OpenProject::FlexLayout.new) do |flex|+ flex.with_row(mb: 3) do+ render(Saml::Providers::NameInputForm.new(form))+ end++ flex.with_row(mb: 3) do+ render(Saml::Providers::MetadataUrlForm.new(form))+ end++ flex.with_row do+ render(+ Saml::Providers::SubmitOrCancelForm.new(form)+ )+ end+ end+ %><% end %>diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.ymlindex 886292f0a10..78112af520d 100644--- a/modules/auth_saml/config/locales/en.yml+++ b/modules/auth_saml/config/locales/en.yml@@ -2,25 +2,30 @@ en:activemodel:attributes:saml/provider:- name: Name+ name: Identifierdisplay_name: Display nameidentifier: Identifiersecret: Secretscope: Scopelimit_self_registration: Limit self registrationsp_entity_id: Service entity ID+ metadata_url: Identity provider metadata URLsaml:menu_title: SAML providersinfo:title: "SAML Protocol Configuration Parameters"description: >Use these parameters to configure your identity provider connection to OpenProject.+ metadata_parser:+ success: "Successfully retrieved the identity provider metadata. Please review and save the configuration."+ invalid_url: "Provided metadata URL is invalid. Provide a HTTP(s) URL."+ error: "Failed to retrieve the identity provider metadata: %{error}"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+ label_add_new: New SAML identity provider+ label_edit: Edit SAML identity provider %{name}+ no_results_table: No SAML identity providers have been defined yet.+ plural: SAML identity providers+ singular: SAML identity providerattribute_mapping: Attribute mappingattribute_mapping_text: >The following fields control which attributes provided by the SAML identity provider@@ -32,6 +37,13 @@ en: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'+ settings:+ metadata_url: Identity provider metadata URL (Optional)setting_instructions:+ name: >+ The identifier of the SAML provider. This needs to be alphanumeric, unique, and is used in the URL fragment to identify the provider.+ metadata_url: >+ Enter the URL of the identity provider XML metadata endpoint.+ If provided, OpenProject will try to prefill all available configuration options from your identity provider.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.rbindex 5e26b8ceaee..cf0ddb5cf77 100644--- a/modules/auth_saml/config/routes.rb+++ b/modules/auth_saml/config/routes.rb@@ -1,7 +1,11 @@Rails.application.routes.draw doscope :admin donamespace :saml do- resources :providers, only: %i[index new create edit update destroy]+ resources :providers, only: %i[index new create edit update destroy] do+ collection do+ post :import+ end+ endendendenddiff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rbindex 202b64e4887..34242d2b032 100644--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb@@ -26,8 +26,9 @@ module OpenProjectdef self.providersconfiguration.map do |name, config|+ config['name'] = namereadonly = global_configuration.keys.include?(name)- ::Saml::Provider.new(name, config, readonly:)+ ::Saml::Provider.new(readonly:, **config)endend