List of usage examples for javax.servlet FilterChain FilterChain
FilterChain
From source file:org.javalite.activeweb.RequestDispatcherSpec.java
@Before public void beforeStart() { filterChain = new FilterChain() { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { fellThrough = true;//w w w . j ava 2 s . c o m } }; badFilterChain = new FilterChain() { public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { throw new RuntimeException("I'm a bad... bad exception!"); } }; Configuration.setUseDefaultLayoutForErrors(true); }
From source file:com.meltmedia.cadmium.servlets.ErrorPageFilterSelectionTest.java
/** * Creates a filter chain that calls sendError(int) with the specified status code. * //w w w. jav a 2 s. c o m * @param statusCode the status code to send. * @return a filter chain that simulates a sendError condition. */ public static FilterChain sendErrorFilterChain(final int statusCode) { return new FilterChain() { @Override public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException { ((HttpServletResponse) res).sendError(statusCode); } }; }
From source file:com.jeanchampemont.notedown.utils.SecurityInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (modelAndView != null) { FilterInvocation filterInvocation = new FilterInvocation(request, response, new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { throw new UnsupportedOperationException(); }//from w w w. j av a 2 s . com }); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { WebSecurityExpressionRoot sec = new WebSecurityExpressionRoot(authentication, filterInvocation); sec.setTrustResolver(new AuthenticationTrustResolverImpl()); modelAndView.getModel().put("sec", sec); } } }
From source file:com.github.carlomicieli.nerdmovies.config.ImplicitObjectsInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if (modelAndView != null && !modelAndView.getViewName().startsWith("redirect:")) { FilterInvocation filterInvocation = new FilterInvocation(request, response, new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { throw new UnsupportedOperationException(); }//from ww w.ja v a2 s . c o m }); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); WebSecurityExpressionRoot sec = new WebSecurityExpressionRoot(authentication, filterInvocation); sec.setTrustResolver(new AuthenticationTrustResolverImpl()); modelAndView.getModel().put("sec", sec); } }
From source file:com.meltmedia.cadmium.servlets.ErrorPageFilterSelectionTest.java
/** * Creates a filter chain that throws a ServletException with the specified cause. * @param cause the cause of the exception that will be thrown. * @return a filter chain that simulates an exception. */// w ww . j a v a 2s . co m public static FilterChain throwExceptionFilterChain(final Throwable cause) { return new FilterChain() { @Override public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException { throw new ServletException(cause); } }; }
From source file:com.github.lothar.security.acl.activation.web.AclActivatorFilterTest.java
@Test public void should_acl_security_be_enabled_when_filter_is_activated() throws IOException, ServletException { AclActivatorFilter filter = new AclActivatorFilter(aclSecurityActivator); FilterChain chainAssert = new FilterChain() { @Override// w w w .j av a 2 s .c o m public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { assertThat(aclSecurityActivator.isEnabled()).isTrue(); } }; assertThat(aclSecurityActivator.isEnabled()).isFalse(); filter.doFilter(null, null, chainAssert); assertThat(aclSecurityActivator.isEnabled()).isFalse(); }
From source file:br.com.suricattus.surispring.spring.security.util.SecurityUtil.java
/** * Method that checks if the user has the given access expression. * /* w w w. j ava 2s . c om*/ * @see Spring Security Expression-Based Access Control * @param access * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static boolean isAuthorized(String access) { Map<String, SecurityExpressionHandler> expressionHandlres = ApplicationContextUtil.getContext() .getBeansOfType(SecurityExpressionHandler.class); SecurityExpressionHandler handler = (SecurityExpressionHandler) expressionHandlres.values().toArray()[0]; Expression accessExpression = handler.getExpressionParser().parseExpression(access); FilterInvocation f = new FilterInvocation(FacesUtils.getRequest(), FacesUtils.getResponse(), new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { throw new UnsupportedOperationException(); } }); return ExpressionUtils.evaluateAsBoolean(accessExpression, handler.createEvaluationContext(SecurityContextHolder.getContext().getAuthentication(), f)); }
From source file:se.trillian.goodies.web.DisableSessionIdInUrlFilterTest.java
public void testSessionIdInRequestUrlIsRemoved() throws Exception { request.setServerName("www.example.com"); request.setRequestURI("/index.html;jsessionid=1047kv5xa62lf"); request.setRequestedSessionIdFromURL(true); final boolean[] called = new boolean[] { false }; filter.doFilter(request, response, new FilterChain() { public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; assertFalse(request.isRequestedSessionIdFromURL()); assertEquals("/index.html", request.getRequestURI()); assertEquals("http://www.example.com:80/index.html", request.getRequestURL().toString()); called[0] = true;/* w ww . j av a 2s. co m*/ } }); assertTrue(called[0]); }
From source file:com.meltmedia.cadmium.servlets.ErrorPageFilterSelectionTest.java
/** * Creates a filter chain that sends a 200 response. * //from w w w . j av a 2 s.c o m * @param content the content to write to the res object. * @return a filter chain that simulates a 200 response. */ public static FilterChain successFilterChain(final String content) { return new FilterChain() { @Override public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException { HttpServletResponse httpRes = (HttpServletResponse) res; httpRes.setStatus(200); OutputStream out = null; InputStream in = null; try { out = res.getOutputStream(); in = new ByteArrayInputStream(content.getBytes()); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } } }; }
From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java
@Test public void testRedirect() throws Exception { final MockHttpSession session = new MockHttpSession(); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain filterChain = new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { // nothing to do }// w w w .j av a 2 s.c o m }; request.setSession(session); this.filter.doFilter(request, response, filterChain); assertEquals(CAS_LOGIN_URL + "?service=" + URLEncoder.encode(CAS_SERVICE_URL, "UTF-8"), response.getRedirectedUrl()); }