Search in sources :

Example 61 with Policy

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();
}
Also used : SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) Policy(org.apache.neethi.Policy) CustomerService(com.example.customerservice.CustomerService) CustomerServiceTester(org.talend.esb.policy.schemavalidate.testservice.client.CustomerServiceTester) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean)

Example 62 with Policy

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));
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) EventFeature(org.talend.esb.sam.agent.feature.EventFeature) EventFeature(org.talend.esb.sam.agent.feature.EventFeature) LocatorFeature(org.talend.esb.servicelocator.cxf.LocatorFeature) Feature(org.apache.cxf.feature.Feature) Crypto(org.apache.wss4j.common.crypto.Crypto) Header(org.apache.cxf.headers.Header) EsbSecurity(org.talend.esb.job.controller.ESBEndpointConstants.EsbSecurity) LocatorFeature(org.talend.esb.servicelocator.cxf.LocatorFeature) Test(org.junit.Test)

Example 63 with Policy

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);
}
Also used : Policy(org.apache.neethi.Policy) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Bus(org.apache.cxf.Bus) Crypto(org.apache.wss4j.common.crypto.Crypto) EsbSecurity(org.talend.esb.job.controller.ESBEndpointConstants.EsbSecurity) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 64 with Policy

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);
}
Also used : Policy(org.apache.neethi.Policy) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Bus(org.apache.cxf.Bus) Crypto(org.apache.wss4j.common.crypto.Crypto) EsbSecurity(org.talend.esb.job.controller.ESBEndpointConstants.EsbSecurity) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 65 with Policy

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);
}
Also used : Policy(org.apache.neethi.Policy) EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) All(org.apache.neethi.All) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) ExactlyOne(org.apache.neethi.ExactlyOne) X509Certificate(java.security.cert.X509Certificate) Crypto(org.apache.wss4j.common.crypto.Crypto)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5