Skip to content

Commit

Permalink
Use injected Httpclient for loader (#122)
Browse files Browse the repository at this point in the history
The loader's interaction with a service with respect to OPTIONS now occurs
through the registry HttpClient, which can be configured for
authentication
  • Loading branch information
birkland authored and emetsger committed Jun 13, 2017
1 parent 63022f4 commit 7b22801
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.fcrepo.apix.model.Ontologies.Service.PROP_IS_SERVICE_INSTANCE_OF;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
Expand All @@ -42,6 +43,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -95,6 +97,8 @@ public class LoaderIT extends ServiceBasedTest {

final AtomicReference<Object> serviceResponse = new AtomicReference<>();

final AtomicBoolean auth = new AtomicBoolean(false);

@Rule
public TestName name = new TestName();

Expand Down Expand Up @@ -149,6 +153,7 @@ public void setUp() {
ex.setOut(ex.getIn());
if ("OPTIONS".equals(ex.getIn().getHeader(Exchange.HTTP_METHOD))) {
ex.getOut().setBody(optionsResponse.get());
auth.set(ex.getIn().getHeader("Authorization") != null);
} else if ("GET".equals(ex.getIn().getHeader(Exchange.HTTP_METHOD))) {
ex.getOut().setBody(serviceResponse.get());
} else {
Expand All @@ -157,6 +162,22 @@ public void setUp() {
});
}

@Test
public void authTest() throws Exception {

final String SERVICE_CANONICAL = "test:" + name.getMethodName();
final String EXPOSED_AT = SERVICE_CANONICAL;

optionsResponse.set(triple("", RDF_TYPE, CLASS_EXTENSION) +
ltriple("", PROP_EXPOSES_SERVICE_AT, EXPOSED_AT) +
triple("", PROP_EXPOSES_SERVICE, SERVICE_CANONICAL));

attempt(60, () -> textPost(LOADER_URI, serviceEndpoint)).getHeaderValue("Location");

assertTrue(auth.get());

}

@Test
public void htmlMinimalTest() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
auth.http.${fcrepo.dynamic.test.port}.localhost.username = fedoraAdmin
auth.http.${fcrepo.dynamic.test.port}.localhost.password = secret3
auth.http.${apix.dynamic.test.port}.localhost.username = fedoraAdmin
auth.http.${apix.dynamic.test.port}.localhost.password = secret3
auth.http.${apix.dynamic.test.port}.localhost.password = secret3
auth.http.${services.dynamic.test.port}.127.0.0.1.username = fedoraAdmin
auth.http.${services.dynamic.test.port}.127.0.0.1.password = secret3
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void configure() throws Exception {
.setHeader(Exchange.HTTP_URI, header(HEADER_SERVICE_URI))
.setHeader("Accept", constant("text/turtle"))
.process(e -> LOG.info("Execution OPTIONS to service URI {}", e.getIn().getHeader(Exchange.HTTP_URI)))
.to("jetty:http://localhost")
.to("http://localhost?httpClient=#httpClient")
.process(DEPOSIT_OBJECTS)
.setHeader(HTTP_RESPONSE_CODE, constant(303));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
</cm:default-properties>
</cm:property-placeholder>

<reference id="httpClientFetcher" ext:proxy-method="classes"
interface="org.fcrepo.apix.registry.HttpClientFetcher" />

<bean id="httpClient" factory-ref="httpClientFetcher"
factory-method="getClient" />

<bean id="http" class="org.apache.camel.component.http4.HttpComponent" />
<bean id="https" class="org.apache.camel.component.http4.HttpComponent" />

<reference id="extensionRegistry"
interface="org.fcrepo.apix.model.components.ExtensionRegistry" />

Expand All @@ -31,7 +40,8 @@
<reference id="generalRegistry" filter="(org.fcrepo.apix.registry.role=default)"
interface="org.fcrepo.apix.model.components.Registry" />

<reference id="routing" interface="org.fcrepo.apix.model.components.RoutingFactory" />
<reference id="routing"
interface="org.fcrepo.apix.model.components.RoutingFactory" />

<bean id="loaderService" class="org.fcrepo.apix.loader.impl.LoaderService">
<property name="extensionRegistry" ref="extensionRegistry" />
Expand Down

0 comments on commit 7b22801

Please sign in to comment.