Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. public class AuthInterceptor extends HandlerInterceptorAdapter {
  2.  
  3.         public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handlerMethod) throws Exception {
  4.                 Log.info(AuthInterceptor.class, "preHandle");
  5.  
  6.                 if ( !Auth.Config.ENABLED ) {
  7.                         return Auth.Config.GRANT_ACCESS;
  8.                 }
  9.  
  10.                 // =======
  11.                 Method method     = ((HandlerMethod) handlerMethod).getMethod();
  12.                 Class<?> clazz    = method.getDeclaringClass();
  13.                 String methodName = method.getName();
  14.                 // =======
  15.  
  16.                 final Set<String> rules = new TreeSet<>();
  17.                 rules.add(Auth.ANYONE);
  18.  
  19.                 HashMap<Class<? extends Authority>, Authority> loggedIn = Auth.getLoggedIn();
  20.  
  21.                 // TODO
  22.                 // Basically here, what I want to do is use the methodName above, which is the action to be invoked after this filter,
  23.                 // and then match it against the rules defined below in the static block below.
  24.                 // "Anyone" have access to RootController.index() for instance.
  25.                 // The user can have more rules.
  26.                 // The problem here is they are being referenced using a String
  27.  
  28.                 return Auth.Config.DENY_ACCESS;
  29.         }
  30.  
  31.         public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
  32.         }
  33.  
  34.         public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
  35.  
  36.         }
  37.  
  38.         // Imagine this running once before the preHandle method above is called
  39.         static {
  40.  
  41.         // This is where I would like to reference the methods in a statically typed manner
  42.                 Rule rule = Rule.get(Auth.ANYONE)
  43.                         .allow(RootController.class, "index")
  44.                         .allow(HomeController.class, "index")
  45.                         .allow(ResourcesController.class, "publics");
  46.         }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement