Search in sources :

Example 26 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.

the class AuthIntegrationStrategy method updateIntegration.

public Integration updateIntegration(IntegrationType integrationType, Long integrationId, UpdateAuthRQ request) {
    updateAuthRequestValidator.validate(request);
    final Integration integration = integrationRepository.findByIdAndTypeIdAndProjectIdIsNull(integrationId, integrationType.getId()).orElseThrow(() -> new ReportPortalException(ErrorType.AUTH_INTEGRATION_NOT_FOUND, integrationType.getName()));
    fill(integration, request);
    return save(integration);
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException)

Example 27 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.

the class SamlIntegrationStrategy method populateProviderDetails.

private void populateProviderDetails(Integration samlIntegration) {
    Map<String, Object> params = samlIntegration.getParams().getParams();
    ExternalIdentityProviderConfiguration externalConfiguration = new ExternalIdentityProviderConfiguration().setMetadata(SamlParameter.IDP_METADATA_URL.getRequiredParameter(samlIntegration));
    IdentityProviderMetadata remoteProvider = serviceProviderProvisioning.getHostedProvider().getRemoteProvider(externalConfiguration);
    params.put(IDP_URL.getParameterName(), remoteProvider.getEntityId());
    params.put(IDP_ALIAS.getParameterName(), remoteProvider.getEntityAlias());
    NameId nameId = ofNullable(remoteProvider.getDefaultNameId()).orElseGet(() -> {
        Optional<NameId> first = remoteProvider.getProviders().stream().filter(IdentityProvider.class::isInstance).map(IdentityProvider.class::cast).flatMap(v -> v.getNameIds().stream()).filter(Objects::nonNull).findFirst();
        return first.orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Provider does not contain information about identification mapping"));
    });
    params.put(IDP_NAME_ID.getParameterName(), nameId.toString());
}
Also used : NameId(org.springframework.security.saml.saml2.metadata.NameId) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IdentityProvider(org.springframework.security.saml.saml2.metadata.IdentityProvider) ExternalIdentityProviderConfiguration(org.springframework.security.saml.provider.service.config.ExternalIdentityProviderConfiguration) IdentityProviderMetadata(org.springframework.security.saml.saml2.metadata.IdentityProviderMetadata)

Example 28 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException 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 29 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException in project service-authorization by reportportal.

the class BasicPasswordAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    boolean accountNonLocked = !failureEventHandler.isBlocked(request.get());
    if (!accountNonLocked) {
        throw new ReportPortalException(ErrorType.ADDRESS_LOCKED);
    }
    Authentication auth = super.authenticate(authentication);
    eventPublisher.publishEvent(new UiUserSignedInEvent(auth));
    return auth;
}
Also used : UiUserSignedInEvent(com.epam.reportportal.auth.event.UiUserSignedInEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Authentication(org.springframework.security.core.Authentication)

Example 30 with ReportPortalException

use of com.epam.ta.reportportal.exception.ReportPortalException 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)

Aggregations

ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)33 Test (org.junit.jupiter.api.Test)7 InputStream (java.io.InputStream)6 AuthIntegrationType (com.epam.reportportal.auth.integration.AuthIntegrationType)5 BaseTest (com.epam.ta.reportportal.BaseTest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 Integration (com.epam.ta.reportportal.entity.integration.Integration)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 IntegrationType (com.epam.ta.reportportal.entity.integration.IntegrationType)3 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)3 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)3 Filter (com.epam.ta.reportportal.commons.querygen.Filter)2 QueryBuilder (com.epam.ta.reportportal.commons.querygen.QueryBuilder)2 ID (com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID)2 JooqFieldNameTransformer.fieldName (com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName)2 QueryUtils (com.epam.ta.reportportal.dao.util.QueryUtils)2 ServerSettings (com.epam.ta.reportportal.database.entity.settings.ServerSettings)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 Log (com.epam.ta.reportportal.entity.log.Log)2 JStatusEnum (com.epam.ta.reportportal.jooq.enums.JStatusEnum)2