Search in sources :

Example 1 with AbstractJAXRSFactoryBean

use of org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean in project tesb-rt-se by Talend.

the class SAMLRESTUtilsTest method configureServerTest.

@Test
public void configureServerTest() throws Exception {
    AbstractJAXRSFactoryBean serverFactory = createMock(AbstractJAXRSFactoryBean.class);
    Map<String, Object> properties = new HashMap<String, Object>();
    expect(serverFactory.getProperties(true)).andReturn(properties).anyTimes();
    Map<String, Object> securityProps = new HashMap<String, Object>();
    serverFactory.setProvider(EasyMock.<Object>anyObject());
    EasyMock.expectLastCall().once();
    replay(serverFactory);
    SAMLRESTUtils.configureServer(serverFactory, securityProps);
    assertTrue(properties.containsKey(SecurityConstants.SIGNATURE_PROPERTIES));
    assertTrue(properties.containsKey(SecurityConstants.CALLBACK_HANDLER));
    assertTrue(properties.containsKey(SecurityConstants.SIGNATURE_USERNAME));
    EasyMock.verify(serverFactory);
}
Also used : HashMap(java.util.HashMap) AbstractJAXRSFactoryBean(org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean) Test(org.junit.Test)

Example 2 with AbstractJAXRSFactoryBean

use of org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean in project camel by apache.

the class CxfRsComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    CxfRsEndpoint answer;
    Object value = parameters.remove("setDefaultBus");
    if (value != null) {
        LOG.warn("The option setDefaultBus is @deprecated, use name defaultBus instead");
        if (!parameters.containsKey("defaultBus")) {
            parameters.put("defaultBus", value);
        }
    }
    if (remaining.startsWith(CxfConstants.SPRING_CONTEXT_ENDPOINT)) {
        // Get the bean from the Spring context
        String beanId = remaining.substring(CxfConstants.SPRING_CONTEXT_ENDPOINT.length());
        if (beanId.startsWith("//")) {
            beanId = beanId.substring(2);
        }
        AbstractJAXRSFactoryBean bean = CamelContextHelper.mandatoryLookup(getCamelContext(), beanId, AbstractJAXRSFactoryBean.class);
        if (bean instanceof BlueprintSupport) {
            answer = new CxfRsBlueprintEndpoint(this, remaining, bean);
        } else {
            answer = new CxfRsSpringEndpoint(this, remaining, bean);
        }
        // with to apply properties defined by URI query. 
        if (bean.getProperties() != null) {
            Map<String, Object> copy = new HashMap<String, Object>();
            copy.putAll(bean.getProperties());
            setProperties(answer, copy);
        }
        // setup the skipFaultLogging
        answer.setBeanId(beanId);
    } else {
        // endpoint URI does not specify a bean
        answer = new CxfRsEndpoint(remaining, this);
    }
    String resourceClass = getAndRemoveParameter(parameters, "resourceClass", String.class);
    if (resourceClass != null) {
        Class<?> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(resourceClass);
        answer.addResourceClass(clazz);
    }
    String resourceClasses = getAndRemoveParameter(parameters, "resourceClasses", String.class);
    Iterator<?> it = ObjectHelper.createIterator(resourceClasses);
    while (it.hasNext()) {
        String name = (String) it.next();
        Class<?> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(name);
        answer.addResourceClass(clazz);
    }
    setProperties(answer, parameters);
    Map<String, String> params = CastUtils.cast(parameters);
    answer.setParameters(params);
    setEndpointHeaderFilterStrategy(answer);
    return answer;
}
Also used : HashMap(java.util.HashMap) BlueprintSupport(org.apache.camel.component.cxf.blueprint.BlueprintSupport) AbstractJAXRSFactoryBean(org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean)

Example 3 with AbstractJAXRSFactoryBean

use of org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean in project tesb-rt-se by Talend.

the class SAMLRESTUtilsTest method configureClientTest.

@Test
public void configureClientTest() throws Exception {
    AbstractJAXRSFactoryBean clientFactory = createMock(AbstractJAXRSFactoryBean.class);
    STSClient stsClient = createMock(STSClient.class);
    List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
    expect(clientFactory.getOutInterceptors()).andReturn(interceptors).anyTimes();
    replay(clientFactory);
    SAMLRESTUtils.configureClient(clientFactory, stsClient);
    assertFalse(interceptors.isEmpty());
    for (Interceptor<? extends Message> i : interceptors) {
        if (i instanceof STSRESTOutInterceptor) {
            assertSame(((STSRESTOutInterceptor) i).getStsClient(), stsClient);
        }
    }
    EasyMock.verify(clientFactory);
}
Also used : STSClient(org.apache.cxf.ws.security.trust.STSClient) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) AbstractJAXRSFactoryBean(org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean) Interceptor(org.apache.cxf.interceptor.Interceptor) STSRESTOutInterceptor(org.talend.esb.security.saml.STSRESTOutInterceptor) Test(org.junit.Test)

Aggregations

AbstractJAXRSFactoryBean (org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 BlueprintSupport (org.apache.camel.component.cxf.blueprint.BlueprintSupport)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 Message (org.apache.cxf.message.Message)1 STSClient (org.apache.cxf.ws.security.trust.STSClient)1 STSRESTOutInterceptor (org.talend.esb.security.saml.STSRESTOutInterceptor)1