From 578266a41994566b516f2725fa306ee67cf5e54c Mon Sep 17 00:00:00 2001 From: navodzoysa Date: Mon, 5 Dec 2022 18:48:41 +0530 Subject: [PATCH 1/6] Fix error when deleting tags/categories with special characters --- .../ApplicationManagementPublisherAdminAPI.java | 14 +++++++------- ...ApplicationManagementPublisherAdminAPIImpl.java | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java index c3db07a21b..37554f6634 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/admin/ApplicationManagementPublisherAdminAPI.java @@ -157,12 +157,12 @@ public interface ApplicationManagementPublisherAdminAPI { @PathParam("appId") int applicatioId); @DELETE - @Path("/tags/{tagName}") + @Path("/tags") @Produces(MediaType.APPLICATION_JSON) @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", + httpMethod = "DELETE", value = "Delete application tag", notes = "This will delete application tag", tags = "Application Management", @@ -185,10 +185,10 @@ public interface ApplicationManagementPublisherAdminAPI { }) Response deleteTag( @ApiParam( - name = "tagName", + name = "tag-name", value = "Tag Name", required = true) - @PathParam("tagName") String tagName + @QueryParam("tag-name") String tagName ); @POST @@ -273,7 +273,7 @@ public interface ApplicationManagementPublisherAdminAPI { ); @DELETE - @Path("/categories/{categoryName}") + @Path("/categories") @Produces(MediaType.APPLICATION_JSON) @ApiOperation( consumes = MediaType.APPLICATION_JSON, @@ -301,10 +301,10 @@ public interface ApplicationManagementPublisherAdminAPI { }) Response deleteCategory( @ApiParam( - name = "categoryName", + name = "category-name", value = "Category Name", required = true) - @PathParam("categoryName") String categoryName + @QueryParam("category-name") String categoryName ); @PUT diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java index 9799ab9a7f..9dae875ca8 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/admin/ApplicationManagementPublisherAdminAPIImpl.java @@ -104,9 +104,9 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa @DELETE @Override @Consumes(MediaType.WILDCARD) - @Path("/tags/{tagName}") + @Path("/tags") public Response deleteTag( - @PathParam("tagName") String tagName) { + @QueryParam("tag-name") String tagName) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { applicationManager.deleteTag(tagName); @@ -169,9 +169,9 @@ public class ApplicationManagementPublisherAdminAPIImpl implements ApplicationMa @DELETE @Override @Consumes(MediaType.WILDCARD) - @Path("/categories/{categoryName}") + @Path("/categories") public Response deleteCategory( - @PathParam("categoryName") String categoryName) { + @QueryParam("category-name") String categoryName) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { applicationManager.deleteCategory(categoryName); From a367cd6b359f1310000c845c01aadd677ab5d9ce Mon Sep 17 00:00:00 2001 From: navodzoysa Date: Mon, 5 Dec 2022 13:11:37 +0530 Subject: [PATCH 2/6] Fix duplicate group and role error handling responses --- .../impl/RoleManagementServiceImpl.java | 27 +++++++++++++------ .../GroupManagementProviderServiceImpl.java | 14 ++++++---- .../api/service/TraccarClientFactory.java | 2 +- .../api/service/addons/TraccarClientImpl.java | 2 +- 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index 7bedb0f890..af05da7991 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -54,6 +54,7 @@ import org.wso2.carbon.registry.core.session.UserRegistry; import org.wso2.carbon.registry.resource.services.utils.ChangeRolePermissionsUtil; import org.wso2.carbon.user.api.*; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; +import org.wso2.carbon.user.core.constants.UserCoreErrorConstants.ErrorMessages; import org.wso2.carbon.user.mgt.UserRealmProxy; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import org.wso2.carbon.user.mgt.common.UserAdminException; @@ -316,21 +317,31 @@ public class RoleManagementServiceImpl implements RoleManagementService { entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been" + " added").build(); } catch (UserStoreException e) { - String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'"; - log.error(msg, e); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + String errorCode = ""; + String errorMessage = e.getMessage(); + if (errorMessage != null && !errorMessage.isEmpty() && + errorMessage.contains(ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode())) { + errorCode = e.getMessage().split("-")[0].trim(); + } + if (ErrorMessages.ERROR_CODE_ROLE_ALREADY_EXISTS.getCode().equals(errorCode)) { + String roleName = roleInfo.getRoleName().split("/")[1]; + String msg = "Role already exists with name " + roleName + "."; + log.warn(msg); + return Response.status(Response.Status.CONFLICT).entity(msg).build(); + } else { + String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } } catch (URISyntaxException e) { String msg = "Error occurred while composing the URI at which the information of the newly created role " + "can be retrieved"; log.error(msg, e); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (UnsupportedEncodingException e) { String msg = "Error occurred while encoding role name"; log.error(msg, e); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 66a8ba9362..aed9bc8782 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -47,6 +47,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; @@ -140,12 +141,15 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid if (HttpReportingUtil.isTrackerEnabled()){ existingGroup = this.groupDAO.getGroup(deviceGroup.getName(), tenantId); int groupId = existingGroup.getGroupId(); - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .addGroup(deviceGroup, groupId, tenantId); + try { + DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() + .addGroup(deviceGroup, groupId, tenantId); + } catch (TrackerAlreadyExistException e) { + throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); + } + } else { + throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); } - // add a group if not exist in traccar starts - - throw new GroupAlreadyExistException("Group exist with name " + deviceGroup.getName()); } } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java index bffa6f5e85..2a94596230 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java @@ -648,7 +648,7 @@ public class TraccarClientFactory { TrackerManagementDAOFactory.openConnection(); trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId); if (trackerGroupInfo != null) { - String msg = "The group already exit"; + String msg = "The group already exists in Traccar."; log.error(msg); throw new TrackerAlreadyExistException(msg); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java index 0e9264a325..efa13ee6a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java @@ -555,7 +555,7 @@ public class TraccarClientImpl implements TraccarClient { TrackerManagementDAOFactory.openConnection(); trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId); if (trackerGroupInfo != null) { - String msg = "The group already exit"; + String msg = "The group already exists in Traccar."; log.error(msg); throw new TrackerAlreadyExistException(msg); } From 71c4e3b4d072cabd7e6a1cb6945455a3664a644b Mon Sep 17 00:00:00 2001 From: Kavin Prathaban Date: Mon, 12 Dec 2022 08:17:48 +0000 Subject: [PATCH 3/6] Add fix for error on searching app with AppType with ALL filter Co-authored-by: Kavin Prathaban Co-committed-by: Kavin Prathaban --- .../core/dao/impl/application/GenericApplicationDAOImpl.java | 5 +++-- .../core/dao/impl/application/OracleApplicationDAOImpl.java | 5 +++-- .../dao/impl/application/SQLServerApplicationDAOImpl.java | 5 +++-- .../application/mgt/core/impl/ApplicationManagerImpl.java | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 5b07d0a049..362c9086d7 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -31,6 +31,7 @@ import io.entgra.application.mgt.core.util.DAOUtil; import io.entgra.application.mgt.core.dao.impl.AbstractDAOImpl; import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException; import io.entgra.application.mgt.core.exception.UnexpectedServerErrorException; +import io.entgra.application.mgt.core.util.Constants; import java.sql.Connection; import java.sql.PreparedStatement; @@ -149,7 +150,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } sql += "WHERE AP_APP.TENANT_ID = ? "; - if (StringUtils.isNotEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { sql += "AND AP_APP.TYPE = ? "; } if (StringUtils.isNotEmpty(filter.getAppName())) { @@ -204,7 +205,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; stmt.setInt(paramIndex++, tenantId); - if (StringUtils.isNotEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } if (StringUtils.isNotEmpty(filter.getAppName())) { diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java index 6f4c31f1b9..58e85560a7 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java @@ -26,6 +26,7 @@ import io.entgra.application.mgt.common.dto.ApplicationDTO; import io.entgra.application.mgt.common.exception.DBConnectionException; import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException; import io.entgra.application.mgt.core.util.DAOUtil; +import io.entgra.application.mgt.core.util.Constants; import java.sql.Connection; import java.sql.PreparedStatement; @@ -94,7 +95,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { || StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; } - if (StringUtils.isNotEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { sql += "AND AP_APP.TYPE = ? "; } if (StringUtils.isNotEmpty(filter.getAppName())) { @@ -145,7 +146,7 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; - if (StringUtils.isNotEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } if (StringUtils.isNotEmpty(filter.getAppName())) { diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java index 0ddbe3c333..9ad0b9d4c0 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java @@ -25,6 +25,7 @@ import io.entgra.application.mgt.common.dto.ApplicationDTO; import io.entgra.application.mgt.common.exception.DBConnectionException; import io.entgra.application.mgt.core.exception.ApplicationManagementDAOException; import io.entgra.application.mgt.core.util.DAOUtil; +import io.entgra.application.mgt.core.util.Constants; import java.sql.Connection; import java.sql.PreparedStatement; @@ -93,7 +94,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { || StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; } - if (StringUtils.isNotEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { sql += "AND AP_APP.TYPE = ? "; } if (StringUtils.isNotEmpty(filter.getAppName())) { @@ -144,7 +145,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; - if (StringUtils.isNotEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } if (StringUtils.isNotEmpty(filter.getAppName())) { diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 26f97f0caf..157d73241d 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -2932,7 +2932,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!StringUtils.isEmpty(appType)) { boolean isValidAppType = false; for (ApplicationType applicationType : ApplicationType.values()) { - if (applicationType.toString().equalsIgnoreCase(appType)) { + if (applicationType.toString().equalsIgnoreCase(appType) || Constants.ALL.equalsIgnoreCase(appType)) { isValidAppType = true; break; } From 458ab342695267cc62e5309d5c361a0a01b2d465 Mon Sep 17 00:00:00 2001 From: Amalka Subasinghe Date: Mon, 12 Dec 2022 11:39:01 +0000 Subject: [PATCH 4/6] updated EntgraLogger methods (#30) Co-authored-by: Amalka Subasinghe Co-authored-by: Pahansith Gunathilake Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/30 Co-authored-by: Amalka Subasinghe Co-committed-by: Amalka Subasinghe --- .../pom.xml | 2 +- .../extensions/logger/spi/EntgraLogger.java | 54 +++++-------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml index d340500b82..fc57038041 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml @@ -51,7 +51,7 @@ Entgra Logger Bundle io.entgra.device.mgt.extensions.logger, - org.apache.commons.logging;version="[1.2,2) + org.apache.commons.logging io.entgra.device.mgt.extensions.logger.* diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java index ba34e1552f..c959eb4885 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/src/main/java/io/entgra/device/mgt/extensions/logger/spi/EntgraLogger.java @@ -24,57 +24,29 @@ import org.apache.commons.logging.Log; public interface EntgraLogger extends Log { - void info(String message); + void info(Object object, LogContext logContext); + + void info(Object object, Throwable t, LogContext logContext); - void info(String message, Throwable t); + void debug(Object object, LogContext logContext); - void info(String message, LogContext logContext); + void debug(Object object, Throwable t, LogContext logContext); - void debug(String message); + void error(Object object, LogContext logContext); - void debug(String message, Throwable t); + void error(Object object, Throwable t, LogContext logContext); - void debug(String message, LogContext logContext); + void fatal(Object object, LogContext logContext); - void error(String message); + void fatal(Object object, Throwable t, LogContext logContext); - void error(String message, Throwable t); + void trace(Object object, LogContext logContext); - void error(String message, LogContext logContext); + void trace(Object object, Throwable t, LogContext logContext); - void error(String message, Throwable t, LogContext logContext); + void warn(Object object, LogContext logContext); - void warn(String message); - - void warn(String message, Throwable t); - - void warn(String message, LogContext logContext); - - void warn(String message, Throwable t, LogContext logContext); - - void trace(String message); - - void trace(String message, Throwable t); - - void trace(String message, LogContext logContext); - - void fatal(String message); - - void fatal(String message, Throwable t); - - void fatal(String message, LogContext logContext); - - boolean isDebugEnabled(); - - boolean isErrorEnabled(); - - boolean isFatalEnabled(); - - boolean isInfoEnabled(); - - boolean isTraceEnabled(); - - boolean isWarnEnabled(); + void warn(Object object, Throwable t, LogContext logContext); void clearLogContext(); From 9a5322845f920225291435b7bbed5ce71778fb9b Mon Sep 17 00:00:00 2001 From: shamalka Date: Tue, 13 Dec 2022 10:54:20 +0530 Subject: [PATCH 5/6] 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 +} From 0712cd744a655687efdc77ace124339a647e1447 Mon Sep 17 00:00:00 2001 From: shamalka Date: Tue, 13 Dec 2022 13:51:32 +0530 Subject: [PATCH 6/6] Remove unwanted lines --- .../core/otp/mgt/service/OTPManagementServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 150795ccb8..985fe76486 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 @@ -85,10 +85,10 @@ public class OTPManagementServiceImpl implements OTPManagementService { try { ConnectionManagerUtil.beginDBTransaction(); this.otpManagementDAO.addOTPData(Collections.singletonList(oneTimePinDTO)); - Properties props = new Properties(); - props.setProperty("first-name", tenant.getAdminFirstName()); - props.setProperty("otp-token", oneTimePinDTO.getOtpToken()); - sendMail(props, tenant.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); +// Properties props = new Properties(); +// props.setProperty("first-name", tenant.getAdminFirstName()); +// props.setProperty("otp-token", oneTimePinDTO.getOtpToken()); +// sendMail(props, tenant.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); ConnectionManagerUtil.commitDBTransaction(); return oneTimePinDTO.getOtpToken(); } catch (TransactionManagementException e) {