use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.
the class ProjectAdministrationRestControllerMockTest method get_project_details_returns_project_details.
@Test
public void get_project_details_returns_project_details() throws Exception {
Project project = new Project();
project.id = "project1";
project.description = "description";
project.owner = new User();
ProjectDetailInformation details = new ProjectDetailInformation(project);
when(detailService.fetchDetails(matches("project1"))).thenReturn(details);
/* execute + test @formatter:off */
this.mockMvc.perform(get(https(PORT_USED).buildAdminFetchProjectInfoUrl(PROJECT_ID.pathElement()), "project1").contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(jsonPath("$.projectId", CoreMatchers.equalTo("project1"))).andExpect(jsonPath("$.description", CoreMatchers.equalTo("description"))).andExpect(jsonPath("$.owner", CoreMatchers.nullValue())).andExpect(jsonPath("$.users", CoreMatchers.notNullValue()));
verify(detailService).fetchDetails(matches("project1"));
/* @formatter:on */
}
use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.
the class ProjectAssignUserServiceTest method assign_already_added_user_to_project__throws_already_exists_exception.
@Test
public void assign_already_added_user_to_project__throws_already_exists_exception() {
User existingUser = mock(User.class);
/* prepare */
Project project1 = new Project();
project1.id = "project1";
project1.users.add(existingUser);
when(projectRepository.findOrFailProject("project1")).thenReturn(project1);
when(existingUser.getName()).thenReturn("existing");
when(userRepository.findOrFailUser("existing")).thenReturn(existingUser);
/* execute */
/* test */
assertThrows(AlreadyExistsException.class, () -> {
serviceToTest.assignUserToProject(existingUser.getName(), project1.getId());
});
}
use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.
the class ProjectAssignUserServiceTest method assign_new_user_to_project.
@Test
public void assign_new_user_to_project() {
User newUser = mock(User.class);
/* prepare */
Project project1 = new Project();
project1.id = "project1";
when(projectRepository.findOrFailProject("project1")).thenReturn(project1);
when(newUser.getName()).thenReturn("new");
when(userRepository.findOrFailUser("new")).thenReturn(newUser);
/* execute */
serviceToTest.assignUserToProject(newUser.getName(), project1.getId());
/* test */
verify(transactionService).saveInOwnTransaction(project1, newUser);
}
use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.
the class ProjectCreationService method createProject.
@Validated
/* @formatter:off */
@UseCaseAdminCreatesProject(@Step(number = 2, name = "Create project", description = "The service will create the project when not already existing with such name."))
public /* @formatter:on */
void createProject(@NotNull String projectId, @NotNull String description, @NotNull String owner, @NotNull Set<URI> whitelist, @NotNull ProjectMetaData metaData) {
LOG.info("Administrator {} triggers create of project:{}, having owner:{}", userContext.getUserId(), projectId, owner);
assertion.assertIsValidProjectId(projectId);
assertion.assertIsValidUserId(owner);
assertion.assertIsValidProjectDescription(description);
/* assert found */
Optional<Project> foundProject = projectRepository.findById(projectId);
if (foundProject.isPresent()) {
throw new AlreadyExistsException("Project '" + projectId + "' already exists");
}
Optional<User> foundOwner = userRepository.findById(owner);
if (!foundOwner.isPresent()) {
throw new NotFoundException("Owner '" + owner + "' not found");
}
/* setup */
Project project = new Project();
project.id = projectId;
project.description = description;
User ownerUser = foundOwner.get();
project.owner = ownerUser;
/**
* add only accepted/valid URIs - sanitize
*/
whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(project.getWhiteList()::add);
List<ProjectMetaDataEntity> metaDataEntities = metaData.getMetaDataMap().entrySet().stream().map(entry -> new ProjectMetaDataEntity(projectId, entry.getKey(), entry.getValue())).collect(Collectors.toList());
project.metaData.addAll(metaDataEntities);
/* store */
persistenceService.saveInOwnTransaction(project);
sendProjectCreatedEvent(projectId, whitelist);
sendRefreshUserAuth(ownerUser);
}
use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.
the class ProjectDeleteService method deleteProject.
@UseCaseAdminDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7 }, description = "The service will delete the project with dependencies and triggers asynchronous events"))
public void deleteProject(String projectId) {
auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30));
assertion.assertIsValidProjectId(projectId);
Project project = projectRepository.findOrFailProject(projectId);
/* create message containing data before project is deleted */
ProjectMessage message = new ProjectMessage();
message.setProjectId(project.getId());
message.setProjectActionTriggeredBy(userContext.getUserId());
User owner = project.getOwner();
if (owner == null) {
LOG.warn("No owner found for project {} while deleting", project.getId());
} else {
message.setProjectOwnerEmailAddress(owner.getEmailAdress());
// handle ORM mapping. Avoid cache conflicts
owner.getOwnedProjects().remove(project);
}
for (User user : project.getUsers()) {
message.addUserEmailAddress(user.getEmailAdress());
// handle ORM mapping. Avoid cache conflicts
user.getProjects().remove(project);
}
transactionService.deleteWithAssociationsInOwnTransaction(projectId);
informProjectDeleted(message);
if (owner != null) {
sendRefreshUserAuth(owner);
}
}
Aggregations