diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 70a5f10..5926b40 100755 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,5 +1,6 @@ class AdminController < ApplicationController + # before_filter :administrative skip_before_filter :has_info def dashboard diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eba7470..a0ef5cf 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,13 +18,13 @@ class ApplicationController < ActionController::Base end def is_admin? - admin = current_user.admin if current_user + current_user.admin if current_user end def administrative if not is_admin? reset_session - redirect_to login_path + redirect_to root_url end end diff --git a/app/views/layouts/tutorial/url_access/_url_access_first.html.erb b/app/views/layouts/tutorial/url_access/_url_access_first.html.erb index 692f6a7..62cdc0c 100755 --- a/app/views/layouts/tutorial/url_access/_url_access_first.html.erb +++ b/app/views/layouts/tutorial/url_access/_url_access_first.html.erb @@ -16,7 +16,7 @@
+ Rails provides the ability to apply before_filter(s) which run prior to rendering content to the user. This is helpful when restricting access to content based on the user's role. Currently, the methods to apply a before_filter already exist in the application controller but were forgotten when creating the administrative functionality. Notice an asbsence of the before_filter within app/controllers/admin_controller.rb +
+
+ <%= %q{
+ class AdminController < ApplicationController
+
+ skip_before_filter :has_info
+ } %>
+
+
Failure to Restrict URL Access - ATTACK
++ Request the following URL /admin/1/dashboard and have fun :-) +
+Failure to Restrict URL Access - SOLUTION
++ The code is already available to restrict access to the admin controller by role within app/controllers/application_controller.rb: +
+
+ helper_method :current_user, :is_admin?
+
+ def is_admin?
+ current_user.admin if current_user
+ end
+
+ def administrative
+ if not is_admin?
+ reset_session
+ redirect_to root_url
+ end
+ end
+
+ + Then add the following line within app/controllers/admin_controller.rb +
+
+ class AdminController < ApplicationController
+
+ before_filter :administrative
+ skip_before_filter :has_info
+