Search in sources :

Example 1 with ProjectWhiteList

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList in project sechub by mercedes-benz.

the class ProjectAdministrationRestController method createProject.

/* @formatter:off */
@UseCaseAdminCreatesProject(@Step(number = 1, name = "Rest call", needsRestDoc = true, description = "Administrator creates a new project by calling rest api"))
@RequestMapping(path = AdministrationAPIConstants.API_CREATE_PROJECT, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseStatus(HttpStatus.CREATED)
public void createProject(@RequestBody @Valid ProjectJsonInput input) {
    Set<URI> whiteListedURIs = new LinkedHashSet<>();
    Optional<ProjectWhiteList> whitelistOption = input.getWhiteList();
    if (whitelistOption.isPresent()) {
        ProjectWhiteList whiteList = whitelistOption.get();
        whiteListedURIs.addAll(whiteList.getUris());
    }
    ProjectMetaData metaData = new ProjectMetaData();
    if (input.getMetaData().isPresent()) {
        metaData = input.getMetaData().get();
    }
    /* @formatter:on */
    creationService.createProject(input.getName(), input.getDescription(), input.getOwner(), whiteListedURIs, metaData);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectMetaData(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData) ProjectWhiteList(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList) URI(java.net.URI) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) UseCaseAdminCreatesProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ProjectWhiteList

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList in project sechub by mercedes-benz.

the class ProjectJsonInputValidationTest method when_whitelisturivalidation_with_empty_uri_invalid_api_error.

@Test
public void when_whitelisturivalidation_with_empty_uri_invalid_api_error() throws URISyntaxException {
    /* prepare */
    ProjectWhiteList whiteList = new ProjectWhiteList();
    whiteList.getUris().add(URI.create(""));
    when(input.getWhiteList()).thenReturn(Optional.of(whiteList));
    when(whiteListValidation.validate(any())).thenReturn(failedResult);
    /* execute */
    toTest.checkWhitelist(errors, input);
    /* test */
    verify(errors, never()).rejectValue(eq(ProjectJsonInput.PROPERTY_WHITELIST), eq("api.error.whitelist.invalid"), any());
}
Also used : ProjectWhiteList(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList) Test(org.junit.Test)

Example 3 with ProjectWhiteList

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList in project sechub by mercedes-benz.

the class ProjectUpdateAdministrationRestController method updateProjectWhitelist.

/* @formatter:off */
@UseCaseUpdateProjectWhitelist(@Step(number = 1, name = "Rest call", description = "White list will be updated", needsRestDoc = true))
@RequestMapping(path = AdministrationAPIConstants.API_UPDATE_PROJECT_WHITELIST, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void updateProjectWhitelist(@Validated @RequestBody ProjectJsonInput input, @PathVariable(name = "projectId") String projectId) {
    /* @formatter:on */
    Optional<ProjectWhiteList> projectWhiteList = input.getWhiteList();
    List<URI> whiteList;
    if (projectWhiteList.isPresent()) {
        ProjectWhiteList r = projectWhiteList.get();
        whiteList = r.getUris();
    } else {
        whiteList = Collections.emptyList();
    }
    updateProjectWhitelistService.updateProjectWhitelist(projectId, whiteList);
}
Also used : ProjectWhiteList(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList) URI(java.net.URI) UseCaseUpdateProjectWhitelist(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseUpdateProjectWhitelist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ProjectWhiteList

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList in project sechub by mercedes-benz.

the class ProjectJsonInputTestMain method main.

public static void main(String[] args) {
    ProjectJsonInput input = new ProjectJsonInput();
    input.setApiVersion("1.0");
    input.setDescription("description");
    ProjectWhiteList list = new ProjectWhiteList();
    list.getUris().add(URI.create("https://localhost/test"));
    Optional<ProjectWhiteList> whitelist = Optional.of(list);
    input.setWhiteList(whitelist);
    Map<String, String> metaData = new HashMap<>();
    metaData.put("key1", "value1");
    input.setMetaData(Optional.of(metaData));
    System.out.println(input.toJSON());
}
Also used : HashMap(java.util.HashMap) ProjectWhiteList(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList)

Aggregations

ProjectWhiteList (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList)4 URI (java.net.URI)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ProjectMetaData (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData)1 UseCaseAdminCreatesProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject)1 UseCaseUpdateProjectWhitelist (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseUpdateProjectWhitelist)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1