diff --git a/.gitignore b/.gitignore index 2ab300b..68e07ab 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target out *.iml .DS_Store +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..618e3f7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM amazoncorretto:11-alpine3.18 AS base + +WORKDIR /app + +FROM base AS builder + +RUN apk add maven + +COPY pom.xml system.properties ./ + +RUN mvn -DskipTests clean dependency:list install + +COPY src src + +RUN mvn -DskipTests clean dependency:list install + +FROM base AS runner + +COPY --from=builder /app/target/calypso-1.0-SNAPSHOT.jar . + +CMD ["java", "-jar", "calypso-1.0-SNAPSHOT.jar"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..60626a6 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,17 @@ +version: "3.8" +services: + db: + image: postgres:16-alpine3.18 + environment: + POSTGRES_PASSWORD: calypso + + web: + build: . + environment: + JDBC_DATABASE_URL: "jdbc:postgresql://db:5432/postgres" + JDBC_DATABASE_USERNAME: postgres + JDBC_DATABASE_PASSWORD: calypso + APPLICATION_URL: http://localhost.datasektionen.se:3000 + env_file: .env + ports: + - "3000:8080" diff --git a/src/main/java/se/datasektionen/calypso/auth/DAuthEntryPoint.java b/src/main/java/se/datasektionen/calypso/auth/DAuthEntryPoint.java index 2f3e07e..618da73 100644 --- a/src/main/java/se/datasektionen/calypso/auth/DAuthEntryPoint.java +++ b/src/main/java/se/datasektionen/calypso/auth/DAuthEntryPoint.java @@ -20,7 +20,7 @@ public DAuthEntryPoint(Config config) { @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { - response.sendRedirect("https://login.datasektionen.se/login?callback=" + + response.sendRedirect(config.getLoginUrl() + "/login?callback=" + config.getBaseUrl() + "/auth/verify?token="); } } diff --git a/src/main/java/se/datasektionen/calypso/auth/DAuthUserDetailsService.java b/src/main/java/se/datasektionen/calypso/auth/DAuthUserDetailsService.java index 01413c7..d0f4059 100644 --- a/src/main/java/se/datasektionen/calypso/auth/DAuthUserDetailsService.java +++ b/src/main/java/se/datasektionen/calypso/auth/DAuthUserDetailsService.java @@ -41,7 +41,7 @@ public DAuthUserDetailsService(Config config) { public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws UsernameNotFoundException { // Required variables var t = token.getPrincipal().toString(); - var url = "https://login.datasektionen.se/verify/" + t + ".json?api_key=" + config.getApiKey(); + var url = config.getLoginUrl() + "/verify/" + t + ".json?api_key=" + config.getLoginApiKey(); var headers = new HttpHeaders(); headers.set("User-Agent", "Spring Framework/Java " + System.getProperty("java.version")); diff --git a/src/main/java/se/datasektionen/calypso/config/Config.java b/src/main/java/se/datasektionen/calypso/config/Config.java index 9ead360..ef5d6c3 100644 --- a/src/main/java/se/datasektionen/calypso/config/Config.java +++ b/src/main/java/se/datasektionen/calypso/config/Config.java @@ -7,13 +7,17 @@ @Component @Getter public class Config { - private final String baseUrl; - private final String apiKey; + private final String loginApiKey; + private final String loginUrl; - public Config(@Value("${APPLICATION_URL}") String baseUrl, @Value("${LOGIN_KEY}") String apiKey) { + public Config( + @Value("${APPLICATION_URL}") String baseUrl, + @Value("${LOGIN_KEY}") String loginApiKey, + @Value("${LOGIN_URL:https://login.datasektionen.se}") String loginUrl + ) { this.baseUrl = baseUrl; - this.apiKey = apiKey; + this.loginApiKey = loginApiKey; + this.loginUrl = loginUrl; } - } diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json index c54ff77..c0889a7 100644 --- a/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -8,7 +8,12 @@ { "name": "LOGIN_KEY", "type": "java.lang.String", - "description": "API key for login.datasektionen.se." + "description": "API key for login." + }, + { + "name": "LOGIN_URL", + "type": "java.lang.String", + "description": "URL to login." } ] -} \ No newline at end of file +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 248a507..b8a7258 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,4 +3,4 @@ spring.jpa.generate-ddl=true spring.datasource.url=${JDBC_DATABASE_URL} spring.datasource.username=${JDBC_DATABASE_USERNAME} spring.datasource.password=${JDBC_DATABASE_PASSWORD} -server.port=${PORT:8080} \ No newline at end of file +server.port=${PORT:8080}