From e06a163e143184aff3b0ef25852af0f0d02628c4 Mon Sep 17 00:00:00 2001 From: Andrei Piankouski Date: Thu, 29 Aug 2024 13:28:21 +0300 Subject: [PATCH] EPMRPP-94013 || Use Feature flag --- build.gradle | 2 +- .../integration/ldap/LdapAuthProvider.java | 61 +++++++++++-------- src/main/resources/application.properties | 2 +- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index ac22f969..2f1b966b 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ dependencies { api 'com.epam.reportportal:commons-dao' api 'com.epam.reportportal:commons' } else { - api 'com.github.reportportal:commons-dao:b0e00d6' + api 'com.github.reportportal:commons-dao:4f0bff6' api 'com.github.reportportal:commons:50a1192' } diff --git a/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapAuthProvider.java b/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapAuthProvider.java index 69c0621e..16fb3bf9 100644 --- a/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapAuthProvider.java +++ b/src/main/java/com/epam/reportportal/auth/integration/ldap/LdapAuthProvider.java @@ -24,7 +24,9 @@ import com.epam.reportportal.rules.exception.ReportPortalException; import com.epam.ta.reportportal.commons.accessible.Accessible; import com.epam.ta.reportportal.dao.IntegrationRepository; +import com.epam.ta.reportportal.entity.enums.FeatureFlag; import com.epam.ta.reportportal.entity.integration.Integration; +import com.epam.ta.reportportal.util.FeatureFlagHandler; import java.util.Collections; import org.jasypt.util.text.BasicTextEncryptor; import org.springframework.beans.factory.annotation.Autowired; @@ -49,6 +51,9 @@ public class LdapAuthProvider extends EnableableAuthProvider { public static final String LDAP_TIMEOUT = "3000"; private final DetailsContextMapper detailsContextMapper; + @Autowired + private FeatureFlagHandler featureFlagHandler; + @Autowired private BasicTextEncryptor encryptor; @@ -99,34 +104,36 @@ protected AuthenticationProvider getDelegate() { LdapParameter.USER_SEARCH_FILTER.getParameter(integration).ifPresent(builder::userSearchFilter); //TODO: temporary solution for working with encoded passwords -/* LdapParameter.PASSWORD_ENCODER_TYPE.getParameter(integration).ifPresent(it -> { - LdapAuthenticationProviderConfigurer - .PasswordCompareConfigurer passwordCompareConfigurer = builder.passwordCompare(); - LdapParameter.PASSWORD_ATTRIBUTE.getParameter(integration) - .ifPresent(passwordCompareConfigurer::passwordAttribute); - - *//* - * DIRTY HACK. If LDAP password has salt, 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); - } + if (!featureFlagHandler.isEnabled(FeatureFlag.DEFAULT_LDAP_ENCODER)) { + LdapParameter.PASSWORD_ENCODER_TYPE.getParameter(integration).ifPresent(it -> { + LdapAuthenticationProviderConfigurer + .PasswordCompareConfigurer passwordCompareConfigurer = builder.passwordCompare(); + LdapParameter.PASSWORD_ATTRIBUTE.getParameter(integration) + .ifPresent(passwordCompareConfigurer::passwordAttribute); + + /* + * DIRTY HACK. If LDAP password has salt, 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); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 38b80fa4..846fa586 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -84,7 +84,7 @@ rp.amqp.pass= # ReportPortal file storage configuration datastore.path=/data/storage -datastore.type:=minio +datastore.type=minio datastore.endpoint= http://play.min.io datastore.accessKey= datastore.secretKey=