@Test(expectedExceptions = ServletException.class) public void shouldThrowServletExceptionIfRequestIsNotHttpServletRequest() throws Exception { initFilter(INIT_PARAMS); ServletRequest request = mock(ServletRequest.class); ServletResponse response = mock(ServletResponse.class); FilterChain filterChain = mock(FilterChain.class); restAuthorizationDispatcherFilter.doFilter(request, response, filterChain); }
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { throw new ServletException("Request must be of types HttpServletRequest"); } HttpServletRequest request = (HttpServletRequest) servletRequest; try { final String resourcePath = request.getPathInfo(); Map<String, String> details = restDispatcher.getRequestDetails(resourcePath == null ? "/" : resourcePath); String endpoint = details.get("resourceName"); if (RestDispatcher.REALMS.equalsIgnoreCase(endpoint)) { authorize(realmsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.USERS.equalsIgnoreCase(endpoint)) { authorize(usersAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.GROUPS.equalsIgnoreCase(endpoint)) { authorize(groupsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.AGENTS.equalsIgnoreCase(endpoint)) { authorize(agentsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SERVER_INFO.equalsIgnoreCase(endpoint)) { authorize(serverInfoAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SESSIONS.equalsIgnoreCase(endpoint)) { authorize(sessionAuthzConfiguratorClassName, request, servletResponse, chain); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found. Not performing authorization on request."); chain.doFilter(servletRequest, servletResponse); } }
RestAuthorizationDispatcherFilter implements Filter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { throw new ServletException("Request must be of types HttpServletRequest"); } HttpServletRequest request = (HttpServletRequest) servletRequest; try { final String resourcePath = request.getPathInfo(); Map<String, String> details = restDispatcher.getRequestDetails(resourcePath == null ? "/" : resourcePath); String endpoint = details.get("resourceName"); if (RestDispatcher.REALMS.equalsIgnoreCase(endpoint)) { authorize(realmsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.USERS.equalsIgnoreCase(endpoint)) { authorize(usersAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.GROUPS.equalsIgnoreCase(endpoint)) { authorize(groupsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.AGENTS.equalsIgnoreCase(endpoint)) { authorize(agentsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SERVER_INFO.equalsIgnoreCase(endpoint)) { authorize(serverInfoAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SESSIONS.equalsIgnoreCase(endpoint)) { authorize(sessionAuthzConfiguratorClassName, request, servletResponse, chain); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found. Not performing authorization on request."); chain.doFilter(servletRequest, servletResponse); } } }
RestAuthorizationDispatcherFilter implements Filter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { throw new ServletException("Request must be of types HttpServletRequest"); } HttpServletRequest request = (HttpServletRequest) servletRequest; try { final String resourcePath = request.getPathInfo(); Map<String, String> details = restDispatcher.getRequestDetails(resourcePath == null ? "/" : resourcePath); String endpoint = details.get("resourceName"); if (RestDispatcher.REALMS.equalsIgnoreCase(endpoint)) { authorize(realmsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.USERS.equalsIgnoreCase(endpoint)) { authorize(usersAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.GROUPS.equalsIgnoreCase(endpoint)) { authorize(groupsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.AGENTS.equalsIgnoreCase(endpoint)) { authorize(agentsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SERVER_INFO.equalsIgnoreCase(endpoint)) { authorize(serverInfoAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SESSIONS.equalsIgnoreCase(endpoint)) { authorize(sessionAuthzConfiguratorClassName, request, servletResponse, chain); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found. Not performing authorization on request."); chain.doFilter(servletRequest, servletResponse); } } RestAuthorizationDispatcherFilter();   RestAuthorizationDispatcherFilter(RestDispatcher restDispatcher, AuthZFilter authZFilter); }
RestAuthorizationDispatcherFilter implements Filter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { throw new ServletException("Request must be of types HttpServletRequest"); } HttpServletRequest request = (HttpServletRequest) servletRequest; try { final String resourcePath = request.getPathInfo(); Map<String, String> details = restDispatcher.getRequestDetails(resourcePath == null ? "/" : resourcePath); String endpoint = details.get("resourceName"); if (RestDispatcher.REALMS.equalsIgnoreCase(endpoint)) { authorize(realmsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.USERS.equalsIgnoreCase(endpoint)) { authorize(usersAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.GROUPS.equalsIgnoreCase(endpoint)) { authorize(groupsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.AGENTS.equalsIgnoreCase(endpoint)) { authorize(agentsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SERVER_INFO.equalsIgnoreCase(endpoint)) { authorize(serverInfoAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SESSIONS.equalsIgnoreCase(endpoint)) { authorize(sessionAuthzConfiguratorClassName, request, servletResponse, chain); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found. Not performing authorization on request."); chain.doFilter(servletRequest, servletResponse); } } RestAuthorizationDispatcherFilter();   RestAuthorizationDispatcherFilter(RestDispatcher restDispatcher, AuthZFilter authZFilter); void init(FilterConfig filterConfig); void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain); void destroy(); }
RestAuthorizationDispatcherFilter implements Filter { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest)) { throw new ServletException("Request must be of types HttpServletRequest"); } HttpServletRequest request = (HttpServletRequest) servletRequest; try { final String resourcePath = request.getPathInfo(); Map<String, String> details = restDispatcher.getRequestDetails(resourcePath == null ? "/" : resourcePath); String endpoint = details.get("resourceName"); if (RestDispatcher.REALMS.equalsIgnoreCase(endpoint)) { authorize(realmsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.USERS.equalsIgnoreCase(endpoint)) { authorize(usersAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.GROUPS.equalsIgnoreCase(endpoint)) { authorize(groupsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.AGENTS.equalsIgnoreCase(endpoint)) { authorize(agentsAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SERVER_INFO.equalsIgnoreCase(endpoint)) { authorize(serverInfoAuthzConfiguratorClassName, request, servletResponse, chain); } else if (RestDispatcher.SESSIONS.equalsIgnoreCase(endpoint)) { authorize(sessionAuthzConfiguratorClassName, request, servletResponse, chain); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found. Not performing authorization on request."); chain.doFilter(servletRequest, servletResponse); } } RestAuthorizationDispatcherFilter();   RestAuthorizationDispatcherFilter(RestDispatcher restDispatcher, AuthZFilter authZFilter); void init(FilterConfig filterConfig); void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain); void destroy();  }