Results 1 to 2 of 2

Thread: Wiring a Bean Which Itself has a Constructor

  1. #1
    Join Date
    Feb 2012
    Posts
    20

    Default Wiring a Bean Which Itself has a Constructor

    I have a web service client that has an Authenticator class. The Authenticator requires a username/password. Looking for ideas on how best to wire this. Should I inject the user/pass into the Authenticator or into the client that is instantiating the Authenticator. These are what the two components look like:

    Code:
        @Controller
        public class WSClient {
            @Autowired
            MyAuthenticator myAuthenticator;
        }
    The Authenticator that includes the user/pass:

    Code:
        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());
            }
        }

  2. #2
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    287

    Default

    Hi,

    I'd rather make user/pass parameters to the getPasswordAuthentication() method.

    On a different note, if this is a multi-user application, then regardless of where you store it, it should be thread local. Otherwise other requests will override them.
    Amila Domingo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •