use of org.apache.neethi.Policy in project tesb-rt-se by Talend.
the class AbstractPolicyTest method customPolicyTest.
public void customPolicyTest(SchemaValidationPolicy assertion, String customerName) throws Exception {
clientCtxt = new ClassPathXmlApplicationContext("classpath:spring/client/policy/client-defaultApplicationContext.xml");
ClientProxyFactoryBean clientFactory = (ClientProxyFactoryBean) clientCtxt.getBean(ClientProxyFactoryBean.class);
Policy policy = new Policy();
policy.addAssertion(assertion);
clientFactory.getProperties().put(PolicyConstants.POLICY_OVERRIDE, policy);
CustomerServiceTester tester = new CustomerServiceTester();
tester.setCustomerService(clientFactory.create(CustomerService.class));
tester.testCustomerService(customerName);
clientCtxt.close();
}
use of org.apache.neethi.Policy in project tesb-rt-se by Talend.
the class RuntimeESBConsumerTest method noPropertiesSetProvidesEmptyArgumentList.
@Test
public void noPropertiesSetProvidesEmptyArgumentList() throws Exception {
QName serviceName = new QName("http://services.talend.org/test/Library/1.0", "LibraryProvider");
QName portName = new QName("http://services.talend.org/test/Library/1.0", "LibraryHttpPort");
QName operationName = new QName("http://services.talend.org/test/Library/1.0", "seekBook");
String publishedEndpointUrl = "local://LibraryHttpPort";
String wsdlURL = "classpath:/conf/libraryService/Library.wsdl";
boolean useServiceLocator = false;
LocatorFeature locatorFeature = null;
Map<String, String> locatorProps = new HashMap<String, String>();
EventFeature samFeature = null;
Map<String, String> samProps = new HashMap<String, String>();
boolean useServiceRegistry = false;
EsbSecurity esbSecurity = null;
Policy policy = null;
String username = "";
String password = "";
String alias = "";
Map<String, String> clientProperties = new HashMap<String, String>();
String roleName = "";
Object securityToken = null;
Crypto cryptoProvider = null;
SecurityArguments securityArguments = new SecurityArguments(esbSecurity, policy, username, password, alias, clientProperties, roleName, securityToken, cryptoProvider);
Bus bus = null;
boolean logging = false;
List<Header> soapHeaders = new ArrayList<Header>();
Feature httpHeadersFeature = null;
boolean enhancedResponse = false;
Object correlationIDCallbackHandler = null;
final boolean useGZipCompression = false;
RuntimeESBConsumer consumer = new RuntimeESBConsumer(serviceName, portName, operationName, publishedEndpointUrl, wsdlURL, useServiceLocator, locatorFeature, locatorProps, samFeature, samProps, useServiceRegistry, securityArguments, bus, logging, soapHeaders, httpHeadersFeature, enhancedResponse, correlationIDCallbackHandler, useGZipCompression);
String requestString = "<ns2:SearchFor xmlns:ns2=\"http://types.talend.org/test/Library/Common/1.0\" " + "xmlns:ns3=\"http://types.talend.org/test/GeneralObjects/ErrorHandling/1.0\">" + "<AuthorLastName>Icebear</AuthorLastName><ISBNNumber>123</ISBNNumber></ns2:SearchFor>";
consumer.invoke(getDocumentFromString(requestString));
}
use of org.apache.neethi.Policy in project tesb-rt-se by Talend.
the class SecurityArgumentsTest method buildClientConfigWithoutAlias.
@Test
public void buildClientConfigWithoutAlias() throws Exception {
initSTSClientUtils();
EsbSecurity esbSecurity = EsbSecurity.fromString("DIGEST");
Policy policy = createNiceMock(Policy.class);
String username = "username";
String password = "password";
String alias = null;
Map<String, String> clientProperties = new HashMap<String, String>();
String actor = "ws-security.actor";
clientProperties.put("ws-security.actor", actor);
String roleName = "roleName";
Object securityToken = new Object();
Crypto cryptoProvider = createNiceMock(Crypto.class);
SecurityArguments sa = new SecurityArguments(esbSecurity, policy, username, password, alias, clientProperties, roleName, securityToken, cryptoProvider);
Bus bus = createNiceMock(Bus.class);
boolean useServiceRegistry = true;
String encryptionUsername = "encryptionUsername";
Map<String, Object> config = sa.buildClientConfig(bus, useServiceRegistry, encryptionUsername);
assertSame(config.get("security.username"), username);
assertSame(config.get("security.encryption.username"), encryptionUsername);
assertSame(config.get("security.password"), password);
assertSame(config.get("security.signature.username"), alias);
assertSame(config.get("security.encryption.crypto"), cryptoProvider);
}
use of org.apache.neethi.Policy in project tesb-rt-se by Talend.
the class SecurityArgumentsTest method buildClientConfig.
@Test
public void buildClientConfig() throws Exception {
initSTSClientUtils();
EsbSecurity esbSecurity = EsbSecurity.fromString("DIGEST");
Policy policy = createNiceMock(Policy.class);
String username = "username";
String password = "password";
String alias = "alias";
Map<String, String> clientProperties = new HashMap<String, String>();
String actor = "actor";
String cacheConfiFile = "file:123";
clientProperties.put(SecurityConstants.ACTOR, actor);
clientProperties.put(SecurityConstants.CACHE_CONFIG_FILE, cacheConfiFile);
String roleName = "roleName";
Object securityToken = new Object();
Crypto cryptoProvider = createNiceMock(Crypto.class);
SecurityArguments sa = new SecurityArguments(esbSecurity, policy, username, password, alias, clientProperties, roleName, securityToken, cryptoProvider);
Bus bus = createNiceMock(Bus.class);
boolean useServiceRegistry = true;
String encryptionUsername = "encryptionUsername";
Map<String, Object> config = sa.buildClientConfig(bus, useServiceRegistry, encryptionUsername);
assertSame(config.get("security.username"), username);
assertSame(config.get("security.encryption.username"), encryptionUsername);
assertSame(config.get("security.password"), password);
assertSame(config.get("security.signature.username"), alias);
assertSame(config.get("security.encryption.crypto"), cryptoProvider);
}
use of org.apache.neethi.Policy in project cxf by apache.
the class AbstractSTSClient method validate.
/**
* Make an "Validate" invocation and return the response as a STSResponse Object
*/
protected STSResponse validate(SecurityToken tok, String tokentype) throws Exception {
createClient();
if (tokentype == null) {
tokentype = tokenType;
}
if (tokentype == null) {
tokentype = namespace + "/RSTR/Status";
}
Policy validatePolicy = new Policy();
ExactlyOne one = new ExactlyOne();
validatePolicy.addPolicyComponent(one);
All all = new All();
one.addPolicyComponent(all);
all.addAssertion(getAddressingAssertion());
client.getRequestContext().clear();
client.getRequestContext().putAll(ctx);
client.getRequestContext().put(SecurityConstants.TOKEN, tok);
BindingOperationInfo boi = findOperation("/RST/Validate");
if (boi == null) {
boi = findOperation("/RST/Issue");
client.getRequestContext().put(PolicyConstants.POLICY_OVERRIDE, validatePolicy);
}
client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/Validate");
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.writeStartElement("wst", "RequestSecurityToken", namespace);
writer.writeNamespace("wst", namespace);
writer.writeStartElement("wst", "RequestType", namespace);
writer.writeCharacters(namespace + "/Validate");
writer.writeEndElement();
writer.writeStartElement("wst", "TokenType", namespace);
writer.writeCharacters(tokentype);
writer.writeEndElement();
if (tokentype.endsWith("/RSTR/Status")) {
addClaims(writer);
writer.writeStartElement("wst", "ValidateTarget", namespace);
Element el = tok.getToken();
if (el != null) {
StaxUtils.copy(el, writer);
}
writer.writeEndElement();
writer.writeEndElement();
Object[] o = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
return new STSResponse((DOMSource) o[0], null);
}
if (enableLifetime) {
addLifetime(writer);
}
// Default to Bearer KeyType
String keyTypeTemplate = keyType;
if (keyTypeTemplate == null) {
keyTypeTemplate = namespace + "/Bearer";
}
keyTypeTemplate = writeKeyType(writer, keyTypeTemplate);
byte[] requestorEntropy = null;
X509Certificate cert = null;
Crypto crypto = null;
if (keySize <= 0) {
keySize = 256;
}
if (keyTypeTemplate != null && keyTypeTemplate.endsWith("SymmetricKey")) {
requestorEntropy = writeElementsForRSTSymmetricKey(writer, false);
} else if (keyTypeTemplate != null && keyTypeTemplate.endsWith("PublicKey")) {
// Use the given cert, or else get it from a Crypto instance
if (useKeyCertificate != null) {
cert = useKeyCertificate;
} else {
crypto = createCrypto(false);
cert = getCert(crypto);
}
writeElementsForRSTPublicKey(writer, cert);
}
writeRenewalSemantics(writer);
addClaims(writer);
writer.writeStartElement("wst", "ValidateTarget", namespace);
Element el = tok.getToken();
StaxUtils.copy(el, writer);
writer.writeEndElement();
writer.writeEndElement();
Object[] o = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
return new STSResponse((DOMSource) o[0], requestorEntropy, cert, crypto);
}
Aggregations