|
| 1 | +/* |
| 2 | + * Cerberus Copyright (C) 2013 - 2025 cerberustesting |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This file is part of Cerberus. |
| 6 | + * |
| 7 | + * Cerberus is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * Cerberus is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with Cerberus. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | +package org.cerberus.core.api.controllers; |
| 21 | + |
| 22 | +import com.fasterxml.jackson.annotation.JsonView; |
| 23 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 24 | +import com.iab.gpp.encoder.GppModel; |
| 25 | +import com.iab.gpp.encoder.section.TcfEuV2; |
| 26 | +import io.swagger.v3.oas.annotations.Operation; |
| 27 | +import io.swagger.v3.oas.annotations.Parameter; |
| 28 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 29 | +import lombok.AllArgsConstructor; |
| 30 | +import org.apache.logging.log4j.LogManager; |
| 31 | +import org.apache.logging.log4j.Logger; |
| 32 | +import org.cerberus.core.api.controllers.wrappers.ResponseWrapper; |
| 33 | +import org.cerberus.core.api.dto.views.View; |
| 34 | +import org.cerberus.core.api.services.PublicApiAuthenticationService; |
| 35 | +import org.cerberus.core.crud.entity.LogEvent; |
| 36 | +import org.cerberus.core.crud.service.ILogEventService; |
| 37 | +import org.cerberus.core.util.IabGppDecoder; |
| 38 | +import org.springframework.http.HttpStatus; |
| 39 | +import org.springframework.http.MediaType; |
| 40 | +import org.springframework.web.bind.annotation.*; |
| 41 | + |
| 42 | +import javax.servlet.http.HttpServletRequest; |
| 43 | +import java.security.Principal; |
| 44 | +import java.util.*; |
| 45 | + |
| 46 | +@AllArgsConstructor |
| 47 | +@Tag(name = "Utils", description = "Operations related to Utils") |
| 48 | +@RestController |
| 49 | +@RequestMapping(path = "/public/utils") |
| 50 | +public class UtilsController { |
| 51 | + |
| 52 | + private static final String API_VERSION_1 = "X-API-VERSION=1"; |
| 53 | + private static final String API_KEY = "X-API-KEY"; |
| 54 | + private final PublicApiAuthenticationService apiAuthenticationService; |
| 55 | + private static final Logger LOG = LogManager.getLogger(UtilsController.class); |
| 56 | + private final ILogEventService logEventService; |
| 57 | + private final IabGppDecoder iapGppDecoder; |
| 58 | + |
| 59 | + @GetMapping(path = "/decode-tcfeuv2", headers = {API_VERSION_1}, produces = MediaType.APPLICATION_JSON_VALUE) |
| 60 | + @Operation( |
| 61 | + summary = "Decode the TCFEuV2 section", |
| 62 | + description = "Decode only the TCFEuV2 (section 2) from an IAB GPP string and return JSON" |
| 63 | + ) |
| 64 | + @JsonView(View.Public.GET.class) |
| 65 | + @ResponseStatus(HttpStatus.OK) |
| 66 | + public ResponseWrapper<Map<String, Object>> decodeTCFEuV2( |
| 67 | + @Parameter(description = "IAB GPP String") |
| 68 | + @RequestParam("iabgpp") String iabgpp, |
| 69 | + @RequestHeader(name = API_KEY, required = false) String apiKey, |
| 70 | + HttpServletRequest request, |
| 71 | + Principal principal) { |
| 72 | + |
| 73 | + String login = this.apiAuthenticationService.authenticateLogin(principal, apiKey); |
| 74 | + logEventService.createForPublicCalls( |
| 75 | + "/public/utils/decode-tcfeuv2", |
| 76 | + "CALL-GET", |
| 77 | + LogEvent.STATUS_INFO, |
| 78 | + String.format("API /decode-tcfeuv2 called with URL: %s", request.getRequestURL()), |
| 79 | + request, |
| 80 | + login); |
| 81 | + |
| 82 | + return ResponseWrapper.wrap(iapGppDecoder.decodeTcfEuV2(iabgpp)); |
| 83 | + } |
| 84 | + |
| 85 | +} |
| 86 | + |
0 commit comments