Announcement Announcement Module
Collapse
No announcement yet.
Wiring a Bean Which Itself has a Constructor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X