From 18531d0500221e2d1072d314c9a850bd554fc893 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Tue, 4 Aug 2020 19:39:05 +0530 Subject: [PATCH] Add tenant ID and username to all layers --- .../mgt/common/otp/mgt/dto/OTPMailDTO.java | 23 ++++++++++++++---- .../otp/mgt/wrapper/OTPMailWrapper.java | 10 ++++---- .../dao/impl/GenericOTPManagementDAOImpl.java | 24 +++++++++++-------- .../mgt/service/OTPManagementServiceImpl.java | 7 +++--- .../src/main/resources/dbscripts/cdm/h2.sql | 1 - .../main/resources/dbscripts/cdm/mssql.sql | 1 - .../main/resources/dbscripts/cdm/mysql.sql | 1 - .../main/resources/dbscripts/cdm/oracle.sql | 1 - .../resources/dbscripts/cdm/postgresql.sql | 1 - 9 files changed, 41 insertions(+), 28 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/dto/OTPMailDTO.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/dto/OTPMailDTO.java index ee582b8288..87c347419e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/dto/OTPMailDTO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/dto/OTPMailDTO.java @@ -23,7 +23,8 @@ public class OTPMailDTO { int id; String otpToken; - String tenantDomain; + int tenantId; + String username; String email; String emailType; String metaInfo; @@ -32,6 +33,22 @@ public class OTPMailDTO { boolean isExpired; boolean isTenantCreated; + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + public int getId() { return id; } @@ -94,10 +111,6 @@ public class OTPMailDTO { isExpired = expired; } - public String getTenantDomain() { return tenantDomain; } - - public void setTenantDomain(String tenantDomain) { this.tenantDomain = tenantDomain; } - public boolean isTenantCreated() { return isTenantCreated; } public void setTenantCreated(boolean tenantCreated) { isTenantCreated = tenantCreated; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/OTPMailWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/OTPMailWrapper.java index 35f255ef6b..176e899a86 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/OTPMailWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/otp/mgt/wrapper/OTPMailWrapper.java @@ -20,18 +20,18 @@ public class OTPMailWrapper { private String firstName; private String lastName; - private String tenantDomain; private String adminUsername; + int tenantId; private String adminPassword; private String email; private String emailType; - public String getTenantDomain() { - return tenantDomain; + public int getTenantId() { + return tenantId; } - public void setTenantDomain(String tenantDomain) { - this.tenantDomain = tenantDomain; + public void setTenantId(int tenantId) { + this.tenantId = tenantId; } public String getAdminUsername() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java index 7cc27618a1..076f5f820f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java @@ -47,22 +47,24 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM String sql = "INSERT INTO DM_OTP_DATA " + "(OTP_TOKEN, " - + "TENANT_DOMAIN," + "EMAIL, " + "EMAIL_TYPE, " + "META_INFO, " - + "CREATED_AT) VALUES (?, ?, ?, ?, ?, ?)"; + + "CREATED_AT," + + "TENANT_ID," + + "USERNAME) VALUES (?, ?, ?, ?, ?, ?, ?)"; try { Connection conn = this.getDBConnection(); Calendar calendar = Calendar.getInstance(); Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { stmt.setString(1, otpMailDTO.getOtpToken()); - stmt.setString(2, otpMailDTO.getTenantDomain()); - stmt.setString(3, otpMailDTO.getEmail()); - stmt.setString(4, otpMailDTO.getEmailType()); - stmt.setString(5, otpMailDTO.getMetaInfo()); - stmt.setTimestamp(6, timestamp); + stmt.setString(2, otpMailDTO.getEmail()); + stmt.setString(3, otpMailDTO.getEmailType()); + stmt.setString(4, otpMailDTO.getMetaInfo()); + stmt.setTimestamp(5, timestamp); + stmt.setInt(6, otpMailDTO.getTenantId()); + stmt.setString(7, otpMailDTO.getUsername()); stmt.executeUpdate(); try (ResultSet rs = stmt.getGeneratedKeys()) { if (rs.next()) { @@ -94,14 +96,15 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM String sql = "SELECT " + "ID, " + "OTP_TOKEN, " - + "TENANT_DOMAIN," + "EMAIL, " + "EMAIL_TYPE, " + "META_INFO, " + "CREATED_AT, " + "EXPIRY_TIME, " + "IS_EXPIRED, " - + "TENANT_CREATED FROM DM_OTP_DATA " + + "TENANT_CREATED," + + "TENANT_ID, " + + "USERNAME FROM DM_OTP_DATA " + "WHERE OTP_TOKEN = ?"; try { @@ -114,7 +117,6 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM OTPMailDTO otpMailDTO = new OTPMailDTO(); otpMailDTO.setId(rs.getInt("ID")); otpMailDTO.setOtpToken(rs.getString("OTP_TOKEN")); - otpMailDTO.setTenantDomain(rs.getString("TENANT_DOMAIN")); otpMailDTO.setEmail(rs.getString("EMAIL")); otpMailDTO.setEmailType(rs.getString("EMAIL_TYPE")); otpMailDTO.setMetaInfo(rs.getString("META_INFO")); @@ -122,6 +124,8 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM otpMailDTO.setExpiryTime(rs.getInt("EXPIRY_TIME")); otpMailDTO.setExpired(rs.getBoolean("IS_EXPIRED")); otpMailDTO.setTenantCreated(rs.getBoolean("TENANT_CREATED")); + otpMailDTO.setTenantId(rs.getInt("TENANT_ID")); + otpMailDTO.setUsername(rs.getString("USERNAME")); return otpMailDTO; } return null; 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 47ef466114..1df9b13b32 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 @@ -70,7 +70,8 @@ public class OTPManagementServiceImpl implements OTPManagementService { OTPMailDTO otpMailDTO = new OTPMailDTO(); otpMailDTO.setEmail(otpMailWrapper.getEmail()); - otpMailDTO.setTenantDomain(otpMailWrapper.getTenantDomain()); + otpMailDTO.setTenantId(otpMailDTO.getTenantId()); + otpMailDTO.setUsername(otpMailWrapper.getAdminUsername()); otpMailDTO.setEmailType(otpMailWrapper.getEmailType()); otpMailDTO.setMetaInfo(metaInfo); otpMailDTO.setOtpToken(otpValue); @@ -190,8 +191,8 @@ public class OTPManagementServiceImpl implements OTPManagementService { log.error("Received empty or blank email type field with OTP creating payload."); return false; } - if (StringUtils.isBlank(otpMailWrapper.getTenantDomain())) { - log.error("Received empty or blank tenant domain field with OTP creating payload."); + if (otpMailWrapper.getTenantId() != -1234 && otpMailWrapper.getTenantId() < 1) { + log.error("Invalid tenant Id field with OTP creating payload."); return false; } return true; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index b75cbd2295..5ff3b1c08c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -576,7 +576,6 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( CREATE TABLE IF NOT EXISTS DM_OTP_DATA ( ID INT AUTO_INCREMENT NOT NULL, OTP_TOKEN VARCHAR(100) NOT NULL, - TENANT_DOMAIN VARCHAR(20) NOT NULL, TENANT_ID INT NOT NULL, USERNAME VARCHAR(500) DEFAULT NOT NULL, EMAIL VARCHAR(100) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 90171e6735..5c82436ff1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -618,7 +618,6 @@ CREATE TABLE DM_METADATA ( CREATE TABLE DM_OTP_DATA ( ID INT IDENTITY NOT NULL, OTP_TOKEN VARCHAR(100) NOT NULL, - TENANT_DOMAIN VARCHAR(20) NOT NULL, TENANT_ID INTEGER NOT NULL, USERNAME VARCHAR(500) NOT NULL, EMAIL VARCHAR(100) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 42e103963b..b2c64ebb3a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -634,7 +634,6 @@ CREATE TABLE IF NOT EXISTS DM_METADATA ( CREATE TABLE IF NOT EXISTS DM_OTP_DATA ( ID INT AUTO_INCREMENT NOT NULL, OTP_TOKEN VARCHAR(100) NOT NULL, - TENANT_DOMAIN VARCHAR(20) NOT NULL, TENANT_ID INT NOT NULL, USERNAME VARCHAR(500) NOT NULL, EMAIL VARCHAR(100) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index da01528e68..16139722fb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -982,7 +982,6 @@ END; CREATE TABLE DM_OTP_DATA ( ID NUMBER(10) NOT NULL, OTP_TOKEN VARCHAR2(100) NOT NULL, - TENANT_DOMAIN VARCHAR(20) NOT NULL, TENANT_ID INTEGER NOT NULL, USERNAME VARCHAR(500) NOT NULL, EMAIL VARCHAR2(100) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 279494c5da..d5db624796 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -623,7 +623,6 @@ CREATE SEQUENCE DM_OTP_DATA_seq; CREATE TABLE IF NOT EXISTS DM_OTP_DATA ( ID INT DEFAULT NEXTVAL ('DM_OTP_DATA_seq') NOT NULL, OTP_TOKEN VARCHAR(100) NOT NULL, - TENANT_DOMAIN VARCHAR(20) NOT NULL, TENANT_ID INTEGER NOT NULL, USERNAME VARCHAR(500) NOT NULL, EMAIL VARCHAR(100) NOT NULL,