Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AuthInterceptor extends HandlerInterceptorAdapter {
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handlerMethod) throws Exception {
- Log.info(AuthInterceptor.class, "preHandle");
- if ( !Auth.Config.ENABLED ) {
- return Auth.Config.GRANT_ACCESS;
- }
- // =======
- Method method = ((HandlerMethod) handlerMethod).getMethod();
- Class<?> clazz = method.getDeclaringClass();
- String methodName = method.getName();
- // =======
- final Set<String> rules = new TreeSet<>();
- rules.add(Auth.ANYONE);
- HashMap<Class<? extends Authority>, Authority> loggedIn = Auth.getLoggedIn();
- // TODO
- // Basically here, what I want to do is use the methodName above, which is the action to be invoked after this filter,
- // and then match it against the rules defined below in the static block below.
- // "Anyone" have access to RootController.index() for instance.
- // The user can have more rules.
- // The problem here is they are being referenced using a String
- return Auth.Config.DENY_ACCESS;
- }
- public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
- }
- public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
- }
- // Imagine this running once before the preHandle method above is called
- static {
- // This is where I would like to reference the methods in a statically typed manner
- Rule rule = Rule.get(Auth.ANYONE)
- .allow(RootController.class, "index")
- .allow(HomeController.class, "index")
- .allow(ResourcesController.class, "publics");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement