feat: remove certificate fingerprint field

This commit is contained in:
Shivam Mishra
2025-08-28 16:13:17 +05:30
parent 85fb20013e
commit 846ea71e56
6 changed files with 11 additions and 34 deletions
@@ -3,7 +3,6 @@ class CreateAccountSamlSettings < ActiveRecord::Migration[7.1]
create_table :account_saml_settings do |t|
t.references :account, null: false
t.string :sso_url
t.string :certificate_fingerprint
t.text :certificate
t.string :sp_entity_id
t.boolean :enforced_sso, default: false, null: false
-1
View File
@@ -31,7 +31,6 @@ ActiveRecord::Schema[7.1].define(version: 2025_08_25_070005) do
create_table "account_saml_settings", force: :cascade do |t|
t.bigint "account_id", null: false
t.string "sso_url"
t.string "certificate_fingerprint"
t.text "certificate"
t.string "sp_entity_id"
t.boolean "enforced_sso", default: false, null: false
@@ -29,7 +29,6 @@ class Api::V1::Accounts::SamlSettingsController < Api::V1::Accounts::BaseControl
def saml_settings_params
params.require(:saml_settings).permit(
:sso_url,
:certificate_fingerprint,
:certificate,
:sp_entity_id,
:enforced_sso,
+11 -27
View File
@@ -2,17 +2,16 @@
#
# Table name: account_saml_settings
#
# id :bigint not null, primary key
# attribute_mappings :json
# certificate :text
# certificate_fingerprint :string
# enforced_sso :boolean default(FALSE), not null
# role_mappings :json
# sso_url :string
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# sp_entity_id :string
# id :bigint not null, primary key
# attribute_mappings :json
# certificate :text
# enforced_sso :boolean default(FALSE), not null
# role_mappings :json
# sso_url :string
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# sp_entity_id :string
#
# Indexes
#
@@ -26,10 +25,8 @@ class AccountSamlSettings < ApplicationRecord
validates :certificate, presence: true
validates :sp_entity_id, presence: true
before_save :generate_certificate_fingerprint, if: :certificate_changed?
def saml_enabled?
sso_url.present? && certificate_fingerprint.present?
sso_url.present? && certificate.present?
end
def sp_entity_id_or_default
@@ -41,17 +38,4 @@ class AccountSamlSettings < ApplicationRecord
def installation_name
GlobalConfigService.load('INSTALLATION_NAME', 'Chatwoot')
end
def generate_certificate_fingerprint
return if certificate.blank?
begin
cert = OpenSSL::X509::Certificate.new(certificate)
self.certificate_fingerprint = OpenSSL::Digest::SHA256.new(cert.to_der).hexdigest.upcase.scan(/.{2}/).join(':')
rescue OpenSSL::X509::CertificateError => e
Rails.logger.error "Failed to parse SAML certificate: #{e.message}"
errors.add(:certificate, 'is not a valid X.509 certificate')
throw(:abort)
end
end
end
@@ -1,9 +1,6 @@
json.id account_saml_settings.id
json.account_id account_saml_settings.account_id
json.enabled account_saml_settings.enabled
json.sso_url account_saml_settings.sso_url
json.certificate_fingerprint account_saml_settings.certificate_fingerprint
json.certificate account_saml_settings.certificate
json.sp_entity_id account_saml_settings.sp_entity_id
json.enforced_sso account_saml_settings.enforced_sso
json.attribute_mappings account_saml_settings.attribute_mappings || {}
-1
View File
@@ -2,7 +2,6 @@ FactoryBot.define do
factory :account_saml_settings do
account
sso_url { 'https://idp.example.com/saml/sso' }
certificate_fingerprint { nil }
certificate do
key = OpenSSL::PKey::RSA.new(2048)
cert = OpenSSL::X509::Certificate.new