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 8435603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:57:34+00:00 2026-06-10T06:57:34+00:00

I have a simple use case where I want to grab a session variable

  • 0

I have a simple use case where I want to grab a session variable at the beginning of the session and only allow access to certain pages based on the result. I’m not real clear on is this best accomplished using bindInterceptor to intercept any @Get or @Post method on any page or is it better to use a filter. Here is a sketch of what I’d like to do but am open to alternatives:

At the start of a new session (@SessionScoped ?), check a session variable authentication token

If (authentication == admin) {
    serveRegex("admin/(jsp|html)/.*").with(GuiceContainer.class);   //only allow /admin subpages
    req.getRequestDispatcher("/admin").forward(req, res); //fwd all initial page requests to /admin
}
else If (authentication == user) {
    serveRegex("user/(jsp|html)/.*").with(GuiceContainer.class);  //only allow /user subpages
    req.getRequestDispatcher("/user").forward(req, res); //fwd all initial page requests to /user
}
else {
    serveRegex("signin/(jsp|html)/.*").with(GuiceContainer.class);  //only allow /signin subpages
    req.getRequestDispatcher("/signin").forward(req, res);  //fwd all initial page requests to /signin
}

Which technique is the preferred approach (least code, fastest, etc) for managing this security model? I’d love to see an example project.

Thanks for your help!

-John

  • 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-06-10T06:57:36+00:00Added an answer on June 10, 2026 at 6:57 am

    The common way of doing this is using a Filter. Given that you seem to segregate your URI space for the different required permissions, that’s also probably the easiest way. A bindInterceptor style is useful if you want the authentication logic declared on the methods/classes (“@AdminRequired” or such), but there’s really no good reason to do that – segregating the URI space is easier.

    Just bind a Filter that gets the current user/authorization logic and checks whether the permissions match the URI the request is going to.

    E.g.

    class AuthenticationFilter implements Filter {
    
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
        User user = getUserSomehow();
        if (user == null) {
          response.sendRedirect(... login page ...);
          return;
        }
        if (request.getRequestURI().startsWith("/admin")) {
          // Enforce Admin login, error out otherwise.
        }
        // Proceed with executing the request.
        chain.doFilter(request, response);
      }
    }
    

    Note that you’ll have to down-cast the ServletRequest/Response to HttpServletRequest/Response.

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

Sidebar

Related Questions

We have a simple requirement to use https for certain specific pages in a
I have a simple use case for df.to_excel() that I'm struggling with. I want
My use case is very simple : I have a GUI application, and inside
My use case is simple. I have a root domain object which references a
This one should be pretty simple. The use case is that I have a
use case is simple: I want to run some boiler plate code before each
I have a simple client-side Sqlite database (via. Google Gears) I want to use
I have a simple use case to solve. Imagine that somebody tells you hey,
I have a simple class for use on JNI, which i need to export
In Java I use getters/setters when I have simple models/pojos. I find that the

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.