Module: Lockdown::Frameworks::Rails::System

Includes:
Controller
Defined in:
lib/lockdown/frameworks/rails.rb

Instance Method Summary collapse

Methods included from Controller

#available_actions, #controller_name

Instance Method Details

#load_controller_classesObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/lockdown/frameworks/rails.rb', line 82

def load_controller_classes
  @controller_classes = {}
 
  maybe_load_framework_controller_parent

  ApplicationController.helper_method :authorized?

  ApplicationController.before_filter do |c|
    c.set_current_user
    c.configure_lockdown
    c.check_request_authorization
  end

  ApplicationController.filter_parameter_logging :password, 
    :password_confirmation
      
  ApplicationController.rescue_from SecurityError, 
    :with => proc{|e| access_denied(e)}


  Dir.chdir("#{Lockdown.project_root}/app/controllers") do
    Dir["**/*.rb"].sort.each do |c|
      c = c.split('.').first
      next if c == "application"
      lockdown_load(c) 
    end
    if PLATFORM =~ /java/
      Dir["**/*.class"].sort.each do |c|
        c = c.split('.').first
        next if c == "application"
        lockdown_load(c)
      end
    end
  end

  if ENV['RAILS_ENV'] != 'production'
    if ActiveSupport.const_defined?("Dependencies")
      ActiveSupport::Dependencies.clear
    else
      Dependencies.clear
    end
  end
end

#lockdown_load(filename) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/lockdown/frameworks/rails.rb', line 136

def lockdown_load(filename)
  klass = Lockdown.class_name_from_file(filename)

  require_or_load(filename)

  @controller_classes[klass] = Lockdown.qualified_const_get(klass) 
end

#maybe_load_framework_controller_parentObject



126
127
128
129
130
131
132
133
134
# File 'lib/lockdown/frameworks/rails.rb', line 126

def maybe_load_framework_controller_parent
  if ::Rails::VERSION::MAJOR >= 2 && ::Rails::VERSION::MINOR >= 3
    filename = "application_controller.rb"
  else
    filename = "application.rb"
  end
  
  require_or_load(filename)
end

#require_or_load(filename) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/lockdown/frameworks/rails.rb', line 144

def require_or_load(filename)
  if ActiveSupport.const_defined?("Dependencies")
    ActiveSupport::Dependencies.require_or_load(filename)
  else
    Dependencies.require_or_load(filename)
  end
end

#skip_sync?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/lockdown/frameworks/rails.rb', line 78

def skip_sync?
  Lockdown::System.fetch(:skip_db_sync_in).include?(ENV['RAILS_ENV'])
end