Leonardo Vannucci
2018-10-25 cb1770fff046c0bbbb6e20562c4604afa89cd30c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package it.digione.dg1cloud.ws.client.isd;
 
import org.apache.wss4j.dom.WSConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.ws.client.support.interceptor.ClientInterceptor;
import org.springframework.ws.soap.security.wss4j2.Wss4jSecurityInterceptor;
 
@Configuration
public class IsdConfig {
   
   @Autowired IsdProperties isdProperties;
   
   @Bean
   public Jaxb2Marshaller marshaller() {
       Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
       marshaller.setContextPath("it.isharedoc.schemas.instance");
       marshaller.setMtomEnabled(true);
       return marshaller;
   }
   
   @Bean
   public Wss4jSecurityInterceptor wsSecurityInterceptor() {
       Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
       wss4jSecurityInterceptor.setSecurementActions(WSConstants.USERNAME_TOKEN_LN);
       wss4jSecurityInterceptor.setSecurementUsername(isdProperties.getUsername());
       wss4jSecurityInterceptor.setSecurementPassword(isdProperties.getPassword());
       wss4jSecurityInterceptor.setSecurementPasswordType(WSConstants.PW_TEXT);
       wss4jSecurityInterceptor.setSecurementUsernameTokenNonce(true);
       wss4jSecurityInterceptor.setSecurementUsernameTokenCreated(true);
       return wss4jSecurityInterceptor;
   }
 
   @Bean
   public IsdSOAPConnector soapConnector(Jaxb2Marshaller marshaller, Wss4jSecurityInterceptor wsSecurityInterceptor) {
       IsdSOAPConnector client = new IsdSOAPConnector();
       client.setDefaultUri(isdProperties.getEndpoint().getInstance());
       client.setMarshaller(marshaller);
       client.setUnmarshaller(marshaller);
       ClientInterceptor[] interceptors = new ClientInterceptor[1];
       interceptors[0] = wsSecurityInterceptor;
       client.setInterceptors(interceptors);
       return client;
   }
}