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 ...@@ -8,48 +8,74 @@ class SamlProvider < ActiveRecord::Base
after_initialize :set_defaults, if: :new_record? 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 def certificate_fingerprint=(value)
"#{full_group_path}/-/saml/callback" super(strip_left_to_right_chars(value))
end end
def issuer def settings
full_group_path ConfiguredOptions.new(self).to_h
end end
def name_identifier_format class DefaultOptions
NAME_IDENTIFIER_FORMAT NAME_IDENTIFIER_FORMAT = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'.freeze
end
def certificate_fingerprint=(value) def initialize(group_path)
super(strip_left_to_right_chars(value)) @group_path = group_path
end end
def settings def name_identifier_format
{ NAME_IDENTIFIER_FORMAT
assertion_consumer_service_url: assertion_consumer_service_url, end
issuer: issuer,
idp_cert_fingerprint: certificate_fingerprint, def full_group_path
idp_sso_target_url: sso_url, "#{host}/groups/#{@group_path}"
name_identifier_format: name_identifier_format 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 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 def to_h
"#{host}/groups/#{group.full_path}" super.merge(
idp_cert_fingerprint: @saml_provider.certificate_fingerprint,
idp_sso_target_url: @saml_provider.sso_url
)
end
end end
private
def set_defaults def set_defaults
self.enabled = true self.enabled = true
end end
def host
@host ||= Gitlab.config.gitlab.url
end
def strip_left_to_right_chars(input) def strip_left_to_right_chars(input)
input&.gsub(/[\u200E]/, '') input&.gsub(/[\u200E]/, '')
end 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