Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
[RFR-641] Remove old authentication and user classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hb0 committed Jun 29, 2023
1 parent c859f5f commit 1631ad6
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 1,514 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Cyface GmbH
* Copyright 2019-2023 Cyface GmbH
*
* This file is part of the Cyface API Library.
*
Expand All @@ -21,8 +21,6 @@
import java.io.IOException;
import java.net.ServerSocket;

import org.apache.commons.lang3.Validate;

import io.vertx.core.AsyncResult;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
Expand All @@ -42,7 +40,7 @@
*
* @author Armin Schnabel
* @author Klemens Muthmann
* @version 3.0.1
* @version 4.0.0
* @since 1.0.0
*/
public final class ApiServer {
Expand Down Expand Up @@ -104,12 +102,8 @@ public void start(final Vertx vertx, final VertxTestContext testContext, final T
port = socket.getLocalPort();
socket.close();

final var privateTestKey = this.getClass().getResource("/private_key.pem");
final var publicTestKey = this.getClass().getResource("/public.pem");
config.put("mongo.db", mongoDatabase.config())
.put("http.port", port)
.put("jwt.private", Validate.notNull(privateTestKey).getFile())
.put("jwt.public", Validate.notNull(publicTestKey).getFile())
.put("http.host", HTTP_HOST)
.put(httpEndpointParameterKey, httpEndpoint);
final DeploymentOptions options = new DeploymentOptions().setConfig(config);
Expand All @@ -118,20 +112,6 @@ public void start(final Vertx vertx, final VertxTestContext testContext, final T
.succeeding(result -> resultHandler.handle(Future.succeededFuture(WebClient.create(vertx)))));
}

/**
* Authenticates with the exporter server providing the received authentication token.
*
* @param client The client to use to access the server
* @param handler <code>Handler</code> called when the response has returned
*/
public void authenticate(final WebClient client, final Handler<AsyncResult<HttpResponse<Buffer>>> handler) {
final JsonObject body = new JsonObject();
body.put("username", "admin");
body.put("password", "secret");

client.post(port(), HTTP_HOST, httpEndpoint + "login").sendJsonObject(body, handler);
}

/**
* Send an authenticated {@code GET} request to a test server instance
*
Expand All @@ -145,23 +125,15 @@ public void authenticate(final WebClient client, final Handler<AsyncResult<HttpR
public void get(final WebClient client, final String endpoint, final VertxTestContext testContext,
final MultiMap headers, final Handler<AsyncResult<HttpResponse<Buffer>>> resultHandler) {

authenticate(client, testContext.succeeding(response -> {
final String authToken = response.getHeader("Authorization");

if (response.statusCode() == 200 && authToken != null) {
final HttpRequest<Buffer> builder = client
.get(port(), HTTP_HOST, httpEndpoint + endpoint)
.authentication(new TokenCredentials(authToken));
if (headers.size() > 0) {
builder.putHeaders(headers);
}
builder.send(resultHandler);
} else {
testContext.failNow(new IllegalStateException(String.format(
"Unable to authenticate. Authentication request response status was %d with authentication token %s.",
response.statusCode(), authToken)));
}
}));
final String authToken = "eyTestToken";

final HttpRequest<Buffer> builder = client
.get(port(), HTTP_HOST, httpEndpoint + endpoint)
.authentication(new TokenCredentials(authToken));
if (headers.size() > 0) {
builder.putHeaders(headers);
}
builder.send(resultHandler);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Cyface GmbH
* Copyright 2019-2023 Cyface GmbH
*
* This file is part of the Cyface API Library.
*
Expand All @@ -22,7 +22,7 @@
* Constants used in the database containing the compressed serialized data received from clients.
*
* @author Armin Schnabel
* @version 1.2.1
* @version 1.3.0
* @since 1.0.0
*/
public class DatabaseConstants {
Expand All @@ -43,10 +43,6 @@ public class DatabaseConstants {
* "myGroup"+{@code #GROUP_MANAGER_ROLE_PREFIX}
*/
public static final String USER_GROUP_ROLE_SUFFIX = "_user";
/**
* The database collection name.
*/
public static final String COLLECTION_USER = "user";
/**
* The database collection name.
*/
Expand All @@ -55,10 +51,6 @@ public class DatabaseConstants {
* The database collection name.
*/
public static final String COLLECTION_CHUNKS = "fs.chunks";
/**
* The database field name.
*/
public static final String USER_USERNAME_FIELD = "username";
/**
* The database field name used to annotate the owner of data by its user id.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 Cyface GmbH
* Copyright 2020-2023 Cyface GmbH
*
* This file is part of the Cyface API Library.
*
Expand All @@ -19,17 +19,17 @@
package de.cyface.apitestutils.fixture;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import de.cyface.apitestutils.fixture.user.DirectTestUser;
import de.cyface.model.MeasurementIdentifier;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.ext.mongo.MongoClient;

/**
* A fixture providing data to use for testing the raw geo-location export.
* A fixture providing data to use for testing the raw geographical location export.
* <p>
* Inserts a test {@link DatabaseConstants#GROUP_MANAGER_ROLE_SUFFIX} user and a test
* {@link DatabaseConstants#USER_GROUP_ROLE_SUFFIX} user and references the group user as data owner in the created
Expand All @@ -39,7 +39,7 @@
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 4.0.1
* @version 5.0.0
* @since 1.0.0
*/
@SuppressWarnings("unused") // API
Expand Down Expand Up @@ -74,29 +74,21 @@ public GeoLocationTestFixture(final List<MeasurementIdentifier> testMeasurementI
@Override
public Future<String> insertTestData(MongoClient mongoClient) {

final var manager = new DirectTestUser(TEST_USER_NAME, "secret",
TEST_GROUP + DatabaseConstants.GROUP_MANAGER_ROLE_SUFFIX);
final var groupUser = new DirectTestUser(TEST_GROUP_USER_USERNAME, "secret",
TEST_GROUP + DatabaseConstants.USER_GROUP_ROLE_SUFFIX);
final var managerInsert = manager.insert(mongoClient);
final var userInsert = groupUser.insert(mongoClient);
// Insert of test group manager and -user removed after switching to OAuth
final var userId = UUID.randomUUID().toString();

final Promise<String> promise = Promise.promise();
userInsert.onSuccess(userId -> {
final var testDocuments = testMeasurementIdentifiers.stream().map(
id -> new TestMeasurementDocument(userId, id.getMeasurementIdentifier(), id.getDeviceIdentifier()))
.collect(Collectors.toList());
final var testDocuments = testMeasurementIdentifiers.stream().map(
id -> new TestMeasurementDocument(userId, id.getMeasurementIdentifier(), id.getDeviceIdentifier()))
.collect(Collectors.toList());

// noinspection rawtypes
final var futures = testDocuments.stream().map(d -> (Future)d.insert(mongoClient))
.collect(Collectors.toList());
futures.add(managerInsert);
// noinspection rawtypes
final var futures = testDocuments.stream().map(d -> (Future)d.insert(mongoClient))
.collect(Collectors.toList());

final CompositeFuture composition = CompositeFuture.all(futures);
composition.onSuccess(succeeded -> promise.complete(userId));
composition.onFailure(promise::fail);
});
userInsert.onFailure(promise::fail);
final CompositeFuture composition = CompositeFuture.all(futures);
composition.onSuccess(succeeded -> promise.complete(userId));
composition.onFailure(promise::fail);

return promise.future();
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1631ad6

Please sign in to comment.