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

The Archive Base Latest Questions

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

I have 2 spring web apps that provide 2 separate set of services. Web

  • 0

I have 2 spring web apps that provide 2 separate set of services. Web App 1 has Spring Security implemented using a user-based authentication.

Now, Web App 2 needs to access the service of Web App 1. Normally, we would use the RestTemplate class to make requests to other web services.

How do we pass the authentication credentials in the request of Web App 2 to Web App 1

  • 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-25T15:37:19+00:00Added an answer on May 25, 2026 at 3:37 pm

    I was in the same situation. Here there is my solution.

    Server – spring security config

    <sec:http>
        <sec:intercept-url pattern="/**" access="ROLE_USER" method="POST"/>
        <sec:intercept-url pattern="/**" filters="none" method="GET"/>
        <sec:http-basic />
    </sec:http>
    
    <sec:authentication-manager alias="authenticationManager">
        <sec:authentication-provider>
            <sec:user-service>
                <sec:user name="${rest.username}" password="${rest.password}" authorities="ROLE_USER"/>
            </sec:user-service>
        </sec:authentication-provider>
    </sec:authentication-manager>
    

    Client side RestTemplate config

    <bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
        <constructor-arg ref="httpClientParams"/>
        <property name="state" ref="httpState"/>
    </bean>
    
    <bean id="httpState" class="CustomHttpState">
        <property name="credentials" ref="credentials"/>
    </bean>
    
    <bean id="credentials" class="org.apache.commons.httpclient.UsernamePasswordCredentials">
        <constructor-arg value="${rest.username}"/>
        <constructor-arg value="${rest.password}"/>
    </bean>
    
    <bean id="httpClientFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory">
        <constructor-arg ref="httpClient"/>
    </bean>
    
    
    <bean class="org.springframework.web.client.RestTemplate">
        <constructor-arg ref="httpClientFactory"/>                
    </bean>
    

    Custom HttpState implementation

    /**
     * Custom implementation of {@link HttpState} with credentials property.
     *
     * @author banterCZ
     */
    public class CustomHttpState extends HttpState {
    
        /**
         * Set credentials property.
         *
         * @param credentials
         * @see #setCredentials(org.apache.commons.httpclient.auth.AuthScope, org.apache.commons.httpclient.Credentials)
         */
        public void setCredentials(final Credentials credentials) {
            super.setCredentials(AuthScope.ANY, credentials);
        }
    
    }
    

    Maven dependency

    <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>3.1</version>
    </dependency>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring Web Flow (v. 1.0.5) and I have a JSP page that
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests
I am implementing spring security framework in my web app. I have all the
Assume you have set of web apps that use various versions of a common
I have a Spring Web MVC application that I'd like to serve a large,
I have what seems like a simple problem. I have a Spring web app,
I have this web application using Spring Web Flow framework. In my main page
I have a web application developed with Spring 2.5. The application has numerous controllers,
I have a web application using JPA and JTA with Spring. I would like
I have noticed from several web pages that apparently Spring 3.0 supports @Inject from

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.