Search in sources :

Example 6 with Integration

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

the class AuthIntegrationStrategy method createIntegration.

public Integration createIntegration(IntegrationType integrationType, UpdateAuthRQ request, String username) {
    updateAuthRequestValidator.validate(request);
    final Integration integration = new AuthIntegrationBuilder().addCreator(username).addIntegrationType(integrationType).addCreationDate(LocalDateTime.now(ZoneOffset.UTC)).build();
    fill(integration, request);
    return save(integration);
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) AuthIntegrationBuilder(com.epam.reportportal.auth.integration.builder.AuthIntegrationBuilder)

Example 7 with Integration

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

the class SamlProvidersReloadEventHandler method onApplicationEvent.

@Override
public void onApplicationEvent(SamlProvidersReloadEvent event) {
    final IntegrationType integrationType = event.getIntegrationType();
    final List<Integration> integrations = integrationRepository.findAllGlobalByType(integrationType);
    LocalServiceProviderConfiguration serviceProvider = samlConfiguration.getServiceProvider();
    serviceProvider.getProviders().clear();
    serviceProvider.getProviders().addAll(SamlConverter.TO_EXTERNAL_PROVIDER_CONFIG.apply(integrations));
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) LocalServiceProviderConfiguration(org.springframework.security.saml.provider.service.config.LocalServiceProviderConfiguration) IntegrationType(com.epam.ta.reportportal.entity.integration.IntegrationType)

Example 8 with Integration

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

the class ActiveDirectoryAuthProvider method getDelegate.

@Override
protected AuthenticationProvider getDelegate() {
    Integration integration = integrationRepository.findAllByTypeIn(AuthIntegrationType.ACTIVE_DIRECTORY.getName()).stream().findFirst().orElseThrow(() -> new BadCredentialsException("Active Directory is not configured"));
    ActiveDirectoryLdapAuthenticationProvider adAuth = new ActiveDirectoryLdapAuthenticationProvider(LdapParameter.DOMAIN.getParameter(integration).orElse(null), LdapParameter.URL.getRequiredParameter(integration), LdapParameter.BASE_DN.getRequiredParameter(integration));
    adAuth.setAuthoritiesMapper(new NullAuthoritiesMapper());
    adAuth.setUserDetailsContextMapper(detailsContextMapper);
    LdapParameter.SEARCH_FILTER_REMOVE_NOT_PRESENT.getParameter(integration).ifPresent(adAuth::setSearchFilter);
    return adAuth;
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) ActiveDirectoryLdapAuthenticationProvider(org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) NullAuthoritiesMapper(org.springframework.security.core.authority.mapping.NullAuthoritiesMapper)

Example 9 with Integration

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

the class LdapAuthProvider method getDelegate.

@Override
protected AuthenticationProvider getDelegate() {
    Integration integration = integrationRepository.findAllByTypeIn(AuthIntegrationType.LDAP.getName()).stream().findFirst().orElseThrow(() -> new BadCredentialsException("LDAP is not configured"));
    DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(singletonList(LdapParameter.URL.getRequiredParameter(integration)), LdapParameter.BASE_DN.getRequiredParameter(integration));
    LdapParameter.MANAGER_PASSWORD.getParameter(integration).ifPresent(it -> contextSource.setPassword(encryptor.decrypt(it)));
    LdapParameter.MANAGER_DN.getParameter(integration).ifPresent(contextSource::setUserDn);
    contextSource.afterPropertiesSet();
    LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> builder = new LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder>().contextSource(contextSource).ldapAuthoritiesPopulator(new NullLdapAuthoritiesPopulator()).userDetailsContextMapper(detailsContextMapper);
    /*
		 * Basically, groups are not used
		 */
    LdapParameter.GROUP_SEARCH_FILTER.getParameter(integration).ifPresent(builder::groupSearchFilter);
    LdapParameter.GROUP_SEARCH_BASE.getParameter(integration).ifPresent(builder::groupSearchBase);
    LdapParameter.USER_SEARCH_FILTER.getParameter(integration).ifPresent(builder::userSearchFilter);
    LdapParameter.PASSWORD_ENCODER_TYPE.getParameter(integration).ifPresent(it -> {
        LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder>.PasswordCompareConfigurer passwordCompareConfigurer = builder.passwordCompare();
        LdapParameter.PASSWORD_ATTRIBUTE.getParameter(integration).ifPresent(passwordCompareConfigurer::passwordAttribute);
        /*
			 * DIRTY HACK. If LDAP's password has solt, ldaptemplate.compare operation does not work
			 * since we don't know server's salt.
			 * To enable local password comparison, we need to provide password encoder from crypto's package
			 * This is why we just wrap old encoder with new one interface
			 * New encoder cannot be used everywhere since it does not have implementation for LDAP
			 */
        final PasswordEncoder delegate = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        builder.passwordEncoder(new org.springframework.security.crypto.password.PasswordEncoder() {

            @Override
            public String encode(CharSequence rawPassword) {
                return delegate.encode(rawPassword);
            }

            @Override
            public boolean matches(CharSequence rawPassword, String encodedPassword) {
                return delegate.matches(rawPassword, encodedPassword);
            }
        });
    });
    LdapParameter.USER_DN_PATTERN.getParameter(integration).ifPresent(builder::userDnPatterns);
    try {
        return (AuthenticationProvider) Accessible.on(builder).method(LdapAuthenticationProviderConfigurer.class.getDeclaredMethod("build")).invoke();
    } catch (Throwable e) {
        throw new ReportPortalException("Cannot build LDAP auth provider", e);
    }
}
Also used : Integration(com.epam.ta.reportportal.entity.integration.Integration) DefaultSpringSecurityContextSource(org.springframework.security.ldap.DefaultSpringSecurityContextSource) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) AuthenticationProvider(org.springframework.security.authentication.AuthenticationProvider) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) NullLdapAuthoritiesPopulator(org.springframework.security.ldap.authentication.NullLdapAuthoritiesPopulator) LdapAuthenticationProviderConfigurer(org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer)

Example 10 with Integration

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

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