From 9a5322845f920225291435b7bbed5ce71778fb9b Mon Sep 17 00:00:00 2001 From: shamalka Date: Tue, 13 Dec 2022 10:54:20 +0530 Subject: [PATCH] Change otp api to return token --- .../carbon/device/mgt/common/spi/OTPManagementService.java | 2 +- .../mgt/core/otp/mgt/service/OTPManagementServiceImpl.java | 3 ++- .../io/entgra/ui/request/interceptor/OTPInvokerHandler.java | 2 +- .../authenticator/framework/WebappAuthenticationValve.java | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java index f63a95ca32..6349407dc1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/OTPManagementService.java @@ -34,7 +34,7 @@ public interface OTPManagementService { * @throws OTPManagementException if error occurs while creating OTP token and storing tenant details. * @throws BadRequestException if found and incompatible payload to create OTP token. */ - void sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException; + String sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException; /** * Check the validity of the OTP diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index c80502ec4f..150795ccb8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -78,7 +78,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { } @Override - public void sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException { + public String sendUserVerifyingMail(OTPWrapper otpWrapper) throws OTPManagementException, DeviceManagementException { Tenant tenant = validateTenantCreatingDetails(otpWrapper); OneTimePinDTO oneTimePinDTO = createOneTimePin(otpWrapper.getEmail(), otpWrapper.getEmailType(), otpWrapper.getUsername(), tenant, -1234); @@ -90,6 +90,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { props.setProperty("otp-token", oneTimePinDTO.getOtpToken()); sendMail(props, tenant.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); ConnectionManagerUtil.commitDBTransaction(); + return oneTimePinDTO.getOtpToken(); } catch (TransactionManagementException e) { String msg = "Error occurred while disabling AutoCommit."; log.error(msg, e); diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/OTPInvokerHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/OTPInvokerHandler.java index 44dbe7882e..440a02f98e 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/OTPInvokerHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/OTPInvokerHandler.java @@ -166,7 +166,7 @@ public class OTPInvokerHandler extends HttpServlet { throws IOException { String schema = req.getScheme(); apiEndpoint = schema + HandlerConstants.SCHEME_SEPARATOR + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) - + HandlerConstants.COLON + HandlerUtil.getGatewayPort(schema); + + HandlerConstants.COLON + HandlerUtil.getCorePort(schema); if (StringUtils.isBlank(req.getHeader(HandlerConstants.OTP_HEADER))) { log.error("Unauthorized, Please provide OTP token."); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java index 3864954fe9..58f35fab19 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java @@ -315,4 +315,4 @@ public class WebappAuthenticationValve extends CarbonTomcatValve { break; } } -} \ No newline at end of file +}