Search in sources :

Example 6 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectChangeOwnerServiceTest method assign_same_owner_to_project__throws_already_exists_exception.

@Test
public void assign_same_owner_to_project__throws_already_exists_exception() {
    User oldOwner = mock(User.class);
    /* prepare */
    Project project1 = new Project();
    project1.id = "project1";
    project1.owner = oldOwner;
    when(projectRepository.findOrFailProject("project1")).thenReturn(project1);
    when(oldOwner.getName()).thenReturn("old");
    when(userRepository.findOrFailUser("old")).thenReturn(oldOwner);
    /* execute */
    /* test */
    assertThrows(AlreadyExistsException.class, () -> {
        serviceToTest.changeProjectOwner(oldOwner.getName(), project1.getId());
    });
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) Test(org.junit.Test)

Example 7 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectTransactionService method saveInOwnTransaction.

/**
 * Persists a project, users and project meta data in same (new) transaction
 *
 * @param project
 * @param users
 * @return persisted project
 */
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Project saveInOwnTransaction(Project project, User... users) {
    requireNonNull(project, "Project may not be null!");
    requireNonNull(users, "User may not be null!");
    /* store */
    Project savedProject = projectRepository.save(project);
    LOG.debug("Saved project:{}", savedProject.getId());
    metaDataRepository.saveAll(project.metaData);
    LOG.debug("Saved metadata for project:{}", savedProject.getId());
    for (User user : users) {
        User savedUser = userRepository.save(user);
        LOG.debug("Saved user:{}", savedUser.getName());
    }
    return savedProject;
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectUnassignUserService method unassignUserFromProject.

/* @formatter:off */
@UseCaseAdminUnassignsUserFromProject(@Step(number = 2, name = "Unassign user", description = "The service will remove the user to the project. If users has no longer access to projects ROLE_USER will be removed"))
public /* @formatter:on */
void unassignUserFromProject(String userId, String projectId) {
    auditLogService.log("triggers unassignment of user:{} to project:{}", logSanitizer.sanitize(userId, 30), logSanitizer.sanitize(projectId, 30));
    assertion.assertIsValidUserId(userId);
    assertion.assertIsValidProjectId(projectId);
    Project project = projectRepository.findOrFailProject(projectId);
    User user = userRepository.findOrFailUser(userId);
    if (!project.getUsers().remove(user)) {
        throw new AlreadyExistsException("User already not assigned to this project!");
    }
    user.getProjects().remove(project);
    transactionService.saveInOwnTransaction(project, user);
    sendUserRemovedFromProjectEvent(projectId, user);
    sendRequestUserRoleRecalculation(user);
}
Also used : UseCaseAdminUnassignsUserFromProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject) User(com.mercedesbenz.sechub.domain.administration.user.User) AlreadyExistsException(com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException) UseCaseAdminUnassignsUserFromProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject)

Example 9 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class JobRestartRequestService method buildMessage.

private JobMessage buildMessage(UUID jobUUID) {
    JobMessage message = new JobMessage();
    message.setJobUUID(jobUUID);
    JobInformation probe = new JobInformation();
    probe.setJobUUID(jobUUID);
    Example<JobInformation> example = Example.of(probe);
    Optional<JobInformation> optJobInfo = repository.findOne(example);
    if (!optJobInfo.isPresent()) {
        LOG.warn("Did not found job information, so not able to resolve owner email address");
        return message;
    }
    JobInformation jobInfo = optJobInfo.get();
    if (jobInfo.owner == null) {
        LOG.warn("Did not found owner inside job information, so not able to resolve owner email address");
        return message;
    }
    Optional<User> optUser = userRepository.findById(jobInfo.owner);
    if (!optUser.isPresent()) {
        LOG.warn("Did not found owner {} inside user repo, so not able to resolve owner email address", jobInfo.owner);
        return message;
    }
    message.setOwner(jobInfo.owner);
    message.setOwnerEmailAddress(optUser.get().getEmailAdress());
    return message;
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) JobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)

Example 10 with User

use of com.mercedesbenz.sechub.domain.administration.user.User in project sechub by mercedes-benz.

the class ProjectAdministrationRestControllerRestDocTest method restdoc_show_project_details.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminShowsProjectDetails.class)
public void restdoc_show_project_details() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminShowsProjectDetailsUrl(PROJECT_ID.pathElement());
    Class<? extends Annotation> useCase = UseCaseAdminShowsProjectDetails.class;
    Project project = mock(Project.class);
    when(project.getId()).thenReturn("projectId1");
    when(project.getAccessLevel()).thenReturn(ProjectAccessLevel.FULL);
    Set<User> users = new LinkedHashSet<>();
    User user1 = mock(User.class);
    when(user1.getName()).thenReturn("name1");
    User user2 = mock(User.class);
    when(user2.getName()).thenReturn("name2");
    users.add(user1);
    users.add(user2);
    when(project.getUsers()).thenReturn(users);
    when(project.getOwner()).thenReturn(user1);
    Set<URI> whiteList = new LinkedHashSet<>();
    whiteList.add(new URI("http://www.sechub.example.org"));
    whiteList.add(new URI("http://www.sechub.example.com"));
    when(project.getWhiteList()).thenReturn(whiteList);
    Set<ProjectMetaDataEntity> metaData = new LinkedHashSet<>();
    ProjectMetaDataEntity entry = new ProjectMetaDataEntity("projectId1", "key1", "value1");
    metaData.add(entry);
    when(project.getMetaData()).thenReturn(metaData);
    when(project.getDescription()).thenReturn("description");
    ProjectDetailInformation detailInformation = new ProjectDetailInformation(project);
    when(detailInformationService.fetchDetails("projectId1")).thenReturn(detailInformation);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, "projectId1").contentType(MediaType.APPLICATION_JSON_VALUE)).andDo(print()).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.PROJECT_DETAILS.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The id for project to show details for")), responseFields(fieldWithPath(ProjectDetailInformation.PROPERTY_PROJECT_ID).description("The name of the project"), fieldWithPath(ProjectDetailInformation.PROPERTY_USERS).description("A list of all users having access to the project"), fieldWithPath(ProjectDetailInformation.PROPERTY_OWNER).description("Username of the owner of this project. An owner is the person in charge."), fieldWithPath(ProjectDetailInformation.PROPERTY_WHITELIST).description("A list of all whitelisted URIs. Only these ones can be scanned for the project!"), fieldWithPath(ProjectDetailInformation.PROPERTY_METADATA).description("An JSON object containing metadata key-value pairs defined for this project."), fieldWithPath(ProjectDetailInformation.PROPERTY_METADATA + ".key1").description("An arbitrary metadata key"), fieldWithPath(ProjectDetailInformation.PROPERTY_ACCESSLEVEL).description("The project access level"), fieldWithPath(ProjectDetailInformation.PROPERTY_DESCRIPTION).description("The project description."))));
/* @formatter:on */
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.mercedesbenz.sechub.domain.administration.project.Project) UseCaseAdminAssignsUserToProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject) UseCaseAdminCreatesProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject) UseCaseAdminDeleteProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject) UseCaseAdminUnassignsUserFromProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject) WithMockUser(org.springframework.security.test.context.support.WithMockUser) User(com.mercedesbenz.sechub.domain.administration.user.User) UseCaseAdminShowsProjectDetails(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminShowsProjectDetails) URI(java.net.URI) ProjectMetaDataEntity(com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity) ProjectDetailInformation(com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Aggregations

User (com.mercedesbenz.sechub.domain.administration.user.User)20 Test (org.junit.Test)11 AlreadyExistsException (com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException)4 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 Project (com.mercedesbenz.sechub.domain.administration.project.Project)3 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)3 UseCaseAdminCreatesProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject)3 UseCaseAdminDeleteProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject)3 UseCaseAdminAssignsUserToProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminAssignsUserToProject)3 UseCaseAdminUnassignsUserFromProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUnassignsUserFromProject)3 URI (java.net.URI)3 LinkedHashSet (java.util.LinkedHashSet)3 ProjectDetailInformation (com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation)2 ProjectMetaDataEntity (com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity)2 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)2 JobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)2 ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)2 ProjectMetaData (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData)1 UserDetailInformation (com.mercedesbenz.sechub.domain.administration.user.UserDetailInformation)1