Skip to content

Commit

Permalink
Merge pull request #3545 from mercedes-benz/feature-3521-templates-an…
Browse files Browse the repository at this point in the history
…d-assets

Provide templates and assets
  • Loading branch information
de-jcup authored Dec 6, 2024
2 parents 2274af0 + 5795a83 commit e1510aa
Show file tree
Hide file tree
Showing 189 changed files with 8,944 additions and 1,039 deletions.
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}";

/* +-----------------------------------------------------------------------+ */
/* +............................ 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

0 comments on commit e1510aa

Please sign in to comment.