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

Services + Contracts

Oliver Günther69946a637c73
diff --git a/modules/auth_saml/app/constants/saml/defaults.rb b/modules/auth_saml/app/constants/saml/defaults.rb
new file mode 100644
index 00000000000..c6e930816af
--- /dev/null
+++ b/modules/auth_saml/app/constants/saml/defaults.rb
@@ -0,0 +1,64 @@
+# 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
+ module Defaults
+ NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'.freeze
+ 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
+
+ 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
+
+ LASTNAME_MAPPING = %w[surname sur_name sn
+ urn:oid:2.5.4.4 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname].freeze
+
+ 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/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
new file mode 100644
index 00000000000..63a5c164f0b
--- /dev/null
+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb
@@ -0,0 +1,40 @@
+#-- 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 BaseContract < ModelContract
+ include RequiresAdminGuard
+
+ def self.model
+ Saml::Provider
+ end
+
+ attribute :display_name
+ end
+ end
+end
diff --git a/modules/auth_saml/app/contracts/saml/providers/create_contract.rb b/modules/auth_saml/app/contracts/saml/providers/create_contract.rb
new file mode 100644
index 00000000000..555aeac3604
--- /dev/null
+++ b/modules/auth_saml/app/contracts/saml/providers/create_contract.rb
@@ -0,0 +1,33 @@
+#-- 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 CreateContract < BaseContract
+ end
+ end
+end
diff --git a/modules/auth_saml/app/contracts/saml/providers/delete_contract.rb b/modules/auth_saml/app/contracts/saml/providers/delete_contract.rb
new file mode 100644
index 00000000000..aae9539da9f
--- /dev/null
+++ b/modules/auth_saml/app/contracts/saml/providers/delete_contract.rb
@@ -0,0 +1,35 @@
+#-- 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 DeleteContract < ::DeleteContract
+ delete_permission :admin
+ end
+ end
+end
diff --git a/modules/auth_saml/app/contracts/saml/providers/update_contract.rb b/modules/auth_saml/app/contracts/saml/providers/update_contract.rb
new file mode 100644
index 00000000000..90e4bf6fd0f
--- /dev/null
+++ b/modules/auth_saml/app/contracts/saml/providers/update_contract.rb
@@ -0,0 +1,34 @@
+#-- 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 UpdateContract < News::BaseContract
+ 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
index 2e9e42b006d..5a1086bd237 100644
--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -29,12 +29,15 @@ module Saml
end
def create
- @provider = ::Saml::Provider.new(**create_params)
+ call = ::Saml::Providers::CreateService
+ .new(user: User.current)
+ .call(**create_params)
- if @provider.save
+ if call.success?
flash[:notice] = I18n.t(:notice_successful_create)
- redirect_to saml_provider_path(@provider)
+ redirect_to saml_provider_path(call.result)
else
+ @provider = call.result
render action: :new
end
end
@@ -52,7 +55,10 @@ module Saml
end
def destroy
- if @provider.destroy
+ call = ::Saml::Providers::DeleteService
+ .new(model: @provider, user: User.current)
+
+ if call.success?
flash[:notice] = I18n.t(:notice_successful_delete)
else
flash[:error] = I18n.t(:error_failed_to_delete_entry)
@@ -100,7 +106,7 @@ module Saml
end
def create_params
- params.require(:saml_provider).permit(:name, :display_name, :identifier, :secret, :limit_self_registration)
+ params.require(:saml_provider).permit(:display_name)
end
def update_params
@@ -108,15 +114,9 @@ module Saml
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
+ @provider = Saml::Provider.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ render_404
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
index b4166f4b6bf..abc2e786405 100644
--- a/modules/auth_saml/app/models/saml/provider.rb
+++ b/modules/auth_saml/app/models/saml/provider.rb
@@ -2,49 +2,20 @@ module Saml
class Provider < ApplicationRecord
self.table_name = "saml_providers"
- DEFAULT_NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'.freeze
- DEFAULT_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
+ belongs_to :creator, class_name: "User"
- DEFAULT_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
-
- DEFAULT_LASTNAME_MAPPING = %w[surname sur_name sn
- urn:oid:2.5.4.4 http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname].freeze
-
- DEFAULT_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
-
- store_attribute :options, :sp_entity_id, :string, default: -> { OpenProject::StaticRouting::StaticUrlHelpers.new.root_url }
- store_attribute :options, :name_identifier_format, :string, default: -> { DEFAULT_NAME_IDENTIFIER_FORMAT }
+ store_attribute :options, :sp_entity_id, :string
+ store_attribute :options, :name_identifier_format, :string
store_attribute :options, :metadata_url, :string
store_attribute :options, :metadata_xml, :string
- store_attribute :options, :mapping_login, :json, default: -> { DEFAULT_MAIL_MAPPING }
- store_attribute :options, :mapping_mail, :json, default: -> { DEFAULT_MAIL_MAPPING }
- store_attribute :options, :mapping_firstname, :json, default: -> { DEFAULT_FIRSTNAME_MAPPING }
- store_attribute :options, :mapping_lastname, :json, default: -> { DEFAULT_LASTNAME_MAPPING }
+ 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, :request_attributes, :json, default: -> { DEFAULT_REQUESTED_ATTRIBUTES }
+ store_attribute :options, :request_attributes, :json
attr_accessor :readonly
validates_presence_of :display_name
diff --git a/modules/auth_saml/app/services/saml/providers/create_service.rb b/modules/auth_saml/app/services/saml/providers/create_service.rb
new file mode 100644
index 00000000000..45edbfdcf92
--- /dev/null
+++ b/modules/auth_saml/app/services/saml/providers/create_service.rb
@@ -0,0 +1,34 @@
+#-- 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 CreateService < BaseServices::Create
+ end
+ end
+end
diff --git a/modules/auth_saml/app/services/saml/providers/delete_service.rb b/modules/auth_saml/app/services/saml/providers/delete_service.rb
new file mode 100644
index 00000000000..ea5bae1a445
--- /dev/null
+++ b/modules/auth_saml/app/services/saml/providers/delete_service.rb
@@ -0,0 +1,33 @@
+#-- 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 DeleteService < BaseServices::Delete
+ end
+ end
+end
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
new file mode 100644
index 00000000000..3ecb58d06df
--- /dev/null
+++ b/modules/auth_saml/app/services/saml/providers/set_attributes_service.rb
@@ -0,0 +1,66 @@
+#-- 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 SetAttributesService < BaseServices::SetAttributes
+ include Attachments::SetReplacements
+
+ private
+
+ def set_default_attributes(*)
+ model.change_by_system do
+ set_default_creator
+ set_attribute_mapping
+ set_issuer
+ set_name_identifier_format
+ end
+ end
+
+ def set_name_identifier_format
+ model.name_identifier_format ||= Saml::Defaults::NAME_IDENTIFIER_FORMAT
+ end
+
+ def set_default_creator
+ model.creator = user
+ end
+
+ def set_attribute_mapping
+ model.mapping_login ||= Saml::Defaults::MAIL_MAPPING
+ 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_issuer
+ model.sp_entity_id ||= OpenProject::StaticRouting::StaticUrlHelpers.new.root_url
+ end
+ end
+ end
+end
diff --git a/modules/auth_saml/app/services/saml/providers/update_service.rb b/modules/auth_saml/app/services/saml/providers/update_service.rb
new file mode 100644
index 00000000000..558bd3cb02a
--- /dev/null
+++ b/modules/auth_saml/app/services/saml/providers/update_service.rb
@@ -0,0 +1,34 @@
+#-- 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 UpdateService < BaseServices::Update
+ end
+ end
+end