Skip to content

Commit

Permalink
Replace Jetty with Helidon
Browse files Browse the repository at this point in the history
Affects: #93
  • Loading branch information
io7m committed Oct 20, 2023
1 parent 7d31c8f commit 0b0d645
Show file tree
Hide file tree
Showing 85 changed files with 1,682 additions and 2,002 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.linux.temurin.current.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: JDK
uses: actions/setup-java@v3
with:
java-version: 20
java-version: 21
distribution: 'temurin'
- name: Build
run: mvn --errors clean verify site
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.linux.temurin.lts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: JDK
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: 'temurin'
- name: Build
run: mvn --errors clean verify site
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.windows.temurin.current.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: JDK
uses: actions/setup-java@v3
with:
java-version: 20
java-version: 21
distribution: 'temurin'
- name: Build
run: mvn --errors clean verify site
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.windows.temurin.lts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: JDK
uses: actions/setup-java@v3
with:
java-version: 17
java-version: 21
distribution: 'temurin'
- name: Build
run: mvn --errors clean verify site
Expand Down
5 changes: 5 additions & 0 deletions checkstyle-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,9 @@
<suppress files="IdArbAMessageProvider\.java"
checks="FileLength"/>

<suppress files="IdUVServer\.java"
checks="ExecutableStatementCount"/>
<suppress files="IdUVHandlerCoreAuthenticated\.java"
checks="NPathComplexity"/>

</suppressions>
16 changes: 6 additions & 10 deletions com.io7m.idstore.server.admin_v1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,16 @@
<artifactId>com.io7m.verdant.core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-session</artifactId>
<groupId>io.helidon.http</groupId>
<artifactId>helidon-http</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.ee10</groupId>
<artifactId>jetty-ee10-servlet</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common-parameters</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import com.io7m.idstore.protocol.admin.IdAResponseError;
import com.io7m.idstore.protocol.admin.cb.IdACB1Messages;
import com.io7m.idstore.server.controller.command_exec.IdCommandExecutionFailure;
import com.io7m.idstore.server.http.IdHTTPServletRequestInformation;
import com.io7m.idstore.server.http.IdHTTPServletResponseFixedSize;
import com.io7m.idstore.server.http.IdHTTPServletResponseType;
import com.io7m.idstore.server.http.IdHTTPRequestInformation;
import com.io7m.idstore.server.http.IdHTTPResponseFixedSize;
import com.io7m.idstore.server.http.IdHTTPResponseType;

import java.util.Set;

/**
* Functions to transform exceptions.
Expand All @@ -48,7 +50,7 @@ private IdA1Errors()
*/

public static IdAResponseError errorOf(
final IdHTTPServletRequestInformation information,
final IdHTTPRequestInformation information,
final IdAResponseBlame blame,
final IdException exception)
{
Expand All @@ -73,17 +75,18 @@ public static IdAResponseError errorOf(
* @return An error response
*/

public static IdHTTPServletResponseType errorResponseOf(
public static IdHTTPResponseType errorResponseOf(
final IdACB1Messages messages,
final IdHTTPServletRequestInformation information,
final IdHTTPRequestInformation information,
final IdAResponseBlame blame,
final IdException exception)
{
return new IdHTTPServletResponseFixedSize(
return new IdHTTPResponseFixedSize(
switch (blame) {
case BLAME_CLIENT -> 400;
case BLAME_SERVER -> 500;
},
Set.of(),
IdACB1Messages.contentType(),
messages.serialize(errorOf(information, blame, exception))
);
Expand All @@ -99,9 +102,9 @@ public static IdHTTPServletResponseType errorResponseOf(
* @return An error response
*/

public static IdHTTPServletResponseType errorResponseOf(
public static IdHTTPResponseType errorResponseOf(
final IdACB1Messages messages,
final IdHTTPServletRequestInformation information,
final IdHTTPRequestInformation information,
final IdCommandExecutionFailure exception)
{
final IdAResponseBlame blame;
Expand All @@ -111,8 +114,9 @@ public static IdHTTPServletResponseType errorResponseOf(
blame = IdAResponseBlame.BLAME_SERVER;
}

return new IdHTTPServletResponseFixedSize(
return new IdHTTPResponseFixedSize(
exception.httpStatusCode(),
Set.of(),
IdACB1Messages.contentType(),
messages.serialize(errorOf(information, blame, exception))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,54 +30,55 @@
import com.io7m.idstore.server.controller.admin.IdACommandContext;
import com.io7m.idstore.server.controller.admin.IdACommandExecutor;
import com.io7m.idstore.server.controller.command_exec.IdCommandExecutionFailure;
import com.io7m.idstore.server.http.IdHTTPServletFunctional;
import com.io7m.idstore.server.http.IdHTTPServletFunctionalCoreType;
import com.io7m.idstore.server.http.IdHTTPServletRequestInformation;
import com.io7m.idstore.server.http.IdHTTPServletResponseFixedSize;
import com.io7m.idstore.server.http.IdHTTPServletResponseType;
import com.io7m.idstore.server.http.IdHTTPHandlerFunctional;
import com.io7m.idstore.server.http.IdHTTPHandlerFunctionalCoreType;
import com.io7m.idstore.server.http.IdHTTPRequestInformation;
import com.io7m.idstore.server.http.IdHTTPResponseFixedSize;
import com.io7m.idstore.server.http.IdHTTPResponseType;
import com.io7m.idstore.server.service.reqlimit.IdRequestLimitExceeded;
import com.io7m.idstore.server.service.reqlimit.IdRequestLimits;
import com.io7m.idstore.server.service.sessions.IdSessionAdmin;
import com.io7m.idstore.server.service.telemetry.api.IdServerTelemetryServiceType;
import com.io7m.idstore.strings.IdStrings;
import com.io7m.repetoir.core.RPServiceDirectoryType;
import jakarta.servlet.http.HttpServletRequest;
import io.helidon.webserver.http.ServerRequest;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static com.io7m.idstore.error_codes.IdStandardErrorCodes.API_MISUSE_ERROR;
import static com.io7m.idstore.protocol.admin.IdAResponseBlame.BLAME_CLIENT;
import static com.io7m.idstore.protocol.admin.IdAResponseBlame.BLAME_SERVER;
import static com.io7m.idstore.server.admin_v1.IdA1Errors.errorResponseOf;
import static com.io7m.idstore.server.admin_v1.IdA1ServletCoreAuthenticated.withAuthentication;
import static com.io7m.idstore.server.admin_v1.IdA1ServletCoreTransactional.withTransaction;
import static com.io7m.idstore.server.http.IdHTTPServletCoreInstrumented.withInstrumentation;
import static com.io7m.idstore.server.admin_v1.IdA1HandlerCoreAuthenticated.withAuthentication;
import static com.io7m.idstore.server.admin_v1.IdA1HandlerCoreTransactional.withTransaction;
import static com.io7m.idstore.server.http.IdHTTPHandlerCoreInstrumented.withInstrumentation;
import static com.io7m.idstore.server.service.telemetry.api.IdServerTelemetryServiceType.setSpanErrorCode;
import static com.io7m.idstore.strings.IdStringConstants.COMMAND_NOT_HERE;

/**
* The v1 command servlet.
* The v1 command handler.
*/

public final class IdA1ServletCommand extends IdHTTPServletFunctional
public final class IdA1HandlerCommand extends IdHTTPHandlerFunctional
{
/**
* The v1 command servlet.
*
* @param services The services
*/

public IdA1ServletCommand(
public IdA1HandlerCommand(
final RPServiceDirectoryType services)
{
super(createCore(services));
}

private static IdHTTPServletFunctionalCoreType createCore(
private static IdHTTPHandlerFunctionalCoreType createCore(
final RPServiceDirectoryType services)
{
final var limits =
Expand Down Expand Up @@ -118,10 +119,10 @@ private static IdHTTPServletFunctionalCoreType createCore(
};
}

private static IdHTTPServletResponseType execute(
private static IdHTTPResponseType execute(
final RPServiceDirectoryType services,
final HttpServletRequest request,
final IdHTTPServletRequestInformation information,
final ServerRequest request,
final IdHTTPRequestInformation information,
final IdACB1Messages messages,
final IdServerTelemetryServiceType telemetry,
final IdRequestLimits limits,
Expand All @@ -131,7 +132,7 @@ private static IdHTTPServletResponseType execute(
final IdDatabaseTransactionType transaction)
{
try (var input =
limits.boundedMaximumInput(request, 1048576)) {
limits.boundedMaximumInput(request, 1048576L)) {

final var message =
parseMessage(telemetry, messages, input);
Expand Down Expand Up @@ -172,9 +173,9 @@ private static IdHTTPServletResponseType execute(
}
}

private static IdHTTPServletResponseType executeCommand(
private static IdHTTPResponseType executeCommand(
final RPServiceDirectoryType services,
final IdHTTPServletRequestInformation information,
final IdHTTPRequestInformation information,
final IdACB1Messages messages,
final IdServerTelemetryServiceType telemetry,
final IdSessionAdmin session,
Expand Down Expand Up @@ -207,19 +208,21 @@ private static IdHTTPServletResponseType executeCommand(

if (result instanceof final IdAResponseError error) {
setSpanErrorCode(error.errorCode());
return new IdHTTPServletResponseFixedSize(
return new IdHTTPResponseFixedSize(
switch (error.blame()) {
case BLAME_SERVER -> 500;
case BLAME_CLIENT -> 400;
},
Set.of(),
IdACB1Messages.contentType(),
messages.serialize(error)
);
}

commit(telemetry, transaction);
return new IdHTTPServletResponseFixedSize(
return new IdHTTPResponseFixedSize(
200,
Set.of(),
IdACB1Messages.contentType(),
messages.serialize(result)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@
import com.io7m.idstore.database.api.IdDatabaseType;
import com.io7m.idstore.error_codes.IdStandardErrorCodes;
import com.io7m.idstore.model.IdAdmin;
import com.io7m.idstore.model.IdValidityException;
import com.io7m.idstore.protocol.admin.IdAResponseBlame;
import com.io7m.idstore.protocol.admin.IdAResponseError;
import com.io7m.idstore.protocol.admin.cb.IdACB1Messages;
import com.io7m.idstore.server.http.IdHTTPServletFunctionalCoreAuthenticatedType;
import com.io7m.idstore.server.http.IdHTTPServletFunctionalCoreType;
import com.io7m.idstore.server.http.IdHTTPServletRequestInformation;
import com.io7m.idstore.server.http.IdHTTPServletResponseFixedSize;
import com.io7m.idstore.server.http.IdHTTPServletResponseType;
import com.io7m.idstore.server.http.IdHTTPHandlerFunctionalCoreAuthenticatedType;
import com.io7m.idstore.server.http.IdHTTPHandlerFunctionalCoreType;
import com.io7m.idstore.server.http.IdHTTPRequestInformation;
import com.io7m.idstore.server.http.IdHTTPResponseFixedSize;
import com.io7m.idstore.server.http.IdHTTPResponseType;
import com.io7m.idstore.server.service.sessions.IdSessionAdmin;
import com.io7m.idstore.server.service.sessions.IdSessionAdminService;
import com.io7m.idstore.server.service.sessions.IdSessionSecretIdentifier;
import com.io7m.idstore.strings.IdStrings;
import com.io7m.repetoir.core.RPServiceDirectoryType;
import jakarta.servlet.http.HttpServletRequest;
import io.helidon.webserver.http.ServerRequest;

import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

import static com.io7m.idstore.database.api.IdDatabaseRole.IDSTORE;
Expand All @@ -52,18 +55,18 @@
* A core that executes the given core under authentication.
*/

public final class IdA1ServletCoreAuthenticated
implements IdHTTPServletFunctionalCoreType
public final class IdA1HandlerCoreAuthenticated
implements IdHTTPHandlerFunctionalCoreType
{
private final IdHTTPServletFunctionalCoreAuthenticatedType<IdSessionAdmin, IdAdmin> core;
private final IdHTTPHandlerFunctionalCoreAuthenticatedType<IdSessionAdmin, IdAdmin> core;
private final IdDatabaseType database;
private final IdSessionAdminService adminSessions;
private final IdACB1Messages messages;
private final IdStrings strings;

private IdA1ServletCoreAuthenticated(
private IdA1HandlerCoreAuthenticated(
final RPServiceDirectoryType services,
final IdHTTPServletFunctionalCoreAuthenticatedType<IdSessionAdmin, IdAdmin> inCore)
final IdHTTPHandlerFunctionalCoreAuthenticatedType<IdSessionAdmin, IdAdmin> inCore)
{
Objects.requireNonNull(services, "services");

Expand All @@ -86,24 +89,34 @@ private IdA1ServletCoreAuthenticated(
* @return A core that executes the given core under authentication
*/

public static IdHTTPServletFunctionalCoreType withAuthentication(
public static IdHTTPHandlerFunctionalCoreType withAuthentication(
final RPServiceDirectoryType services,
final IdHTTPServletFunctionalCoreAuthenticatedType<IdSessionAdmin, IdAdmin> inCore)
final IdHTTPHandlerFunctionalCoreAuthenticatedType<IdSessionAdmin, IdAdmin> inCore)
{
return new IdA1ServletCoreAuthenticated(services, inCore);
return new IdA1HandlerCoreAuthenticated(services, inCore);
}

@Override
public IdHTTPServletResponseType execute(
final HttpServletRequest request,
final IdHTTPServletRequestInformation information)
public IdHTTPResponseType execute(
final ServerRequest request,
final IdHTTPRequestInformation information)
{
final var httpSession =
request.getSession(true);
final var adminSessionId =
(IdSessionSecretIdentifier) httpSession.getAttribute("ID");
final var headers =
request.headers();
final var cookies =
headers.cookies();

if (adminSessionId == null) {
final String cookie;
try {
cookie = cookies.get("IDSTORE_ADMIN_API_SESSION");
} catch (final NoSuchElementException e) {
return this.notAuthenticated(information);
}

final IdSessionSecretIdentifier adminSessionId;
try {
adminSessionId = new IdSessionSecretIdentifier(cookie);
} catch (final IdValidityException e) {
return this.notAuthenticated(information);
}

Expand Down Expand Up @@ -137,11 +150,12 @@ public IdHTTPServletResponseType execute(
);
}

private IdHTTPServletResponseType notAuthenticated(
final IdHTTPServletRequestInformation information)
private IdHTTPResponseType notAuthenticated(
final IdHTTPRequestInformation information)
{
return new IdHTTPServletResponseFixedSize(
return new IdHTTPResponseFixedSize(
401,
Set.of(),
IdACB1Messages.contentType(),
this.messages.serialize(
new IdAResponseError(
Expand Down
Loading

0 comments on commit 0b0d645

Please sign in to comment.