Address reviews on jakarta migration.
Fix JettyServerTest, init package, and some java docs.
Make scope extraction more flexible.
Bumped Kustvakt version to 0.72-SNAPSHOT
Updated changes file
Change-Id: I9ba8620e244106b706e95d82dc2e3aeaceb37ae5
diff --git a/full/src/main/java/de/ids_mannheim/de/init/Initializator.java b/full/src/main/java/de/ids_mannheim/korap/init/Initializator.java
similarity index 97%
rename from full/src/main/java/de/ids_mannheim/de/init/Initializator.java
rename to full/src/main/java/de/ids_mannheim/korap/init/Initializator.java
index bea303e..e908737 100644
--- a/full/src/main/java/de/ids_mannheim/de/init/Initializator.java
+++ b/full/src/main/java/de/ids_mannheim/korap/init/Initializator.java
@@ -1,4 +1,4 @@
-package de.ids_mannheim.de.init;
+package de.ids_mannheim.korap.init;
import java.io.IOException;
import java.util.EnumSet;
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2AuthorizationService.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2AuthorizationService.java
index 06960bb..19cf2e1 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2AuthorizationService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2AuthorizationService.java
@@ -160,7 +160,7 @@
* @param username
* @param clientId
* @param redirectUri
- * @param scopeSet
+ * @param scope
* @param code
* @param authenticationTime
* user authentication time
@@ -208,9 +208,6 @@
*
* @param client
* an OAuth2Client
- * @param hasRedirectUri
- * true if request contains redirect_uri, false
- * otherwise
* @param redirectUri
* the redirect_uri value
* @return a client's redirect URI
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeServiceImpl.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeServiceImpl.java
index 56f0115..f8430aa 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeServiceImpl.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2ScopeServiceImpl.java
@@ -78,7 +78,7 @@
public Set<AccessScope> convertToAccessScope (String scopes)
throws KustvaktException {
- String[] scopeArray = scopes.split(" ");
+ String[] scopeArray = scopes.split("\\s+");
List<AccessScope> definedScopes = accessScopeDao.retrieveAccessScopes();
Set<AccessScope> requestedScopes =
new HashSet<AccessScope>(scopeArray.length);
diff --git a/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2TokenService.java b/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2TokenService.java
index 40ef907..70c9a0b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2TokenService.java
+++ b/full/src/main/java/de/ids_mannheim/korap/oauth2/service/OAuth2TokenService.java
@@ -449,6 +449,8 @@
* a user id
* @param authenticationTime
* the user authentication time
+ * @param client
+ * an OAuth2Client
* @return an {@link OAuthResponse}
* @throws OAuthSystemException
* @throws KustvaktException
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java
index 0686a89..a74d241 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/OAuth2Controller.java
@@ -40,6 +40,7 @@
import de.ids_mannheim.korap.web.filter.BlockingFilter;
import de.ids_mannheim.korap.web.utils.ResourceFilters;
import jakarta.servlet.http.HttpServletRequest;
+import jakarta.validation.constraints.NotEmpty;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.GET;
@@ -261,7 +262,8 @@
@ResourceFilters({APIVersionFilter.class})
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response requestAccessToken (@Context HttpServletRequest request,
- @FormParam("client_id") String clientId,
+ @NotEmpty @FormParam("grant_type") String grantType,
+ @NotEmpty @FormParam("client_id") String clientId,
@FormParam("client_secret") String clientSecret,
MultivaluedMap<String, String> form) {
diff --git a/full/src/main/resources/default-config.xml b/full/src/main/resources/default-config.xml
index f726e2a..36925cb 100644
--- a/full/src/main/resources/default-config.xml
+++ b/full/src/main/resources/default-config.xml
@@ -189,7 +189,7 @@
<constructor-arg name="properties" ref="props" />
</bean>
- <bean id="initializator" class="de.ids_mannheim.de.init.Initializator"
+ <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
init-method="init">
</bean>
diff --git a/full/src/main/resources/default-lite-config.xml b/full/src/main/resources/default-lite-config.xml
index c4cdd96..8069c8e 100644
--- a/full/src/main/resources/default-lite-config.xml
+++ b/full/src/main/resources/default-lite-config.xml
@@ -130,9 +130,7 @@
</bean>
<!-- Initialization -->
- <!-- <bean id="initializator" class="de.ids_mannheim.de.init.LiteInitializatorImpl"
- init-method="init">
- </bean>
+ <!--
<bean id="annotationParser" class="de.ids_mannheim.korap.annotation.AnnotationParser"
scope="singleton" />
-->
diff --git a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
index 02c4642..95af5dc 100644
--- a/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/dao/VirtualCorpusDaoTest.java
@@ -59,7 +59,11 @@
QueryType.VIRTUAL_CORPUS, User.CorpusAccess.FREE,
"corpusSigle=GOE", "definition", "description", "experimental",
false, "system", null, null);
- });
+ });
+
+ assertEquals(exception.getMessage(),
+ "Converting `org.hibernate.exception.GenericJDBCException` "
+ + "to JPA `PersistenceException` : could not execute statement");
}
@Test
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java
index 0255c45..571c15c 100644
--- a/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/web/JettyServerTest.java
@@ -4,38 +4,43 @@
import java.io.IOException;
import java.net.HttpURLConnection;
+import java.net.ServerSocket;
import java.net.URL;
-import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ShutdownHandler;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* @author margaretha
*/
-@Disabled
public class JettyServerTest {
+ static int selectedPort = 0;
+
@BeforeAll
static void testServerStarts() throws Exception {
- Server server = new Server();
- ServerConnector connector = new ServerConnector(server);
- connector.setPort(8000);
- server.setConnectors(new Connector[]{connector});
- HandlerList handlers = new HandlerList();
- handlers.addHandler(new ShutdownHandler("secret", false, true));
- server.setHandler(handlers);
+
+
+ for (int port = 1000; port <= 2000; port++) {
+ try (ServerSocket ignored = new ServerSocket(port)) {
+ selectedPort = port;
+ break;
+ } catch (IOException ignored) {
+ // Port is already in use, try the next one
+ }
+ }
+
+ Server server = new Server(selectedPort);
+ ShutdownHandler shutdownHandler = new ShutdownHandler("secret");
+ server.setHandler(shutdownHandler);
server.start();
}
-
+
@Test
public void testShutdown() throws IOException {
- URL url = new URL("http://localhost:8000/shutdown?token=secret");
+ URL url = new URL("http://localhost:"+selectedPort+"/shutdown?token=secret");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
assertEquals(200, connection.getResponseCode());
diff --git a/full/src/test/resources/test-config-icc.xml b/full/src/test/resources/test-config-icc.xml
index 466b052..9d65017 100644
--- a/full/src/test/resources/test-config-icc.xml
+++ b/full/src/test/resources/test-config-icc.xml
@@ -177,7 +177,7 @@
<constructor-arg name="properties" ref="props" />
</bean>
- <bean id="initializator" class="de.ids_mannheim.de.init.Initializator"
+ <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
init-method="initTest">
</bean>
diff --git a/full/src/test/resources/test-config.xml b/full/src/test/resources/test-config.xml
index 6abc135..b3ae6f3 100644
--- a/full/src/test/resources/test-config.xml
+++ b/full/src/test/resources/test-config.xml
@@ -172,7 +172,7 @@
<constructor-arg name="properties" ref="props" />
</bean>
- <bean id="initializator" class="de.ids_mannheim.de.init.Initializator"
+ <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
init-method="initTest">
</bean>
diff --git a/full/src/test/resources/test-resource-config.xml b/full/src/test/resources/test-resource-config.xml
index 8b5e7d5..28eea3e 100644
--- a/full/src/test/resources/test-resource-config.xml
+++ b/full/src/test/resources/test-resource-config.xml
@@ -16,7 +16,7 @@
http://www.springframework.org/schema/util/spring-util.xsd">
<import resource="classpath:test-config.xml"/>
- <bean id="initializator" class="de.ids_mannheim.de.init.Initializator"
+ <bean id="initializator" class="de.ids_mannheim.korap.init.Initializator"
init-method="initResourceTest">
</bean>