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

[#62107] Fix SCIM PUT. Disable SCIM PATCH.

Pavel Balashou326b781c0bff
diff --git a/app/controllers/scim_v2/groups_controller.rb b/app/controllers/scim_v2/groups_controller.rb
index 0f88525b368..94dec422b3a 100644
--- a/app/controllers/scim_v2/groups_controller.rb
+++ b/app/controllers/scim_v2/groups_controller.rb
@@ -59,21 +59,7 @@ module ScimV2
group.from_scim!(scim_hash: scim_resource.as_json)
Groups::UpdateService
.new(user: User.system, model: group)
- .call
- .on_failure { |call| raise call.message }
- group.to_scim(location: url_for(action: :show, id: group.id))
- end
- end
- end
-
- def update
- super do |group_id, patch_hash|
- storage_class.transaction do
- group = storage_scope.find(group_id)
- group.from_scim_patch!(patch_hash: patch_hash)
- Groups::UpdateService
- .new(user: User.system, model: group)
- .call
+ .call(user_ids: scim_resource.members.map(&:value))
.on_failure { |call| raise call.message }
group.to_scim(location: url_for(action: :show, id: group.id))
end
diff --git a/app/controllers/scim_v2/users_controller.rb b/app/controllers/scim_v2/users_controller.rb
index fa9103906ab..5d8fad44c89 100644
--- a/app/controllers/scim_v2/users_controller.rb
+++ b/app/controllers/scim_v2/users_controller.rb
@@ -62,20 +62,6 @@ module ScimV2
end
end
- def update
- super do |user_id, patch_hash|
- storage_class.transaction do
- user = storage_scope.find(user_id)
- user.from_scim_patch!(patch_hash: patch_hash)
- Users::UpdateService
- .new(user: User.system, model: user)
- .call
- .on_failure { |call| raise call.message }
- user.to_scim(location: url_for(action: :show, id: user.id))
- end
- end
- end
-
def destroy
super do |user_id|
user = storage_scope.find(user_id)
diff --git a/app/models/group.rb b/app/models/group.rb
index 5be997277bd..dfaa753d9eb 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -88,6 +88,8 @@ class Group < Principal
end
def scim_users_and_groups=(_array)
+ # Nothing is happening here, because users should be added/removed to the group
+ # through Groups::UpdateSerivce. So, it is done on a higher(controller) level.
users
end
@@ -113,7 +115,7 @@ class Group < Principal
when "user"
User.not_builtin.find_by(id:)
when "group"
- # TODO OP does not support nesting of groups but SCIM does.
+ # OP does not support nesting of groups but SCIM does.
# For now raises exception in case of group as a member arrival.
raise Scimitar::InvalidSyntaxError.new("Unsupported type #{type.inspect}")
else
@@ -125,6 +127,7 @@ class Group < Principal
end
def self.scim_mutable_attributes
+ # Allow mutation of everything with a write accessor
nil
end
diff --git a/app/models/user.rb b/app/models/user.rb
index db93b634272..6cc38d94ec9 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -629,6 +629,7 @@ class User < Principal
end
def self.scim_mutable_attributes
+ # Allow mutation of everything with a write accessor
nil
end
diff --git a/config/initializers/scimitar.rb b/config/initializers/scimitar.rb
index 9fede9b3c55..b5fcb6807f0 100644
--- a/config/initializers/scimitar.rb
+++ b/config/initializers/scimitar.rb
@@ -29,6 +29,9 @@
#++
Rails.application.config.to_prepare do
+ Scimitar.service_provider_configuration = Scimitar::ServiceProviderConfiguration.new({
+ patch: Scimitar::Supportable.unsupported
+ })
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new(
token_authenticator: Proc.new do |_token, _options|
OpenProject::FeatureDecisions.scim_api_active?
diff --git a/config/routes.rb b/config/routes.rb
index 418e4e26217..f274504d17d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -890,14 +890,12 @@ Rails.application.routes.draw do
get "Users/:id", to: "users#show"
post "Users", to: "users#create"
put "Users/:id", to: "users#replace"
- patch "Users/:id", to: "users#update"
delete "Users/:id", to: "users#destroy"
get "Groups", to: "groups#index"
get "Groups/:id", to: "groups#show"
post "Groups", to: "groups#create"
put "Groups/:id", to: "groups#replace"
- patch "Groups/:id", to: "groups#update"
delete "Groups/:id", to: "groups#destroy"
end
diff --git a/spec/requests/scim_v2/groups_spec.rb b/spec/requests/scim_v2/groups_spec.rb
index 262ed35a2cc..c087c0da55c 100644
--- a/spec/requests/scim_v2/groups_spec.rb
+++ b/spec/requests/scim_v2/groups_spec.rb
@@ -235,7 +235,10 @@ RSpec.describe "SCIM API Groups" do
"active" => true,
"externalId" => new_external_group_id,
"displayName" => group.name,
- "members" => [{ "value" => user.id.to_s }],
+ "members" => [
+ { "value" => user.id.to_s },
+ { "value" => admin.id.to_s },
+ ],
"schemas" => ["urn:ietf:params:scim:schemas:core:2.0:Group"]
}
@@ -246,7 +249,10 @@ RSpec.describe "SCIM API Groups" do
expect(response_body).to eq({ "displayName" => group.name,
"externalId" => new_external_group_id,
"id" => group.id.to_s,
- "members" => [{ "value" => user.id.to_s }],
+ "members" => [
+ { "value" => admin.id.to_s },
+ { "value" => user.id.to_s },
+ ],
"meta" => { "location" => "http://test.host/scim_v2/Groups/#{group.id}",
"created" => group.created_at.iso8601,
"lastModified" => group.updated_at.iso8601,
@@ -267,47 +273,4 @@ RSpec.describe "SCIM API Groups" do
end
end
end
-
- describe "PATCH /scim_v2/Users/:id" do
- context "with the feature flag enabled", with_flag: { scim_api: true } do
- it "changes external_id" do
- group
- new_external_group_id = "new_idp_user_id_123asdqwe12345"
- request_body = {
- "schemas" =>
- ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
- "Operations" => [{
- "op" => "replace",
- "path" => "externalId",
- "value" => new_external_group_id
- }]
- }
- patch "/scim_v2/Groups/#{group.id}", request_body.to_json, headers
-
- response_body = JSON.parse(last_response.body)
- group.reload
- expect(response_body).to eq({ "displayName" => group.name,
- "externalId" => new_external_group_id,
- "id" => group.id.to_s,
- "members" => [{ "value" => user.id.to_s }],
- "meta" => { "location" => "http://test.host/scim_v2/Groups/#{group.id}",
- "created" => group.created_at.iso8601,
- "lastModified" => group.updated_at.iso8601,
- "resourceType" => "Group" },
- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:Group"] })
- end
- end
-
- context "with the feature flag disabled", with_flag: { scim_api: false } do
- it do
- patch "/scim_v2/Groups/123", "", headers
-
- response_body = JSON.parse(last_response.body)
- expect(response_body).to eq(
- { "detail" => "Requires authentication", "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
- "status" => "401" }
- )
- end
- end
- end
end
diff --git a/spec/requests/scim_v2/users_spec.rb b/spec/requests/scim_v2/users_spec.rb
index 608d1043c0e..825ca2c0ed2 100644
--- a/spec/requests/scim_v2/users_spec.rb
+++ b/spec/requests/scim_v2/users_spec.rb
@@ -347,92 +347,4 @@ RSpec.describe "SCIM API Users" do
end
end
end
-
- describe "PATCH /scim_v2/Users/:id" do
- let(:new_external_user_id) { "new_idp_user_id_123asdqwe12345" }
-
- before { group }
-
- context "with the feature flag enabled", with_flag: { scim_api: true } do
- it "changes external_id" do
- request_body = {
- "schemas" =>
- ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
- "Operations" => [{
- "op" => "replace",
- "path" => "externalId",
- "value" => new_external_user_id
- }]
- }
- patch "/scim_v2/Users/#{user.id}", request_body.to_json, headers
-
- response_body = JSON.parse(last_response.body)
- user.reload
- expect(response_body).to eq({ "active" => true,
- "emails" => [{ "primary" => true,
- "type" => "work",
- "value" => user.mail }],
- "externalId" => new_external_user_id,
- "groups" => [{ "value" => group.id.to_s }],
- "id" => user.id.to_s,
- "meta" => { "created" => user.created_at.iso8601,
- "lastModified" => user.updated_at.iso8601,
- "location" => "http://test.host/scim_v2/Users/#{user.id}",
- "resourceType" => "User" },
- "name" => { "familyName" => user.lastname,
- "givenName" => user.firstname },
- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:User"],
- "userName" => user.login })
- end
-
- it "changes email value" do
- new_email_value = "[email protected]"
- request_body = {
- "schemas" =>
- ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
- "Operations" => [{
- "op" => "replace",
- "path" => "emails[type eq \"work\"]",
- "value" =>
- {
- "type" => "work",
- "value" => new_email_value,
- "primary" => true
- }
- }]
- }
- patch "/scim_v2/Users/#{user.id}", request_body.to_json, headers
-
- response_body = JSON.parse(last_response.body)
- user.reload
- expect(response_body).to eq({ "active" => true,
- "emails" => [{ "primary" => true,
- "type" => "work",
- "value" => new_email_value }],
- "externalId" => user.scim_external_id,
- "groups" => [{ "value" => group.id.to_s }],
- "id" => user.id.to_s,
- "meta" => { "created" => user.created_at.iso8601,
- "lastModified" => user.updated_at.iso8601,
- "location" => "http://test.host/scim_v2/Users/#{user.id}",
- "resourceType" => "User" },
- "name" => { "familyName" => user.lastname,
- "givenName" => user.firstname },
- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:User"],
- "userName" => user.login })
- end
- end
-
- context "with the feature flag disabled", with_flag: { scim_api: false } do
- it do
- patch "/scim_v2/Users/123", "", headers
-
- response_body = JSON.parse(last_response.body)
- expect(response_body).to eq(
- { "detail" => "Requires authentication", "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
- "status" => "401" }
- )
- end
- end
- end
end