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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:19:39+00:00 2026-06-06T18:19:39+00:00

I have a web service client that has an Authenticator class. The Authenticator requires

  • 0

I have a web service client that has an Authenticator class. The Authenticator requires a username/password. Looking for help on how to inject the credentials using Spring.

Should I inject the user/pass into the Authenticator or into the client that is instantiating the Authenticator.

Any concrete examples would be appreciated, as I am new to Spring.

These are what the two components look like:

@Controller
    public class WSClient {
        @Autowired
        MyAuthenticator myAuthenticator;
    }
}

The Authenticator, with the credentials:

public class MyAuthenticator extends Authenticator {
    private final String userName;
    private final String passWord;

    public MyAuthenticator(String userName, String passWord) {
        this.userName = userName;
        this.passWord = passWord;
    }

    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(this.userName, this.passWord.toCharArray());
    }
}
  • 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-06T18:19:41+00:00Added an answer on June 6, 2026 at 6:19 pm

    Use @Value to set username/password in Authentication bean

    @Component
    public class MyAuthenticator extends Authenticator {
        @Value("${credentials.username}")
        private final String userName;
        @Value("${credentials.password}")
        private final String passWord;
    
        public MyAuthenticator(String userName, String passWord) {
            this.userName = userName;
            this.passWord = passWord;
        }
    
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(this.userName, this.passWord.toCharArray());
        }
    }
    

    and in XML file

    add

    <util:properties id="credentials" location="classpath:credentials.properties"/>
    

    and put credentials.properties in classpath

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

Sidebar

Related Questions

I have a .NET web-service client that has been autogenerated from a wsdl-file using
I have a .NET Web Service running in VS2005 and a client that consumes
I have a windows forms client that consumes an ASP.net web service. It's my
I have a complex RIA client that communicates with a WCF SOAP web service,
I have a client program that consumes a web service. It works quite well
I have a Linux/c client app that connects to a WCF web service over
I have a have Winforms client that uses Web services on a IIS7 (W2008)
So I have an app that uses the Zend amazon web services client. I
I have a web application, which has Servlet and a static Class accessed through
I have a Java client that consumes SharePoint 2010 standard web services (sitedata.asmx, permissions.asmx,

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.