From e2545b04e68f3eaebf826a11223082e5a57c8ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dvo=C5=99=C3=A1k?= Date: Mon, 26 Aug 2024 21:14:49 +0200 Subject: [PATCH] Add request/response wrapper --- .../spring/controller/KeyStoreController.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/powerauth-restful-security-spring/src/main/java/io/getlime/security/powerauth/rest/api/spring/controller/KeyStoreController.java b/powerauth-restful-security-spring/src/main/java/io/getlime/security/powerauth/rest/api/spring/controller/KeyStoreController.java index 19c268c1..76a706b4 100644 --- a/powerauth-restful-security-spring/src/main/java/io/getlime/security/powerauth/rest/api/spring/controller/KeyStoreController.java +++ b/powerauth-restful-security-spring/src/main/java/io/getlime/security/powerauth/rest/api/spring/controller/KeyStoreController.java @@ -19,6 +19,8 @@ */ package io.getlime.security.powerauth.rest.api.spring.controller; +import io.getlime.core.rest.model.base.request.ObjectRequest; +import io.getlime.core.rest.model.base.response.ObjectResponse; import io.getlime.security.powerauth.rest.api.model.request.TemporaryKeyRequest; import io.getlime.security.powerauth.rest.api.model.response.TemporaryKeyResponse; import io.getlime.security.powerauth.rest.api.spring.exception.PowerAuthTemporaryKeyException; @@ -26,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; /** @@ -62,12 +65,21 @@ public KeyStoreController(KeyStoreService service) { * @throws PowerAuthTemporaryKeyException In case temporary key cannot be returned. */ @PostMapping("create") - public TemporaryKeyResponse fetchTemporaryKey(@RequestBody TemporaryKeyRequest request) throws PowerAuthTemporaryKeyException { + public ObjectResponse fetchTemporaryKey(@RequestBody ObjectRequest request) throws PowerAuthTemporaryKeyException { if (request == null) { - logger.warn("Invalid request while fetching temporary key"); + logger.warn("Null request while fetching temporary key"); throw new PowerAuthTemporaryKeyException(); } - return service.fetchTemporaryKey(request); + final TemporaryKeyRequest requestObject = request.getRequestObject(); + if (requestObject == null) { + logger.warn("Null request object while fetching temporary key"); + throw new PowerAuthTemporaryKeyException(); + } + if (!StringUtils.hasLength(requestObject.getJwt())) { + logger.warn("Invalid request object with empty JWT while fetching temporary key"); + throw new PowerAuthTemporaryKeyException(); + } + return new ObjectResponse<>(service.fetchTemporaryKey(requestObject)); } }