Commit dba65b24 authored by James Edwards-Jones's avatar James Edwards-Jones

SamlProvider settings extracted for use unconfigured

parent 0ec8038a
......@@ -8,48 +8,74 @@ class SamlProvider < ActiveRecord::Base
after_initialize :set_defaults, if: :new_record?
NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'.freeze
delegate :assertion_consumer_service_url, :issuer, :name_identifier_format, to: :settings
def assertion_consumer_service_url
"#{full_group_path}/-/saml/callback"
def certificate_fingerprint=(value)
super(strip_left_to_right_chars(value))
end
def issuer
full_group_path
def settings
ConfiguredOptions.new(self).to_h
end
def name_identifier_format
NAME_IDENTIFIER_FORMAT
end
class DefaultOptions
NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'.freeze
def certificate_fingerprint=(value)
super(strip_left_to_right_chars(value))
end
def initialize(group_path)
@group_path = group_path
end
def settings
{
assertion_consumer_service_url: assertion_consumer_service_url,
issuer: issuer,
idp_cert_fingerprint: certificate_fingerprint,
idp_sso_target_url: sso_url,
name_identifier_format: name_identifier_format
}
def name_identifier_format
NAME_IDENTIFIER_FORMAT
end
def full_group_path
"#{host}/groups/#{@group_path}"
end
def issuer
full_group_path
end
def assertion_consumer_service_url
"#{full_group_path}/-/saml/callback"
end
def to_h
{
assertion_consumer_service_url: assertion_consumer_service_url,
issuer: issuer,
name_identifier_format: name_identifier_format
}
end
private
def host
@host ||= Gitlab.config.gitlab.url
end
end
private
class ConfiguredOptions < DefaultOptions
def initialize(saml_provider)
@group_path = saml_provider.group.full_path
@saml_provider = saml_provider
end
def full_group_path
"#{host}/groups/#{group.full_path}"
def to_h
super.merge(
idp_cert_fingerprint: @saml_provider.certificate_fingerprint,
idp_sso_target_url: @saml_provider.sso_url
)
end
end
private
def set_defaults
self.enabled = true
end
def host
@host ||= Gitlab.config.gitlab.url
end
def strip_left_to_right_chars(input)
input&.gsub(/[\u200E]/, '')
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment