use of org.apache.cxf.ext.logging.LoggingInInterceptor in project cxf by apache.
the class StaxRoundTripTest method testEncryptUsernameToken.
@Test
public void testEncryptUsernameToken() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.USERNAMETOKEN);
actions.add(XMLSecurityConstants.ENCRYPT);
properties.setActions(actions);
properties.addEncryptionPart(new SecurePart(new QName(WSSConstants.NS_WSSE10, "UsernameToken"), SecurePart.Modifier.Element));
properties.setEncryptionUser("myalias");
properties.setTokenUser("username");
properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setEncryptionCryptoProperties(outCryptoProperties);
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ext.logging.LoggingInInterceptor in project cxf by apache.
the class StaxRoundTripTest method testEncrypt.
@Test
public void testEncrypt() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(XMLSecurityConstants.ENCRYPT);
properties.setActions(actions);
properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);
properties.setEncryptionUser("myalias");
Properties outCryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setEncryptionCryptoProperties(outCryptoProperties);
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ext.logging.LoggingInInterceptor in project cxf by apache.
the class StaxRoundTripTest method testSignaturePKIConfig.
@Test
public void testSignaturePKIConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inConfig = new HashMap<>();
inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inConfig.put(ConfigurationConstants.SIG_VER_PROP_FILE, "cxfca.properties");
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
principalInterceptor.setPrincipalName("CN=alice,OU=eng,O=apache.org");
service.getInInterceptors().add(inhandler);
service.getInInterceptors().add(principalInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> outConfig = new HashMap<>();
outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
outConfig.put(ConfigurationConstants.SIGNATURE_USER, "alice");
outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
outConfig.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
outConfig.put(ConfigurationConstants.USE_SINGLE_CERTIFICATE, "true");
outConfig.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ext.logging.LoggingInInterceptor in project cxf by apache.
the class StaxRoundTripTest method testEncryptSignatureConfig.
@Test
public void testEncryptSignatureConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inConfig = new HashMap<>();
inConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inConfig.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
inConfig.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inConfig);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> outConfig = new HashMap<>();
outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT + " " + ConfigurationConstants.SIGNATURE);
outConfig.put(ConfigurationConstants.SIGNATURE_USER, "myalias");
outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");
outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
outConfig.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128);
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ext.logging.LoggingInInterceptor in project cxf by apache.
the class StaxRoundTripTest method testTimestamp.
@Test
public void testTimestamp() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.TIMESTAMP);
properties.setActions(actions);
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
Aggregations