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

Provide templates and assets #3545

Merged
merged 23 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ba2b4ef
Enhanced concept of templates and assets #3521
de-jcup Oct 17, 2024
c5fc929
Introduce templates #3520
de-jcup Oct 22, 2024
099fe10
Fix -f option for sdc.sh
de-jcup Oct 22, 2024
aff4f71
Rename other Template to CodeTemplate + Entity hash and equals #3520
de-jcup Oct 22, 2024
9f143b2
Made type property for template definition immutable #3520
de-jcup Oct 23, 2024
27232ad
Implemented template assignment handling for projects #3522
de-jcup Oct 24, 2024
27f2dd3
Introduce asset storage #3553
de-jcup Nov 5, 2024
f5b6559
Inititial asset implementations #3553
de-jcup Nov 6, 2024
d5795e6
Merge branch 'develop' into feature-3521-templates-and-assets
de-jcup Nov 6, 2024
c7ee778
Asset storage improved, implemented asset service logic + more #3553
de-jcup Nov 7, 2024
249b28b
Asset parts added to open api file #3553
de-jcup Nov 11, 2024
e346ecf
SecHub PDS communication parts for assets and templates #3523
de-jcup Nov 14, 2024
550b0b5
Made flaky integration test TemplateScenario1IntTest stable #3523
de-jcup Nov 15, 2024
c2c6f1b
Implemented PDS asset handling #3524
de-jcup Nov 18, 2024
68ec5d7
Merge branch 'develop' into feature-3521-templates-and-assets
de-jcup Nov 20, 2024
6586448
Documentation improved #3525
de-jcup Nov 29, 2024
b48c9e8
Change field and columns from "templates" to "templateIds"
de-jcup Dec 3, 2024
91e98bd
Moved shared kernel template parts to own package + renaming #3521
de-jcup Dec 5, 2024
110ce3a
Fixed typos, minor changes and added test #3521
de-jcup Dec 5, 2024
de70eb3
Changed template create/update REST call from POST to PUT #3521
de-jcup Dec 5, 2024
7203934
Minor changes #321
de-jcup Dec 5, 2024
a78848d
Separated examples to 2 different enums to fix failing unit test #3521
de-jcup Dec 5, 2024
5795a83
Fix flaky db test + added tests #3705
de-jcup Dec 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -565,23 +565,28 @@ private String createJobDataJSON(PDSContext context) throws AdapterException {
}

private PDSJobData createJobData(PDSContext context) {
PDSAdapterConfig config = context.getConfig();
PDSAdapterConfigData data = config.getPDSAdapterConfigData();
assertConfigDataNotNull(data);
Map<String, String> parameters = data.getJobParameters();

PDSAdapterConfig adapterConfig = context.getConfig();
PDSAdapterConfigData adapterConfigData = adapterConfig.getPDSAdapterConfigData();
assertConfigDataNotNull(adapterConfigData);
Map<String, String> adapterConfigDataJobParameters = adapterConfigData.getJobParameters();

/*
* convert adapter configuration to PDS job data that shall be sent to PDS as
* key value parameters:
*/
PDSJobData jobData = new PDSJobData();
for (String key : parameters.keySet()) {

for (String key : adapterConfigDataJobParameters.keySet()) {
PDSJobParameterEntry parameter = new PDSJobParameterEntry();
parameter.key = key;
parameter.value = parameters.get(key);
parameter.value = adapterConfigDataJobParameters.get(key);

jobData.parameters.add(parameter);
}

UUID secHubJobUUID = data.getSecHubJobUUID();
UUID secHubJobUUID = adapterConfigData.getSecHubJobUUID();
jobData.sechubJobUUID = secHubJobUUID.toString();
jobData.productId = data.getPdsProductIdentifier();
jobData.productId = adapterConfigData.getPdsProductIdentifier();

return jobData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.LoggerFactory;

import com.mercedesbenz.sechub.adapter.support.URIShrinkSupport;
import com.mercedesbenz.sechub.commons.core.ConfigurationFailureException;
import com.mercedesbenz.sechub.commons.core.security.CryptoAccess;

/**
Expand Down Expand Up @@ -69,10 +70,11 @@ protected URIShrinkSupport createURIShrinkSupport() {
*
* @param strategy
* @return builder (configured by strategy)
* @throws ConfigurationFailureException
*/
@Override
@SuppressWarnings("unchecked")
public final B configure(AdapterConfigurationStrategy strategy) {
public final B configure(AdapterConfigurationStrategy strategy) throws ConfigurationFailureException {
strategy.configure((B) this);
return (B) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import static com.mercedesbenz.sechub.adapter.TimeConstants.*;

import com.mercedesbenz.sechub.commons.core.ConfigurationFailureException;

public interface AdapterConfigBuilder {

public static final int DEFAULT_SCAN_RESULT_CHECK_IN_MILLISECONDS = TIME_1_MINUTE_IN_MILLISECONDS;
Expand Down Expand Up @@ -30,7 +32,7 @@ public interface AdapterConfigBuilder {
* @param strategy
* @return builder (configured by strategy)
*/
AdapterConfigBuilder configure(AdapterConfigurationStrategy strategy);
AdapterConfigBuilder configure(AdapterConfigurationStrategy strategy) throws ConfigurationFailureException;

/**
* Set result check interval in minutes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.adapter;

import com.mercedesbenz.sechub.commons.core.ConfigurationFailureException;

/**
* A configuration strategy is used to configure a given config adapter builder
*
Expand All @@ -16,6 +18,6 @@ public interface AdapterConfigurationStrategy {
*
* @param configBuilder
*/
<B extends AdapterConfigBuilder, C extends AdapterConfig> void configure(B configBuilder);
<B extends AdapterConfigBuilder, C extends AdapterConfig> void configure(B configBuilder) throws ConfigurationFailureException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ private AdministrationAPIConstants() {

public static final String API_CHANGE_PROJECT_ACCESSLEVEL = API_ADMINISTRATION + "project/{projectId}/accesslevel/{projectAccessLevel}";

/* +-----------------------------------------------------------------------+ */
/* +............................ Templates.................................+ */
/* +-----------------------------------------------------------------------+ */
public static final String API_ASSIGN_TEMPLATE_TO_PROJECT = API_ADMINISTRATION + "project/{projectId}/template/{templateId}";
public static final String API_UNASSIGN_TEMPLATE_FROM_PROJECT = API_ADMINISTRATION + "project/{projectId}/template/{templateId}";
de-jcup marked this conversation as resolved.
Show resolved Hide resolved

/* +-----------------------------------------------------------------------+ */
/* +............................ Encryption................................+ */
/* +-----------------------------------------------------------------------+ */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Project {
public static final String TABLE_NAME_PROJECT_TO_METADATA = "ADM_PROJECT_TO_METADATA";
public static final String TABLE_NAME_PROJECT_WHITELIST_URI = "ADM_PROJECT_WHITELIST_URI";
public static final String TABLE_NAME_PROJECT_METADATA = "ADM_PROJECT_METADATA";
public static final String TABLE_NAME_PROJECT_TEMPLATES = "ADM_PROJECT_TEMPLATES";

public static final String COLUMN_PROJECT_ID = "PROJECT_ID";
public static final String COLUMN_PROJECT_OWNER = "PROJECT_OWNER";
Expand All @@ -43,10 +44,12 @@ public class Project {
public static final String COLUMN_METADATA = "METADATA_KEY";

public static final String COLUMN_PROJECT_ACCESS_LEVEL = "PROJECT_ACCESS_LEVEL";
public static final String COLUMN_TEMPLATE_ID = "PROJECT_TEMPLATE_ID";

public static final String ASSOCIATE_PROJECT_TO_USER_COLUMN_PROJECT_ID = "PROJECTS_PROJECT_ID";
public static final String ASSOCIATE_PROJECT_TO_URI_COLUMN_PROJECT_ID = "PROJECT_PROJECT_ID";
public static final String ASSOCIATE_PROJECT_TO_METADATA_COLUMN_PROJECT_ID = "PROJECT_ID";
public static final String ASSOCIATE_PROJECT_TO_TEMPLATE_COLUMN_PROJECT_ID = "PROJECT_PROJECT_ID";

/* +-----------------------------------------------------------------------+ */
/* +............................ JPQL .....................................+ */
Expand Down Expand Up @@ -88,6 +91,11 @@ public class Project {
@OneToMany(cascade = { CascadeType.REFRESH }, fetch = FetchType.EAGER, mappedBy = ProjectMetaDataEntity.PROPERTY_PROJECT_ID)
Set<ProjectMetaDataEntity> metaData = new HashSet<>();

@Column(name = COLUMN_TEMPLATE_ID, nullable = false)
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
@CollectionTable(name = TABLE_NAME_PROJECT_TEMPLATES)
Set<String> templateIds = new HashSet<>();

@Version
@Column(name = "VERSION")
Integer version;
Expand Down Expand Up @@ -127,6 +135,10 @@ public ProjectAccessLevel getAccessLevel() {
return accessLevel;
}

public Set<String> getTemplateIds() {
return templateIds;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.mercedesbenz.sechub.sharedkernel.Step;
import com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel;
import com.mercedesbenz.sechub.sharedkernel.security.RoleConstants;
import com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminAssignsTemplateToProject;
import com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUnassignsTemplateFromProject;
import com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminChangesProjectAccessLevel;
import com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminChangesProjectDescription;
import com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject;
Expand Down Expand Up @@ -86,6 +88,9 @@ public class ProjectAdministrationRestController {
@Autowired
ListProjectsService listProjectsService;

@Autowired
ProjectTemplateService projectTemplateService;

/* @formatter:off */
@UseCaseAdminCreatesProject(
@Step(
Expand Down Expand Up @@ -180,6 +185,22 @@ public void changeProjectAccessLevel(@PathVariable(name = "projectId") String pr
projectAccessLevelChangeService.changeProjectAccessLevel(projectId, projectAccessLevel);
}

/* @formatter:off */
@UseCaseAdminAssignsTemplateToProject(@Step(number = 1, name = "Rest call", description = "Admin does call REST API to assign a template to project", needsRestDoc = true))
@RequestMapping(path = AdministrationAPIConstants.API_ASSIGN_TEMPLATE_TO_PROJECT, method = RequestMethod.PUT, produces = {MediaType.APPLICATION_JSON_VALUE})
public void assignTemplateToProject(@PathVariable(name = "projectId") String projectId, @PathVariable(name = "templateId") String templateId) {
/* @formatter:on */
projectTemplateService.assignTemplateToProject(templateId, projectId);
}

/* @formatter:off */
@UseCaseAdminUnassignsTemplateFromProject(@Step(number = 1, name = "Rest call", description = "Admin does call REST API to unassign a template from project", needsRestDoc = true))
@RequestMapping(path = AdministrationAPIConstants.API_UNASSIGN_TEMPLATE_FROM_PROJECT, method = RequestMethod.DELETE, produces = {MediaType.APPLICATION_JSON_VALUE})
public void unassignTemplateFromProject(@PathVariable(name = "projectId") String projectId, @PathVariable(name = "templateId") String templateId) {
/* @formatter:on */
projectTemplateService.unassignTemplateFromProject(templateId, projectId);
}

@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.setValidator(validator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ public class ProjectDetailInformation {
public static final String PROPERTY_OWNER = "owner";
public static final String PROPERTY_ACCESSLEVEL = "accessLevel";
public static final String PROPERTY_DESCRIPTION = "description";
public static final String PROPERTY_TEMPLATE_IDS = "templateIds";

private String projectId;

private List<String> users = new ArrayList<>();
private List<String> whitelist = new ArrayList<>();
private List<String> templateIds = new ArrayList<>();
private Map<String, String> metaData = new HashMap<>();
private String owner;
private String description;
private String accessLevel;

ProjectDetailInformation() {
/* for JSON */
}

public ProjectDetailInformation(Project project) {
this.projectId = project.getId();

Expand All @@ -38,6 +44,8 @@ public ProjectDetailInformation(Project project) {

project.getMetaData().forEach(entry -> this.metaData.put(entry.key, entry.value));

project.getTemplateIds().forEach(templateid -> this.templateIds.add(templateid));

this.owner = project.getOwner().getName();

this.description = project.getDescription();
Expand Down Expand Up @@ -72,4 +80,8 @@ public String getDescription() {
public String getAccessLevel() {
return accessLevel;
}

public List<String> getTemplateIds() {
return templateIds;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
package com.mercedesbenz.sechub.domain.administration.project;

import static com.mercedesbenz.sechub.domain.administration.project.Project.*;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
Expand All @@ -9,14 +11,17 @@ public class ProjectRepositoryImpl implements ProjectRepositoryCustom {

@PersistenceContext
private EntityManager em;
/* @formatter:off */
private static final String QUERY_DELETE_PROJECT_TO_USER = "delete from " + TABLE_NAME_PROJECT_TO_USER + " p2u where p2u." + ASSOCIATE_PROJECT_TO_USER_COLUMN_PROJECT_ID + " = ?1";

private static final String QUERY_DELETE_PROJECT_TO_URI = "delete from " + TABLE_NAME_PROJECT_WHITELIST_URI + " p2w where p2w." + Project.ASSOCIATE_PROJECT_TO_URI_COLUMN_PROJECT_ID + " = ?1";

private static final String QUERY_DELETE_PROJECT_TO_METADATA = "delete from " + TABLE_NAME_PROJECT_METADATA + " p2w where p2w." + Project.ASSOCIATE_PROJECT_TO_METADATA_COLUMN_PROJECT_ID + " = ?1";

private static final String QUERY_DELETE_PROJECT_TO_USER = "delete from " + Project.TABLE_NAME_PROJECT_TO_USER + " p2u where p2u."
+ Project.ASSOCIATE_PROJECT_TO_USER_COLUMN_PROJECT_ID + " = ?1";
private static final String QUERY_DELETE_PROJECT_TO_URI = "delete from " + Project.TABLE_NAME_PROJECT_WHITELIST_URI + " p2w where p2w."
+ Project.ASSOCIATE_PROJECT_TO_URI_COLUMN_PROJECT_ID + " = ?1";
private static final String QUERY_DELETE_PROJECT_TO_METADATA = "delete from " + Project.TABLE_NAME_PROJECT_METADATA + " p2w where p2w."
+ Project.ASSOCIATE_PROJECT_TO_METADATA_COLUMN_PROJECT_ID + " = ?1";
private static final String QUERY_DELETE_PROJECT = "delete from " + Project.TABLE_NAME + " p where p." + Project.COLUMN_PROJECT_ID + " = ?1";
private static final String QUERY_DELETE_PROJECT_TO_TEMPLATE = "delete from " + TABLE_NAME_PROJECT_TEMPLATES + " p2w where p2w." + Project.ASSOCIATE_PROJECT_TO_TEMPLATE_COLUMN_PROJECT_ID + " = ?1";

private static final String QUERY_DELETE_PROJECT = "delete from " + TABLE_NAME + " p where p." + Project.COLUMN_PROJECT_ID + " = ?1";
/* @formatter:on */

@Override
public void deleteProjectWithAssociations(String projectId) {
Expand All @@ -32,6 +37,10 @@ public void deleteProjectWithAssociations(String projectId) {
deleteProjectToMetaData.setParameter(1, projectId);
deleteProjectToMetaData.executeUpdate();

Query deleteProjectToTemplate = em.createNativeQuery(QUERY_DELETE_PROJECT_TO_TEMPLATE);
deleteProjectToTemplate.setParameter(1, projectId);
deleteProjectToTemplate.executeUpdate();

Query deleteProject = em.createNativeQuery(QUERY_DELETE_PROJECT);
deleteProject.setParameter(1, projectId);
deleteProject.executeUpdate();
Expand Down
Loading
Loading