use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class ServerMode method configure.
@Override
protected void configure() {
super.configure();
String authUsersProviderClassName = propertiesProvider.get("authUsersProvider").orElse("org.icij.datashare.session.UsersInRedis");
String batchQueueType = propertiesProvider.get("batchQueueType").orElse("org.icij.datashare.extract.MemoryBlockingQueue");
bind(TaskManager.class).toInstance(new TaskManagerRedis(propertiesProvider, getBlockingQueue(propertiesProvider, batchQueueType, "ds:batchdownload:queue")));
Class<? extends UsersWritable> authUsersProviderClass = UsersInRedis.class;
try {
authUsersProviderClass = (Class<? extends UsersWritable>) Class.forName(authUsersProviderClassName);
logger.info("setting auth users provider to {}", authUsersProviderClass);
} catch (ClassNotFoundException e) {
logger.warn("\"{}\" auth users provider class not found. Setting provider to {}", authUsersProviderClassName, authUsersProviderClass);
}
bind(UsersWritable.class).to(authUsersProviderClass);
bind(SessionIdStore.class).to(RedisSessionIdStore.class);
bind(ApiKeyStore.class).to(ApiKeyStoreAdapter.class);
String authFilterClassName = propertiesProvider.get("authFilter").orElse("");
Class<? extends Filter> authFilterClass = OAuth2CookieFilter.class;
if (!authFilterClassName.isEmpty()) {
try {
authFilterClass = (Class<? extends Filter>) Class.forName(authFilterClassName);
logger.info("setting auth filter to {}", authFilterClass);
} catch (ClassNotFoundException e) {
logger.warn("\"{}\" auth filter class not found. Setting filter to {}", authFilterClassName, authFilterClass);
}
}
bind(Filter.class).to(authFilterClass);
if (authFilterClass.equals(BasicAuthAdaptorFilter.class)) {
bind(ApiKeyFilter.class).toInstance(new ApiKeyFilter(null, apiKey -> null) {
@Override
public Payload apply(String uri, Context context, PayloadSupplier nextFilter) throws Exception {
return nextFilter.get();
}
});
}
bind(StatusResource.class).asEagerSingleton();
configurePersistence();
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class ProjectResource method deleteProject.
/**
* Delete the project from database and elasticsearch indices.
*
* It returns 204 (no content) when something has been removed (index and/or database), or
* 404 if nothing has been removed (i.e. index and database don't exist).
*
* If the project id is not the current user project (local-datashare in local mode),
* then it will return 401 (unauthorized)
*
* @param id
* @return 204 (no content) or 404
*
* Example :
* $(curl -I -XDELETE -H 'Content-Type:application/json' localhost:8080/api/project/unknown-project)
*/
@Delete("/:id")
public Payload deleteProject(String id, Context context) throws Exception {
if (!context.currentUser().isInRole("local")) {
return new Payload(401);
}
boolean isDeleted = this.repository.deleteAll(id);
boolean indexDeleted = this.indexer.deleteAll(id);
return isDeleted || indexDeleted ? new Payload(204) : new Payload(404);
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class YesBasicAuthFilterTest method test_reject_secure_request_without_user.
@Test
public void test_reject_secure_request_without_user() throws Exception {
Payload payload = filter.apply("/secure/uri", context, nextFilter);
assertThat(payload.code()).isEqualTo(401);
assertThat(payload.headers()).includes(entry("WWW-Authenticate", "Basic realm=\"datashare\""));
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class YesBasicAuthFilterTest method test_pass_with_user_information.
@Test
public void test_pass_with_user_information() throws Exception {
// "foo:bar" base64 encoded
when(context.header("Authorization")).thenReturn("Basic Zm9vOmJhcg==");
Payload payload = filter.apply("/secure/uri", context, nextFilter);
assertThat(payload).isSameAs(next);
verify(context).setCurrentUser(user.capture());
assertThat(user.getValue().login()).isEqualTo("foo");
}
use of net.codestory.http.payload.Payload in project datashare by ICIJ.
the class ApiKeyFilterTest method test_adds_user_to_context.
@Test
public void test_adds_user_to_context() throws Exception {
when(context.header("authorization")).thenReturn("Bearer session_id");
when(apiKeyStore.getLogin("session_id")).thenReturn("user_id");
when(users.find("user_id")).thenReturn(new DatashareUser("user_id"));
Payload payload = apiKeyFilter.apply("url", context, nextFilter);
assertThat(payload).isSameAs(next);
verify(context).setCurrentUser(user.capture());
assertThat(user.getValue().login()).isEqualTo("user_id");
}
Aggregations