lib/osso/models/identity_provider.rb in osso-0.0.5.pre.zeta vs lib/osso/models/identity_provider.rb in osso-0.0.5

- old
+ new

@@ -4,29 +4,34 @@ module Models # Base class for SAML Providers class IdentityProvider < ActiveRecord::Base belongs_to :enterprise_account belongs_to :oauth_client - has_many :users + has_many :users, dependent: :delete_all + before_create :set_sso_issuer before_save :set_status validate :sso_cert_valid - enum status: { pending: "PENDING", configured: 'CONFIGURED', active: "ACTIVE", error: "ERROR"} + enum status: { pending: 'PENDING', configured: 'CONFIGURED', active: 'ACTIVE', error: 'ERROR' } PEM_HEADER = "-----BEGIN CERTIFICATE-----\n" PEM_FOOTER = "\n-----END CERTIFICATE-----" + ENTITY_ID_URI_REQUIRED = [ + 'PING', + ] + def name service.titlecase end def saml_options { domain: domain, idp_sso_target_url: sso_url, idp_cert: sso_cert, - issuer: domain, + issuer: sso_issuer, } end def assertion_consumer_service_url [ @@ -38,14 +43,26 @@ ].join('/') end alias acs_url assertion_consumer_service_url + def acs_url_validator + Regexp.escape(acs_url) + end + def set_status self.status = 'configured' if sso_url && sso_cert && pending? end + def set_sso_issuer + parts = [domain, oauth_client_id] + + parts.unshift('https:/') if ENTITY_ID_URI_REQUIRED.any?(service) + + self.sso_issuer = parts.join('/') + end + def active! update(status: 'active') end def error! @@ -79,18 +96,19 @@ # == Schema Information # # Table name: identity_providers # # id :uuid not null, primary key -# service :string +# service :enum # domain :string not null # sso_url :string # sso_cert :text # enterprise_account_id :uuid # oauth_client_id :uuid -# status :enum default("PENDING") +# status :enum default("pending") # created_at :datetime # updated_at :datetime +# users_count :integer default(0) # # Indexes # # index_identity_providers_on_domain (domain) # index_identity_providers_on_enterprise_account_id (enterprise_account_id)