Search in sources :

Example 1 with BonitaAuthFilter

use of org.apache.camel.component.bonita.api.filter.BonitaAuthFilter in project camel by apache.

the class BonitaAPIUtil method getInstance.

public static BonitaAPIUtil getInstance(BonitaAPIConfig bonitaAPIConfig) {
    if (instance == null) {
        instance = new BonitaAPIUtil();
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.register(MultiPartFeature.class);
        clientConfig.register(JacksonJsonProvider.class);
        Logger logger = Logger.getLogger("org.bonitasoft.camel.bonita.api.util.BonitaAPIUtil");
        Feature feature = new LoggingFeature(logger, Level.INFO, null, null);
        clientConfig.register(feature);
        ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
        Client client = clientBuilder.build();
        client.register(new JsonClientFilter());
        client.register(new BonitaAuthFilter(bonitaAPIConfig));
        instance.setWebTarget(client.target(bonitaAPIConfig.getBaseBonitaURI()));
    }
    return instance;
}
Also used : LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) JsonClientFilter(org.apache.camel.component.bonita.api.filter.JsonClientFilter) ClientConfig(org.glassfish.jersey.client.ClientConfig) Logger(java.util.logging.Logger) Client(javax.ws.rs.client.Client) BonitaAuthFilter(org.apache.camel.component.bonita.api.filter.BonitaAuthFilter) Feature(javax.ws.rs.core.Feature) MultiPartFeature(org.glassfish.jersey.media.multipart.MultiPartFeature) LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 2 with BonitaAuthFilter

use of org.apache.camel.component.bonita.api.filter.BonitaAuthFilter in project camel by apache.

the class BonitaAuthFilterConnectionTest method testConnectionSupportCSRF.

@Test
public void testConnectionSupportCSRF() throws Exception {
    String port = wireMockRule.port() + "";
    stubFor(post(urlEqualTo("/bonita/loginservice")).willReturn(aResponse().withHeader("Set-Cookie", "JSESSIONID=something", "X-Bonita-API-Token=something")));
    BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("localhost", port, "username", "password");
    BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
    bonitaAuthFilter.filter(requestContext);
    assertEquals(2, requestContext.getHeaders().size());
}
Also used : BonitaAPIConfig(org.apache.camel.component.bonita.api.util.BonitaAPIConfig) BonitaAuthFilter(org.apache.camel.component.bonita.api.filter.BonitaAuthFilter) Test(org.junit.Test)

Example 3 with BonitaAuthFilter

use of org.apache.camel.component.bonita.api.filter.BonitaAuthFilter in project camel by apache.

the class BonitaAuthFilterTest method testBonitaAuthFilterUsernameEmpty.

@Test(expected = IllegalArgumentException.class)
public void testBonitaAuthFilterUsernameEmpty() throws IOException {
    BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("localhost", "port", "", "password");
    BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
    bonitaAuthFilter.filter(requestContext);
}
Also used : BonitaAPIConfig(org.apache.camel.component.bonita.api.util.BonitaAPIConfig) BonitaAuthFilter(org.apache.camel.component.bonita.api.filter.BonitaAuthFilter) Test(org.junit.Test)

Example 4 with BonitaAuthFilter

use of org.apache.camel.component.bonita.api.filter.BonitaAuthFilter in project camel by apache.

the class BonitaAPIBuilder method build.

public static BonitaAPI build(BonitaAPIConfig bonitaAPIConfig) {
    if (bonitaAPIConfig == null) {
        throw new IllegalArgumentException("bonitaApiConfig is null");
    }
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
    Client client = clientBuilder.build();
    client.register(new BonitaAuthFilter(bonitaAPIConfig));
    WebTarget webTarget = client.target(bonitaAPIConfig.getBaseBonitaURI()).path("/API/bpm");
    return new BonitaAPI(bonitaAPIConfig, webTarget);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) BonitaAuthFilter(org.apache.camel.component.bonita.api.filter.BonitaAuthFilter) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 5 with BonitaAuthFilter

use of org.apache.camel.component.bonita.api.filter.BonitaAuthFilter in project camel by apache.

the class BonitaAuthFilterAlreadyConnectedTest method testAlreadyConnected.

@Test
public void testAlreadyConnected() throws Exception {
    BonitaAPIConfig bonitaApiConfig = new BonitaAPIConfig("hostname", "port", "username", "password");
    BonitaAuthFilter bonitaAuthFilter = new BonitaAuthFilter(bonitaApiConfig);
    bonitaAuthFilter.filter(requestContext);
}
Also used : BonitaAPIConfig(org.apache.camel.component.bonita.api.util.BonitaAPIConfig) BonitaAuthFilter(org.apache.camel.component.bonita.api.filter.BonitaAuthFilter) Test(org.junit.Test)

Aggregations

BonitaAuthFilter (org.apache.camel.component.bonita.api.filter.BonitaAuthFilter)7 BonitaAPIConfig (org.apache.camel.component.bonita.api.util.BonitaAPIConfig)5 Test (org.junit.Test)5 Client (javax.ws.rs.client.Client)2 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 Logger (java.util.logging.Logger)1 WebTarget (javax.ws.rs.client.WebTarget)1 Feature (javax.ws.rs.core.Feature)1 JsonClientFilter (org.apache.camel.component.bonita.api.filter.JsonClientFilter)1 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)1 MultiPartFeature (org.glassfish.jersey.media.multipart.MultiPartFeature)1