move configuration init into baseservlet
This commit is contained in:
parent
aa11ffc47b
commit
8a85bca1ef
@ -3,11 +3,10 @@ package de.devloop.mavor;
|
||||
import java.io.IOException;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
public class AuthenticatedServlet extends HttpServlet {
|
||||
public class AuthenticatedServlet extends BaseServlet {
|
||||
protected Session session;
|
||||
|
||||
@Override
|
||||
|
19
src/main/java/de/devloop/mavor/BaseServlet.java
Normal file
19
src/main/java/de/devloop/mavor/BaseServlet.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.devloop.mavor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
|
||||
public class BaseServlet extends HttpServlet {
|
||||
protected Configuration configuration;
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
try {
|
||||
configuration = new Configuration();
|
||||
} catch (IOException e) {
|
||||
throw new ServletException("Configuration Error", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,8 @@ public class Configuration {
|
||||
|
||||
private static final String DEVELOPMENT_PROPERTIES = "development.properties";
|
||||
|
||||
private static final String ENV_WEB_ROOT = "MAVOR_WEB_ROOT";
|
||||
|
||||
private static final String ENV_MAVEN_EXECUTABLE = "MAVOR_MAVEN_EXECUTABLE";
|
||||
private static final String ENV_TEMP_DIR = "MAVOR_TEMP_DIR";
|
||||
|
||||
@ -20,6 +22,7 @@ public class Configuration {
|
||||
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 webRoot;
|
||||
private String mavenExecutable;
|
||||
private String tempDir;
|
||||
private String openIdClientId;
|
||||
@ -43,6 +46,7 @@ public class Configuration {
|
||||
}
|
||||
|
||||
private void initByProperties(Properties properties) {
|
||||
webRoot = getNullSafeProperty(properties, ENV_WEB_ROOT);
|
||||
mavenExecutable = getNullSafeProperty(properties, ENV_MAVEN_EXECUTABLE);
|
||||
tempDir = getNullSafeProperty(properties, ENV_TEMP_DIR);
|
||||
openIdClientId = getNullSafeProperty(properties, ENV_OPENID_CLIENT_ID);
|
||||
@ -58,6 +62,10 @@ public class Configuration {
|
||||
return Objects.requireNonNull(properties.getProperty(key));
|
||||
}
|
||||
|
||||
public String getWebRoot() {
|
||||
return webRoot;
|
||||
}
|
||||
|
||||
public String getMavenExecutable() {
|
||||
return mavenExecutable;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package de.devloop.mavor.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.devloop.mavor.Configuration;
|
||||
import de.devloop.mavor.BaseServlet;
|
||||
import de.devloop.mavor.Session;
|
||||
import de.devloop.openid.AuthenticationUrl;
|
||||
import de.devloop.openid.OpenID;
|
||||
@ -12,12 +12,11 @@ import de.devloop.openid.Token;
|
||||
import de.devloop.openid.UserInfo;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet("/authenticate")
|
||||
public class Authentication extends HttpServlet {
|
||||
public class Authentication extends BaseServlet {
|
||||
|
||||
private static final String PARAMETER_STATE = "state";
|
||||
private static final String PARAMETER_CODE = "code";
|
||||
@ -27,12 +26,7 @@ public class Authentication extends HttpServlet {
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
Configuration configuration;
|
||||
try {
|
||||
configuration = new Configuration();
|
||||
} catch (IOException e) {
|
||||
throw new ServletException("Configuration Error", e);
|
||||
}
|
||||
super.init();
|
||||
|
||||
openIdConfiguration = new OpenIdConfiguration();
|
||||
openIdConfiguration.setAuthUrl(configuration.getOpenIdAuthUrl());
|
||||
|
@ -18,7 +18,6 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
import de.devloop.mavor.Artifact;
|
||||
import de.devloop.mavor.AuthenticatedServlet;
|
||||
import de.devloop.mavor.Configuration;
|
||||
import jakarta.servlet.RequestDispatcher;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
@ -35,17 +34,6 @@ public class DownloadJars extends AuthenticatedServlet {
|
||||
private static final String PARAMETER_POM = "pom";
|
||||
private static final String PARAMETER_TYPE = "type";
|
||||
|
||||
private Configuration configuration;
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
try {
|
||||
configuration = new Configuration();
|
||||
} catch (IOException e) {
|
||||
throw new ServletException("Configuration Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
doAuthenticatedGet(req, resp);
|
||||
|
@ -5,7 +5,6 @@ import java.io.FileInputStream;
|
||||
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.HttpServletRequest;
|
||||
@ -16,17 +15,6 @@ public class DownloadZip extends AuthenticatedServlet {
|
||||
|
||||
private static final String PARAMETER_FILENAME = "file";
|
||||
|
||||
private Configuration configuration;
|
||||
|
||||
@Override
|
||||
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 {
|
||||
File tempDir = new File(configuration.getTempDir());
|
||||
|
@ -3,7 +3,6 @@ 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.HttpServletRequest;
|
||||
@ -12,16 +11,6 @@ import jakarta.servlet.http.HttpSession;
|
||||
|
||||
@WebServlet("/logout")
|
||||
public class Logout extends AuthenticatedServlet {
|
||||
private Configuration configuration;
|
||||
|
||||
@Override
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user