Skip to content
Snippets Groups Projects
Commit 7869cf40 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Merge branch 'zacharysabourin/main/23' into 'main'

feat: Implement LDAP search for mail and GH fields

Closes #23

See merge request !9
parents 01cea45a 6597061e
No related branches found
No related tags found
1 merge request!9feat: Implement LDAP search for mail and GH fields
Pipeline #15931 passed
Showing
with 401 additions and 165 deletions
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipsefoundation</groupId>
<artifactId>eclipsefdn-profile-api</artifactId>
......@@ -51,7 +53,8 @@
<groupId>org.eclipsefoundation</groupId>
<artifactId>quarkus-core</artifactId>
<version>${eclipse-api-version}</version>
<!-- Can be removed once dependency is removed from base package https://stackoverflow.com/questions/67510802/logging-in-quarkus-works-in-dev-mode-but-doesnt-output-in-jvm-docker-image -->
<!-- Can be removed once dependency is removed from base package
https://stackoverflow.com/questions/67510802/logging-in-quarkus-works-in-dev-mode-but-doesnt-output-in-jvm-docker-image -->
<exclusions>
<exclusion>
<groupId>org.jboss.logmanager</groupId>
......@@ -74,6 +77,14 @@
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.unboundid/unboundid-ldapsdk -->
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>6.0.7</version>
</dependency>
<!-- Annotation preprocessors - reduce all of the boiler plate -->
<dependency>
<groupId>com.google.auto.value</groupId>
......@@ -116,7 +127,7 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
......@@ -140,7 +151,8 @@
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.value</groupId>
<groupId>
com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${auto-value.version}</version>
</path>
......@@ -151,10 +163,12 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<skipTests>false</skipTests>
<skipTests>
false</skipTests>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.home>
${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
......@@ -181,8 +195,10 @@
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>
org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
......@@ -192,7 +208,8 @@
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.package.type>
native</quarkus.package.type>
</properties>
</profile>
</profiles>
......
......@@ -13,7 +13,6 @@ package org.eclipsefoundation.profile.api;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
......@@ -31,28 +30,12 @@ import org.eclipsefoundation.profile.api.models.AccountsProfileData;
public interface DrupalProfileAPI {
/**
* Gets user profile data via EF username. Unauthorized connections won't expose
* the email.
* Gets user profile data via EF username.
*
* @param authHeader The bearer token.
* @param username The EF username.
* @return An AccountsProfileData entity.
*/
@GET
@Path("/account/profile/{username}")
AccountsProfileData getProfileByUsername(@HeaderParam("Authorization") String authHeader,
@PathParam("username") String username);
/**
* Gets user profile data via GH handle. Unauthorized connections won't expose
* the email.
*
* @param authHeader The bearer token.
* @param handle The GH handle.
* @return An AccountsProfileData entity.
*/
@GET
@Path("/github/profile/{handle}")
AccountsProfileData getProfileByGHHandle(@HeaderParam("Authorization") String authHeader,
@PathParam("handle") String handle);
AccountsProfileData getProfileByUsername(@PathParam("username") String username);
}
......@@ -36,11 +36,6 @@ public abstract class AccountsProfileData {
public abstract Map<String, PublisherAgreement> getPublisherAgreements();
@Nullable
public abstract String getMail();
public abstract String getGithubHandle();
public abstract String getTwitterHandle();
public abstract String getOrg();
......@@ -98,10 +93,6 @@ public abstract class AccountsProfileData {
public abstract Builder setPublisherAgreements(Map<String, PublisherAgreement> agreements);
public abstract Builder setMail(@Nullable String mail);
public abstract Builder setGithubHandle(String handle);
public abstract Builder setTwitterHandle(String handle);
public abstract Builder setOrg(String org);
......
package org.eclipsefoundation.profile.config;
import io.smallrye.config.ConfigMapping;
@ConfigMapping(prefix = "eclipse.ldap")
public interface LDAPConnectionConfig {
String host();
Integer port();
String baseDn();
}
......@@ -51,6 +51,7 @@ public abstract class EfUser {
public abstract Map<String, PublisherAgreement> getPublisherAgreements();
@Nullable
public abstract String getGithubHandle();
public abstract String getTwitterHandle();
......@@ -118,7 +119,7 @@ public abstract class EfUser {
public abstract Builder setPublisherAgreements(Map<String, PublisherAgreement> agreements);
public abstract Builder setGithubHandle(String handle);
public abstract Builder setGithubHandle(@Nullable String handle);
public abstract Builder setTwitterHandle(String handle);
......
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.profile.models;
import javax.annotation.Nullable;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;
@AutoValue
@JsonDeserialize(builder = AutoValue_LdapResult.Builder.class)
public abstract class LdapResult {
@Nullable
public abstract String getUid();
@Nullable
public abstract String getMail();
@Nullable
public abstract String getGithubId();
public static Builder builder() {
return new AutoValue_LdapResult.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setUid(@Nullable String uid);
public abstract Builder setMail(@Nullable String mail);
public abstract Builder setGithubId(@Nullable String id);
public abstract LdapResult build();
}
}
......@@ -29,9 +29,11 @@ public final class ProfileAPIParameterNames implements UrlParameterNamespace {
public static final UrlParameter QUERY_TYPE = new UrlParameter("query_type");
public static final UrlParameter USERNAME = new UrlParameter("username");
public static final UrlParameter GITHUB = new UrlParameter("github");
public static final UrlParameter MAIL = new UrlParameter("mail");
private static final List<UrlParameter> params = Collections
.unmodifiableList(Arrays.asList(FRIEND_ID, UID, IS_AUTHENTICATED, QUERY_TYPE, USERNAME, GITHUB));
.unmodifiableList(
Arrays.asList(FRIEND_ID, UID, IS_AUTHENTICATED, QUERY_TYPE, USERNAME, GITHUB, MAIL));
@Override
public List<UrlParameter> getParameters() {
......
......@@ -11,6 +11,8 @@
**********************************************************************/
package org.eclipsefoundation.profile.resources;
import java.util.Optional;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
......@@ -41,41 +43,32 @@ public class ProfileResource {
@Path("/account/profile/{username}")
public Response getUserProfileByUsername(@PathParam("username") String username) {
// default token value used for eclipse api authentication
String token = "";
// Get token status to determine if authenticated
DrupalOAuthData tokenStatus = (DrupalOAuthData) request.getAttribute(OAuthFilter.TOKEN_STATUS);
if (tokenStatus != null) {
token = tokenStatus.getAccessToken();
}
EfUser user = profileService.getUserProfileByUsername(username, token);
if (user == null) {
Optional<EfUser> user = profileService.getUserProfileByUsername(username);
if (user.isEmpty()) {
throw new NotFoundException(String.format("User with name '%s' not found", username));
}
return Response.ok(user).build();
return Response.ok(filterEmailByAuth(user.get())).build();
}
@GET
@Path("/github/profile/{handle}")
public Response getUserProfileByHandle(@PathParam("handle") String handle) {
// default token value used for eclipse api authentication
String token = "";
// Get token status to determine if authenticated
DrupalOAuthData tokenStatus = (DrupalOAuthData) request.getAttribute(OAuthFilter.TOKEN_STATUS);
if (tokenStatus != null) {
token = tokenStatus.getAccessToken();
}
EfUser user = profileService.getUserProfileByHandle(handle, token);
if (user == null) {
Optional<EfUser> user = profileService.getUserProfileByHandle(handle);
if (user.isEmpty()) {
throw new NotFoundException(String.format("User with GH handle '%s' not found", handle));
}
return Response.ok(user).build();
return Response.ok(filterEmailByAuth(user.get())).build();
}
private EfUser filterEmailByAuth(EfUser user) {
// Get token status to determine if authenticated. Only exists if token is valid
DrupalOAuthData tokenStatus = (DrupalOAuthData) request.getAttribute(OAuthFilter.TOKEN_STATUS);
if (tokenStatus == null) {
return user.toBuilder().setMail("").build();
}
return user;
}
}
\ No newline at end of file
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.profile.services;
import org.eclipsefoundation.profile.models.LdapResult;
/**
* Defines the service used to perform LDAP searches using specific fields.
*/
public interface LDAPService {
/**
* Performs an LDAP search, mathing via the username. Returns an empty
* LdapResult if no result found.
*
* @param efUsername The desired EF username.
* @return An LdapResult entity.
*/
LdapResult searchLdapByUsername(String efUsername);
/**
* Performs an LDAP search, matching via the the GH id. Returns an empty
* LdapResult if no result found.
*
* @param ghHandle the desired GH id.
* @return An LdapResult entity.
*/
LdapResult searchLdapByGhHandle(String ghHandle);
}
......@@ -11,6 +11,8 @@
**********************************************************************/
package org.eclipsefoundation.profile.services;
import java.util.Optional;
import org.eclipsefoundation.profile.models.EfUser;
/**
......@@ -19,22 +21,20 @@ import org.eclipsefoundation.profile.models.EfUser;
public interface ProfileService {
/**
* Fetches a user profile given the username and Auth token. Aggregates Friend,
* Fetches a user profile given the username. Aggregates Friend,
* ECA and committer status information.
*
* @param username The given user's EF username.
* @param token The bearer token.
* @return An EfUser object or null.
* @return An Optional conatining an EfUser if it exists.
*/
EfUser getUserProfileByUsername(String username, String token);
Optional<EfUser> getUserProfileByUsername(String username);
/**
* Fetches a user profile given the GH handle and Auth token. Aggregates Friend,
* Fetches a user profile given the GH handle. Aggregates Friend,
* ECA and committer status information.
*
* @param handle The given user's GH handle
* @param token The bearer token.
* @return An EfUser object or null.
* @return An Optional containing an EfUser if it exists.
*/
EfUser getUserProfileByHandle(String handle, String token);
Optional<EfUser> getUserProfileByHandle(String handle);
}
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.profile.services.impl;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.eclipsefoundation.profile.config.LDAPConnectionConfig;
import org.eclipsefoundation.profile.models.LdapResult;
import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames;
import org.eclipsefoundation.profile.services.LDAPService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.unboundid.ldap.sdk.DN;
import com.unboundid.ldap.sdk.Filter;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchResult;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.unboundid.ldap.sdk.SearchScope;
@ApplicationScoped
public class DefaultLDAPService implements LDAPService {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLDAPService.class);
private static final String EMPLOYEE_TYPE = "employeeType";
@Inject
LDAPConnectionConfig config;
@Override
public LdapResult searchLdapByUsername(String efUsername) {
return searchLdap(Filter.createEqualityFilter(ProfileAPIParameterNames.UID.getName(), efUsername));
}
@Override
public LdapResult searchLdapByGhHandle(String ghHandle) {
return searchLdap(
Filter.createEqualityFilter(EMPLOYEE_TYPE, "GITHUB:" + ghHandle));
}
/**
* Performs an LDAP search using the desired filter. Establishes a connection,
* 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
* there was a conneciton error.
*
* @param searchFilter The search filter used in the search
* @return
*/
private LdapResult searchLdap(Filter searchFilter) {
try (LDAPConnection connection = new LDAPConnection(config.host(), config.port())) {
LOGGER.debug("Successfully connected to Eclipse LDAP Server");
// Create a search request with base dn, scope, and filter
DN dn = new DN(config.baseDn());
SearchRequest request = new SearchRequest(dn, SearchScope.SUB, searchFilter);
LOGGER.debug("LDAP REQUEST: {}", request);
// Perform search and get entries
SearchResult result = connection.search(request);
List<SearchResultEntry> searchEntries = result.getSearchEntries();
if (searchEntries == null || searchEntries.isEmpty()) {
LOGGER.error("No results found using filter: {}", searchFilter);
return null;
}
// Only using equality filters on uid and employeeType. 1 result expected
SearchResultEntry entry = searchEntries.get(0);
LOGGER.debug("LDAP RESULT: {}", entry);
return LdapResult.builder()
.setUid(entry.getAttributeValue(ProfileAPIParameterNames.UID.getName()))
.setMail(entry.getAttributeValue(ProfileAPIParameterNames.MAIL.getName()))
.setGithubId(isolateGhHandle(entry.getAttributeValue(EMPLOYEE_TYPE)))
.build();
} catch (LDAPException e) {
LOGGER.error("Error performing user search on LDAP server", e);
return null;
}
}
/**
* Strips the "GITHUB:" part of the employeeType attribute, isolating the
* handle.
*
* @param employeeType The employeetype attribute
* @return The isolated GH id.
*/
private String isolateGhHandle(String employeeType) {
return employeeType == null ? employeeType : employeeType.replace("GITHUB:", "");
}
}
......@@ -18,7 +18,6 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.core.service.CachingService;
......@@ -33,9 +32,11 @@ import org.eclipsefoundation.profile.api.models.AccountsProfileData;
import org.eclipsefoundation.profile.config.DocumentLoaderConfig;
import org.eclipsefoundation.profile.dtos.Friends;
import org.eclipsefoundation.profile.models.EfUser;
import org.eclipsefoundation.profile.models.LdapResult;
import org.eclipsefoundation.profile.models.EfUser.Eca;
import org.eclipsefoundation.profile.models.EfUser.FriendsData;
import org.eclipsefoundation.profile.namespace.ProfileAPIParameterNames;
import org.eclipsefoundation.profile.services.LDAPService;
import org.eclipsefoundation.profile.services.ProfileService;
import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
import org.slf4j.Logger;
......@@ -48,6 +49,9 @@ public class DefaultProfileService implements ProfileService {
@Inject
DocumentLoaderConfig docConfig;
@Inject
LDAPService ldapService;
@Inject
@RestClient
DrupalProfileAPI profileAPI;
......@@ -66,88 +70,81 @@ public class DefaultProfileService implements ProfileService {
RequestWrapper wrap;
@Override
public EfUser getUserProfileByUsername(String username, String token) {
public Optional<EfUser> getUserProfileByUsername(String username) {
LOGGER.debug("Fetching profile for user: {}", username);
Optional<AccountsProfileData> profile = cache.get(username,
buildCacheParams(ProfileAPIParameterNames.USERNAME.getName(), token), AccountsProfileData.class,
() -> profileAPI.getProfileByUsername(buildBearerToken(token), username));
LOGGER.debug("Searching LDAP for user: {}", username);
Optional<LdapResult> ldapResult = cache.get(username, new MultivaluedMapImpl<>(), LdapResult.class,
() -> ldapService.searchLdapByUsername(username));
if (profile.isPresent()) {
return buildEfUser(profile.get());
if (ldapResult.isPresent()) {
return Optional.of(buildEfUser(ldapResult.get()));
}
LOGGER.debug("Unable to find user with name: {}", username);
return null;
LOGGER.error("LDAP - no user with name: {}", username);
return Optional.empty();
}
@Override
public EfUser getUserProfileByHandle(String handle, String token) {
public Optional<EfUser> getUserProfileByHandle(String handle) {
LOGGER.info("Fetching profile for GH handle: {}", handle);
Optional<AccountsProfileData> profile = cache.get(handle,
buildCacheParams(ProfileAPIParameterNames.GITHUB.getName(), token), AccountsProfileData.class,
() -> profileAPI.getProfileByGHHandle(buildBearerToken(token), handle));
LOGGER.debug("Searching LDAP for GH handle: {}", handle);
Optional<LdapResult> ldapResult = cache.get(handle, new MultivaluedMapImpl<>(), LdapResult.class,
() -> ldapService.searchLdapByGhHandle(handle));
if (profile.isPresent()) {
return buildEfUser(profile.get());
if (ldapResult.isPresent()) {
return Optional.of(buildEfUser(ldapResult.get()));
}
LOGGER.debug("Unable to find user GH handle: {}", handle);
return null;
LOGGER.debug("LDAP - no user with GH id: {}", handle);
return Optional.empty();
}
/**
* Builds a set of cache key params using the token value and the query type.
* Used to avoid collision in the case where a username and handle are the same
* value.
* Builds an EFUser entity using the given LDAP information. Fetches from the
* profile API for the remaining profile info.
*
* @param querytype the given query type.
* @param token The given token value.
* @return A populated map containing the unique cache params.
* @param ldapResult The fetched LdapResult entity.
* @return A populated EfUser entity.
*/
private MultivaluedMap<String, String> buildCacheParams(String querytype, String token) {
MultivaluedMap<String, String> cacheParams = new MultivaluedMapImpl<>();
cacheParams.add(ProfileAPIParameterNames.QUERY_TYPE.getName(), querytype);
cacheParams.add(ProfileAPIParameterNames.IS_AUTHENTICATED.getName(),
StringUtils.isBlank(token) ? "false" : "true");
private EfUser buildEfUser(LdapResult ldapResult) {
return cacheParams;
}
LOGGER.debug("Fetching profile for user: {}", ldapResult.getUid());
Optional<AccountsProfileData> result = cache.get(ldapResult.getUid(), new MultivaluedMapImpl<>(),
AccountsProfileData.class, () -> profileAPI.getProfileByUsername(ldapResult.getUid()));
if (result.isEmpty()) {
LOGGER.error("Error fetching profile data for user: {}", ldapResult.getUid());
return null;
}
AccountsProfileData profileData = result.get();
/**
* Builds an EFUser entity using the given profile information.
*
* @param profile The fetched AccountsProfileData entity.
* @return A populated EfUser entity.
*/
private EfUser buildEfUser(AccountsProfileData profile) {
return EfUser.builder()
.setUid(profile.getUid())
.setName(profile.getName())
.setPicture(profile.getPicture())
.setMail(profile.getMail())
.setFirstName(profile.getFirstName())
.setLastName(profile.getLastName())
.setGithubHandle(profile.getGithubHandle())
.setTwitterHandle(profile.getTwitterHandle())
.setPublisherAgreements(profile.getPublisherAgreements())
.setOrg(profile.getOrg())
.setOrgId(profile.getOrgId())
.setJobTitle(profile.getJobTitle())
.setWebsite(profile.getWebsite())
.setCountry(profile.getCountry())
.setBio(profile.getBio())
.setInterests(profile.getInterests())
.setWorkingGroupsInterests(profile.getWorkingGroupsInterests())
.setForumsUrl(profile.getForumsUrl())
.setProjectsUrl(profile.getProjectsUrl())
.setGerritUrl(profile.getGerritUrl())
.setMailinglistUrl(profile.getMailinglistUrl())
.setMpcFavoritesUrl(profile.getMpcFavoritesUrl())
.setFriends(getFriends(profile.getName()))
.setEca(getEcaStatus(profile.getName()))
.setIsCommitter(getCommitterStatus(profile.getName()))
.setUid(profileData.getUid())
.setName(ldapResult.getUid())
.setPicture(profileData.getPicture())
.setMail(ldapResult.getMail())
.setFirstName(profileData.getFirstName())
.setLastName(profileData.getLastName())
.setGithubHandle(ldapResult.getGithubId())
.setTwitterHandle(profileData.getTwitterHandle())
.setPublisherAgreements(profileData.getPublisherAgreements())
.setOrg(profileData.getOrg())
.setOrgId(profileData.getOrgId())
.setJobTitle(profileData.getJobTitle())
.setWebsite(profileData.getWebsite())
.setCountry(profileData.getCountry())
.setBio(profileData.getBio())
.setInterests(profileData.getInterests())
.setWorkingGroupsInterests(profileData.getWorkingGroupsInterests())
.setForumsUrl(profileData.getForumsUrl())
.setProjectsUrl(profileData.getProjectsUrl())
.setGerritUrl(profileData.getGerritUrl())
.setMailinglistUrl(profileData.getMailinglistUrl())
.setMpcFavoritesUrl(profileData.getMpcFavoritesUrl())
.setFriends(getFriends(profileData.getName()))
.setEca(getEcaStatus(profileData.getName()))
.setIsCommitter(getCommitterStatus(profileData.getName()))
.build();
}
......@@ -220,8 +217,4 @@ public class DefaultProfileService implements ProfileService {
|| (d.getDocumentID().equalsIgnoreCase(docConfig.ecaId())
&& d.getVersion() == docConfig.ecaVersion()));
}
private String buildBearerToken(String token) {
return "Bearer " + token;
}
}
......@@ -4,6 +4,8 @@ quarkus.oidc.enabled=false
quarkus.log.level=INFO
quarkus.hibernate-orm.physical-naming-strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
cache.ttl.write.seconds=300
fdndb-api/mp-rest/url=http://foundationdb:8095
%dev.fdndb-api/mp-rest/url=http://localhost:10109
......
......@@ -40,7 +40,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
AccountsProfileData.builder()
.setUid(666)
.setName("username")
.setMail("email@website.com")
.setFirstName("user")
.setLastName("name")
.setTwitterHandle("handle")
......@@ -54,7 +53,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
.setBio("Likes do do things")
.setInterests(Arrays.asList("item1", "item2"))
.setPicture("pic URL")
.setGithubHandle("userhandle")
.setOrgId("Id")
.setWorkingGroupsInterests(Arrays.asList("item1"))
.setForumsUrl("Url")
......@@ -67,7 +65,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
AccountsProfileData.builder()
.setUid(42)
.setName("firstlast")
.setMail("email@website.com")
.setFirstName("first")
.setLastName("last")
.setTwitterHandle("twit")
......@@ -81,7 +78,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
.setBio("Likes do do things")
.setInterests(Arrays.asList("item1", "item2"))
.setPicture("pic URL")
.setGithubHandle("firstlast")
.setOrgId("Id")
.setWorkingGroupsInterests(Arrays.asList("item1"))
.setForumsUrl("Url")
......@@ -94,7 +90,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
AccountsProfileData.builder()
.setUid(77)
.setName("fakeperson")
.setMail("email@website.com")
.setFirstName("fake")
.setLastName("person")
.setTwitterHandle("tweets")
......@@ -108,7 +103,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
.setBio("Likes do do things")
.setInterests(Arrays.asList("item1", "item2"))
.setPicture("pic URL")
.setGithubHandle("handle")
.setOrgId("Id")
.setWorkingGroupsInterests(Arrays.asList("item1"))
.setForumsUrl("Url")
......@@ -122,7 +116,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
AccountsProfileData.builder()
.setUid(88)
.setName("barshallblathers")
.setMail("email@website.com")
.setFirstName("barshall")
.setLastName("blathers")
.setTwitterHandle("twitter@handle")
......@@ -136,7 +129,6 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
.setBio("Likes do do things")
.setInterests(Arrays.asList("item1", "item2"))
.setPicture("pic URL")
.setGithubHandle("handle")
.setOrgId("Id")
.setWorkingGroupsInterests(Arrays.asList("item1"))
.setForumsUrl("Url")
......@@ -149,26 +141,10 @@ public class MockDrupalProfileAPI implements DrupalProfileAPI {
}
@Override
public AccountsProfileData getProfileByUsername(String authHeader, String username) {
public AccountsProfileData getProfileByUsername(String username) {
AccountsProfileData result = internal.stream().filter(a -> a.getName().equalsIgnoreCase(username)).findFirst()
.orElse(null);
if (result != null && authHeader.equalsIgnoreCase("Bearer ")) {
result = result.toBuilder().setMail("").build();
}
return result;
}
@Override
public AccountsProfileData getProfileByGHHandle(String authHeader, String handle) {
AccountsProfileData result = internal.stream().filter(a -> a.getGithubHandle().equalsIgnoreCase(handle)).findFirst()
.orElse(null);
if (result != null && authHeader.equalsIgnoreCase("Bearer ")) {
result = result.toBuilder().setMail("").build();
}
return result;
}
}
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.profile.test.services;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import org.eclipsefoundation.profile.models.LdapResult;
import org.eclipsefoundation.profile.services.LDAPService;
import io.quarkus.test.Mock;
@Mock
@ApplicationScoped
public class MockLDAPService implements LDAPService {
private List<LdapResult> internal;
public MockLDAPService() {
internal = new ArrayList<>();
internal.addAll(Arrays.asList(
LdapResult.builder()
.setUid("username")
.setMail("email@website.com")
.setGithubId("userhandle")
.build(),
LdapResult.builder()
.setUid("firstlast")
.setMail("email@website.com")
.setGithubId("firstlast")
.build(),
LdapResult.builder()
.setUid("fakeperson")
.setMail("email@website.com")
.setGithubId("handle")
.build(),
LdapResult.builder()
.setUid("barshallblathers")
.setMail("email@website.com")
.setGithubId("handle")
.build()));
}
@Override
public LdapResult searchLdapByUsername(String efUsername) {
return internal.stream().filter(r -> r.getUid().equalsIgnoreCase(efUsername)).findFirst().orElse(null);
}
@Override
public LdapResult searchLdapByGhHandle(String ghHandle) {
return internal.stream().filter(r -> r.getGithubId().equalsIgnoreCase(ghHandle)).findFirst().orElse(null);
}
}
......@@ -23,4 +23,8 @@ eclipse.profile.documents.mcca-id=mccaId
eclipse.profile.oauth-filter.enabled=true
eclipse.profile.clients=test-id
eclipse.profile.scopes=read,write,admin
\ No newline at end of file
eclipse.profile.scopes=read,write,admin
eclipse.ldap.host=sample
eclipse.ldap.port=0000
eclipse.ldap.base-dn=dc=sample
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment