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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:29:17+00:00 2026-05-30T12:29:17+00:00

I currently have a number of web applications which access a common service running

  • 0

I currently have a number of web applications which access a common service running in JBoss 5.0. The service is very simple, using Guice and POJOs. The web applications are authenticated and know who the user is and what roles they have. When calling the service how should I pass this authentication information to the service?

It would seem the simple approach is to simply add a parameter to the interface to take the user information. Possibly a Subject. But this has the downside of cluttering up the interface with contextual information that isn’t specific to the job in hand.

void doSomething(Subject subject, ...) {
}

The alternative I have seen is to use ThreadLocal storage, put the user information in there before making the call and make this accessible via some utility class that the service can use. This cleans up the interface but hides the fact that the client of the service has to set the user information before making the call.

Is there another way of doing this? I get the feeling the AOP may be of use here too but can’t quite see how. Is there some “best practice” I am missing? Would EJB help?

  • 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-30T12:29:19+00:00Added an answer on May 30, 2026 at 12:29 pm

    This cleans up the interface but hides the fact that the client of the
    service has to set the user information before making the call.

    True, but if you need to pass something to a particular method across the application then you are defeating the purpose of using Dependency Injection. It’s there so that you don’t have to pass a bunch of services and objects to other services and objects and so forth, they are created with everything they need.

    Is there another way of doing this? I get the feeling the AOP may be
    of use here too but can’t quite see how. Is there some “best practice”
    I am missing? Would EJB help?

    The other way of doing this would be to use a single filter on every Servlet that calls the services that need the Subject / User. Set the user in the filter, and clear the user at the end in a try-finally block. In fact, OWASP Esapi uses this style when setting their ThreadLocalUser, it allows the User to be available in every part of the application.

    Something like this:

    @Singleton
    public MyUserFilter extends FilterOfTheMonth {
    
        private final Provider<Authenticator> authProvider;
    
        @Inject
        MyUserFilter(Provider<Authenticator> auth) {
            this.authProvider = auth;
        }
    
        public void doFilter(ServletRequest request, ServletResponse response, 
                FilterChain chain) throws java.io.IOException, ServletException {
            try {
                // Authenticate and SET the current user utilizing the request and/or                       
                // session objects
                authProvider.get().authenticateUser(HttpRequest currentRequest);
    
                // Continue on here along the servlet chain
                ... other processing
            } finally {
                authProvider.get().getRidOfCurrentUser();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of websites and web based applications running on a dedicated
I have a location using our ASP.NET 4.0 web application which was running fine
We currently have a number of desktop applications (PowerBuilder, Winforms, WPF) that make use
I'm currently using QDataStream to serialize my classes. I have quite a few number
Currently, I have a ASP.net 3.5 web application for which I currently am working
I currently have a number of databases in a hadoop cluster and wish to
I currently have a number of Python scripts that help prep a staging area
I currently have a SQL query that returns a number of fields. I need
I currently have an advanced search page that searches a number of fields in
I currently have about 650,000 items in memcached (430MB memory used) and the number

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.