From 9af8ef7d0dc8c470c811ad91dd5d90554114b63c Mon Sep 17 00:00:00 2001 From: "Vladimir.Shapkin" Date: Mon, 16 Oct 2023 23:11:06 +0400 Subject: [PATCH] added helidon se --- config-server/pom.xml | 61 +++- eureka-server/pom.xml | 28 +- {helidon_mp => helidon-se}/Dockerfile | 6 +- {helidon_mp => helidon-se}/Dockerfile.native | 6 +- {helidon_mp => helidon-se}/README.md | 25 +- helidon-se/pom.xml | 163 +++++++++ .../examples/quickstart/se/GreetService.java | 137 ++++++++ .../helidon/examples/quickstart/se/Main.java | 102 ++++++ .../quickstart/se/SimpleGreetService.java | 74 ++++ .../examples/quickstart/se/package-info.java | 1 + .../test/authorization/rules/AuthFactory.java | 0 .../rules/AuthenticateUserInteractor.java | 0 .../AuthenticationResponsePresenter.java | 6 +- .../rules/CreateUserInteractor.java | 0 .../rules/CreationUserResponsePresenter.java | 4 +- .../authorization/rules/ResponseFactory.java | 15 +- .../AuthenticateUserInteractorImpl.java | 0 .../creation/CreateUserInteractorImpl.java | 0 .../validator/EmptyStringChainValidator.java | 0 .../rules/creation/validator/Validator.java | 0 .../rules/impl/AuthFactoryImpl.java | 8 - .../rules/impl/PolicyFactoryFake.java | 0 .../rules/impl/ResponseFactoryImpl.java | 17 +- .../AuthenticationResponseModel.java | 13 + .../CreationUserResponseModel.java | 13 + .../api/AuthenticationService.java | 56 ++++ .../controllers/api/dto/AuthInfo.java | 65 ++++ .../controllers/api/dto/Authentication.java | 156 +++++++++ .../incomings/controllers/api/dto/Token.java | 83 +++++ .../controllers/api/dto/TokenPair.java | 81 +++++ .../incomings/controllers/api/dto/User.java | 119 +++++++ .../impl/AuthenticationServiceImpl.java | 45 +++ .../incomings/controllers/package-info.java | 1 + .../controllers/presenters/ErrorMessage.java | 5 + .../AuthenticationUserResponseModelImpl.java | 74 ++++ .../CreationUserResponseModelImpl.java | 82 +++++ .../native-image.properties | 8 + .../helidon-quickstart-se/reflect-config.json | 65 ++++ .../src/main/resources/application.yaml | 8 + .../src/main/resources/logging.properties | 4 - .../main/resources/oas/Authentications.yaml | 0 .../examples/quickstart/se/MainTest.java | 127 +++++++ .../src/test/resources/application.yaml | 10 + helidon_mp/Dockerfile.jlink | 26 -- helidon_mp/pom.xml | 316 ------------------ .../examples/quickstart/mp/GreetResource.java | 115 ------- .../quickstart/mp/GreetingProvider.java | 35 -- .../examples/quickstart/mp/Message.java | 32 -- .../quickstart/mp/SimpleGreetResource.java | 69 ---- .../examples/quickstart/mp/package-info.java | 2 - .../AuthenticationResponseModel.java | 12 - .../CreationUserResponseModel.java | 12 - .../api/AuthenticationService.java | 77 ----- .../controllers/api/dto/AuthInfo.java | 91 ----- .../controllers/api/dto/Authentication.java | 199 ----------- .../incomings/controllers/api/dto/Token.java | 91 ----- .../controllers/api/dto/TokenPair.java | 88 ----- .../incomings/controllers/api/dto/User.java | 153 --------- .../impl/AuthenticationServiceImpl.java | 62 ---- .../AuthenticationUserResponseModelImpl.java | 57 ---- .../CreationUserResponseModelImpl.java | 62 ---- .../src/main/resources/META-INF/beans.xml | 8 - .../META-INF/microprofile-config.properties | 10 - .../native-image.properties | 1 - .../src/main/resources/application.yaml | 0 .../examples/quickstart/mp/MainTest.java | 94 ------ .../src/test/resources/application.yaml | 2 - oas/pom.xml | 10 +- policy/pom.xml | 12 +- .../impl/AuthenticationPolicyImplTest.java | 1 - pom.xml | 77 +---- service-bus/pom.xml | 14 +- starter/pom.xml | 36 +- user-store/pom.xml | 14 +- 74 files changed, 1684 insertions(+), 1762 deletions(-) rename {helidon_mp => helidon-se}/Dockerfile (75%) rename {helidon_mp => helidon-se}/Dockerfile.native (86%) rename {helidon_mp => helidon-se}/README.md (87%) create mode 100644 helidon-se/pom.xml create mode 100644 helidon-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java create mode 100644 helidon-se/src/main/java/io/helidon/examples/quickstart/se/Main.java create mode 100644 helidon-se/src/main/java/io/helidon/examples/quickstart/se/SimpleGreetService.java create mode 100644 helidon-se/src/main/java/io/helidon/examples/quickstart/se/package-info.java rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/AuthFactory.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/AuthenticateUserInteractor.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java (86%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/CreateUserInteractor.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java (90%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/ResponseFactory.java (52%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/authentication/AuthenticateUserInteractorImpl.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/creation/CreateUserInteractorImpl.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/creation/validator/EmptyStringChainValidator.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/creation/validator/Validator.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java (88%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/impl/PolicyFactoryFake.java (100%) rename {helidon_mp => helidon-se}/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java (61%) create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/package-info.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/ErrorMessage.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java create mode 100644 helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java create mode 100644 helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/native-image.properties create mode 100644 helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/reflect-config.json create mode 100644 helidon-se/src/main/resources/application.yaml rename {helidon_mp => helidon-se}/src/main/resources/logging.properties (94%) rename {helidon_mp => helidon-se}/src/main/resources/oas/Authentications.yaml (100%) create mode 100644 helidon-se/src/test/java/io/helidon/examples/quickstart/se/MainTest.java create mode 100644 helidon-se/src/test/resources/application.yaml delete mode 100644 helidon_mp/Dockerfile.jlink delete mode 100644 helidon_mp/pom.xml delete mode 100644 helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java delete mode 100644 helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetingProvider.java delete mode 100644 helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/Message.java delete mode 100644 helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/SimpleGreetResource.java delete mode 100644 helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/package-info.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java delete mode 100644 helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java delete mode 100644 helidon_mp/src/main/resources/META-INF/beans.xml delete mode 100644 helidon_mp/src/main/resources/META-INF/microprofile-config.properties delete mode 100644 helidon_mp/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-mp/native-image.properties delete mode 100644 helidon_mp/src/main/resources/application.yaml delete mode 100644 helidon_mp/src/test/java/io/helidon/examples/quickstart/mp/MainTest.java delete mode 100644 helidon_mp/src/test/resources/application.yaml diff --git a/config-server/pom.xml b/config-server/pom.xml index 556890c..af860f1 100644 --- a/config-server/pom.xml +++ b/config-server/pom.xml @@ -3,10 +3,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - my.test.eureka - parent-pom - 0.0.1-SNAPSHOT - ../pom.xml + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + config-server @@ -14,6 +14,23 @@ config Demo project for Spring Boot + + UTF-8 + 2022.0.1 + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + org.springframework.cloud @@ -35,4 +52,40 @@ + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + diff --git a/eureka-server/pom.xml b/eureka-server/pom.xml index 4519f3b..e5032cb 100644 --- a/eureka-server/pom.xml +++ b/eureka-server/pom.xml @@ -4,12 +4,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - my.test.eureka - parent-pom - 0.0.1-SNAPSHOT - ../pom.xml - + + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + + eureka-server 1.0-SNAPSHOT @@ -17,6 +17,22 @@ eureka-server Demo project eureka service discovery + + UTF-8 + 2022.0.1 + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + diff --git a/helidon_mp/Dockerfile b/helidon-se/Dockerfile similarity index 75% rename from helidon_mp/Dockerfile rename to helidon-se/Dockerfile index 36faa8c..84a9583 100644 --- a/helidon_mp/Dockerfile +++ b/helidon-se/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /helidon # Incremental docker builds will always resume after that, unless you update # the pom ADD pom.xml pom.xml -RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -DskipOpenApiGenerate +RUN mvn package -Dmaven.test.skip # Do the Maven build! # Incremental docker builds will resume here when you change sources @@ -22,9 +22,9 @@ FROM openjdk:17-jdk-slim WORKDIR /helidon # Copy the binary built in the 1st stage -COPY --from=build /helidon/target/helidon-quickstart-mp.jar ./ +COPY --from=build /helidon/target/helidon-quickstart-se.jar ./ COPY --from=build /helidon/target/libs ./libs -CMD ["java", "-jar", "helidon-quickstart-mp.jar"] +CMD ["java", "-jar", "helidon-quickstart-se.jar"] EXPOSE 8080 diff --git a/helidon_mp/Dockerfile.native b/helidon-se/Dockerfile.native similarity index 86% rename from helidon_mp/Dockerfile.native rename to helidon-se/Dockerfile.native index a0f3144..ae0db64 100644 --- a/helidon_mp/Dockerfile.native +++ b/helidon-se/Dockerfile.native @@ -1,6 +1,6 @@ # 1st stage, build the app -FROM ghcr.io/graalvm/graalvm-ce:ol9-java17-22.3.0 as build +FROM ghcr.io/graalvm/graalvm-ce:ol9-java19-22.3.0 as build # Install native-image RUN gu install native-image @@ -35,8 +35,8 @@ FROM scratch WORKDIR /helidon # Copy the binary built in the 1st stage -COPY --from=build /helidon/target/helidon-quickstart-mp . +COPY --from=build /helidon/target/helidon-quickstart-se . -ENTRYPOINT ["./helidon-quickstart-mp"] +ENTRYPOINT ["./helidon-quickstart-se"] EXPOSE 8080 diff --git a/helidon_mp/README.md b/helidon-se/README.md similarity index 87% rename from helidon_mp/README.md rename to helidon-se/README.md index b0173c3..9c62acd 100644 --- a/helidon_mp/README.md +++ b/helidon-se/README.md @@ -1,6 +1,6 @@ -# helidon-quickstart-mp +# helidon-quickstart-se -Minimal Helidon MP project suitable to start from scratch. +Sample Helidon SE project that includes multiple REST operations. ## Build and run @@ -8,7 +8,7 @@ Minimal Helidon MP project suitable to start from scratch. With JDK17+ ```bash mvn package -java -jar target/helidon-quickstart-mp.jar +java -jar target/helidon-quickstart-se.jar ``` ## Exercise the application @@ -16,6 +16,7 @@ java -jar target/helidon-quickstart-mp.jar curl -X GET http://localhost:8080/simple-greet {"message":"Hello World!"} ``` + ``` curl -X GET http://localhost:8080/greet {"message":"Hello World!"} @@ -30,6 +31,7 @@ curl -X GET http://localhost:8080/greet/Jose ``` + ## Try metrics ``` @@ -45,6 +47,7 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics ``` + ## Try health ``` @@ -54,6 +57,7 @@ curl -s -X GET http://localhost:8080/health ``` + ## Building a Native Image Make sure you have GraalVM locally installed: @@ -72,24 +76,27 @@ This uses the helidon-maven-plugin to perform the native compilation using your Once it completes start the application using the native executable (no JVM!): ``` -./target/helidon-quickstart-mp +./target/helidon-quickstart-se ``` Yep, it starts fast. You can exercise the application’s endpoints as before. + + ## Building the Docker Image ``` -docker build -t helidon-quickstart-mp . +docker build -t helidon-quickstart-se . ``` ## Running the Docker Image ``` -docker run --rm -p 8080:8080 helidon-quickstart-mp:latest +docker run --rm -p 8080:8080 helidon-quickstart-se:latest ``` Exercise the application as described above. + ## Building a Custom Runtime Image Build the custom runtime image using the jlink image profile: @@ -101,11 +108,11 @@ mvn package -Pjlink-image This uses the helidon-maven-plugin to perform the custom image generation. After the build completes it will report some statistics about the build including the reduction in image size. -The target/helidon-quickstart-mp-jri directory is a self contained custom image of your application. It contains your application, +The target/helidon-quickstart-se-jri directory is a self contained custom image of your application. It contains your application, its runtime dependencies and the JDK modules it depends on. You can start your application using the provide start script: ``` -./target/helidon-quickstart-mp-jri/bin/start +./target/helidon-quickstart-se-jri/bin/start ``` Class Data Sharing (CDS) Archive @@ -123,4 +130,4 @@ mvn package -Pjlink-image -Djlink.image.addClassDataSharingArchive=false ``` For more information on available configuration options see the helidon-maven-plugin documentation. - \ No newline at end of file + diff --git a/helidon-se/pom.xml b/helidon-se/pom.xml new file mode 100644 index 0000000..b9a29b8 --- /dev/null +++ b/helidon-se/pom.xml @@ -0,0 +1,163 @@ + + + 4.0.0 + + io.helidon.applications + helidon-se + 3.2.2 + + + + io.helidon.examples + helidon-quickstart-se + 1.0-SNAPSHOT + + + io.helidon.examples.quickstart.se.Main + 6.4.0 + 0.2.3 + + + + + my.test + policy + 1.0-SNAPSHOT + compile + + + my.test + user-store + 1.0-SNAPSHOT + compile + + + my.test + service-bus + 1.0-SNAPSHOT + compile + + + jakarta.validation + jakarta.validation-api + + + io.helidon.webserver + helidon-webserver + + + io.helidon.config + helidon-config-yaml + + + io.helidon.metrics + helidon-metrics + + + io.helidon.health + helidon-health + + + io.helidon.health + helidon-health-checks + + + + + + + io.helidon.media + helidon-media-jsonp + + + io.helidon.media + helidon-media-jsonb + + + io.helidon.media + helidon-media-multipart + + + org.openapitools + jackson-databind-nullable + ${version.jackson.databind.nullable} + + + + + + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest-all + test + + + io.helidon.webclient + helidon-webclient + test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-libs + + + + + + diff --git a/helidon-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java new file mode 100644 index 0000000..028e37c --- /dev/null +++ b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/GreetService.java @@ -0,0 +1,137 @@ + +package io.helidon.examples.quickstart.se; + +import java.util.Collections; +import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Level; +import java.util.logging.Logger; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonException; +import jakarta.json.JsonObject; + +import io.helidon.common.http.Http; +import io.helidon.config.Config; +import io.helidon.webserver.Routing; +import io.helidon.webserver.ServerRequest; +import io.helidon.webserver.ServerResponse; +import io.helidon.webserver.Service; + +/** + * A simple service to greet you. Examples: + * + * Get default greeting message: + * curl -X GET http://localhost:8080/greet + * + * Get greeting message for Joe: + * curl -X GET http://localhost:8080/greet/Joe + * + * Change greeting + * curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Howdy"}' http://localhost:8080/greet/greeting + * + * The message is returned as a JSON object + */ + +public class GreetService implements Service { + + /** + * The config value for the key {@code greeting}. + */ + private final AtomicReference greeting = new AtomicReference<>(); + + private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap()); + + private static final Logger LOGGER = Logger.getLogger(GreetService.class.getName()); + + GreetService(Config config) { + greeting.set(config.get("app.greeting").asString().orElse("Ciao")); + } + + /** + * A service registers itself by updating the routing rules. + * @param rules the routing rules. + */ + @Override + public void update(Routing.Rules rules) { + rules + .get("/", this::getDefaultMessageHandler) + .get("/{name}", this::getMessageHandler) + .put("/greeting", this::updateGreetingHandler); + } + + /** + * Return a worldly greeting message. + * @param request the server request + * @param response the server response + */ + private void getDefaultMessageHandler(ServerRequest request, ServerResponse response) { + sendResponse(response, "World"); + } + + /** + * Return a greeting message using the name that was provided. + * @param request the server request + * @param response the server response + */ + private void getMessageHandler(ServerRequest request, ServerResponse response) { + String name = request.path().param("name"); + sendResponse(response, name); + } + + private void sendResponse(ServerResponse response, String name) { + String msg = String.format("%s %s!", greeting.get(), name); + + JsonObject returnObject = JSON.createObjectBuilder() + .add("message", msg) + .build(); + response.send(returnObject); + } + + private static T processErrors(Throwable ex, ServerRequest request, ServerResponse response) { + + if (ex.getCause() instanceof JsonException){ + + LOGGER.log(Level.FINE, "Invalid JSON", ex); + JsonObject jsonErrorObject = JSON.createObjectBuilder() + .add("error", "Invalid JSON") + .build(); + response.status(Http.Status.BAD_REQUEST_400).send(jsonErrorObject); + } else { + + LOGGER.log(Level.FINE, "Internal error", ex); + JsonObject jsonErrorObject = JSON.createObjectBuilder() + .add("error", "Internal error") + .build(); + response.status(Http.Status.INTERNAL_SERVER_ERROR_500).send(jsonErrorObject); + } + + return null; + } + + private void updateGreetingFromJson(JsonObject jo, ServerResponse response) { + if (!jo.containsKey("greeting")) { + JsonObject jsonErrorObject = JSON.createObjectBuilder() + .add("error", "No greeting provided") + .build(); + response.status(Http.Status.BAD_REQUEST_400) + .send(jsonErrorObject); + return; + } + + greeting.set(jo.getString("greeting")); + response.status(Http.Status.NO_CONTENT_204).send(); + } + + /** + * Set the greeting to use in future messages. + * @param request the server request + * @param response the server response + */ + private void updateGreetingHandler(ServerRequest request, + ServerResponse response) { + request.content().as(JsonObject.class) + .forSingle(jo -> updateGreetingFromJson(jo, response)) + .exceptionally(ex -> processErrors(ex, request, response)); + } +} diff --git a/helidon-se/src/main/java/io/helidon/examples/quickstart/se/Main.java b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/Main.java new file mode 100644 index 0000000..598a0cc --- /dev/null +++ b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/Main.java @@ -0,0 +1,102 @@ +package io.helidon.examples.quickstart.se; + +import io.helidon.media.jsonb.JsonbSupport; +import io.helidon.media.jsonp.JsonpSupport; +import io.helidon.metrics.MetricsSupport; +import io.helidon.health.HealthSupport; +import io.helidon.health.checks.HealthChecks; +import io.helidon.common.LogConfig; +import io.helidon.common.reactive.Single; +import io.helidon.config.Config; +//import io.helidon.openapi.OpenAPISupport; +import io.helidon.webserver.Routing; +import io.helidon.webserver.WebServer; +import jakarta.json.bind.Jsonb; +import jakarta.json.bind.JsonbBuilder; +import my.test.authorization.rules.impl.AuthFactoryImpl; +import my.test.authorization.rules.impl.ResponseFactoryImpl; +import my.test.rest.incomings.controllers.impl.AuthenticationServiceImpl; + +/** + * The application main class. + */ +public final class Main { + + private static final Jsonb JSONB = JsonbBuilder.create(); + + /** + * Cannot be instantiated. + */ + private Main() { + } + + /** + * Application main entry point. + * + * @param args command line arguments. + */ + public static void main(final String[] args) { + startServer(); + } + + /** + * Start the server. + * + * @return the created {@link WebServer} instance + */ + static Single startServer() { + // load logging configuration + LogConfig.configureRuntime(); + + // By default this will pick up application.yaml from the classpath + Config config = Config.create(); + + WebServer server = WebServer.builder(createRouting(config)) + .config(config.get("server")) + .addMediaSupport(JsonpSupport.create()) + .addMediaSupport(JsonbSupport.create(JSONB)) + //.addMediaSupport(JacksonSupport.create(JsonProvider.objectMapper())) + .build(); + + Single webserver = server.start(); + + // Try to start the server. If successful, print some info and arrange to + // print a message at shutdown. If unsuccessful, print the exception. + webserver.forSingle(ws -> { + System.out.println("WEB server is up! http://localhost:" + ws.port() + "/greet"); + ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!")); + }) + .exceptionallyAccept(t -> { + System.err.println("Startup failed: " + t.getMessage()); + t.printStackTrace(System.err); + }); + + return webserver; + } + + /** + * Creates new {@link Routing}. + * + * @param config configuration of this server + * @return routing configured with JSON support, a health check, and a service + */ + private static Routing createRouting(Config config) { + + SimpleGreetService simpleGreetService = new SimpleGreetService(config); + GreetService greetService = new GreetService(config); + + HealthSupport health = HealthSupport.builder() + .addLiveness(HealthChecks.healthChecks()) // Adds a convenient set of checks + .build(); + + Routing.Builder builder = Routing.builder() + //.register(OpenAPISupport.create(config.get(OpenAPISupport.Builder.CONFIG_KEY))) + .register(MetricsSupport.create()) // Metrics at "/metrics" + .register(health) // Health at "/health" + .register("/simple-greet", simpleGreetService) + .register("/greet", greetService) + .register("/api", new AuthenticationServiceImpl(new AuthFactoryImpl(), new ResponseFactoryImpl(JSONB))); + + return builder.build(); + } +} diff --git a/helidon-se/src/main/java/io/helidon/examples/quickstart/se/SimpleGreetService.java b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/SimpleGreetService.java new file mode 100644 index 0000000..560a8ec --- /dev/null +++ b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/SimpleGreetService.java @@ -0,0 +1,74 @@ +package io.helidon.examples.quickstart.se; + +import java.util.Collections; +import java.util.logging.Logger; + +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.Counter; +import io.helidon.metrics.api.RegistryFactory; +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; + +import io.helidon.config.Config; +import io.helidon.webserver.Routing; +import io.helidon.webserver.ServerRequest; +import io.helidon.webserver.ServerResponse; +import io.helidon.webserver.Service; + +/** + * A simple service to greet you. Examples: + * + * Get default greeting message: + * curl -X GET http://localhost:8080/simple-greet + * + * The message is returned as a JSON object + */ +public class SimpleGreetService implements Service { + + private static final Logger LOGGER = Logger.getLogger(SimpleGreetService.class.getName()); + private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap()); + + private final MetricRegistry registry = RegistryFactory.getInstance() + .getRegistry(MetricRegistry.Type.APPLICATION); + private final Counter accessCtr = registry.counter("accessctr"); + + private final String greeting; + + SimpleGreetService(Config config) { + greeting = config.get("app.greeting").asString().orElse("Ciao"); + } + + + /** + * A service registers itself by updating the routing rules. + * + * @param rules the routing rules. + */ + @Override + public void update(Routing.Rules rules) { + rules.get("/", this::getDefaultMessageHandler); + rules.get("/greet-count", this::countAccess, this::getDefaultMessageHandler); + } + + /** + * Return a worldly greeting message. + * + * @param request the server request + * @param response the server response + */ + private void getDefaultMessageHandler(ServerRequest request, ServerResponse response) { + String msg = String.format("%s %s!", greeting, "World"); + LOGGER.info("Greeting message is " + msg); + JsonObject returnObject = JSON.createObjectBuilder() + .add("message", msg) + .build(); + response.send(returnObject); + } + + + private void countAccess(ServerRequest request, ServerResponse response) { + accessCtr.inc(); + request.next(); + } +} diff --git a/helidon-se/src/main/java/io/helidon/examples/quickstart/se/package-info.java b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/package-info.java new file mode 100644 index 0000000..6d783a8 --- /dev/null +++ b/helidon-se/src/main/java/io/helidon/examples/quickstart/se/package-info.java @@ -0,0 +1 @@ +package io.helidon.examples.quickstart.se; diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/AuthFactory.java b/helidon-se/src/main/java/my/test/authorization/rules/AuthFactory.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/AuthFactory.java rename to helidon-se/src/main/java/my/test/authorization/rules/AuthFactory.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/AuthenticateUserInteractor.java b/helidon-se/src/main/java/my/test/authorization/rules/AuthenticateUserInteractor.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/AuthenticateUserInteractor.java rename to helidon-se/src/main/java/my/test/authorization/rules/AuthenticateUserInteractor.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java b/helidon-se/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java similarity index 86% rename from helidon_mp/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java rename to helidon-se/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java index e567613..09bcf97 100644 --- a/helidon_mp/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java +++ b/helidon-se/src/main/java/my/test/authorization/rules/AuthenticationResponsePresenter.java @@ -1,6 +1,5 @@ package my.test.authorization.rules; -import jakarta.ws.rs.core.Response; import my.test.authorization.domain.api.AuthenticationResponseFactory; import my.test.rest.incomings.controllers.AuthenticationResponseModel; @@ -11,18 +10,15 @@ public interface AuthenticationResponsePresenter extends AuthenticationResponseF final class Fake implements AuthenticationResponsePresenter { @Override - public Response renderModel() { - return null; + public void send() { } @Override public void userNotFound() { - } @Override public void incorrectPassword() { - } @Override diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/CreateUserInteractor.java b/helidon-se/src/main/java/my/test/authorization/rules/CreateUserInteractor.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/CreateUserInteractor.java rename to helidon-se/src/main/java/my/test/authorization/rules/CreateUserInteractor.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java b/helidon-se/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java similarity index 90% rename from helidon_mp/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java rename to helidon-se/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java index 503c316..71d8f06 100644 --- a/helidon_mp/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java +++ b/helidon-se/src/main/java/my/test/authorization/rules/CreationUserResponsePresenter.java @@ -1,6 +1,5 @@ package my.test.authorization.rules; -import jakarta.ws.rs.core.Response; import my.test.authorization.domain.api.CreationUserResponseFactory; import my.test.rest.incomings.controllers.CreationUserResponseModel; @@ -13,8 +12,7 @@ final class Fake implements CreationUserResponsePresenter { public boolean invalidPasswordHashField; @Override - public Response renderModel() { - return null; + public void send() { } @Override diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/ResponseFactory.java b/helidon-se/src/main/java/my/test/authorization/rules/ResponseFactory.java similarity index 52% rename from helidon_mp/src/main/java/my/test/authorization/rules/ResponseFactory.java rename to helidon-se/src/main/java/my/test/authorization/rules/ResponseFactory.java index cce7483..9f11288 100644 --- a/helidon_mp/src/main/java/my/test/authorization/rules/ResponseFactory.java +++ b/helidon-se/src/main/java/my/test/authorization/rules/ResponseFactory.java @@ -1,10 +1,12 @@ package my.test.authorization.rules; +import io.helidon.webserver.ServerResponse; + public interface ResponseFactory { - AuthenticationResponsePresenter createAuthenticationResponsePresenter(); + AuthenticationResponsePresenter createAuthenticationResponsePresenter(ServerResponse response); - CreationUserResponsePresenter createCreationUserResponsePresenter(); + CreationUserResponsePresenter createCreationUserResponsePresenter(ServerResponse response); record Fake(AuthenticationResponsePresenter createAuthenticationResponsePresenter, CreationUserResponsePresenter createCreationUserResponsePresenter) implements ResponseFactory { @@ -13,5 +15,14 @@ public Fake() { this(new AuthenticationResponsePresenter.Fake(), new CreationUserResponsePresenter.Fake()); } + @Override + public AuthenticationResponsePresenter createAuthenticationResponsePresenter(ServerResponse response) { + return createAuthenticationResponsePresenter; + } + + @Override + public CreationUserResponsePresenter createCreationUserResponsePresenter(ServerResponse response) { + return createCreationUserResponsePresenter; + } } } diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/authentication/AuthenticateUserInteractorImpl.java b/helidon-se/src/main/java/my/test/authorization/rules/authentication/AuthenticateUserInteractorImpl.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/authentication/AuthenticateUserInteractorImpl.java rename to helidon-se/src/main/java/my/test/authorization/rules/authentication/AuthenticateUserInteractorImpl.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/creation/CreateUserInteractorImpl.java b/helidon-se/src/main/java/my/test/authorization/rules/creation/CreateUserInteractorImpl.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/creation/CreateUserInteractorImpl.java rename to helidon-se/src/main/java/my/test/authorization/rules/creation/CreateUserInteractorImpl.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/creation/validator/EmptyStringChainValidator.java b/helidon-se/src/main/java/my/test/authorization/rules/creation/validator/EmptyStringChainValidator.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/creation/validator/EmptyStringChainValidator.java rename to helidon-se/src/main/java/my/test/authorization/rules/creation/validator/EmptyStringChainValidator.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/creation/validator/Validator.java b/helidon-se/src/main/java/my/test/authorization/rules/creation/validator/Validator.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/creation/validator/Validator.java rename to helidon-se/src/main/java/my/test/authorization/rules/creation/validator/Validator.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java b/helidon-se/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java similarity index 88% rename from helidon_mp/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java rename to helidon-se/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java index 6737342..35e4701 100644 --- a/helidon_mp/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java +++ b/helidon-se/src/main/java/my/test/authorization/rules/impl/AuthFactoryImpl.java @@ -1,7 +1,5 @@ package my.test.authorization.rules.impl; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; import my.test.authorization.domain.api.PolicyFactory; import my.test.authorization.domain.api.UserInfo; import my.test.authorization.domain.api.servicebus.LogonEventTransmitter; @@ -16,16 +14,10 @@ import my.test.authorization.rules.creation.CreateUserInteractorImpl; import my.test.authorization.store.UserMockBuilderImpl; -@ApplicationScoped public class AuthFactoryImpl implements AuthFactory { private final PolicyFactory policyFactory; -// @Inject -// public AuthFactoryImpl(PolicyFactory policyFactory) { -// this.policyFactory = policyFactory; -// } - public AuthFactoryImpl() { this.policyFactory = new PolicyFactoryImpl(new UserMockBuilderImpl(), new LogonEventTransmitterBuilder.Fake(new LogonEventTransmitter.Fake())); diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/impl/PolicyFactoryFake.java b/helidon-se/src/main/java/my/test/authorization/rules/impl/PolicyFactoryFake.java similarity index 100% rename from helidon_mp/src/main/java/my/test/authorization/rules/impl/PolicyFactoryFake.java rename to helidon-se/src/main/java/my/test/authorization/rules/impl/PolicyFactoryFake.java diff --git a/helidon_mp/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java b/helidon-se/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java similarity index 61% rename from helidon_mp/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java rename to helidon-se/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java index 8dc31d4..1a05376 100644 --- a/helidon_mp/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java +++ b/helidon-se/src/main/java/my/test/authorization/rules/impl/ResponseFactoryImpl.java @@ -1,22 +1,27 @@ package my.test.authorization.rules.impl; -import jakarta.enterprise.context.ApplicationScoped; +import io.helidon.webserver.ServerResponse; +import jakarta.json.bind.Jsonb; import my.test.authorization.rules.AuthenticationResponsePresenter; import my.test.authorization.rules.CreationUserResponsePresenter; import my.test.authorization.rules.ResponseFactory; import my.test.rest.incomings.controllers.presenters.authentication.AuthenticationUserResponseModelImpl; import my.test.rest.incomings.controllers.presenters.creation.CreationUserResponseModelImpl; -@ApplicationScoped public class ResponseFactoryImpl implements ResponseFactory { + private final Jsonb jsonb; + + public ResponseFactoryImpl(Jsonb jsonb) { + this.jsonb = jsonb; + } @Override - public AuthenticationResponsePresenter createAuthenticationResponsePresenter() { - return new AuthenticationUserResponseModelImpl(); + public AuthenticationResponsePresenter createAuthenticationResponsePresenter(ServerResponse response) { + return new AuthenticationUserResponseModelImpl(response, jsonb); } @Override - public CreationUserResponsePresenter createCreationUserResponsePresenter() { - return new CreationUserResponseModelImpl(); + public CreationUserResponsePresenter createCreationUserResponsePresenter(ServerResponse response) { + return new CreationUserResponseModelImpl(response, jsonb); } } diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java new file mode 100644 index 0000000..7377cfa --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java @@ -0,0 +1,13 @@ +package my.test.rest.incomings.controllers; + +public interface AuthenticationResponseModel { + + void send(); + + final class Fake implements AuthenticationResponseModel { + + @Override + public void send() { + } + } +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java new file mode 100644 index 0000000..6f25d18 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java @@ -0,0 +1,13 @@ +package my.test.rest.incomings.controllers; + +public interface CreationUserResponseModel { + + void send(); + + final class Fake implements CreationUserResponseModel { + + @Override + public void send() { + } + } +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java new file mode 100644 index 0000000..b48da73 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java @@ -0,0 +1,56 @@ +package my.test.rest.incomings.controllers.api; + +import my.test.rest.incomings.controllers.api.dto.AuthInfo; +import io.helidon.webserver.Handler; + +import io.helidon.webserver.Routing; +import io.helidon.webserver.ServerRequest; +import io.helidon.webserver.ServerResponse; +import io.helidon.webserver.Service; + +public interface AuthenticationService extends Service { + + /** + * A service registers itself by updating the routing rules. + * @param rules the routing rules. + */ + @Override + default void update(Routing.Rules rules) { + rules.put("/create", Handler.create(AuthInfo.class, this::create)); + rules.post("/login", Handler.create(AuthInfo.class, this::login)); + rules.get("/logout", this::logout); + rules.get("/tokens/refresh", this::refreshTokens); + } + + + /** + * PUT /create : Создание пользователя. + * @param request the server request + * @param response the server response + * @param authInfo authInfo + */ + void create(ServerRequest request, ServerResponse response, AuthInfo authInfo); + + /** + * POST /login : Логин пользователя. + * @param request the server request + * @param response the server response + * @param authInfo authInfo + */ + void login(ServerRequest request, ServerResponse response, AuthInfo authInfo); + + /** + * GET /logout : Логаут пользователя. + * @param request the server request + * @param response the server response + */ + void logout(ServerRequest request, ServerResponse response); + + /** + * GET /tokens/refresh : Обновление пары токенов. + * @param request the server request + * @param response the server response + */ + void refreshTokens(ServerRequest request, ServerResponse response); + +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java new file mode 100644 index 0000000..ea61d14 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java @@ -0,0 +1,65 @@ +package my.test.rest.incomings.controllers.api.dto; + +public class AuthInfo { + + private String userName; + private String passwordHash; + + /** + * Default constructor. + */ + public AuthInfo() { + super(); + // JSON-B / Jackson + } + + /** + * Get userName + * + * @return userName + */ + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + /** + * MD5 hashed password + * + * @return passwordHash + */ + public String getPasswordHash() { + return passwordHash; + } + + public void setPasswordHash(String passwordHash) { + this.passwordHash = passwordHash; + } + + /** + * Create a string representation of this pojo. + **/ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AuthInfo {\n"); + + sb.append(" userName: ").append(toIndentedString(userName)).append("\n"); + sb.append(" passwordHash: ").append(toIndentedString(passwordHash)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java new file mode 100644 index 0000000..26a81be --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java @@ -0,0 +1,156 @@ +package my.test.rest.incomings.controllers.api.dto; + +import java.util.ArrayList; +import java.util.List; + + +public class Authentication { + + private Token accessToken; + private Token refreshToken; + private String username; + private String firstName; + private String lastName; + private List roles = new ArrayList<>(); + + /** + * Default constructor. + */ + public Authentication() { + // JSON-B / Jackson + } + + /** + * Create Authentication. + * + * @param accessToken accessToken + * @param refreshToken refreshToken + * @param username Логин пользователя + * @param firstName Имя пользователя + * @param lastName Фамилия пользователя + * @param roles Роли пользователя (допустимые для использования обладающие максимальным уровнем) + */ + public Authentication( + Token accessToken, + Token refreshToken, + String username, + String firstName, + String lastName, + List roles + ) { + this.accessToken = accessToken; + this.refreshToken = refreshToken; + this.username = username; + this.firstName = firstName; + this.lastName = lastName; + this.roles = roles; + } + + + /** + * Get accessToken + * + * @return accessToken + */ + public Token getAccessToken() { + return accessToken; + } + + public void setAccessToken(Token accessToken) { + this.accessToken = accessToken; + } + + /** + * Get refreshToken + * + * @return refreshToken + */ + public Token getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(Token refreshToken) { + this.refreshToken = refreshToken; + } + + /** + * Логин пользователя + * + * @return username + */ + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + /** + * Имя пользователя + * + * @return firstName + */ + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * Фамилия пользователя + * + * @return lastName + */ + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * Роли пользователя (допустимые для использования обладающие максимальным уровнем) + * + * @return roles + */ + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + /** + * Create a string representation of this pojo. + **/ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Authentication {\n"); + + sb.append(" accessToken: ").append(toIndentedString(accessToken)).append("\n"); + sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" roles: ").append(toIndentedString(roles)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java new file mode 100644 index 0000000..f22c278 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java @@ -0,0 +1,83 @@ +package my.test.rest.incomings.controllers.api.dto; + +import java.time.OffsetDateTime; + + +public class Token { + + private String value; + private OffsetDateTime expirationDateTime; + + /** + * Default constructor. + */ + public Token() { + // JSON-B / Jackson + } + + /** + * Create Token. + * + * @param value value + * @param expirationDateTime expirationDateTime + */ + public Token( + String value, + OffsetDateTime expirationDateTime + ) { + this.value = value; + this.expirationDateTime = expirationDateTime; + } + + + /** + * Get value + * + * @return value + */ + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + /** + * Get expirationDateTime + * + * @return expirationDateTime + */ + public OffsetDateTime getExpirationDateTime() { + return expirationDateTime; + } + + public void setExpirationDateTime(OffsetDateTime expirationDateTime) { + this.expirationDateTime = expirationDateTime; + } + + /** + * Create a string representation of this pojo. + **/ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Token {\n"); + + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append(" expirationDateTime: ").append(toIndentedString(expirationDateTime)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java new file mode 100644 index 0000000..492d1ae --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java @@ -0,0 +1,81 @@ +package my.test.rest.incomings.controllers.api.dto; + + +public class TokenPair { + + private Token accessToken; + private Token refreshToken; + + /** + * Default constructor. + */ + public TokenPair() { + // JSON-B / Jackson + } + + /** + * Create TokenPair. + * + * @param accessToken accessToken + * @param refreshToken refreshToken + */ + public TokenPair( + Token accessToken, + Token refreshToken + ) { + this.accessToken = accessToken; + this.refreshToken = refreshToken; + } + + + + /** + * Get accessToken + * @return accessToken + */ + public Token getAccessToken() { + return accessToken; + } + + public void setAccessToken(Token accessToken) { + this.accessToken = accessToken; + } + + /** + * Get refreshToken + * @return refreshToken + */ + public Token getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(Token refreshToken) { + this.refreshToken = refreshToken; + } + + /** + * Create a string representation of this pojo. + **/ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TokenPair {\n"); + + sb.append(" accessToken: ").append(toIndentedString(accessToken)).append("\n"); + sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java new file mode 100644 index 0000000..7297bf1 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java @@ -0,0 +1,119 @@ +package my.test.rest.incomings.controllers.api.dto; + +import java.util.ArrayList; +import java.util.List; + + + +public class User { + + private String username; + private String firstName; + private String lastName; + private List roles = new ArrayList<>(); + + /** + * Default constructor. + */ + public User() { + // JSON-B / Jackson + } + + /** + * Create User. + * + * @param username Логин пользователя + * @param firstName Имя пользователя + * @param lastName Фамилия пользователя + * @param roles Роли пользователя (допустимые для использования обладающие максимальным уровнем) + */ + public User( + String username, + String firstName, + String lastName, + List roles + ) { + this.username = username; + this.firstName = firstName; + this.lastName = lastName; + this.roles = roles; + } + + + + /** + * Логин пользователя + * @return username + */ + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + /** + * Имя пользователя + * @return firstName + */ + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * Фамилия пользователя + * @return lastName + */ + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * Роли пользователя (допустимые для использования обладающие максимальным уровнем) + * @return roles + */ + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + /** + * Create a string representation of this pojo. + **/ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" roles: ").append(toIndentedString(roles)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private static String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java new file mode 100644 index 0000000..5d43f94 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java @@ -0,0 +1,45 @@ +package my.test.rest.incomings.controllers.impl; + +import io.helidon.common.http.Http.Status; +import io.helidon.webserver.ServerRequest; +import io.helidon.webserver.ServerResponse; +import my.test.authorization.rules.AuthFactory; +import my.test.authorization.rules.AuthenticateUserInteractor; +import my.test.authorization.rules.CreateUserInteractor; +import my.test.authorization.rules.ResponseFactory; +import my.test.rest.incomings.controllers.api.AuthenticationService; +import my.test.rest.incomings.controllers.api.dto.AuthInfo; + + +public class AuthenticationServiceImpl implements AuthenticationService { + + private final AuthFactory authFactory; + private final ResponseFactory responseFactory; + + public AuthenticationServiceImpl(AuthFactory authFactory, ResponseFactory responseFactory) { + this.authFactory = authFactory; + this.responseFactory = responseFactory; + } + + public void create(ServerRequest request, ServerResponse response, AuthInfo authInfo) { + CreateUserInteractor createUserInteractor = authFactory + .createNewUserInteractor(authInfo.getUserName(), authInfo.getPasswordHash(), + responseFactory.createCreationUserResponsePresenter(response)); + createUserInteractor.createNewUserAndGetPresenter().send(); + } + + public void login(ServerRequest request, ServerResponse response, AuthInfo authInfo) { + AuthenticateUserInteractor authenticateUserInteractor = authFactory + .createAuthenticateUserInteractor(authInfo.getUserName(), authInfo.getPasswordHash(), + responseFactory.createAuthenticationResponsePresenter(response)); + authenticateUserInteractor.authenticateAndGetPresenter().send(); + } + + public void logout(ServerRequest request, ServerResponse response) { + response.status(Status.NOT_IMPLEMENTED_501).send(); + } + + public void refreshTokens(ServerRequest request, ServerResponse response) { + response.status(Status.NOT_IMPLEMENTED_501).send(); + } +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/package-info.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/package-info.java new file mode 100644 index 0000000..40a7c23 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/package-info.java @@ -0,0 +1 @@ +package my.test.rest.incomings.controllers; \ No newline at end of file diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/ErrorMessage.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/ErrorMessage.java new file mode 100644 index 0000000..3916bc2 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/ErrorMessage.java @@ -0,0 +1,5 @@ +package my.test.rest.incomings.controllers.presenters; + +public record ErrorMessage(String message) { + +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java new file mode 100644 index 0000000..f024dad --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java @@ -0,0 +1,74 @@ +package my.test.rest.incomings.controllers.presenters.authentication; + +import io.helidon.common.http.Http.Status; +import io.helidon.webserver.ServerResponse; +import jakarta.json.bind.Jsonb; +import java.time.LocalDateTime; +import java.time.ZoneId; +import my.test.authorization.domain.api.AuthenticationResponseFactory.UserData; +import my.test.authorization.rules.AuthenticationResponsePresenter; +import my.test.rest.incomings.controllers.api.dto.Authentication; +import my.test.rest.incomings.controllers.api.dto.Token; +import my.test.rest.incomings.controllers.presenters.ErrorMessage; + +public class AuthenticationUserResponseModelImpl implements AuthenticationResponsePresenter, UserData { + + private final Authentication authentication; + private final ServerResponse response; + + private final Jsonb jsonb; + private Runnable send; + + public AuthenticationUserResponseModelImpl(ServerResponse response, Jsonb jsonb) { + this.response = response; + this.jsonb = jsonb; + this.authentication = new Authentication(); + this.authentication.setAccessToken(new Token()); + this.send = () -> { + String returnObject = jsonb.toJson(authentication); + response.status(Status.OK_200).send(returnObject); + }; + } + + @Override + public void userNotFound() { + this.send = () -> { + String returnObject = jsonb.toJson(new ErrorMessage("User not found")); + response.status(Status.UNAUTHORIZED_401).send(returnObject); + }; + } + + @Override + public void incorrectPassword() { + this.send = () -> { + String returnObject = jsonb.toJson(new ErrorMessage("Invalid password")); + response.status(Status.UNAUTHORIZED_401).send(returnObject); + }; + } + + @Override + public UserData success() { + return this; + } + + @Override + public void writeUserName(String name) { + authentication.setUsername(name); + } + + @Override + public void writeToken(String token) { + authentication.getAccessToken().setValue(token); + } + + @Override + public void writeTokenExpirationDate(LocalDateTime expirationDateTime) { + authentication.getAccessToken() + .setExpirationDateTime(expirationDateTime.atZone(ZoneId.systemDefault()).toOffsetDateTime()); + } + + @Override + public void send() { + send.run(); + } +} diff --git a/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java b/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java new file mode 100644 index 0000000..d367c42 --- /dev/null +++ b/helidon-se/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java @@ -0,0 +1,82 @@ +package my.test.rest.incomings.controllers.presenters.creation; + +import io.helidon.common.http.Http.Status; +import io.helidon.webserver.ServerResponse; +import jakarta.json.bind.Jsonb; +import java.time.LocalDateTime; +import java.time.ZoneId; +import my.test.authorization.domain.api.CreationUserResponseFactory.UserData; +import my.test.authorization.rules.CreationUserResponsePresenter; +import my.test.rest.incomings.controllers.api.dto.Authentication; +import my.test.rest.incomings.controllers.api.dto.Token; +import my.test.rest.incomings.controllers.presenters.ErrorMessage; + +public class CreationUserResponseModelImpl implements CreationUserResponsePresenter, UserData { + + private final Authentication authentication; + private final ServerResponse response; + + private final Jsonb jsonb; + private Runnable send; + + public CreationUserResponseModelImpl(ServerResponse response, Jsonb jsonb) { + this.response = response; + this.jsonb = jsonb; + this.authentication = new Authentication(); + this.authentication.setAccessToken(new Token()); + this.send = () -> { + String returnObject = jsonb.toJson(authentication); + response.status(Status.OK_200).send(returnObject); + }; + } + + @Override + public void userAlreadyExists() { + this.send = () -> { + String returnObject = jsonb.toJson(new ErrorMessage("User already exists")); + response.status(Status.FORBIDDEN_403).send(returnObject); + }; + } + + @Override + public void invalidUserNameField() { + this.send = () -> { + String returnObject = jsonb.toJson(new ErrorMessage("Invalid user name")); + response.status(Status.FORBIDDEN_403).send(returnObject); + }; + } + + @Override + public void invalidPasswordHashField() { + this.send = () -> { + String returnObject = jsonb.toJson(new ErrorMessage("Invalid user password")); + response.status(Status.FORBIDDEN_403).send(returnObject); + }; + } + + @Override + public UserData success() { + return this; + } + + @Override + public void writeUserName(String name) { + authentication.setUsername(name); + } + + @Override + public void writeToken(String token) { + authentication.getAccessToken().setValue(token); + } + + @Override + public void writeTokenExpirationDate(LocalDateTime expirationDateTime) { + authentication.getAccessToken() + .setExpirationDateTime(expirationDateTime.atZone(ZoneId.systemDefault()).toOffsetDateTime()); + } + + @Override + public void send() { + send.run(); + } +} diff --git a/helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/native-image.properties b/helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/native-image.properties new file mode 100644 index 0000000..36bd0b9 --- /dev/null +++ b/helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/native-image.properties @@ -0,0 +1,8 @@ +Args=--initialize-at-build-time=io.helidon.examples.quickstart.se \ + --initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder \ + --initialize-at-build-time=org.slf4j.LoggerFactory \ + --initialize-at-build-time=net.jpountz.util.Utils \ + --initialize-at-build-time=net.jpountz.util.UnsafeUtils \ + --initialize-at-build-time=org.eclipse.yasson \ + --initialize-at-build-time=org.eclipse.yasson.internal + diff --git a/helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/reflect-config.json b/helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/reflect-config.json new file mode 100644 index 0000000..14773b6 --- /dev/null +++ b/helidon-se/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-se/reflect-config.json @@ -0,0 +1,65 @@ +[ + { + "name" : "my.test.rest.incomings.controllers.api.dto.AuthInfo", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true + }, + { + "name" : "my.test.rest.incomings.controllers.api.dto.Authentication", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true + }, + { + "name" : "my.test.rest.incomings.controllers.api.dto.Token", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true + }, + { + "name" : "my.test.rest.incomings.controllers.api.dto.TokenPair", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true + }, + { + "name" : "my.test.rest.incomings.controllers.api.dto.User", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true + }, + { + "name" : "my.test.rest.incomings.controllers.presenters.ErrorMessage", + "allDeclaredConstructors" : true, + "allPublicConstructors" : true, + "allDeclaredMethods" : true, + "allPublicMethods" : true, + "allDeclaredFields" : true, + "allPublicFields" : true + }, + { + "name": "org.apache.commons.logging.impl.LogFactoryImpl", + "allDeclaredConstructors": true, + "allPublicConstructors": true, + "allDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + } +] diff --git a/helidon-se/src/main/resources/application.yaml b/helidon-se/src/main/resources/application.yaml new file mode 100644 index 0000000..6b26b0d --- /dev/null +++ b/helidon-se/src/main/resources/application.yaml @@ -0,0 +1,8 @@ +server: + port: 8080 + host: 0.0.0.0 + +app: + greeting: "Hello" + + diff --git a/helidon_mp/src/main/resources/logging.properties b/helidon-se/src/main/resources/logging.properties similarity index 94% rename from helidon_mp/src/main/resources/logging.properties rename to helidon-se/src/main/resources/logging.properties index 5157244..4d1080e 100644 --- a/helidon_mp/src/main/resources/logging.properties +++ b/helidon-se/src/main/resources/logging.properties @@ -1,4 +1,3 @@ - # Example Logging Configuration File # For more information see $JAVA_HOME/jre/lib/logging.properties @@ -11,9 +10,6 @@ java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$ # Global logging level. Can be overridden by specific loggers .level=INFO -# Quiet Weld -org.jboss.level=WARNING - # Component specific log levels #io.helidon.webserver.level=INFO #io.helidon.config.level=INFO diff --git a/helidon_mp/src/main/resources/oas/Authentications.yaml b/helidon-se/src/main/resources/oas/Authentications.yaml similarity index 100% rename from helidon_mp/src/main/resources/oas/Authentications.yaml rename to helidon-se/src/main/resources/oas/Authentications.yaml diff --git a/helidon-se/src/test/java/io/helidon/examples/quickstart/se/MainTest.java b/helidon-se/src/test/java/io/helidon/examples/quickstart/se/MainTest.java new file mode 100644 index 0000000..e9a3218 --- /dev/null +++ b/helidon-se/src/test/java/io/helidon/examples/quickstart/se/MainTest.java @@ -0,0 +1,127 @@ + +package io.helidon.examples.quickstart.se; + +import java.time.Duration; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.TimeUnit; +import java.time.Duration; +import java.util.Collections; +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; + +import io.helidon.media.jsonp.JsonpSupport; +import io.helidon.common.http.Http; +import io.helidon.webclient.WebClient; +import io.helidon.webclient.WebClientResponse; +import io.helidon.webserver.WebServer; + +import org.junit.jupiter.api.Order; +import jakarta.json.JsonObject; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +class MainTest { + + private static final JsonBuilderFactory JSON_BUILDER = Json.createBuilderFactory(Collections.emptyMap()); + private static final JsonObject TEST_JSON_OBJECT = JSON_BUILDER.createObjectBuilder() + .add("greeting", "Hola") + .build(); + + private static WebServer webServer; + private static WebClient webClient; + + @BeforeAll + static void startTheServer() { + webServer = Main.startServer().await(Duration.ofSeconds(10)); + + webClient = WebClient.builder() + .baseUri("http://localhost:" + webServer.port()) + .addMediaSupport(JsonpSupport.create()) + .build(); + } + + @AfterAll + static void stopServer() { + if (webServer != null) { + webServer.shutdown().await(10, TimeUnit.SECONDS); + } + } + + + @Test + void testMicroprofileMetrics() { + String get = webClient.get() + .path("/simple-greet/greet-count") + .request(String.class) + .await(Duration.ofSeconds(5)); + + assertThat(get, containsString("Hello World!")); + + String openMetricsOutput = webClient.get() + .path("/metrics") + .request(String.class) + .await(Duration.ofSeconds(5)); + + assertThat("Metrics output", openMetricsOutput, containsString("application_accessctr_total")); + } + + @Test + void testMetrics() { + WebClientResponse response = webClient.get() + .path("/metrics") + .request() + .await(Duration.ofSeconds(5)); + assertThat(response.status().code(), is(200)); + } + + @Test + void testHealth() { + WebClientResponse response = webClient.get() + .path("health") + .request() + .await(Duration.ofSeconds(5)); + assertThat(response.status().code(), is(200)); + } + + @Test + void testSimpleGreet() { + JsonObject jsonObject = webClient.get() + .path("/simple-greet") + .request(JsonObject.class) + .await(Duration.ofSeconds(5)); + assertThat(jsonObject.getString("message"), is("Hello World!")); + } + + @Test + void testGreetings() { + JsonObject jsonObject; + WebClientResponse response; + + jsonObject = webClient.get() + .path("/greet/Joe") + .request(JsonObject.class) + .await(Duration.ofSeconds(5)); + assertThat(jsonObject.getString("message"), is("Hello Joe!")); + + response = webClient.put() + .path("/greet/greeting") + .submit(TEST_JSON_OBJECT) + .await(Duration.ofSeconds(5)); + assertThat(response.status().code(), is(204)); + + jsonObject = webClient.get() + .path("/greet/Joe") + .request(JsonObject.class) + .await(Duration.ofSeconds(5)); + assertThat(jsonObject.getString("message"), is("Hola Joe!")); + } + +} diff --git a/helidon-se/src/test/resources/application.yaml b/helidon-se/src/test/resources/application.yaml new file mode 100644 index 0000000..996b48a --- /dev/null +++ b/helidon-se/src/test/resources/application.yaml @@ -0,0 +1,10 @@ +server: + port: 8180 + host: 0.0.0.0 + +app: + greeting: "Hello" + +security: + enabled: false + diff --git a/helidon_mp/Dockerfile.jlink b/helidon_mp/Dockerfile.jlink deleted file mode 100644 index bdc4877..0000000 --- a/helidon_mp/Dockerfile.jlink +++ /dev/null @@ -1,26 +0,0 @@ - -# 1st stage, build the app -FROM maven:3.8.4-openjdk-17-slim as build - -WORKDIR /helidon - -# Create a first layer to cache the "Maven World" in the local repository. -# Incremental docker builds will always resume after that, unless you update -# the pom -ADD pom.xml . -RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip - -# Do the Maven build to create the custom Java Runtime Image -# Incremental docker builds will resume here when you change sources -ADD src src -# Don't generate CDS archive to work around JVM bug https://bugs.openjdk.org/browse/JDK-8274944 -RUN mvn package -Pjlink-image -DskipTests -Djlink.image.addClassDataSharingArchive=false -RUN echo "done!" - -# 2nd stage, build the final image with the JRI built in the 1st stage - -FROM debian:stretch-slim -WORKDIR /helidon -COPY --from=build /helidon/target/helidon-quickstart-mp-jri ./ -ENTRYPOINT ["/bin/bash", "/helidon/bin/start"] -EXPOSE 8080 diff --git a/helidon_mp/pom.xml b/helidon_mp/pom.xml deleted file mode 100644 index e940b02..0000000 --- a/helidon_mp/pom.xml +++ /dev/null @@ -1,316 +0,0 @@ - - - 4.0.0 - - io.helidon.applications - helidon-mp - 3.2.0 - - - io.helidon.examples - helidon-quickstart-mp - 1.0-SNAPSHOT - - - 0.9.12 - 20 - 20 - io.helidon.microprofile.cdi.Main - 6.4.0 - - - - - my.test.eureka - policy - 1.0-SNAPSHOT - compile - - - my.test.eureka - user-store - 1.0-SNAPSHOT - compile - - - my.test.eureka - service-bus - 1.0-SNAPSHOT - compile - - - io.helidon.microprofile.bundles - helidon-microprofile-core - - - io.helidon.microprofile.openapi - helidon-microprofile-openapi - - - org.eclipse.microprofile.metrics - microprofile-metrics-api - - - io.helidon.microprofile.metrics - helidon-microprofile-metrics - - - io.helidon.microprofile.health - helidon-microprofile-health - - - jakarta.json.bind - jakarta.json.bind-api - - - org.glassfish.jersey.media - jersey-media-json-binding - runtime - - - org.jboss - jandex - runtime - - - jakarta.activation - jakarta.activation-api - runtime - - - com.fasterxml.jackson.core - jackson-annotations - 2.14.2 - - - com.fasterxml.jackson.core - jackson-databind - 2.14.2 - - - - org.junit.jupiter - junit-jupiter-api - test - - - io.helidon.microprofile.tests - helidon-microprofile-tests-junit5 - test - - - org.hamcrest - hamcrest-all - test - - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-libs - - - - - org.jboss.jandex - jandex-maven-plugin - - - make-index - - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.2 - - - - true - ${mainClass} - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - package - - single - - - - - - - true - ${mainClass} - - - - jar-with-dependencies - - - - - - - - native - - - - org.graalvm.buildtools - native-maven-plugin - ${native.maven.plugin.version} - true - - - build-native - - build - - package - - - - - false - - -H:DashboardDump=fortune -H:+DashboardAll - - - true - - - - - - - - - - - diff --git a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java b/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java deleted file mode 100644 index 5250be8..0000000 --- a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetResource.java +++ /dev/null @@ -1,115 +0,0 @@ - -package io.helidon.examples.quickstart.mp; - -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.PUT; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.PathParam; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; - -import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; - -/** - * A simple JAX-RS resource to greet you. Examples: - * - * Get default greeting message: - * curl -X GET http://localhost:8080/greet - * - * Get greeting message for Joe: - * curl -X GET http://localhost:8080/greet/Joe - * - * Change greeting - * curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Howdy"}' http://localhost:8080/greet/greeting - * - * The message is returned as a JSON object. - */ -@Path("/greet") -@RequestScoped -public class GreetResource { - - /** - * The greeting message provider. - */ - private final GreetingProvider greetingProvider; - - /** - * Using constructor injection to get a configuration property. - * By default this gets the value from META-INF/microprofile-config - * - * @param greetingConfig the configured greeting message - */ - @Inject - public GreetResource(GreetingProvider greetingConfig) { - this.greetingProvider = greetingConfig; - } - - /** - * Return a worldly greeting message. - * - * @return {@link Message} - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Message getDefaultMessage() { - return createResponse("World"); - } - - /** - * Return a greeting message using the name that was provided. - * - * @param name the name to greet - * @return {@link Message} - */ - @Path("/{name}") - @GET - @Produces(MediaType.APPLICATION_JSON) - public Message getMessage(@PathParam("name") String name) { - return createResponse(name); - } - - /** - * Set the greeting to use in future messages. - * - * @param message Message containing the new greeting - * @return {@link Response} - */ - @Path("/greeting") - @PUT - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @RequestBody(name = "greeting", - required = true, - content = @Content(mediaType = "application/json", - schema = @Schema(type = SchemaType.OBJECT, requiredProperties = { "greeting" }))) - @APIResponses({ - @APIResponse(name = "normal", responseCode = "204", description = "Greeting updated"), - @APIResponse(name = "missing 'greeting'", responseCode = "400", - description = "JSON did not contain setting for 'greeting'")}) - public Response updateGreeting(Message message) { - - if (message.getGreeting() == null || message.getGreeting().isEmpty()) { - Message error = new Message(); - error.setMessage("No greeting provided"); - return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); - } - - greetingProvider.setMessage(message.getGreeting()); - return Response.status(Response.Status.NO_CONTENT).build(); - } - - private Message createResponse(String who) { - String msg = String.format("%s %s!", greetingProvider.getMessage(), who); - - return new Message(msg); - } -} diff --git a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetingProvider.java b/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetingProvider.java deleted file mode 100644 index adc3d49..0000000 --- a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/GreetingProvider.java +++ /dev/null @@ -1,35 +0,0 @@ - -package io.helidon.examples.quickstart.mp; - -import java.util.concurrent.atomic.AtomicReference; - -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; - -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * Provider for greeting message. - */ -@ApplicationScoped -public class GreetingProvider { - private final AtomicReference message = new AtomicReference<>(); - - /** - * Create a new greeting provider, reading the message from configuration. - * - * @param message greeting to use - */ - @Inject - public GreetingProvider(@ConfigProperty(name = "app.greeting") String message) { - this.message.set(message); - } - - String getMessage() { - return message.get(); - } - - void setMessage(String message) { - this.message.set(message); - } -} diff --git a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/Message.java b/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/Message.java deleted file mode 100644 index 87e1ce5..0000000 --- a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/Message.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.helidon.examples.quickstart.mp; - - -public class Message { - - private String message; - - private String greeting; - - public Message() { - } - - public Message(String message) { - this.message = message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getMessage() { - return this.message; - } - - public void setGreeting(String greeting) { - this.greeting = greeting; - } - - public String getGreeting() { - return this.greeting; - } -} diff --git a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/SimpleGreetResource.java b/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/SimpleGreetResource.java deleted file mode 100644 index 4b790cf..0000000 --- a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/SimpleGreetResource.java +++ /dev/null @@ -1,69 +0,0 @@ - -package io.helidon.examples.quickstart.mp; - -import java.util.Collections; - -import org.eclipse.microprofile.metrics.MetricUnits; -import org.eclipse.microprofile.metrics.annotation.Counted; -import org.eclipse.microprofile.metrics.annotation.Timed; -import jakarta.ws.rs.PathParam; - -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; - -import org.eclipse.microprofile.config.inject.ConfigProperty; - -/** - * A simple JAX-RS resource to greet you. Examples: - * - * Get default greeting message: - * curl -X GET http://localhost:8080/simple-greet - * - * The message is returned as a JSON object. - */ -@Path("/simple-greet") -public class SimpleGreetResource { - - private static final String PERSONALIZED_GETS_COUNTER_NAME = "personalizedGets"; - private static final String PERSONALIZED_GETS_COUNTER_DESCRIPTION = "Counts personalized GET operations"; - private static final String GETS_TIMER_NAME = "allGets"; - private static final String GETS_TIMER_DESCRIPTION = "Tracks all GET operations"; private final String message; - - @Inject - public SimpleGreetResource(@ConfigProperty(name = "app.greeting") String message) { - this.message = message; - } - - /** - * Return a worldly greeting message. - * - * @return {@link Message} - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Message getDefaultMessage() { - String msg = String.format("%s %s!", message, "World"); - Message message = new Message(); - message.setMessage(msg); - return message; - } - - - @Path("/{name}") - @GET - @Produces(MediaType.APPLICATION_JSON) - @Counted(name = PERSONALIZED_GETS_COUNTER_NAME, - absolute = true, - description = PERSONALIZED_GETS_COUNTER_DESCRIPTION) - @Timed(name = GETS_TIMER_NAME, - description = GETS_TIMER_DESCRIPTION, - unit = MetricUnits.SECONDS, - absolute = true) - public String getMessage(@PathParam("name") String name) { - return String.format("Hello %s", name); - } -} diff --git a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/package-info.java b/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/package-info.java deleted file mode 100644 index 95b328a..0000000 --- a/helidon_mp/src/main/java/io/helidon/examples/quickstart/mp/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ - -package io.helidon.examples.quickstart.mp; diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java deleted file mode 100644 index c8520f6..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/AuthenticationResponseModel.java +++ /dev/null @@ -1,12 +0,0 @@ -package my.test.rest.incomings.controllers; - -import jakarta.ws.rs.core.Response; - -public interface AuthenticationResponseModel { - - Response renderModel(); - - record Fake(Response renderModel) implements AuthenticationResponseModel { - - } -} diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java deleted file mode 100644 index ef2fe24..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/CreationUserResponseModel.java +++ /dev/null @@ -1,12 +0,0 @@ -package my.test.rest.incomings.controllers; - -import jakarta.ws.rs.core.Response; - -public interface CreationUserResponseModel { - - Response renderModel(); - - record Fake(Response renderModel) implements CreationUserResponseModel { - - } -} diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java deleted file mode 100644 index 5b8a740..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/AuthenticationService.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.api; - -import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.PUT; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; -import my.test.rest.incomings.controllers.api.dto.AuthInfo; -import my.test.rest.incomings.controllers.api.dto.Authentication; -import my.test.rest.incomings.controllers.api.dto.TokenPair; - -import jakarta.validation.Valid; -import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; - -@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaHelidonServerCodegen") -public interface AuthenticationService { - - @PUT - @Path("/create") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @RequestBody(name = "greeting", - required = true, - content = @Content(mediaType = "application/json", - schema = @Schema(type = SchemaType.OBJECT, requiredProperties = {"greeting"}))) - @APIResponses({ - @APIResponse(name = "normal", responseCode = "200", description = "Greeting updated"), - @APIResponse(name = "incorrect name or password", responseCode = "403", - description = "incorrect name or password") - }) - Response create(@Valid AuthInfo authInfo); - - @POST - @Path("/login") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - @APIResponses({ - @APIResponse(name = "normal", responseCode = "200", description = "Greeting updated", - content = {@Content(mediaType = "application/json", - schema = @Schema(implementation = Authentication.class))}), - @APIResponse(name = "incorrect name or password", responseCode = "401", - description = "incorrect name or password"), - @APIResponse(name = "no permissions", responseCode = "403", - description = "Login and password are correct, but the user does not have a valid role") - }) - Response login(@Valid @NotNull AuthInfo authInfo); - - @GET - @Path("/logout") - void logout(); - - @GET - @Path("/tokens/refresh") - @Produces({"application/json"}) - TokenPair refreshTokens(); -} diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java deleted file mode 100644 index 1b3b710..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/AuthInfo.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.api.dto; - - -public class AuthInfo { - - private String userName; - - /** - * MD5 hashed password - **/ - private String passwordHash; - - /** - * Get userName - * @return userName - **/ - public String getUserName() { - return userName; - } - - /** - * Set userName - **/ - public void setUserName(String userName) { - this.userName = userName; - } - - public AuthInfo userName(String userName) { - this.userName = userName; - return this; - } - - /** - * MD5 hashed password - * @return passwordHash - **/ - public String getPasswordHash() { - return passwordHash; - } - - /** - * Set passwordHash - **/ - public void setPasswordHash(String passwordHash) { - this.passwordHash = passwordHash; - } - - public AuthInfo passwordHash(String passwordHash) { - this.passwordHash = passwordHash; - return this; - } - - - /** - * Create a string representation of this pojo. - **/ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class AuthInfo {\n"); - - sb.append(" userName: ").append(toIndentedString(userName)).append("\n"); - sb.append(" passwordHash: ").append(toIndentedString(passwordHash)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private static String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } -} - diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java deleted file mode 100644 index ffb7d9c..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Authentication.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.api.dto; - -import java.util.List; - - -public class Authentication { - - private Token accessToken; - - private Token refreshToken; - - /** - * Логин пользователя - **/ - private String username; - - /** - * Имя пользователя - **/ - private String firstName; - - /** - * Фамилия пользователя - **/ - private String lastName; - - /** - * Роли пользователя (допустимые для использования обладающие максимальным уровнем) - **/ - private List roles = null; - - /** - * Get accessToken - * @return accessToken - **/ - public Token getAccessToken() { - return accessToken; - } - - /** - * Set accessToken - **/ - public void setAccessToken(Token accessToken) { - this.accessToken = accessToken; - } - - public Authentication accessToken(Token accessToken) { - this.accessToken = accessToken; - return this; - } - - /** - * Get refreshToken - * @return refreshToken - **/ - public Token getRefreshToken() { - return refreshToken; - } - - /** - * Set refreshToken - **/ - public void setRefreshToken(Token refreshToken) { - this.refreshToken = refreshToken; - } - - public Authentication refreshToken(Token refreshToken) { - this.refreshToken = refreshToken; - return this; - } - - /** - * Логин пользователя - * @return username - **/ - public String getUsername() { - return username; - } - - /** - * Set username - **/ - public void setUsername(String username) { - this.username = username; - } - - public Authentication username(String username) { - this.username = username; - return this; - } - - /** - * Имя пользователя - * @return firstName - **/ - public String getFirstName() { - return firstName; - } - - /** - * Set firstName - **/ - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public Authentication firstName(String firstName) { - this.firstName = firstName; - return this; - } - - /** - * Фамилия пользователя - * @return lastName - **/ - public String getLastName() { - return lastName; - } - - /** - * Set lastName - **/ - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Authentication lastName(String lastName) { - this.lastName = lastName; - return this; - } - - /** - * Роли пользователя (допустимые для использования обладающие максимальным уровнем) - * @return roles - **/ - public List getRoles() { - return roles; - } - - /** - * Set roles - **/ - public void setRoles(List roles) { - this.roles = roles; - } - - public Authentication roles(List roles) { - this.roles = roles; - return this; - } - - public Authentication addRolesItem(String rolesItem) { - this.roles.add(rolesItem); - return this; - } - - - /** - * Create a string representation of this pojo. - **/ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class Authentication {\n"); - - sb.append(" accessToken: ").append(toIndentedString(accessToken)).append("\n"); - sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n"); - sb.append(" username: ").append(toIndentedString(username)).append("\n"); - sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); - sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); - sb.append(" roles: ").append(toIndentedString(roles)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private static String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } -} - diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java deleted file mode 100644 index 55dc8ae..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/Token.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.api.dto; - -import java.time.OffsetDateTime; -import jakarta.validation.constraints.*; - - -public class Token { - - private String value; - - private OffsetDateTime expirationDateTime; - - /** - * Get value - * @return value - **/ - public String getValue() { - return value; - } - - /** - * Set value - **/ - public void setValue(String value) { - this.value = value; - } - - public Token value(String value) { - this.value = value; - return this; - } - - /** - * Get expirationDateTime - * @return expirationDateTime - **/ - @Pattern(regexp="DD-MM-YYYY HH:mm:ss") public OffsetDateTime getExpirationDateTime() { - return expirationDateTime; - } - - /** - * Set expirationDateTime - **/ - public void setExpirationDateTime(OffsetDateTime expirationDateTime) { - this.expirationDateTime = expirationDateTime; - } - - public Token expirationDateTime(OffsetDateTime expirationDateTime) { - this.expirationDateTime = expirationDateTime; - return this; - } - - - /** - * Create a string representation of this pojo. - **/ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class Token {\n"); - - sb.append(" value: ").append(toIndentedString(value)).append("\n"); - sb.append(" expirationDateTime: ").append(toIndentedString(expirationDateTime)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private static String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } -} - diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java deleted file mode 100644 index d34119b..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/TokenPair.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.api.dto; - - -public class TokenPair { - - private Token accessToken; - - private Token refreshToken; - - /** - * Get accessToken - * @return accessToken - **/ - public Token getAccessToken() { - return accessToken; - } - - /** - * Set accessToken - **/ - public void setAccessToken(Token accessToken) { - this.accessToken = accessToken; - } - - public TokenPair accessToken(Token accessToken) { - this.accessToken = accessToken; - return this; - } - - /** - * Get refreshToken - * @return refreshToken - **/ - public Token getRefreshToken() { - return refreshToken; - } - - /** - * Set refreshToken - **/ - public void setRefreshToken(Token refreshToken) { - this.refreshToken = refreshToken; - } - - public TokenPair refreshToken(Token refreshToken) { - this.refreshToken = refreshToken; - return this; - } - - - /** - * Create a string representation of this pojo. - **/ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class TokenPair {\n"); - - sb.append(" accessToken: ").append(toIndentedString(accessToken)).append("\n"); - sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private static String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } -} - diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java deleted file mode 100644 index 23bd43f..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/api/dto/User.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.api.dto; - -import java.util.List; - - -public class User { - - /** - * Логин пользователя - **/ - private String username; - - /** - * Имя пользователя - **/ - private String firstName; - - /** - * Фамилия пользователя - **/ - private String lastName; - - /** - * Роли пользователя (допустимые для использования обладающие максимальным уровнем) - **/ - private List roles = null; - - /** - * Логин пользователя - * @return username - **/ - public String getUsername() { - return username; - } - - /** - * Set username - **/ - public void setUsername(String username) { - this.username = username; - } - - public User username(String username) { - this.username = username; - return this; - } - - /** - * Имя пользователя - * @return firstName - **/ - public String getFirstName() { - return firstName; - } - - /** - * Set firstName - **/ - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public User firstName(String firstName) { - this.firstName = firstName; - return this; - } - - /** - * Фамилия пользователя - * @return lastName - **/ - public String getLastName() { - return lastName; - } - - /** - * Set lastName - **/ - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public User lastName(String lastName) { - this.lastName = lastName; - return this; - } - - /** - * Роли пользователя (допустимые для использования обладающие максимальным уровнем) - * @return roles - **/ - public List getRoles() { - return roles; - } - - /** - * Set roles - **/ - public void setRoles(List roles) { - this.roles = roles; - } - - public User roles(List roles) { - this.roles = roles; - return this; - } - - public User addRolesItem(String rolesItem) { - this.roles.add(rolesItem); - return this; - } - - - /** - * Create a string representation of this pojo. - **/ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class User {\n"); - - sb.append(" username: ").append(toIndentedString(username)).append("\n"); - sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); - sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); - sb.append(" roles: ").append(toIndentedString(roles)).append("\n"); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces - * (except the first line). - */ - private static String toIndentedString(Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } -} - diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java deleted file mode 100644 index 3be1083..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/impl/AuthenticationServiceImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Аутентификация - * `Design First`, `Validated` - * - * The version of the OpenAPI document: 1.0.0 - * Contact: my_test@mail.ru - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package my.test.rest.incomings.controllers.impl; - -import jakarta.inject.Inject; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.Valid; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.core.Response; -import my.test.authorization.rules.AuthFactory; -import my.test.authorization.rules.AuthenticateUserInteractor; -import my.test.authorization.rules.CreateUserInteractor; -import my.test.authorization.rules.ResponseFactory; -import my.test.rest.incomings.controllers.api.AuthenticationService; -import my.test.rest.incomings.controllers.api.dto.AuthInfo; -import my.test.rest.incomings.controllers.api.dto.TokenPair; - -@Path("/api") -@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaHelidonServerCodegen") -public class AuthenticationServiceImpl implements AuthenticationService { - - private final AuthFactory authFactory; - private final ResponseFactory responseFactory; - - @Inject - public AuthenticationServiceImpl(AuthFactory authFactory, ResponseFactory responseFactory) { - this.authFactory = authFactory; - this.responseFactory = responseFactory; - } - - public Response create(@Valid AuthInfo authInfo) { - CreateUserInteractor createUserInteractor = authFactory - .createNewUserInteractor(authInfo.getUserName(), authInfo.getPasswordHash(), - responseFactory.createCreationUserResponsePresenter()); - return createUserInteractor.createNewUserAndGetPresenter().renderModel(); - } - - public Response login(@Valid @NotNull AuthInfo authInfo) { - AuthenticateUserInteractor authInteractor = authFactory.createAuthenticateUserInteractor( - authInfo.getUserName(), authInfo.getPasswordHash(), - responseFactory.createAuthenticationResponsePresenter()); - return authInteractor.authenticateAndGetPresenter().renderModel(); - } - - public void logout() { - } - - public TokenPair refreshTokens() { - TokenPair result = null; - return result; - } -} diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java deleted file mode 100644 index 57328f6..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/authentication/AuthenticationUserResponseModelImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -package my.test.rest.incomings.controllers.presenters.authentication; - -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.core.Response.Status; -import java.time.LocalDateTime; -import java.time.ZoneId; -import my.test.authorization.domain.api.AuthenticationResponseFactory.UserData; -import my.test.authorization.rules.AuthenticationResponsePresenter; -import my.test.rest.incomings.controllers.api.dto.Authentication; -import my.test.rest.incomings.controllers.api.dto.Token; - -public class AuthenticationUserResponseModelImpl implements AuthenticationResponsePresenter, UserData { - - private final Authentication authentication; - private Response model; - - public AuthenticationUserResponseModelImpl() { - authentication = new Authentication().accessToken(new Token()); - model = Response.status(Status.OK).entity(authentication).build(); - } - - @Override - public void userNotFound() { - model = Response.status(Status.UNAUTHORIZED).entity("User not found").build(); - } - - @Override - public void incorrectPassword() { - model = Response.status(Status.UNAUTHORIZED).entity("Invalid password").build(); - } - - @Override - public UserData success() { - return this; - } - - @Override - public void writeUserName(String name) { - authentication.username(name); - } - - @Override - public void writeToken(String token) { - authentication.getAccessToken().value(token); - } - - @Override - public void writeTokenExpirationDate(LocalDateTime expirationDateTime) { - authentication.getAccessToken() - .expirationDateTime(expirationDateTime.atZone(ZoneId.systemDefault()).toOffsetDateTime()); - } - - @Override - public Response renderModel() { - return model; - } -} diff --git a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java b/helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java deleted file mode 100644 index 741c1b9..0000000 --- a/helidon_mp/src/main/java/my/test/rest/incomings/controllers/presenters/creation/CreationUserResponseModelImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -package my.test.rest.incomings.controllers.presenters.creation; - -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.core.Response.Status; -import java.time.LocalDateTime; -import java.time.ZoneId; -import my.test.authorization.domain.api.CreationUserResponseFactory.UserData; -import my.test.authorization.rules.CreationUserResponsePresenter; -import my.test.rest.incomings.controllers.api.dto.Authentication; -import my.test.rest.incomings.controllers.api.dto.Token; - -public class CreationUserResponseModelImpl implements CreationUserResponsePresenter, UserData { - - private final Authentication authentication; - private Response model; - - public CreationUserResponseModelImpl() { - authentication = new Authentication().accessToken(new Token()); - model = Response.status(Status.OK).entity(authentication).build(); - } - - @Override - public void userAlreadyExists() { - model = Response.status(Response.Status.FORBIDDEN).entity("User already exists").build(); - } - - @Override - public void invalidUserNameField() { - model = Response.status(Response.Status.FORBIDDEN).entity("Invalid user name").build(); - } - - @Override - public void invalidPasswordHashField() { - model = Response.status(Response.Status.FORBIDDEN).entity("Invalid user password").build(); - } - - @Override - public UserData success() { - return this; - } - - @Override - public void writeUserName(String name) { - authentication.username(name); - } - - @Override - public void writeToken(String token) { - authentication.getAccessToken().value(token); - } - - @Override - public void writeTokenExpirationDate(LocalDateTime expirationDateTime) { - authentication.getAccessToken() - .expirationDateTime(expirationDateTime.atZone(ZoneId.systemDefault()).toOffsetDateTime()); - } - - @Override - public Response renderModel() { - return model; - } -} diff --git a/helidon_mp/src/main/resources/META-INF/beans.xml b/helidon_mp/src/main/resources/META-INF/beans.xml deleted file mode 100644 index 7605752..0000000 --- a/helidon_mp/src/main/resources/META-INF/beans.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - diff --git a/helidon_mp/src/main/resources/META-INF/microprofile-config.properties b/helidon_mp/src/main/resources/META-INF/microprofile-config.properties deleted file mode 100644 index 6608363..0000000 --- a/helidon_mp/src/main/resources/META-INF/microprofile-config.properties +++ /dev/null @@ -1,10 +0,0 @@ -# Microprofile server properties -server.port=8080 -server.host=0.0.0.0 - -# Change the following to true to enable the optional MicroProfile Metrics REST.request metrics -metrics.rest-request.enabled=false - -# Application properties. This is the default greeting -app.greeting=Hello - diff --git a/helidon_mp/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-mp/native-image.properties b/helidon_mp/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-mp/native-image.properties deleted file mode 100644 index 48e4c58..0000000 --- a/helidon_mp/src/main/resources/META-INF/native-image/io.helidon.examples/helidon-quickstart-mp/native-image.properties +++ /dev/null @@ -1 +0,0 @@ -Args=--initialize-at-build-time=io.helidon.examples.quickstart.mp diff --git a/helidon_mp/src/main/resources/application.yaml b/helidon_mp/src/main/resources/application.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/helidon_mp/src/test/java/io/helidon/examples/quickstart/mp/MainTest.java b/helidon_mp/src/test/java/io/helidon/examples/quickstart/mp/MainTest.java deleted file mode 100644 index 21ed41d..0000000 --- a/helidon_mp/src/test/java/io/helidon/examples/quickstart/mp/MainTest.java +++ /dev/null @@ -1,94 +0,0 @@ - -package io.helidon.examples.quickstart.mp; - -import org.eclipse.microprofile.metrics.Counter; -import org.eclipse.microprofile.metrics.MetricRegistry; -import jakarta.inject.Inject; -import jakarta.ws.rs.client.WebTarget; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.client.Entity; -import jakarta.ws.rs.core.MediaType; - -import io.helidon.microprofile.tests.junit5.HelidonTest; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -@HelidonTest -class MainTest { - - @Inject - private MetricRegistry registry; - @Inject - private WebTarget target; - - - @Test - void testMicroprofileMetrics() { - String message = target.path("simple-greet/Joe") - .request() - .get(String.class); - - assertThat(message, is("Hello Joe")); - Counter counter = registry.counter("personalizedGets"); - double before = counter.getCount(); - - message = target.path("simple-greet/Eric") - .request() - .get(String.class); - - assertThat(message, is("Hello Eric")); - double after = counter.getCount(); - assertEquals(1d, after - before, "Difference in personalized greeting counter between successive calls"); - } - @Test - void testMetrics() { - Response response = target - .path("metrics") - .request() - .get(); - assertThat(response.getStatus(), is(200)); - } - @Test - void testHealth() { - Response response = target - .path("health") - .request() - .get(); - assertThat(response.getStatus(), is(200)); - } - @Test - void testGreet() { - Message message = target - .path("simple-greet") - .request() - .get(Message.class); - assertThat(message.getMessage(), is("Hello World!")); - } - @Test - void testGreetings() { - Message jsonMessage = target - .path("greet/Joe") - .request() - .get(Message.class); - assertThat(jsonMessage.getMessage(), is("Hello Joe!")); - - try (Response r = target - .path("greet/greeting") - .request() - .put(Entity.entity("{\"greeting\" : \"Hola\"}", MediaType.APPLICATION_JSON))) { - assertThat(r.getStatus(), is(204)); - } - - jsonMessage = target - .path("greet/Jose") - .request() - .get(Message.class); - assertThat(jsonMessage.getMessage(), is("Hola Jose!")); - } - } diff --git a/helidon_mp/src/test/resources/application.yaml b/helidon_mp/src/test/resources/application.yaml deleted file mode 100644 index 94f3451..0000000 --- a/helidon_mp/src/test/resources/application.yaml +++ /dev/null @@ -1,2 +0,0 @@ -security: - enabled: false \ No newline at end of file diff --git a/oas/pom.xml b/oas/pom.xml index 7b8d783..fd587cc 100644 --- a/oas/pom.xml +++ b/oas/pom.xml @@ -4,8 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + my.test + parent-pom + 1.0-SNAPSHOT + ../pom.xml + - my.test.eureka + my.test.spring oas 1.0-SNAPSHOT @@ -36,7 +42,7 @@ - my.test.eureka + my.test policy 1.0-SNAPSHOT compile diff --git a/policy/pom.xml b/policy/pom.xml index f403cd0..9583538 100644 --- a/policy/pom.xml +++ b/policy/pom.xml @@ -4,7 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - my.test.eureka + + my.test + parent-pom + 1.0-SNAPSHOT + ../pom.xml + + + my.test jar policy 1.0-SNAPSHOT @@ -14,9 +21,6 @@ UTF-8 - 20 - 20 - 20 diff --git a/policy/src/test/java/my/test/authorization/domain/impl/AuthenticationPolicyImplTest.java b/policy/src/test/java/my/test/authorization/domain/impl/AuthenticationPolicyImplTest.java index 1aa663f..502dbc6 100644 --- a/policy/src/test/java/my/test/authorization/domain/impl/AuthenticationPolicyImplTest.java +++ b/policy/src/test/java/my/test/authorization/domain/impl/AuthenticationPolicyImplTest.java @@ -16,7 +16,6 @@ public void unsuccessAuthenticate() { new UserBuilder.Fake(new AuthenticateUser.Fake(AuthenticationResult.UNSUCCESS), null), createUserInfo(), null, null); subj.authenticate(); - } private UserInfo createUserInfo() { diff --git a/pom.xml b/pom.xml index 56a1894..2b74bdb 100644 --- a/pom.xml +++ b/pom.xml @@ -2,23 +2,19 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.0.5 - - - my.test.eureka + + my.test parent-pom - 0.0.1-SNAPSHOT + 1.0-SNAPSHOT pom test project parent pom UTF-8 - 19 - 2022.0.1 + 20 + 20 + 20 @@ -29,66 +25,7 @@ policy user-store service-bus - + helidon-se - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - false - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - false - - - diff --git a/service-bus/pom.xml b/service-bus/pom.xml index 9d04cd3..0c38416 100644 --- a/service-bus/pom.xml +++ b/service-bus/pom.xml @@ -4,7 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - my.test.eureka + + my.test + parent-pom + 1.0-SNAPSHOT + ../pom.xml + + + my.test jar service-bus 1.0-SNAPSHOT @@ -14,9 +21,6 @@ UTF-8 - 20 - 20 - 20 @@ -33,7 +37,7 @@ test - my.test.eureka + my.test policy 1.0-SNAPSHOT compile diff --git a/starter/pom.xml b/starter/pom.xml index 8f64ed2..83cbe55 100644 --- a/starter/pom.xml +++ b/starter/pom.xml @@ -5,10 +5,10 @@ 4.0.0 - my.test.eureka - parent-pom - 0.0.1-SNAPSHOT - ../pom.xml + org.springframework.boot + spring-boot-starter-parent + 3.0.5 + spring-starter @@ -17,27 +17,47 @@ spring-starter Demo project spring starter + + UTF-8 + 21 + 21 + 21 + 2022.0.1 + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + - my.test.eureka + my.test.spring oas 1.0-SNAPSHOT compile - my.test.eureka + my.test policy 1.0-SNAPSHOT compile - my.test.eureka + my.test user-store 1.0-SNAPSHOT compile - my.test.eureka + my.test service-bus 1.0-SNAPSHOT compile diff --git a/user-store/pom.xml b/user-store/pom.xml index 05f893d..fc629ca 100644 --- a/user-store/pom.xml +++ b/user-store/pom.xml @@ -4,7 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - my.test.eureka + + my.test + parent-pom + 1.0-SNAPSHOT + ../pom.xml + + + my.test jar user-store 1.0-SNAPSHOT @@ -14,14 +21,11 @@ UTF-8 - 20 - 20 - 20 - my.test.eureka + my.test policy 1.0-SNAPSHOT compile