Java Code Examples for javax.servlet.FilterChain

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project candlepin, under directory /src/test/java/org/candlepin/servlet/filter/.

Source file: CandlepinPersistFilterTest.java

  18 
vote

@Test public void transaction() throws IOException, ServletException {
  ServletRequest req=mock(ServletRequest.class);
  ServletResponse rsp=mock(ServletResponse.class);
  FilterChain chain=mock(FilterChain.class);
  filter.doFilter(req,rsp,chain);
  verify(work,atLeastOnce()).begin();
  verify(work,atLeastOnce()).end();
  verify(chain,atLeastOnce()).doFilter(eq(req),eq(rsp));
}
 

Example 2

From project doorkeeper, under directory /core/src/test/java/net/dataforte/doorkeeper/filter/.

Source file: AuthenticatorFilterTest.java

  18 
vote

@Test public void testAuthenticatorFilter() throws Exception {
  Doorkeeper doorkeeper=new Doorkeeper("doorkeeper.properties");
  AuthenticatorFilter filter=new AuthenticatorFilter();
  filter.setDoorkeeper(doorkeeper);
  HttpServletRequest request=mock(HttpServletRequest.class);
  HttpServletResponse response=mock(HttpServletResponse.class);
  FilterChain chain=mock(FilterChain.class);
}
 

Example 3

From project java-cas-client, under directory /cas-client-core/src/test/java/org/jasig/cas/client/authentication/.

Source file: AuthenticationFilterTests.java

  18 
vote

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 arg0,    ServletResponse arg1) throws IOException, ServletException {
    }
  }
;
  request.setSession(session);
  this.filter.doFilter(request,response,filterChain);
  assertEquals(CAS_LOGIN_URL + "?service=" + URLEncoder.encode(CAS_SERVICE_URL,"UTF-8"),response.getRedirectedUrl());
}
 

Example 4

From project jsf-test, under directory /stage/src/main/java/org/jboss/test/faces/staging/.

Source file: FilterContainer.java

  18 
vote

public void execute(ServletRequest request,ServletResponse response) throws ServletException, IOException {
  if (!initialized) {
    throw new IllegalStateException("Filter " + getName() + " have not been initialized, could'n execute request");
  }
  log.finest("Request '" + request + "' executes by the '"+ getName()+ "' filter");
  FilterChain chain=new FilterChain(){
    public void doFilter(    ServletRequest request,    ServletResponse response) throws IOException, ServletException {
      next.execute(request,response);
    }
  }
;
  filter.doFilter(request,response,chain);
}
 

Example 5

From project alfredo, under directory /alfredo/src/test/java/com/cloudera/alfredo/server/.

Source file: TestAuthenticationFilter.java

  17 
vote

public void testDoFilterNotAuthenticated() throws Exception {
  AuthenticationFilter filter=new AuthenticationFilter();
  try {
    FilterConfig config=Mockito.mock(FilterConfig.class);
    Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE)).thenReturn(DummyAuthenticationHandler.class.getName());
    Mockito.when(config.getInitParameterNames()).thenReturn(new Vector(Arrays.asList(AuthenticationFilter.AUTH_TYPE)).elements());
    filter.init(config);
    HttpServletRequest request=Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
    HttpServletResponse response=Mockito.mock(HttpServletResponse.class);
    FilterChain chain=Mockito.mock(FilterChain.class);
    Mockito.doAnswer(new Answer(){
      @Override public Object answer(      InvocationOnMock invocation) throws Throwable {
        fail();
        return null;
      }
    }
).when(chain).doFilter(Mockito.<ServletRequest>anyObject(),Mockito.<ServletResponse>anyObject());
    filter.doFilter(request,response,chain);
    Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
  }
  finally {
    filter.destroy();
  }
}
 

Example 6

From project components-ness-tracking, under directory /src/test/java/com/nesscomputing/tracking/.

Source file: TestLogging.java

  17 
vote

@Test public void testLoggingFromHeader() throws Exception {
  Assert.assertThat(trackingTokenProvider.get().getValue(),is(nullValue()));
  req.addHeader(TrackingFilter.X_NESS_TRACK,value.toString());
  guiceFilter.doFilter(req,res,new FilterChain(){
    @Override public void doFilter(    ServletRequest request,    ServletResponse response) throws IOException, ServletException {
    }
  }
);
  Assert.assertThat(trackingTokenProvider.get().getValue(),is(nullValue()));
}
 

Example 7

From project guice-jit-providers, under directory /extensions/servlet/test/com/google/inject/servlet/.

Source file: ContinuingRequestIntegrationTest.java

  17 
vote

public final void testRequestContinuesInOtherThread() throws ServletException, IOException, InterruptedException {
  executor=Executors.newSingleThreadExecutor();
  injector=Guice.createInjector(new ServletModule(){
    @Override protected void configureServlets(){
      serve("/*").with(ContinuingServlet.class);
      bind(ExecutorService.class).toInstance(executor);
    }
  }
);
  FilterConfig filterConfig=createMock(FilterConfig.class);
  expect(filterConfig.getServletContext()).andReturn(createMock(ServletContext.class));
  GuiceFilter guiceFilter=injector.getInstance(GuiceFilter.class);
  HttpServletRequest request=createMock(HttpServletRequest.class);
  expect(request.getRequestURI()).andReturn("/");
  expect(request.getContextPath()).andReturn("").anyTimes();
  expect(request.getMethod()).andReturn("GET");
  FilterChain filterChain=createMock(FilterChain.class);
  expect(request.getParameter(PARAM_NAME)).andReturn(PARAM_VALUE);
  replay(request,filterConfig,filterChain);
  guiceFilter.init(filterConfig);
  guiceFilter.doFilter(request,null,filterChain);
  executor.shutdown();
  executor.awaitTermination(10,TimeUnit.SECONDS);
  assertEquals(PARAM_VALUE,injector.getInstance(OffRequestCallable.class).value);
  verify(request,filterConfig,filterChain);
}
 

Example 8

From project hoop, under directory /hoop-server/src/test/java/com/cloudera/lib/servlet/.

Source file: TestHostnameFilter.java

  17 
vote

@Test public void hostname() throws Exception {
  ServletRequest request=Mockito.mock(ServletRequest.class);
  Mockito.when(request.getRemoteAddr()).thenReturn("localhost");
  ServletResponse response=Mockito.mock(ServletResponse.class);
  final AtomicBoolean invoked=new AtomicBoolean();
  FilterChain chain=new FilterChain(){
    @Override public void doFilter(    ServletRequest servletRequest,    ServletResponse servletResponse) throws IOException, ServletException {
      Assert.assertEquals(HostnameFilter.get(),"localhost");
      invoked.set(true);
    }
  }
;
  Filter filter=new HostnameFilter();
  filter.init(null);
  Assert.assertNull(HostnameFilter.get());
  filter.doFilter(request,response,chain);
  Assert.assertTrue(invoked.get());
  Assert.assertNull(HostnameFilter.get());
  filter.destroy();
}
 

Example 9

From project jsecurity, under directory /web/src/main/java/org/apache/ki/web/servlet/.

Source file: KiFilter.java

  17 
vote

protected void doFilterInternal(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain origChain) throws ServletException, IOException {
  ServletRequest request=prepareServletRequest(servletRequest,servletResponse,origChain);
  ServletResponse response=prepareServletResponse(request,servletResponse,origChain);
  bind(request,response);
  FilterChain chain=getConfiguration().getChain(request,response,origChain);
  if (chain == null) {
    chain=origChain;
    if (log.isTraceEnabled()) {
      log.trace("No security filter chain configured for the current request.  Using default.");
    }
  }
 else {
    if (log.isTraceEnabled()) {
      log.trace(" Using configured filter chain for the current request.");
    }
  }
  try {
    chain.doFilter(request,response);
  }
  finally {
    unbind(request,response);
  }
}
 

Example 10

From project core_4, under directory /legacy-tests/src/main/java/org/ajax4jsf/tests/.

Source file: AbstractAjax4JsfTestCase.java

  16 
vote

/** 
 * Render test view and parse to htmlunit page structure.
 * @return
 * @throws Exception
 */
protected HtmlPage renderView() throws Exception {
  setupResponseWriter();
  TestXMLFilter filter=new TestXMLFilter();
  try {
    filter.processFilter(new FilterChain(){
      public void doFilter(      ServletRequest request,      ServletResponse response) throws IOException, ServletException {
        response.setContentType("text/html");
        facesContext.setResponseWriter((MockResponseWriter)renderKit.createResponseWriter(response.getWriter(),"text/html",null));
        ViewResources viewResources=new ViewResources();
        viewResources.initialize(facesContext);
        viewResources.setUseStdControlsSkinning(false);
        viewResources.setUseStdControlsSkinningClasses(false);
        renderChild(facesContext,facesContext.getViewRoot());
        viewResources.processHeadResources(facesContext);
        Object[] headEvents=(Object[])viewResources.getHeadEvents();
        request.setAttribute(AjaxContext.HEAD_EVENTS_PARAMETER,headEvents);
        facesContext.setResponseWriter(writer);
      }
    }
,request,response);
  }
 catch (  Exception e) {
    throw e;
  }
  return processResponseWriter();
}
 

Example 11

From project Hesperid, under directory /server/src/main/java/ch/astina/hesperid/web/services/springsecurity/internal/.

Source file: HttpServletRequestFilterWrapper.java

  16 
vote

public final boolean service(final HttpServletRequest request,final HttpServletResponse response,final HttpServletRequestHandler handler) throws IOException {
  final boolean[] res=new boolean[]{true};
  try {
    filter.doFilter(request,response,new FilterChain(){
      public void doFilter(      final ServletRequest request,      final ServletResponse response) throws IOException, ServletException {
        res[0]=handler.service((HttpServletRequest)request,(HttpServletResponse)response);
      }
    }
);
  }
 catch (  ServletException e) {
    IOException ex=new IOException(e.getMessage());
    ex.initCause(e);
    throw ex;
  }
catch (  Throwable e) {
  }
  return res[0];
}
 

Example 12

From project accesointeligente, under directory /src/org/accesointeligente/server/.

Source file: GWTCacheControlFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  String requestURI=httpRequest.getRequestURI();
  if (requestURI.contains(".nocache.")) {
    Date now=new Date();
    HttpServletResponse httpResponse=(HttpServletResponse)response;
    httpResponse.setDateHeader("Date",now.getTime());
    httpResponse.setDateHeader("Expires",now.getTime() - 86400000L);
    httpResponse.setHeader("Pragma","no-cache");
    httpResponse.setHeader("Cache-control","no-cache, no-store, must-revalidate");
  }
  filterChain.doFilter(request,response);
}
 

Example 13

From project AdServing, under directory /modules/server/adserver/src/main/java/net/mad/ads/server/utils/http/listener/.

Source file: AdContextListener.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest req=(HttpServletRequest)request;
  HttpServletResponse res=(HttpServletResponse)response;
  AdContext context=AdContextHelper.getAdContext(req,res);
  ADCONTEXT.set(context);
  chain.doFilter(request,response);
  ADCONTEXT.remove();
}
 

Example 14

From project aerogear-controller, under directory /src/main/java/org/jboss/aerogear/controller/router/.

Source file: DefaultRouter.java

  15 
vote

@Override public void dispatch(HttpServletRequest request,HttpServletResponse response,FilterChain chain) throws ServletException {
  try {
    final String requestPath=extractPath(request);
    Route route=routes.routeFor(extractMethod(request),requestPath);
    Object[] params;
    if (route.isSecured()) {
      securityProvider.isRouteAllowed(route);
    }
    if (route.isParameterized()) {
      params=extractPathParameters(requestPath,route);
    }
 else {
      params=extractParameters(request,route);
    }
    Object result=route.getTargetMethod().invoke(getController(route),params);
    String viewPath=viewResolver.resolveViewPathFor(route);
    View view=new View(viewPath,result);
    if (view.hasModelData()) {
      request.setAttribute(view.getModelName(),view.getModel());
    }
    request.getRequestDispatcher(view.getViewPath()).forward(request,response);
  }
 catch (  Exception e) {
    if (e instanceof HttpStatusAwareException) {
      response.setStatus(((HttpStatusAwareException)e).getStatus());
    }
    final Throwable rootCause=Throwables.getRootCause(e);
    final Route errorRoute=routes.routeFor(rootCause);
    invokeErrorRoute(errorRoute,rootCause);
    forwardErrorToView(errorRoute,rootCause,request,response);
  }
}
 

Example 15

From project aio-webos, under directory /webui/webos/src/main/java/org/exoplatform/webos/common/filter/.

Source file: LazyDesktopPageCreation.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  String userName=httpRequest.getRemoteUser();
  try {
    ExoContainer container=ExoContainerContext.getCurrentContainer();
    RequestLifeCycle.begin(container);
    if (userName != null) {
      try {
        Class.forName(UIDesktopPage.class.getName());
      }
 catch (      ClassNotFoundException e) {
        throw new ServletException(e);
      }
      createPortalConfig(container,userName);
      createUserPage(container,userName);
    }
  }
 catch (  Throwable t) {
    log.debug("Could not create User Portal Config or User Desktop Page for " + userName,t);
  }
 finally {
    chain.doFilter(httpRequest,response);
    RequestLifeCycle.end();
  }
}
 

Example 16

From project airlift, under directory /http-server/src/main/java/io/airlift/http/server/.

Source file: GZipRequestFilter.java

  15 
vote

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)servletRequest;
  HttpServletResponse response=(HttpServletResponse)servletResponse;
  String contentEncoding=request.getHeader("content-encoding");
  if (equalsIgnoreCase(contentEncoding,"gzip")) {
    filterChain.doFilter(new GZipRequestWrapper(request),servletResponse);
  }
 else {
    filterChain.doFilter(request,response);
  }
}
 

Example 17

From project ajah, under directory /ajah-event-http/src/main/java/com/ajah/log/http/servlet/filter/.

Source file: AccessLoggerFilter.java

  15 
vote

/** 
 * Logs requests.
 */
@Override public void doFilter(final HttpServletRequest request,final HttpServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final RequestEvent requestEvent=new RequestEvent(request);
  request.setAttribute("ajahRequestEvent",requestEvent);
  try {
    chain.doFilter(request,response);
  }
  finally {
    requestEvent.complete();
    if (isLoggable(request)) {
      log.finest(requestEvent.getUri() + " took " + requestEvent.getDuration()+ "ms");
      AjahUtils.requireParam(this.taskExecutor,"taskExecutor");
      this.taskExecutor.execute(new RequestEventHandler(requestEvent,this.requestEventManager));
    }
  }
}
 

Example 18

From project alphaportal_dev, under directory /sys-src/alphaportal/web/src/main/java/alpha/portal/webapp/filter/.

Source file: LocaleFilter.java

  15 
vote

/** 
 * This method looks for a "locale" request parameter. If it finds one, it sets it as the preferred locale and also configures it to work with JSTL.
 * @param request the current request
 * @param response the current response
 * @param chain the chain
 * @throws IOException when something goes wrong
 * @throws ServletException when a communication failure happens
 */
@Override @SuppressWarnings("unchecked") public void doFilterInternal(HttpServletRequest request,final HttpServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final String locale=request.getParameter("locale");
  Locale preferredLocale=null;
  if (locale != null) {
    final int indexOfUnderscore=locale.indexOf('_');
    if (indexOfUnderscore != -1) {
      final String language=locale.substring(0,indexOfUnderscore);
      final String country=locale.substring(indexOfUnderscore + 1);
      preferredLocale=new Locale(language,country);
    }
 else {
      preferredLocale=new Locale(locale);
    }
  }
  final HttpSession session=request.getSession(false);
  if (session != null) {
    if (preferredLocale == null) {
      preferredLocale=(Locale)session.getAttribute(Constants.PREFERRED_LOCALE_KEY);
    }
 else {
      session.setAttribute(Constants.PREFERRED_LOCALE_KEY,preferredLocale);
      Config.set(session,Config.FMT_LOCALE,preferredLocale);
    }
    if ((preferredLocale != null) && !(request instanceof LocaleRequestWrapper)) {
      request=new LocaleRequestWrapper(request,preferredLocale);
      LocaleContextHolder.setLocale(preferredLocale);
    }
  }
  final String theme=request.getParameter("theme");
  if ((theme != null) && request.isUserInRole(Constants.ADMIN_ROLE)) {
    final Map<String,Object> config=(Map)this.getServletContext().getAttribute(Constants.CONFIG);
    config.put(Constants.CSS_THEME,theme);
  }
  chain.doFilter(request,response);
  LocaleContextHolder.setLocaleContext(null);
}
 

Example 19

From project aranea, under directory /server/src/main/java/no/dusken/aranea/ehcache/.

Source file: ExcludablePageCachingFilter.java

  15 
vote

@Override protected PageInfo buildPageInfo(HttpServletRequest request,HttpServletResponse response,FilterChain chain) throws Exception {
  String url=request.getRequestURI() + request.getQueryString();
  if (shouldExclude(url,excludeRegexps)) {
    return buildPage(request,response,chain);
  }
 else   if (shouldExclude(url,forward)) {
    chain.doFilter(request,response);
    return null;
  }
 else {
    return super.buildPageInfo(request,response,chain);
  }
}
 

Example 20

From project arquillian-extension-warp, under directory /impl/src/main/java/org/jboss/arquillian/warp/impl/server/execution/.

Source file: HttpRequestProcessor.java

  15 
vote

public void processHttpRequest(@Observes ProcessHttpRequest event,ServiceLoader services,HttpServletRequest request,HttpServletResponse response,FilterChain filterChain) throws IOException, ServletException {
  HttpRequestDeenricher requestDeenricher=services.onlyOne(HttpRequestDeenricher.class);
  if (requestDeenricher.isEnriched()) {
    responsePayload.set(new ResponsePayload());
    requestPayload.set(requestDeenricher.resolvePayload());
    processWarpRequest.fire(new ProcessWarpRequest());
  }
 else {
    filterChain.doFilter(request,response);
  }
}
 

Example 21

From project azure-sdk-for-java-samples, under directory /WAAD.WebSSO.JAVA/java/code/samples/sample/src/main/java/.

Source file: FederationFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (request instanceof HttpServletRequest) {
    HttpServletRequest httpRequest=(HttpServletRequest)request;
    if (!httpRequest.getRequestURL().toString().contains(this.loginPage)) {
      ConfigurableFederatedLoginManager loginManager=ConfigurableFederatedLoginManager.fromRequest(httpRequest);
      boolean allowedUrl=Pattern.compile(this.allowedRegex).matcher(httpRequest.getRequestURL().toString()).find();
      if (!allowedUrl && !loginManager.isAuthenticated()) {
        HttpServletResponse httpResponse=(HttpServletResponse)response;
        String encodedReturnUrl=URLUTF8Encoder.encode(httpRequest.getRequestURL().toString());
        httpResponse.setHeader("Location",this.loginPage + "?returnUrl=" + encodedReturnUrl);
        httpResponse.setStatus(302);
        return;
      }
    }
  }
  chain.doFilter(request,response);
}
 

Example 22

From project azure4j-blog-samples, under directory /ACSExample/src/com/persistent/azure/acs/filter/.

Source file: AuthorizationFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  String acsToken=httpServletRequest.getParameter("wresult");
  if (null != acsToken && acsToken.trim().length() == 0) {
    acsToken=null;
  }
  if (!(httpServletRequest.getRequestURI().contains("claims.do") && acsToken != null)) {
    Cookie[] cookies=httpServletRequest.getCookies();
    Cookie currentCookie=null;
    String cookieName=resourceBundle.getString("acs.cookie.name");
    if (cookies != null && cookies.length > 0) {
      for (      Cookie c : cookies) {
        if (cookieName.equals(c.getName())) {
          currentCookie=c;
          break;
        }
      }
    }
    if (currentCookie == null) {
      StringBuffer loginURL=new StringBuffer();
      loginURL.append(resourceBundle.getString("acs.url"));
      loginURL.append("/v2/wsfederation?wa=wsignin1.0&wtrealm=");
      loginURL.append(resourceBundle.getString("acs.realm"));
      httpServletResponse.sendRedirect(loginURL.toString());
    }
 else {
      chain.doFilter(request,response);
    }
  }
 else {
    chain.doFilter(request,response);
  }
}
 

Example 23

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/servlet/filter/.

Source file: AbstractGZIPFilter.java

  15 
vote

/** 
 * Wraps the http servlet response with GZIP if could.
 * @param request the specified request
 * @param response the specified response
 * @param chain filter chain
 * @throws IOException io exception
 * @throws ServletException servlet exception
 */
@Override public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  final String requestURI=httpServletRequest.getRequestURI();
  if (shouldSkip(requestURI)) {
    LOGGER.log(Level.FINEST,"Skip GZIP filter request[URI={0}]",requestURI);
    chain.doFilter(request,response);
    return;
  }
  final String acceptEncoding=httpServletRequest.getHeader("Accept-Encoding");
  boolean supportGZIP=false;
  if (null != acceptEncoding && 0 <= acceptEncoding.indexOf("gzip")) {
    supportGZIP=true;
  }
  if (!supportGZIP) {
    LOGGER.info("Gzip NOT be supported");
    chain.doFilter(request,response);
    return;
  }
  final HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  httpServletResponse.addHeader("Content-Encoding","gzip");
  httpServletResponse.addHeader("Vary","Accept-Encoding");
  chain.doFilter(request,new GZIPServletResponseWrapper(httpServletResponse));
}
 

Example 24

From project b3log-solo, under directory /core/src/main/java/org/b3log/solo/filter/.

Source file: AuthFilter.java

  15 
vote

/** 
 * If the specified request is NOT made by an authenticated user, sends  error 403.
 * @param request the specified request
 * @param response the specified response
 * @param chain filter chain
 * @throws IOException io exception
 * @throws ServletException servlet exception
 */
@Override public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain chain) throws IOException, ServletException {
  final HttpServletResponse httpServletResponse=(HttpServletResponse)response;
  final HttpServletRequest httpServletRequest=(HttpServletRequest)request;
  try {
    LoginProcessor.tryLogInWithCookie(httpServletRequest,httpServletResponse);
    final GeneralUser currentUser=userService.getCurrentUser(httpServletRequest);
    if (null == currentUser) {
      LOGGER.warning("The request has been forbidden");
      httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
      return;
    }
    final String currentUserEmail=currentUser.getEmail();
    LOGGER.log(Level.FINER,"Current user email[{0}]",currentUserEmail);
    if (users.isSoloUser(currentUserEmail)) {
      chain.doFilter(request,response);
      return;
    }
    LOGGER.warning("The request has been forbidden");
    httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
  }
 catch (  final Exception e) {
    httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
  }
}
 

Example 25

From project Blitz, under directory /src/com/laxser/blitz/.

Source file: BlitzFilter.java

  15 
vote

/** 
 * ???????? BlitzFilter ???????????????????????????????????????????????????????????????? ????????????????????litz??????????????????????????????eb?????????????????
 */
@Override public void doFilter(ServletRequest request,final ServletResponse response,final FilterChain filterChain) throws IOException, ServletException {
  final HttpServletRequest httpRequest=(HttpServletRequest)request;
  final HttpServletResponse httpResponse=(HttpServletResponse)response;
  if (logger.isDebugEnabled()) {
    StringBuffer sb=httpRequest.getRequestURL();
    String query=httpRequest.getQueryString();
    if (query != null && query.length() > 0) {
      sb.append("?").append(query);
    }
    logger.debug(httpRequest.getMethod() + " " + sb.toString());
  }
  supportsBlitzpipe(httpRequest);
  final RequestPath requestPath=new RequestPath(httpRequest);
  if (quicklyPass(requestPath)) {
    notMatched(filterChain,httpRequest,httpResponse,requestPath);
    return;
  }
  boolean matched=false;
  try {
    final Blitz Blitz=new Blitz(modules,mappingTree,httpRequest,httpResponse,requestPath);
    matched=Blitz.start();
  }
 catch (  Throwable exception) {
    throwServletException(requestPath,exception);
  }
  if (!matched) {
    notMatched(filterChain,httpRequest,httpResponse,requestPath);
  }
}
 

Example 26

From project CalendarPortlet, under directory /src/main/java/org/jasig/portlet/calendar/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 27

From project CampusLifePortlets, under directory /src/main/java/org/jasig/portlet/campuslife/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 28

From project capedwarf-blue, under directory /appidentity/src/main/java/org/jboss/capedwarf/appidentity/.

Source file: GAEFilter.java

  15 
vote

public void doFilter(ServletRequest req,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=new CapedwarfHttpServletRequestWrapper((HttpServletRequest)req);
  ApiProxy.Delegate previous=ApiProxy.getDelegate();
  JBossDelegate delegate=JBossDelegate.INSTANCE;
  ApiProxy.setDelegate(delegate);
  try {
    delegate.addRequest(req);
    chain.doFilter(request,response);
  }
  finally {
    delegate.removeRequest();
    ApiProxy.setDelegate(previous);
  }
}
 

Example 29

From project Carolina-Digital-Repository, under directory /access-security/src/main/java/edu/unc/lib/dl/security/access/.

Source file: SpoofShibbolethHeadersFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (request instanceof HttpServletRequest) {
    String members=(String)((HttpServletRequest)request).getHeader("isMemberOf");
    LOG.debug("Unspoofed isMemberOf: " + members);
    if (!(((HttpServletRequest)request).getServletPath().startsWith("/js/") || ((HttpServletRequest)request).getServletPath().startsWith("/css/") || ((HttpServletRequest)request).getServletPath().startsWith("/images/"))) {
      request=new javax.servlet.http.HttpServletRequestWrapper((HttpServletRequest)request){
        @Override public String getHeader(        String name){
          if ("isMemberOf".equals(name)) {
            return isMemberOfHeader;
          }
 else {
            return super.getHeader(name);
          }
        }
        @Override public String getRemoteUser(){
          return remoteUser;
        }
      }
;
      LOG.warn("SpoofShibbolethHeadersFilter: remoteUser = " + remoteUser);
      LOG.warn("SpoofShibbolethHeadersFilter: isMemberOf header = " + isMemberOfHeader);
    }
    chain.doFilter(request,response);
  }
 else {
    throw new RuntimeException("Not an HTTP request.");
  }
}
 

Example 30

From project Coffee-Framework, under directory /coffeeframework-core/src/main/java/coffee/servlet/.

Source file: CoffeeFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  CoffeeRequestContext coffeeContext=Cafeteria.createRequestContext(request,response,filterConfig.getServletContext());
  try {
    if (renderTheWebPageAsXHTML(coffeeContext))     return;
    Object instance=lookupCoffeeResource(coffeeContext);
    if (instance == null) {
      chain.doFilter(request,response);
      return;
    }
    runWebResource(coffeeContext,instance);
  }
 catch (  Exception e) {
    throw new ServletException(e.getMessage(),e);
  }
}
 

Example 31

From project com.idega.content, under directory /src/java/com/idega/content/filter/.

Source file: ContentDispatcher.java

  15 
vote

public void doFilter(ServletRequest srequest,ServletResponse sresponse,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)srequest;
  String jackrabbitBasePath="/repository/default";
  if (contentRepository.equals(CONTENT_REPOSITORY_JACKRABBIT)) {
    String url=getURIMinusContextPath(request);
    String newUrl=jackrabbitBasePath + url;
    RequestDispatcher dispatcher=request.getRequestDispatcher(newUrl);
    dispatcher.include(srequest,sresponse);
  }
 else {
    chain.doFilter(srequest,sresponse);
  }
}
 

Example 32

From project cometd, under directory /cometd-java/cometd-java-server/src/test/java/org/cometd/server/.

Source file: SlowConnectionTest.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  try {
    chain.doFilter(request,response);
  }
 catch (  EofException x) {
    exceptionLatch.countDown();
    throw x;
  }
}
 

Example 33

From project ConferenceProgramPortlet, under directory /src/main/java/org/jasig/portlet/conference/program/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 34

From project conversation, under directory /spi/src/test/java/org/jboss/seam/conversation/support/.

Source file: RealTestFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  String cid=request.getParameter("cid");
  System.err.println("Testing ..." + cid + ", sessionId = "+ ((HttpServletRequest)request).getSession().getId());
  Assert.assertNotNull(bean);
  Conversation conversation=bean.getConversation();
  Assert.assertNotNull(conversation);
  if (cid == null) {
    conversation.begin(cId);
  }
 else {
    Assert.assertEquals(cId,conversation.getId());
  }
  try {
    chain.doFilter(request,response);
  }
  finally {
    if (cid != null)     conversation.end();
  }
}
 

Example 35

From project core_5, under directory /exo.core.component.security.core/src/main/java/org/exoplatform/services/security/j2ee/websphere/.

Source file: WebsphereFilter.java

  15 
vote

/** 
 * Do filter. Remove ltpa token cookie when we are going on public context, nothing to do otherwise.
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  HttpServletResponse httpResponse=(HttpServletResponse)response;
  if (httpRequest.getQueryString() == null && httpRequest.getRequestURI() != null && httpRequest.getRequestURI().contains("/public")) {
    removeLtpaTokenCookie(httpRequest,httpResponse);
  }
 else   if (httpRequest.getQueryString() != null && httpRequest.getQueryString().contains("UIPortalComponentLogin") && httpRequest.getRequestURI() != null && httpRequest.getRequestURI().contains("/public")) {
    removeLtpaTokenCookie(httpRequest,httpResponse);
  }
  chain.doFilter(request,response);
}
 

Example 36

From project Cours-3eme-ann-e, under directory /Java/tomcat/examples/WEB-INF/classes/filters/.

Source file: ExampleFilter.java

  15 
vote

/** 
 * Time the processing that is performed by all subsequent filters in the current filter stack, including the ultimately invoked servlet.
 * @param request The servlet request we are processing
 * @param result The servlet response we are creating
 * @param chain The filter chain we are processing
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet error occurs
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (attribute != null)   request.setAttribute(attribute,this);
  long startTime=System.currentTimeMillis();
  chain.doFilter(request,response);
  long stopTime=System.currentTimeMillis();
  filterConfig.getServletContext().log(this.toString() + ": " + (stopTime - startTime)+ " milliseconds");
}
 

Example 37

From project cxf-dosgi, under directory /samples/security_filter/src/main/java/org/apache/cxf/dosgi/samples/security/.

Source file: SampleSecurityFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if ("secure".equals(((HttpServletRequest)request).getQueryString())) {
    LOG.info("Access granted");
    chain.doFilter(request,response);
  }
 else {
    LOG.warning("Access denied");
    ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN);
  }
}
 

Example 38

From project demoiselle-contrib, under directory /demoiselle-fuselage/src/main/java/br/gov/frameworkdemoiselle/fuselage/filter/.

Source file: AuthorizerURL.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (!config.isWebfilterEnabled()) {
    chain.doFilter(request,response);
    return;
  }
  this.request=(HttpServletRequest)request;
  String url=this.request.getRequestURI().replaceAll("^/.+?/","/");
  if (isPublicURL(url) || hasPermission(url))   chain.doFilter(request,response);
 else   redirect(response,getContext() + config.getLoginPage());
}
 

Example 39

From project dev-examples, under directory /misc-demo/src/main/java/org/richfaces/demo/.

Source file: TestIdentityFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequestWrapper wrapper=new HttpServletRequestWrapper((HttpServletRequest)request){
    private UserBean getUserBean(){
      HttpSession session=getSession(false);
      if (session != null) {
        return (UserBean)session.getAttribute("userBean");
      }
      return null;
    }
    @Override public boolean isUserInRole(    String role){
      UserBean userBean=getUserBean();
      if (userBean != null) {
        return userBean.isUserInRole(role);
      }
      return false;
    }
    @Override public Principal getUserPrincipal(){
      UserBean userBean=getUserBean();
      if (userBean != null) {
        return userBean.getPrincipal();
      }
      return null;
    }
    @Override public String getRemoteUser(){
      UserBean userBean=getUserBean();
      if (userBean != null) {
        return userBean.getRolename();
      }
      return null;
    }
  }
;
  chain.doFilter(wrapper,response);
}
 

Example 40

From project dolphin, under directory /dolphinmaple/src/com/tan/filter/.

Source file: EncodingFilter.java

  15 
vote

public final void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  if (encoding != null) {
    req.setCharacterEncoding(encoding);
  }
  chain.doFilter(req,res);
}
 

Example 41

From project EasySOA, under directory /easysoa-registry/easysoa-registry-rest-miner/src/main/java/org/easysoa/records/filters/.

Source file: ExchangeRecordServletFilterImpl.java

  15 
vote

/** 
 * Process the filter 
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (exchangeHandler != null) {
    logger.info("Filtering a EasySOA API request");
    if (!(request instanceof CopyHttpServletResponse)) {
      request=new CopyHttpServletRequest((HttpServletRequest)request);
    }
    if (!(response instanceof CopyHttpServletResponse)) {
      response=new CopyHttpServletResponse((HttpServletResponse)response);
    }
  }
  chain.doFilter(request,response);
  if (exchangeHandler != null) {
    if (request instanceof HttpServletRequest) {
      try {
        InMessage inMessage=new InMessage((CopyHttpServletRequest)request);
        OutMessage outMessage=new OutMessage((CopyHttpServletResponse)response);
        this.exchangeHandler.handleMessage(inMessage,outMessage);
      }
 catch (      Exception e) {
        logger.error("An error occurred during the exchange handling",e);
      }
    }
  }
}
 

Example 42

From project exo-training, under directory /gxt-showcase/src/main/java/com/sencha/gxt/examples/resources/server/.

Source file: EntityManagerFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  EntityManager em=null;
  try {
    em=factory.createEntityManager();
    EntityManagerUtil.MANAGERS.set(em);
    chain.doFilter(request,response);
    EntityManagerUtil.MANAGERS.remove();
  }
  finally {
    try {
      if (em != null)       em.close();
    }
 catch (    Throwable t) {
      t.printStackTrace();
    }
  }
}
 

Example 43

From project flip, under directory /servlet/src/test/java/com/tacitknowledge/flip/servlet/.

Source file: FlipOverrideFilterTest.java

  15 
vote

@Before public void setUp() throws IOException, ServletException {
  filter=new FlipOverrideFilter();
  request=mock(HttpServletRequest.class);
  response=mock(HttpServletResponse.class);
  filterChain=mock(FilterChain.class);
}
 

Example 44

From project gatein-sso, under directory /agent/src/main/java/org/gatein/sso/agent/filter/.

Source file: AbstractLogoutFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpRequest=(HttpServletRequest)request;
  HttpServletResponse httpResponse=(HttpServletResponse)response;
  boolean isLogoutInProgress=this.isLogoutInProgress(httpRequest);
  if (isLogoutInProgress) {
    if (httpRequest.getSession().getAttribute("SSO_LOGOUT_FLAG") == null) {
      httpRequest.getSession().setAttribute("SSO_LOGOUT_FLAG",Boolean.TRUE);
      String redirectUrl=this.getRedirectUrl(httpRequest);
      redirectUrl=httpResponse.encodeRedirectURL(redirectUrl);
      httpResponse.sendRedirect(redirectUrl);
      return;
    }
 else {
      httpRequest.getSession().removeAttribute("SSO_LOGOUT_FLAG");
    }
  }
  chain.doFilter(request,response);
}
 

Example 45

From project gatein-toolbox, under directory /CoreOrganizationInitializer/src/main/java/org/exoplatform/core/component/organization/initializer/.

Source file: TriggerInitializerFilter.java

  15 
vote

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  if (log.isTraceEnabled()) {
    log.trace("filter in progress. checkFolders=" + checkFolders + ", TriggerListenersForGroups="+ triggerListenersForGroups);
  }
  HttpServletRequest httpServletRequest=(HttpServletRequest)servletRequest;
  if (httpServletRequest.getRemoteUser() != null && httpServletRequest.getSession().getAttribute(ATTR_FLAG_NAME) == null) {
    ExoContainer container=ExoContainerContext.getCurrentContainer();
    OrganizationListenersInitializerService initializer=(OrganizationListenersInitializerService)container.getComponentInstanceOfType(OrganizationListenersInitializerService.class);
    OrganizationService orgService=(OrganizationService)container.getComponentInstanceOfType(OrganizationService.class);
    RequestLifeCycle.begin(container);
    try {
      String username=httpServletRequest.getRemoteUser();
      User user=orgService.getUserHandler().findUserByName(username);
      initializer.treatUser(user,checkFolders);
      if (triggerListenersForGroups) {
        Collection<Group> groups=orgService.getGroupHandler().findGroupsOfUser(username);
        for (        Group group : groups) {
          initializer.treatGroup(group,checkFolders);
        }
      }
      httpServletRequest.getSession().setAttribute(ATTR_FLAG_NAME,"true");
    }
 catch (    Exception e) {
      log.error("Error occured in TriggerInitializerFilter",e);
    }
 finally {
      RequestLifeCycle.end();
    }
  }
  filterChain.doFilter(servletRequest,servletResponse);
}
 

Example 46

From project gengweibo, under directory /src/com/gengweibo/web/.

Source file: SessionFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filter) throws IOException, ServletException {
  String api=request.getParameter("api");
  if (null == api) {
    String queryString=((HttpServletRequest)request).getQueryString();
    if (queryString.length() > 0) {
      Pattern pattern=Pattern.compile("(\\?|&){0,1}api=(.*?)&{0,1}");
      Matcher matcher=pattern.matcher(queryString);
      if (matcher.matches() && matcher.groupCount() >= 2) {
        api=matcher.group(2);
      }
    }
  }
  if (null != api && !"link".equalsIgnoreCase(api) && !"logout".equalsIgnoreCase(api) && !"flush".equalsIgnoreCase(api) && null == ((HttpServletRequest)request).getSession().getAttribute(Account.ACCOUNT_SESSION_KEY)) {
    ((HttpServletResponse)response).sendRedirect(((HttpServletRequest)request).getContextPath() + "/error.jsp?desc=UnLogin");
    return;
  }
  filter.doFilter(request,response);
}
 

Example 47

From project gmc, under directory /src/org.gluster.storage.management.gateway/src/org/gluster/storage/management/gateway/filters/.

Source file: AuthenticationFailureFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)req;
  if (request.getRequestURI().contains("download")) {
    chain.doFilter(req,res);
    return;
  }
  CharResponseWrapper wrapper=new CharResponseWrapper((HttpServletResponse)res);
  chain.doFilter(req,wrapper);
  if (wrapper.getStatus() == Response.Status.UNAUTHORIZED.ordinal()) {
    PrintWriter out=res.getWriter();
    out.println("<status><code>1</code><message>Authentication Failed!</message></status>");
  }
}
 

Example 48

From project GNDMS, under directory /gndms/src/de/zib/gndms/gndms/security/.

Source file: LocalRequestSkippingChannelProcessingFilter.java

  15 
vote

@Override public void doFilter(final ServletRequest req,final ServletResponse res,final FilterChain chain) throws IOException, ServletException {
  final String remoteAddr=req.getRemoteAddr();
  logger.info("request from: " + remoteAddr);
  if (remoteAddr.equals(req.getLocalAddr()))   chain.doFilter(req,res);
 else   super.doFilter(req,res,chain);
}
 

Example 49

From project Guit, under directory /src/main/java/com/guit/server/crawling/.

Source file: CrawlingFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest r=(HttpServletRequest)request;
  String query=r.getQueryString();
  if (query == null || !query.contains("_escaped_fragment_=")) {
    chain.doFilter(request,response);
  }
 else {
    String reqUrl=r.getRequestURL().toString();
    String queryString=r.getQueryString();
    if (queryString != null) {
      reqUrl+="?" + queryString;
    }
    URL fetchUrl=new URL(snapshootService + "/ajaxcrawler?url=" + URLEncoder.encode(reqUrl,"UTF-8"));
    response.setContentType("text/html");
    response.setCharacterEncoding("ISO-8859-1");
    ServletOutputStream out=response.getOutputStream();
    InputStream in=fetchUrl(fetchUrl);
    if (in == null) {
      out.print("<html><head></head><body></body></html>");
      return;
    }
    final byte[] bytes=new byte[4096];
    int bytesRead=in.read(bytes);
    while (bytesRead > -1) {
      out.write(bytes,0,bytesRead);
      bytesRead=in.read(bytes);
    }
  }
}
 

Example 50

From project guj.com.br, under directory /src/br/com/caelum/guj/vraptor/filter/.

Source file: BookmarkableURIFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)req;
  HttpServletResponse response=(HttpServletResponse)res;
  ConverterMatcher converters=new ConverterMatcher(AllBookmarkableToCompatibleConverters.get(request.getRequestURI()));
  if (converters.oneMatched()) {
    String compatibleURI=converters.getConverter().convert();
    if (converters.shortBookmarkableURI()) {
      redirectUsingCache(request,response,compatibleURI);
    }
 else {
      setRequestAttributesToCanonicalLink(request,converters);
      request.getRequestDispatcher(compatibleURI).forward(request,response);
    }
  }
 else {
    chain.doFilter(request,response);
  }
}
 

Example 51

From project hadoop_framework, under directory /webapp/src/main/java/org/sleuthkit/web/sampleapp/server/.

Source file: SecurityFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  boolean authorized=false;
  HttpSession session=((HttpServletRequest)req).getSession();
  String authVal=(String)session.getAttribute("SAMPLE_GWT_AUTH");
  if (authVal != null)   authorized=authVal.equals("y");
  if (authorized) {
    chain.doFilter(req,res);
  }
 else {
    String username=req.getParameter("username");
    String password=req.getParameter("password");
    if (username != null && password != null) {
      if (checkCredentials(username,password)) {
        session.setAttribute("SAMPLE_GWT_AUTH","y");
        session.setMaxInactiveInterval(SESSION_TIMEOUT * 60);
        ((HttpServletResponse)res).sendRedirect("/sampleapp/SampleApp.jsp");
      }
 else {
        String loginUrl="/sampleapp/login.jsp?failed=true";
        ((HttpServletResponse)res).sendRedirect(loginUrl);
      }
    }
 else {
      String loginUrl="/sampleapp/login.jsp";
      ((HttpServletResponse)res).sendRedirect(loginUrl);
    }
  }
}
 

Example 52

From project harmony, under directory /harmony.common.serviceinterface/src/main/java/org/opennaas/extensions/idb/serviceinterface/utils/.

Source file: CommonServletFilter.java

  15 
vote

@Override public void doFilter(final ServletRequest arg0,final ServletResponse arg1,final FilterChain arg2) throws IOException, ServletException {
  if (null != this.servletFiler) {
    this.servletFiler.doFilter(arg0,arg1,arg2);
  }
 else {
    arg2.doFilter(arg0,arg1);
  }
}
 

Example 53

From project httpobjects, under directory /servlet/src/main/java/org/httpobjects/servlet/.

Source file: ServletFilter.java

  15 
vote

@Override public void doFilter(ServletRequest basicRequest,ServletResponse basicResponse,FilterChain chain) throws IOException, ServletException {
  final HttpServletRequest request=(HttpServletRequest)basicRequest;
  final HttpServletResponse response=(HttpServletResponse)basicResponse;
  final String path=request.getRequestURI();
  final boolean invocationHappened=invoker().invokeFirstPathMatchIfAble(path,request,response);
  if (!invocationHappened) {
    chain.doFilter(basicRequest,basicResponse);
  }
}
 

Example 54

From project https-utils, under directory /src/main/java/org/italiangrid/utils/https/.

Source file: PasswordProtectFilter.java

  15 
vote

/** 
 * {@inheritDoc} 
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  String password=Strings.safeTrimOrNullString(request.getParameter(PASSWORD_PARAM_NAME));
  if (requestPassword != null && !requestPassword.equals(password)) {
    ((HttpServletResponse)response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return;
  }
  chain.doFilter(request,response);
}
 

Example 55

From project huiswerk, under directory /print/zxing-1.6/zxingorg/src/com/google/zxing/web/.

Source file: DoSFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (isBanned(request)) {
    HttpServletResponse servletResponse=(HttpServletResponse)response;
    servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
  }
 else {
    chain.doFilter(request,response);
  }
}
 

Example 56

From project iJetty, under directory /console/webapp/src/main/java/org/mortbay/ijetty/console/.

Source file: CacheFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  try {
    HttpServletRequest httpRequest=(HttpServletRequest)request;
    ((HttpServletResponse)response).setHeader("Cache-Control","no-store");
  }
  finally {
    chain.doFilter(request,response);
  }
}
 

Example 57

From project inspektr, under directory /inspektr-common/src/main/java/com/github/inspektr/common/web/.

Source file: ClientInfoThreadLocalFilter.java

  15 
vote

public void doFilter(final ServletRequest request,final ServletResponse response,final FilterChain filterChain) throws IOException, ServletException {
  try {
    final ClientInfo clientInfo;
    if (otherHeader == null || otherHeader.isEmpty()) {
      clientInfo=new ClientInfo((HttpServletRequest)request);
    }
 else {
      clientInfo=new ClientInfo((HttpServletRequest)request,this.otherHeader);
    }
    ClientInfoHolder.setClientInfo(clientInfo);
    filterChain.doFilter(request,response);
  }
  finally {
    ClientInfoHolder.clear();
  }
}
 

Example 58

From project ipdburt, under directory /iddb-web/src/main/java/iddb/web/security/service/.

Source file: UserServiceFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletResponse resp=(HttpServletResponse)response;
  HttpServletRequest req=(HttpServletRequest)request;
  CommonUserService service=(CommonUserService)UserServiceFactory.getUserService();
  Subject s=service.findUserSession(req);
  if (s == null) {
    log.debug("No authenticated session found");
    service.cleanUp();
    s=new AnonymousSubject();
  }
  if (haveAccess(s,(HttpServletRequest)request,resp)) {
    try {
      chain.doFilter(request,response);
    }
  finally {
      service.cleanUp();
    }
  }
}
 

Example 59

From project jBilling, under directory /src/java/com/sapienter/jbilling/client/authentication/.

Source file: StaticAuthenticationFilter.java

  15 
vote

/** 
 * Perform authentication using the configured username and password. This filter does not allow anonymous authentication. If a user is already logged in anonymously (if the filter chain puts anonymous authentication before this filter), the token will be removed and a real authentication attempt will be made.
 * @param req servlet request
 * @param res servlet response
 * @param chain filter chain
 * @throws IOException
 * @throws ServletException
 */
public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  final HttpServletRequest request=(HttpServletRequest)req;
  final HttpServletResponse response=(HttpServletResponse)res;
  String username=getUsername() != null ? getUsername().trim() : "";
  String password=getPassword() != null ? getPassword() : "";
  if (isAuthenticationRequired(username)) {
    UsernamePasswordAuthenticationToken authRequest=new UsernamePasswordAuthenticationToken(username,password);
    authRequest.setDetails(getAuthenticationDetailsSource().buildDetails(request));
    Authentication authResult;
    try {
      authResult=getAuthenticationManager().authenticate(authRequest);
    }
 catch (    AuthenticationException failed) {
      SecurityContextHolder.getContext().setAuthentication(null);
      getRememberMeServices().loginFail(request,response);
      getAuthenticationEntryPoint().commence(request,response,failed);
      return;
    }
    SecurityContextHolder.getContext().setAuthentication(authResult);
    getRememberMeServices().loginSuccess(request,response,authResult);
  }
  chain.doFilter(request,response);
}
 

Example 60

From project jboss-as-quickstart, under directory /kitchensink-html5-mobile/src/main/java/org/jboss/as/quickstarts/html5_mobile/util/.

Source file: JSONPRequestFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (!(request instanceof HttpServletRequest)) {
    throw new ServletException("Only HttpServletRequest requests are supported");
  }
  final HttpServletRequest httpRequest=(HttpServletRequest)request;
  final HttpServletResponse httpResponse=(HttpServletResponse)response;
  String callback=getCallbackMethod(httpRequest);
  if (!isJSONPRequest(callback)) {
    chain.doFilter(request,response);
  }
 else {
    if (!SAFE_PRN.matcher(callback).matches()) {
      throw new ServletException("JSONP Callback method '" + CALLBACK_METHOD + "' parameter not valid function");
    }
    final ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
    HttpServletResponseWrapper responseWrapper=new HttpServletResponseWrapper(httpResponse){
      @Override public ServletOutputStream getOutputStream() throws IOException {
        return new ServletOutputStream(){
          @Override public void write(          int b) throws IOException {
            byteStream.write(b);
          }
        }
;
      }
      @Override public PrintWriter getWriter() throws IOException {
        return new PrintWriter(byteStream);
      }
    }
;
    chain.doFilter(request,responseWrapper);
    response.setContentType(CONTENT_TYPE);
    response.setCharacterEncoding("UTF-8");
    response.getOutputStream().write((callback + "(").getBytes());
    response.getOutputStream().write(byteStream.toByteArray());
    response.getOutputStream().write(");".getBytes());
  }
}
 

Example 61

From project jbpm-plugin, under directory /jbpm/src/main/java/hudson/jbpm/.

Source file: JbpmContextFilter.java

  15 
vote

public void doFilter(ServletRequest servletRequest,ServletResponse servletResponse,FilterChain filterChain) throws IOException, ServletException {
  String actorId=null;
  if (servletRequest instanceof HttpServletRequest) {
    HttpServletRequest httpServletRequest=(HttpServletRequest)servletRequest;
    Principal userPrincipal=httpServletRequest.getUserPrincipal();
    if (userPrincipal != null) {
      actorId=userPrincipal.getName();
    }
  }
  if (actorId == null) {
    Authentication auth=Hudson.getAuthentication();
    if (auth != null) {
      actorId=auth.getName();
    }
  }
  JbpmContext jbpmContext=getJbpmConfiguration().createJbpmContext(jbpmContextName);
  try {
    if (isAuthenticationEnabled) {
      jbpmContext.setActorId(actorId);
    }
    filterChain.doFilter(servletRequest,servletResponse);
  }
  finally {
    jbpmContext.close();
  }
}
 

Example 62

From project jdonframework, under directory /JdonAccessory/src/com/jdon/persistence/hibernate/.

Source file: CloseSessionInViewFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  try {
    chain.doFilter(request,response);
  }
  finally {
    if (SessionFactoryHolder.isSessionIsActive()) {
      log.debug("Close a session!");
      SessionFactoryHolder.closeSession();
    }
  }
}
 

Example 63

From project Jetwick, under directory /src/main/java/de/jetwick/ui/raw/.

Source file: ResourceFilter.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletResponse rsp=(HttpServletResponse)response;
  SimpleDateFormat formatter=new SimpleDateFormat(Helper.cacheDateFormatString);
  formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
  int minutes=30 * 24 * 60;
  rsp.setHeader("Cache-Control","public, max-age=" + minutes * 60);
  chain.doFilter(request,response);
}
 

Example 64

From project jforum2, under directory /src/net/jforum/util/legacy/clickstream/.

Source file: ClickstreamFilter.java

  15 
vote

/** 
 * Processes the given request and/or response.
 * @param request The request
 * @param response The response
 * @param chain The processing chain
 * @throws IOException If an error occurs
 * @throws ServletException If an error occurs
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (request.getAttribute(FILTER_APPLIED) == null) {
    request.setAttribute(FILTER_APPLIED,Boolean.TRUE);
    String bot=BotChecker.isBot((HttpServletRequest)request);
    if (bot != null && log.isDebugEnabled()) {
      log.debug("Found a bot: " + bot);
    }
    request.setAttribute(ConfigKeys.IS_BOT,Boolean.valueOf(bot != null));
  }
  chain.doFilter(request,response);
}
 

Example 65

From project jibu, under directory /jibu-web/jibu-core-extjs/src/main/java/org/gaixie/jibu/security/servlet/.

Source file: LoginFilter.java

  15 
vote

public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException, ServletException {
  HttpSession ses=((HttpServletRequest)req).getSession(false);
  boolean allowedRequest=false;
  if (null != ses) {
    if (null != ses.getAttribute("username")) {
      allowedRequest=true;
    }
  }
  if (!allowedRequest) {
    ((HttpServletResponse)res).sendRedirect("Login.x");
    return;
  }
  ((HttpServletResponse)res).setHeader("Pragma","no-cache");
  ((HttpServletResponse)res).setHeader("Cache-Control","no-cache,no-store,max-age=0");
  chain.doFilter(req,res);
}
 

Example 66

From project jira-hudson-integration, under directory /hudson-apiv2-plugin/src/main/java/com/marvelution/hudson/plugins/apiv2/servlet/filter/.

Source file: HudsonAPIV2ServletFilter.java

  15 
vote

/** 
 * {@inheritDoc}
 */
@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException, ServletException {
  if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
    final HttpServletRequestWrapper servletRequest=new HttpServletRequestWrapper((HttpServletRequest)request);
    String requestUri=servletRequest.getPathInfo();
    if (StringUtils.isNotBlank(requestUri) && requestUri.startsWith("/")) {
      requestUri=requestUri.substring(1);
    }
    LOGGER.log(Level.FINE,"Got a request from URI: " + requestUri + " with Accept Header: "+ servletRequest.getHeader("Accept"));
    if (StringUtils.isNotBlank(requestUri) && requestUri.startsWith(BaseRestResource.BASE_REST_URI)) {
      validateRuntimeDelegate();
      LOGGER.log(Level.FINE,"Got a REST request, forwarding it to the Wink RestFilter");
      FilteredHttpServletResponse servletResponse=new FilteredHttpServletResponse((HttpServletResponse)response);
      restServlet.service(servletRequest,servletResponse);
      if ((!(servletResponse.isCommitted())) && (servletResponse.getStatusCode() == 404)) {
        LOGGER.log(Level.FINE,"Filter " + this.getClass().getName() + " did not match a resource so letting request continue on FilterChain");
        servletResponse.setStatus(200);
        filterChain.doFilter(request,response);
      }
    }
 else {
      LOGGER.log(Level.FINE,"No REST request, forwarding request to the next ServletFilter");
      filterChain.doFilter(request,response);
    }
  }
 else {
    LOGGER.log(Level.FINE,"No HttpServletRequest and HttpServletResponse, forwarding request to the next ServletFilter");
    filterChain.doFilter(request,response);
  }
}
 

Example 67

From project jsfunit, under directory /jboss-jsfunit-core/src/main/java/org/jboss/jsfunit/framework/.

Source file: JSFUnitFilter.java

  15 
vote

public void doFilter(ServletRequest req,ServletResponse res,FilterChain filterChain) throws IOException, ServletException {
  JSFUnitFacesContext.cleanUpOldFacesContext();
  HttpServletRequest request=(HttpServletRequest)req;
  HttpServletResponse response=(HttpServletResponse)res;
  putWarURLinApplication(request);
  storeRequestParamsInSession(request);
  try {
    WebConversationFactory.setThreadLocals(request);
    System.setProperty("cactus.contextURL",WebConversationFactory.getWARURL());
    if (isSnoopRequest(request)) {
      snoop(request,response);
      return;
    }
    filterChain.doFilter(req,res);
  }
  finally {
    HttpSession session=((HttpServletRequest)req).getSession(false);
    if (session != null) {
      session.removeAttribute(JSFUnitFacesContext.SESSION_KEY);
      session.removeAttribute(WebClientSpec.SESSION_KEY);
    }
    WebConversationFactory.removeThreadLocals();
  }
}
 

Example 68

From project kernel_1, under directory /exo.kernel.container/src/main/java/org/exoplatform/container/web/.

Source file: PortalContainerFilter.java

  15 
vote

/** 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,javax.servlet.ServletResponse,javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (PortalContainer.isPortalContainerNameDisabled(servletContextName)) {
    onPortalContainerDisabled(request,response,chain);
    return;
  }
 else   if (PropertyManager.isDevelopping()) {
    HttpSession sess=((HttpServletRequest)request).getSession(false);
    if (sess != null && sess.getAttribute(RootContainer.SESSION_TO_BE_INVALIDATED_ATTRIBUTE_NAME) != null) {
      sess.invalidate();
    }
  }
  chain.doFilter(request,response);
}
 

Example 69

From project litle-sdk-for-java, under directory /lib/apache-cxf-2.5.2/samples/oauth/server/src/main/java/demo/oauth/server/spring/.

Source file: SpringOAuthAuthenticationFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  HttpServletRequest req=(HttpServletRequest)request;
  HttpServletResponse resp=(HttpServletResponse)response;
  List<String> authorities=(List<String>)request.getAttribute(OAUTH_AUTHORITIES);
  List<GrantedAuthority> grantedAuthorities=new ArrayList<GrantedAuthority>();
  if (authorities != null) {
    for (    String authority : authorities) {
      grantedAuthorities.add(new GrantedAuthorityImpl(authority));
    }
    Authentication auth=new AnonymousAuthenticationToken(UUID.randomUUID().toString(),req.getUserPrincipal(),grantedAuthorities);
    SecurityContextHolder.getContext().setAuthentication(auth);
  }
  chain.doFilter(req,resp);
}
 

Example 70

From project logback, under directory /logback-access/src/main/java/ch/qos/logback/access/servlet/.

Source file: TeeFilter.java

  15 
vote

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException, ServletException {
  if (active && request instanceof HttpServletRequest) {
    try {
      TeeHttpServletRequest teeRequest=new TeeHttpServletRequest((HttpServletRequest)request);
      TeeHttpServletResponse teeResponse=new TeeHttpServletResponse((HttpServletResponse)response);
      filterChain.doFilter(teeRequest,teeResponse);
      teeResponse.finish();
      teeRequest.setAttribute(LB_OUTPUT_BUFFER,teeResponse.getOutputBuffer());
    }
 catch (    IOException e) {
      e.printStackTrace();
      throw e;
    }
catch (    ServletException e) {
      e.printStackTrace();
      throw e;
    }
  }
 else {
    filterChain.doFilter(request,response);
  }
}
 

Example 71

From project lor-jamwiki, under directory /jamwiki-web/src/main/java/org/jamwiki/authentication/.

Source file: JAMWikiPostAuthenticationFilter.java

  15 
vote

/** 
 */
public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (!(request instanceof HttpServletRequest)) {
    throw new ServletException("HttpServletRequest required");
  }
  Authentication auth=SecurityContextHolder.getContext().getAuthentication();
  if (auth instanceof AnonymousAuthenticationToken) {
    this.handleAnonymousUser(auth);
  }
 else   if (auth != null && auth.isAuthenticated()) {
    this.handleRegisteredUser(auth);
  }
  chain.doFilter(request,response);
}
 

Example 72

From project MapPortlet, under directory /src/main/java/org/jasig/portlet/maps/mvc/.

Source file: AggregationAwareFilterBean.java

  15 
vote

@Override public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
  if (this.elementsProvider.getIncludedType((HttpServletRequest)request) == Included.AGGREGATED) {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation enabled, delegating to filter: " + this.filter);
    }
    this.filter.doFilter(request,response,chain);
  }
 else {
    if (logger.isDebugEnabled()) {
      logger.debug("Aggregation disabled, skipping filter: " + this.filter);
    }
    chain.doFilter(request,response);
  }
}
 

Example 73

From project maven-wagon, under directory /wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/.

Source file: AuthSnoopFilter.java

  15 
vote

public void doFilter(final ServletRequest req,final ServletResponse response,final FilterChain chain) throws IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)req;
  String authHeader=request.getHeader("Authorization");
  if (authHeader != null) {
    logger.info("Authorization: " + authHeader);
    String data=authHeader.substring("BASIC ".length());
    String decoded=new String(Base64.decodeBase64(data));
    logger.info(decoded);
    String[] creds=decoded.split(":");
    logger.info("User: " + creds[0] + "\nPassword: "+ creds[1]);
  }
}
 

Example 74

From project milton, under directory /milton/milton-servlet/src/main/java/com/bradmcevoy/http/.

Source file: SpringMiltonFilter.java

  15 
vote

@Override public void doFilter(ServletRequest req,ServletResponse resp,FilterChain fc) throws IOException, ServletException {
  if (req instanceof HttpServletRequest) {
    HttpServletRequest hsr=(HttpServletRequest)req;
    String url=hsr.getRequestURI();
    for (    String s : excludeMiltonPaths) {
      if (url.startsWith(s)) {
        fc.doFilter(req,resp);
        return;
      }
    }
    doMiltonProcessing((HttpServletRequest)req,(HttpServletResponse)resp);
  }
 else {
    fc.doFilter(req,resp);
    return;
  }
}
 

Example 75

From project milton2, under directory /examples/milton-test/src/main/java/com/mycompany/.

Source file: CustomFilter.java

  15 
vote

public void doFilter(javax.servlet.ServletRequest servletRequest,javax.servlet.ServletResponse servletResponse,FilterChain chain) throws IOException, ServletException {
  log.debug("doFilter");
  HttpServletRequest req=(HttpServletRequest)servletRequest;
  HttpServletResponse resp=(HttpServletResponse)servletResponse;
  String url=null;
  url=((HttpServletRequest)servletRequest).getRequestURL().toString();
  if (!url.endsWith(".jsp")) {
    log.debug("not a JSP, use milton");
    try {
      Request request=new ServletRequest(req);
      Response response=new ServletResponse(resp);
      httpManager.process(request,response);
    }
  finally {
      servletResponse.getOutputStream().flush();
      servletResponse.flushBuffer();
    }
  }
 else {
    log.debug("is a JSP, do not use milton");
    chain.doFilter(servletRequest,servletResponse);
  }
}
 

Example 76

From project miso-lims, under directory /miso-web/src/main/java/uk/ac/bbsrc/tgac/miso/webapp/context/.

Source file: AjaxSessionFilter.java

  15 
vote

/** 
 * Does the filtering at the given point in the filter chain.
 * @param req of type ServletRequest
 * @param res of type ServletResponse
 * @param chain of type FilterChain
 * @throws AuthenticationException when
 * @throws IOException when
 * @throws ServletException when
 */
@Override public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws AuthenticationException, IOException, ServletException {
  HttpServletRequest request=(HttpServletRequest)req;
  HttpServletResponse response=(HttpServletResponse)res;
  if (request.getAttribute(FILTER_APPLIED) != null) {
    chain.doFilter(request,response);
    return;
  }
  request.setAttribute(FILTER_APPLIED,Boolean.TRUE);
  if (!securityContextRepository.containsContext(request)) {
    if (request.getRequestedSessionId() != null && !request.isRequestedSessionIdValid()) {
      log.info("Session expired - informing client.");
      request.getSession();
      JSONObject jsonObject=JSONObject.fromObject("{'sessiontimeout':'sessiontimeout'}");
      jsonObject.write(res.getWriter());
      return;
    }
 else {
      chain.doFilter(req,res);
      return;
    }
  }
  chain.doFilter(req,res);
  return;
}