use of org.apache.cxf.service.Service in project cxf by apache.
the class StaxRoundTripTest method testUsernameTokenDigestUnknownPassword.
@Test
public void testUsernameTokenDigestUnknownPassword() 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);
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<>();
actions.add(WSSConstants.USERNAMETOKEN);
properties.setActions(actions);
properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
properties.setTokenUser("username");
properties.setCallbackHandler(new UnknownUserPasswordCallbackHandler());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);
try {
echo.echo("test");
fail("Failure expected on an unknown password");
} 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.service.Service in project cxf by apache.
the class StaxRoundTripTest method testTimestampConfig.
@Test
public void testTimestampConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inConfig = new HashMap<>();
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.TIMESTAMP);
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class StaxToDOMRoundTripTest method testSignaturePKI.
@Test
public void testSignaturePKI() 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 KeystorePasswordCallback());
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "cxfca.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<>();
actions.add(XMLSecurityConstants.SIGNATURE);
properties.setActions(actions);
properties.setSignatureUser("alice");
Properties cryptoProperties = CryptoFactory.getProperties("alice.properties", this.getClass().getClassLoader());
properties.setSignatureCryptoProperties(cryptoProperties);
properties.setCallbackHandler(new KeystorePasswordCallback());
properties.setUseSingleCert(true);
properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_SECURITY_TOKEN_DIRECT_REFERENCE);
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class StaxToDOMRoundTripTest method testSignatureConfirmationConfig.
@Test
public void testSignatureConfirmationConfig() 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);
Map<String, Object> outProperties = new HashMap<>();
outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
outProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
outProperties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
outProperties.put(ConfigurationConstants.ENABLE_SIGNATURE_CONFIRMATION, "true");
outProperties.put(ConfigurationConstants.USER, "myalias");
WSS4JOutInterceptor domOhandler = new WSS4JOutInterceptor(outProperties);
service.getOutInterceptors().add(domOhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> clientOutConfig = new HashMap<>();
clientOutConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
clientOutConfig.put(ConfigurationConstants.SIGNATURE_USER, "myalias");
clientOutConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
clientOutConfig.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
WSS4JStaxOutInterceptor clientOhandler = new WSS4JStaxOutInterceptor(clientOutConfig);
client.getOutInterceptors().add(clientOhandler);
Map<String, Object> clientInConfig = new HashMap<>();
clientInConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
clientInConfig.put(ConfigurationConstants.ENABLE_SIGNATURE_CONFIRMATION, "true");
clientInConfig.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
WSS4JStaxInInterceptor clientInHandler = new WSS4JStaxInInterceptor(clientInConfig);
client.getInInterceptors().add(clientInHandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class StaxToDOMRoundTripTest method testUsernameTokenTextConfig.
@Test
public void testUsernameTokenTextConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
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.USERNAME_TOKEN);
outConfig.put(ConfigurationConstants.PASSWORD_TYPE, "PasswordText");
outConfig.put(ConfigurationConstants.USER, "username");
outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
// Negative test for wrong password type
service.getInInterceptors().remove(inInterceptor);
inProperties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_DIGEST);
inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
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));
}
}
Aggregations