Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Integrating java api client in WebUI , SecHub client enhancements, initial WebUI containerization, Change UC-40 #2518

Merged
merged 20 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
712eca5
Replace status page API calls with SecHub Java API calls #2513 and im…
Jeeppler Aug 28, 2023
36413f1
Merge branch 'develop' into feature-2513-webui-use-sechub-java-api-cl…
Jeeppler Sep 22, 2023
0814795
Use SecHub Mocked client #2513
Jeeppler Sep 27, 2023
21210b9
Move configuration services to configuration package #2513
Jeeppler Sep 27, 2023
d03b881
Merge branch 'develop' into feature-2513-webui-use-sechub-java-api-cl…
Jeeppler Sep 27, 2023
a053b60
Containerized WebUI #2571 and fixes for #2513
Jeeppler Sep 30, 2023
112a096
Containerize WebUI Solution #2571
Jeeppler Oct 4, 2023
eadb25b
Add the README.adoc for the copy folder #2571
Jeeppler Oct 4, 2023
af722d6
Add the README.adoc for the copy folder #2571
Jeeppler Oct 4, 2023
f04f301
Small improvements in Gradle and apply Spotless #2513
Jeeppler Oct 4, 2023
607cf13
Merge branch 'feature-2513-webui-use-sechub-java-api-client' of https…
Jeeppler Oct 4, 2023
06142bb
Return only server version #469
Jeeppler Oct 4, 2023
e931edb
Fix status scheduler call #2513
Jeeppler Oct 4, 2023
1561e58
Merge branch 'develop' into
de-jcup Feb 27, 2024
4b60835
Changed DefaultSecHubClient creation to builder pattern #2513
de-jcup Feb 27, 2024
d74cc5f
Rename sechub client username parts to userId #2942
de-jcup Feb 27, 2024
39a8d5a
Refactorings #2513
de-jcup Feb 28, 2024
57a22f6
Usecase changed: UC-40 renamed + changed java implementation #469
de-jcup Feb 28, 2024
ac3a28a
Some changes for initial WebUI docker image #2571
de-jcup Feb 28, 2024
91bc352
adapted to new api call /api/admin/info/server #469
sven-dmlr Feb 29, 2024
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ buildscript{
classpath "org.ajoberstar.grgit:grgit-gradle:${libraryVersion.grgit}" // necessary for version calculation
classpath "com.epages:restdocs-api-spec-gradle-plugin:${libraryVersion.restDocsApiSpec}"
classpath "org.owasp:dependency-check-gradle:${libraryVersion.dependency_check}"
classpath "org.cyclonedx:cyclonedx-gradle-plugin:1.7.4"
classpath "org.cyclonedx:cyclonedx-gradle-plugin:${libraryVersion.cyclonedx_gradle_plugin}"
}
}

Expand All @@ -37,7 +37,7 @@ plugins {

// spotless code formatter
// (see https://github.com/diffplug/spotless)
id 'com.diffplug.spotless' version '6.18.0'
id 'com.diffplug.spotless' version '6.22.0'

// versions plugin for checking new available library versions etc.
// (see https://github.com/ben-manes/gradle-versions-plugin)
Expand Down
6 changes: 4 additions & 2 deletions gradle/libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ext {
/* documentation */
asciidoctor_j: "2.5.2",
asciidoctor_j_diagram: "2.2.1",

// openapi3-generator, releases see https://github.com/ePages-de/restdocs-api-spec/releases
restDocsApiSpec: "0.16.4", // newest version compatible with Spring Boot 2.x

Expand All @@ -75,9 +76,10 @@ ext {

/* SARIF */
sarif_210: "1.1.0",

/* cycloneDX core */
cycloneDX_core: "8.0.0"
cycloneDX_core: "8.0.0",
cyclonedx_gradle_plugin: "1.7.4"

]

Expand Down
20 changes: 10 additions & 10 deletions gradle/projects.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,13 @@ projectType = [

],

/* SecHub frontend projects */
springBootWebUiProjects:[
project(':sechub-webui'),
],

bootableSpringApplicationProjects:[
project(':sechub-server'),
project(':sechub-pds'),
project(':sechub-wrapper-checkmarx'),
project(':sechub-webui'),
],

springBootWebUIProjects:[], // is filled later programmatically

/* documentation projects */
springDocProjects: [
Expand All @@ -113,8 +109,8 @@ projectType = [
project(':sechub-pds-solutions'),
project(':sechub-solution'),
project(':sechub-solutions-shared'),
project(':sechub-wrapper-xray'),

project(':sechub-wrapper-xray'),
project(':sechub-webui-solution'),
],

asciiDoctorProjects: [
Expand All @@ -132,7 +128,7 @@ projectType = [
}

if (secHubBuildStage.providesGeneratedOpenApiFile()){
/* add the java projects which need a open api file / compiled java api */
/* add the java projects which need an open api file / compiled java api */
projectType.javaProjects.add(project(':sechub-api-java'))

projectType.javaProjects.add(project(':sechub-systemtest'))
Expand All @@ -145,6 +141,10 @@ if (secHubBuildStage.providesGeneratedOpenApiFile()){

/* make it possible to use integration test parts for systemtest (unit tests) as well */
projectType.integrationTestProjects.add(project(':sechub-systemtest'))

/* webui */
projectType.bootableSpringApplicationProjects.add(project(':sechub-webui'))
projectType.springBootWebUIProjects.add(project(':sechub-webui'))
}


Expand All @@ -153,7 +153,7 @@ projectType.springBootProjects.addAll(projectType.springBootSecHubServerProjects
projectType.springBootProjects.addAll(projectType.springBootPDSProjects)
projectType.springBootProjects.addAll(projectType.springBootAdapterProjects)
projectType.springBootProjects.addAll(projectType.springDocProjects)
projectType.springBootProjects.addAll(projectType.springBootWebUiProjects)
projectType.springBootProjects.addAll(projectType.springBootWebUIProjects)

projectType.javaProjects.addAll(projectType.springBootProjects)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@
public abstract class AbstractSecHubClient implements SecHubClient {

private boolean trustAll;
private String username;
private String userId;
private SealedObject sealedApiToken;
private URI serverUri;
private CryptoAccess<String> apiTokenAccess = new CryptoAccess<>();

private Set<SecHubClientListener> secHubClientListeners;

public AbstractSecHubClient(URI serverUri, String username, String apiToken, boolean trustAll) {
protected AbstractSecHubClient(URI serverUri, String userId, String apiToken, boolean trustAll) {
this.serverUri = serverUri;
this.trustAll = trustAll;

this.secHubClientListeners = new LinkedHashSet<>();

setUsername(username);
setUserId(userId);
setApiToken(apiToken);
}

public void setUsername(String username) {
this.username = username;
public void setUserId(String userId) {
if (userId == null) {
throw new IllegalArgumentException("userId may be not null");
}
this.userId = userId;
}

public void setApiToken(String apiToken) {
if (apiToken == null) {
throw new IllegalArgumentException("api token may be not null");
}
this.sealedApiToken = apiTokenAccess.seal(apiToken);
}

Expand All @@ -48,8 +54,8 @@ public boolean isTrustAll() {
}

@Override
public String getUsername() {
return username;
public String getUserId() {
return userId;
}

@Override
Expand Down Expand Up @@ -81,8 +87,8 @@ protected File calculateFullScanLogFile(UUID sechubJobUUID, Path downloadFilePat

/**
* Adds a listener to the client. For some action on client side the listener
* will be informed. A listener can be added only one time no matter how many
* times this method is called.
* will be informed. Same listener instance can be added only one time no matter
* how many times this method is called.
*
* @param listener
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.Callable;

import javax.crypto.SealedObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -42,6 +46,7 @@
import com.mercedesbenz.sechub.commons.archive.ArchiveSupport.ArchivesCreationResult;
import com.mercedesbenz.sechub.commons.core.RunOrFail;
import com.mercedesbenz.sechub.commons.core.security.CheckSumSupport;
import com.mercedesbenz.sechub.commons.core.security.CryptoAccess;
import com.mercedesbenz.sechub.commons.model.JsonMapperFactory;
import com.mercedesbenz.sechub.commons.model.SecHubConfigurationModel;

Expand All @@ -65,12 +70,14 @@ public class DefaultSecHubClient extends AbstractSecHubClient {

private WorkaroundProjectApi workaroundProjectApi;

public DefaultSecHubClient(URI serverUri, String username, String apiToken) {
this(serverUri, username, apiToken, false);
private SecHubStatusFactory sechubStatusFactory = new SecHubStatusFactory();

public static DefaultSecHubClientBuilder builder() {
return new DefaultSecHubClientBuilder();
}

public DefaultSecHubClient(URI serverUri, String username, String apiToken, boolean trustAll) {
super(serverUri, username, apiToken, trustAll);
private DefaultSecHubClient(URI serverUri, String userId, String apiToken, boolean trustAll) {
super(serverUri, userId, apiToken, trustAll);

apiClient = new ApiClientBuilder().createApiClient(this, mapper);

Expand All @@ -86,10 +93,6 @@ public DefaultSecHubClient(URI serverUri, String username, String apiToken, bool

}

private ApiClient getApiClient() {
return apiClient;
}

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* + ................Create.......................... + */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
Expand Down Expand Up @@ -220,16 +223,20 @@ public List<ExecutorConfigurationInfo> fetchAllExecutorConfigurationInfo() throw
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
@Override
public SecHubStatus fetchSecHubStatus() throws SecHubClientException {
SecHubStatus status = new SecHubStatus();

Map<String, String> statusInformation = new TreeMap<>();

runOrFail(() -> {
List<OpenApiStatusInformationInner> statusInformationList = adminApi.adminListsStatusInformation();
for (OpenApiStatusInformationInner info : statusInformationList) {
String key = info.getKey();
if (key != null) {
status.statusInformation.put(key, info.getValue());
statusInformation.put(key, info.getValue());
de-jcup marked this conversation as resolved.
Show resolved Hide resolved
}
}
}, "Was not able to fetch SecHub status!");

SecHubStatus status = sechubStatusFactory.createFromMap(statusInformation);
return status;
}

Expand All @@ -244,7 +251,7 @@ public void triggerRefreshOfSecHubSchedulerStatus() throws SecHubClientException
@Override
public boolean isServerAlive() throws SecHubClientException {
try {
anonymousApi.anonymousCheckAliveGet();
anonymousApi.anonymousCheckAliveHead();
return true;
} catch (ApiException e) {
return false;
Expand Down Expand Up @@ -432,6 +439,24 @@ public Path downloadFullScanLog(UUID sechubJobUUID, Path downloadFilePath) throw
return targetFile.toPath();
}

/* +++++++++++++++++++++++++++++++++++++++++++++++++ */
/* + ................Version...................... + */
/* +++++++++++++++++++++++++++++++++++++++++++++++++ */

@Override
public String getServerVersion() throws SecHubClientException {
return runOrFail(() -> adminApi.adminFetchesServerRuntimeData().getServerVersion(), "Get server version");
}

@Override
public void requestNewApiToken(String emailAddress) throws SecHubClientException {
runOrFail(() -> anonymousApi.userRequestsNewApiToken(emailAddress), "User requests a new API Token");
}

private ApiClient getApiClient() {
return apiClient;
}

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* + ................Helpers......................... + */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++ */
Expand All @@ -456,4 +481,45 @@ private SecHubClientException createClientException(String message, Exception ca
return new SecHubClientException(message + " - " + cause.getMessage(), cause);
}

public static class DefaultSecHubClientBuilder {
private URI serverUri;
private String userName;
private CryptoAccess<String> apiTokenAccess = new CryptoAccess<>();
private SealedObject sealedApiToken;
private boolean trustAll;

public DefaultSecHubClientBuilder server(URI serverUri) {
this.serverUri = serverUri;
return this;
}

public DefaultSecHubClientBuilder user(String userId) {
this.userName = userId;
return this;
}

public DefaultSecHubClientBuilder apiToken(String token) {
sealedApiToken = apiTokenAccess.seal(token);
return this;
}

public DefaultSecHubClientBuilder trustAll(boolean trustAll) {
this.trustAll = trustAll;
return this;
}

public SecHubClient build() {
if (serverUri == null) {
throw new IllegalStateException("server uri is not defined!");
}
if (userName == null) {
throw new IllegalStateException("user name is not defined!");
}
if (sealedApiToken == null) {
throw new IllegalStateException("token is not defined!");
}
return new DefaultSecHubClient(serverUri, userName, apiTokenAccess.unseal(sealedApiToken), trustAll);
}
}

}
Loading
Loading