Skip to content

Commit

Permalink
fix(impl): [#199] Add additional validation to avoid wrong API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed Mar 28, 2024
1 parent 97122e8 commit 8397352
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.eclipse.tractusx.irs.common.auth.IrsRoles;
import org.eclipse.tractusx.irs.dtos.ErrorResponse;
import org.eclipse.tractusx.irs.edc.client.policy.Policy;
Expand Down Expand Up @@ -83,6 +85,8 @@ public class PolicyStoreController {

private final PolicyStoreService service;

private final HttpServletRequest httpServletRequest;

@Operation(operationId = "registerAllowedPolicy",
summary = "Register a policy that should be accepted in EDC negotiation.",
security = @SecurityRequirement(name = "api_key"), tags = { "Item Relationship Service" },
Expand Down Expand Up @@ -155,6 +159,13 @@ public CreatePoliciesResponse registerAllowedPolicy(@Valid @RequestBody final Cr
@PreAuthorize("hasAuthority('" + IrsRoles.ADMIN_IRS + "')")
public Map<String, List<PolicyResponse>> getPolicies(
@RequestParam(required = false) final List<String> businessPartnerNumbers) {

final Map<String, String[]> parameterMap = this.httpServletRequest.getParameterMap();
if (CollectionUtils.containsAny(parameterMap.keySet(), List.of("bpn", "bpns", "bpnls"))) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
"Please use parameter 'businessPartnerNumbers' instead");
}

return service.getPolicies(businessPartnerNumbers)
.entrySet()
.stream()
Expand Down

0 comments on commit 8397352

Please sign in to comment.