From 9e5dd759ec3df4e7159438a85ea2b8e0e59acaef Mon Sep 17 00:00:00 2001 From: wso2-engineering-bot Date: Thu, 11 Sep 2025 10:53:23 +0530 Subject: [PATCH] Log improvements --- .../ExtensionManagementServiceHolder.java | 13 +++- .../common/utils/ExtensionMgtUtils.java | 28 +++++++- .../v1/function/ExtensionListItemBuilder.java | 15 +++++ .../ExtensionResponseModelBuilder.java | 19 ++++++ .../v1/impl/ExtensionsApiServiceImpl.java | 62 ++++++++++++++++++ .../common/RemoteFetchServiceHolder.java | 15 ++++- ...verRemoteFetchConfigManagementService.java | 28 +++++++- ...teFetchConfigManagementServiceFactory.java | 8 +++ .../v1/impl/RemoteFetchApiServiceImpl.java | 35 ++++++++++ .../common/FlowExecutionServiceHolder.java | 31 ++++++++- .../v1/core/FlowExecutionServiceCore.java | 26 ++++++++ .../FlowExecutionServiceFactory.java | 13 ++++ .../execution/v1/impl/FlowApiServiceImpl.java | 16 +++++ .../server/flow/execution/v1/utils/Utils.java | 24 ++++++- .../common/FlowMgtServiceHolder.java | 40 ++++++++++-- .../management/v1/core/FlowAIServiceCore.java | 5 ++ .../v1/core/ServerFlowMgtService.java | 41 ++++++++++++ .../v1/factories/FlowAIServiceFactory.java | 5 ++ .../ServerFlowMgtServiceFactory.java | 7 +- .../v1/impl/FlowApiServiceImpl.java | 41 ++++++++++++ .../flow/management/v1/utils/Utils.java | 14 ++++ .../common/GovernanceDataHolder.java | 13 +++- .../core/ServerIdentityGovernanceService.java | 50 ++++++++++++++ ...erverIdentityGovernanceServiceFactory.java | 13 ++++ .../IdentityGovernanceApiServiceImpl.java | 41 ++++++++++++ .../common/IdentityProviderServiceHolder.java | 22 +++++++ .../v1/core/ServerIdpManagementService.java | 46 +++++++++++++ .../ServerIdpManagementServiceFactory.java | 6 ++ ...atedAuthenticatorConfigBuilderFactory.java | 4 ++ .../impl/IdentityProvidersApiServiceImpl.java | 20 +++++- .../TrustedTokenIssuersApiServiceImpl.java | 4 ++ .../IdentityVerificationServiceHolder.java | 14 +++- .../provider/v1/core/IdVProviderService.java | 65 ++++++++++++++++++- .../factories/IdVProviderServiceFactory.java | 13 ++++ .../v1/impl/IdvProvidersApiServiceImpl.java | 46 +++++++++++++ .../common/InputValidationServiceHolder.java | 13 +++- .../input/validation/common/util/Utils.java | 19 +++++- .../ValidationRulesManagementApiService.java | 45 +++++++++++++ ...ationRulesManagementApiServiceFactory.java | 11 ++++ .../impl/ValidationRulesApiServiceImpl.java | 32 +++++++++ .../common/KeyStoreManagamentDataHolder.java | 13 +++- .../management/v1/core/KeyStoreService.java | 46 ++++++++++++- .../v1/factories/KeyStoreServiceFactory.java | 11 ++++ .../v1/impl/KeystoresApiServiceImpl.java | 39 +++++++++++ 44 files changed, 1046 insertions(+), 26 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/ExtensionManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/ExtensionManagementServiceHolder.java index 4ff6482664..77ce57519c 100644 --- a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/ExtensionManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/ExtensionManagementServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.extension.management.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.extension.mgt.ExtensionManager; @@ -26,6 +28,8 @@ */ public class ExtensionManagementServiceHolder { + private static final Log log = LogFactory.getLog(ExtensionManagementServiceHolder.class); + private ExtensionManagementServiceHolder() {} private static class ExtensionManagerHolder { @@ -41,6 +45,13 @@ private static class ExtensionManagerHolder { */ public static ExtensionManager getExtensionManager() { - return ExtensionManagerHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving ExtensionManager OSGi service."); + } + ExtensionManager extensionManager = ExtensionManagerHolder.SERVICE; + if (extensionManager == null) { + log.warn("ExtensionManager OSGi service is not available."); + } + return extensionManager; } } diff --git a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/utils/ExtensionMgtUtils.java b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/utils/ExtensionMgtUtils.java index 8987570132..e2faf1299b 100644 --- a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/utils/ExtensionMgtUtils.java +++ b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.common/src/main/java/org/wso2/carbon/identity/api/server/extension/management/common/utils/ExtensionMgtUtils.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.extension.management.common.utils; import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.Constants; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.common.error.APIError; @@ -27,13 +29,16 @@ import javax.ws.rs.core.Response; -import static org.wso2.carbon.identity.api.server.extension.management.common.utils.ExtensionMgtConstants.EXTENSION_MGT_PATH_COMPONENT; +import static org.wso2.carbon.identity.api.server.extension.management.common.utils.ExtensionMgtConstants + .EXTENSION_MGT_PATH_COMPONENT; /** * Utility class for extension management. */ public class ExtensionMgtUtils { + private static final Log log = LogFactory.getLog(ExtensionMgtUtils.class); + /** * Get the path of the extension type. * @@ -42,6 +47,11 @@ public class ExtensionMgtUtils { */ public static String getExtensionInfoLocation(String extensionType, String extensionId) { + if (log.isDebugEnabled()) { + log.debug("Building extension info location for type: " + + (extensionType != null ? extensionType : "null") + ", id: " + + (extensionId != null ? extensionId : "null")); + } return ContextLoader.buildURIForBody( Constants.V1_API_PATH_COMPONENT + EXTENSION_MGT_PATH_COMPONENT + '/' + extensionType + "/" + extensionId).toString(); @@ -58,6 +68,13 @@ public static String getExtensionInfoLocation(String extensionType, String exten public static APIError handleClientException(Response.Status status, ExtensionMgtConstants.ErrorMessage error, String... data) { + if (error == null) { + throw new IllegalArgumentException("Error message cannot be null."); + } + if (log.isDebugEnabled()) { + log.debug("Handling client exception with status: " + status + ", error code: " + + error.getCode()); + } return new APIError(status, getErrorBuilder(error, data).build()); } @@ -72,6 +89,11 @@ public static APIError handleClientException(Response.Status status, ExtensionMg public static APIError handleServerException(Response.Status status, ExtensionMgtConstants.ErrorMessage error, String... data) { + if (error == null) { + throw new IllegalArgumentException("Error message cannot be null."); + } + log.error("Server exception occurred with status: " + status + ", error code: " + + error.getCode()); return new APIError(status, getErrorBuilder(error, data).build()); } @@ -100,8 +122,12 @@ private static ErrorResponse.Builder getErrorBuilder(ExtensionMgtConstants.Error */ public static void validateExtensionType(String extensionType) { + if (log.isDebugEnabled()) { + log.debug("Validating extension type: " + (extensionType != null ? extensionType : "null")); + } if (!ArrayUtils.contains(ExtensionManagementServiceHolder.getExtensionManager() .getExtensionTypes(), extensionType)) { + log.warn("Invalid extension type provided: " + (extensionType != null ? extensionType : "null")); throw handleClientException(Response.Status.BAD_REQUEST, ExtensionMgtConstants.ErrorMessage .ERROR_CODE_INVALID_EXTENSION_TYPE, extensionType); } diff --git a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/function/ExtensionListItemBuilder.java b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/function/ExtensionListItemBuilder.java index dcf7f58e91..4eebb59afd 100644 --- a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/function/ExtensionListItemBuilder.java +++ b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/function/ExtensionListItemBuilder.java @@ -36,6 +36,16 @@ public class ExtensionListItemBuilder implements Function { + private static final Log log = LogFactory.getLog(ExtensionResponseModelBuilder.class); + @Override public ExtensionResponseModel apply(ExtensionInfo extensionInfo) { + if (log.isDebugEnabled()) { + log.debug("Building ExtensionResponseModel for extension: " + + (extensionInfo != null ? extensionInfo.getId() : "null")); + } + + if (extensionInfo == null) { + log.warn("ExtensionInfo is null. Cannot build ExtensionResponseModel."); + return null; + } + ExtensionResponseModel responseModel = new ExtensionResponseModel(); responseModel.setId(extensionInfo.getId()); responseModel.setVersion(extensionInfo.getVersion()); @@ -41,6 +55,11 @@ public ExtensionResponseModel apply(ExtensionInfo extensionInfo) { responseModel.setTags(extensionInfo.getTags()); responseModel.setCategory(extensionInfo.getCategory()); responseModel.setType(extensionInfo.getType()); + + if (log.isDebugEnabled()) { + log.debug("Successfully built ExtensionResponseModel for extension: " + extensionInfo.getId()); + } + return responseModel; } } diff --git a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/impl/ExtensionsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/impl/ExtensionsApiServiceImpl.java index 1ad1bc44a0..9f62cccdb7 100644 --- a/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/impl/ExtensionsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.extension.management/org.wso2.carbon.identity.api.server.extension.management.v1/src/main/java/org/wso2/carbon/identity/api/server/extension/management/v1/impl/ExtensionsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.extension.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.json.JSONObject; import org.wso2.carbon.identity.api.server.extension.management.common.ExtensionManagementServiceHolder; import org.wso2.carbon.identity.api.server.extension.management.common.utils.ExtensionMgtConstants; @@ -40,6 +42,8 @@ */ public class ExtensionsApiServiceImpl implements ExtensionsApiService { + private static final Log log = LogFactory.getLog(ExtensionsApiServiceImpl.class); + /** * Get all the extensions. * @@ -48,8 +52,17 @@ public class ExtensionsApiServiceImpl implements ExtensionsApiService { @Override public Response listExtensions() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all extensions"); + } + List extensionInfoList = ExtensionManagementServiceHolder.getExtensionManager() .getExtensions(); + + if (log.isDebugEnabled()) { + log.debug("Found " + extensionInfoList.size() + " extensions"); + } + return Response.ok().entity(extensionInfoList.stream().map(new ExtensionListItemBuilder()).collect(Collectors.toList())).build(); } @@ -63,14 +76,24 @@ public Response listExtensions() { @Override public Response listExtensionsByType(String extensionType) { + if (log.isDebugEnabled()) { + log.debug("Retrieving extensions by type: " + extensionType); + } + // TODO: Add pagination support. validateExtensionType(extensionType); try { List extensionInfoList = ExtensionManagementServiceHolder.getExtensionManager() .getExtensionsByType(extensionType); + + if (log.isDebugEnabled()) { + log.debug("Found " + extensionInfoList.size() + " extensions for type: " + extensionType); + } + return Response.ok().entity(extensionInfoList.stream().map(new ExtensionListItemBuilder()).collect(Collectors.toList())).build(); } catch (ExtensionManagementException e) { + log.warn("Failed to retrieve extensions by type: " + extensionType + ". Error: " + e.getMessage()); throw ExtensionMgtUtils.handleServerException(Response.Status.INTERNAL_SERVER_ERROR, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_EXTENSIONS_BY_TYPE, extensionType); } @@ -86,16 +109,29 @@ public Response listExtensionsByType(String extensionType) { @Override public Response getExtensionInfoById(String extensionType, String extensionId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving extension info for type: " + extensionType + ", id: " + extensionId); + } + validateExtensionType(extensionType); try { ExtensionInfo extensionInfo = ExtensionManagementServiceHolder.getExtensionManager() .getExtensionByTypeAndId(extensionType, extensionId); if (extensionInfo == null) { + log.warn("Extension not found for type: " + extensionType + ", id: " + extensionId); throw ExtensionMgtUtils.handleClientException(Response.Status.NOT_FOUND, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_EXTENSION_NOT_FOUND, extensionId, extensionType); } + + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved extension info for type: " + extensionType + ", id: " + + extensionId); + } + return Response.ok().entity(new ExtensionResponseModelBuilder().apply(extensionInfo)).build(); } catch (ExtensionManagementException e) { + log.warn("Failed to retrieve extension for type: " + extensionType + ", id: " + extensionId + + ". Error: " + e.getMessage()); throw ExtensionMgtUtils.handleServerException(Response.Status.INTERNAL_SERVER_ERROR, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_EXTENSION, extensionId, extensionType); } @@ -111,16 +147,29 @@ public Response getExtensionInfoById(String extensionType, String extensionId) { @Override public Response getTemplateById(String extensionType, String extensionId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving template for extension type: " + extensionType + ", id: " + extensionId); + } + validateExtensionType(extensionType); try { JSONObject template = ExtensionManagementServiceHolder.getExtensionManager() .getExtensionTemplate(extensionType, extensionId); if (template == null) { + log.warn("Template not found for extension type: " + extensionType + ", id: " + extensionId); throw ExtensionMgtUtils.handleClientException(Response.Status.NOT_FOUND, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_TEMPLATE_NOT_FOUND, extensionId, extensionType); } + + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved template for extension type: " + extensionType + ", id: " + + extensionId); + } + return Response.ok().entity(template.toString()).build(); } catch (ExtensionManagementException e) { + log.warn("Failed to retrieve template for extension type: " + extensionType + ", id: " + extensionId + + ". Error: " + e.getMessage()); throw ExtensionMgtUtils.handleServerException(Response.Status.INTERNAL_SERVER_ERROR, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_TEMPLATE, extensionId, extensionType); } @@ -136,16 +185,29 @@ public Response getTemplateById(String extensionType, String extensionId) { @Override public Response getMetadataById(String extensionType, String extensionId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving metadata for extension type: " + extensionType + ", id: " + extensionId); + } + validateExtensionType(extensionType); try { JSONObject metadata = ExtensionManagementServiceHolder.getExtensionManager() .getExtensionMetadata(extensionType, extensionId); if (metadata == null) { + log.warn("Metadata not found for extension type: " + extensionType + ", id: " + extensionId); throw ExtensionMgtUtils.handleClientException(Response.Status.NOT_FOUND, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_METADATA_NOT_FOUND, extensionId, extensionType); } + + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved metadata for extension type: " + extensionType + ", id: " + + extensionId); + } + return Response.ok().entity(metadata.toString()).build(); } catch (ExtensionManagementException e) { + log.warn("Failed to retrieve metadata for extension type: " + extensionType + ", id: " + extensionId + + ". Error: " + e.getMessage()); throw ExtensionMgtUtils.handleServerException(Response.Status.INTERNAL_SERVER_ERROR, ExtensionMgtConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_METADATA, extensionId, extensionType); } diff --git a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.common/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/common/RemoteFetchServiceHolder.java b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.common/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/common/RemoteFetchServiceHolder.java index a2f2212264..3e41d96fb0 100755 --- a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.common/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/common/RemoteFetchServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.common/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/common/RemoteFetchServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.fetch.remote.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.remotefetch.common.RemoteFetchConfigurationService; @@ -26,6 +28,8 @@ */ public class RemoteFetchServiceHolder { + private static final Log log = LogFactory.getLog(RemoteFetchServiceHolder.class); + private RemoteFetchServiceHolder() {} private static class RemoteFetchConfigurationServiceHolder { @@ -41,6 +45,15 @@ private static class RemoteFetchConfigurationServiceHolder { */ public static RemoteFetchConfigurationService getRemoteFetchConfigurationService() { - return RemoteFetchConfigurationServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving RemoteFetchConfigurationService OSGi service."); + } + RemoteFetchConfigurationService service = RemoteFetchConfigurationServiceHolder.SERVICE; + if (service == null) { + log.warn("RemoteFetchConfigurationService OSGi service is not available."); + } else if (log.isDebugEnabled()) { + log.debug("RemoteFetchConfigurationService OSGi service retrieved successfully."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/core/ServerRemoteFetchConfigManagementService.java b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/core/ServerRemoteFetchConfigManagementService.java index 7d440d4ba3..e4ec0afcb5 100755 --- a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/core/ServerRemoteFetchConfigManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/core/ServerRemoteFetchConfigManagementService.java @@ -94,6 +94,9 @@ public ServerRemoteFetchConfigManagementService(RemoteFetchConfigurationService */ public RemoteFetchConfigurationListResponse getRemoteFetchConfigs() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all remote fetch configurations."); + } OptionalInt optionalIntLimit = OptionalInt.empty(); OptionalInt optionalIntOffset = OptionalInt.empty(); @@ -113,8 +116,12 @@ public RemoteFetchConfigurationListResponse getRemoteFetchConfigs() { */ public void deleteRemoteFetchConfig(String remoteFetchConfigurationId) { + if (log.isDebugEnabled()) { + log.debug("Attempting to delete remote fetch configuration with ID: " + remoteFetchConfigurationId); + } try { remoteFetchConfigurationService.deleteRemoteFetchConfiguration(remoteFetchConfigurationId); + log.info("Remote fetch configuration deleted successfully with ID: " + remoteFetchConfigurationId); } catch (RemoteFetchCoreException e) { throw handleRemoteFetchConfigurationException(e, RemoteFetchConfigurationConstants. ErrorMessage.ERROR_CODE_ERROR_DELETING_RF_CONFIGS, remoteFetchConfigurationId); @@ -183,12 +190,16 @@ public void updateRemoteFetchConfig(String id, */ public void triggerRemoteFetch(String remoteFetchConfigurationId) { + log.info("Triggering remote fetch for configuration with ID: " + remoteFetchConfigurationId); try { RemoteFetchConfiguration remoteFetchConfiguration = remoteFetchConfigurationService .getRemoteFetchConfiguration(remoteFetchConfigurationId); if (remoteFetchConfiguration != null) { remoteFetchConfigurationService.triggerRemoteFetch(remoteFetchConfiguration); + log.info("Remote fetch triggered successfully for configuration with ID: " + + remoteFetchConfigurationId); } else { + log.warn("Remote fetch configuration not found with ID: " + remoteFetchConfigurationId); throw handleException(Response.Status.NOT_FOUND, RemoteFetchConfigurationConstants. ErrorMessage.ERROR_CODE_RE_CONFIG_NOT_FOUND, remoteFetchConfigurationId); } @@ -206,10 +217,17 @@ public void triggerRemoteFetch(String remoteFetchConfigurationId) { */ public String addRemoteFetchConfiguration(RemoteFetchConfigurationPOSTRequest remoteFetchConfigurationPOSTRequest) { + if (log.isDebugEnabled()) { + log.debug("Adding new remote fetch configuration with name: " + + (remoteFetchConfigurationPOSTRequest != null ? + remoteFetchConfigurationPOSTRequest.getRemoteFetchName() : "null")); + } try { validatePOSTRequest(remoteFetchConfigurationPOSTRequest); - return remoteFetchConfigurationService.addRemoteFetchConfiguration(createRemoteFetchConfiguration( - remoteFetchConfigurationPOSTRequest)).getId(); + String configId = remoteFetchConfigurationService.addRemoteFetchConfiguration( + createRemoteFetchConfiguration(remoteFetchConfigurationPOSTRequest)).getId(); + log.info("Remote fetch configuration added successfully with ID: " + configId); + return configId; } catch (RemoteFetchCoreException e) { throw handleRemoteFetchConfigurationException(e, RemoteFetchConfigurationConstants.ErrorMessage. ERROR_CODE_ERROR_ADDING_RF_CONFIG, null); @@ -584,12 +602,18 @@ private StatusListItem populateDeploymentRevision(DeploymentRevision deploymentR */ public void handleWebHook(PushEventWebHookPOSTRequest pushEventWebHookPOSTRequest) { + log.info("Processing webhook request for remote fetch configuration."); try { validateWebHookRequest(pushEventWebHookPOSTRequest); String cloneURL = pushEventWebHookPOSTRequest.getRepository().getCloneUrl(); String branch = populateBranch(pushEventWebHookPOSTRequest.getRef()); List modifiedFiles = extractAddedAndModifiedFiles(pushEventWebHookPOSTRequest.getCommits()); + if (log.isDebugEnabled()) { + log.debug("Webhook processing for repository: " + cloneURL + ", branch: " + branch + + ", modified files count: " + (modifiedFiles != null ? modifiedFiles.size() : 0)); + } remoteFetchConfigurationService.handleWebHook(cloneURL, branch, modifiedFiles); + log.info("Webhook request processed successfully for repository: " + cloneURL); } catch (RemoteFetchCoreException e) { throw handleException(Response.Status.INTERNAL_SERVER_ERROR, RemoteFetchConfigurationConstants.ErrorMessage .ERROR_CODE_ERROR_WEB_HOOK_REMOTE_FETCH, null); diff --git a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/factories/ServerRemoteFetchConfigManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/factories/ServerRemoteFetchConfigManagementServiceFactory.java index be5582df64..ad66b9de31 100644 --- a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/factories/ServerRemoteFetchConfigManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/factories/ServerRemoteFetchConfigManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.fetch.remote.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchServiceHolder; import org.wso2.carbon.identity.api.server.fetch.remote.v1.core.ServerRemoteFetchConfigManagementService; import org.wso2.carbon.identity.remotefetch.common.RemoteFetchConfigurationService; @@ -27,17 +29,23 @@ */ public class ServerRemoteFetchConfigManagementServiceFactory { + private static final Log log = LogFactory.getLog(ServerRemoteFetchConfigManagementServiceFactory.class); private static final ServerRemoteFetchConfigManagementService SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing ServerRemoteFetchConfigManagementService factory."); + } RemoteFetchConfigurationService remoteFetchConfigurationService = RemoteFetchServiceHolder .getRemoteFetchConfigurationService(); if (remoteFetchConfigurationService == null) { + log.error("RemoteFetchConfigurationService is not available from OSGi context."); throw new IllegalStateException("RemoteFetchConfigurationService is not available from OSGi context."); } SERVICE = new ServerRemoteFetchConfigManagementService(remoteFetchConfigurationService); + log.info("ServerRemoteFetchConfigManagementService factory initialized successfully."); } /** diff --git a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/impl/RemoteFetchApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/impl/RemoteFetchApiServiceImpl.java index cf389ad907..796bf2c97c 100644 --- a/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/impl/RemoteFetchApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.fetch.remote/org.wso2.carbon.identity.api.server.fetch.remote.v1/src/main/java/org/wso2/carbon/identity/api/server/fetch/remote/v1/impl/RemoteFetchApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.fetch.remote.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.Constants; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.fetch.remote.common.RemoteFetchConfigurationConstants; @@ -37,6 +39,7 @@ */ public class RemoteFetchApiServiceImpl implements RemoteFetchApiService { + private static final Log log = LogFactory.getLog(RemoteFetchApiServiceImpl.class); private final ServerRemoteFetchConfigManagementService serverRemoteFetchConfigManagementService; public RemoteFetchApiServiceImpl() { @@ -52,27 +55,43 @@ public RemoteFetchApiServiceImpl() { @Override public Response addRemoteFetch(RemoteFetchConfigurationPOSTRequest remoteFetchConfigurationPOSTRequest) { + if (log.isDebugEnabled()) { + log.debug("Adding remote fetch configuration with name: " + + (remoteFetchConfigurationPOSTRequest != null ? + remoteFetchConfigurationPOSTRequest.getRemoteFetchName() : "null")); + } String remoteFetchConfigurationId = serverRemoteFetchConfigManagementService .addRemoteFetchConfiguration(remoteFetchConfigurationPOSTRequest); + log.info("Remote fetch configuration added successfully with ID: " + remoteFetchConfigurationId); return Response.created(getResourceLocation(remoteFetchConfigurationId)).build(); } @Override public Response deleteRemoteFetch(String id) { + if (log.isDebugEnabled()) { + log.debug("Deleting remote fetch configuration with ID: " + id); + } serverRemoteFetchConfigManagementService.deleteRemoteFetchConfig(id); + log.info("Remote fetch configuration deleted successfully with ID: " + id); return Response.noContent().build(); } @Override public Response getRemoteFetch(String id) { + if (log.isDebugEnabled()) { + log.debug("Retrieving remote fetch configuration with ID: " + id); + } return Response.ok().entity(serverRemoteFetchConfigManagementService.getRemoteFetchConfig(id)).build(); } @Override public Response getRemoteFetchConfigs() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all remote fetch configurations."); + } RemoteFetchConfigurationListResponse remoteFetchConfigurationListResponse = serverRemoteFetchConfigManagementService.getRemoteFetchConfigs(); return Response.ok().entity(remoteFetchConfigurationListResponse).build(); @@ -81,6 +100,9 @@ public Response getRemoteFetchConfigs() { @Override public Response getStatus(String id) { + if (log.isDebugEnabled()) { + log.debug("Retrieving status for remote fetch configuration with ID: " + id); + } StatusListResponse statusListResponse = serverRemoteFetchConfigManagementService.getStatus(id); return Response.ok().entity(statusListResponse).build(); } @@ -88,14 +110,23 @@ public Response getStatus(String id) { @Override public Response handleWebHook(PushEventWebHookPOSTRequest pushEventWebHookPOSTRequest) { + log.info("Received webhook request for remote fetch configuration."); + if (log.isDebugEnabled()) { + log.debug("Processing webhook request from repository: " + + (pushEventWebHookPOSTRequest != null && pushEventWebHookPOSTRequest.getRepository() != null ? + pushEventWebHookPOSTRequest.getRepository().getCloneUrl() : "unknown")); + } serverRemoteFetchConfigManagementService.handleWebHook(pushEventWebHookPOSTRequest); + log.info("Webhook request processed successfully."); return Response.accepted().build(); } @Override public Response triggerRemoteFetch(String id) { + log.info("Triggering remote fetch for configuration with ID: " + id); serverRemoteFetchConfigManagementService.triggerRemoteFetch(id); + log.info("Remote fetch triggered successfully for configuration with ID: " + id); return Response.accepted().build(); } @@ -103,7 +134,11 @@ public Response triggerRemoteFetch(String id) { public Response updateRemoteFetch(String id, RemoteFetchConfigurationPatchRequest remoteFetchConfigurationPatchRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating remote fetch configuration with ID: " + id); + } serverRemoteFetchConfigManagementService.updateRemoteFetchConfig(id, remoteFetchConfigurationPatchRequest); + log.info("Remote fetch configuration updated successfully with ID: " + id); return Response.ok().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.common/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/common/FlowExecutionServiceHolder.java b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.common/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/common/FlowExecutionServiceHolder.java index de15a5e001..143ca03f23 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.common/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/common/FlowExecutionServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.common/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/common/FlowExecutionServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.execution.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.flow.execution.engine.FlowExecutionService; import org.wso2.carbon.identity.flow.mgt.FlowMgtService; @@ -28,6 +30,8 @@ */ public class FlowExecutionServiceHolder { + private static final Log log = LogFactory.getLog(FlowExecutionServiceHolder.class); + private FlowExecutionServiceHolder() { } @@ -60,7 +64,14 @@ private static class IdentityGovernanceServiceHolder { */ public static FlowExecutionService getInstance() { - return FlowExecutionServiceHolderInstance.INSTANCE; + if (log.isDebugEnabled()) { + log.debug("Retrieving FlowExecutionService instance."); + } + FlowExecutionService service = FlowExecutionServiceHolderInstance.INSTANCE; + if (service == null && log.isWarnEnabled()) { + log.warn("FlowExecutionService instance is not available."); + } + return service; } /** @@ -70,7 +81,14 @@ public static FlowExecutionService getInstance() { */ public static FlowMgtService getFlowMgtService() { - return FlowMgtServiceHolderInstance.INSTANCE; + if (log.isDebugEnabled()) { + log.debug("Retrieving FlowMgtService instance."); + } + FlowMgtService service = FlowMgtServiceHolderInstance.INSTANCE; + if (service == null && log.isWarnEnabled()) { + log.warn("FlowMgtService instance is not available."); + } + return service; } /** @@ -80,6 +98,13 @@ public static FlowMgtService getFlowMgtService() { */ public static IdentityGovernanceService getIdentityGovernanceService() { - return IdentityGovernanceServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving IdentityGovernanceService instance."); + } + IdentityGovernanceService service = IdentityGovernanceServiceHolder.SERVICE; + if (service == null && log.isWarnEnabled()) { + log.warn("IdentityGovernanceService instance is not available."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/core/FlowExecutionServiceCore.java b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/core/FlowExecutionServiceCore.java index 768c951a3c..a3145f7347 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/core/FlowExecutionServiceCore.java +++ b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/core/FlowExecutionServiceCore.java @@ -21,6 +21,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.server.flow.execution.v1.FlowExecutionRequest; import org.wso2.carbon.identity.api.server.flow.execution.v1.FlowExecutionResponse; @@ -38,11 +40,15 @@ */ public class FlowExecutionServiceCore { + private static final Log LOG = LogFactory.getLog(FlowExecutionServiceCore.class); private final FlowExecutionService flowExecutionService; public FlowExecutionServiceCore(FlowExecutionService flowExecutionService) { this.flowExecutionService = flowExecutionService; + if (LOG.isDebugEnabled()) { + LOG.debug("FlowExecutionServiceCore initialized with FlowExecutionService."); + } } /** @@ -54,8 +60,21 @@ public FlowExecutionServiceCore(FlowExecutionService flowExecutionService) { public FlowExecutionResponse processFlowExecution(FlowExecutionRequest flowExecutionRequest) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Processing flow execution for tenant: " + tenantDomain + + ", flowType: " + (flowExecutionRequest != null ? flowExecutionRequest.getFlowType() : "null")); + } + + if (flowExecutionRequest == null) { + LOG.warn("FlowExecutionRequest is null. Cannot process flow execution."); + throw new IllegalArgumentException("FlowExecutionRequest cannot be null"); + } + try { if (StringUtils.isBlank(flowExecutionRequest.getFlowId())) { + if (LOG.isDebugEnabled()) { + LOG.debug("Flow ID is blank, validating flow initiation."); + } Utils.validateFlowInitiation(flowExecutionRequest); } @@ -69,9 +88,16 @@ public FlowExecutionResponse processFlowExecution(FlowExecutionRequest flowExecu FlowExecutionResponse flowExecutionResponse = new FlowExecutionResponse(); if (flowExecutionStep == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Flow execution step is null, returning empty response."); + } return flowExecutionResponse; } + if (LOG.isDebugEnabled()) { + LOG.debug("Flow execution completed successfully for flowId: " + flowExecutionStep.getFlowId() + + ", flowStatus: " + flowExecutionStep.getFlowStatus()); + } return flowExecutionResponse .flowId(flowExecutionStep.getFlowId()) .flowType(flowExecutionStep.getFlowType()) diff --git a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/factories/FlowExecutionServiceFactory.java b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/factories/FlowExecutionServiceFactory.java index e0f6ff4706..2e8a1aba32 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/factories/FlowExecutionServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/factories/FlowExecutionServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.execution.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.flow.execution.common.FlowExecutionServiceHolder; import org.wso2.carbon.identity.api.server.flow.execution.v1.core.FlowExecutionServiceCore; import org.wso2.carbon.identity.flow.execution.engine.FlowExecutionService; @@ -27,14 +29,22 @@ */ public class FlowExecutionServiceFactory { + private static final Log LOG = LogFactory.getLog(FlowExecutionServiceFactory.class); private static final FlowExecutionServiceCore SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing FlowExecutionServiceFactory."); + } FlowExecutionService flowExecutionService = FlowExecutionServiceHolder.getInstance(); if (flowExecutionService == null) { + LOG.error("FlowExecutionService is not available from OSGi context."); throw new IllegalStateException("UserRegistrationFlowService is not available from OSGi context."); } SERVICE = new FlowExecutionServiceCore(flowExecutionService); + if (LOG.isDebugEnabled()) { + LOG.debug("FlowExecutionServiceFactory initialized successfully."); + } } /** @@ -44,6 +54,9 @@ public class FlowExecutionServiceFactory { */ public static FlowExecutionServiceCore getFlowExecutionService() { + if (LOG.isDebugEnabled()) { + LOG.debug("Returning FlowExecutionServiceCore instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/impl/FlowApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/impl/FlowApiServiceImpl.java index d6809fa140..08fa865964 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/impl/FlowApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/impl/FlowApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.execution.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.flow.execution.v1.FlowApiService; import org.wso2.carbon.identity.api.server.flow.execution.v1.FlowExecutionRequest; import org.wso2.carbon.identity.api.server.flow.execution.v1.core.FlowExecutionServiceCore; @@ -30,16 +32,30 @@ */ public class FlowApiServiceImpl implements FlowApiService { + private static final Log LOG = LogFactory.getLog(FlowApiServiceImpl.class); private final FlowExecutionServiceCore flowExecutionServiceCore; public FlowApiServiceImpl() { this.flowExecutionServiceCore = FlowExecutionServiceFactory.getFlowExecutionService(); + if (LOG.isDebugEnabled()) { + LOG.debug("FlowApiServiceImpl initialized successfully."); + } } @Override public Response flowExecutePost(FlowExecutionRequest flowExecutionRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing flow execution request for flowType: " + + (flowExecutionRequest != null ? flowExecutionRequest.getFlowType() : "null")); + } + + if (flowExecutionRequest == null) { + LOG.warn("FlowExecutionRequest is null. Cannot process flow execution."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + return Response.ok() .entity(flowExecutionServiceCore.processFlowExecution((flowExecutionRequest))) .build(); diff --git a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/utils/Utils.java b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/utils/Utils.java index ac124e1bc2..16fac8f97b 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/utils/Utils.java +++ b/components/org.wso2.carbon.identity.api.server.flow.execution/org.wso2.carbon.identity.api.server.flow.execution.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/execution/v1/utils/Utils.java @@ -169,6 +169,9 @@ public static FlowExecutionErrorDTO getError(String errorCode, String errorMessa */ public static void isSelfRegistrationEnabled(String tenantDomain) { + if (LOG.isDebugEnabled()) { + LOG.debug("Checking if self registration is enabled for tenant: " + tenantDomain); + } try { IdentityGovernanceService identityGovernanceService = FlowExecutionServiceHolder.getIdentityGovernanceService(); @@ -195,6 +198,9 @@ public static void isSelfRegistrationEnabled(String tenantDomain) { */ public static void isDynamicRegistrationPortalEnabled(String tenantDomain) { + if (LOG.isDebugEnabled()) { + LOG.debug("Checking if dynamic registration portal is enabled for tenant: " + tenantDomain); + } try { IdentityGovernanceService identityGovernanceService = FlowExecutionServiceHolder.getIdentityGovernanceService(); @@ -225,6 +231,9 @@ public static void isDynamicRegistrationPortalEnabled(String tenantDomain) { */ public static boolean isShowUsernameUnavailabilityEnabled(String tenantDomain) { + if (LOG.isDebugEnabled()) { + LOG.debug("Checking if show username unavailability is enabled for tenant: " + tenantDomain); + } try { IdentityGovernanceService identityGovernanceService = FlowExecutionServiceHolder.getIdentityGovernanceService(); @@ -292,8 +301,14 @@ public static Data convertToData(DataDTO dataDTO, String type) { public static void validateFlowInitiation(FlowExecutionRequest flowExecutionRequest) { String flowType = flowExecutionRequest.getFlowType(); + if (LOG.isDebugEnabled()) { + LOG.debug("Validating flow initiation request for flowType: " + flowType); + } if (StringUtils.isBlank(flowType) || Arrays.stream(Constants.FlowTypes.values()) .noneMatch(type -> type.name().equals(flowType))) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid flow type provided: " + flowType); + } throw Utils.handleFlowException(new FlowEngineClientException( ERROR_CODE_INVALID_FLOW_TYPE.getCode(), ERROR_CODE_INVALID_FLOW_TYPE.getMessage(), @@ -324,10 +339,17 @@ public static void validateFlowInitiation(FlowExecutionRequest flowExecutionRequ */ public static boolean isOrchestrationEnabled(String flowType, String tenantDomain) { + if (LOG.isDebugEnabled()) { + LOG.debug("Checking if orchestration is enabled for flowType: " + flowType + ", tenant: " + tenantDomain); + } try { FlowConfigDTO flowConfig = FlowExecutionServiceHolder.getFlowMgtService().getFlowConfig( flowType, IdentityTenantUtil.getTenantId(tenantDomain)); - return flowConfig.getIsEnabled(); + boolean isEnabled = flowConfig.getIsEnabled(); + if (LOG.isDebugEnabled()) { + LOG.debug("Orchestration enabled status for flowType " + flowType + ": " + isEnabled); + } + return isEnabled; } catch (FlowMgtFrameworkException e) { throw handleFlowException(new FlowEngineServerException( ERROR_CODE_GET_FLOW_CONFIG.getCode(), diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.common/src/main/java/org/wso2/carbon/identity/api/server/flow/management/common/FlowMgtServiceHolder.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.common/src/main/java/org/wso2/carbon/identity/api/server/flow/management/common/FlowMgtServiceHolder.java index 4329c86179..c3db91e652 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.common/src/main/java/org/wso2/carbon/identity/api/server/flow/management/common/FlowMgtServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.common/src/main/java/org/wso2/carbon/identity/api/server/flow/management/common/FlowMgtServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.management.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.flow.mgt.FlowAIService; import org.wso2.carbon.identity.flow.mgt.FlowMgtService; @@ -29,6 +31,8 @@ */ public class FlowMgtServiceHolder { + private static final Log log = LogFactory.getLog(FlowMgtServiceHolder.class); + private FlowMgtServiceHolder() { } @@ -66,7 +70,14 @@ private static class FlowAIServiceHolder { */ public static FlowMgtService getMgtService() { - return FlowMgtServiceHolderInstance.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving FlowMgtService OSGi service."); + } + FlowMgtService flowMgtService = FlowMgtServiceHolderInstance.SERVICE; + if (flowMgtService == null) { + log.warn("FlowMgtService OSGi service is not available."); + } + return flowMgtService; } /** @@ -76,7 +87,14 @@ public static FlowMgtService getMgtService() { */ public static IdentityGovernanceService getIdentityGovernanceService() { - return IdentityGovernanceServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving IdentityGovernanceService OSGi service."); + } + IdentityGovernanceService identityGovernanceService = IdentityGovernanceServiceHolder.SERVICE; + if (identityGovernanceService == null) { + log.warn("IdentityGovernanceService OSGi service is not available."); + } + return identityGovernanceService; } /** @@ -86,7 +104,14 @@ public static IdentityGovernanceService getIdentityGovernanceService() { */ public static IdpManager getIdpManager() { - return IdpManagerHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving IdpManager OSGi service."); + } + IdpManager idpManager = IdpManagerHolder.SERVICE; + if (idpManager == null) { + log.warn("IdpManager OSGi service is not available."); + } + return idpManager; } /** @@ -96,6 +121,13 @@ public static IdpManager getIdpManager() { */ public static FlowAIService getFlowAIService() { - return FlowAIServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving FlowAIService OSGi service."); + } + FlowAIService flowAIService = FlowAIServiceHolder.SERVICE; + if (flowAIService == null) { + log.warn("FlowAIService OSGi service is not available."); + } + return flowAIService; } } diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/FlowAIServiceCore.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/FlowAIServiceCore.java index a477562f1b..3b52d365b3 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/FlowAIServiceCore.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/FlowAIServiceCore.java @@ -80,6 +80,9 @@ public FlowGenerateResponse generateFlow(FlowGenerateRequest flowGenerateRequest */ public FlowGenerateStatus getFlowGenerationStatus(String operationId) { + if (log.isDebugEnabled()) { + log.debug("Getting flow generation status for operation ID: " + operationId); + } try { FlowGenerationStatusDTO responseDTO = FlowMgtServiceHolder.getFlowAIService() .getFlowGenerationStatus(operationId); @@ -89,6 +92,7 @@ public FlowGenerateStatus getFlowGenerationStatus(String operationId) { .generatingFlow(responseDTO.isGeneratingFlow()) .completed(responseDTO.isCompleted()); } catch (FlowMgtFrameworkException e) { + log.error("Error getting flow generation status for operation ID: " + operationId, e); throw Utils.handleFlowMgtException(e); } } @@ -126,6 +130,7 @@ public FlowGenerateResult getFlowGenerationResult(String operationId) { } return flowGenerateResult; } catch (FlowMgtFrameworkException e) { + log.error("Error retrieving flow generation result for operation ID: " + operationId, e); throw Utils.handleFlowMgtException(e); } } diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/ServerFlowMgtService.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/ServerFlowMgtService.java index f8741fe532..c95cccd4db 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/ServerFlowMgtService.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/core/ServerFlowMgtService.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.management.v1.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.server.flow.management.v1.FlowConfig; import org.wso2.carbon.identity.api.server.flow.management.v1.FlowConfigPatchModel; @@ -50,6 +52,7 @@ */ public class ServerFlowMgtService { + private static final Log log = LogFactory.getLog(ServerFlowMgtService.class); private final FlowMgtService flowMgtService; public ServerFlowMgtService(FlowMgtService flowMgtService) { @@ -64,6 +67,9 @@ public ServerFlowMgtService(FlowMgtService flowMgtService) { */ public FlowResponse getFlow(String flowType) { + if (log.isDebugEnabled()) { + log.debug("Retrieving flow for type: " + flowType); + } FlowDTO flowDTO; try { Utils.validateFlowType(flowType); @@ -71,12 +77,19 @@ public FlowResponse getFlow(String flowType) { .getFlow(flowType, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); FlowResponse flowResponse = new FlowResponse(); if (flowDTO == null) { + if (log.isDebugEnabled()) { + log.debug("No flow found for type: " + flowType); + } return flowResponse; } flowResponse.steps(flowDTO.getSteps().stream().map(Utils::convertToStep) .collect(Collectors.toList())); + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved flow for type: " + flowType); + } return flowResponse; } catch (FlowMgtFrameworkException e) { + log.error("Error retrieving flow for type: " + flowType, e); throw Utils.handleFlowMgtException(e); } } @@ -101,6 +114,16 @@ public FlowMetaResponse getFlowMeta(String flowType) { */ public void updateFlow(FlowRequest flowRequest) { + String flowType = flowRequest != null ? flowRequest.getFlowType() : null; + if (log.isDebugEnabled()) { + log.debug("Updating flow for type: " + flowType); + } + + if (flowRequest == null) { + log.warn("FlowRequest is null. Cannot update flow."); + throw new IllegalArgumentException("FlowRequest cannot be null"); + } + try { Utils.validateFlowType(flowRequest.getFlowType()); validateFlow(flowRequest.getFlowType(), flowRequest.getSteps()); @@ -110,7 +133,9 @@ public void updateFlow(FlowRequest flowRequest) { flowDTO.setFlowType(flowRequest.getFlowType()); flowMgtService.updateFlow(flowDTO, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + log.info("Flow updated successfully for type: " + flowType); } catch (FlowMgtFrameworkException e) { + log.error("Error updating flow for type: " + flowType, e); throw Utils.handleFlowMgtException(e); } } @@ -158,6 +183,16 @@ public FlowConfig getFlowConfigForFlow(String flowType) { */ public FlowConfig updateFlowConfig(FlowConfigPatchModel flowConfigPatchModel) { + String flowType = flowConfigPatchModel != null ? flowConfigPatchModel.getFlowType() : null; + if (log.isDebugEnabled()) { + log.debug("Updating flow config for type: " + flowType); + } + + if (flowConfigPatchModel == null) { + log.warn("FlowConfigPatchModel is null. Cannot update flow config."); + throw new IllegalArgumentException("FlowConfigPatchModel cannot be null"); + } + try { Utils.validateFlowType(flowConfigPatchModel.getFlowType()); FlowConfigDTO existingFlowConfig = flowMgtService.getFlowConfig( @@ -176,8 +211,10 @@ public FlowConfig updateFlowConfig(FlowConfigPatchModel flowConfigPatchModel) { FlowConfigDTO updatedFlowConfig = flowMgtService.updateFlowConfig(Utils.convertToFlowConfigDTO(flowConfigPatchModel), PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + log.info("Flow config updated successfully for type: " + flowType); return Utils.convertToFlowConfig(updatedFlowConfig); } catch (FlowMgtFrameworkException e) { + log.error("Error updating flow config for type: " + flowType, e); throw Utils.handleFlowMgtException(e); } } @@ -207,6 +244,9 @@ private void validateFlow(String flowType, List flowSteps) { */ private AbstractMetaResponseHandler resolveHandler(String flowType) { + if (log.isDebugEnabled()) { + log.debug("Resolving handler for flow type: " + flowType); + } switch (Constants.FlowTypes.valueOf(flowType)) { case REGISTRATION: return new RegistrationFlowMetaHandler(); @@ -215,6 +255,7 @@ private AbstractMetaResponseHandler resolveHandler(String flowType) { case INVITED_USER_REGISTRATION: return new AskPasswordFlowMetaHandler(); default: + log.error("No handler available for flow type: " + flowType); throw new IllegalStateException("Unhandled flow type: " + flowType); } } diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/FlowAIServiceFactory.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/FlowAIServiceFactory.java index bd62ebbb41..f1ad20dad3 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/FlowAIServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/FlowAIServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.flow.management.v1.core.FlowAIServiceCore; /** @@ -25,10 +27,13 @@ */ public class FlowAIServiceFactory { + private static final Log log = LogFactory.getLog(FlowAIServiceFactory.class); private static final FlowAIServiceCore SERVICE; static { + log.info("Initializing FlowAIService factory."); SERVICE = new FlowAIServiceCore(); + log.info("FlowAIService factory initialized successfully."); } /** diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/ServerFlowMgtServiceFactory.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/ServerFlowMgtServiceFactory.java index b1708b11a4..3df1602e49 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/ServerFlowMgtServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/factories/ServerFlowMgtServiceFactory.java @@ -18,7 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.management.v1.factories; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.flow.management.common.FlowMgtServiceHolder; import org.wso2.carbon.identity.api.server.flow.management.v1.core.ServerFlowMgtService; import org.wso2.carbon.identity.flow.mgt.FlowMgtService; @@ -28,17 +29,21 @@ */ public class ServerFlowMgtServiceFactory { + private static final Log log = LogFactory.getLog(ServerFlowMgtServiceFactory.class); private static final ServerFlowMgtService SERVICE; static { + log.info("Initializing ServerFlowMgtService factory."); FlowMgtService flowMgtService = FlowMgtServiceHolder .getMgtService(); if (flowMgtService == null) { + log.error("FlowMgtService is not available from OSGi context."); throw new IllegalStateException("FlowMgtService is not available from OSGi context."); } SERVICE = new ServerFlowMgtService(flowMgtService); + log.info("ServerFlowMgtService factory initialized successfully."); } /** diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/impl/FlowApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/impl/FlowApiServiceImpl.java index 5f519d8aa6..068ab4c04d 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/impl/FlowApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/impl/FlowApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.flow.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.flow.management.v1.FlowApiService; import org.wso2.carbon.identity.api.server.flow.management.v1.FlowConfig; import org.wso2.carbon.identity.api.server.flow.management.v1.FlowConfigPatchModel; @@ -42,15 +44,19 @@ */ public class FlowApiServiceImpl implements FlowApiService { + private static final Log log = LogFactory.getLog(FlowApiServiceImpl.class); ServerFlowMgtService flowMgtService; FlowAIServiceCore flowAIServiceCore; public FlowApiServiceImpl() { try { + log.info("Initializing Flow API service implementation."); this.flowMgtService = ServerFlowMgtServiceFactory.getFlowMgtService(); this.flowAIServiceCore = FlowAIServiceFactory.getFlowAIService(); + log.info("Flow API service implementation initialized successfully."); } catch (IllegalStateException e) { + log.error("Failed to initialize flow management service.", e); throw new RuntimeException("Error occurred while initiating flow management service.", e); } } @@ -58,6 +64,16 @@ public FlowApiServiceImpl() { @Override public Response generateFlow(FlowGenerateRequest flowGenerateRequest) { + if (log.isDebugEnabled()) { + log.debug("Generating flow for type: " + + (flowGenerateRequest != null ? flowGenerateRequest.getFlowType() : null)); + } + + if (flowGenerateRequest == null) { + log.warn("FlowGenerateRequest is null. Cannot generate flow."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + FlowGenerateResponse flowResponse = flowAIServiceCore.generateFlow(flowGenerateRequest); return Response.ok().entity(flowResponse).build(); } @@ -65,6 +81,9 @@ public Response generateFlow(FlowGenerateRequest flowGenerateRequest) { @Override public Response getFlow(String flowType) { + if (log.isDebugEnabled()) { + log.debug("Retrieving flow for type: " + flowType); + } FlowResponse flow = flowMgtService.getFlow(flowType); return Response.ok().entity(flow).build(); } @@ -107,14 +126,36 @@ public Response getFlowMeta(String flowType) { @Override public Response updateFlow(FlowRequest flowRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating flow for type: " + + (flowRequest != null ? flowRequest.getFlowType() : null)); + } + + if (flowRequest == null) { + log.warn("FlowRequest is null. Cannot update flow."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + flowMgtService.updateFlow(flowRequest); + log.info("Flow updated successfully for type: " + flowRequest.getFlowType()); return Response.ok().build(); } @Override public Response updateFlowConfig(FlowConfigPatchModel flowConfigPatchModel) { + if (log.isDebugEnabled()) { + log.debug("Updating flow config for type: " + + (flowConfigPatchModel != null ? flowConfigPatchModel.getFlowType() : null)); + } + + if (flowConfigPatchModel == null) { + log.warn("FlowConfigPatchModel is null. Cannot update flow config."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + FlowConfig flowConfig = flowMgtService.updateFlowConfig(flowConfigPatchModel); + log.info("Flow config updated successfully for type: " + flowConfigPatchModel.getFlowType()); return Response.ok().entity(flowConfig).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/utils/Utils.java b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/utils/Utils.java index da3b966a95..f62c1ee2d7 100644 --- a/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/utils/Utils.java +++ b/components/org.wso2.carbon.identity.api.server.flow.management/org.wso2.carbon.identity.api.server.flow.management.v1/src/main/java/org/wso2/carbon/identity/api/server/flow/management/v1/utils/Utils.java @@ -407,6 +407,9 @@ private static void traverseComponents(List components, Set e */ public static void validateIdentifiers(AbstractMetaResponseHandler metaResponseHandler, Set identifiers) { + if (LOG.isDebugEnabled()) { + LOG.debug("Validating identifiers: " + identifiers); + } List required = metaResponseHandler.getRequiredInputFields(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); boolean alternativeLoginStatus = Utils.getGovernanceConfig(tenantDomain, @@ -422,6 +425,7 @@ public static void validateIdentifiers(AbstractMetaResponseHandler metaResponseH boolean hasIdentity = identifiers.stream().anyMatch(identityIdentifiers::contains); if (needsIdentity && !hasIdentity) { + LOG.warn("Required identity identifier missing for identifiers: " + identifiers); throw handleFlowMgtException(new FlowMgtClientException( FlowEndpointConstants.ErrorMessages.ERROR_CODE_MISSING_IDENTIFIER.getCode(), FlowEndpointConstants.ErrorMessages.ERROR_CODE_MISSING_IDENTIFIER.getMessage(), @@ -435,6 +439,8 @@ public static void validateIdentifiers(AbstractMetaResponseHandler metaResponseH remainingRequired.removeAll(identityIdentifiers); if (!identifiers.containsAll(remainingRequired)) { + LOG.warn("Missing required identifiers: " + remainingRequired + + ", provided: " + identifiers); throw handleFlowMgtException(new FlowMgtClientException( FlowEndpointConstants.ErrorMessages.ERROR_CODE_MISSING_IDENTIFIER.getCode(), FlowEndpointConstants.ErrorMessages.ERROR_CODE_MISSING_IDENTIFIER.getMessage(), @@ -450,7 +456,11 @@ public static void validateIdentifiers(AbstractMetaResponseHandler metaResponseH */ public static void validateExecutors(AbstractMetaResponseHandler metaResponseHandler, Set executors) { + if (LOG.isDebugEnabled()) { + LOG.debug("Validating executors: " + executors); + } if (!new HashSet<>(metaResponseHandler.getSupportedExecutors()).containsAll(executors)) { + LOG.warn("Unsupported executors found: " + executors); throw handleFlowMgtException(new FlowMgtClientException( ERROR_CODE_UNSUPPORTED_EXECUTOR.getCode(), ERROR_CODE_UNSUPPORTED_EXECUTOR.getMessage(), @@ -480,8 +490,12 @@ public static FlowConfigDTO convertToFlowConfigDTO(FlowConfigPatchModel flowConf public static void validateFlowType(String value) { + if (LOG.isDebugEnabled()) { + LOG.debug("Validating flow type: " + value); + } if (StringUtils.isBlank(value) || Arrays.stream(Constants.FlowTypes.values()) .noneMatch(type -> type.name().equals(value))) { + LOG.warn("Invalid flow type provided: " + value); throw Utils.handleFlowMgtException(new FlowMgtClientException( FlowEndpointConstants.ErrorMessages.ERROR_CODE_INVALID_FLOW_TYPE.getCode(), FlowEndpointConstants.ErrorMessages.ERROR_CODE_INVALID_FLOW_TYPE.getMessage(), diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java index 000557142c..3bc12135c1 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.identity.governance.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.governance.IdentityGovernanceService; @@ -26,6 +28,8 @@ */ public class GovernanceDataHolder { + private static final Log log = LogFactory.getLog(GovernanceDataHolder.class); + private GovernanceDataHolder() {} private static class IdentityGovernanceServiceHolder { @@ -40,6 +44,13 @@ private static class IdentityGovernanceServiceHolder { */ public static IdentityGovernanceService getIdentityGovernanceService() { - return IdentityGovernanceServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving IdentityGovernanceService OSGi service."); + } + IdentityGovernanceService service = IdentityGovernanceServiceHolder.SERVICE; + if (service == null) { + log.warn("IdentityGovernanceService OSGi service is not available."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java index 2acb2ae1a0..e16bd2533b 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java @@ -76,6 +76,9 @@ public class ServerIdentityGovernanceService { public ServerIdentityGovernanceService(IdentityGovernanceService identityGovernanceService) { this.identityGovernanceService = identityGovernanceService; + if (LOG.isDebugEnabled()) { + LOG.debug("ServerIdentityGovernanceService initialized successfully."); + } } /** @@ -93,6 +96,9 @@ public List getGovernanceConnectors(Integer limit, Integer offset try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving categorized connector list for tenant: " + tenantDomain); + } Map> connectorConfigs = identityGovernanceService.getCategorizedConnectorListWithConfigs(tenantDomain); @@ -102,6 +108,7 @@ public List getGovernanceConnectors(Integer limit, Integer offset GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CATEGORIES; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to retrieve governance connector categories.", e); throw handleException(e, errorEnum, status); } } @@ -134,10 +141,16 @@ public List getGovernanceConnectorsByCategory(String categoryId) { try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String category = new String(Base64.getUrlDecoder().decode(categoryId), StandardCharsets.UTF_8); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving connectors for category: " + category + " in tenant: " + tenantDomain); + } List connectorConfigs = identityGovernanceService.getConnectorListWithConfigsByCategory(tenantDomain, category); if (connectorConfigs.size() == 0) { + if (LOG.isDebugEnabled()) { + LOG.debug("No connectors found for category: " + category); + } throw handleNotFoundError(categoryId, GovernanceConstants.ErrorMessage.ERROR_CODE_CATEGORY_NOT_FOUND); } @@ -147,6 +160,7 @@ public List getGovernanceConnectorsByCategory(String categoryId) { GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CATEGORY; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to retrieve governance connectors by category.", e); throw handleException(e, errorEnum, status); } } @@ -163,15 +177,24 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String connectorName = new String(Base64.getUrlDecoder().decode(connectorId), StandardCharsets.UTF_8); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving connector: " + connectorName + " for tenant: " + tenantDomain); + } ConnectorConfig connectorConfig = identityGovernanceService.getConnectorWithConfigs(tenantDomain, connectorName); if (connectorConfig == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Connector not found: " + connectorName); + } throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND); } String categoryIdFound = Base64.getUrlEncoder() .withoutPadding() .encodeToString(connectorConfig.getCategory().getBytes(StandardCharsets.UTF_8)); if (!categoryId.equals(categoryIdFound)) { + if (LOG.isDebugEnabled()) { + LOG.debug("Connector category mismatch. Expected: " + categoryId + ", Found: " + categoryIdFound); + } throw handleNotFoundError(connectorId, GovernanceConstants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND); } @@ -181,6 +204,7 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to retrieve governance connector.", e); throw handleException(e, errorEnum, status); } } @@ -194,6 +218,10 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId public List getConfigPreference(List preferenceSearchAttribute) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving config preferences for " + preferenceSearchAttribute.size() + + " attributes in tenant: " + tenantDomain); + } List preferenceRespList = new ArrayList<>(); for (PreferenceSearchAttribute prefSearchAttr : preferenceSearchAttribute) { String connectorName = prefSearchAttr.getConnectorName(); @@ -214,6 +242,7 @@ public List getConfigPreference(List GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR_PREFERENCES; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to retrieve connector preferences.", e); throw handleException(e, errorEnum, status); } } @@ -293,6 +322,9 @@ public void updateGovernanceConnectorProperty(String categoryId, String connecto try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating governance connector property for tenant: " + tenantDomain); + } ConnectorRes connector = getGovernanceConnector(categoryId, connectorId); if (connector == null) { @@ -317,6 +349,9 @@ public void updateGovernanceConnectorProperty(String categoryId, String connecto } } identityGovernanceService.updateConfiguration(tenantDomain, configurationDetails); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully updated connector configuration for tenant: " + tenantDomain); + } } catch (IdentityGovernanceClientException e) { throw handleBadRequestError(GovernanceConstants.ErrorMessage.ERROR_CODE_INVALID_CONNECTOR_CONFIGURATION, e.getMessage()); @@ -324,6 +359,7 @@ public void updateGovernanceConnectorProperty(String categoryId, String connecto GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_CONNECTOR_PROPERTY; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to update governance connector property.", e); throw handleException(e, errorEnum, status); } } @@ -340,6 +376,9 @@ public void updateGovernanceConnectorProperties(String categoryId, try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating multiple governance connector properties for tenant: " + tenantDomain); + } // Check whether the category ID exists. CategoryRes category = getGovernanceConnectorCategory(categoryId); @@ -380,11 +419,15 @@ public void updateGovernanceConnectorProperties(String categoryId, } identityGovernanceService.updateConfiguration(tenantDomain, configurationDetails); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully updated multiple connector configurations for tenant: " + tenantDomain); + } } catch (IdentityGovernanceException e) { GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_CONNECTOR_PROPERTY; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to update multiple governance connector properties.", e); throw handleException(e, errorEnum, status); } } @@ -401,6 +444,9 @@ public void revertGovernanceConnectorProperties(String categoryId, String connec try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Reverting governance connector properties for tenant: " + tenantDomain); + } ConnectorRes connector = getGovernanceConnector(categoryId, connectorId); // Throw an error if propertyRevertReq contain properties that are not in the connector. @@ -413,10 +459,14 @@ public void revertGovernanceConnectorProperties(String categoryId, String connec } identityGovernanceService.deleteConfiguration(propertyRevertReq.getProperties(), tenantDomain); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully reverted connector properties for tenant: " + tenantDomain); + } } catch (IdentityGovernanceException e) { GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_REVERTING_CONNECTOR_PROPERTY; Response.Status status = Response.Status.INTERNAL_SERVER_ERROR; + LOG.error("Failed to revert governance connector properties.", e); throw handleException(e, errorEnum, status); } } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java index 9c018374d3..858fba0939 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.identity.governance.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.identity.governance.common.GovernanceDataHolder; import org.wso2.carbon.identity.api.server.identity.governance.v1.core.ServerIdentityGovernanceService; import org.wso2.carbon.identity.governance.IdentityGovernanceService; @@ -27,16 +29,24 @@ */ public class ServerIdentityGovernanceServiceFactory { + private static final Log LOG = LogFactory.getLog(ServerIdentityGovernanceServiceFactory.class); private static final ServerIdentityGovernanceService SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing ServerIdentityGovernanceServiceFactory."); + } IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); if (identityGovernanceService == null) { + LOG.error("IdentityGovernanceService is not available from OSGi context."); throw new IllegalStateException("RolePermissionManagementService is not available from OSGi context."); } SERVICE = new ServerIdentityGovernanceService(identityGovernanceService); + if (LOG.isDebugEnabled()) { + LOG.debug("ServerIdentityGovernanceServiceFactory initialized successfully."); + } } /** @@ -46,6 +56,9 @@ public class ServerIdentityGovernanceServiceFactory { */ public static ServerIdentityGovernanceService getServerIdentityGovernanceService() { + if (LOG.isDebugEnabled()) { + LOG.debug("Returning ServerIdentityGovernanceService instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java index bc1152a6b2..65d74a4ab7 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.identity.governance.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.identity.governance.v1.IdentityGovernanceApiService; import org.wso2.carbon.identity.api.server.identity.governance.v1.core.ServerIdentityGovernanceService; import org.wso2.carbon.identity.api.server.identity.governance.v1.factories.ServerIdentityGovernanceServiceFactory; @@ -35,14 +37,19 @@ */ public class IdentityGovernanceApiServiceImpl implements IdentityGovernanceApiService { + private static final Log LOG = LogFactory.getLog(IdentityGovernanceApiServiceImpl.class); private final ServerIdentityGovernanceService identityGovernanceService; public IdentityGovernanceApiServiceImpl() { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing IdentityGovernanceApiService implementation."); + } this.identityGovernanceService = ServerIdentityGovernanceServiceFactory .getServerIdentityGovernanceService(); } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating identity governance service.", e); throw new RuntimeException("Error occurred while initiating identity governance service.", e); } } @@ -50,6 +57,9 @@ public IdentityGovernanceApiServiceImpl() { @Override public Response getCategories(Integer limit, Integer offset, String filter, String sort) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving governance connector categories with limit: " + limit + ", offset: " + offset); + } return Response.ok().entity(identityGovernanceService.getGovernanceConnectors(limit, offset, filter, sort)) .build(); } @@ -57,25 +67,40 @@ public Response getCategories(Integer limit, Integer offset, String filter, Stri @Override public Response getConnectorCategory(String categoryId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving governance connector category for categoryId: " + categoryId); + } return Response.ok().entity(identityGovernanceService.getGovernanceConnectorCategory(categoryId)).build(); } @Override public Response getConnectorsOfCategory(String categoryId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving governance connectors for categoryId: " + categoryId); + } return Response.ok().entity(identityGovernanceService.getGovernanceConnectorsByCategory(categoryId)).build(); } @Override public Response getConnector(String categoryId, String connectorId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving governance connector for categoryId: " + categoryId + ", connectorId: " + + connectorId); + } return Response.ok().entity(identityGovernanceService.getGovernanceConnector(categoryId, connectorId)).build(); } @Override public Response patchConnector(String categoryId, String connectorId, ConnectorsPatchReq governanceConnector) { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating governance connector for categoryId: " + categoryId + ", connectorId: " + + connectorId); + } identityGovernanceService.updateGovernanceConnectorProperty(categoryId, connectorId, governanceConnector); + LOG.info("Successfully updated governance connector property for connector: " + connectorId); return Response.ok().build(); } @@ -83,13 +108,24 @@ public Response patchConnector(String categoryId, String connectorId, Connectors public Response patchConnectorsOfCategory(String categoryId, MultipleConnectorsPatchReq multipleConnectorsPatchReq) { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating multiple governance connectors for categoryId: " + categoryId); + } identityGovernanceService.updateGovernanceConnectorProperties(categoryId, multipleConnectorsPatchReq); + LOG.info("Successfully updated governance connector properties for category: " + categoryId); return Response.ok().build(); } @Override public Response getPreferenceByPost(List preferenceSearchAttribute) { + if (preferenceSearchAttribute == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving configuration preferences for " + + preferenceSearchAttribute.size() + " attributes"); + } return Response.ok().entity(identityGovernanceService.getConfigPreference(preferenceSearchAttribute)).build(); } @@ -97,7 +133,12 @@ public Response getPreferenceByPost(List preferenceSe public Response revertConnectorProperties(String categoryId, String connectorId, PropertyRevertReq propertyRevertReq) { + if (LOG.isDebugEnabled()) { + LOG.debug("Reverting governance connector properties for categoryId: " + categoryId + + ", connectorId: " + connectorId); + } identityGovernanceService.revertGovernanceConnectorProperties(categoryId, connectorId, propertyRevertReq); + LOG.info("Successfully reverted governance connector properties for connector: " + connectorId); return Response.ok().build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/IdentityProviderServiceHolder.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/IdentityProviderServiceHolder.java index eacdf4944e..5eabfff321 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/IdentityProviderServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.common/src/main/java/org/wso2/carbon/identity/api/server/idp/common/IdentityProviderServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idp.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; import org.wso2.carbon.identity.template.mgt.TemplateManager; @@ -28,6 +30,8 @@ */ public class IdentityProviderServiceHolder { + private static final Log log = LogFactory.getLog(IdentityProviderServiceHolder.class); + private IdentityProviderServiceHolder() { } @@ -56,6 +60,12 @@ private static class TemplateManagerHolder { */ public static IdentityProviderManager getIdentityProviderManager() { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdentityProviderManager service instance."); + } + if (IdentityProviderManagerHolder.SERVICE == null) { + log.warn("IdentityProviderManager service is not available."); + } return IdentityProviderManagerHolder.SERVICE; } @@ -66,6 +76,12 @@ public static IdentityProviderManager getIdentityProviderManager() { */ public static ClaimMetadataManagementService getClaimMetadataManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ClaimMetadataManagementService service instance."); + } + if (ClaimMetadataManagementServiceHolder.SERVICE == null) { + log.warn("ClaimMetadataManagementService service is not available."); + } return ClaimMetadataManagementServiceHolder.SERVICE; } @@ -76,6 +92,12 @@ public static ClaimMetadataManagementService getClaimMetadataManagementService() */ public static TemplateManager getTemplateManager() { + if (log.isDebugEnabled()) { + log.debug("Retrieving TemplateManager service instance."); + } + if (TemplateManagerHolder.SERVICE == null) { + log.warn("TemplateManager service is not available."); + } return TemplateManagerHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java index 159b44973f..bb3651c3ea 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/core/ServerIdpManagementService.java @@ -214,6 +214,10 @@ public IdentityProviderListResponse getIDPs(String requiredAttributes, Integer l String sortBy, String sortOrder) { try { + if (log.isDebugEnabled()) { + log.debug("Retrieving identity providers with filter: " + filter + ", limit: " + limit + + ", offset: " + offset); + } List requestedAttributeList = null; if (StringUtils.isNotBlank(requiredAttributes)) { requestedAttributeList = new ArrayList<>(Arrays.asList(requiredAttributes.split(","))); @@ -222,6 +226,7 @@ public IdentityProviderListResponse getIDPs(String requiredAttributes, Integer l ContextLoader.getTenantDomainFromContext(), requestedAttributeList), requestedAttributeList); } catch (IdentityProviderManagementException e) { + log.error("Error while retrieving identity providers.", e); throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_LISTING_IDPS, null); } } @@ -241,6 +246,10 @@ public IdentityProviderListResponse getTrustedTokenIssuers(String requiredAttrib String filter, String sortBy, String sortOrder) { try { + if (log.isDebugEnabled()) { + log.debug("Retrieving trusted token issuers with filter: " + filter + ", limit: " + limit + + ", offset: " + offset); + } List requestedAttributeList = null; if (StringUtils.isNotBlank(requiredAttributes)) { requestedAttributeList = new ArrayList<>(Arrays.asList(requiredAttributes.split(","))); @@ -249,6 +258,7 @@ public IdentityProviderListResponse getTrustedTokenIssuers(String requiredAttrib sortOrder, ContextLoader.getTenantDomainFromContext(), requestedAttributeList), requestedAttributeList); } catch (IdentityProviderManagementException e) { + log.error("Error while retrieving trusted token issuers.", e); throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_LISTING_TRUSTED_TOKEN_ISSUERS, null); } } @@ -261,12 +271,27 @@ public IdentityProviderListResponse getTrustedTokenIssuers(String requiredAttrib */ public IdentityProviderResponse addIDP(IdentityProviderPOSTRequest identityProviderPOSTRequest) { + if (identityProviderPOSTRequest == null) { + throw handleIdPException(new IdentityProviderManagementClientException( + Constants.ErrorMessage.ERROR_CODE_INVALID_INPUT.getCode(), + "Identity provider request cannot be null."), + Constants.ErrorMessage.ERROR_CODE_INVALID_INPUT, null); + } + String idpName = identityProviderPOSTRequest.getName(); + if (log.isDebugEnabled()) { + log.debug("Adding identity provider: " + idpName); + } IdentityProvider identityProvider; try { validateSystemReservedIDP(identityProviderPOSTRequest.getName()); identityProvider = identityProviderManager.addIdPWithResourceId(createIDP(identityProviderPOSTRequest), ContextLoader.getTenantDomainFromContext()); + if (log.isInfoEnabled()) { + log.info("Successfully added identity provider: " + identityProvider.getIdentityProviderName() + + " with resource ID: " + identityProvider.getResourceId()); + } } catch (IdentityProviderManagementException e) { + log.error("Error while adding identity provider: " + idpName, e); throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP, null); } return createIDPResponse(identityProvider); @@ -280,15 +305,22 @@ public IdentityProviderResponse addIDP(IdentityProviderPOSTRequest identityProvi */ public IdentityProviderResponse getIDP(String idpId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving identity provider with ID: " + idpId); + } try { IdentityProvider identityProvider = identityProviderManager.getIdPByResourceId(idpId, ContextLoader.getTenantDomainFromContext(), true); if (identityProvider == null) { + if (log.isWarnEnabled()) { + log.warn("Identity provider not found with ID: " + idpId); + } throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_IDP_NOT_FOUND, idpId); } return createIDPResponse(identityProvider); } catch (IdentityProviderManagementException e) { + log.error("Error while retrieving identity provider with ID: " + idpId, e); throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_IDP, idpId); } } @@ -331,10 +363,17 @@ public IdentityProviderResponse patchIDP(String identityProviderId, List */ public void deleteIDP(String identityProviderId) { + if (log.isDebugEnabled()) { + log.debug("Deleting identity provider with ID: " + identityProviderId); + } try { identityProviderManager.deleteIdPByResourceId(identityProviderId, ContextLoader.getTenantDomainFromContext()); + if (log.isInfoEnabled()) { + log.info("Successfully deleted identity provider with ID: " + identityProviderId); + } } catch (IdentityProviderManagementException e) { + log.error("Error while deleting identity provider with ID: " + identityProviderId, e); throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_DELETING_IDP, identityProviderId); } } @@ -347,10 +386,17 @@ public void deleteIDP(String identityProviderId) { */ public void forceDeleteIDP(String identityProviderId) { + if (log.isDebugEnabled()) { + log.debug("Force deleting identity provider with ID: " + identityProviderId); + } try { identityProviderManager.forceDeleteIdpByResourceId(identityProviderId, ContextLoader.getTenantDomainFromContext()); + if (log.isInfoEnabled()) { + log.info("Successfully force deleted identity provider with ID: " + identityProviderId); + } } catch (IdentityProviderManagementException e) { + log.error("Error while force deleting identity provider with ID: " + identityProviderId, e); throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_DELETING_IDP, identityProviderId); } } diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/factories/ServerIdpManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/factories/ServerIdpManagementServiceFactory.java index f5bf50b5c1..c0244b07c8 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/factories/ServerIdpManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/factories/ServerIdpManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idp.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.idp.common.IdentityProviderServiceHolder; import org.wso2.carbon.identity.api.server.idp.v1.core.ServerIdpManagementService; import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; @@ -29,6 +31,7 @@ */ public class ServerIdpManagementServiceFactory { + private static final Log LOG = LogFactory.getLog(ServerIdpManagementServiceFactory.class); private static final ServerIdpManagementService SERVICE; static { @@ -38,14 +41,17 @@ public class ServerIdpManagementServiceFactory { TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager(); if (identityProviderManager == null) { + LOG.error("IdentityProviderManager is not available from OSGi context."); throw new IllegalStateException("IdentityProviderManager is not available from OSGi context."); } if (claimMetadataManagementService == null) { + LOG.error("ClaimMetadataManagementService is not available from OSGi context."); throw new IllegalStateException("ClaimMetadataManagementService is not available from OSGi context."); } if (templateManager == null) { + LOG.error("TemplateManager is not available from OSGi context."); throw new IllegalStateException("TemplateManager is not available from OSGi context."); } diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java index b2803d6d1b..d34dd1f958 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java @@ -20,6 +20,8 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.idp.common.Constants; import org.wso2.carbon.identity.api.server.idp.common.IdentityProviderServiceHolder; @@ -60,6 +62,8 @@ */ public class FederatedAuthenticatorConfigBuilderFactory { + private static final Log LOG = LogFactory.getLog(FederatedAuthenticatorConfigBuilderFactory.class); + /** * Builds a FederatedAuthenticatorConfig instance based on the definedBy type for the * given FederatedAuthenticatorPUTRequest. diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/IdentityProvidersApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/IdentityProvidersApiServiceImpl.java index 36d1cf061f..11466db297 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/IdentityProvidersApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/IdentityProvidersApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idp.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.search.SearchContext; import org.apache.http.HttpHeaders; @@ -55,6 +57,7 @@ */ public class IdentityProvidersApiServiceImpl implements IdentityProvidersApiService { + private static final Log LOG = LogFactory.getLog(IdentityProvidersApiServiceImpl.class); private final ServerIdpManagementService idpManagementService; public IdentityProvidersApiServiceImpl() { @@ -62,6 +65,7 @@ public IdentityProvidersApiServiceImpl() { try { this.idpManagementService = ServerIdpManagementServiceFactory.getServerIdpManagementService(); } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating ServerIdpManagementService.", e); throw new RuntimeException("Error occurred while initiating ServerIdpManagementService.", e); } } @@ -69,9 +73,18 @@ public IdentityProvidersApiServiceImpl() { @Override public Response addIDP(IdentityProviderPOSTRequest identityProviderPOSTRequest) { + if (identityProviderPOSTRequest == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Adding identity provider: " + identityProviderPOSTRequest.getName()); + } IdentityProviderResponse idPResponse = idpManagementService.addIDP(identityProviderPOSTRequest); URI location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/" + idPResponse.getId()); + if (LOG.isInfoEnabled()) { + LOG.info("Successfully created identity provider with ID: " + idPResponse.getId()); + } return Response.created(location).entity(idPResponse).build(); } @@ -88,12 +101,17 @@ public Response addIDPTemplate(IdentityProviderTemplate identityProviderTemplate @Override public Response deleteIDP(String identityProviderId, Boolean force) { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting identity provider: " + identityProviderId + ", force: " + force); + } if (force) { idpManagementService.forceDeleteIDP(identityProviderId); } else { idpManagementService.deleteIDP(identityProviderId); } - + if (LOG.isInfoEnabled()) { + LOG.info("Successfully deleted identity provider: " + identityProviderId); + } return Response.noContent().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/TrustedTokenIssuersApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/TrustedTokenIssuersApiServiceImpl.java index 7f7e569ad1..13b89b2a04 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/TrustedTokenIssuersApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/TrustedTokenIssuersApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idp.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.idp.v1.TrustedTokenIssuersApiService; import org.wso2.carbon.identity.api.server.idp.v1.core.ServerIdpManagementService; @@ -41,6 +43,7 @@ */ public class TrustedTokenIssuersApiServiceImpl implements TrustedTokenIssuersApiService { + private static final Log LOG = LogFactory.getLog(TrustedTokenIssuersApiServiceImpl.class); private final ServerIdpManagementService idpManagementService; public TrustedTokenIssuersApiServiceImpl() { @@ -48,6 +51,7 @@ public TrustedTokenIssuersApiServiceImpl() { try { this.idpManagementService = ServerIdpManagementServiceFactory.getServerIdpManagementService(); } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating ServerIdpManagementService.", e); throw new RuntimeException("Error occurred while initiating ServerIdpManagementService.", e); } } diff --git a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.common/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/common/IdentityVerificationServiceHolder.java b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.common/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/common/IdentityVerificationServiceHolder.java index 6721bd16ea..6077f19715 100644 --- a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.common/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/common/IdentityVerificationServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.common/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/common/IdentityVerificationServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idv.provider.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.extension.identity.verification.provider.IdVProviderManager; @@ -26,6 +28,8 @@ */ public class IdentityVerificationServiceHolder { + private static final Log log = LogFactory.getLog(IdentityVerificationServiceHolder.class); + private IdentityVerificationServiceHolder() {}; private static class IdVProviderManagerHolder { @@ -40,6 +44,14 @@ private static class IdVProviderManagerHolder { */ public static IdVProviderManager getIdVProviderManager() { - return IdVProviderManagerHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving IdVProviderManager OSGi service."); + } + + IdVProviderManager service = IdVProviderManagerHolder.SERVICE; + if (service == null) { + log.warn("IdVProviderManager OSGi service is not available."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/core/IdVProviderService.java b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/core/IdVProviderService.java index ca4172b34f..1bdc009be5 100644 --- a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/core/IdVProviderService.java +++ b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/core/IdVProviderService.java @@ -74,6 +74,18 @@ public IdVProviderResponse addIdVProvider(IdVProviderRequest idVProviderRequest) IdVProvider idVProvider; int tenantId = getTenantId(); + if (log.isDebugEnabled()) { + log.debug("Adding IdV provider with name: " + + (idVProviderRequest != null ? idVProviderRequest.getName() : "null") + + " for tenant ID: " + tenantId); + } + + if (idVProviderRequest == null) { + log.warn("IdVProviderRequest is null. Cannot add IdV provider."); + throw handleException(Response.Status.BAD_REQUEST, + Constants.ErrorMessage.ERROR_ADDING_IDVP, "null"); + } + try { idVProvider = idvProviderManager.addIdVProvider(createIdVProvider(idVProviderRequest), tenantId); } catch (IdVProviderMgtException e) { @@ -81,7 +93,12 @@ public IdVProviderResponse addIdVProvider(IdVProviderRequest idVProviderRequest) throw handleException(Response.Status.CONFLICT, Constants.ErrorMessage.ERROR_CODE_IDVP_EXISTS, idVProviderRequest.getName()); } - throw handleIdVException(e, Constants.ErrorMessage.ERROR_ADDING_IDVP, idVProviderRequest.getName()); + throw handleIdVException(e, Constants.ErrorMessage.ERROR_ADDING_IDVP, + idVProviderRequest.getName()); + } + if (log.isDebugEnabled()) { + log.debug("IdV provider created successfully with ID: " + idVProvider.getIdVProviderUuid() + + " for tenant ID: " + tenantId); } return getIdVProviderResponse(idVProvider); } @@ -98,6 +115,18 @@ public IdVProviderResponse updateIdVProvider(String idVProviderId, IdVProviderRe IdVProvider oldIdVProvider; IdVProvider newIdVProvider; int tenantId = getTenantId(); + if (log.isDebugEnabled()) { + log.debug("Updating IdV provider with ID: " + idVProviderId + ", name: " + + (idVProviderRequest != null ? idVProviderRequest.getName() : "null") + + " for tenant ID: " + tenantId); + } + + if (idVProviderRequest == null) { + log.warn("IdVProviderRequest is null. Cannot update IdV provider."); + throw handleException(Response.Status.BAD_REQUEST, + Constants.ErrorMessage.ERROR_UPDATING_IDVP, idVProviderId); + } + try { oldIdVProvider = idvProviderManager.getIdVProvider(idVProviderId, tenantId); @@ -119,6 +148,10 @@ public IdVProviderResponse updateIdVProvider(String idVProviderId, IdVProviderRe throw handleIdVException(e, Constants.ErrorMessage.ERROR_UPDATING_IDVP, idVProviderId); } } + if (log.isDebugEnabled()) { + log.debug("IdV provider updated successfully with ID: " + idVProviderId + + " for tenant ID: " + tenantId); + } return getIdVProviderResponse(newIdVProvider); } @@ -132,11 +165,19 @@ public IdVProviderResponse getIdVProvider(String idVProviderId) { try { int tenantId = getTenantId(); + if (log.isDebugEnabled()) { + log.debug("Retrieving IdV provider with ID: " + idVProviderId + + " for tenant ID: " + tenantId); + } IdVProvider idVProvider = idvProviderManager.getIdVProvider(idVProviderId, tenantId); if (idVProvider == null) { throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_IDVP_NOT_FOUND, idVProviderId); } + if (log.isDebugEnabled()) { + log.debug("IdV provider retrieved successfully with ID: " + idVProviderId + + " for tenant ID: " + tenantId); + } return getIdVProviderResponse(idVProvider); } catch (IdVProviderMgtException e) { if (IdVProviderMgtConstants.ErrorMessage.ERROR_EMPTY_IDVP_ID.getCode().equals(e.getErrorCode())) { @@ -169,6 +210,10 @@ public IdVProviderListResponse getIdVProviders(Integer limit, Integer offset) { public IdVProviderListResponse getIdVProviders(Integer limit, Integer offset, String filter) { int tenantId = getTenantId(); + if (log.isDebugEnabled()) { + log.debug("Retrieving IdV providers with limit: " + limit + ", offset: " + offset + + ", filter: " + filter + " for tenant ID: " + tenantId); + } try { int totalResults = idvProviderManager.getCountOfIdVProviders(tenantId, filter); @@ -194,6 +239,10 @@ public IdVProviderListResponse getIdVProviders(Integer limit, Integer offset, St offset = (offset == null) ? Integer.valueOf(0) : offset; idVProviderListResponse.setStartIndex(offset + 1); idVProviderListResponse.setTotalResults(totalResults); + if (log.isDebugEnabled()) { + log.debug("Retrieved " + idVProviderListResponse.getCount() + " out of " + totalResults + + " IdV providers for tenant ID: " + tenantId); + } return idVProviderListResponse; } catch (IdVProviderMgtException e) { throw handleIdVException(e, Constants.ErrorMessage.ERROR_RETRIEVING_IDVPS, @@ -209,8 +258,15 @@ public IdVProviderListResponse getIdVProviders(Integer limit, Integer offset, St public void deleteIdVProvider(String idVProviderId) { int tenantId = getTenantId(); + if (log.isDebugEnabled()) { + log.debug("Deleting IdV provider with ID: " + idVProviderId + " for tenant ID: " + tenantId); + } try { idvProviderManager.deleteIdVProvider(idVProviderId, tenantId); + if (log.isDebugEnabled()) { + log.debug("IdV provider deleted successfully with ID: " + idVProviderId + + " for tenant ID: " + tenantId); + } } catch (IdVProviderMgtException e) { throw handleIdVException(e, Constants.ErrorMessage.ERROR_DELETING_IDVP, idVProviderId); } @@ -404,11 +460,16 @@ private int getTenantId() { String tenantDomain = ContextLoader.getTenantDomainFromContext(); if (StringUtils.isBlank(tenantDomain)) { + log.warn("Tenant domain is blank or null while retrieving tenant ID"); throw handleException( Response.Status.INTERNAL_SERVER_ERROR, Constants.ErrorMessage.ERROR_RETRIEVING_TENANT, tenantDomain); } - return IdentityTenantUtil.getTenantId(tenantDomain); + int tenantId = IdentityTenantUtil.getTenantId(tenantDomain); + if (log.isDebugEnabled()) { + log.debug("Resolved tenant ID: " + tenantId + " for domain: " + tenantDomain); + } + return tenantId; } } diff --git a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/factories/IdVProviderServiceFactory.java b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/factories/IdVProviderServiceFactory.java index 029e046d52..8892f5ff2b 100644 --- a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/factories/IdVProviderServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/factories/IdVProviderServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idv.provider.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.extension.identity.verification.provider.IdVProviderManager; import org.wso2.carbon.identity.api.server.idv.provider.common.IdentityVerificationServiceHolder; import org.wso2.carbon.identity.api.server.idv.provider.v1.core.IdVProviderService; @@ -27,16 +29,24 @@ */ public class IdVProviderServiceFactory { + private static final Log log = LogFactory.getLog(IdVProviderServiceFactory.class); private static final IdVProviderService SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing IdVProviderService factory"); + } IdVProviderManager idvProviderManager = IdentityVerificationServiceHolder.getIdVProviderManager(); if (idvProviderManager == null) { + log.error("IdVProviderManager is not available from OSGi context during factory initialization"); throw new IllegalStateException("IdVProviderManager is not available from OSGi context."); } SERVICE = new IdVProviderService(idvProviderManager); + if (log.isDebugEnabled()) { + log.debug("IdVProviderService factory initialized successfully"); + } } /** @@ -46,6 +56,9 @@ public class IdVProviderServiceFactory { */ public static IdVProviderService getIdVProviderService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdVProviderService instance from factory"); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/impl/IdvProvidersApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/impl/IdvProvidersApiServiceImpl.java index 15b137b3ba..432f649033 100644 --- a/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/impl/IdvProvidersApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.idv.provider/org.wso2.carbon.identity.api.server.idv.provider.v1/src/main/java/org/wso2/carbon/identity/api/server/idv/provider/v1/impl/IdvProvidersApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.idv.provider.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.idv.provider.v1.IdvProvidersApiService; import org.wso2.carbon.identity.api.server.idv.provider.v1.core.IdVProviderService; @@ -37,13 +39,18 @@ */ public class IdvProvidersApiServiceImpl implements IdvProvidersApiService { + private static final Log log = LogFactory.getLog(IdvProvidersApiServiceImpl.class); private final IdVProviderService idVProviderService; public IdvProvidersApiServiceImpl() { try { this.idVProviderService = IdVProviderServiceFactory.getIdVProviderService(); + if (log.isDebugEnabled()) { + log.debug("IdvProvidersApiServiceImpl initialized successfully."); + } } catch (IllegalStateException e) { + log.error("Error occurred while initiating IdVProviderService: " + e.getMessage(), e); throw new RuntimeException("Error occurred while initiating IdVProviderService.", e); } } @@ -51,38 +58,77 @@ public IdvProvidersApiServiceImpl() { @Override public Response addIdVProvider(IdVProviderRequest idVProviderRequest) { + if (log.isDebugEnabled()) { + log.debug("Adding IdV provider with name: " + + (idVProviderRequest != null ? idVProviderRequest.getName() : "null")); + } + + if (idVProviderRequest == null) { + log.warn("IdVProviderRequest is null. Cannot add IdV provider."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + IdVProviderResponse idVProviderResponse = idVProviderService.addIdVProvider(idVProviderRequest); URI location = ContextLoader.buildURIForHeader(IDV_API_PATH_COMPONENT + idVProviderResponse.getId()); + log.info("IdV provider added successfully with ID: " + idVProviderResponse.getId()); return Response.created(location).entity(idVProviderResponse).build(); } @Override public Response deleteIdVProvider(String idvProviderId) { + if (log.isDebugEnabled()) { + log.debug("Deleting IdV provider with ID: " + idvProviderId); + } idVProviderService.deleteIdVProvider(idvProviderId); + log.info("IdV provider deleted successfully with ID: " + idvProviderId); return Response.noContent().build(); } @Override public Response getIdVProvider(String idvProviderId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdV provider with ID: " + idvProviderId); + } IdVProviderResponse idVProviderResponse = idVProviderService.getIdVProvider(idvProviderId); + if (log.isDebugEnabled()) { + log.debug("IdV provider retrieved successfully with ID: " + idvProviderId); + } return Response.ok().entity(idVProviderResponse).build(); } @Override public Response getIdVProviders(Integer limit, Integer offset, String filter) { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdV providers with limit: " + limit + ", offset: " + offset + + ", filter: " + filter); + } IdVProviderListResponse idVProviderListResponse = idVProviderService.getIdVProviders(limit, offset, filter); + if (log.isDebugEnabled()) { + log.debug("Retrieved " + idVProviderListResponse.getCount() + " IdV providers"); + } return Response.ok().entity(idVProviderListResponse).build(); } @Override public Response updateIdVProviders(String idvProviderId, IdVProviderRequest idVProviderRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating IdV provider with ID: " + idvProviderId + ", name: " + + (idVProviderRequest != null ? idVProviderRequest.getName() : "null")); + } + + if (idVProviderRequest == null) { + log.warn("IdVProviderRequest is null. Cannot update IdV provider."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + IdVProviderResponse idVProviderResponse = idVProviderService.updateIdVProvider(idvProviderId, idVProviderRequest); + log.info("IdV provider updated successfully with ID: " + idvProviderId); return Response.ok().entity(idVProviderResponse).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/InputValidationServiceHolder.java b/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/InputValidationServiceHolder.java index 9f2a0426a0..b5c64fb8be 100644 --- a/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/InputValidationServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/InputValidationServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.input.validation.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.input.validation.mgt.services.InputValidationManagementService; @@ -26,6 +28,8 @@ */ public class InputValidationServiceHolder { + private static final Log log = LogFactory.getLog(InputValidationServiceHolder.class); + private InputValidationServiceHolder () {}; private static class InputValidationManagementServiceHolder { @@ -41,6 +45,13 @@ private static class InputValidationManagementServiceHolder { */ public static InputValidationManagementService getInputValidationMgtService() { - return InputValidationManagementServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving InputValidationManagementService from OSGi service registry."); + } + InputValidationManagementService service = InputValidationManagementServiceHolder.SERVICE; + if (service == null) { + log.warn("InputValidationManagementService is not available in the OSGi service registry."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/util/Utils.java b/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/util/Utils.java index 2066c880cb..f18c90e523 100644 --- a/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/util/Utils.java +++ b/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.common/src/main/java/org/wso2/carbon/identity/api/server/input/validation/common/util/Utils.java @@ -18,17 +18,22 @@ package org.wso2.carbon.identity.api.server.input.validation.common.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.slf4j.MDC; import java.util.UUID; -import static org.wso2.carbon.identity.api.server.input.validation.common.util.ValidationManagementConstants.CORRELATION_ID; +import static org.wso2.carbon.identity.api.server.input.validation.common.util.ValidationManagementConstants + .CORRELATION_ID; /** * Util class. */ public class Utils { + private static final Log log = LogFactory.getLog(Utils.class); + /** * Get correlation id of current thread. * @@ -37,9 +42,17 @@ public class Utils { public static String getCorrelation() { if (isCorrelationIDPresent()) { - return MDC.get(CORRELATION_ID); + String correlationId = MDC.get(CORRELATION_ID); + if (log.isDebugEnabled()) { + log.debug("Retrieved existing correlation ID from MDC: " + correlationId); + } + return correlationId; + } + String newCorrelationId = UUID.randomUUID().toString(); + if (log.isDebugEnabled()) { + log.debug("Generated new correlation ID: " + newCorrelationId); } - return UUID.randomUUID().toString(); + return newCorrelationId; } /** diff --git a/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.v1/src/main/java/org/wso2/carbon/identity/api/server/input/validation/v1/core/ValidationRulesManagementApiService.java b/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.v1/src/main/java/org/wso2/carbon/identity/api/server/input/validation/v1/core/ValidationRulesManagementApiService.java index 85754e3531..0fce31dc8a 100644 --- a/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.v1/src/main/java/org/wso2/carbon/identity/api/server/input/validation/v1/core/ValidationRulesManagementApiService.java +++ b/components/org.wso2.carbon.identity.api.server.input.validation/org.wso2.carbon.identity.api.server.input.validation.v1/src/main/java/org/wso2/carbon/identity/api/server/input/validation/v1/core/ValidationRulesManagementApiService.java @@ -85,9 +85,13 @@ public ValidationRulesManagementApiService(InputValidationManagementService inpu */ public List getValidationConfiguration(String tenantDomain) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Retrieving validation configuration for tenant: " + tenantDomain); + } try { List configurations = inputValidationManagementService .getInputValidationConfiguration(tenantDomain); + LOGGER.info("Successfully retrieved validation configuration for tenant: " + tenantDomain); return buildResponse(configurations); } catch (InputValidationMgtException e) { throw handleInputValidationMgtException(e, ERROR_CODE_ERROR_GETTING_VALIDATION_CONFIG, tenantDomain); @@ -102,10 +106,15 @@ public List getValidationConfiguration(String tenantDomai */ public ValidationConfigModel getValidationConfigurationForField(String tenantDomain, String field) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Retrieving validation configuration for field: " + field + " in tenant: " + tenantDomain); + } try { isFieldSupported(field); ValidationConfiguration configuration = inputValidationManagementService .getInputValidationConfigurationForField(tenantDomain, field); + LOGGER.info("Successfully retrieved validation configuration for field: " + field + " in tenant: " + + tenantDomain); return buildResponse(configuration); } catch (InputValidationMgtException e) { throw handleInputValidationMgtException(e, ERROR_CODE_ERROR_GETTING_VALIDATION_CONFIG, tenantDomain); @@ -121,11 +130,15 @@ public ValidationConfigModel getValidationConfigurationForField(String tenantDom public List updateInputValidationConfiguration( List validationConfigModel, String tenantDomain) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Updating validation configuration for tenant: " + tenantDomain); + } try { List requestDTO = buildRequestDTOFromValidationRequest(validationConfigModel); validateProperties(requestDTO, tenantDomain); List configurations = inputValidationManagementService .updateInputValidationConfiguration(requestDTO, tenantDomain); + LOGGER.info("Successfully updated validation configuration for tenant: " + tenantDomain); return buildResponse(configurations); } catch (InputValidationMgtException e) { throw handleInputValidationMgtException(e, ERROR_CODE_ERROR_UPDATING_VALIDATION_CONFIG, tenantDomain); @@ -142,6 +155,16 @@ public List updateInputValidationConfiguration( public ValidationConfigModel updateInputValidationConfigurationForField( ValidationConfigModel validationConfigModel, String tenantDomain) { + if (validationConfigModel == null) { + throw handleInputValidationMgtException( + new InputValidationMgtClientException(ERROR_CODE_FIELD_NOT_EXISTS.getCode(), + "Validation configuration model cannot be null."), + ERROR_CODE_FIELD_NOT_EXISTS, tenantDomain); + } + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Updating validation configuration for field: " + + validationConfigModel.getField() + " in tenant: " + tenantDomain); + } try { isFieldSupported(validationConfigModel.getField()); List configModels = new ArrayList<>(); @@ -150,6 +173,8 @@ public ValidationConfigModel updateInputValidationConfigurationForField( validateProperties(requestDTO, tenantDomain); ValidationConfiguration configurations = inputValidationManagementService .updateValidationConfiguration(requestDTO.get(0), tenantDomain); + LOGGER.info("Successfully updated validation configuration for field: " + + validationConfigModel.getField() + " in tenant: " + tenantDomain); return buildResponse(configurations); } catch (InputValidationMgtException e) { throw handleInputValidationMgtException(e, ERROR_CODE_ERROR_UPDATING_VALIDATION_CONFIG, tenantDomain); @@ -164,12 +189,18 @@ public ValidationConfigModel updateInputValidationConfigurationForField( */ public void revertInputValidationConfigurationForFields(List fields, String tenantDomain) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Reverting validation configuration for fields: " + fields + " in tenant: " + + tenantDomain); + } try { for (String field : fields) { isFieldSupported(field); } inputValidationManagementService.revertInputValidationConfiguration(fields, tenantDomain); + LOGGER.info("Successfully reverted validation configuration for fields: " + fields + " in tenant: " + + tenantDomain); } catch (InputValidationMgtException e) { throw handleInputValidationMgtException(e, ERROR_CODE_ERROR_REVERTING_VALIDATION_CONFIG, tenantDomain); } @@ -182,9 +213,13 @@ public void revertInputValidationConfigurationForFields(List fields, Str */ public List getValidators(String tenantDomain) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Retrieving validators for tenant: " + tenantDomain); + } List validators; try { validators = inputValidationManagementService.getValidatorConfigurations(tenantDomain); + LOGGER.info("Successfully retrieved validators for tenant: " + tenantDomain); return buildValidatorResponse(validators); } catch (InputValidationMgtException e) { if (ERROR_CODE_INPUT_VALIDATION_NOT_EXISTS.getCode().contains(e.getErrorCode())) { @@ -360,6 +395,9 @@ private void validateProperties(List configurations, St throws InputValidationMgtClientException { for (ValidationConfiguration config: configurations) { + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Validating properties for field: " + config.getField()); + } if (!SUPPORTED_PARAMS.contains(config.getField())) { throw new InputValidationMgtClientException(ERROR_VALIDATION_PARAM_NOT_SUPPORTED.getCode(), String.format(ERROR_VALIDATION_PARAM_NOT_SUPPORTED.getDescription(), config.getField(), @@ -389,6 +427,9 @@ private void validateProperties(String field, boolean isRules, List allValidators = inputValidationManagementService.getValidators(tenantDomain); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Validating rules for field: " + field + " with " + rules.size() + " rules"); + } ValidationContext context; for (RulesConfiguration rule: rules) { Validator validator = allValidators.get(rule.getValidatorName()); @@ -397,6 +438,10 @@ private void validateProperties(String field, boolean isRules, List validationConfigModels) { String tenantDomain = getTenantDomainFromContext(); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Processing request to update validation rules for tenant: " + tenantDomain); + } return Response.ok().entity(validationRulesManagementApiService .updateInputValidationConfiguration(validationConfigModels, tenantDomain)).build(); } @@ -94,7 +115,14 @@ public Response updateValidationRules(List validationConf @Override public Response revertValidationRulesForFields(RevertFields revertFields) { + if (revertFields == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } String tenantDomain = getTenantDomainFromContext(); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Processing request to revert validation rules for fields: " + + revertFields.getFields() + " in tenant: " + tenantDomain); + } validationRulesManagementApiService.revertInputValidationConfigurationForFields(revertFields.getFields(), tenantDomain); return Response.ok().build(); @@ -112,6 +140,10 @@ public Response updateValidationRulesForField(String field, ValidationConfigMode validationConfigModelForField) { String tenantDomain = getTenantDomainFromContext(); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Processing request to update validation rules for field: " + field + " in tenant: " + + tenantDomain); + } ValidationConfigModel validationConfigModel = new ValidationConfigModel(); validationConfigModel.setField(field); validationConfigModel.setRules(validationConfigModelForField.getRules()); diff --git a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.common/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/common/KeyStoreManagamentDataHolder.java b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.common/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/common/KeyStoreManagamentDataHolder.java index 4c8cdd9c4a..5897b60685 100644 --- a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.common/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/common/KeyStoreManagamentDataHolder.java +++ b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.common/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/common/KeyStoreManagamentDataHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.keystore.management.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.security.keystore.KeyStoreManagementService; @@ -26,6 +28,8 @@ */ public class KeyStoreManagamentDataHolder { + private static final Log log = LogFactory.getLog(KeyStoreManagamentDataHolder.class); + public KeyStoreManagamentDataHolder() {} private static class KeyStoreManagementServiceHolder { @@ -41,6 +45,13 @@ private static class KeyStoreManagementServiceHolder { */ public static KeyStoreManagementService getKeyStoreManager() { - return KeyStoreManagementServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving KeyStoreManagementService from OSGi context."); + } + KeyStoreManagementService service = KeyStoreManagementServiceHolder.SERVICE; + if (service == null && log.isWarnEnabled()) { + log.warn("KeyStoreManagementService is not available in OSGi context."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/core/KeyStoreService.java b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/core/KeyStoreService.java index 98f41ee0d0..faeb742456 100644 --- a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/core/KeyStoreService.java +++ b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/core/KeyStoreService.java @@ -81,12 +81,18 @@ public List listCertificateAliases(String filter) { List aliasList; String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Listing certificate aliases for tenant: " + tenantDomain + " with filter: " + filter); + } try { aliasList = keyStoreManagementService.getKeyStoreCertificateAliases(tenantDomain, filter); + if (LOG.isDebugEnabled()) { + LOG.debug("Found " + (aliasList != null ? aliasList.size() : 0) + " certificate aliases."); + } } catch (KeyStoreManagementException e) { throw handleException(e, "Unable to list certificates from keystore."); } - return generateCertificateResponseList(aliasList, false); + return generateCertificateResponseList(aliasList != null ? aliasList : new ArrayList<>(), false); } /** @@ -100,6 +106,10 @@ public File getCertificate(String alias, boolean encodeCert) { X509Certificate certificate; String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving certificate for tenant: " + tenantDomain + ", alias: " + alias + + ", encodeCert: " + encodeCert); + } try { certificate = keyStoreManagementService.getKeyStoreCertificate(tenantDomain, alias); } catch (KeyStoreManagementException e) { @@ -107,9 +117,13 @@ public File getCertificate(String alias, boolean encodeCert) { } if (certificate == null) { + LOG.warn("Certificate not found for alias: " + alias); throw handleException(ERROR_CODE_INVALID_ALIAS, alias, "Couldn't find a certificate with alias: " + alias + " from the keystore.", Response.Status.BAD_REQUEST); } + if (LOG.isDebugEnabled()) { + LOG.debug("Certificate retrieved successfully for alias: " + alias); + } return generateCertificateFile(alias, certificate, encodeCert); } @@ -122,8 +136,12 @@ public File getCertificate(String alias, boolean encodeCert) { public URI uploadCertificate(String alias, String certificate) { String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Uploading certificate for tenant: " + tenantDomain + ", alias: " + alias); + } try { keyStoreManagementService.addCertificate(tenantDomain, alias, certificate); + LOG.info("Certificate uploaded successfully for tenant: " + tenantDomain + ", alias: " + alias); } catch (KeyStoreManagementException e) { throw handleException(e, "Unable to upload the certificate with alias: " + alias + " to the keystore."); } @@ -140,8 +158,12 @@ public URI uploadCertificate(String alias, String certificate) { public void deleteCertificate(String alias) { String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting certificate for tenant: " + tenantDomain + ", alias: " + alias); + } try { keyStoreManagementService.deleteCertificate(tenantDomain, alias); + LOG.info("Certificate deleted successfully for tenant: " + tenantDomain + ", alias: " + alias); } catch (KeyStoreManagementException e) { throw handleException(e, "Unable to remove the certificate with alias: " + alias + " from the keystore."); } @@ -157,12 +179,18 @@ public List listClientCertificateAliases(String filter) { List aliasList; String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Listing client certificate aliases for tenant: " + tenantDomain + " with filter: " + filter); + } try { aliasList = keyStoreManagementService.getClientCertificateAliases(tenantDomain, filter); + if (LOG.isDebugEnabled()) { + LOG.debug("Found " + (aliasList != null ? aliasList.size() : 0) + " client certificate aliases."); + } } catch (KeyStoreManagementException e) { throw handleException(e, "Unable to retrieve the list of certificates from client truststore."); } - return generateCertificateResponseList(aliasList, true); + return generateCertificateResponseList(aliasList != null ? aliasList : new ArrayList<>(), true); } /** @@ -176,6 +204,10 @@ public File getClientCertificate(String alias, boolean encodeCert) { X509Certificate certificate; String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving client certificate for tenant: " + tenantDomain + ", alias: " + alias + + ", encodeCert: " + encodeCert); + } try { certificate = keyStoreManagementService.getClientCertificate(tenantDomain, alias); } catch (KeyStoreManagementException e) { @@ -184,9 +216,13 @@ public File getClientCertificate(String alias, boolean encodeCert) { } if (certificate == null) { + LOG.warn("Client certificate not found for alias: " + alias); throw handleException(ERROR_CODE_INVALID_ALIAS, alias, "Couldn't find a certificate with alias: " + alias + " from the keystore.", Response.Status.BAD_REQUEST); } + if (LOG.isDebugEnabled()) { + LOG.debug("Client certificate retrieved successfully for alias: " + alias); + } return generateCertificateFile(alias, certificate, encodeCert); } @@ -200,6 +236,9 @@ public File getPublicCertificate(boolean encodeCert) { Map certificateData; String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving public certificate for tenant: " + tenantDomain + ", encodeCert: " + encodeCert); + } try { certificateData = keyStoreManagementService.getPublicCertificate(tenantDomain); } catch (KeyStoreManagementException e) { @@ -213,6 +252,9 @@ public File getPublicCertificate(boolean encodeCert) { alias = key; certificate = certificateData.get(alias); } + if (LOG.isDebugEnabled()) { + LOG.debug("Public certificate retrieved successfully with alias: " + alias); + } return generateCertificateFile(alias, certificate, encodeCert); } diff --git a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/factories/KeyStoreServiceFactory.java b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/factories/KeyStoreServiceFactory.java index 3afc8e2b51..e1800d2822 100644 --- a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/factories/KeyStoreServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/factories/KeyStoreServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.keystore.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.keystore.management.common.KeyStoreManagamentDataHolder; import org.wso2.carbon.identity.api.server.keystore.management.v1.core.KeyStoreService; import org.wso2.carbon.security.keystore.KeyStoreManagementService; @@ -27,16 +29,22 @@ */ public class KeyStoreServiceFactory { + private static final Log LOG = LogFactory.getLog(KeyStoreServiceFactory.class); private static final KeyStoreService SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing KeyStoreService factory."); + } KeyStoreManagementService keyStoreManagementService = KeyStoreManagamentDataHolder.getKeyStoreManager(); if (keyStoreManagementService == null) { + LOG.error("KeyStoreManagementService is not available from OSGi context."); throw new IllegalStateException("KeyStoreManagementService is not available from OSGi context."); } SERVICE = new KeyStoreService(keyStoreManagementService); + LOG.info("KeyStoreService factory initialized successfully."); } /** @@ -46,6 +54,9 @@ public class KeyStoreServiceFactory { */ public static KeyStoreService getKeyStoreService() { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving KeyStoreService instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/impl/KeystoresApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/impl/KeystoresApiServiceImpl.java index 8473e1ab6e..80f2ce8ade 100644 --- a/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/impl/KeystoresApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.keystore.management/org.wso2.carbon.identity.api.server.keystore.management.v1/src/main/java/org/wso2/carbon/identity/api/server/keystore/management/v1/impl/KeystoresApiServiceImpl.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.keystore.management.v1.impl; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.identity.api.server.keystore.management.v1.KeystoresApiService; import org.wso2.carbon.identity.api.server.keystore.management.v1.core.KeyStoreService; @@ -36,13 +38,18 @@ */ public class KeystoresApiServiceImpl implements KeystoresApiService { + private static final Log LOG = LogFactory.getLog(KeystoresApiServiceImpl.class); private final KeyStoreService keyStoreService; public KeystoresApiServiceImpl() { try { this.keyStoreService = KeyStoreServiceFactory.getKeyStoreService(); + if (LOG.isDebugEnabled()) { + LOG.debug("KeystoresApiServiceImpl initialized successfully."); + } } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating key store management service.", e); throw new RuntimeException("Error occurred while initiating key store management service.", e); } } @@ -51,9 +58,14 @@ public KeystoresApiServiceImpl() { public Response deleteCertificate(String alias) { if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + LOG.warn("Delete certificate operation not allowed for super tenant. Alias: " + alias); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting certificate with alias: " + alias); + } keyStoreService.deleteCertificate(alias); + LOG.info("Certificate deleted successfully. Alias: " + alias); return Response.noContent().build(); } @@ -63,12 +75,18 @@ public Response getCertificate(String alias, Boolean encodeCert) { if (encodeCert == null) { encodeCert = false; } + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving certificate with alias: " + alias + ", encodeCert: " + encodeCert); + } return Response.ok().entity(keyStoreService.getCertificate(alias, encodeCert)).build(); } @Override public Response getCertificateAliases(String filter) { + if (LOG.isDebugEnabled()) { + LOG.debug("Listing certificate aliases with filter: " + filter); + } return Response.ok().entity(keyStoreService.listCertificateAliases(filter)).build(); } @@ -76,12 +94,16 @@ public Response getCertificateAliases(String filter) { public Response getClientCertificate(String alias, Boolean encodeCert) { if (!StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + LOG.warn("Get client certificate operation only allowed for super tenant. Alias: " + alias); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } if (encodeCert == null) { encodeCert = false; } + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving client certificate with alias: " + alias + ", encodeCert: " + encodeCert); + } return Response.ok().entity(keyStoreService.getClientCertificate(alias, encodeCert)).build(); } @@ -89,8 +111,12 @@ public Response getClientCertificate(String alias, Boolean encodeCert) { public Response getClientCertificateAliases(String filter) { if (!StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + LOG.warn("Get client certificate aliases operation only allowed for super tenant. Filter: " + filter); return Response.status(Response.Status.NOT_FOUND).build(); } + if (LOG.isDebugEnabled()) { + LOG.debug("Listing client certificate aliases with filter: " + filter); + } return Response.ok().entity(keyStoreService.listClientCertificateAliases(filter)).build(); } @@ -100,6 +126,9 @@ public Response getPublicCertificate(Boolean encodeCert) { if (encodeCert == null) { encodeCert = false; } + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving public certificate, encodeCert: " + encodeCert); + } return Response.ok().entity(keyStoreService.getPublicCertificate(encodeCert)).build(); } @@ -107,10 +136,20 @@ public Response getPublicCertificate(Boolean encodeCert) { public Response uploadCertificate(CertificateRequest certificateRequest) { if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + LOG.warn("Upload certificate operation not allowed for super tenant. Alias: " + + (certificateRequest != null ? certificateRequest.getAlias() : "null")); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + if (certificateRequest == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + String alias = certificateRequest.getAlias(); + if (LOG.isDebugEnabled()) { + LOG.debug("Uploading certificate with alias: " + alias); + } URI certResource = keyStoreService.uploadCertificate(certificateRequest.getAlias(), certificateRequest.getCertificate()); + LOG.info("Certificate uploaded successfully. Alias: " + alias); NewCookie resourceCookie = new NewCookie("Location", certResource.toString()); return Response.created(certResource).cookie(resourceCookie).build(); }