Skip to content

Commit

Permalink
generic RESTful 'Clipboard' (#272)
Browse files Browse the repository at this point in the history
* generic RESTful 'Clipboard'
* added dependencies on micrometer.io and OkHttp
* added generic Data[Container] and MIME-type definition classes

N.B. an experimental concept to be expanded (not tackled: HTML and CSS PMD issues)
  • Loading branch information
RalphSteinhagen authored Oct 8, 2020
1 parent 08727d5 commit cf5b1ab
Show file tree
Hide file tree
Showing 51 changed files with 4,272 additions and 3 deletions.
15 changes: 13 additions & 2 deletions chartfx-acc/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -23,5 +22,17 @@
<artifactId>chartfx-chart</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>de.gsi</groupId>
<artifactId>microservice</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>openjfx-monocle</artifactId>
<version>jdk-12.0.1+2</version>
</dependency>


</dependencies>
</project>
6 changes: 6 additions & 0 deletions chartfx-acc/scripts/DefaultRestUserPasswords.pwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# demo password file -- please change for production since these 'password's are not safe!!
admin:$2a$10$h.dl5J86rGH7I8bD9bZeZe:$2a$10$h.dl5J86rGH7I8bD9bZeZeci0pDt0.VwFTGujlnEaZXPf/q7vM5wO:ADMIN:
anonymous:$2a$10$e0MYzXyjpJS7Pd0RVvHwHe:$2a$10$e0MYzXyjpJS7Pd0RVvHwHe1HlCS4bZJ18JuywdEMLT83E1KDmUhCy:READ_WRITE:
alex:$2a$10$rQu1pxN6wCsS.bf6zYObX.:$2a$10$rQu1pxN6wCsS.bf6zYObX.QdkJN85dFpkcrzy1xwWK57ToqpKEVBy:READ_WRITE:
bernd:$2a$10$j2l8uniY45FyKvZLy3ZvaO:$2a$10$j2l8uniY45FyKvZLy3ZvaORFZjPHuGr69Rb/rRCs0W2aPdIfH99pi:READ_ONLY:
zoro:$2a$10$vLiwSkM2/krIqO1eDhGgcu:$2a$10$vLiwSkM2/krIqO1eDhGgcuRv/vJxE8Sh4xePZkBKKZeswP2pTzlAi:ANYONE:
Binary file added chartfx-acc/scripts/keystore.jks
Binary file not shown.
1 change: 1 addition & 0 deletions chartfx-acc/scripts/keystore.pwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nopassword
3 changes: 3 additions & 0 deletions chartfx-acc/scripts/runClipboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

java -server -XX:G1HeapRegionSize=32M -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=j2d,sw -Dprism.verbose=true -DrestKeyStore=keystore.jks -DrestKeyStorePassword=keystore.pwd -DrestUserPasswordStore=DefaultRestUserPasswords.pwd -jar Clipboard.jar
39 changes: 39 additions & 0 deletions chartfx-acc/src/main/java/de/gsi/acc/remote/BasicRestRoles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.gsi.acc.remote;

import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;

import org.jetbrains.annotations.NotNull;

import io.javalin.core.security.Role;

public enum BasicRestRoles implements Role {
NULL,
ANYONE,
ADMIN,
READ_ONLY,
READ_WRITE;

public static String getRoles(final Set<Role> roleSet) {
return roleSet.stream().map(Role::toString).collect(Collectors.joining(", "));
}

public static Set<Role> getRoles(@NotNull final String roleString) {
if (roleString.contains(":")) {
throw new IllegalArgumentException("roleString must not contain [:]");
}

final HashSet<Role> roles = new HashSet<>();
for (final String role : roleString.replaceAll("\\s", "").split(",")) {
if (role == null || role.isEmpty() || "*".equals(role)) { // NOPMD
continue;
}
roles.add(valueOf(role.toUpperCase(Locale.UK)));
}

return Collections.unmodifiableSet(roles);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package de.gsi.acc.remote;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

@SuppressWarnings("PMD.DoNotUseThreads") // purpose of this class
public final class RestCommonThreadPool implements ThreadFactory {
private static final int MAX_THREADS = getDefaultThreadCount();
private static final int MAX_SCHEDULED_THREADS = getDefaultScheduledThreadCount();
private static final ThreadFactory DEFAULT_FACTORY = Executors.defaultThreadFactory();
private static final RestCommonThreadPool SELF = new RestCommonThreadPool();
private static final ExecutorService COMMON_POOL = Executors.newFixedThreadPool(MAX_THREADS, SELF);
private static final ScheduledExecutorService SCHEDULED_POOL = Executors.newScheduledThreadPool(MAX_SCHEDULED_THREADS, SELF);
private static final AtomicInteger THREAD_COUNTER = new AtomicInteger();

private RestCommonThreadPool() {
// helper class
}

@Override
public Thread newThread(final Runnable r) {
final Thread thread = DEFAULT_FACTORY.newThread(r);
THREAD_COUNTER.incrementAndGet();
thread.setName("RestCommonThreadPool#" + THREAD_COUNTER.intValue());
thread.setDaemon(true);
return thread;
}

public static ExecutorService getCommonPool() {
return COMMON_POOL;
}

public static ScheduledExecutorService getCommonScheduledPool() {
return SCHEDULED_POOL;
}

public static RestCommonThreadPool getInstance() {
return SELF;
}

public static int getNumbersOfThreads() {
return MAX_THREADS;
}

private static int getDefaultScheduledThreadCount() {
int nthreads = 32;
try {
nthreads = Integer.parseInt(System.getProperty("restScheduledThreadCount", "32"));
} catch (final NumberFormatException e) {
// malformed number
}

return Math.max(32, nthreads);
}

private static int getDefaultThreadCount() {
int nthreads = 32;
try {
nthreads = Integer.parseInt(System.getProperty("restThreadCount", "64"));
} catch (final NumberFormatException e) {
// malformed number
}

return Math.max(32, nthreads);
}
}
Loading

0 comments on commit cf5b1ab

Please sign in to comment.