Search in sources :

Example 11 with Integration

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

the class SamlIntegrationStrategy method save.

@Override
protected Integration save(Integration integration) {
    populateProviderDetails(integration);
    final Integration result = super.save(integration);
    eventPublisher.publishEvent(new SamlProvidersReloadEvent(result.getType()));
    return result;
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) SamlProvidersReloadEvent(com.epam.reportportal.auth.event.SamlProvidersReloadEvent)

Example 12 with Integration

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

the class DeleteAuthIntegrationHandlerImpl method deleteAuthIntegrationById.

@Override
public OperationCompletionRS deleteAuthIntegrationById(Long integrationId) {
    Integration integration = integrationRepository.findById(integrationId).orElseThrow(() -> new ReportPortalException(ErrorType.INTEGRATION_NOT_FOUND, integrationId));
    BusinessRule.expect(integration.getType().getIntegrationGroup(), equalTo(IntegrationGroupEnum.AUTH)).verify(ErrorType.BAD_REQUEST_ERROR, "Integration should have an 'AUTH' integration group type.");
    integrationRepository.deleteById(integrationId);
    if (AuthIntegrationType.SAML.getName().equals(integration.getType().getName())) {
        eventPublisher.publishEvent(new SamlProvidersReloadEvent(integration.getType()));
    }
    return new OperationCompletionRS("Auth integration with id= " + integrationId + " has been successfully removed.");
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) SamlProvidersReloadEvent(com.epam.reportportal.auth.event.SamlProvidersReloadEvent) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 13 with Integration

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

the class GetSamlIntegrationsStrategy method getIntegration.

@Override
public AbstractAuthResource getIntegration() {
    IntegrationType samlIntegrationType = integrationTypeRepository.findByName(AuthIntegrationType.SAML.getName()).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, AuthIntegrationType.SAML.getName()));
    List<Integration> providers = integrationRepository.findAllGlobalByType(samlIntegrationType);
    SamlProvidersResource resource = TO_PROVIDERS_RESOURCE.apply(providers);
    resource.setType(samlIntegrationType.getName());
    return resource;
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) SamlProvidersResource(com.epam.ta.reportportal.ws.model.integration.auth.SamlProvidersResource) AuthIntegrationType(com.epam.reportportal.auth.integration.AuthIntegrationType) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType)

Example 14 with Integration

use of com.epam.ta.reportportal.entity.integration.Integration 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 15 with Integration

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

the class IntegrationRepositoryTest method shouldFindAllByProjectIdAndIntegrationTypeWhenExists.

@Test
void shouldFindAllByProjectIdAndIntegrationTypeWhenExists() {
    IntegrationType integrationType = integrationTypeRepository.findById(JIRA_INTEGRATION_TYPE_ID).get();
    List<Integration> integrations = integrationRepository.findAllByProjectIdAndType(DEFAULT_PERSONAL_PROJECT_ID, integrationType);
    assertNotNull(integrations);
    assertEquals(1L, integrations.size());
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

Integration (com.epam.ta.reportportal.entity.integration.Integration)18 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)8 BaseTest (com.epam.ta.reportportal.BaseTest)7 Test (org.junit.jupiter.api.Test)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 AuthIntegrationType (com.epam.reportportal.auth.integration.AuthIntegrationType)4 SamlProvidersReloadEvent (com.epam.reportportal.auth.event.SamlProvidersReloadEvent)2 AuthIntegrationStrategy (com.epam.reportportal.auth.integration.handler.impl.strategy.AuthIntegrationStrategy)2 Project (com.epam.ta.reportportal.entity.project.Project)2 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)2 AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)1 AuthIntegrationBuilder (com.epam.reportportal.auth.integration.builder.AuthIntegrationBuilder)1 SamlParameter (com.epam.reportportal.auth.integration.parameter.SamlParameter)1 CROP_DOMAIN (com.epam.reportportal.auth.util.AuthUtils.CROP_DOMAIN)1 ContentTypeResolver (com.epam.reportportal.commons.ContentTypeResolver)1 UserBinaryDataService (com.epam.ta.reportportal.binary.UserBinaryDataService)1 IntegrationRepository (com.epam.ta.reportportal.dao.IntegrationRepository)1 IntegrationTypeRepository (com.epam.ta.reportportal.dao.IntegrationTypeRepository)1 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)1 UserRepository (com.epam.ta.reportportal.dao.UserRepository)1