Compare commits

..

6 Commits

Author SHA1 Message Date
b2c166c806 woodpecker.yml aktualisiert
All checks were successful
ci/woodpecker/cron/woodpecker Pipeline was successful
2025-01-24 18:53:39 +01:00
5ec9a95d5e added style...
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-29 17:19:41 +01:00
bb419be5f4 init maven subsystem in docker
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing
2024-12-23 15:44:45 +01:00
3edcc4e09d actually get configuration from env *facepalm*
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-23 15:30:25 +01:00
85d16ebfc7 setting web root via configuration
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-23 15:23:24 +01:00
8a85bca1ef move configuration init into baseservlet 2024-12-23 15:14:17 +01:00
15 changed files with 204 additions and 98 deletions

View File

@ -9,6 +9,7 @@ this environment variables are preset in docker image:
* `MAVOR_TEMP_DIR`: path to a readable and writeable directory to temporarily store files * `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: this environemnt variables are required to be set in docker container:
* `MAVOR_WEB_ROOT`: Base URL of how the client access the web page
* `MAVOR_OPENID_CLIENT_ID`: OpenID Client ID * `MAVOR_OPENID_CLIENT_ID`: OpenID Client ID
* `MAVOR_OPENID_CLIENT_SECRET`: OpenID Client Secret - not yet providing docker secrets * `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_REDIRECT_URL`: OpenID Redirect URL - where to redirect after authentication
@ -20,6 +21,7 @@ this environemnt variables are required to be set in docker container:
## Development ## Development
To avoid setting environment variables during devleopment, create `src/main/resources/development.properties` with content like: To avoid setting environment variables during devleopment, create `src/main/resources/development.properties` with content like:
``` ```
MAVOR_WEB_ROOT=http://localhost:8080/mavor
MAVOR_MAVEN_EXECUTABLE=/usr/bin/mvn MAVOR_MAVEN_EXECUTABLE=/usr/bin/mvn
MAVOR_TEMP_DIR=/home/damage/Temp MAVOR_TEMP_DIR=/home/damage/Temp
MAVOR_OPENID_CLIENT_ID=foo MAVOR_OPENID_CLIENT_ID=foo

View File

@ -9,6 +9,11 @@ COPY target/mavor.war /usr/local/tomcat/webapps/ROOT.war
# create temporary directory, no need to be a volume # create temporary directory, no need to be a volume
RUN mkdir /mavor RUN mkdir /mavor
# this mvn command fails but is intended to fail
# it just initializes maven subsystem so the first
# download on the website is faster
RUN /usr/bin/mvn dependency:copy-dependencies || echo "maven init done. fail is intended"
# set required ENV # set required ENV
ENV MAVOR_MAVEN_EXECUTABLE="/usr/bin/mvn" ENV MAVOR_MAVEN_EXECUTABLE="/usr/bin/mvn"
ENV MAVOR_TEMP_DIR="/mavor" ENV MAVOR_TEMP_DIR="/mavor"

View File

@ -1,21 +0,0 @@
kind: pipeline
name: default
steps:
- name: maven
image: maven:3
commands:
- mvn package
- name: docker
image: plugins/docker
settings:
dockerfile: build/Dockerfile
registry: source.devloop.de
repo: source.devloop.de/damage/mavor
username:
from_secret: docker_username
password:
from_secret: docker_password
tags:
- latest
- '1'

View File

@ -3,18 +3,18 @@ package de.devloop.mavor;
import java.io.IOException; import java.io.IOException;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
public class AuthenticatedServlet extends HttpServlet { public class AuthenticatedServlet extends BaseServlet {
protected Session session; protected Session session;
@Override @Override
protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
session = new Session(req.getSession(true)); session = new Session(req.getSession(true));
if (!session.isAuthenticated()) { if (!session.isAuthenticated()) {
resp.sendRedirect("/mavor/authenticate"); resp.sendRedirect(configuration.getWebRoot() + "/authenticate");
} else { } else {
doAuthenticatedGet(req, resp); doAuthenticatedGet(req, resp);
} }
@ -22,9 +22,10 @@ public class AuthenticatedServlet extends HttpServlet {
@Override @Override
protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
session = new Session(req.getSession(true)); session = new Session(req.getSession(true));
if (!session.isAuthenticated()) { if (!session.isAuthenticated()) {
resp.sendRedirect("/mavor/authenticate"); resp.sendRedirect(configuration.getWebRoot() + "/authenticate");
} else { } else {
doAuthenticatedPost(req, resp); doAuthenticatedPost(req, resp);
} }

View File

@ -0,0 +1,31 @@
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 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);
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setAttribute("WEB_ROOT", configuration.getWebRoot());
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setAttribute("WEB_ROOT", configuration.getWebRoot());
}
}

View File

@ -2,6 +2,7 @@ package de.devloop.mavor;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Properties; import java.util.Properties;
@ -9,6 +10,8 @@ public class Configuration {
private static final String DEVELOPMENT_PROPERTIES = "development.properties"; 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_MAVEN_EXECUTABLE = "MAVOR_MAVEN_EXECUTABLE";
private static final String ENV_TEMP_DIR = "MAVOR_TEMP_DIR"; private static final String ENV_TEMP_DIR = "MAVOR_TEMP_DIR";
@ -20,6 +23,7 @@ public class Configuration {
private static final String ENV_OPENID_USERINFO_URL = "MAVOR_OPENID_USERINFO_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 static final String ENV_OPENID_LOGOUT_URL = "MAVOR_OPENID_LOGOUT_URL";
private String webRoot;
private String mavenExecutable; private String mavenExecutable;
private String tempDir; private String tempDir;
private String openIdClientId; private String openIdClientId;
@ -38,16 +42,30 @@ public class Configuration {
developmentProperties.load(developmentPropertiesStream); developmentProperties.load(developmentPropertiesStream);
initByProperties(developmentProperties); initByProperties(developmentProperties);
} else { } else {
initByProperties(System.getProperties()); initByMap(System.getenv());
} }
} }
private void initByMap(Map<String, String> map) {
webRoot = Objects.requireNonNull(map.get(ENV_WEB_ROOT));
mavenExecutable = Objects.requireNonNull(map.get(ENV_MAVEN_EXECUTABLE));
tempDir = Objects.requireNonNull(map.get(ENV_TEMP_DIR));
openIdClientId = Objects.requireNonNull(map.get(ENV_OPENID_CLIENT_ID));
openIdClientSecret = Objects.requireNonNull(map.get(ENV_OPENID_CLIENT_SECRET));
openIdRedirectUrl = Objects.requireNonNull(map.get(ENV_OPENID_REDIRECT_URL));
openIdAuthUrl = Objects.requireNonNull(map.get(ENV_OPENID_AUTH_URL));
openIdTokenUrl = Objects.requireNonNull(map.get(ENV_OPENID_TOKEN_URL));
openIdUserInfoUrl = Objects.requireNonNull(map.get(ENV_OPENID_USERINFO_URL));
openIdLogoutUrl = Objects.requireNonNull(map.get(ENV_OPENID_LOGOUT_URL));
}
private void initByProperties(Properties properties) { private void initByProperties(Properties properties) {
webRoot = getNullSafeProperty(properties, ENV_WEB_ROOT);
mavenExecutable = getNullSafeProperty(properties, ENV_MAVEN_EXECUTABLE); mavenExecutable = getNullSafeProperty(properties, ENV_MAVEN_EXECUTABLE);
tempDir = getNullSafeProperty(properties, ENV_TEMP_DIR); tempDir = getNullSafeProperty(properties, ENV_TEMP_DIR);
openIdClientId = getNullSafeProperty(properties, ENV_OPENID_CLIENT_ID); openIdClientId = getNullSafeProperty(properties, ENV_OPENID_CLIENT_ID);
openIdClientSecret = getNullSafeProperty(properties, ENV_OPENID_CLIENT_SECRET); openIdClientSecret = getNullSafeProperty(properties, ENV_OPENID_CLIENT_SECRET);
openIdRedirectUrl = getNullSafeProperty((properties), ENV_OPENID_REDIRECT_URL); openIdRedirectUrl = getNullSafeProperty(properties, ENV_OPENID_REDIRECT_URL);
openIdAuthUrl = getNullSafeProperty(properties, ENV_OPENID_AUTH_URL); openIdAuthUrl = getNullSafeProperty(properties, ENV_OPENID_AUTH_URL);
openIdTokenUrl = getNullSafeProperty(properties, ENV_OPENID_TOKEN_URL); openIdTokenUrl = getNullSafeProperty(properties, ENV_OPENID_TOKEN_URL);
openIdUserInfoUrl = getNullSafeProperty(properties, ENV_OPENID_USERINFO_URL); openIdUserInfoUrl = getNullSafeProperty(properties, ENV_OPENID_USERINFO_URL);
@ -58,6 +76,10 @@ public class Configuration {
return Objects.requireNonNull(properties.getProperty(key)); return Objects.requireNonNull(properties.getProperty(key));
} }
public String getWebRoot() {
return webRoot;
}
public String getMavenExecutable() { public String getMavenExecutable() {
return mavenExecutable; return mavenExecutable;
} }

View File

@ -2,7 +2,7 @@ package de.devloop.mavor.servlet;
import java.io.IOException; import java.io.IOException;
import de.devloop.mavor.Configuration; import de.devloop.mavor.BaseServlet;
import de.devloop.mavor.Session; import de.devloop.mavor.Session;
import de.devloop.openid.AuthenticationUrl; import de.devloop.openid.AuthenticationUrl;
import de.devloop.openid.OpenID; import de.devloop.openid.OpenID;
@ -12,12 +12,11 @@ import de.devloop.openid.Token;
import de.devloop.openid.UserInfo; import de.devloop.openid.UserInfo;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/authenticate") @WebServlet("/authenticate")
public class Authentication extends HttpServlet { public class Authentication extends BaseServlet {
private static final String PARAMETER_STATE = "state"; private static final String PARAMETER_STATE = "state";
private static final String PARAMETER_CODE = "code"; private static final String PARAMETER_CODE = "code";
@ -27,12 +26,7 @@ public class Authentication extends HttpServlet {
@Override @Override
public void init() throws ServletException { public void init() throws ServletException {
Configuration configuration; super.init();
try {
configuration = new Configuration();
} catch (IOException e) {
throw new ServletException("Configuration Error", e);
}
openIdConfiguration = new OpenIdConfiguration(); openIdConfiguration = new OpenIdConfiguration();
openIdConfiguration.setAuthUrl(configuration.getOpenIdAuthUrl()); openIdConfiguration.setAuthUrl(configuration.getOpenIdAuthUrl());
@ -63,7 +57,7 @@ public class Authentication extends HttpServlet {
session.setOAuthToken(token.getAccessToken()); session.setOAuthToken(token.getAccessToken());
session.setUsername(userInfo.getEmail()); session.setUsername(userInfo.getEmail());
resp.sendRedirect("/mavor/"); resp.sendRedirect(configuration.getWebRoot());
} else { } else {
throw new ServletException("OpenID state mismatch!"); throw new ServletException("OpenID state mismatch!");
} }

View File

@ -18,7 +18,6 @@ import java.util.zip.ZipOutputStream;
import de.devloop.mavor.Artifact; import de.devloop.mavor.Artifact;
import de.devloop.mavor.AuthenticatedServlet; import de.devloop.mavor.AuthenticatedServlet;
import de.devloop.mavor.Configuration;
import jakarta.servlet.RequestDispatcher; import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet; 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_POM = "pom";
private static final String PARAMETER_TYPE = "type"; 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 @Override
protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doAuthenticatedPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doAuthenticatedGet(req, resp); doAuthenticatedGet(req, resp);

View File

@ -5,7 +5,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import de.devloop.mavor.AuthenticatedServlet; import de.devloop.mavor.AuthenticatedServlet;
import de.devloop.mavor.Configuration;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -16,17 +15,6 @@ public class DownloadZip extends AuthenticatedServlet {
private static final String PARAMETER_FILENAME = "file"; 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 @Override
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
File tempDir = new File(configuration.getTempDir()); File tempDir = new File(configuration.getTempDir());
@ -46,7 +34,7 @@ public class DownloadZip extends AuthenticatedServlet {
throw new ServletException("-.-"); throw new ServletException("-.-");
} }
} else { } else {
Main.redirectToMe(resp); resp.sendRedirect(configuration.getWebRoot());
} }
} }
} }

View File

@ -3,7 +3,6 @@ package de.devloop.mavor.servlet;
import java.io.IOException; import java.io.IOException;
import de.devloop.mavor.AuthenticatedServlet; import de.devloop.mavor.AuthenticatedServlet;
import de.devloop.mavor.Configuration;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -12,16 +11,6 @@ import jakarta.servlet.http.HttpSession;
@WebServlet("/logout") @WebServlet("/logout")
public class Logout extends AuthenticatedServlet { 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 @Override
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

View File

@ -19,8 +19,4 @@ public class Main extends AuthenticatedServlet {
view.forward(req, resp); view.forward(req, resp);
} }
public static void redirectToMe(HttpServletResponse resp) throws IOException {
resp.sendRedirect("/mavor");
}
} }

View File

@ -1,10 +1,15 @@
<%@ taglib uri="jakarta.tags.core" prefix="c" %> <%@ taglib uri="jakarta.tags.core" prefix="c" %>
<%@ page isELIgnored="false" %> <%@ page isELIgnored="false" %>
<html> <html>
<body style="background-color:black; color:white"> <head>
Download dependencies (Link only works once!): <a href="/mavor/download/zip?file=${zipFilename}">${zipFilename}</a><br/> <link rel="stylesheet" href="${WEB_ROOT}/style/main.css">
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a><br/> </head>
Maven Output:<br/> <body>
<h2>Hello ${username}</h2>
<a href="${WEB_ROOT}/logout">logout</a> | <a href="${WEB_ROOT}">back</a>
<h3>Download dependencies</h3>
(Link only works once!) <a href="${WEB_ROOT}/download/zip?file=${zipFilename}">${zipFilename}</a>
<h3>Maven Output:</h3>
<pre>${stdout}</pre> <pre>${stdout}</pre>
</body> </body>
</html> </html>

View File

@ -1,21 +1,59 @@
<%@ taglib uri="jakarta.tags.core" prefix="c" %> <%@ taglib uri="jakarta.tags.core" prefix="c" %>
<%@ page isELIgnored="false" %> <%@ page isELIgnored="false" %>
<html> <html>
<body style="background-color:black; color:white"> <head>
<h2>Hello ${username}</h2> <link rel="stylesheet" href="${WEB_ROOT}/style/main.css">
<form method="get" action="/mavor/download/jars"> </head>
<input type="hidden" name="type" value="artifact"/> <body>
Repository: <input type="text" name="repository" value="https://source.devloop.de/api/packages/damage/maven/" /><br/> <h2>Hello ${username}</h2>
Group ID: <input type="text" name="groupId" value="org.apache.activemq"/><br/> <a href="${WEB_ROOT}/logout">logout</a>
Artifact ID: <input type="text" name="artifactId" value="artemis-core-client"/><br/> <h3>download dependencies of given artifact:</h3>
Version: <input type="text" name="version" value="2.39.0"/><br/> <form method="get" action="${WEB_ROOT}/download/jars">
<input type="submit"/> <input type="hidden" name="type" value="artifact"/>
</form> <div class="row">
<form method="post" action="/mavor/download/jars"> <div class="label">
<input type="hidden" name="type" value="pom"/> <label for="repository">Repository:</label>
POM: <textarea name="pom" cols="80" rows="20"></textarea><br/> </div>
<input type="submit"/> <div class="input">
</form> <input type="text" name="repository" id="repository" value="https://source.devloop.de/api/packages/damage/maven/" />
<a href="/mavor/logout">logout</a> </div>
</body> </div>
<div class="row">
<div class="label">
<label for="groupId">Group ID:</label>
</div>
<div class="input small">
<input type="text" name="groupId" id="groupId" value="org.apache.activemq"/>
</div>
</div>
<div class="row">
<div class="label">
<label for="artifactId">Artifact ID:</label>
</div>
<div class="input small">
<input type="text" name="artifactId" id="artifactId" value="artemis-core-client"/>
</div>
</div>
<div class="row">
<div class="label">
<label for="version">Version:</label>
</div>
<div class="input small">
<input type="text" name="version" id="version" value="2.39.0"/>
</div>
</div>
<input type="submit" value="download by artifact"/>
</form>
<h3>download dependencies as given in pom.xml:</h3>
<form method="post" action="${WEB_ROOT}/download/jars">
<input type="hidden" name="type" value="pom"/>
<div class="row">
<div class="input big">
<textarea name="pom" id="pom"></textarea><br/>
</div>
</div>
<input type="submit" value="download by pom.xml"/>
</form>
</body>
</html> </html>

View File

@ -0,0 +1,46 @@
body {
background-color: #1b1b1b;
color: #c0c0c0;
}
h3 {
margin-bottom: 0;
}
textarea, input {
background-color: #2b2b2b;
color: #c0c0c0;
}
.row {
width: 100%;
}
.row div {
display: inline-block;
}
.label {
width: 75pt;
}
.input {
width: 300pt;
}
.input.small {
width: 150pt;
}
.input.big {
width: 500pt;
}
.input input, .input textarea {
width: 100%;
}
.input textarea {
height: 50em;
white-space: pre;
}

22
woodpecker.yml Normal file
View File

@ -0,0 +1,22 @@
when:
- event: [cron, manual]
steps:
- name: maven
image: maven:3
commands:
- mvn package
- name: tag
image: node
commands:
- echo -n "$(date +%Y%m%d_%H%M%S), latest, 1" > .tags
- name: docker
image: woodpeckerci/plugin-docker-buildx:5
settings:
dockerfile: build/Dockerfile
registry: https://source.devloop.de
repo: source.devloop.de/damage/mavor
username:
from_secret: docker_username
password:
from_secret: docker_password