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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:47:02+00:00 2026-06-01T06:47:02+00:00

I want to pass a security context to my rest service. On server side

  • 0

I want to pass a security context to my rest service.

On server side I try to get this with:

 public Response postObject(@Context SecurityContext security, JAXBElement<Object> object) {
    System.out.println("Security Context: " + security.getUserPrincipal());
 .....

But actually the Syso is null.

On Client side im just doing:

    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    client.addFilter(new HTTPBasicAuthFilter("user", "password"));

So, do I have to change in addition something in my web.xml to get it working?

I hoped its working without setting up static users in the tomcat user xml. So I can compare the user/password from security context with my “persistent” user/password hashmap located server sided. But when it is not working without tomcat user xml, how can it be done to add dynamically user to that user xml? When I ve static users I cant register a new user. I dont want to use this attempt: http://objecthunter.congrace.de/tinybo/blog/articles/89 cuz I want just to work with a semi persistence like a HashMap of user/password.

Besides another question: Why does everybody refer to Apache HttpClient when it is about security in Jersey, when it is working like I wrote as well?

My attempt refers to this post:

Jersey Client API – authentication

  • 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-01T06:47:03+00:00Added an answer on June 1, 2026 at 6:47 am

    You need to set up your application on the server so that it requires Basic authentication. I.e. include something like the following in the web.xml in your application war file – otherwise Tomcat does not perform the authentication and does not populate the security context.

    <security-constraint>
        <display-name>Authentication Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>all</web-resource-name>
            <description/>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description>authentication required</description>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>realm_name</realm-name>
    </login-config>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a few variables to another page. Currently I'm using response.redirect
i want to pass large variables to a PHP script on another server with
I want to pass external XML a variable. How do I do this? WHAT
I want to set my applications to connect to SQL server using a service
I want pass a class-instace to a method of an other and be sure
I want to pass a variable to he buttonEvent method in the selector. [button
I want to pass an array of arbitrary struct pointers and a comparison function
I want to pass data between a Python and a C# application in Windows
I want to pass through configuration arguments to a class. These are all the
I want to pass around some values in an array that will always be

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.