use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.
the class StaxRoundTripTest method testEncryptConfig.
@Test
public void testEncryptConfig() 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.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);
outConfig.put(ConfigurationConstants.ENCRYPTION_USER, "myalias");
outConfig.put(ConfigurationConstants.ENC_SYM_ALGO, XMLSecurityConstants.NS_XENC_AES128);
outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
outConfig.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.
the class StaxRoundTripTest method testUsernameTokenDigest.
@Test
public void testUsernameTokenDigest() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
WSS4JPrincipalInterceptor principalInterceptor = new WSS4JPrincipalInterceptor();
principalInterceptor.setPrincipalName("username");
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());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<WSSConstants.Action>();
actions.add(WSSConstants.USERNAMETOKEN);
properties.setActions(actions);
properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
properties.setTokenUser("username");
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
// Negative test for wrong password type
service.getInInterceptors().remove(inhandler);
inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);
try {
echo.echo("test");
fail("Failure expected on the wrong password type");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
String error = "The security token could not be authenticated or authorized";
assertTrue(ex.getMessage().contains(error));
}
}
use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.
the class StaxToDOMEncryptionIdentifierTest method testEncryptDirectReference.
@Test
public void testEncryptDirectReference() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPT);
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// 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.setEncryptionUser("myalias");
properties.setEncryptionKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);
Properties cryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setEncryptionCryptoProperties(cryptoProperties);
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.LoggingOutInterceptor in project cxf by apache.
the class StaxToDOMRoundTripTest method testEncryptSignature.
@Test
public void testEncryptSignature() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPT);
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
inProperties.put(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// 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);
actions.add(XMLSecurityConstants.SIGNATURE);
properties.setActions(actions);
properties.setEncryptionUser("myalias");
properties.setSignatureUser("myalias");
properties.setEncryptionSymAlgorithm(XMLSecurityConstants.NS_XENC_AES128);
Properties cryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setEncryptionCryptoProperties(cryptoProperties);
properties.setSignatureCryptoProperties(cryptoProperties);
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.LoggingOutInterceptor in project cxf by apache.
the class StaxToDOMRoundTripTest method testSignatureConfig.
@Test
public void testSignatureConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// 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, "myalias");
outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
outConfig.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
Aggregations