Search in sources :

Example 6 with Project

use of com.epam.ta.reportportal.entity.project.Project in project service-authorization by reportportal.

the class SamlUserReplicator method replicateUser.

public User replicateUser(ReportPortalSamlAuthentication samlAuthentication) {
    String userName = CROP_DOMAIN.apply(samlAuthentication.getPrincipal());
    Optional<User> userOptional = userRepository.findByLogin(userName);
    if (userOptional.isPresent()) {
        return userOptional.get();
    }
    IntegrationType samlIntegrationType = integrationTypeRepository.findByName(AuthIntegrationType.SAML.getName()).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, AuthIntegrationType.SAML.getName()));
    List<Integration> providers = integrationRepository.findAllGlobalByType(samlIntegrationType);
    Optional<Integration> samlProvider = providers.stream().filter(provider -> {
        Optional<String> idpUrlOptional = SamlParameter.IDP_URL.getParameter(provider);
        return idpUrlOptional.isPresent() && idpUrlOptional.get().equalsIgnoreCase(samlAuthentication.getIssuer());
    }).findFirst();
    User user = new User();
    user.setLogin(userName);
    List<Attribute> details = samlAuthentication.getDetails();
    if (samlProvider.isPresent()) {
        populateUserDetailsIfSettingsArePresent(user, samlProvider.get(), details);
    } else {
        populateUserDetails(user, details);
    }
    user.setUserType(UserType.SAML);
    user.setRole(UserRole.USER);
    user.setExpired(false);
    Project project = generatePersonalProject(user);
    user.getProjects().add(project.getUsers().iterator().next());
    user.setMetadata(defaultMetaData());
    userRepository.save(user);
    return user;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) PersonalProjectService(com.epam.ta.reportportal.util.PersonalProjectService) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) UserRole(com.epam.ta.reportportal.entity.user.UserRole) IntegrationRepository(com.epam.ta.reportportal.dao.IntegrationRepository) UserType(com.epam.ta.reportportal.entity.user.UserType) AbstractUserReplicator(com.epam.reportportal.auth.integration.AbstractUserReplicator) ContentTypeResolver(com.epam.reportportal.commons.ContentTypeResolver) AuthIntegrationType(com.epam.reportportal.auth.integration.AuthIntegrationType) User(com.epam.ta.reportportal.entity.user.User) Integration(com.epam.ta.reportportal.entity.integration.Integration) UserRepository(com.epam.ta.reportportal.dao.UserRepository) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationTypeRepository(com.epam.ta.reportportal.dao.IntegrationTypeRepository) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) List(java.util.List) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) UserBinaryDataService(com.epam.ta.reportportal.binary.UserBinaryDataService) CROP_DOMAIN(com.epam.reportportal.auth.util.AuthUtils.CROP_DOMAIN) SamlParameter(com.epam.reportportal.auth.integration.parameter.SamlParameter) Transactional(org.springframework.transaction.annotation.Transactional) Integration(com.epam.ta.reportportal.entity.integration.Integration) User(com.epam.ta.reportportal.entity.user.User) Optional(java.util.Optional) Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) AuthIntegrationType(com.epam.reportportal.auth.integration.AuthIntegrationType)

Example 7 with Project

use of com.epam.ta.reportportal.entity.project.Project in project service-authorization by reportportal.

the class GitHubUserReplicator method createUser.

private User createUser(UserResource userResource, GitHubClient gitHubClient) {
    User user = new User();
    String login = normalizeId(userResource.getLogin());
    user.setLogin(login);
    updateUser(user, userResource, gitHubClient);
    user.setUserType(UserType.GITHUB);
    user.setRole(UserRole.USER);
    user.setExpired(false);
    final Project project = generatePersonalProject(user);
    user.getProjects().addAll(project.getUsers());
    return user;
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User)

Example 8 with Project

use of com.epam.ta.reportportal.entity.project.Project in project commons-dao by reportportal.

the class IntegrationRepositoryTest method findAllProjectByIntegrationGroup.

@Test
void findAllProjectByIntegrationGroup() {
    Project project = new Project();
    project.setId(1L);
    List<Integration> integrations = integrationRepository.findAllProjectByGroup(project, IntegrationGroupEnum.BTS);
    assertThat(integrations, hasSize(4));
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) Integration(com.epam.ta.reportportal.entity.integration.Integration) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

Project (com.epam.ta.reportportal.entity.project.Project)8 User (com.epam.ta.reportportal.entity.user.User)6 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)4 Transactional (org.springframework.transaction.annotation.Transactional)4 AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)3 ContentTypeResolver (com.epam.reportportal.commons.ContentTypeResolver)3 UserBinaryDataService (com.epam.ta.reportportal.binary.UserBinaryDataService)3 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)3 UserRepository (com.epam.ta.reportportal.dao.UserRepository)3 Metadata (com.epam.ta.reportportal.entity.Metadata)3 UserRole (com.epam.ta.reportportal.entity.user.UserRole)3 UserType (com.epam.ta.reportportal.entity.user.UserType)3 PersonalProjectService (com.epam.ta.reportportal.util.PersonalProjectService)3 Optional (java.util.Optional)3 Component (org.springframework.stereotype.Component)3 UserSynchronizationException (com.epam.reportportal.auth.oauth.UserSynchronizationException)2 CROP_DOMAIN (com.epam.reportportal.auth.util.AuthUtils.CROP_DOMAIN)2 BaseTest (com.epam.ta.reportportal.BaseTest)2 EntityUtils.normalizeId (com.epam.ta.reportportal.commons.EntityUtils.normalizeId)2 Integration (com.epam.ta.reportportal.entity.integration.Integration)2