]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2327, SONAR-2382 Add security checks
authorFabrice Bellingard <bellingard@gmail.com>
Fri, 29 Apr 2011 13:36:35 +0000 (15:36 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Fri, 29 Apr 2011 14:34:46 +0000 (16:34 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb
sonar-server/src/main/webapp/WEB-INF/lib/need_authorization.rb

index 179238269150d6e0821bc4af9da863f9ec9ad271..ad85564b11b3e865ea51ff2b157191f34ebb8af8 100644 (file)
@@ -23,7 +23,7 @@ require 'json'
 class Api::ReviewsController < Api::ApiController
 
   def index
-    reviews=Review.search(params)
+    reviews=select_authorized(:user, Review.search(params), :project)
     
     respond_to do |format|
       format.json { render :json => jsonp(Review.reviews_to_json(reviews)) }
index ac563f86f089f2e1bd37a580c150fc477cb46832..60cb1f9cc8a187e116d9bea3e7eec1fdb053e691 100644 (file)
@@ -35,8 +35,12 @@ class ReviewsController < ApplicationController
   
   # Used for the permalink, e.g. http://localhost:9000/reviews/view/1
   def view
-    @review=Review.find(params[:id], :include => ['resource', 'project'])
-    render 'reviews/_review', :locals => {:review => @review}
+    @review=Review.find(params[:id], :include => ['project'])
+    if has_role?(:user, @review.project)
+      render 'reviews/_review', :locals => {:review => @review}
+    else
+      render :text => "<b>Cannot access this review</b> : access denied."
+    end
   end
 
 
@@ -47,7 +51,7 @@ class ReviewsController < ApplicationController
   #
 
   def show
-    @review=Review.find(params[:id], :include => ['resource', 'project'])
+    @review=Review.find(params[:id], :include => ['project'])
     render :partial => 'reviews/show'
   end
 
@@ -322,7 +326,11 @@ class ReviewsController < ApplicationController
       end
     end
     
-    @reviews = Review.search(options)
+    found_reviews = Review.search(options)
+    @reviews = select_authorized(:user, found_reviews, :project)
+    if found_reviews.size != @reviews.size
+      @security_exclusions = true
+    end
   end
 
   def is_number?(s)
index d77813855a7ba2ccfc09590f89372f456ec17b83..01e838d9cd2a7433d104c71efedb55ff436cf713 100644 (file)
   <%
      end
   %>
+  
+  <% if @security_exclusions %>
+    <br/>
+    <p class="notes">Due to security settings, some results are not being displayed.</p>
+  <% end %>
+  
 </div>
 
 <div id="review-loading" style="display: none"><%= image_tag 'loading.gif' -%></div>
index bde096664fab2c24c9fc2a9672b9ccdf23a75bc5..f5cf8dcc89f8351f4a701d723a0619922c100aba 100644 (file)
@@ -177,6 +177,19 @@ module NeedAuthorization
       result
     end
 
+    def select_authorized(role, objects, resource_method=nil)
+      if resource_method
+        booleans=has_role?(role, objects.map{|obj| obj.send(resource_method)})
+      else
+        booleans=has_role?(role, objects)
+      end
+      result=[]
+      objects.each_with_index do |obj, index|
+        result<<obj if booleans[index]==true
+      end
+      result
+    end
+    
     #
     # Filter method to enforce a login admin requirement.
     #