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
Check if users are active before authenticating them
Jan Sandbrink47bb07194f4a
diff --git a/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb b/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rbindex a3fadbb4fb7..51cd9698e53 100644--- a/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb+++ b/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb@@ -26,15 +26,31 @@ module OpenProject->(payload_and_provider) dopayload, provider = payload_and_provideruser = User.find_by(identity_url: "#{provider.slug}:#{payload['sub']}")- if user- success!(user)- else- fail_with_header!(error: "invalid_token", error_description: "The user identified by the token is not known")- end+ authentication_result(user)end,->(error) { fail_with_header!(error: "invalid_token", error_description: error) })end++ private++ def authentication_result(user)+ if user.nil?+ return fail_with_header!(+ error: "invalid_token",+ error_description: "The user identified by the token is not known"+ )+ end++ if user.active?+ success!(user)+ else+ fail_with_header!(+ error: "invalid_token",+ error_description: "The user account is locked"+ )+ end+ endendendenddiff --git a/spec/requests/api/v3/authentication_spec.rb b/spec/requests/api/v3/authentication_spec.rbindex 3be1938395a..c985ca4cbba 100644--- a/spec/requests/api/v3/authentication_spec.rb+++ b/spec/requests/api/v3/authentication_spec.rb@@ -527,5 +527,18 @@ RSpec.describe "API V3 Authentication" do.to eq(%{Bearer realm="OpenProject API", error="invalid_token", error_description="#{error}"})endend++ context "when user identified by token is locked" do+ let(:user) { create(:user, :locked, identity_url: "keycloak:#{token_sub}") }++ it "fails with HTTP 401 Unauthorized" do+ get resource+ expect(last_response).to have_http_status :unauthorized+ expect(JSON.parse(last_response.body)).to eq(error_response_body)+ error = "The user account is locked"+ expect(last_response.header["WWW-Authenticate"])+ .to eq(%{Bearer realm="OpenProject API", error="invalid_token", error_description="#{error}"})+ end+ endendend