diff --git a/app/controllers/institutions_controller.rb b/app/controllers/institutions_controller.rb index 7170bed0..13ac6c2f 100644 --- a/app/controllers/institutions_controller.rb +++ b/app/controllers/institutions_controller.rb @@ -953,6 +953,7 @@ def settings_params :saml_idp_sso_post_service_url, :saml_idp_sso_redirect_service_url, :saml_last_name_attribute, + :saml_sp_entity_id, :saml_sp_next_public_cert, :saml_sp_private_key, :saml_sp_public_cert, diff --git a/app/models/institution.rb b/app/models/institution.rb index 5aa9b416..9a2b1ec5 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -124,6 +124,7 @@ # * `saml_metadata_url` Caches the value entered into the URL # field when supplying SAML metadata from # A URL. +# * `saml_sp_entity_id` SAML SP entity ID. # * `saml_sp_next_public_cert` SAML X.509 public certificate with a # later expiration than # {saml_sp_public_cert} to facilitate @@ -463,6 +464,13 @@ def default_metadata_profile self.metadata_profiles.where(institution_default: true).limit(1).first end + ## + # @return [String] + # + def default_saml_sp_entity_id + [scope_url, "entity"].join("/") + end + ## # @return [SubmissionProfile] # @@ -709,7 +717,7 @@ def required_elements # @return [String] # def saml_sp_entity_id - [scope_url, "entity"].join("/") + read_attribute(:saml_sp_entity_id) || default_saml_sp_entity_id end ## diff --git a/app/views/institutions/_saml_authentication_form.html.haml b/app/views/institutions/_saml_authentication_form.html.haml index d6850e91..0d153f57 100644 --- a/app/views/institutions/_saml_authentication_form.html.haml +++ b/app/views/institutions/_saml_authentication_form.html.haml @@ -36,6 +36,9 @@ .row .col-lg-6 %h5 Service Provider + .mb-3 + = f.label :saml_sp_entity_id, "Entity ID" + = f.text_field :saml_sp_entity_id, class: "form-control" .mb-3 = f.label :saml_sp_private_key, "Private Key" = f.text_area :saml_sp_private_key, rows: 10, class: "form-control" diff --git a/db/migrate/20240119023719_add_institutions_saml_sp_entity_id_column.rb b/db/migrate/20240119023719_add_institutions_saml_sp_entity_id_column.rb new file mode 100644 index 00000000..0cc590d4 --- /dev/null +++ b/db/migrate/20240119023719_add_institutions_saml_sp_entity_id_column.rb @@ -0,0 +1,5 @@ +class AddInstitutionsSamlSpEntityIdColumn < ActiveRecord::Migration[7.1] + def change + add_column :institutions, :saml_sp_entity_id, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 6ff605ac..f5dc8673 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_12_12_202706) do +ActiveRecord::Schema[7.1].define(version: 2024_01_19_023719) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "unaccent" @@ -448,6 +448,7 @@ t.string "saml_idp_sso_redirect_service_url" t.boolean "allow_user_registration", default: true, null: false t.string "saml_metadata_url" + t.string "saml_sp_entity_id" t.index ["fqdn"], name: "index_institutions_on_fqdn", unique: true t.index ["incoming_message_queue"], name: "index_institutions_on_incoming_message_queue", unique: true t.index ["key"], name: "index_institutions_on_key", unique: true diff --git a/test/models/institution_test.rb b/test/models/institution_test.rb index 1da7c515..76895a7d 100644 --- a/test/models/institution_test.rb +++ b/test/models/institution_test.rb @@ -301,6 +301,12 @@ class InstitutionTest < ActiveSupport::TestCase assert @instance.default_metadata_profile.institution_default end + # default_saml_sp_entity_id() + + test "default_saml_sp_entity_id() returns a correct value" do + assert_equal "#{@instance.scope_url}/entity", @instance.default_saml_sp_entity_id + end + # default_submission_profile() test "default_submission_profile() returns the default submission profile" do @@ -981,8 +987,9 @@ class InstitutionTest < ActiveSupport::TestCase # saml_sp_entity_id() - test "saml_sp_entity_id() returns a correct value" do - assert_equal "#{@instance.scope_url}/entity", @instance.saml_sp_entity_id + test "saml_sp_entity_id() returns the default entity ID when not set" do + assert_equal @instance.default_saml_sp_entity_id, + @instance.saml_sp_entity_id end # saml_sp_next_public_cert