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

[#66434] /ServiceProviderConfig endpoint responds with limited output without authorization.

Pavel Balashou35486e70f640
diff --git a/app/controllers/scim_v2/scim_controller_mixins.rb b/app/controllers/scim_v2/scim_controller_mixins.rb
index 274ce52e7c7..adbeecd0f5c 100644
--- a/app/controllers/scim_v2/scim_controller_mixins.rb
+++ b/app/controllers/scim_v2/scim_controller_mixins.rb
@@ -30,29 +30,65 @@
module ScimV2
module ScimControllerMixins
- def self.included(base)
- base.prepend(Overwrites)
- end
+ module ApplicationControllerMixin
+ def self.included(base)
+ base.prepend(Overwrites)
+ end
+
+ module Overwrites
+ # Completely overwriting authenticate method of Scimitar
+ def authenticate
+ if !EnterpriseToken.allows_to?(:scim_api) || !OpenProject::FeatureDecisions.scim_api_active?
+ return handle_scim_error(Scimitar::AuthenticationError.new)
+ end
- module Overwrites
- # Completely overwriting authenticate method of Scimitar
- def authenticate
- if !EnterpriseToken.allows_to?(:scim_api) || !OpenProject::FeatureDecisions.scim_api_active?
- return handle_scim_error(Scimitar::AuthenticationError.new)
+ user = warden.authenticate(scope: :scim_v2)
+ if user == nil
+ throw(:warden) unless available_publically?
+ else
+ User.current = user
+ # Only a ServiceAccount associated with a ScimClient can use SCIM Server API
+ unless User.current.respond_to?(:service) && User.current.service.is_a?(ScimClient)
+ handle_scim_error(Scimitar::AuthenticationError.new)
+ end
+ end
end
- User.current = warden.authenticate!(scope: :scim_v2)
+ def available_publically?
+ false
+ end
+
+ private
- # Only a ServiceAccount associated with a ScimClient can use SCIM Server API
- unless User.current.respond_to?(:service) && User.current.service.is_a?(ScimClient)
- handle_scim_error(Scimitar::AuthenticationError.new)
+ def warden
+ request.env["warden"]
end
end
+ end
- private
+ module ServiceProviderConfigurationControllerMixin
+ def self.included(base)
+ base.prepend(Overwrites)
+ end
+
+ module Overwrites
+ def show
+ if User.current == User.anonymous
+ if warden.winning_strategy.blank? # it means authorization header was absent. So, there is no appropriate strategy
+ render json: ScimitarSchemaExtension::LimitedServiceProviderConfiguration.new
+ else
+ throw(:warden)
+ end
+ else
+ super
+ end
+ end
- def warden
- request.env["warden"]
+ private
+
+ def available_publically?
+ true
+ end
end
end
end
diff --git a/config/initializers/scimitar.rb b/config/initializers/scimitar.rb
index 5a03a0d9e0f..47ec8a89c72 100644
--- a/config/initializers/scimitar.rb
+++ b/config/initializers/scimitar.rb
@@ -31,10 +31,14 @@
Rails.application.config.to_prepare do
Scimitar.service_provider_configuration = Scimitar::ServiceProviderConfiguration.new(
patch: Scimitar::Supportable.supported,
- authenticationSchemes: [Scimitar::AuthenticationScheme.bearer]
+ authenticationSchemes: ScimitarSchemaExtension::AUTHENTICATION_SCHEMES
)
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new(
- application_controller_mixin: ScimV2::ScimControllerMixins
+ application_controller_mixin: ScimV2::ScimControllerMixins::ApplicationControllerMixin
+ )
+
+ Scimitar::ServiceProviderConfigurationsController.include(
+ ScimV2::ScimControllerMixins::ServiceProviderConfigurationControllerMixin
)
Scimitar::Schema::User.singleton_class.class_eval do
diff --git a/config/static_links.yml b/config/static_links.yml
index bb2fe894bc6..8885b128ede 100644
--- a/config/static_links.yml
+++ b/config/static_links.yml
@@ -170,6 +170,10 @@ sysadmin_docs:
href: https://www.openproject.org/docs/system-admin-guide/authentication/saml/
scim:
href: https://www.openproject.org/docs/system-admin-guide/authentication/scim/
+ scim_static_access_token_authentication_method:
+ href: https://www.openproject.org/docs/system-admin-guide/authentication/scim/#a-static-access-token
+ scim_oauth2_client_credentials_authentication_method:
+ href: https://www.openproject.org/docs/system-admin-guide/authentication/scim/#b-oauth-20-client-credentials
scim_jwt_authetication_method:
href: https://www.openproject.org/docs/system-admin-guide/authentication/scim/#c-jwt-from-identity-provider
text_formatting:
diff --git a/lib/scimitar_schema_extension.rb b/lib/scimitar_schema_extension.rb
index 93b43ddc96b..77a0809ceef 100644
--- a/lib/scimitar_schema_extension.rb
+++ b/lib/scimitar_schema_extension.rb
@@ -48,6 +48,49 @@ class OpenProjectNameComplexType < Scimitar::ComplexTypes::Base
end
module ScimitarSchemaExtension
+ AUTHENTICATION_SCHEMES = [
+ Scimitar::AuthenticationScheme.new(
+ type: "oauth2",
+ name: "OAuth2",
+ description: OpenProject::Static::Links.links[:sysadmin_docs][:scim_static_access_token_authentication_method][:href]
+ ),
+ Scimitar::AuthenticationScheme.new(
+ type: "oauthbearertoken",
+ name: "OAuth Bearer Token",
+ description: OpenProject::Static::Links.links[:sysadmin_docs][:scim_oauth2_client_credentials_authentication_method][:href]
+ ),
+ Scimitar::AuthenticationScheme.new(
+ type: "oidcjwt",
+ name: "OpenID Provider JWT",
+ description: OpenProject::Static::Links.links[:sysadmin_docs][:scim_jwt_authetication_method][:href]
+ )
+ ].freeze
+
+ class LimitedServiceProviderConfiguration
+ include ActiveModel::Model
+
+ attr_accessor(
+ :authenticationSchemes,
+ :meta,
+ :schemas
+ )
+
+ def initialize(attributes = {})
+ defaults = {
+ meta: Scimitar::Meta.new(
+ resourceType: "ServiceProviderConfig",
+ created: Time.zone.now,
+ lastModified: Time.zone.now,
+ version: "1"
+ ),
+ schemas: ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
+ authenticationSchemes: AUTHENTICATION_SCHEMES
+ }
+
+ super(defaults.merge(attributes))
+ end
+ end
+
module Group
def scim_attributes
[
diff --git a/spec/requests/scim_v2/service_provider_config_spec.rb b/spec/requests/scim_v2/service_provider_config_spec.rb
index ccdc54439cb..bef4fcdcbf1 100644
--- a/spec/requests/scim_v2/service_provider_config_spec.rb
+++ b/spec/requests/scim_v2/service_provider_config_spec.rb
@@ -42,21 +42,60 @@ RSpec.describe "SCIM API ServiceProviderConfig", with_ee: [:scim_api] do
describe "GET /scim_v2/ServiceProviderConfig" do
context "with the feature flag enabled", with_flag: { scim_api: true } do
- it "responds with ServiceProviderConfig information" do
+ it "responds with full ServiceProviderConfig information if authorization is correct" do
get "/scim_v2/ServiceProviderConfig", {}, headers
response_body = JSON.parse(last_response.body)
- expect(response_body).to include({ "authenticationSchemes" => [{ "description" => "Authentication scheme using the OAuth Bearer Token Standard",
- "name" => "OAuth Bearer Token",
- "type" => "oauthbearertoken" }],
- "bulk" => { "supported" => false },
- "changePassword" => { "supported" => false },
- "etag" => { "supported" => false },
- "filter" => { "maxResults" => 100,
- "supported" => true },
- "patch" => { "supported" => true },
- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
- "sort" => { "supported" => false } })
+ expect(response_body).to include("authenticationSchemes" => [{"description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#a-static-access-token",
+ "name" => "OAuth2",
+ "type" => "oauth2"},
+ {"description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#b-oauth-20-client-credentials",
+ "name" => "OAuth Bearer Token",
+ "type" => "oauthbearertoken"},
+ {"description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#c-jwt-from-identity-provider",
+ "name" => "OpenID Provider JWT",
+ "type" => "oidcjwt"}],
+ "bulk" => { "supported" => false },
+ "changePassword" => { "supported" => false },
+ "etag" => { "supported" => false },
+ "filter" => { "maxResults" => 100,
+ "supported" => true },
+ "patch" => { "supported" => true },
+ "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],
+ "sort" => { "supported" => false })
+ end
+
+ context '' do
+ let(:token) { OpenStruct.new(plaintext_token: "123123") }
+
+ it "responds with 401 Unauthorized if authorization is incorrect" do
+ get "/scim_v2/ServiceProviderConfig", {}, headers
+
+ expect(last_response.status).to eq(401)
+ expect(last_response.body).to eq("invalid_token")
+ end
+ end
+
+ context '' do
+ let(:token) { OpenStruct.new(plaintext_token: "123123") }
+
+ it "responds with full ServiceProviderConfig information if authorization is absent" do
+ get "/scim_v2/ServiceProviderConfig", {}, { "CONTENT_TYPE" => "application/scim+json" }
+
+ expect(last_response.status).to eq(200)
+ response_body = JSON.parse(last_response.body)
+ expect(response_body.keys).to eq(["meta", "schemas", "authenticationSchemes"])
+ expect(response_body).to include("authenticationSchemes" => [{"description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#a-static-access-token",
+ "name" => "OAuth2",
+ "type" => "oauth2"},
+ {"description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#b-oauth-20-client-credentials",
+ "name" => "OAuth Bearer Token",
+ "type" => "oauthbearertoken"},
+ {"description" => "https://www.openproject.org/docs/system-admin-guide/authentication/scim/#c-jwt-from-identity-provider",
+ "name" => "OpenID Provider JWT",
+ "type" => "oidcjwt"}],
+ "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"],)
+ end
end
end
@@ -68,7 +107,7 @@ RSpec.describe "SCIM API ServiceProviderConfig", with_ee: [:scim_api] do
expect(response_body).to eq(
{ "detail" => "Requires authentication", "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],
"status" => "401" }
- )
+ )
expect(last_response).to have_http_status(401)
end
end