Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1041109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:18:28+00:00 2026-05-16T15:18:28+00:00

I have an apache webserver that is used to serve php and static web

  • 0

I have an apache webserver that is used to serve php and static web files. In order to use active directory authentication i’ve written some code that can connect to AD through JNDI and authenticate usernames passwords and groups. What I would like is to map all requests to pages in apache through my servlet in order to make sure that a valid session is present and then if they have to login again that they have the correct AD group to visit a particular url. My issue is that when I map my servlet to every url with /* it cannot forward requests to the actual pages that I’m trying to get. It just keeps forwarding the request to my servlet and calling its doGet method till a servlet exception occurs. I want the functionality of a transparent proxy but I cannot seem to get that from this. Does anyone have any concrete examples of a transparent proxy servlet or know a way to do this with servlets. The forwarding functionality of a servlet seems to make this a perfect vehicle for doing it but I seem to be stuck.

Filter code

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest)request;
    HttpServletResponse res = (HttpServletResponse)response;
    boolean authenticated = false; //should be false when testing is done.
    //skip if its the login page
    if(req.getRequestURI().equals("/auth/login.jsp") || authenticated){
        chain.doFilter(req, res);   
    }else{
        req.setAttribute("protectedUrl", req.getRequestURI());
        res.sendRedirect("/auth/login.jsp");
    }
}

Web.xml

(snip)
<filter-mapping>
   <filter-name>SessionFilter</filter-name>
   <url-pattern>/*</url-pattern>
   <dispatcher>REQUEST</dispatcher>
</filter-mapping>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:18:29+00:00Added an answer on May 16, 2026 at 3:18 pm

    Because the servlet is mapped on /*, the RequestDispatcher#forward() will call it again, resulting in an infinite loop and finally a StackOverflowError (or some other exception depending on the servletcontainer in question which might have some recursion prevention builtin which kicks in after a certain amount of recursive calls).

    After all, the Servlet is not entirely the right tool for the job, you’d rather like to use a Filter here. Implement javax.servlet.Filter and do the same job in doFilter() method. It won’t call itself recursively when mapped on /* since it by default listens on requests only, not on forwards or includes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm from PHP background. I used to use Apache, MySQL and PHP for web
I have an apache webserver serving 2 URLs. I use VirtualHosts to configure it
I have webserver using default virtualhost apache <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory
I am creating a PHP based web application which requires simple authentication to use.
I have installed PHP and its not working in the Apache Webserver. Steps followed
I'm having trouble with my Apache Web Server. I have a folder (htdocs\images) where
I am using apache tomcat as a web server. I have deployed webservices on
I have apache httpd that I want to proxy to two different tomcat servers.
Using CentOS5, I have Apache configured with the following directives. Alias /pscript/ /var/www/pscript/ <Directory
I have an apache proxy between browser and my custom web server. So after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.