Skip to content

Commit

Permalink
EPMRPP-94013 || Not possible to create LDAP integration with any enco…
Browse files Browse the repository at this point in the history
…der type (#334)
  • Loading branch information
APiankouski committed Aug 29, 2024
1 parent dcb6704 commit 971dabb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -98,34 +103,37 @@ protected AuthenticationProvider getDelegate() {
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 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);
}
//TODO: temporary solution for working with encoded passwords
if (featureFlagHandler.isEnabled(FeatureFlag.DEFAULT_LDAP_ENCODER)) {
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 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);

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 971dabb

Please sign in to comment.