diff --git a/pom.xml b/pom.xml index 1cec70ce33faaf91925f0eb260796eb25b0db237..b561c8aec024ace01ffca5f62ed0c4b3d68e9748 100644 --- a/pom.xml +++ b/pom.xml @@ -9,20 +9,20 @@ <version>1.0.0-SNAPSHOT</version> <properties> - <compiler-plugin.version>3.11.0</compiler-plugin.version> + <compiler-plugin.version>3.13.0</compiler-plugin.version> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id> - <quarkus.platform.version>3.8.3</quarkus.platform.version> - <surefire-plugin.version>3.1.2</surefire-plugin.version> + <quarkus.platform.version>3.15.3</quarkus.platform.version> + <surefire-plugin.version>3.3.1</surefire-plugin.version> <auto-value.version>1.10.4</auto-value.version> <hibernate.version>5.5.6.Final</hibernate.version> - <eclipse-api-version>1.0.0</eclipse-api-version> + <eclipse-api-version>1.2.0</eclipse-api-version> <org.mapstruct.version>1.5.5.Final</org.mapstruct.version> - <fdndb-api-version>1.0.6</fdndb-api-version> + <fdndb-api-version>1.1.2</fdndb-api-version> <sonar.sources>src/main</sonar.sources> <sonar.tests>src/test</sonar.tests> <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> diff --git a/src/main/java/org/eclipsefoundation/openvsx/api/PeopleAPI.java b/src/main/java/org/eclipsefoundation/openvsx/api/PeopleAPI.java index a505cc9668c0bce8bc7b958a7ccf41a19b39f479..5bb58d87942841e179371bfc1303f4502feaccb8 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/api/PeopleAPI.java +++ b/src/main/java/org/eclipsefoundation/openvsx/api/PeopleAPI.java @@ -14,8 +14,8 @@ package org.eclipsefoundation.openvsx.api; import java.util.List; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; -import org.eclipsefoundation.foundationdb.client.model.PeopleData; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; import org.eclipsefoundation.openvsx.api.models.ModLogHeaders; import io.quarkus.oidc.client.filter.OidcClientFilter; diff --git a/src/main/java/org/eclipsefoundation/openvsx/api/SysAPI.java b/src/main/java/org/eclipsefoundation/openvsx/api/SysAPI.java index 3565cbb32c4cc193a7a5e443515700c9e7c15869..c5fc23c484d2319e166fcaaa71588ee42f0f0918 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/api/SysAPI.java +++ b/src/main/java/org/eclipsefoundation/openvsx/api/SysAPI.java @@ -14,7 +14,7 @@ package org.eclipsefoundation.openvsx.api; import java.util.List; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; -import org.eclipsefoundation.foundationdb.client.model.SysModLogData; +import org.eclipsefoundation.foundationdb.client.runtime.model.system.SysModLogData; import io.quarkus.oidc.client.filter.OidcClientFilter; import jakarta.annotation.security.RolesAllowed; diff --git a/src/main/java/org/eclipsefoundation/openvsx/models/RequestUserProfileWrapper.java b/src/main/java/org/eclipsefoundation/openvsx/models/RequestUserProfileWrapper.java deleted file mode 100644 index 9bdce63e47964c574c9fc2d072e06018b47c6ba9..0000000000000000000000000000000000000000 --- a/src/main/java/org/eclipsefoundation/openvsx/models/RequestUserProfileWrapper.java +++ /dev/null @@ -1,46 +0,0 @@ -/********************************************************************* -* 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.openvsx.models; - -import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.utils.exception.FinalForbiddenException; - -import jakarta.enterprise.context.RequestScoped; -import jakarta.servlet.http.HttpServletRequest; - -/** - * A RequestScoped bean that wraps the EfUser value set in the request chain. This bean is used to access profile information about the user - * associated with the current token. To set this data, a user search must be performed using the 'uid' from the current oauth token info. - * To access this data, a EfUser object must be set as the 'current_profile' property in the HttpServletRequest bound to the current request - * chain. - */ -@RequestScoped -public class RequestUserProfileWrapper { - - public static final String CURRENT_PROFILE = "current_profile"; - - private final EfUser currentUserProfile; - - public RequestUserProfileWrapper(HttpServletRequest request) { - this.currentUserProfile = (EfUser) request.getAttribute(CURRENT_PROFILE); - } - - /* - * Retrieves the EfUser object bound to the current request - */ - public EfUser getCurrentUserProfile() { - if (currentUserProfile == null) { - throw new FinalForbiddenException("No profile data in request chain"); - } - return this.currentUserProfile; - } -} diff --git a/src/main/java/org/eclipsefoundation/openvsx/request/OAuthFilter.java b/src/main/java/org/eclipsefoundation/openvsx/request/OAuthFilter.java deleted file mode 100644 index 325d3d6611867e148e3d5f22edc2a38e2e1349ed..0000000000000000000000000000000000000000 --- a/src/main/java/org/eclipsefoundation/openvsx/request/OAuthFilter.java +++ /dev/null @@ -1,75 +0,0 @@ -/********************************************************************* -* 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.openvsx.request; - -import java.io.IOException; -import java.util.Optional; - -import org.eclipsefoundation.efservices.api.models.DrupalOAuthData; -import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.efservices.api.models.UserSearchParams; -import org.eclipsefoundation.efservices.helpers.DrupalAuthHelper; -import org.eclipsefoundation.efservices.services.DrupalOAuthService; -import org.eclipsefoundation.efservices.services.ProfileService; -import org.eclipsefoundation.http.config.OAuth2SecurityConfig; -import org.eclipsefoundation.openvsx.models.RequestUserProfileWrapper; -import org.eclipsefoundation.utils.exception.FinalForbiddenException; -import org.jboss.resteasy.util.HttpHeaderNames; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import jakarta.enterprise.inject.Instance; -import jakarta.inject.Inject; -import jakarta.ws.rs.container.ContainerRequestContext; -import jakarta.ws.rs.container.ContainerRequestFilter; -import jakarta.ws.rs.ext.Provider; - -@Provider -public class OAuthFilter implements ContainerRequestFilter { - private static final Logger LOGGER = LoggerFactory.getLogger(OAuthFilter.class); - - @Inject - Instance<OAuth2SecurityConfig> config; - - @Inject - DrupalOAuthService oauthService; - @Inject - ProfileService profileService; - - @Override - public void filter(ContainerRequestContext requestContext) throws IOException { - if (Boolean.TRUE.equals(config.get().filter().enabled())) { - - // Strip token from Auth header - String token = DrupalAuthHelper.stripBearerToken(requestContext.getHeaderString(HttpHeaderNames.AUTHORIZATION)); - - DrupalOAuthData tokenStatus = oauthService - .validateTokenStatus(token, config.get().filter().validScopes(), config.get().filter().validClientIds()); - - // The incoming token must have a user associated with it. - if (tokenStatus == null || tokenStatus.getUserId() == null) { - throw new FinalForbiddenException("Invalid user credentials"); - } - - // There is no openid scope incoming. User search needed for user data - Optional<EfUser> currentUserProfile = profileService - .performUserSearch(UserSearchParams.builder().setUid(tokenStatus.getUserId()).build()); - if (currentUserProfile.isEmpty()) { - LOGGER.warn("Cannot find profile for user {}", tokenStatus.getUserId()); - throw new FinalForbiddenException(String.format("Cannot find profile for user %s", tokenStatus.getUserId())); - } - - // Set profile data into context - requestContext.setProperty(RequestUserProfileWrapper.CURRENT_PROFILE, currentUserProfile.get()); - } - } -} diff --git a/src/main/java/org/eclipsefoundation/openvsx/resources/ProfileResource.java b/src/main/java/org/eclipsefoundation/openvsx/resources/ProfileResource.java index 8f56a6424604248495f82e4523b3b760ed28b1ba..f0c754f77bc486e3c3b7a07d039f6ac1af77c70f 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/resources/ProfileResource.java +++ b/src/main/java/org/eclipsefoundation/openvsx/resources/ProfileResource.java @@ -13,7 +13,7 @@ package org.eclipsefoundation.openvsx.resources; import java.util.Arrays; -import org.eclipsefoundation.openvsx.models.RequestUserProfileWrapper; +import org.eclipsefoundation.efservices.models.AuthenticatedRequestWrapper; import jakarta.inject.Inject; import jakarta.ws.rs.GET; @@ -24,11 +24,11 @@ import jakarta.ws.rs.core.Response; public class ProfileResource { @Inject - RequestUserProfileWrapper userProfile; + AuthenticatedRequestWrapper userProfile; @GET public Response getProfileInfo() { // Returns the public profile data tied to the current user - return Response.ok(Arrays.asList(userProfile.getCurrentUserProfile())).build(); + return Response.ok(Arrays.asList(userProfile.getUserPublicProfileData())).build(); } } diff --git a/src/main/java/org/eclipsefoundation/openvsx/resources/PublisherAgreementResource.java b/src/main/java/org/eclipsefoundation/openvsx/resources/PublisherAgreementResource.java index 8cf7d10cc70339977f4ee38252b6e716fec63f87..c346f501829704bf5d2b1aa75983eaa6e2e2170e 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/resources/PublisherAgreementResource.java +++ b/src/main/java/org/eclipsefoundation/openvsx/resources/PublisherAgreementResource.java @@ -15,12 +15,12 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; +import org.eclipsefoundation.efservices.models.AuthenticatedRequestWrapper; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; import org.eclipsefoundation.http.model.WebError; import org.eclipsefoundation.openvsx.config.PublisherAgreementConfig; import org.eclipsefoundation.openvsx.models.AgreementSigningRequest; import org.eclipsefoundation.openvsx.models.PublisherAgreementData; -import org.eclipsefoundation.openvsx.models.RequestUserProfileWrapper; import org.eclipsefoundation.openvsx.services.FoundationOperationService; import org.eclipsefoundation.openvsx.services.PublisherAgreementService; import org.eclipsefoundation.utils.exception.FinalForbiddenException; @@ -46,7 +46,7 @@ public class PublisherAgreementResource { PublisherAgreementConfig config; @Inject - RequestUserProfileWrapper userProfile; + AuthenticatedRequestWrapper userProfile; @Inject PublisherAgreementService agreementService; @@ -58,7 +58,7 @@ public class PublisherAgreementResource { public Response getAgreement() { // Uses currently logged in user. Only an onwer can fetch their agreement - String username = userProfile.getCurrentUserProfile().getName(); + String username = userProfile.getUserPublicProfileData().name(); // Fetch agreement for user Optional<PublisherAgreementData> result = agreementService.getPublisherAgreementByUsername(username); @@ -73,13 +73,13 @@ public class PublisherAgreementResource { public Response createAgreement(AgreementSigningRequest body) { // Uses currently logged in user. Only an owner can create their agreement - EfUser user = userProfile.getCurrentUserProfile(); + EfUser user = userProfile.getUserPublicProfileData(); // Check if body format is correct validateSigningRequest(body); // Conflict if already signed agreement that isn't expired - if (agreementService.getPublisherAgreementByUsername(user.getName()).isPresent()) { + if (agreementService.getPublisherAgreementByUsername(user.name()).isPresent()) { return new WebError(Status.CONFLICT, "The request could not be completed due to a conflict with the current state of the resource.").asResponse(); } @@ -124,7 +124,7 @@ public class PublisherAgreementResource { throw new NotFoundException(String.format(NOT_FOUND_MSG_FORMAT, username)); } - String currentUser = userProfile.getCurrentUserProfile().getName(); + String currentUser = userProfile.getUserPublicProfileData().name(); Optional<PeopleDocumentData> updateResult = agreementService.revokePublisherAgreement(fetchResult.get(), currentUser); if (updateResult.isEmpty()) { @@ -150,7 +150,7 @@ public class PublisherAgreementResource { } // Ensure GH handle from current user same as in request body. - if (!StringUtils.equalsIgnoreCase(userProfile.getCurrentUserProfile().getGithubHandle(), request.githubHandle())) { + if (!StringUtils.equalsIgnoreCase(userProfile.getUserPublicProfileData().githubHandle(), request.githubHandle())) { throw new BadRequestException("The github_handle does not match our records."); } } @@ -164,8 +164,9 @@ public class PublisherAgreementResource { */ void checkIfAdminOrSelf(String urlUsername) { // Reject request if current user is not in URL and they aren't an admin - if (!urlUsername.equalsIgnoreCase(userProfile.getCurrentUserProfile().getName()) - && config.adminUsers().stream().noneMatch(email -> email.equalsIgnoreCase(userProfile.getCurrentUserProfile().getMail()))) { + EfUser user = userProfile.getUserPrivateProfileData(); + if (!urlUsername.equalsIgnoreCase(user.name()) + && config.adminUsers().stream().noneMatch(email -> email.equalsIgnoreCase(user.mail()))) { throw new FinalForbiddenException(String.format("Access denied to resources for: %s", urlUsername)); } } diff --git a/src/main/java/org/eclipsefoundation/openvsx/services/FoundationOperationService.java b/src/main/java/org/eclipsefoundation/openvsx/services/FoundationOperationService.java index a897823b852ec6ab8d3a123a1f6c6ae0cd0cb3ab..4ac5485b4ef5bd552850433a47769545b66312c2 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/services/FoundationOperationService.java +++ b/src/main/java/org/eclipsefoundation/openvsx/services/FoundationOperationService.java @@ -14,8 +14,8 @@ package org.eclipsefoundation.openvsx.services; import java.util.Optional; import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; -import org.eclipsefoundation.foundationdb.client.model.SysModLogData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.system.SysModLogData; import org.eclipsefoundation.openvsx.api.models.ModLogHeaders; /** diff --git a/src/main/java/org/eclipsefoundation/openvsx/services/PublisherAgreementService.java b/src/main/java/org/eclipsefoundation/openvsx/services/PublisherAgreementService.java index cd61f7e067afb39e0cb5cc5f80516e3141b435bd..74f1597c8ec2322b603b01a910c15abe597d4b9e 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/services/PublisherAgreementService.java +++ b/src/main/java/org/eclipsefoundation/openvsx/services/PublisherAgreementService.java @@ -14,7 +14,7 @@ package org.eclipsefoundation.openvsx.services; import java.util.Optional; import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; import org.eclipsefoundation.openvsx.models.PublisherAgreementData; /** diff --git a/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultFoundationOperationService.java b/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultFoundationOperationService.java index 03e403f1a86ce2400b09fa64b85cf7d3c086883d..e2ffe823e8939b707ea5177af3813ba2602b4a1a 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultFoundationOperationService.java +++ b/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultFoundationOperationService.java @@ -18,9 +18,11 @@ import java.util.Optional; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.caching.service.CachingService; import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.foundationdb.client.model.PeopleData; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; -import org.eclipsefoundation.foundationdb.client.model.SysModLogData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDataBuilder; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.system.SysModLogData; +import org.eclipsefoundation.foundationdb.client.runtime.model.system.SysModLogDataBuilder; import org.eclipsefoundation.http.helper.IPParser; import org.eclipsefoundation.openvsx.api.PeopleAPI; import org.eclipsefoundation.openvsx.api.SysAPI; @@ -28,12 +30,12 @@ import org.eclipsefoundation.openvsx.api.models.ModLogHeaders; import org.eclipsefoundation.openvsx.config.PublisherAgreementConfig; import org.eclipsefoundation.openvsx.namespace.OpenvsxModLogActions; import org.eclipsefoundation.openvsx.services.FoundationOperationService; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.Response.Status; @ApplicationScoped @@ -65,7 +67,7 @@ public class DefaultFoundationOperationService implements FoundationOperationSer } // Sort by date. Most recent first - return results.stream().sorted((pDoc1, pDoc2) -> pDoc2.getEffectiveDate().compareTo(pDoc1.getEffectiveDate())).findFirst(); + return results.stream().sorted((pDoc1, pDoc2) -> pDoc2.effectiveDate().compareTo(pDoc1.effectiveDate())).findFirst(); } catch (Exception e) { LOGGER.error("Error while fetching publisher agreement for user: {}", username, e); @@ -75,11 +77,11 @@ public class DefaultFoundationOperationService implements FoundationOperationSer @Override public Optional<PeopleDocumentData> persistDocumentWithModLog(ModLogHeaders headers, PeopleDocumentData toInsert) { - LOGGER.debug("Persisting publisher agreement for user: {}", toInsert.getPersonID()); + LOGGER.debug("Persisting publisher agreement for user: {}", toInsert.personID()); - List<PeopleDocumentData> results = peopleAPI.persistPeopleDocument(headers, toInsert.getPersonID(), toInsert); + List<PeopleDocumentData> results = peopleAPI.persistPeopleDocument(headers, toInsert.personID(), toInsert); if (results == null || results.isEmpty()) { - LOGGER.error("Unable to create agreement for user with name: {}", toInsert.getPersonID()); + LOGGER.error("Unable to create agreement for user with name: {}", toInsert.personID()); return Optional.empty(); } @@ -90,14 +92,14 @@ public class DefaultFoundationOperationService implements FoundationOperationSer public Optional<SysModLogData> insertErrorSysModLog(String pk1, String personId) { try { // All error ModLogs use client IP and log the failed action taken - SysModLogData src = SysModLogData + SysModLogData src = SysModLogDataBuilder .builder() - .setLogTable("openvsx/publisher_agreement") - .setPK1(pk1) - .setPK2(ipParser.getBestMatchingIP()) - .setLogAction(OpenvsxModLogActions.SQL_ERROR) - .setPersonId(personId) - .setModDateTime(ZonedDateTime.now()) + .logTable("openvsx/publisher_agreement") + .pk1(pk1) + .pk2(ipParser.getBestMatchingIP()) + .logAction(OpenvsxModLogActions.SQL_ERROR) + .personId(personId) + .modDateTime(ZonedDateTime.now()) .build(); LOGGER.debug("Inserting error ModLog: {}", src); @@ -119,31 +121,31 @@ public class DefaultFoundationOperationService implements FoundationOperationSer public boolean createDbUserIfNotFound(EfUser user) { try { // No need to create new user if they already exist in fdndb - Optional<PeopleData> fetchResult = fetchFoundationUser(user.getName()); + Optional<PeopleData> fetchResult = fetchFoundationUser(user.name()); if (fetchResult.isPresent()) { return true; } - LOGGER.debug("User {} not found in fdndb. Creating new entry", user.getName()); + LOGGER.debug("User {} not found in fdndb. Creating new entry", user.name()); - PeopleData person = PeopleData + PeopleData person = PeopleDataBuilder .builder() - .setPersonID(user.getName()) - .setFname(user.getFirstName()) - .setLname(user.getLastName()) - .setType("XX") - .setMember(false) - .setEmail(user.getMail()) - .setUnixAcctCreated(false) - .setIssuesPending(false) + .personID(user.name()) + .fname(user.firstName()) + .lname(user.lastName()) + .type("XX") + .member(false) + .email(user.mail()) + .unixAcctCreated(false) + .issuesPending(false) .build(); // Insert new person record return peopleAPI.persistPersonEntity(person).getStatus() == Status.OK.getStatusCode(); } catch (Exception e) { - LOGGER.error("Error inserting user: {}", user.getName(), e); - insertErrorSysModLog("createFoundationUser", user.getName()); + LOGGER.error("Error inserting user: {}", user.name(), e); + insertErrorSysModLog("createFoundationUser", user.name()); return false; } } @@ -157,7 +159,7 @@ public class DefaultFoundationOperationService implements FoundationOperationSer private Optional<PeopleData> fetchFoundationUser(String personId) { try { LOGGER.debug("Fetching user: {}", personId); - return cache.get(personId, new MultivaluedMapImpl<>(), PeopleData.class, () -> peopleAPI.getPerson(personId)).getData(); + return cache.get(personId, new MultivaluedHashMap<>(), PeopleData.class, () -> peopleAPI.getPerson(personId)).data(); } catch (Exception e) { LOGGER.error("Error searching for user: {}", personId, e); insertErrorSysModLog("fetchFoundationUser", personId); diff --git a/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultPublisherAgreementService.java b/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultPublisherAgreementService.java index ff64538aca93707b4ff1850b0f406bb6e5538017..1bd3b5a01794a3b840273305353405582d2e33cc 100644 --- a/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultPublisherAgreementService.java +++ b/src/main/java/org/eclipsefoundation/openvsx/services/impl/DefaultPublisherAgreementService.java @@ -21,7 +21,8 @@ import java.util.Optional; import org.apache.commons.lang3.ArrayUtils; import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentDataBuilder; import org.eclipsefoundation.openvsx.api.models.ModLogHeaders; import org.eclipsefoundation.openvsx.config.PublisherAgreementConfig; import org.eclipsefoundation.openvsx.models.DocumentBody; @@ -61,26 +62,26 @@ public class DefaultPublisherAgreementService implements PublisherAgreementServi @Override public Optional<PublisherAgreementData> createPublisherAgreement(EfUser user) { try { - LOGGER.debug("Creating publisher agreement for user: {}", user.getName()); + LOGGER.debug("Creating publisher agreement for user: {}", user.name()); - ModLogHeaders headers = new ModLogHeaders(user.getName(), user.getName(), OpenvsxModLogActions.AGREEMENT_SIGNED); + ModLogHeaders headers = new ModLogHeaders(user.name(), user.name(), OpenvsxModLogActions.AGREEMENT_SIGNED); - LOGGER.debug("Encoding publisher agreement document for user: {}", user.getName()); + LOGGER.debug("Encoding publisher agreement document for user: {}", user.name()); // Create document from user data + request info. Then encode it String jsonDoc = objectMapper - .writeValueAsString(new DocumentBody(String.valueOf(config.docVersion()), user.getGithubHandle(), user.getName(), - user.getFirstName(), user.getLastName(), user.getMail())); + .writeValueAsString(new DocumentBody(String.valueOf(config.docVersion()), user.githubHandle(), user.name(), + user.firstName(), user.lastName(), user.mail())); Optional<PeopleDocumentData> creationResult = foundationService - .persistDocumentWithModLog(headers, createDocumentSigningRequest(jsonDoc, user.getName())); + .persistDocumentWithModLog(headers, createDocumentSigningRequest(jsonDoc, user.name())); // Convert to PublisherAgreementData if persistence successful return creationResult.isEmpty() ? Optional.empty() : Optional.of(buildPublisherAgreement(creationResult.get(), false)); } catch (Exception e) { LOGGER.error("Error while creating publisher agreement", e); - foundationService.insertErrorSysModLog("_openvsx_publisher_agreement_create", user.getName()); + foundationService.insertErrorSysModLog("_openvsx_publisher_agreement_create", user.name()); return Optional.empty(); } } @@ -88,31 +89,31 @@ public class DefaultPublisherAgreementService implements PublisherAgreementServi @Override public Optional<PeopleDocumentData> revokePublisherAgreement(PeopleDocumentData document, String currentUser) { try { - LOGGER.debug("{} is revoking publisher agreement for user: {}", currentUser, document.getPersonID()); + LOGGER.debug("{} is revoking publisher agreement for user: {}", currentUser, document.personID()); // Update the doc with an expiry date - PeopleDocumentData updated = PeopleDocumentData + PeopleDocumentData updated = PeopleDocumentDataBuilder .builder() - .setPersonID(document.getPersonID()) - .setDocumentID(document.getDocumentID()) - .setVersion(document.getVersion()) - .setEffectiveDate(document.getEffectiveDate()) - .setReceivedDate(document.getReceivedDate()) - .setScannedDocumentFileName(document.getScannedDocumentFileName()) - .setScannedDocumentMime(document.getScannedDocumentMime()) - .setScannedDocumentBLOB(document.getScannedDocumentBLOB()) - .setScannedDocumentBytes(document.getScannedDocumentBytes()) - .setComments(document.getComments()) - .setExpirationDate(new Date()) + .personID(document.personID()) + .documentID(document.documentID()) + .version(document.version()) + .effectiveDate(document.effectiveDate()) + .receivedDate(document.receivedDate()) + .scannedDocumentFileName(document.scannedDocumentFileName()) + .scannedDocumentMime(document.scannedDocumentMime()) + .scannedDocumentBLOB(document.scannedDocumentBLOB()) + .scannedDocumentBytes(document.scannedDocumentBytes()) + .comments(document.comments()) + .expirationDate(new Date()) .build(); - ModLogHeaders headers = new ModLogHeaders(document.getPersonID(), currentUser, OpenvsxModLogActions.AGREEMENT_REVOKED); + ModLogHeaders headers = new ModLogHeaders(document.personID(), currentUser, OpenvsxModLogActions.AGREEMENT_REVOKED); return foundationService.persistDocumentWithModLog(headers, updated); } catch (Exception e) { LOGGER.error("Error while revoking publisher agreement", e); - foundationService.insertErrorSysModLog("_openvsx_publisher_agreement_delete", document.getPersonID()); + foundationService.insertErrorSysModLog("_openvsx_publisher_agreement_delete", document.personID()); return Optional.empty(); } } @@ -124,7 +125,7 @@ public class DefaultPublisherAgreementService implements PublisherAgreementServi * @return True if expired/invalid, false otherwise */ private boolean isdocumentExpired(PeopleDocumentData document) { - boolean isExpired = document.getExpirationDate() != null && document.getExpirationDate().before(Date.from(Instant.now())); + boolean isExpired = document.expirationDate() != null && document.expirationDate().before(Date.from(Instant.now())); if (isExpired) { LOGGER.warn("Most recent document is expired"); } @@ -147,18 +148,18 @@ public class DefaultPublisherAgreementService implements PublisherAgreementServi // Set date to UTC timezone when creating Date now = Date.from(DateTimeHelper.now().toInstant()); - return PeopleDocumentData + return PeopleDocumentDataBuilder .builder() - .setPersonID(username) - .setDocumentID(config.docId()) - .setVersion(config.docVersion()) - .setEffectiveDate(now) - .setReceivedDate(now) - .setScannedDocumentFileName("openvsx-publisher-agreement.json") - .setScannedDocumentMime("application/json") - .setScannedDocumentBLOB(docAsBytes) - .setScannedDocumentBytes(jsonDoc.length()) - .setComments("Generated by api.eclipse.org/openvsx/publisher_agreement") + .personID(username) + .documentID(config.docId()) + .version(config.docVersion()) + .effectiveDate(now) + .receivedDate(now) + .scannedDocumentFileName("openvsx-publisher-agreement.json") + .scannedDocumentMime("application/json") + .scannedDocumentBLOB(docAsBytes) + .scannedDocumentBytes(jsonDoc.length()) + .comments("Generated by api.eclipse.org/openvsx/publisher_agreement") .build(); } @@ -173,8 +174,8 @@ public class DefaultPublisherAgreementService implements PublisherAgreementServi private PublisherAgreementData buildPublisherAgreement(PeopleDocumentData document, boolean adjustTime) { // Conversion of List<Byte> to byte[] to allow conversion to string - byte[] blob = document.getScannedDocumentBLOB() == null ? new byte[0] - : ArrayUtils.toPrimitive(document.getScannedDocumentBLOB().toArray(new Byte[document.getScannedDocumentBLOB().size()])); + byte[] blob = document.scannedDocumentBLOB() == null ? new byte[0] + : ArrayUtils.toPrimitive(document.scannedDocumentBLOB().toArray(new Byte[document.scannedDocumentBLOB().size()])); SimpleDateFormat effectiveDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat receivedDateFormat = new SimpleDateFormat("yyyy-MM-dd"); @@ -184,14 +185,14 @@ public class DefaultPublisherAgreementService implements PublisherAgreementServi // The 'received_date' column is only a 'date' type and gets rewinded a day when // adjusted for UTC time by fdndb-api. Flag should onlybe set on fetch requests if (adjustTime) { - ZonedDateTime adjustedTime = ZonedDateTime.parse(DateTimeHelper.toRFC3339(document.getReceivedDate())).plusDays(1); + ZonedDateTime adjustedTime = ZonedDateTime.parse(DateTimeHelper.toRFC3339(document.receivedDate())).plusDays(1); receivedDate = receivedDateFormat.format(Date.from(adjustedTime.toInstant())); } else { - receivedDate = receivedDateFormat.format(document.getReceivedDate()); + receivedDate = receivedDateFormat.format(document.receivedDate()); } - return new PublisherAgreementData(document.getPersonID(), document.getDocumentID(), Integer.toString((int) document.getVersion()), - effectiveDateFormat.format(document.getEffectiveDate()), receivedDate, new String(blob), document.getScannedDocumentMime(), - Integer.toString(blob.length), document.getScannedDocumentFileName(), document.getComments()); + return new PublisherAgreementData(document.personID(), document.documentID(), Integer.toString((int) document.version()), + effectiveDateFormat.format(document.effectiveDate()), receivedDate, new String(blob), document.scannedDocumentMime(), + Integer.toString(blob.length), document.scannedDocumentFileName(), document.comments()); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index dc480aaa55ac8ba25101f613c831b4757cd8990d..742eede55a8afdd768403ab42f00d9c757860687 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,7 @@ fdndb-api/mp-rest/url=http://foundationdb:8095 %dev.fdndb-api/mp-rest/url=http://localhost:10112 eclipse.security.oauth2.filter.enabled=true +eclipse.security.oauth2.filter.always-on.enabled=true quarkus.log.file.enable=false - quarkus.micrometer.enabled=true \ No newline at end of file diff --git a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockDrupalOAuthAPI.java b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockDrupalOAuthAPI.java index fa454cb1e2f4a390b91be59675a0afd92ee33290..e845c5da741dff7bc51d6f26ea903bcd662a860b 100644 --- a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockDrupalOAuthAPI.java +++ b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockDrupalOAuthAPI.java @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.efservices.api.DrupalOAuthAPI; import org.eclipsefoundation.efservices.api.models.DrupalOAuthData; +import org.eclipsefoundation.efservices.api.models.DrupalOAuthDataBuilder; import org.eclipsefoundation.efservices.api.models.DrupalUserInfo; import org.eclipsefoundation.efservices.helpers.DrupalAuthHelper; import org.eclipsefoundation.utils.exception.FinalForbiddenException; @@ -38,79 +39,78 @@ public class MockDrupalOAuthAPI implements DrupalOAuthAPI { tokens = new ArrayList<>(); tokens .addAll(Arrays - .asList(DrupalOAuthData + .asList(DrupalOAuthDataBuilder .builder() - .setAccessToken("token1") - .setClientId("client-id") - .setExpires(1674111182) - .setScope("read write") + .accessToken("token1") + .clientId("client-id") + .expires(1674111182) + .scope("read write") .build(), - DrupalOAuthData + DrupalOAuthDataBuilder .builder() - .setAccessToken("token2") - .setClientId("test-id") - .setUserId("42") - .setExpires(Instant.now().getEpochSecond() + 20000) - .setScope("read write admin") + .accessToken("token2") + .clientId("test-id") + .userId("42") + .expires(Instant.now().getEpochSecond() + 20000) + .scope("read write admin") .build(), - DrupalOAuthData + DrupalOAuthDataBuilder .builder() - .setAccessToken("token3") - .setClientId("test-id") - .setExpires(1234567890) - .setScope("read admin") + .accessToken("token3") + .clientId("test-id") + .expires(1234567890) + .scope("read admin") .build(), - DrupalOAuthData + DrupalOAuthDataBuilder .builder() - .setAccessToken("token4") - .setClientId("client-id") - .setExpires(Instant.now().getEpochSecond() + 20000) - .setScope("read write") + .accessToken("token4") + .clientId("client-id") + .expires(Instant.now().getEpochSecond() + 20000) + .scope("read write") .build(), - DrupalOAuthData + DrupalOAuthDataBuilder .builder() - .setAccessToken("token5") - .setClientId("test-id") - .setUserId("333") - .setExpires(Instant.now().getEpochSecond() + 20000) - .setScope("read write admin") + .accessToken("token5") + .clientId("test-id") + .userId("333") + .expires(Instant.now().getEpochSecond() + 20000) + .scope("read write admin") .build(), - DrupalOAuthData + DrupalOAuthDataBuilder .builder() - .setAccessToken("token6") - .setClientId("test-id") - .setExpires(Instant.now().getEpochSecond() + 20000) - .setScope("read write admin") + .accessToken("token6") + .clientId("test-id") + .expires(Instant.now().getEpochSecond() + 20000) + .scope("read write admin") .build(), - DrupalOAuthData + DrupalOAuthDataBuilder .builder() - .setAccessToken("token7") - .setClientId("test-id") - .setUserId("444") - .setExpires(Instant.now().getEpochSecond() + 20000) - .setScope("read write admin") + .accessToken("token7") + .clientId("test-id") + .userId("444") + .expires(Instant.now().getEpochSecond() + 20000) + .scope("read write admin") .build())); users = new ArrayList<>(); users .addAll(Arrays - .asList(DrupalUserInfo.builder().setSub("42").setName("fakeuser").setGithubHandle("fakeuser").build(), - DrupalUserInfo.builder().setSub("333").setName("otheruser").setGithubHandle("other").build(), - DrupalUserInfo.builder().setSub("444").setName("nodoc").setGithubHandle("nodoc").build())); + .asList(new DrupalUserInfo("42", "fakeuser", "fakeuser"), new DrupalUserInfo("333", "otheruser", "other"), + new DrupalUserInfo("444", "nodoc", "nodoc"))); } @Override public DrupalOAuthData getTokenInfo(String token) { - return tokens.stream().filter(t -> t.getAccessToken().equalsIgnoreCase(token)).findFirst().orElse(null); + return tokens.stream().filter(t -> t.accessToken().equalsIgnoreCase(token)).findFirst().orElse(null); } @Override public DrupalUserInfo getUserInfoFromToken(String token) { DrupalOAuthData tokenInfo = getTokenInfo(DrupalAuthHelper.stripBearerToken(token)); - if (tokenInfo == null || tokenInfo.getUserId() == null) { + if (tokenInfo == null || tokenInfo.userId() == null) { throw new FinalForbiddenException("The access token " + DrupalAuthHelper.stripBearerToken(token) + " provided is invalid"); } - return users.stream().filter(u -> u.getSub().equalsIgnoreCase(tokenInfo.getUserId())).findFirst().orElse(null); + return users.stream().filter(u -> u.sub().equalsIgnoreCase(tokenInfo.userId())).findFirst().orElse(null); } } \ No newline at end of file diff --git a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockPeopleAPI.java b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockPeopleAPI.java index e4c0941aad4393ab0ee04d25ff510caebef44da3..71eaec8ac9f0671052ea15e602440b14604093b7 100644 --- a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockPeopleAPI.java +++ b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockPeopleAPI.java @@ -22,14 +22,16 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.ArrayUtils; import org.eclipse.microprofile.rest.client.inject.RestClient; -import org.eclipsefoundation.foundationdb.client.model.PeopleData; -import org.eclipsefoundation.foundationdb.client.model.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDataBuilder; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentData; +import org.eclipsefoundation.foundationdb.client.runtime.model.people.PeopleDocumentDataBuilder; import org.eclipsefoundation.openvsx.api.PeopleAPI; import org.eclipsefoundation.openvsx.api.models.ModLogHeaders; -import org.jboss.resteasy.specimpl.MultivaluedMapImpl; import io.quarkus.test.Mock; import jakarta.enterprise.context.ApplicationScoped; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.Response; @@ -42,7 +44,7 @@ public class MockPeopleAPI implements PeopleAPI { private Map<String, PeopleData> people; public MockPeopleAPI() { - this.peopleDocs = new MultivaluedMapImpl<>(); + this.peopleDocs = new MultivaluedHashMap<>(); this.peopleDocs.add("fakeuser", buildPeopleDocument("fakeuser", "sampleId")); this.peopleDocs.add("firstlast", buildPeopleDocument("firstlast", "sampleId")); @@ -58,7 +60,7 @@ public class MockPeopleAPI implements PeopleAPI { @Override public Response persistPersonEntity(PeopleData src) { - return Response.ok(Arrays.asList(people.put(src.getPersonID(), src))).build(); + return Response.ok(Arrays.asList(people.put(src.personID(), src))).build(); } @Override @@ -72,7 +74,7 @@ public class MockPeopleAPI implements PeopleAPI { : peopleDocs .get(personId) .stream() - .filter(pd -> pd.getDocumentID().equalsIgnoreCase(documentId)) + .filter(pd -> pd.documentID().equalsIgnoreCase(documentId)) .collect(Collectors.toList()); } @@ -85,8 +87,8 @@ public class MockPeopleAPI implements PeopleAPI { Optional<PeopleDocumentData> existingDoc = peopleDocs .get(personId) .stream() - .filter(d -> d.getPersonID().equalsIgnoreCase(personId) && d.getDocumentID().equalsIgnoreCase(src.getDocumentID()) - && d.getEffectiveDate().compareTo(src.getEffectiveDate()) == 0) + .filter(d -> d.personID().equalsIgnoreCase(personId) && d.documentID().equalsIgnoreCase(src.documentID()) + && d.effectiveDate().compareTo(src.effectiveDate()) == 0) .findFirst(); if (existingDoc.isPresent()) { peopleDocs.remove(personId, existingDoc.get()); @@ -99,32 +101,32 @@ public class MockPeopleAPI implements PeopleAPI { } private PeopleData buildPeople(String personId) { - return PeopleData + return PeopleDataBuilder .builder() - .setPersonID(personId) - .setFname("test") - .setLname("entity") - .setType("XX") - .setMember(false) - .setEmail("test@mail.com") - .setUnixAcctCreated(false) - .setIssuesPending(false) + .personID(personId) + .fname("test") + .lname("entity") + .type("XX") + .member(false) + .email("test@mail.com") + .unixAcctCreated(false) + .issuesPending(false) .build(); } private PeopleDocumentData buildPeopleDocument(String personId, String docId) { - return PeopleDocumentData + return PeopleDocumentDataBuilder .builder() - .setPersonID(personId) - .setDocumentID(docId) - .setVersion(1) - .setEffectiveDate(new Date()) - .setReceivedDate(new Date()) - .setScannedDocumentFileName("name") - .setScannedDocumentMime("application/json") - .setScannedDocumentBLOB(Arrays.asList(ArrayUtils.toObject("test blob".getBytes()))) - .setScannedDocumentBytes(100) - .setComments("Some comments") + .personID(personId) + .documentID(docId) + .version(1) + .effectiveDate(new Date()) + .receivedDate(new Date()) + .scannedDocumentFileName("name") + .scannedDocumentMime("application/json") + .scannedDocumentBLOB(Arrays.asList(ArrayUtils.toObject("test blob".getBytes()))) + .scannedDocumentBytes(100) + .comments("Some comments") .build(); } } diff --git a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockProfileAPI.java b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockProfileAPI.java index 7652803e6a37065e258bac6fa45efbe901f3c115..b1f214b8281f68d7c961bf18ed9b26072b984ee0 100644 --- a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockProfileAPI.java +++ b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockProfileAPI.java @@ -22,7 +22,8 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipsefoundation.efservices.api.ProfileAPI; import org.eclipsefoundation.efservices.api.models.EfUser; -import org.eclipsefoundation.efservices.api.models.EfUser.Country; +import org.eclipsefoundation.efservices.api.models.EfUserBuilder; +import org.eclipsefoundation.efservices.api.models.EfUserCountryBuilder; import org.eclipsefoundation.efservices.api.models.UserSearchParams; import io.quarkus.test.Mock; @@ -40,115 +41,115 @@ public class MockProfileAPI implements ProfileAPI { this.users = new ArrayList<>(); this.users .addAll(Arrays - .asList(EfUser + .asList(EfUserBuilder .builder() - .setUid("666") - .setName("firstlast") - .setFullName("sample") - .setGithubHandle("handle") - .setMail("firstlast@test.com") - .setPicture("pic url") - .setFirstName("first") - .setLastName("last") - .setPublisherAgreements(new HashMap<>()) - .setTwitterHandle("") - .setOrg("null") - .setJobTitle("employee") - .setWebsite("site url") - .setCountry(Country.builder().build()) - .setInterests(Arrays.asList()) + .uid("666") + .name("firstlast") + .fullName("sample") + .githubHandle("handle") + .mail("firstlast@test.com") + .picture("pic url") + .firstName("first") + .lastName("last") + .publisherAgreements(new HashMap<>()) + .twitterHandle("") + .org("null") + .jobTitle("employee") + .website("site url") + .country(EfUserCountryBuilder.builder().build()) + .interests(Arrays.asList()) .build(), - EfUser + EfUserBuilder .builder() - .setUid("42") - .setName("fakeuser") - .setFullName("sample") - .setPicture("pic url") - .setFirstName("fake") - .setLastName("user") - .setMail("fakeuser@test.com") - .setPublisherAgreements(new HashMap<>()) - .setGithubHandle("fakeuser") - .setTwitterHandle("") - .setOrg("null") - .setJobTitle("employee") - .setWebsite("site url") - .setCountry(Country.builder().build()) - .setInterests(Arrays.asList()) + .uid("42") + .name("fakeuser") + .fullName("sample") + .picture("pic url") + .firstName("fake") + .lastName("user") + .mail("fakeuser@test.com") + .publisherAgreements(new HashMap<>()) + .githubHandle("fakeuser") + .twitterHandle("") + .org("null") + .jobTitle("employee") + .website("site url") + .country(EfUserCountryBuilder.builder().build()) + .interests(Arrays.asList()) .build(), - EfUser + EfUserBuilder .builder() - .setUid("333") - .setName("otheruser") - .setFullName("sample") - .setGithubHandle("other") - .setMail("admin@email.com") - .setPicture("pic url") - .setFirstName("other") - .setLastName("user") - .setPublisherAgreements(new HashMap<>()) - .setTwitterHandle("") - .setOrg("null") - .setJobTitle("employee") - .setWebsite("site url") - .setCountry(Country.builder().build()) - .setInterests(Arrays.asList()) + .uid("333") + .name("otheruser") + .fullName("sample") + .githubHandle("other") + .mail("admin@email.com") + .picture("pic url") + .firstName("other") + .lastName("user") + .publisherAgreements(new HashMap<>()) + .twitterHandle("") + .org("null") + .jobTitle("employee") + .website("site url") + .country(EfUserCountryBuilder.builder().build()) + .interests(Arrays.asList()) .build(), - EfUser + EfUserBuilder .builder() - .setUid("222") - .setName("name") - .setFullName("sample") - .setGithubHandle("name") - .setMail("Mail@test.com") - .setPicture("pic url") - .setFirstName("fake") - .setLastName("user") - .setPublisherAgreements(new HashMap<>()) - .setTwitterHandle("") - .setOrg("null") - .setJobTitle("employee") - .setWebsite("site url") - .setCountry(Country.builder().build()) - .setInterests(Arrays.asList()) + .uid("222") + .name("name") + .fullName("sample") + .githubHandle("name") + .mail("Mail@test.com") + .picture("pic url") + .firstName("fake") + .lastName("user") + .publisherAgreements(new HashMap<>()) + .twitterHandle("") + .org("null") + .jobTitle("employee") + .website("site url") + .country(EfUserCountryBuilder.builder().build()) + .interests(Arrays.asList()) .build(), - EfUser + EfUserBuilder .builder() - .setUid("444") - .setName("nodoc") - .setFullName("sample") - .setGithubHandle("nodoc") - .setMail("nodoc@test.com") - .setPicture("pic url") - .setFirstName("no") - .setLastName("doc") - .setPublisherAgreements(new HashMap<>()) - .setTwitterHandle("") - .setOrg("null") - .setJobTitle("employee") - .setWebsite("site url") - .setCountry(Country.builder().build()) - .setInterests(Arrays.asList()) + .uid("444") + .name("nodoc") + .fullName("sample") + .githubHandle("nodoc") + .mail("nodoc@test.com") + .picture("pic url") + .firstName("no") + .lastName("doc") + .publisherAgreements(new HashMap<>()) + .twitterHandle("") + .org("null") + .jobTitle("employee") + .website("site url") + .country(EfUserCountryBuilder.builder().build()) + .interests(Arrays.asList()) .build())); } @Override public List<EfUser> getUsers(String token, UserSearchParams params) { - if (params.getUid() == null && StringUtils.isBlank(params.getMail()) && StringUtils.isBlank(params.getName())) { + if (params.uid == null && StringUtils.isBlank(params.mail) && StringUtils.isBlank(params.name)) { return Collections.emptyList(); } List<EfUser> results = Collections.emptyList(); // Only filter via additional fields if it can't find with previous ones - if (params.getUid() != null) { - results = users.stream().filter(u -> u.getUid().compareTo(params.getUid()) == 0).collect(Collectors.toList()); + if (params.uid != null) { + results = users.stream().filter(u -> u.uid().compareTo(params.uid) == 0).collect(Collectors.toList()); } - if (StringUtils.isNotBlank(params.getName()) && results.isEmpty()) { - results = users.stream().filter(u -> u.getName().equalsIgnoreCase(params.getName())).collect(Collectors.toList()); + if (StringUtils.isNotBlank(params.name) && results.isEmpty()) { + results = users.stream().filter(u -> u.name().equalsIgnoreCase(params.name)).collect(Collectors.toList()); } - if (StringUtils.isNotBlank(params.getMail()) && results.isEmpty()) { - results = users.stream().filter(u -> u.getMail().equalsIgnoreCase(params.getMail())).collect(Collectors.toList()); + if (StringUtils.isNotBlank(params.mail) && results.isEmpty()) { + results = users.stream().filter(u -> u.mail().equalsIgnoreCase(params.mail)).collect(Collectors.toList()); } return results; @@ -158,7 +159,7 @@ public class MockProfileAPI implements ProfileAPI { public EfUser getUserByEfUsername(String token, String username) { return users .stream() - .filter(u -> u.getName().equalsIgnoreCase(username)) + .filter(u -> u.name().equalsIgnoreCase(username)) .findFirst() .orElseThrow(() -> new NotFoundException(String.format("User '%s' not found", username))); } @@ -167,7 +168,7 @@ public class MockProfileAPI implements ProfileAPI { public EfUser getUserByGithubHandle(String token, String handle) { return users .stream() - .filter(u -> u.getGithubHandle().equalsIgnoreCase(handle)) + .filter(u -> u.githubHandle().equalsIgnoreCase(handle)) .findFirst() .orElseThrow(() -> new NotFoundException(String.format("User '%s' not found", handle))); } diff --git a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockSysAPI.java b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockSysAPI.java index 517df61e806951497f9d4620fc327119411f29f2..29a955b4cf57c62d4117b921c3834265bf846511 100644 --- a/src/test/java/org/eclipsefoundation/openvsx/test/api/MockSysAPI.java +++ b/src/test/java/org/eclipsefoundation/openvsx/test/api/MockSysAPI.java @@ -16,7 +16,7 @@ import java.util.Arrays; import java.util.List; import org.eclipse.microprofile.rest.client.inject.RestClient; -import org.eclipsefoundation.foundationdb.client.model.SysModLogData; +import org.eclipsefoundation.foundationdb.client.runtime.model.system.SysModLogData; import org.eclipsefoundation.openvsx.api.SysAPI; import io.quarkus.test.Mock; diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 93df54c1a168ef2dd673c0e26c85f85b3233f0d8..61b37f778a97ca8e0c0bee4fc6ee2ce60fd31e03 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -7,6 +7,7 @@ quarkus.oidc-client.enabled=false eclipse.security.oauth2.filter.valid-client-ids=test-id eclipse.security.oauth2.filter.valid-scopes=read,write,admin eclipse.security.oauth2.filter.enabled=true +eclipse.security.oauth2.filter.always-on.enabled=true eclipse.openvsx.publisher-agreement.doc-id=sampleId eclipse.openvsx.publisher-agreement.doc-version=1