我正在使用Apache cxf和spring boot,使用基本身份验证来设置SOAP服务 . 我正在尝试使用此服务,但我不知道如何传递用户名和密码 .

这是我的消费者:

public class Consumer {

    private Service service;
    public Consumer() throws MalformedURLException {
        URL wsdlURL = new URL("http://localhost:8081/soap/booksService?wsdl");
        QName SERVICE_NAME = new QName("http://service_interface.san.com/", "LibraryImplService");
        service = Service.create(wsdlURL,SERVICE_NAME);
    }
}

这是服务的安全配置:

@Configuration
public class SecurityConfig  extends WebSecurityConfigurerAdapter {
    @Autowired
    private void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("admin").password("admin1").roles("ADMIN");
    }

    @Override
    public void configure(HttpSecurity http) throws Exception{
        http.authorizeRequests()
                .antMatchers("/soap/**").hasRole("ADMIN")
                .and()
                .httpBasic()
                .and()
                .csrf().disable();
    }
}

我已经看到很多解决方案 BindingProvider 但由于auth问题我可以't seem to get them working because I can't初始 service = Service.create(wsdlURL,SERVICE_NAME); .