简体   繁体   中英

SOAP Authentication with Spring BOOT in SSL

I have to authenticate in to a service gateway that redirect me to one node of soap service, im using spring boot and cxf. But my code dont work.

public class ServiceGatewayAuthentication {
    @Value("${client.serviceGateway.address}")
    private String address;

    @Value("${client.serviceGateway.username}")
    private String userName;

    @Value("${client.serviceGateway.password}")
    private String password;

    @Bean(name = "asdAgentProxy")
    public ASD asdAgentProxy() {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean =
                new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setServiceClass(ASD.class);
        jaxWsProxyFactoryBean.setAddress(address);

        return (ASD) jaxWsProxyFactoryBean.create();
    }

    @Bean
    public Client asdAgentClientProxy() {
        return ClientProxy.getClient(asdAgentProxy());
    }

    @Bean
    public HTTPConduit asdAgentConduit() {
        HTTPConduit httpConduit =
                (HTTPConduit) asdAgentClientProxy().getConduit();
        httpConduit.setAuthorization(basicAuthorization());

        return httpConduit;
    }

    @Bean
    public AuthorizationPolicy basicAuthorization() {
        AuthorizationPolicy authorizationPolicy =
                new AuthorizationPolicy();
        authorizationPolicy.setUserName(userName);
        authorizationPolicy.setPassword(password);
        authorizationPolicy.setAuthorizationType(HttpAuthHeader.AUTH_TYPE_BASIC);

        return authorizationPolicy;
    }
}

The error is

Caused by: java.net.MalformedURLException: unknown protocol: null
    at org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit.setupConnection(AsyncHTTPConduit.java:155)
    at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:505)
    at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:47)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)

If instead i insert the {{client.serviceGateway.address}} directly in my wsdl i receive 401 Error because i havent authentication. Can you help me? Thanks so much.

I used the BindingProvider, and now all work.

@Bean(name = "asdServiceGateway")
    public ASD asdServiceGateway() {
        ASDServiceV2 asdServiceV2=new ASDServiceV2();
        ASD client = new ASDServiceV2().getASDPortV2();
        BindingProvider provider = (BindingProvider) client;;
        provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
        provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
        provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
        return client;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM