Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Feat/swagger #187

Merged
merged 7 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
cache: 'maven'

Expand Down Expand Up @@ -64,10 +64,10 @@ jobs:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
cache: 'maven'

Expand Down Expand Up @@ -178,10 +178,10 @@ jobs:
- name: Check out Git repository
uses: actions/checkout@v3

- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'temurin'
cache: 'maven'

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up JDK 8
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
cache: 'maven'

- name: Deploy to Github packages
Expand Down
52 changes: 40 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,6 @@
<version>4.0.0</version>
</dependency>

<!-- Swagger API documentation
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>${version.swagger.core}</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
<version>${version.swagger.core}</version>
</dependency>-->

<!-- /~https://github.com/powermock/powermock/wiki/Mockito-2-Maven -->
<dependency>
<groupId>org.powermock</groupId>
Expand Down Expand Up @@ -445,6 +433,21 @@
<version>4.5.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>2.2.10-1</version>
</dependency>
<dependency>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>4.9.9</version>
</dependency>

</dependencies>

Expand Down Expand Up @@ -472,6 +475,31 @@
<build>
<finalName>negotiator</finalName>
<plugins>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
Expand Down
26 changes: 9 additions & 17 deletions src/main/java/de/samply/bbmri/negotiator/ServletUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@

package de.samply.bbmri.negotiator;

import de.samply.string.util.StringUtil;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import de.samply.string.util.StringUtil;

/**
* Some servlet utils used to get the server name or redirect URL.
*
Expand Down Expand Up @@ -165,19 +164,12 @@ private static void loadProperties(ServletContext context) {
if (version == null) {
Properties prop = new Properties();
try {
InputStream propResource = context.getResourceAsStream("/META-INF/MANIFEST.MF");

if(propResource == null) {
version = "unknown";
buildTimestamp = "unknown";
buildCommitId = "unknown";
} else {
InputStream propResource = context.getClassLoader().getResourceAsStream("git.properties");
prop.load(propResource);
version = prop.getProperty("Implementation-Version");
buildTimestamp = prop.getProperty("Build-Timestamp");
buildCommitId = prop.getProperty("SCM-Version");
buildCommitBranch = prop.getProperty("SCM-Branch");
}
version = prop.getProperty("git.build.version");
buildTimestamp = prop.getProperty("git.build.time");
buildCommitId = prop.getProperty("git.commit.id.full");
buildCommitBranch = prop.getProperty("git.branch");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,19 @@

import de.samply.bbmri.negotiator.NegotiatorConfig;
import de.samply.bbmri.negotiator.control.UserBean;
import de.samply.common.config.OAuth2Client;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.AuthClient;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.InvalidKeyException;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.InvalidTokenException;
import eu.bbmri.eric.csit.service.negotiator.authentication.client.jwt.KeyLoader;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.faces.application.ResourceHandler;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import javax.ws.rs.core.UriBuilder;

/**
* This filter checks if there is a user logged in or not. If no valid user is
Expand Down Expand Up @@ -80,6 +73,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
* Skip /api/.*
*/
if(path.startsWith(request.getContextPath() + "/api/") ||
path.startsWith(request.getContextPath() + "/swagger/") ||
path.startsWith(request.getContextPath() + "/help/") ||
path.equals(request.getContextPath() + "/logout.xhtml")) {
chain.doFilter(req, res);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/samply/bbmri/negotiator/rest/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import eu.bbmri.eric.csit.service.negotiator.lifecycle.util.LifeCycleRequestStatusType;
import eu.bbmri.eric.csit.service.negotiator.util.NToken;
import eu.bbmri.eric.csit.service.negotiator.util.QueryJsonStringManipulator;
import io.swagger.annotations.Api;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
Expand All @@ -72,6 +73,7 @@
* REST endpoints for the directory
*/
@Path("/directory")
@Api(value = "/directory")
public class Directory {

private static final Logger logger = LogManager.getLogger(Directory.class);
Expand Down
30 changes: 25 additions & 5 deletions src/main/java/de/samply/bbmri/negotiator/rest/RestApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,45 @@

package de.samply.bbmri.negotiator.rest;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

import org.glassfish.jersey.server.ResourceConfig;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
import io.swagger.jaxrs.listing.SwaggerSerializers;
import org.glassfish.jersey.server.ResourceConfig;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

public class RestApplication extends ResourceConfig {

/**
* <p>Constructor for OAuth2RestApplication.</p>
*/
public RestApplication() {
this.registerEndpoints();
this.configureSwagger();
packages(RestApplication.class.getPackage().getName());
}

private void registerEndpoints() {
this.register(Directory.class);
}

private void configureSwagger() {
this.register(ApiListingResource.class);
this.register(SwaggerSerializers.class);
BeanConfig config = new BeanConfig();
packages("io.swagger.jaxrs.listing");
config.setVersion("v1");
config.setSchemes(new String[]{"https", "http"});
config.setResourcePackage("io.swagger.resources");
config.setPrettyPrint(true);
config.setScan(true);
}

/**
* Defines a custom object mapper with disabled null-value inclusion.
*/
Expand Down
16 changes: 15 additions & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/api</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet>
<servlet-name>fileServlet</servlet-name>
Expand Down Expand Up @@ -121,4 +135,4 @@
<res-auth>Container</res-auth>
</resource-ref>

</web-app>
</web-app>
Binary file added src/main/webapp/swagger/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/swagger/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/main/webapp/swagger/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after {
box-sizing: inherit;
}

body {
margin: 0;
background: #fafafa;
}
19 changes: 19 additions & 0 deletions src/main/webapp/swagger/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
</head>

<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>
Loading