Module: StandardId::ControllerPolicy

Extended by:
ActiveSupport::Concern
Included in:
Api::BaseController, Api::WellKnown::JwksController, Api::WellKnown::OpenidConfigurationController, Web::BaseController
Defined in:
app/controllers/concerns/standard_id/controller_policy.rb

Class Method Summary collapse

Class Method Details

.all_controllersObject



51
52
53
# File 'app/controllers/concerns/standard_id/controller_policy.rb', line 51

def all_controllers
  LOCK.synchronize { registry[:public] + registry[:authenticated] }
end

.authenticated_controllersObject



47
48
49
# File 'app/controllers/concerns/standard_id/controller_policy.rb', line 47

def authenticated_controllers
  LOCK.synchronize { registry[:authenticated].dup }
end

.public_controllersObject



43
44
45
# File 'app/controllers/concerns/standard_id/controller_policy.rb', line 43

def public_controllers
  LOCK.synchronize { registry[:public].dup }
end

.register(controller, policy) ⇒ Object

Registers a controller under the given policy. Raises if the controller is already registered under the opposite policy. Re-registering under the same policy is a safe no-op (Set semantics).



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/concerns/standard_id/controller_policy.rb', line 58

def register(controller, policy)
  LOCK.synchronize do
    other = policy == :public ? :authenticated : :public
    if registry[other].include?(controller)
      raise ArgumentError, "#{controller} is already registered as #{other}"
    end

    registry[policy] << controller
  end

  # If AuthorizationBypass has already been applied, apply skips to this
  # newly registered controller immediately. This handles dev-mode lazy
  # loading where controllers register after the initial apply_skips! call.
  AuthorizationBypass.apply_to_controller(controller, policy) if AuthorizationBypass.applied?
end

.registry_snapshotObject

Returns a point-in-time copy of the registry, safe to iterate without holding the lock.



76
77
78
79
80
81
# File 'app/controllers/concerns/standard_id/controller_policy.rb', line 76

def registry_snapshot
  LOCK.synchronize do
    (@registry ||= { public: Set.new, authenticated: Set.new })
      .transform_values(&:dup)
  end
end

.reset_registry!Object



92
93
94
95
96
# File 'app/controllers/concerns/standard_id/controller_policy.rb', line 92

def reset_registry!
  LOCK.synchronize do
    @registry = { public: Set.new, authenticated: Set.new }
  end
end