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

Require authentication for SCIM requests

Jan Sandbrink99ad5d99e9d7
diff --git a/app/controllers/scim_v2/scim_controller_mixins.rb b/app/controllers/scim_v2/scim_controller_mixins.rb
new file mode 100644
index 00000000000..5e5f88468a2
--- /dev/null
+++ b/app/controllers/scim_v2/scim_controller_mixins.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 ScimV2
+ module ScimControllerMixins
+ def self.included(base)
+ base.prepend(Overwrites)
+ end
+
+ module Overwrites
+ # Completely overwriting authenticate method of Scimitar
+ def authenticate
+ return handle_scim_error(Scimitar::AuthenticationError.new) unless OpenProject::FeatureDecisions.scim_api_active?
+
+ warden = request.env["warden"]
+ User.current = warden.authenticate! scope: :scim_v2
+
+ # Only admins are able to manage users, so that's the only permission we can check for it
+ handle_scim_error(Scimitar::AuthenticationError.new) unless User.current.admin?
+ end
+ end
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index 0d4eb649c83..d7cec2fa289 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -771,3 +771,7 @@ class User < Principal
!User.active.find_by_login("admin").try(:current_password).try(:matches_plaintext?, "admin")
end
end
+
+# Fix for development (and non eagerloaded environments), where User.find(...) would not return service accounts before
+# they've been autoloaded.
+require "service_account"
diff --git a/config/initializers/scimitar.rb b/config/initializers/scimitar.rb
index 6069bb87a87..cf6bfd5713f 100644
--- a/config/initializers/scimitar.rb
+++ b/config/initializers/scimitar.rb
@@ -33,9 +33,7 @@ Rails.application.config.to_prepare do
patch: Scimitar::Supportable.supported
)
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new(
- token_authenticator: Proc.new do |_token, _options|
- OpenProject::FeatureDecisions.scim_api_active?
- end
+ application_controller_mixin: ScimV2::ScimControllerMixins
)
module ScimitarSchemaExtension
diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb
index 49215af78e2..96da619d4c5 100644
--- a/config/initializers/warden.rb
+++ b/config/initializers/warden.rb
@@ -26,6 +26,10 @@ OpenProject::Authentication.update_strategies(OpenProject::Authentication::Scope
anonymous_fallback]
end
+OpenProject::Authentication.update_strategies(OpenProject::Authentication::Scope::SCIM_V2, { store: false }) do |_|
+ %i[oauth jwt_oidc session]
+end
+
Rails.application.configure do |app|
app.config.middleware.use OpenProject::Authentication::Manager, intercept_401: false # rubocop:disable Naming/VariableNumber
end