diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index ab4acbd..6d4382d 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -81,10 +81,6 @@ jobs: file: ./Dockerfile platforms: linux/amd64 push: ${{ github.event_name != 'pull_request' }} - # tags: ghcr.io/${{ github.repository_owner }}/its-battistar-express:latest - # TODO: tag with release version - # tags: ${{ steps.meta.outputs.tags }}, ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest - # TODO: add latest tag tags: | ${{ steps.meta.outputs.tags }} ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest diff --git a/Dockerfile b/Dockerfile index d086b9d..d0f4016 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,6 @@ FROM eclipse-temurin:21 as BUILD_IMAGE -# TODO: fix label -# LABEL org.opencontainers.image.source https://github.com/gipo355/template-fastify - -# TODO: provide watch mode for development -# the cmd is ./gradlew war on file change -# which outputs to build/libs/*.war - # VULN: should probably not run as root # VULN: should probably move to alpine, preferably embedding tomcat in the app diff --git a/build.gradle b/build.gradle index ce26f10..c7447b9 100644 --- a/build.gradle +++ b/build.gradle @@ -41,10 +41,8 @@ dependencies { rewrite("org.openrewrite.recipe:rewrite-java-security:2.8.1") - // app implementation(group: 'org.slf4j', name: 'slf4j-api', version: '2+') - // NOTE: why require tomcat 9? why is this a dependency if it's a war to be deployed on an external tomcat? compileOnly(group: 'org.apache.tomcat', name: 'tomcat-catalina', version: "${TOMCAT_VERSION}") implementation('javax.xml.bind:jaxb-api:2.3.1') @@ -225,10 +223,10 @@ jacocoTestReport { } } - -// war { -// dependsOn 'test' -// } +war { + dependsOn 'check' + dependsOn 'test' +} task cleanEclipse(type: Delete, overwrite: true) { delete '.project' diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 0000000..3fa6b4e --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,9 @@ +## MULTI STAGE + +FROM tomcat:9-jdk21-temurin-jammy + +COPY build/libs/* /usr/local/tomcat/webapps + +EXPOSE ${PORT} + +CMD ["catalina.sh", "run"] diff --git a/docker/builder.Dockerfile b/docker/builder.Dockerfile index caea505..384fa23 100644 --- a/docker/builder.Dockerfile +++ b/docker/builder.Dockerfile @@ -4,13 +4,6 @@ FROM eclipse-temurin:21 # TODO: must provide gradle otherwise it downloads every restart?? -# TODO: fix label -# LABEL org.opencontainers.image.source https://github.com/gipo355/template-fastify - -# TODO: provide watch mode for development -# the cmd is ./gradlew war on file change -# which outputs to build/libs/*.war - # VULN: should probably not run as root # initialize defaults for overriding through --env diff --git a/src/main/java/com/smi/xxx/rest/base/Application.java b/src/main/java/com/smi/xxx/rest/base/App.java similarity index 53% rename from src/main/java/com/smi/xxx/rest/base/Application.java rename to src/main/java/com/smi/xxx/rest/base/App.java index 47eed71..4ae398a 100644 --- a/src/main/java/com/smi/xxx/rest/base/Application.java +++ b/src/main/java/com/smi/xxx/rest/base/App.java @@ -5,14 +5,21 @@ import javax.ws.rs.ApplicationPath; /** - * @author Pavel Bucek + * Main application class. + * + * @author Pavel Bucek. */ @ApplicationPath("/") -public class Application extends javax.ws.rs.core.Application { +public class App extends javax.ws.rs.core.Application { + /** + * Set of classes that are root resources. + * + * @return set of classes + */ @Override public Set> getClasses() { - final Set> classes = new HashSet>(); + final Set> classes = new HashSet<>(); // register root resource classes.add(BaseService.class); diff --git a/src/main/java/com/smi/xxx/rest/base/BaseService.java b/src/main/java/com/smi/xxx/rest/base/BaseService.java index a8f8801..9bd4490 100644 --- a/src/main/java/com/smi/xxx/rest/base/BaseService.java +++ b/src/main/java/com/smi/xxx/rest/base/BaseService.java @@ -10,6 +10,7 @@ import javax.ws.rs.core.Response; import org.glassfish.jersey.media.multipart.FormDataParam; +/** Base service. */ @Path("/base") public class BaseService { @@ -27,7 +28,7 @@ public Response get() { public Response login( @FormParam("username") String username, @FormParam("password") String password) { - return Response.ok("Bearer " + username + "__" + password).build(); + return Response.ok(createToken(username, password)).build(); } // login @POST @@ -37,7 +38,7 @@ public Response login( public Response loginFormData( @FormDataParam("username") String username, @FormDataParam("password") String password) { - return Response.ok("Bearer " + username + "__" + password).build(); + return Response.ok(createToken(username, password)).build(); } // login @POST @@ -46,7 +47,7 @@ public Response loginFormData( @Path("/login") public Response loginByModel(LoginModel datas) { - return Response.ok("Bearer " + datas.username + "__" + datas.password).build(); + return Response.ok(createToken(datas.username, datas.password)).build(); } // loginByModel @POST @@ -55,4 +56,8 @@ public Response health() { return Response.ok().build(); } // health + + private String createToken(String username, String password) { + return "Bearer " + username + "__" + password; + } } // LoginService diff --git a/src/main/java/com/smi/xxx/rest/base/CorsFilter.java b/src/main/java/com/smi/xxx/rest/base/CorsFilter.java index 84e53eb..565e868 100644 --- a/src/main/java/com/smi/xxx/rest/base/CorsFilter.java +++ b/src/main/java/com/smi/xxx/rest/base/CorsFilter.java @@ -14,6 +14,7 @@ import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; +/** CORS Filter. */ @Provider public class CorsFilter implements Filter, ContainerResponseFilter, ExceptionMapper { diff --git a/src/main/java/com/smi/xxx/rest/base/JwtFilter.java b/src/main/java/com/smi/xxx/rest/base/JwtFilter.java index fbb11da..31936c5 100644 --- a/src/main/java/com/smi/xxx/rest/base/JwtFilter.java +++ b/src/main/java/com/smi/xxx/rest/base/JwtFilter.java @@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse; import javax.ws.rs.core.HttpHeaders; +/** JWT Filter. */ public class JwtFilter implements Filter { @Override @@ -28,7 +29,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) } else { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - return; + // return; sonarlint } // try - catch } // doFilter } // JwtFilter diff --git a/src/main/java/com/smi/xxx/rest/base/LoginModel.java b/src/main/java/com/smi/xxx/rest/base/LoginModel.java index 2001dc3..b7c3741 100644 --- a/src/main/java/com/smi/xxx/rest/base/LoginModel.java +++ b/src/main/java/com/smi/xxx/rest/base/LoginModel.java @@ -1,5 +1,6 @@ package com.smi.xxx.rest.base; +/** Login Model. */ public class LoginModel { String username; String password;