cartodb-4.42/app/controllers/carto/saml_controller.rb
2024-04-06 05:25:13 +00:00

27 lines
732 B
Ruby

require_dependency 'carto/controller_helper'
module Carto
class SamlController < ApplicationController
ssl_required :metadata
before_filter :load_organization, :ensure_saml_enabled
rescue_from LoadError, UnauthorizedError, with: :rescue_from_carto_error
def metadata
render(xml: Carto::SamlService.new(@organization).saml_metadata)
end
private
def load_organization
@organization = Carto::Organization.where(name: CartoDB.extract_subdomain(request)).first
raise LoadError.new('Organization does not exist') unless @organization
end
def ensure_saml_enabled
raise UnauthorizedError.new('SAML not enabled') unless @organization.auth_saml_enabled?
end
end
end