package ca.uhnresearch.pughlab.tracker.restlets;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.Status;
import org.restlet.routing.Filter;

public class AdminAuthorizer extends Filter {
	
	/**
	 * Use Shiro to check whether we have an admin permission, and only allow the request to 
	 * continue if we do. Ideal for naive coarse-grained authorization.
	 */
	protected int beforeHandle(Request request, Response response) {
		
    	Subject currentUser = SecurityUtils.getSubject();
    	if (currentUser.isPermitted("admin")) {
    		return CONTINUE;
    	} else {
    		response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
    		return STOP;
    	}
	}

}

@@ -203,102 +203,131 @@
 let.
-data.Status;%0Aimport org.restlet.routing.Filter;%0A%0Apublic class AdminAuthorizer extends Filter %7B
+security.Authorizer;%0A%0Apublic class AdminAuthorizer extends Authorizer %7B%0A%09%0A%09AdminAuthorizer() %7B%0A%09%09setIdentifier(%22admin%22);%0A%09%7D
 %0A%09%0A%09
@@ -500,33 +500,45 @@
 */%0A%09
-protected int beforeHandl
+@Override%0A%09protected boolean authoriz
 e(Re
@@ -575,22 +575,16 @@
 se) %7B%0A%09%09
-%0A    %09
 Subject 
@@ -629,17 +629,17 @@
 ();%0A
-    %09if (
+%09%09return 
 curr
@@ -670,134 +670,9 @@
 in%22)
-) %7B%0A    %09%09return CONTINUE;%0A    %09%7D else %7B%0A    %09%09response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);%0A    %09%09return STOP;%0A    %09%7D
+;
 %0A%09%7D%0A

Make the AdminAuthorizer into an Authorizer