我遇到了一个问题,我需要读取用户名和密码值给一些在开发初期是静态的第三方,因此我在属性文件中使用了用户名和密码,现在的要求是获取用户名和密码。动态密码
Application propeties file values.
service.ledgerUsername:2896
service.ledgerPassword:355Y
So, i am trying to set ledgerUsername dynamically from input request, but the issue is since the below webservice Template is @Bean, it is initialized only once so the username and password as assigned during program instance for the first time, and it is not taking values at run time.
Is there any chance to change the scope from singleton to prototype or any good method to help?
@Bean
public WebServiceTemplate webServiceTemplate() {
final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setMarshaller(marshaller());
webServiceTemplate.setUnmarshaller(marshaller());
webServiceTemplate.setDefaultUri(serviceProviderApplicationConfiguration.getSoapUrl());
webServiceTemplate.setMessageSender(webServiceMessageSender());
webServiceTemplate.setInterceptors(new ClientInterceptor[] {securityInterceptor()});
return webServiceTemplate;
}
@SuppressWarnings("deprecation")
@Bean
public WebServiceMessageSender webServiceMessageSender() {
HttpClient httpclient = new HttpClient();
httpclient.getParams().setAuthenticationPreemptive(true);
httpclient.getHostConfiguration().setProxy("bmaproxy.bredband.local", 3128);
httpclient.getState().setProxyCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(**serviceProviderApplicationConfiguration.getLedgerUsername()**,
serviceProviderApplicationConfiguration.getLedgerPassword()));
CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender(httpclient);
messageSender.setConnectionTimeout(1000);
messageSender.setReadTimeout(1000);
return messageSender;
}
@Bean
public Wss4jSecurityInterceptor securityInterceptor() {
Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
wss4jSecurityInterceptor.setValidateResponse(false);
wss4jSecurityInterceptor.setSecurementActions("UsernameToken");
wss4jSecurityInterceptor
.setSecurementUsername(**serviceProviderApplicationConfiguration.getLedgerUsername()**);
wss4jSecurityInterceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
wss4jSecurityInterceptor
.setSecurementPassword(serviceProviderApplicationConfiguration.getLedgerPassword());
return wss4jSecurityInterceptor;
}