From aff6987fe27ec24dede091c75eda9ddc4773d079 Mon Sep 17 00:00:00 2001 From: damage Date: Mon, 23 Dec 2024 14:58:50 +0100 Subject: [PATCH] more configurations.. --- README.md | 22 ++++++++++++++++--- .../java/de/devloop/mavor/Configuration.java | 9 +++++++- .../java/de/devloop/mavor/servlet/Logout.java | 20 ++++++++++++----- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 504c78d..ab98e80 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,29 @@ download a maven artifact and all its dependencies as zip ## Environment Variables -all environemnt variables are required -* `MAVOR_MAVEN_EXECUTABLE`: path to the maven executable, e.g. `/usr/bin/mvn` -* `MAVOR_TEMP_DIR`: path to a readable and writeable directory to temporarily store files, e.g. `/home/damage/Temp` +this environment variables are preset in docker image: +* `MAVOR_MAVEN_EXECUTABLE`: path to the maven executable +* `MAVOR_TEMP_DIR`: path to a readable and writeable directory to temporarily store files + +this environemnt variables are required to be set in docker container: +* `MAVOR_OPENID_CLIENT_ID`: OpenID Client ID +* `MAVOR_OPENID_CLIENT_SECRET`: OpenID Client Secret - not yet providing docker secrets +* `MAVOR_OPENID_REDIRECT_URL`: OpenID Redirect URL - where to redirect after authentication +* `MAVOR_OPENID_AUTH_URL`: OpenID Authentication URL - where to redirect client for authentication +* `MAVOR_OPENID_TOKEN_URL`: OpenID Token URL - where to get a valid token after authentication +* `MAVOR_OPENID_USERINFO_URL`: OpenID User Info URL - where to get user informations from +* `MOVOR_OPENID_LOGOUT_URL`: OpenID Logout URL - where to redirect client for logout ## Development To avoid setting environment variables during devleopment, create `src/main/resources/development.properties` with content like: ``` MAVOR_MAVEN_EXECUTABLE=/usr/bin/mvn MAVOR_TEMP_DIR=/home/damage/Temp +MAVOR_OPENID_CLIENT_ID=foo +MAVOR_OPENID_CLIENT_SECRET=bar +MAVOR_OPENID_REDIRECT_URL=http://localhost:8080/mavor/authenticate +MAVOR_OPENID_AUTH_URL=https://auth.devloop.de/application/o/authorize/ +MAVOR_OPENID_TOKEN_URL=https://auth.devloop.de/application/o/token/ +MAVOR_OPENID_USERINFO_URL=https://auth.devloop.de/application/o/userinfo/ +MOVOR_OPENID_LOGOUT_URL=https://auth.devloop.de/application/o/devloop-mavor-development/end-session/ ``` \ No newline at end of file diff --git a/src/main/java/de/devloop/mavor/Configuration.java b/src/main/java/de/devloop/mavor/Configuration.java index 94ea54f..5dde83c 100644 --- a/src/main/java/de/devloop/mavor/Configuration.java +++ b/src/main/java/de/devloop/mavor/Configuration.java @@ -18,6 +18,7 @@ public class Configuration { private static final String ENV_OPENID_AUTH_URL = "MAVOR_OPENID_AUTH_URL"; private static final String ENV_OPENID_TOKEN_URL = "MAVOR_OPENID_TOKEN_URL"; private static final String ENV_OPENID_USERINFO_URL = "MAVOR_OPENID_USERINFO_URL"; + private static final String ENV_OPENID_LOGOUT_URL = "MAVOR_OPENID_LOGOUT_URL"; private String mavenExecutable; private String tempDir; @@ -27,6 +28,7 @@ public class Configuration { private String openIdAuthUrl; private String openIdTokenUrl; private String openIdUserInfoUrl; + private String openIdLogoutUrl; public Configuration() throws IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); @@ -49,6 +51,7 @@ public class Configuration { openIdAuthUrl = getNullSafeProperty(properties, ENV_OPENID_AUTH_URL); openIdTokenUrl = getNullSafeProperty(properties, ENV_OPENID_TOKEN_URL); openIdUserInfoUrl = getNullSafeProperty(properties, ENV_OPENID_USERINFO_URL); + openIdLogoutUrl = getNullSafeProperty(properties, ENV_OPENID_LOGOUT_URL); } private String getNullSafeProperty(Properties properties, String key) { @@ -70,7 +73,7 @@ public class Configuration { public String getOpenIdClientSecret() { return openIdClientSecret; } - + public String getOpenIdRedirectUrl() { return openIdRedirectUrl; } @@ -86,4 +89,8 @@ public class Configuration { public String getOpenIdUserInfoUrl() { return openIdUserInfoUrl; } + + public String getOpenIdLogoutUrl() { + return openIdLogoutUrl; + } } \ No newline at end of file diff --git a/src/main/java/de/devloop/mavor/servlet/Logout.java b/src/main/java/de/devloop/mavor/servlet/Logout.java index 491e9e8..b82fba0 100644 --- a/src/main/java/de/devloop/mavor/servlet/Logout.java +++ b/src/main/java/de/devloop/mavor/servlet/Logout.java @@ -2,23 +2,33 @@ package de.devloop.mavor.servlet; import java.io.IOException; +import de.devloop.mavor.AuthenticatedServlet; +import de.devloop.mavor.Configuration; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; @WebServlet("/logout") -public class Logout extends HttpServlet { - private static final String OAUTH_LOGOUT_URL = "https://auth.devloop.de/application/o/devloop-mavor/end-session/"; +public class Logout extends AuthenticatedServlet { + private Configuration configuration; @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + public void init() throws ServletException { + try { + configuration = new Configuration(); + } catch (IOException e) { + throw new ServletException("Configuration Error", e); + } + } + + @Override + protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession httpSession = req.getSession(); if (httpSession != null) { httpSession.invalidate(); } - resp.sendRedirect(OAUTH_LOGOUT_URL); + resp.sendRedirect(configuration.getOpenIdLogoutUrl()); } }