Search in sources :

Example 1 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 2 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 3 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 4 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 5 with Policy

use of org.apache.neethi.Policy in project cxf by apache.

the class SpnegoContextTokenInInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    // extract Assertion information
    if (aim != null) {
        Collection<AssertionInfo> ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SPNEGO_CONTEXT_TOKEN);
        if (ais.isEmpty()) {
            return;
        }
        if (isRequestor(message)) {
            // client side should be checked on the way out
            for (AssertionInfo ai : ais) {
                ai.setAsserted(true);
            }
            return;
        }
        String s = (String) message.get(SoapBindingConstants.SOAP_ACTION);
        if (s == null) {
            s = SoapActionInInterceptor.getSoapAction(message);
        }
        AddressingProperties inProps = (AddressingProperties) message.getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
        if (inProps != null && s == null) {
            // MS/WCF doesn't put a soap action out for this, must check the headers
            s = inProps.getAction().getValue();
        }
        if (s != null && s.contains("/RST/Issue") && (s.startsWith(STSUtils.WST_NS_05_02) || s.startsWith(STSUtils.WST_NS_05_12))) {
            Policy p = new Policy();
            ExactlyOne ea = new ExactlyOne();
            p.addPolicyComponent(ea);
            All all = new All();
            Assertion ass = NegotiationUtils.getAddressingPolicy(aim, false);
            all.addPolicyComponent(ass);
            ea.addPolicyComponent(all);
            // setup endpoint and forward to it.
            unmapSecurityProps(message);
            String ns = STSUtils.WST_NS_05_12;
            if (s.startsWith(STSUtils.WST_NS_05_02)) {
                ns = STSUtils.WST_NS_05_02;
            }
            NegotiationUtils.recalcEffectivePolicy(message, ns, p, new SpnegoSTSInvoker(), false);
        } else {
            message.getInterceptorChain().add(SpnegoContextTokenFinderInterceptor.INSTANCE);
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) All(org.apache.neethi.All) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Assertion(org.apache.neethi.Assertion) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) ExactlyOne(org.apache.neethi.ExactlyOne) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Aggregations

Policy (org.apache.neethi.Policy)123 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 Element (org.w3c.dom.Element)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 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 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 Document (org.w3c.dom.Document)6 InputStream (java.io.InputStream)5