Skip to content
Snippets Groups Projects

feat: Integrate LDAP secure port through UnboundID

1 unresolved thread
4 files
+ 61
40
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -11,26 +11,33 @@
@@ -11,26 +11,33 @@
**********************************************************************/
**********************************************************************/
package org.eclipsefoundation.profile.services.impl;
package org.eclipsefoundation.profile.services.impl;
 
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.List;
 
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Inject;
 
import org.eclipsefoundation.core.service.CachingService;
import org.eclipsefoundation.profile.config.LDAPConnectionConfig;
import org.eclipsefoundation.profile.config.LDAPConnectionConfig;
import org.eclipsefoundation.profile.models.LdapResult;
import org.eclipsefoundation.profile.models.LdapResult;
import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames;
import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames;
import org.eclipsefoundation.profile.services.LDAPService;
import org.eclipsefoundation.profile.services.LDAPService;
 
import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import com.unboundid.ldap.sdk.DN;
import com.unboundid.ldap.sdk.DN;
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnection;
 
import com.unboundid.ldap.sdk.LDAPConnectionOptions;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchScope;
import com.unboundid.ldap.sdk.SearchScope;
 
import com.unboundid.util.ssl.HostNameSSLSocketVerifier;
 
import com.unboundid.util.ssl.SSLUtil;
@ApplicationScoped
@ApplicationScoped
public class DefaultLDAPService implements LDAPService {
public class DefaultLDAPService implements LDAPService {
@@ -41,28 +48,57 @@ public class DefaultLDAPService implements LDAPService {
@@ -41,28 +48,57 @@ public class DefaultLDAPService implements LDAPService {
@Inject
@Inject
LDAPConnectionConfig config;
LDAPConnectionConfig config;
 
@Inject
 
CachingService cache;
 
@Override
@Override
public LdapResult searchLdapByUsername(String efUsername) {
public Optional<LdapResult> searchLdapByUsername(String efUsername) {
return searchLdap(Filter.createEqualityFilter(ProfileAPIParameterNames.UID.getName(), efUsername));
 
LOGGER.debug("Searching LDAP for user: {}", efUsername);
 
 
Optional<LdapResult> result = cache.get(efUsername, new MultivaluedMapImpl<>(), LdapResult.class,
 
() -> searchLdap(Filter.createEqualityFilter(ProfileAPIParameterNames.UID.getName(), efUsername)));
 
 
if (result.isEmpty()) {
 
LOGGER.warn("LDAP - no user with name: {}", efUsername);
 
}
 
 
return result;
}
}
@Override
@Override
public LdapResult searchLdapByGhHandle(String ghHandle) {
public Optional<LdapResult> searchLdapByGhHandle(String ghHandle) {
return searchLdap(
Filter.createEqualityFilter(EMPLOYEE_TYPE, "GITHUB:" + ghHandle));
LOGGER.debug("Searching LDAP for GH handle: {}", ghHandle);
 
 
Optional<LdapResult> result = cache.get(ghHandle, new MultivaluedMapImpl<>(), LdapResult.class,
 
() -> searchLdap(Filter.createEqualityFilter(EMPLOYEE_TYPE, "GITHUB:" + ghHandle)));
 
 
if (result.isEmpty()) {
 
LOGGER.warn("LDAP - no user with GH id: {}", ghHandle);
 
}
 
 
return result;
}
}
/**
/**
* Performs an LDAP search using the desired filter. Establishes a connection,
* Performs an LDAP search using the desired filter. Establishes a connection,
* creates a request, and constructs an LdapResult entity from the entry if
* creates a request, and constructs an LdapResult entity from the entry if
* found. Returns an empty LdapResult object if no results were found or if
* found. Returns an empty LdapResult object if no results were found or if
* there was a conneciton error.
* there was a connection error.
*
*
* @param searchFilter The search filter used in the search
* @param searchFilter The search filter used in the search
* @return
* @return the LdapResult or null
*/
*/
private LdapResult searchLdap(Filter searchFilter) {
private LdapResult searchLdap(Filter searchFilter) {
try (LDAPConnection connection = new LDAPConnection(config.host(), config.port())) {
 
// Enable SSL
 
SSLUtil sslUtil = new SSLUtil();
 
LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
 
connectionOptions.setSSLSocketVerifier(new HostNameSSLSocketVerifier(true));
 
 
try (LDAPConnection connection = new LDAPConnection(sslUtil.createSSLSocketFactory(), connectionOptions,
 
config.host(), config.port())) {
LOGGER.debug("Successfully connected to Eclipse LDAP Server");
LOGGER.debug("Successfully connected to Eclipse LDAP Server");
// Create a search request with base dn, scope, and filter
// Create a search request with base dn, scope, and filter
@@ -90,7 +126,7 @@ public class DefaultLDAPService implements LDAPService {
@@ -90,7 +126,7 @@ public class DefaultLDAPService implements LDAPService {
.setGithubId(isolateGhHandle(entry.getAttributeValue(EMPLOYEE_TYPE)))
.setGithubId(isolateGhHandle(entry.getAttributeValue(EMPLOYEE_TYPE)))
.build();
.build();
} catch (LDAPException e) {
} catch (LDAPException | GeneralSecurityException e) {
LOGGER.error("Error performing user search on LDAP server", e);
LOGGER.error("Error performing user search on LDAP server", e);
return null;
return null;
}
}
Loading