diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementServiceHolder.java index 27a75672df..32f0033884 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementServiceHolder.java @@ -45,14 +45,38 @@ private ApplicationManagementServiceHolder() { private static class ApplicationServiceHolder { - static final ApplicationManagementService SERVICE = (ApplicationManagementService) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(ApplicationManagementService.class, null); + private static final Log log = LogFactory.getLog(ApplicationServiceHolder.class); + static final ApplicationManagementService SERVICE = initializeService(); + + private static ApplicationManagementService initializeService() { + + ApplicationManagementService service = (ApplicationManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(ApplicationManagementService.class, null); + if (service == null) { + log.warn("ApplicationManagementService is not available in OSGi context."); + } else { + log.debug("ApplicationManagementService successfully retrieved from OSGi context."); + } + return service; + } } private static class OAuthAdminServiceImplHolder { - static final OAuthAdminServiceImpl SERVICE = (OAuthAdminServiceImpl) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null); + private static final Log log = LogFactory.getLog(OAuthAdminServiceImplHolder.class); + static final OAuthAdminServiceImpl SERVICE = initializeService(); + + private static OAuthAdminServiceImpl initializeService() { + + OAuthAdminServiceImpl service = (OAuthAdminServiceImpl) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null); + if (service == null) { + log.warn("OAuthAdminServiceImpl is not available in OSGi context."); + } else { + log.debug("OAuthAdminServiceImpl successfully retrieved from OSGi context."); + } + return service; + } } private static class STSAdminServiceInterfaceHolder { @@ -68,13 +92,17 @@ private static class STSAdminServiceInterfaceHolder { private static STSAdminServiceInterface initializeService() { try { - - return (STSAdminServiceInterface) PrivilegedCarbonContext + STSAdminServiceInterface service = (STSAdminServiceInterface) PrivilegedCarbonContext .getThreadLocalCarbonContext().getOSGiService(STSAdminServiceInterface.class, null); + if (service == null) { + log.warn("STSAdminServiceInterface is not available in OSGi context."); + } else { + log.debug("STSAdminServiceInterface successfully retrieved from OSGi context."); + } + return service; } catch (NullPointerException e) { - // Catch NullPointerException if the context or the service isn't properly set. log.debug("NullPointerException occurred while retrieving STSAdminServiceInterface. " + - "Context or service might not be available."); + "Context or service might not be available.", e); return null; } } @@ -82,57 +110,164 @@ private static STSAdminServiceInterface initializeService() { private static class SAMLSSOConfigServiceImplHolder { - static final SAMLSSOConfigServiceImpl SERVICE = (SAMLSSOConfigServiceImpl) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(SAMLSSOConfigServiceImpl.class, null); + private static final Log log = LogFactory.getLog(SAMLSSOConfigServiceImplHolder.class); + static final SAMLSSOConfigServiceImpl SERVICE = initializeService(); + + private static SAMLSSOConfigServiceImpl initializeService() { + + SAMLSSOConfigServiceImpl service = (SAMLSSOConfigServiceImpl) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(SAMLSSOConfigServiceImpl.class, null); + if (service == null) { + log.warn("SAMLSSOConfigServiceImpl is not available in OSGi context."); + } else { + log.debug("SAMLSSOConfigServiceImpl successfully retrieved from OSGi context."); + } + return service; + } } private static class LoginFlowAIManagerServiceHolder { - static final LoginFlowAIManager SERVICE = - (LoginFlowAIManager) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(LoginFlowAIManager.class, null); + private static final Log log = LogFactory.getLog(LoginFlowAIManagerServiceHolder.class); + static final LoginFlowAIManager SERVICE = initializeService(); + + private static LoginFlowAIManager initializeService() { + + LoginFlowAIManager service = (LoginFlowAIManager) PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getOSGiService(LoginFlowAIManager.class, null); + if (service == null) { + log.warn("LoginFlowAIManager is not available in OSGi context."); + } else { + log.debug("LoginFlowAIManager successfully retrieved from OSGi context."); + } + return service; + } } private static class OAuthServerConfigurationHolder { - static final OAuthServerConfiguration SERVICE = (OAuthServerConfiguration) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(OAuthServerConfiguration.class, null); + private static final Log log = LogFactory.getLog(OAuthServerConfigurationHolder.class); + static final OAuthServerConfiguration SERVICE = initializeService(); + + private static OAuthServerConfiguration initializeService() { + + OAuthServerConfiguration service = (OAuthServerConfiguration) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OAuthServerConfiguration.class, null); + if (service == null) { + log.warn("OAuthServerConfiguration is not available in OSGi context."); + } else { + log.debug("OAuthServerConfiguration successfully retrieved from OSGi context."); + } + return service; + } } private static class TemplateManagerHolder { - static final TemplateManager SERVICE = (TemplateManager) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(TemplateManager.class, null); + private static final Log log = LogFactory.getLog(TemplateManagerHolder.class); + static final TemplateManager SERVICE = initializeService(); + + private static TemplateManager initializeService() { + + TemplateManager service = (TemplateManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(TemplateManager.class, null); + if (service == null) { + log.warn("TemplateManager is not available in OSGi context."); + } else { + log.debug("TemplateManager successfully retrieved from OSGi context."); + } + return service; + } } private static class CORSManagementServiceHolder { - static final CORSManagementService SERVICE = (CORSManagementService) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(CORSManagementService.class, null); + private static final Log log = LogFactory.getLog(CORSManagementServiceHolder.class); + static final CORSManagementService SERVICE = initializeService(); + + private static CORSManagementService initializeService() { + + CORSManagementService service = (CORSManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(CORSManagementService.class, null); + if (service == null) { + log.warn("CORSManagementService is not available in OSGi context."); + } else { + log.debug("CORSManagementService successfully retrieved from OSGi context."); + } + return service; + } } private static class RealmServiceHolder { - static final RealmService SERVICE = (RealmService) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(RealmService.class, null); + private static final Log log = LogFactory.getLog(RealmServiceHolder.class); + static final RealmService SERVICE = initializeService(); + + private static RealmService initializeService() { + + RealmService service = (RealmService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(RealmService.class, null); + if (service == null) { + log.warn("RealmService is not available in OSGi context."); + } else { + log.debug("RealmService successfully retrieved from OSGi context."); + } + return service; + } } private static class APIResourceManagerHolder { - static final APIResourceManager SERVICE = (APIResourceManager) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(APIResourceManager.class, null); + private static final Log log = LogFactory.getLog(APIResourceManagerHolder.class); + static final APIResourceManager SERVICE = initializeService(); + + private static APIResourceManager initializeService() { + + APIResourceManager service = (APIResourceManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(APIResourceManager.class, null); + if (service == null) { + log.warn("APIResourceManager is not available in OSGi context."); + } else { + log.debug("APIResourceManager successfully retrieved from OSGi context."); + } + return service; + } } private static class AuthorizedAPIManagementServiceHolder { - static final AuthorizedAPIManagementService SERVICE = (AuthorizedAPIManagementService) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(AuthorizedAPIManagementService.class, null); + private static final Log log = LogFactory.getLog(AuthorizedAPIManagementServiceHolder.class); + static final AuthorizedAPIManagementService SERVICE = initializeService(); + + private static AuthorizedAPIManagementService initializeService() { + + AuthorizedAPIManagementService service = (AuthorizedAPIManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(AuthorizedAPIManagementService.class, null); + if (service == null) { + log.warn("AuthorizedAPIManagementService is not available in OSGi context."); + } else { + log.debug("AuthorizedAPIManagementService successfully retrieved from OSGi context."); + } + return service; + } } private static class OrgApplicationManagerHolder { - static final OrgApplicationManager SERVICE = (OrgApplicationManager) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(OrgApplicationManager.class, null); + private static final Log log = LogFactory.getLog(OrgApplicationManagerHolder.class); + static final OrgApplicationManager SERVICE = initializeService(); + + private static OrgApplicationManager initializeService() { + + OrgApplicationManager service = (OrgApplicationManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OrgApplicationManager.class, null); + if (service == null) { + log.warn("OrgApplicationManager is not available in OSGi context."); + } else { + log.debug("OrgApplicationManager successfully retrieved from OSGi context."); + } + return service; + } } /** diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAdvancedConfigurations.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAdvancedConfigurations.java index 6ee6b62c9e..629e32136d 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAdvancedConfigurations.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAdvancedConfigurations.java @@ -20,6 +20,8 @@ import com.google.gson.Gson; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.application.management.v1.AdditionalSpProperty; import org.wso2.carbon.identity.api.server.application.management.v1.AdvancedApplicationConfiguration; import org.wso2.carbon.identity.api.server.application.management.v1.Certificate; @@ -44,6 +46,7 @@ */ public class UpdateAdvancedConfigurations implements UpdateFunction { + private static final Log log = LogFactory.getLog(UpdateAdvancedConfigurations.class); public static final String TYPE_JWKS = "JWKS"; public static final String TYPE_PEM = "PEM"; @@ -51,6 +54,10 @@ public class UpdateAdvancedConfigurations implements UpdateFunction spAdditiona // `additionalSpProperties` not yet supported. if (!CollectionUtils.isEmpty(spAdditionalProperties)) { + log.warn("Additional SP properties are not yet supported. Request will be rejected."); throw buildBadRequestError(ADDITIONAL_SP_PROP_NOT_SUPPORTED.getCode(), ADDITIONAL_SP_PROP_NOT_SUPPORTED.getDescription()); } diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAssociatedRoles.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAssociatedRoles.java index 2c98826768..94b6fa743f 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAssociatedRoles.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateAssociatedRoles.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.application.management.v1.AssociatedRolesConfig; import org.wso2.carbon.identity.api.server.application.management.v1.core.functions.UpdateFunction; import org.wso2.carbon.identity.application.common.model.RoleV2; @@ -31,9 +33,15 @@ */ public class UpdateAssociatedRoles implements UpdateFunction { + private static final Log log = LogFactory.getLog(UpdateAssociatedRoles.class); + @Override public void apply(ServiceProvider serviceProvider, AssociatedRolesConfig associatedRolesConfig) { + if (log.isDebugEnabled()) { + log.debug("Updating associated roles config for application: " + + serviceProvider.getApplicationName()); + } org.wso2.carbon.identity.application.common.model.AssociatedRolesConfig rolesConfig = new org.wso2.carbon.identity.application.common.model.AssociatedRolesConfig(); if (associatedRolesConfig != null) { @@ -47,5 +55,9 @@ public void apply(ServiceProvider serviceProvider, AssociatedRolesConfig associa } } serviceProvider.setAssociatedRolesConfig(rolesConfig); + if (log.isDebugEnabled()) { + log.debug("Successfully updated associated roles config for application: " + + serviceProvider.getApplicationName()); + } } } diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateClaimConfiguration.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateClaimConfiguration.java index 79f2b43dc4..f4c98986e7 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateClaimConfiguration.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/UpdateClaimConfiguration.java @@ -15,6 +15,9 @@ */ package org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.identity.api.server.application.management.v1.ClaimConfiguration; import org.wso2.carbon.identity.api.server.application.management.v1.ClaimMappings; @@ -44,9 +47,15 @@ */ public class UpdateClaimConfiguration implements UpdateFunction { + private static final Log log = LogFactory.getLog(UpdateClaimConfiguration.class); + @Override public void apply(ServiceProvider application, ClaimConfiguration claimApiModel) { + if (log.isDebugEnabled()) { + log.debug("Updating claim configuration for application: " + + application.getApplicationName()); + } if (claimApiModel != null) { ClaimConfig applicationClaimConfiguration = getClaimConfig(application); @@ -58,6 +67,10 @@ public void apply(ServiceProvider application, ClaimConfiguration claimApiModel) updateRoleClaimConfigs(claimApiModel.getRole(), application); // Subject claim. updateSubjectClaimConfigs(claimApiModel.getSubject(), application); + if (log.isDebugEnabled()) { + log.debug("Successfully updated claim configuration for application: " + + application.getApplicationName()); + } } } @@ -135,6 +148,8 @@ private void updateSubjectClaimConfigs(SubjectConfig subjectApiModel, ServicePro if (Boolean.TRUE.equals(subjectApiModel.getMappedLocalSubjectMandatory()) && Boolean.FALSE.equals(subjectApiModel.getUseMappedLocalSubject())) { + log.warn("Invalid subject claim configuration: mapped local subject mandatory is true but " + + "use mapped local subject is false"); throw buildBadRequestError(ERROR_ASSERT_LOCAL_SUBJECT_IDENTIFIER_DISABLED.getCode(), ERROR_ASSERT_LOCAL_SUBJECT_IDENTIFIER_DISABLED.getDescription()); } diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/provisioning/UpdateProvisioningConfiguration.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/provisioning/UpdateProvisioningConfiguration.java index 5c20a9055a..790ce23c76 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/provisioning/UpdateProvisioningConfiguration.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/provisioning/UpdateProvisioningConfiguration.java @@ -15,6 +15,8 @@ */ package org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.provisioning; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.application.management.v1.InboundSCIMProvisioningConfiguration; import org.wso2.carbon.identity.api.server.application.management.v1.OutboundProvisioningConfiguration; import org.wso2.carbon.identity.api.server.application.management.v1.ProvisioningConfiguration; @@ -35,9 +37,15 @@ */ public class UpdateProvisioningConfiguration implements UpdateFunction { + private static final Log log = LogFactory.getLog(UpdateProvisioningConfiguration.class); + @Override public void apply(ServiceProvider application, ProvisioningConfiguration provisioningConfigApiModel) { + if (log.isDebugEnabled()) { + log.debug("Updating provisioning configuration for application: " + + (application != null ? application.getApplicationName() : "null")); + } if (provisioningConfigApiModel != null) { InboundSCIMProvisioningConfiguration inboundProvisioningModel = provisioningConfigApiModel.getInboundProvisioning(); @@ -61,6 +69,10 @@ public void apply(ServiceProvider application, ProvisioningConfiguration provisi application.setOutboundProvisioningConfig(outboundProvisioningConfig); } + if (log.isDebugEnabled()) { + log.debug("Successfully updated provisioning configuration for application: " + + (application != null ? application.getApplicationName() : "null")); + } } } diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/template/TemplateToApplicationTemplate.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/template/TemplateToApplicationTemplate.java index 139c47de36..b4f865f965 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/template/TemplateToApplicationTemplate.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/template/TemplateToApplicationTemplate.java @@ -20,6 +20,8 @@ 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.identity.api.server.application.management.common.ApplicationManagementConstants; import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationModel; import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplateModel; @@ -36,9 +38,18 @@ */ public class TemplateToApplicationTemplate implements Function { + private static final Log log = LogFactory.getLog(TemplateToApplicationTemplate.class); + @Override public ApplicationTemplateModel apply(Template template) { + if (log.isDebugEnabled()) { + log.debug("Converting template to application template: " + + (template != null ? template.getTemplateName() : "null")); + } + if (template == null) { + return null; + } ApplicationTemplateModel applicationTemplate = new ApplicationTemplateModel(); applicationTemplate.setName(template.getTemplateName()); applicationTemplate.setId(template.getTemplateId()); @@ -83,6 +94,7 @@ private ApplicationModel createApplicationTemplate(String applicationTemplate) { try { return mapper.readValue(applicationTemplate, ApplicationModel.class); } catch (IOException e) { + log.error("Error occurred while parsing application template script", e); throw buildServerError( ApplicationManagementConstants.ErrorMessage.ERROR_RESOLVING_APPLICATION_TEMPLATE.getCode(), ApplicationManagementConstants.ErrorMessage.ERROR_RESOLVING_APPLICATION_TEMPLATE.getMessage(), diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/impl/ApplicationsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/impl/ApplicationsApiServiceImpl.java index ed0b994a9e..202efe1360 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/impl/ApplicationsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/impl/ApplicationsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.application.management.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.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants; @@ -70,12 +72,16 @@ */ public class ApplicationsApiServiceImpl implements ApplicationsApiService { + private static final Log log = LogFactory.getLog(ApplicationsApiServiceImpl.class); private final ServerApplicationManagementService applicationManagementService; private final ServerApplicationMetadataService applicationMetadataService; private final ServerApplicationSharingService applicationSharingService; public ApplicationsApiServiceImpl() { + if (log.isDebugEnabled()) { + log.debug("Initializing ApplicationsApiServiceImpl."); + } try { this.applicationManagementService = ServerApplicationManagementServiceFactory .getServerApplicationManagementService(); @@ -84,8 +90,12 @@ public ApplicationsApiServiceImpl() { this.applicationSharingService = ServerApplicationSharingServiceFactory .getServerApplicationSharingService(); } catch (IllegalStateException e) { + log.error("Error occurred while initiating application management services.", e); throw new RuntimeException("Error occurred while initiating application management services.", e); } + if (log.isDebugEnabled()) { + log.debug("Successfully initialized ApplicationsApiServiceImpl."); + } } @Deprecated @@ -100,6 +110,10 @@ public Response getAllApplications(Integer limit, Integer offset, String filter, public Response getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String requiredAttributes, Boolean excludeSystemPortals) { + if (log.isDebugEnabled()) { + log.debug("Retrieving applications with limit: " + limit + ", offset: " + offset + ", filter: " + + filter); + } ApplicationListResponse listResponse = applicationManagementService.getAllApplications(limit, offset, filter, sortOrder, sortBy, requiredAttributes, Boolean.TRUE.equals(excludeSystemPortals)); return Response.ok().entity(listResponse).build(); @@ -108,6 +122,9 @@ public Response getAllApplications(Integer limit, Integer offset, String filter, @Override public Response getApplication(String applicationId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving application with ID: " + applicationId); + } return Response.ok().entity(applicationManagementService.getApplication(applicationId)).build(); } @@ -147,7 +164,12 @@ public Response changeApplicationOwner(String applicationId, ApplicationOwner ap @Override public Response createApplication(ApplicationModel applicationModel, String template) { + if (log.isDebugEnabled()) { + log.debug("Creating application with name: " + + (applicationModel != null ? applicationModel.getName() : "null") + ", template: " + template); + } String resourceId = applicationManagementService.createApplication(applicationModel, template); + log.info("Successfully created application with ID: " + resourceId); return Response.created(getResourceLocation(resourceId)).build(); } @@ -161,7 +183,11 @@ public Response createApplicationTemplate(ApplicationTemplateModel applicationTe @Override public Response deleteApplication(String applicationId) { + if (log.isDebugEnabled()) { + log.debug("Deleting application with ID: " + applicationId); + } applicationManagementService.deleteApplication(applicationId); + log.info("Successfully deleted application with ID: " + applicationId); return Response.noContent().build(); } @@ -182,7 +208,11 @@ public Response deleteAuthorizedAPI(String applicationId, String authorizationId @Override public Response patchApplication(String applicationId, ApplicationPatchModel applicationPatchModel) { + if (log.isDebugEnabled()) { + log.debug("Updating application with ID: " + applicationId); + } applicationManagementService.patchApplication(applicationId, applicationPatchModel); + log.info("Successfully updated application with ID: " + applicationId); return Response.ok().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.common/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/common/AsyncOperationStatusMgtServiceHolder.java b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.common/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/common/AsyncOperationStatusMgtServiceHolder.java index 44914fad14..ffbe401c3d 100644 --- a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.common/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/common/AsyncOperationStatusMgtServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.common/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/common/AsyncOperationStatusMgtServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.asynchronous.operation.status.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.framework.async.operation.status.mgt.api.service.AsyncOperationStatusMgtService; @@ -26,6 +28,8 @@ */ public class AsyncOperationStatusMgtServiceHolder { + private static final Log log = LogFactory.getLog(AsyncOperationStatusMgtServiceHolder.class); + private AsyncOperationStatusMgtServiceHolder() { } @@ -44,6 +48,15 @@ private static class ServiceHolder { */ public static AsyncOperationStatusMgtService getAsyncOperationStatusMgtService() { - return ServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving AsyncOperationStatusMgtService from service holder."); + } + + AsyncOperationStatusMgtService service = ServiceHolder.SERVICE; + if (service == null) { + log.warn("AsyncOperationStatusMgtService is not available."); + } + + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/core/AsyncOperationsApiServiceCore.java b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/core/AsyncOperationsApiServiceCore.java index e356aefc62..e6262b299d 100644 --- a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/core/AsyncOperationsApiServiceCore.java +++ b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/core/AsyncOperationsApiServiceCore.java @@ -75,15 +75,26 @@ public class AsyncOperationsApiServiceCore { public AsyncOperationsApiServiceCore(AsyncOperationStatusMgtService asyncOperationStatusMgtService) { this.asyncOperationStatusMgtService = asyncOperationStatusMgtService; + if (LOG.isDebugEnabled()) { + LOG.debug("AsyncOperationsApiServiceCore initialized with AsyncOperationStatusMgtService."); + } } public Response getOperations(String after, String before, Integer limit, String filter) { String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving operations for tenant: %s with parameters - after: %s, " + + "before: %s, limit: %s, filter: %s", tenantDomain, after, before, limit, filter)); + } try { limit = validateLimit(limit); List records = asyncOperationStatusMgtService.getOperations(tenantDomain, after, before, limit + 1, filter); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Successfully retrieved %d operations for tenant: %s", + records != null ? records.size() : 0, tenantDomain)); + } return Response.ok().entity(getOperationsResponse(limit, after, before, filter, records)).build(); } catch (AsyncOperationStatusMgtException e) { throw AsyncOperationStatusEndpointUtil.handleAsyncOperationStatusMgtException(e); @@ -93,9 +104,15 @@ public Response getOperations(String after, String before, Integer limit, String public Response getOperation(String operationId) { String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving operation with ID: %s for tenant: %s", operationId, tenantDomain)); + } try { OperationResponseDTO record = asyncOperationStatusMgtService.getOperation(operationId, tenantDomain); if (record == null) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Operation not found for ID: %s in tenant: %s", operationId, tenantDomain)); + } return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok().entity(getOperationResponse(record)).build(); @@ -107,10 +124,18 @@ public Response getOperation(String operationId) { public Response getUnitOperation(String unitOperationId) { String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving unit operation with ID: %s for tenant: %s", + unitOperationId, tenantDomain)); + } try { UnitOperationResponseDTO record = asyncOperationStatusMgtService.getUnitOperation(unitOperationId, tenantDomain); if (record == null) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Unit operation not found for ID: %s in tenant: %s", + unitOperationId, tenantDomain)); + } return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok().entity(getUnitOperationResponse(record)).build(); @@ -123,11 +148,20 @@ public Response getUnitOperations(String operationId, String after, String befor Integer limit, String filter) { String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving unit operations for operation ID: %s in tenant: %s with " + + "parameters - after: %s, before: %s, limit: %s, filter: %s", + operationId, tenantDomain, after, before, limit, filter)); + } try { limit = validateLimit(limit); List records = asyncOperationStatusMgtService.getUnitOperationStatusRecords(operationId, tenantDomain, after, before, limit + 1, filter); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Successfully retrieved %d unit operations for operation ID: %s in tenant: %s", + records != null ? records.size() : 0, operationId, tenantDomain)); + } return Response.ok().entity( getUnitOperationsResponse(limit, after, before, filter, records, operationId)).build(); } catch (AsyncOperationStatusMgtException e) { @@ -178,7 +212,8 @@ private Operations getOperationsResponse(Integer limit, String after, String bef try { url += "&" + FILTER_PARAM + "=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { - throw new AsyncOperationStatusMgtServerException("Error"); + LOG.error("Error encoding filter parameter for pagination URL", e); + throw new AsyncOperationStatusMgtServerException("Error encoding filter parameter"); } } @@ -258,7 +293,8 @@ private UnitOperations getUnitOperationsResponse(Integer limit, String after, St try { url += "&" + FILTER_PARAM + "=" + URLEncoder.encode(filter, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { - throw new AsyncOperationStatusMgtServerException("Error"); + LOG.error("Error encoding filter parameter for unit operations pagination URL", e); + throw new AsyncOperationStatusMgtServerException("Error encoding filter parameter"); } } diff --git a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/factories/AsyncOperationsApiServiceCoreFactory.java b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/factories/AsyncOperationsApiServiceCoreFactory.java index ec4b5ed217..5fbc22c093 100644 --- a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/factories/AsyncOperationsApiServiceCoreFactory.java +++ b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/factories/AsyncOperationsApiServiceCoreFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.common.AsyncOperationStatusMgtServiceHolder; import org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1.core.AsyncOperationsApiServiceCore; import org.wso2.carbon.identity.framework.async.operation.status.mgt.api.service.AsyncOperationStatusMgtService; @@ -27,15 +29,23 @@ */ public class AsyncOperationsApiServiceCoreFactory { + private static final Log log = LogFactory.getLog(AsyncOperationsApiServiceCoreFactory.class); private static final AsyncOperationsApiServiceCore SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing AsyncOperationsApiServiceCoreFactory."); + } AsyncOperationStatusMgtService asyncOperationStatusMgtService = AsyncOperationStatusMgtServiceHolder.getAsyncOperationStatusMgtService(); if (asyncOperationStatusMgtService == null) { + log.error("AsyncOperationStatusMgtService is not available from the OSGi context."); throw new IllegalStateException("AsyncOperationStatusMgtService is not available from the OSGi context."); } SERVICE = new AsyncOperationsApiServiceCore(asyncOperationStatusMgtService); + if (log.isDebugEnabled()) { + log.debug("AsyncOperationsApiServiceCoreFactory initialized successfully."); + } } /** @@ -45,6 +55,9 @@ public class AsyncOperationsApiServiceCoreFactory { */ public static AsyncOperationsApiServiceCore getAsyncOperationsApiServiceCore() { + if (log.isDebugEnabled()) { + log.debug("Returning AsyncOperationsApiServiceCore instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/impl/AsyncOperationsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/impl/AsyncOperationsApiServiceImpl.java index 8591c1927f..74c4a8f954 100644 --- a/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/impl/AsyncOperationsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management/org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1/src/main/java/org/wso2/carbon/identity/api/server/asynchronous/operation/status/management/v1/impl/AsyncOperationsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1.AsyncOperationsApiService; import org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1.core.AsyncOperationsApiServiceCore; import org.wso2.carbon.identity.api.server.asynchronous.operation.status.management.v1.factories.AsyncOperationsApiServiceCoreFactory; @@ -29,23 +31,34 @@ */ public class AsyncOperationsApiServiceImpl implements AsyncOperationsApiService { + private static final Log LOG = LogFactory.getLog(AsyncOperationsApiServiceImpl.class); private AsyncOperationsApiServiceCore asyncOperationsApiServiceCore; public AsyncOperationsApiServiceImpl() { this.asyncOperationsApiServiceCore = AsyncOperationsApiServiceCoreFactory .getAsyncOperationsApiServiceCore(); + if (LOG.isDebugEnabled()) { + LOG.debug("AsyncOperationsApiServiceImpl initialized successfully."); + } } @Override public Response asyncOperationsGet(String after, String before, Integer limit, String filter) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving async operations with parameters - after: %s, before: %s, " + + "limit: %s, filter: %s", after, before, limit, filter)); + } return asyncOperationsApiServiceCore.getOperations(after, before, limit, filter); } @Override public Response asyncOperationsOperationIdGet(String operationId) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving async operation with ID: %s", operationId)); + } return asyncOperationsApiServiceCore.getOperation(operationId); } @@ -53,6 +66,10 @@ public Response asyncOperationsOperationIdGet(String operationId) { public Response asyncOperationsOperationIdUnitOperationsGet(String operationId, String after, String before, Integer limit, String filter) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving unit operations for operation ID: %s with parameters - " + + "after: %s, before: %s, limit: %s, filter: %s", operationId, after, before, limit, filter)); + } return asyncOperationsApiServiceCore.getUnitOperations(operationId, after, before, limit, filter); } @@ -60,6 +77,10 @@ public Response asyncOperationsOperationIdUnitOperationsGet(String operationId, public Response asyncOperationsOperationIdUnitOperationsUnitOperationIdGet(String operationId, String unitOperationId) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving unit operation with ID: %s for operation ID: %s", + unitOperationId, operationId)); + } return asyncOperationsApiServiceCore.getUnitOperation(unitOperationId); } } diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.common/src/main/java/org/wso2/carbon/identity/api/server/authenticators/common/AuthenticatorsServiceHolder.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.common/src/main/java/org/wso2/carbon/identity/api/server/authenticators/common/AuthenticatorsServiceHolder.java index 2e476d4160..38fdde7424 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.common/src/main/java/org/wso2/carbon/identity/api/server/authenticators/common/AuthenticatorsServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.common/src/main/java/org/wso2/carbon/identity/api/server/authenticators/common/AuthenticatorsServiceHolder.java @@ -16,6 +16,8 @@ package org.wso2.carbon.identity.api.server.authenticators.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; @@ -26,6 +28,8 @@ */ public class AuthenticatorsServiceHolder { + private static final Log log = LogFactory.getLog(AuthenticatorsServiceHolder.class); + private AuthenticatorsServiceHolder() { } @@ -56,6 +60,12 @@ private static class ApplicationAuthenticatorServiceHolder { */ public static ApplicationManagementService getApplicationManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ApplicationManagementService from OSGi service registry."); + } + if (ApplicationManagementServiceHolder.SERVICE == null) { + log.warn("ApplicationManagementService is not available in OSGi service registry."); + } return ApplicationManagementServiceHolder.SERVICE; } @@ -66,6 +76,12 @@ public static ApplicationManagementService getApplicationManagementService() { */ public static IdpManager getIdentityProviderManager() { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdpManager from OSGi service registry."); + } + if (IdentityProviderManagerHolder.SERVICE == null) { + log.warn("IdpManager is not available in OSGi service registry."); + } return IdentityProviderManagerHolder.SERVICE; } @@ -76,6 +92,12 @@ public static IdpManager getIdentityProviderManager() { */ public static ApplicationAuthenticatorService getApplicationAuthenticatorService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ApplicationAuthenticatorService from OSGi service registry."); + } + if (ApplicationAuthenticatorServiceHolder.SERVICE == null) { + log.warn("ApplicationAuthenticatorService is not available in OSGi service registry."); + } return ApplicationAuthenticatorServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java index 20f452387e..f12ce802a5 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java @@ -109,6 +109,10 @@ public ServerAuthenticatorManagementService(ApplicationManagementService applica */ public List getAuthenticators(String filter, Integer limit, Integer offset) { + if (log.isDebugEnabled()) { + log.debug("Retrieving authenticators with filter: " + filter + ", limit: " + limit + + ", offset: " + offset); + } handleNotImplementedCapabilities(limit, offset); try { @@ -223,13 +227,20 @@ public ConnectedApps getConnectedAppsOfLocalAuthenticator(String authenticatorId */ public Authenticator addUserDefinedLocalAuthenticator(UserDefinedLocalAuthenticatorCreation config) { + if (config == null) { + throw new IllegalArgumentException("Authenticator configuration is required."); + } + + log.info("Adding user defined local authenticator: " + config.getName()); try { UserDefinedLocalAuthenticatorConfig createdConfig = applicationAuthenticatorService .addUserDefinedLocalAuthenticator( LocalAuthenticatorConfigBuilderFactory.build(config), CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + log.info("Successfully added user defined local authenticator: " + config.getName()); return LocalAuthenticatorConfigBuilderFactory.build(createdConfig); } catch (AuthenticatorMgtException e) { + log.error("Error adding user defined local authenticator: " + config.getName(), e); throw handleAuthenticatorException(e); } } @@ -241,10 +252,14 @@ public Authenticator addUserDefinedLocalAuthenticator(UserDefinedLocalAuthentica */ public void deleteUserDefinedLocalAuthenticator(String authenticatorId) { + log.info("Deleting user defined local authenticator with ID: " + authenticatorId); try { - applicationAuthenticatorService.deleteUserDefinedLocalAuthenticator(base64URLDecode(authenticatorId), + String authenticatorName = base64URLDecode(authenticatorId); + applicationAuthenticatorService.deleteUserDefinedLocalAuthenticator(authenticatorName, CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + log.info("Successfully deleted user defined local authenticator: " + authenticatorName); } catch (AuthenticatorMgtException e) { + log.error("Error deleting user defined local authenticator with ID: " + authenticatorId, e); throw handleAuthenticatorException(e); } } @@ -259,12 +274,14 @@ public void deleteUserDefinedLocalAuthenticator(String authenticatorId) { public Authenticator updateUserDefinedLocalAuthenticator( String authenticatorId, UserDefinedLocalAuthenticatorUpdate config) { + log.info("Updating user defined local authenticator with ID: " + authenticatorId); try { String authenticatorName = base64URLDecode(authenticatorId); String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); LocalAuthenticatorConfig existingAuthenticator = applicationAuthenticatorService .getLocalAuthenticatorByName(authenticatorName, tenantDomain); if (existingAuthenticator == null) { + log.warn("Authenticator not found for update: " + authenticatorName); AuthenticatorMgtError error = AuthenticatorMgtError.ERROR_CODE_ERROR_AUTHENTICATOR_NOT_FOUND; throw handleAuthenticatorException(new AuthenticatorMgtClientException(error.getCode(), error.getMessage(), String.format(error.getMessage(), authenticatorName)), @@ -274,8 +291,10 @@ public Authenticator updateUserDefinedLocalAuthenticator( .updateUserDefinedLocalAuthenticator( LocalAuthenticatorConfigBuilderFactory.build(config, existingAuthenticator), tenantDomain); + log.info("Successfully updated user defined local authenticator: " + authenticatorName); return LocalAuthenticatorConfigBuilderFactory.build(updatedConfig); } catch (AuthenticatorMgtException e) { + log.error("Error updating user defined local authenticator with ID: " + authenticatorId, e); throw handleAuthenticatorException(e); } } diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/factories/ServerAuthenticatorManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/factories/ServerAuthenticatorManagementServiceFactory.java index 5fdcd73109..730d33e186 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/factories/ServerAuthenticatorManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/factories/ServerAuthenticatorManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.authenticators.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.authenticators.common.AuthenticatorsServiceHolder; import org.wso2.carbon.identity.api.server.authenticators.v1.core.ServerAuthenticatorManagementService; import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; @@ -29,9 +31,12 @@ */ public class ServerAuthenticatorManagementServiceFactory { + private static final Log log = LogFactory.getLog(ServerAuthenticatorManagementServiceFactory.class); private static final ServerAuthenticatorManagementService SERVICE; static { + log.info("Initializing ServerAuthenticatorManagementService"); + ApplicationManagementService applicationManagementService = AuthenticatorsServiceHolder .getApplicationManagementService(); IdpManager idpManager = AuthenticatorsServiceHolder.getIdentityProviderManager(); @@ -39,15 +44,18 @@ public class ServerAuthenticatorManagementServiceFactory { .getApplicationAuthenticatorService(); if (applicationManagementService == null) { + log.error("ApplicationManagementService is not available from OSGi context"); throw new IllegalStateException("ApplicationManagementService is not available from OSGi context."); } if (idpManager == null) { + log.error("IdpManager is not available from OSGi context"); throw new IllegalStateException("IdpManager is not available from OSGi context."); } SERVICE = new ServerAuthenticatorManagementService(applicationManagementService, idpManager, applicationAuthenticatorService); + log.info("Successfully initialized ServerAuthenticatorManagementService"); } /** diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/AuthenticatorsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/AuthenticatorsApiServiceImpl.java index 015140237a..9ea343cf1f 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/AuthenticatorsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/AuthenticatorsApiServiceImpl.java @@ -16,6 +16,8 @@ package org.wso2.carbon.identity.api.server.authenticators.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.authenticators.v1.AuthenticatorsApiService; import org.wso2.carbon.identity.api.server.authenticators.v1.core.ServerAuthenticatorManagementService; import org.wso2.carbon.identity.api.server.authenticators.v1.factories.ServerAuthenticatorManagementServiceFactory; @@ -34,14 +36,18 @@ */ public class AuthenticatorsApiServiceImpl implements AuthenticatorsApiService { + private static final Log log = LogFactory.getLog(AuthenticatorsApiServiceImpl.class); private final ServerAuthenticatorManagementService authenticatorManagementService; public AuthenticatorsApiServiceImpl() { try { + log.info("Initializing AuthenticatorsApiService"); authenticatorManagementService = ServerAuthenticatorManagementServiceFactory .getServerAuthenticatorManagementService(); + log.info("Successfully initialized AuthenticatorsApiService"); } catch (IllegalStateException e) { + log.error("Error occurred while initiating the authenticator management services", e); throw new RuntimeException("Error occurred while initiating the authenticator management services.", e); } } @@ -49,6 +55,10 @@ public AuthenticatorsApiServiceImpl() { @Override public Response authenticatorsGet(String filter, Integer limit, Integer offset) { + if (log.isDebugEnabled()) { + log.debug("Retrieving authenticators with filter: " + filter + ", limit: " + limit + + ", offset: " + offset); + } return Response.ok().entity(authenticatorManagementService.getAuthenticators(filter, limit, offset)).build(); } @@ -62,23 +72,35 @@ public Response authenticatorsMetaTagsGet() { public Response addUserDefinedLocalAuthenticator( UserDefinedLocalAuthenticatorCreation userDefinedLocalAuthenticatorCreation) { + log.info("Creating user defined local authenticator: " + + (userDefinedLocalAuthenticatorCreation != null ? + userDefinedLocalAuthenticatorCreation.getName() : "null")); + Authenticator response = authenticatorManagementService .addUserDefinedLocalAuthenticator(userDefinedLocalAuthenticatorCreation); URI location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + "/authenticator/custom/" + response.getId()); + + log.info("Successfully created user defined local authenticator with ID: " + response.getId()); return Response.created(location).entity(response).build(); } @Override public Response deleteUserDefinedLocalAuthenticator(String authenticatorId) { + log.info("Deleting user defined local authenticator with ID: " + authenticatorId); authenticatorManagementService.deleteUserDefinedLocalAuthenticator(authenticatorId); + log.info("Successfully deleted user defined local authenticator with ID: " + authenticatorId); return Response.noContent().build(); } @Override public Response getConnectedAppsOfLocalAuthenticator(String authenticatorId, Integer limit, Integer offset) { + if (log.isDebugEnabled()) { + log.debug("Retrieving connected apps for authenticator ID: " + authenticatorId + + ", limit: " + limit + ", offset: " + offset); + } return Response.ok().entity(authenticatorManagementService .getConnectedAppsOfLocalAuthenticator(authenticatorId, limit, offset)).build(); } @@ -87,7 +109,10 @@ public Response getConnectedAppsOfLocalAuthenticator(String authenticatorId, Int public Response updateUserDefinedLocalAuthenticator( String authenticatorId, UserDefinedLocalAuthenticatorUpdate userDefinedLocalAuthenticatorUpdate) { - return Response.ok().entity(authenticatorManagementService - .updateUserDefinedLocalAuthenticator(authenticatorId, userDefinedLocalAuthenticatorUpdate)).build(); + log.info("Updating user defined local authenticator with ID: " + authenticatorId); + Authenticator response = authenticatorManagementService + .updateUserDefinedLocalAuthenticator(authenticatorId, userDefinedLocalAuthenticatorUpdate); + log.info("Successfully updated user defined local authenticator with ID: " + authenticatorId); + return Response.ok().entity(response).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java index 38f92595f1..de192658e7 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.authenticators.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.authenticators.v1.model.AuthenticationType; import org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator; import org.wso2.carbon.identity.api.server.authenticators.v1.model.Endpoint; @@ -45,6 +47,7 @@ */ public class LocalAuthenticatorConfigBuilderFactory { + private static final Log log = LogFactory.getLog(LocalAuthenticatorConfigBuilderFactory.class); private static final String TAG_2FA = "2FA"; /** @@ -55,6 +58,17 @@ public class LocalAuthenticatorConfigBuilderFactory { */ public static Authenticator build(UserDefinedLocalAuthenticatorConfig config) { + if (config == null) { + if (log.isDebugEnabled()) { + log.debug("UserDefinedLocalAuthenticatorConfig is null, returning null"); + } + return null; + } + + if (log.isDebugEnabled()) { + log.debug("Building authenticator model from UserDefinedLocalAuthenticatorConfig: " + config.getName()); + } + Authenticator authenticator = new Authenticator(); String authenticatorId = base64URLEncode(config.getName()); authenticator.setName(config.getName()); @@ -69,6 +83,9 @@ public static Authenticator build(UserDefinedLocalAuthenticatorConfig config) { authenticator.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + CONFIGS_AUTHENTICATOR_PATH_COMPONENT, authenticatorId)).toString()); + if (log.isDebugEnabled()) { + log.debug("Successfully built authenticator model for: " + config.getName()); + } return authenticator; } @@ -82,6 +99,15 @@ public static Authenticator build(UserDefinedLocalAuthenticatorConfig config) { public static UserDefinedLocalAuthenticatorConfig build(UserDefinedLocalAuthenticatorCreation config) throws AuthenticatorMgtClientException { + if (config == null) { + throw new IllegalArgumentException("Authentication configuration cannot be null"); + } + + if (log.isDebugEnabled()) { + log.debug("Building UserDefinedLocalAuthenticatorConfig from creation request: " + + config.getName()); + } + validateUserDefinedLocalAuthenticatorConfig(config); String authenticationType = AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION.toString(); if (config.getAuthenticationType() != null) { @@ -96,6 +122,7 @@ public static UserDefinedLocalAuthenticatorConfig build(UserDefinedLocalAuthenti authConfig.setEnabled(config.getIsEnabled()); authConfig.setEndpointConfig(buildEndpointConfig(config.getEndpoint())); + log.info("Created user defined local authenticator config: " + config.getName()); return authConfig; } @@ -110,6 +137,15 @@ public static UserDefinedLocalAuthenticatorConfig build(UserDefinedLocalAuthenti public static UserDefinedLocalAuthenticatorConfig build(UserDefinedLocalAuthenticatorUpdate config, LocalAuthenticatorConfig existingConfig) throws AuthenticatorMgtClientException { + if (existingConfig == null) { + throw new IllegalArgumentException("Existing authenticator configuration cannot be null"); + } + + if (log.isDebugEnabled()) { + log.debug("Building UserDefinedLocalAuthenticatorConfig from update request for: " + + existingConfig.getName()); + } + UserDefinedLocalAuthenticatorConfig authConfig = new UserDefinedLocalAuthenticatorConfig( resolveAuthenticationType(existingConfig)); authConfig.setName(existingConfig.getName()); @@ -119,6 +155,7 @@ public static UserDefinedLocalAuthenticatorConfig build(UserDefinedLocalAuthenti authConfig.setEnabled(config.getIsEnabled()); authConfig.setEndpointConfig(buildEndpointConfig(config.getEndpoint())); + log.info("Updated user defined local authenticator config: " + existingConfig.getName()); return authConfig; } @@ -137,6 +174,7 @@ private static UserDefinedAuthenticatorEndpointConfig buildEndpointConfig(Endpoi endpointConfigBuilder.allowedParameters(endpointConfig.getAllowedParameters()); return endpointConfigBuilder.build(); } catch (NoSuchElementException | IllegalArgumentException e) { + log.warn("Failed to build endpoint configuration due to invalid config: " + e.getMessage()); AuthenticatorMgtError error = AuthenticatorMgtError.ERROR_CODE_INVALID_ENDPOINT_CONFIG; throw new AuthenticatorMgtClientException(error.getCode(), error.getMessage(), e.getMessage()); } @@ -155,12 +193,21 @@ private static AuthenticatorPropertyConstants.AuthenticationType resolveAuthenti private static void validateUserDefinedLocalAuthenticatorConfig(UserDefinedLocalAuthenticatorCreation config) throws AuthenticatorMgtClientException { + if (config == null) { + throw new IllegalArgumentException("Authentication configuration cannot be null"); + } + + if (config.getEndpoint() == null || config.getEndpoint().getAuthentication() == null) { + throw new IllegalArgumentException("Endpoint authentication configuration is required"); + } + if (config.getEndpoint().getAuthentication().getType() == AuthenticationType.TypeEnum.NONE) { return; } if (config.getEndpoint().getAuthentication().getProperties() == null || config.getEndpoint().getAuthentication().getProperties().isEmpty()) { + log.warn("Endpoint authentication properties missing for authenticator: " + config.getName()); AuthenticatorMgtError error = AuthenticatorMgtError.ERROR_CODE_INVALID_ENDPOINT_CONFIG; throw new AuthenticatorMgtClientException(error.getCode(), error.getMessage(), "Endpoint authentication properties must be provided for user defined local authenticator: " diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java index 2ecd683e18..371c2c9dc9 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.common/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/common/BrandingPreferenceServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.branding.preference.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.branding.preference.management.core.BrandingPreferenceManager; import org.wso2.carbon.identity.branding.preference.management.core.ai.BrandingAIPreferenceManager; @@ -27,6 +29,8 @@ */ public class BrandingPreferenceServiceHolder { + private static final Log log = LogFactory.getLog(BrandingPreferenceServiceHolder.class); + private static class BrandingPreferenceManagerHolder { static final BrandingPreferenceManager SERVICE = (BrandingPreferenceManager) PrivilegedCarbonContext @@ -46,7 +50,14 @@ private static class BrandingAIPreferenceManagerServiceHolder { */ public static BrandingPreferenceManager getBrandingPreferenceManager() { - return BrandingPreferenceManagerHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving BrandingPreferenceManager OSGi service."); + } + BrandingPreferenceManager manager = BrandingPreferenceManagerHolder.SERVICE; + if (manager == null && log.isDebugEnabled()) { + log.debug("BrandingPreferenceManager OSGi service is not available."); + } + return manager; } /** @@ -56,6 +67,13 @@ public static BrandingPreferenceManager getBrandingPreferenceManager() { */ public static BrandingAIPreferenceManager getBrandingPreferenceAiManager() { - return BrandingAIPreferenceManagerServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving BrandingAIPreferenceManager OSGi service."); + } + BrandingAIPreferenceManager aiManager = BrandingAIPreferenceManagerServiceHolder.SERVICE; + if (aiManager == null && log.isDebugEnabled()) { + log.debug("BrandingAIPreferenceManager OSGi service is not available."); + } + return aiManager; } } diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java index 0ec8e08155..500d3301e0 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingAIPreferenceManagementService.java @@ -58,9 +58,18 @@ public class BrandingAIPreferenceManagementService { public BrandingGenerationResponseModel generateBrandingPreference( BrandingGenerationRequestModel brandingGenerationRequestModel) { + if (LOG.isDebugEnabled()) { + LOG.debug("Initiating branding preference generation for website URL: " + + (brandingGenerationRequestModel.getWebsiteUrl() != null ? + brandingGenerationRequestModel.getWebsiteUrl() : "null")); + } try { String operationId = BrandingPreferenceServiceHolder.getBrandingPreferenceAiManager() .generateBrandingPreference(brandingGenerationRequestModel.getWebsiteUrl()); + if (LOG.isInfoEnabled()) { + LOG.info("Branding preference generation initiated successfully with operation ID: " + + (operationId != null ? operationId : "null")); + } BrandingGenerationResponseModel response = new BrandingGenerationResponseModel(); response.setOperationId(operationId); return response; @@ -79,6 +88,10 @@ public BrandingGenerationResponseModel generateBrandingPreference( */ public BrandingGenerationStatusModel getBrandingPreferenceGenerationStatus(String operationId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving branding preference generation status for operation ID: " + + (operationId != null ? operationId : "null")); + } try { Object generationStatus = BrandingPreferenceServiceHolder.getBrandingPreferenceAiManager() .getBrandingPreferenceGenerationStatus(operationId); @@ -89,6 +102,10 @@ public BrandingGenerationStatusModel getBrandingPreferenceGenerationStatus(Strin ERROR_CODE_ERROR_GETTING_BRANDING_RESULT_STATUS.getCode()); } response.setStatus(generationStatusMap.get(AI_RESPONSE_STATUS_KEY)); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved branding preference generation status for operation ID: " + + (operationId != null ? operationId : "null")); + } return response; } catch (AIServerException e) { throw handleServerException(e); @@ -105,6 +122,10 @@ public BrandingGenerationStatusModel getBrandingPreferenceGenerationStatus(Strin */ public BrandingGenerationResultModel getBrandingPreferenceGenerationResult(String operationId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving branding preference generation result for operation ID: " + + (operationId != null ? operationId : "null")); + } try { Object generationResult = BrandingPreferenceServiceHolder.getBrandingPreferenceAiManager() .getBrandingPreferenceGenerationResult(operationId); @@ -120,6 +141,10 @@ public BrandingGenerationResultModel getBrandingPreferenceGenerationResult(Strin Map dataMap = (Map) resultMap.get(AI_RESPONSE_DATA_KEY); response.setData(dataMap); + if (LOG.isInfoEnabled()) { + LOG.info("Successfully retrieved branding preference generation result for operation ID: " + + (operationId != null ? operationId : "null")); + } return response; } catch (AIServerException e) { throw handleServerException(e); diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingPreferenceManagementService.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingPreferenceManagementService.java index 15fccb55b3..a6513d9448 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingPreferenceManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/BrandingPreferenceManagementService.java @@ -99,6 +99,8 @@ public BrandingPreferenceModel addBrandingPreference(BrandingPreferenceModel bra try { BrandingPreference requestDTO = buildRequestDTOFromBrandingRequest(brandingPreferenceModel); responseDTO = brandingPreferenceManager.addBrandingPreference(requestDTO); + log.info("Branding preference added successfully for tenant: " + tenantDomain + + " and type: " + brandingPreferenceModel.getType()); } catch (BrandingPreferenceMgtException e) { if (BRANDING_PREFERENCE_ALREADY_EXISTS_ERROR_CODE.equals(e.getErrorCode())) { if (log.isDebugEnabled()) { @@ -136,6 +138,8 @@ public void deleteBrandingPreference(String type, String name, String locale) { try { brandingPreferenceManager.deleteBrandingPreference(type, name, locale); + log.info("Branding preference deleted successfully for tenant: " + tenantDomain + + " and type: " + type); } catch (BrandingPreferenceMgtException e) { if (BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) { if (log.isDebugEnabled()) { @@ -263,6 +267,8 @@ public BrandingPreferenceModel updateBrandingPreference(BrandingPreferenceModel try { BrandingPreference requestDTO = buildRequestDTOFromBrandingRequest(brandingPreferenceModel); responseDTO = brandingPreferenceManager.replaceBrandingPreference(requestDTO); + log.info("Branding preference updated successfully for tenant: " + tenantDomain + + " and type: " + brandingPreferenceModel.getType()); } catch (BrandingPreferenceMgtException e) { if (BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) { if (log.isDebugEnabled()) { @@ -302,6 +308,8 @@ public CustomTextModel addCustomTextPreference(CustomTextModel customTextModal) try { CustomText requestDTO = buildRequestDTOFromCustomTextRequest(customTextModal); responseDTO = brandingPreferenceManager.addCustomText(requestDTO); + log.info("Custom text preference added successfully for tenant: " + tenantDomain + + " and screen: " + (customTextModal.getScreen() != null ? customTextModal.getScreen() : "null")); } catch (BrandingPreferenceMgtException e) { if (CUSTOM_TEXT_PREFERENCE_ALREADY_EXISTS_ERROR_CODE.equals(e.getErrorCode())) { if (log.isDebugEnabled()) { @@ -332,6 +340,8 @@ public void deleteCustomTextPreference(String type, String name, String screen, try { brandingPreferenceManager.deleteCustomText(type, name, screen, locale); + log.info("Custom text preference deleted successfully for tenant: " + tenantDomain + + " and screen: " + (screen != null ? screen : "null")); } catch (BrandingPreferenceMgtException e) { if (CUSTOM_TEXT_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) { if (log.isDebugEnabled()) { @@ -450,6 +460,8 @@ public CustomTextModel updateCustomTextPreference(CustomTextModel customTextMode try { CustomText requestDTO = buildRequestDTOFromCustomTextRequest(customTextModel); responseDTO = brandingPreferenceManager.replaceCustomText(requestDTO); + log.info("Custom text preference updated successfully for tenant: " + tenantDomain + + " and screen: " + (customTextModel.getScreen() != null ? customTextModel.getScreen() : "null")); } catch (BrandingPreferenceMgtException e) { if (CUSTOM_TEXT_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) { if (log.isDebugEnabled()) { diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/utils/BrandingPreferenceUtils.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/utils/BrandingPreferenceUtils.java index 8751f7c2b5..3be2fb17e9 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/utils/BrandingPreferenceUtils.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/core/utils/BrandingPreferenceUtils.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.utils; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; @@ -27,6 +29,8 @@ */ public class BrandingPreferenceUtils { + private static final Log log = LogFactory.getLog(BrandingPreferenceUtils.class); + /** * Check whether the given string is a valid JSON or not. * @@ -36,14 +40,23 @@ public class BrandingPreferenceUtils { public static boolean isValidJSONString(String stringJSON) { if (StringUtils.isBlank(stringJSON)) { + if (log.isDebugEnabled()) { + log.debug("JSON string is blank or null during validation."); + } return false; } try { JSONObject objectJSON = new JSONObject(stringJSON); if (objectJSON.length() == 0) { + if (log.isDebugEnabled()) { + log.debug("JSON object is empty after parsing."); + } return false; } } catch (JSONException exception) { + if (log.isDebugEnabled()) { + log.debug("Invalid JSON string provided for validation.", exception); + } return false; } return true; diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java index 333de30673..74c443ed1b 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingAIPreferenceManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.branding.preference.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingAIPreferenceManagementService; /** @@ -25,10 +27,14 @@ */ public class BrandingAIPreferenceManagementServiceFactory { + private static final Log log = LogFactory.getLog(BrandingAIPreferenceManagementServiceFactory.class); private static final BrandingAIPreferenceManagementService SERVICE; static { SERVICE = new BrandingAIPreferenceManagementService(); + if (log.isDebugEnabled()) { + log.debug("BrandingAIPreferenceManagementService initialized successfully."); + } } public static BrandingAIPreferenceManagementService getBrandingAIPreferenceManagementService() { diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceManagementServiceFactory.java index e01a523a44..6423db2675 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/factories/BrandingPreferenceManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.branding.preference.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.branding.preference.management.common.BrandingPreferenceServiceHolder; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingPreferenceManagementService; import org.wso2.carbon.identity.branding.preference.management.core.BrandingPreferenceManager; @@ -27,6 +29,7 @@ */ public class BrandingPreferenceManagementServiceFactory { + private static final Log log = LogFactory.getLog(BrandingPreferenceManagementServiceFactory.class); private static final BrandingPreferenceManagementService SERVICE; static { @@ -34,10 +37,14 @@ public class BrandingPreferenceManagementServiceFactory { .getBrandingPreferenceManager(); if (brandingPreferenceManager == null) { + log.error("BrandingPreferenceManager is not available from OSGi context."); throw new IllegalStateException("BrandingPreferenceManager is not available from OSGi context."); } SERVICE = new BrandingPreferenceManagementService(brandingPreferenceManager); + if (log.isDebugEnabled()) { + log.debug("BrandingPreferenceManagementService initialized successfully."); + } } /** diff --git a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java index 3af71ea8d5..610318f789 100644 --- a/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.branding.preference.management/org.wso2.carbon.identity.api.server.branding.preference.management.v1/src/main/java/org/wso2/carbon/identity/api/server/branding/preference/management/v1/impl/BrandingPreferenceApiServiceImpl.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.branding.preference.management.v1.impl; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.BrandingPreferenceApiService; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.core.BrandingPreferenceManagementService; import org.wso2.carbon.identity.api.server.branding.preference.management.v1.factories.BrandingAIPreferenceManagementServiceFactory; @@ -56,6 +58,7 @@ */ public class BrandingPreferenceApiServiceImpl implements BrandingPreferenceApiService { + private static final Log log = LogFactory.getLog(BrandingPreferenceApiServiceImpl.class); private final BrandingPreferenceManagementService brandingPreferenceManagementService; //TODO: Improve API to manage application level & language level theming resources in addition to the tenant level. @@ -73,6 +76,9 @@ public BrandingPreferenceApiServiceImpl() { public Response addBrandingPreference(BrandingPreferenceModel brandingPreferenceModel) { if (StringUtils.isBlank(brandingPreferenceModel.getType().toString())) { + if (log.isDebugEnabled()) { + log.debug("Invalid request: Branding preference type is blank."); + } return Response.status(Response.Status.BAD_REQUEST).build(); } if (!(ORGANIZATION_TYPE.equals(brandingPreferenceModel.getType().toString()) || @@ -104,6 +110,9 @@ public Response addCustomText(CustomTextModel customTextModel) { if (StringUtils.isBlank(customTextModel.getType().toString()) || StringUtils.isBlank(customTextModel.getScreen())) { + if (log.isDebugEnabled()) { + log.debug("Invalid request: Custom text type or screen is blank."); + } return Response.status(Response.Status.BAD_REQUEST).build(); } if (!ORGANIZATION_TYPE.equals(customTextModel.getType().toString())) { @@ -137,6 +146,9 @@ public Response deleteBrandingPreference(String type, String name, String locale if (type != null) { if (!(ORGANIZATION_TYPE.equals(type) || APPLICATION_TYPE.equals(type) || CUSTOM_TYPE.equals(type))) { + if (log.isDebugEnabled()) { + log.debug("Invalid request: Invalid type provided for branding preference deletion: " + type); + } return Response.status(Response.Status.BAD_REQUEST).build(); } if (!(ORGANIZATION_TYPE.equals(type) || APPLICATION_TYPE.equals(type))) { @@ -170,12 +182,18 @@ public Response deleteCustomText(String type, String name, String locale, String if (StringUtils.isBlank(type)) { type = ORGANIZATION_TYPE; } else if (!(ORGANIZATION_TYPE.equals(type) || APPLICATION_TYPE.equals(type) || CUSTOM_TYPE.equals(type))) { + if (log.isDebugEnabled()) { + log.debug("Invalid request: Invalid type provided for custom text deletion: " + type); + } return Response.status(Response.Status.BAD_REQUEST).build(); } else if (!ORGANIZATION_TYPE.equals(type)) { return Response.status(Response.Status.NOT_FOUND).build(); } if (StringUtils.isBlank(screen)) { + if (log.isDebugEnabled()) { + log.debug("Invalid request: Screen parameter is blank for custom text deletion."); + } return Response.status(Response.Status.BAD_REQUEST).build(); } if (StringUtils.isBlank(locale)) { diff --git a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.common/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/common/CertificateValidationManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.common/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/common/CertificateValidationManagementServiceHolder.java index fa7c7969b6..4e54632d43 100644 --- a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.common/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/common/CertificateValidationManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.common/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/common/CertificateValidationManagementServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.certificate.validation.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.x509Certificate.validation.service.CertificateValidationManagementService; @@ -26,6 +28,8 @@ */ public class CertificateValidationManagementServiceHolder { + private static final Log LOG = LogFactory.getLog(CertificateValidationManagementServiceHolder.class); + private CertificateValidationManagementServiceHolder() { } @@ -37,7 +41,19 @@ private CertificateValidationManagementServiceHolder() { */ public static CertificateValidationManagementService getCertificateValidationService() { - return CertificateValidationServiceHolder.SERVICE; + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving CertificateValidationManagementService from OSGi service registry."); + } + + CertificateValidationManagementService service = CertificateValidationServiceHolder.SERVICE; + if (service == null) { + LOG.warn("CertificateValidationManagementService is not available from OSGi service registry."); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved CertificateValidationManagementService from OSGi service registry."); + } + } + return service; } /** @@ -45,8 +61,22 @@ public static CertificateValidationManagementService getCertificateValidationSer */ private static class CertificateValidationServiceHolder { - static final CertificateValidationManagementService SERVICE = (CertificateValidationManagementService) - PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService( - CertificateValidationManagementService.class, null); + static final CertificateValidationManagementService SERVICE; + + static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing CertificateValidationManagementService from OSGi service registry."); + } + SERVICE = (CertificateValidationManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(CertificateValidationManagementService.class, null); + if (SERVICE == null) { + LOG.warn("Failed to initialize CertificateValidationManagementService from OSGi service registry."); + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully initialized CertificateValidationManagementService from OSGi service " + + "registry."); + } + } + } } } diff --git a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/core/ServerCertificateValidationManagementService.java b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/core/ServerCertificateValidationManagementService.java index 039d0f62b7..ef2037ea75 100644 --- a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/core/ServerCertificateValidationManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/core/ServerCertificateValidationManagementService.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.certificate.validation.management.v1.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.model.CACertificate; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.model.CACertificates; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.model.Validator; @@ -28,6 +30,7 @@ import org.wso2.carbon.identity.x509Certificate.validation.model.CACertificateInfo; import org.wso2.carbon.identity.x509Certificate.validation.service.CertificateValidationManagementService; +import java.util.ArrayList; import java.util.List; import static org.wso2.carbon.identity.api.server.certificate.validation.management.v1.util.ModelMapperUtil.mapApiModelToCertificateValidatorObject; @@ -41,6 +44,7 @@ */ public class ServerCertificateValidationManagementService { + private static final Log LOG = LogFactory.getLog(ServerCertificateValidationManagementService.class); private final CertificateValidationManagementService certificateValidationManagementService; public ServerCertificateValidationManagementService(CertificateValidationManagementService @@ -50,14 +54,27 @@ public ServerCertificateValidationManagementService(CertificateValidationManagem } /** - * Get the logger instance. + * Get validators. + * + * @return Validators. */ public Validators getValidators() { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving certificate validators for tenant: " + tenantDomain); + } try { List validators = - certificateValidationManagementService.getValidators(ContextLoader.getTenantDomainFromContext()); + certificateValidationManagementService.getValidators(tenantDomain); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved " + (validators != null ? validators.size() : 0) + + " validators for tenant: " + tenantDomain); + } + if (validators == null) { + validators = new ArrayList<>(); + } return mapValidatorsToApiModel(validators); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -72,11 +89,17 @@ public Validators getValidators() { */ public Validator getValidator(String name) { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving certificate validator with name: " + name + " for tenant: " + tenantDomain); + } try { org.wso2.carbon.identity.x509Certificate.validation.model.Validator validator = - certificateValidationManagementService - .getValidator(name, ContextLoader.getTenantDomainFromContext()); + certificateValidationManagementService.getValidator(name, tenantDomain); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved validator: " + name + " for tenant: " + tenantDomain); + } return mapValidatorToApiModel(validator); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -92,12 +115,17 @@ public Validator getValidator(String name) { */ public Validator updateValidator(String validatorName, Validator validator) { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating certificate validator: " + validatorName + " for tenant: " + tenantDomain); + } try { org.wso2.carbon.identity.x509Certificate.validation.model.Validator updatedValidator = certificateValidationManagementService .updateValidator(mapApiModelToCertificateValidatorObject(validator, validatorName), - ContextLoader.getTenantDomainFromContext()); + tenantDomain); + LOG.info("Successfully updated certificate validator: " + validatorName + " for tenant: " + tenantDomain); return mapValidatorToApiModel(updatedValidator); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -111,10 +139,21 @@ public Validator updateValidator(String validatorName, Validator validator) { */ public CACertificates getCACertificates() { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving CA certificates for tenant: " + tenantDomain); + } try { List caCertificates = certificateValidationManagementService - .getCACertificates(ContextLoader.getTenantDomainFromContext()); + .getCACertificates(tenantDomain); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved " + (caCertificates != null ? caCertificates.size() : 0) + + " CA certificates for tenant: " + tenantDomain); + } + if (caCertificates == null) { + caCertificates = new ArrayList<>(); + } return mapCACertificatesToApiModel(caCertificates); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -129,10 +168,17 @@ public CACertificates getCACertificates() { */ public CACertificate getCertificate(String certificateId) { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving CA certificate with ID: " + certificateId + " for tenant: " + tenantDomain); + } try { CACertificateInfo caCertificate = certificateValidationManagementService - .getCACertificate(certificateId, ContextLoader.getTenantDomainFromContext()); + .getCACertificate(certificateId, tenantDomain); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved CA certificate: " + certificateId + " for tenant: " + tenantDomain); + } return mapCACertificateToApiModel(caCertificate); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -147,11 +193,20 @@ public CACertificate getCertificate(String certificateId) { */ public CACertificate addCACertificate(String caCertificate) { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding CA certificate for tenant: " + tenantDomain); + } try { CACertificateInfo addedCACertificate = certificateValidationManagementService - .addCACertificate(caCertificate, - ContextLoader.getTenantDomainFromContext()); + .addCACertificate(caCertificate, tenantDomain); + LOG.info("Successfully added CA certificate with ID: " + (addedCACertificate != null ? + addedCACertificate.getCertId() : "null") + " for tenant: " + tenantDomain); + if (addedCACertificate == null) { + throw new CertificateValidationManagementException( + "Failed to retrieve added CA certificate information"); + } return mapCACertificateToApiModel(addedCACertificate); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -167,11 +222,15 @@ public CACertificate addCACertificate(String caCertificate) { */ public CACertificate updateCACertificate(String certificateId, String caCertificate) { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating CA certificate with ID: " + certificateId + " for tenant: " + tenantDomain); + } try { CACertificateInfo updatedCACertificate = certificateValidationManagementService - .updateCACertificate(certificateId, caCertificate, - ContextLoader.getTenantDomainFromContext()); + .updateCACertificate(certificateId, caCertificate, tenantDomain); + LOG.info("Successfully updated CA certificate: " + certificateId + " for tenant: " + tenantDomain); return mapCACertificateToApiModel(updatedCACertificate); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); @@ -185,9 +244,13 @@ public CACertificate updateCACertificate(String certificateId, String caCertific */ public void deleteCACertificate(String certificateId) { + String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting CA certificate with ID: " + certificateId + " for tenant: " + tenantDomain); + } try { - certificateValidationManagementService.deleteCACertificate(certificateId, - ContextLoader.getTenantDomainFromContext()); + certificateValidationManagementService.deleteCACertificate(certificateId, tenantDomain); + LOG.info("Successfully deleted CA certificate: " + certificateId + " for tenant: " + tenantDomain); } catch (CertificateValidationManagementException e) { throw CertificateValidationMgtEndpointUtil.handleCertificateValidationMgtException(e); } diff --git a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/factories/ServerCertificateValidationManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/factories/ServerCertificateValidationManagementServiceFactory.java index 9b5d4cbbd7..b0d0b6622c 100644 --- a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/factories/ServerCertificateValidationManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/factories/ServerCertificateValidationManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.certificate.validation.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.certificate.validation.management.common.CertificateValidationManagementServiceHolder; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.core.ServerCertificateValidationManagementService; import org.wso2.carbon.identity.x509Certificate.validation.service.CertificateValidationManagementService; @@ -27,17 +29,25 @@ */ public class ServerCertificateValidationManagementServiceFactory { + private static final Log LOG = LogFactory.getLog(ServerCertificateValidationManagementServiceFactory.class); private static final ServerCertificateValidationManagementService SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing ServerCertificateValidationManagementService factory"); + } CertificateValidationManagementService certificateValidationService = CertificateValidationManagementServiceHolder.getCertificateValidationService(); if (certificateValidationService == null) { + LOG.error("certificateValidationService is not available from OSGi context"); throw new IllegalStateException("certificateValidationService is not available from OSGi context."); } SERVICE = new ServerCertificateValidationManagementService(certificateValidationService); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully initialized ServerCertificateValidationManagementService factory"); + } } /** diff --git a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/impl/CertificateValidationApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/impl/CertificateValidationApiServiceImpl.java index 8677cbe888..fe4a52635b 100644 --- a/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/impl/CertificateValidationApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.certificate.validation.management/org.wso2.carbon.identity.api.server.certificate.validation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/certificate/validation/management/v1/impl/CertificateValidationApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.certificate.validation.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.CertificateValidationApiService; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.core.ServerCertificateValidationManagementService; import org.wso2.carbon.identity.api.server.certificate.validation.management.v1.factories.ServerCertificateValidationManagementServiceFactory; @@ -41,14 +43,19 @@ */ public class CertificateValidationApiServiceImpl implements CertificateValidationApiService { + private static final Log LOG = LogFactory.getLog(CertificateValidationApiServiceImpl.class); private final ServerCertificateValidationManagementService certificateValidationManagementService; public CertificateValidationApiServiceImpl() { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing CertificateValidationApiServiceImpl"); + } certificateValidationManagementService = ServerCertificateValidationManagementServiceFactory .getServerCertificateValidationManagementService(); } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating the certificate validation management service", e); throw new RuntimeException("Error occurred while initiating the certificate validation management service.", e); } @@ -57,42 +64,66 @@ public CertificateValidationApiServiceImpl() { @Override public Response addCACertificate(CACertificateAddRequest caCertificateAddRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Add CA certificate API endpoint called"); + } CACertificate caCertificate = certificateValidationManagementService .addCACertificate(caCertificateAddRequest.getCertificate()); URI location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + CERTIFICATE_VALIDATION_MANAGEMENT_PATH_COMPONENT + CERTIFICATE_MANAGEMENT_PATH_COMPONENT + PATH_SEPARATOR + caCertificate.getId()); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully processed add CA certificate request"); + } return Response.created(location).entity(caCertificate).build(); } @Override public Response deleteCACertificateById(String certificateId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Delete CA certificate API endpoint called for certificateId: " + certificateId); + } certificateValidationManagementService.deleteCACertificate(certificateId); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully processed delete CA certificate request for certificateId: " + certificateId); + } return Response.noContent().build(); } @Override public Response getCACertificateById(String certificateId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Get CA certificate API endpoint called for certificateId: " + certificateId); + } return Response.ok().entity(certificateValidationManagementService.getCertificate(certificateId)).build(); } @Override public Response getCACertificates() { + if (LOG.isDebugEnabled()) { + LOG.debug("Get CA certificates API endpoint called"); + } return Response.ok().entity(certificateValidationManagementService.getCACertificates()).build(); } @Override public Response getCertificateRevocationValidator(String validatorName) { + if (LOG.isDebugEnabled()) { + LOG.debug("Get certificate revocation validator API endpoint called for validatorName: " + validatorName); + } return Response.ok().entity(certificateValidationManagementService.getValidator(validatorName)).build(); } @Override public Response getCertificateRevocationValidators() { + if (LOG.isDebugEnabled()) { + LOG.debug("Get certificate revocation validators API endpoint called"); + } return Response.ok().entity(certificateValidationManagementService.getValidators()).build(); } @@ -100,6 +131,9 @@ public Response getCertificateRevocationValidators() { public Response updateCACertificateById(String certificateId, CACertificateUpdateRequest caCertificateUpdateRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Update CA certificate API endpoint called for certificateId: " + certificateId); + } return Response.ok().entity(certificateValidationManagementService.updateCACertificate(certificateId, caCertificateUpdateRequest.getCertificate())).build(); } @@ -107,6 +141,10 @@ public Response updateCACertificateById(String certificateId, @Override public Response updateCertificateRevocationValidator(String validatorName, Validator validator) { + if (LOG.isDebugEnabled()) { + LOG.debug("Update certificate revocation validator API endpoint called for validatorName: " + + validatorName); + } return Response.ok().entity(certificateValidationManagementService .updateValidator(validatorName, validator)).build(); } diff --git a/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/ContextLoader.java b/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/ContextLoader.java index 6139587d61..6b1bf1d1b8 100644 --- a/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/ContextLoader.java +++ b/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/ContextLoader.java @@ -53,6 +53,13 @@ public static String getTenantDomainFromContext() { String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; if (IdentityUtil.threadLocalProperties.get().get(TENANT_NAME_FROM_CONTEXT) != null) { tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(TENANT_NAME_FROM_CONTEXT); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved tenant domain from thread local context: " + tenantDomain); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Using default super tenant domain as no tenant context found."); + } } return tenantDomain; } @@ -64,7 +71,11 @@ public static String getTenantDomainFromContext() { */ public static String getUsernameFromContext() { - return PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved username from carbon context: " + (username != null ? "[username]" : "null")); + } + return username; } /** @@ -76,12 +87,19 @@ public static String getUsernameFromContext() { */ public static URI buildURIForBody(String endpoint) { + if (LOG.isDebugEnabled()) { + LOG.debug("Building URI for response body with endpoint: " + endpoint); + } String url; String context = getContext(endpoint); try { url = ServiceURLBuilder.create().addPath(context).build().getRelativePublicURL(); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully built relative URI for response body."); + } } catch (URLBuilderException e) { + LOG.error("Failed to build URL for response body with endpoint: " + endpoint, e); String errorDescription = "Server encountered an error while building URL for response body."; throw buildInternalServerError(e, errorDescription); } @@ -98,13 +116,20 @@ public static URI buildURIForBody(String endpoint) { */ public static URI buildURIForHeader(String endpoint) { + if (LOG.isDebugEnabled()) { + LOG.debug("Building URI for response header with endpoint: " + endpoint); + } URI loc; String context = getContext(endpoint); try { String url = ServiceURLBuilder.create().addPath(context).build().getAbsolutePublicURL(); loc = URI.create(url); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully built absolute URI for response header."); + } } catch (URLBuilderException e) { + LOG.error("Failed to build URL for response header with endpoint: " + endpoint, e); String errorDescription = "Server encountered an error while building URL for response header."; throw buildInternalServerError(e, errorDescription); } diff --git a/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/Util.java b/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/Util.java index 31ff32fc0c..d8109e4ed4 100644 --- a/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/Util.java +++ b/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/Util.java @@ -17,6 +17,8 @@ package org.wso2.carbon.identity.api.server.common; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.slf4j.MDC; import java.nio.charset.StandardCharsets; @@ -30,6 +32,7 @@ */ public class Util { + private static final Log LOG = LogFactory.getLog(Util.class); private static final String PAGE_LINK_REL_NEXT = "next"; private static final String PAGE_LINK_REL_PREVIOUS = "previous"; private static final String PAGINATION_LINK_FORMAT = Constants.V1_API_PATH_COMPONENT @@ -44,9 +47,14 @@ public static String getCorrelation() { String ref; if (isCorrelationIDPresent()) { ref = MDC.get(Constants.CORRELATION_ID_MDC); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved existing correlation ID from MDC."); + } } else { ref = UUID.randomUUID().toString(); - + if (LOG.isDebugEnabled()) { + LOG.debug("Generated new correlation ID as none was present in MDC."); + } } return ref; } @@ -68,6 +76,9 @@ public static boolean isCorrelationIDPresent() { */ public static String base64URLEncode(String value) { + if (LOG.isDebugEnabled()) { + LOG.debug("Performing Base64 URL encoding."); + } return Base64.getUrlEncoder() .withoutPadding() .encodeToString(value.getBytes(StandardCharsets.UTF_8)); @@ -81,6 +92,9 @@ public static String base64URLEncode(String value) { */ public static String base64URLDecode(String value) { + if (LOG.isDebugEnabled()) { + LOG.debug("Performing Base64 URL decoding."); + } return new String( Base64.getUrlDecoder().decode(value), StandardCharsets.UTF_8); @@ -100,6 +114,10 @@ public static String base64URLDecode(String value) { public static Map buildPaginationLinks(int limit, int currentOffset, int totalResultsFromSearch, String servicePathComponent) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Building pagination links with limit: %d, offset: %d, total: %d", + limit, currentOffset, totalResultsFromSearch)); + } Map links = new HashMap<>(); // Next link. @@ -143,6 +161,11 @@ public static Map buildPaginationLinks(int limit, int currentOff String servicePathComponent, String requiredAttributes, String filter) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Building pagination links with limit: %d, offset: %d, total: %d, " + + "attributes: %s, filter: %s", limit, currentOffset, totalResultsFromSearch, + requiredAttributes != null ? "[provided]" : "null", filter != null ? "[provided]" : "null")); + } Map links = new HashMap<>(); StringBuilder otherParams = new StringBuilder(); @@ -203,6 +226,10 @@ private static int calculateOffsetForPreviousLink(int offset, int limit, int tot */ public static String getMediaType(String fileType) { + if (LOG.isDebugEnabled()) { + LOG.debug("Resolving media type for file type: " + (fileType != null ? fileType : "null")); + } + if (containsValidMediaType(fileType, Constants.VALID_MEDIA_TYPES_XML)) { return Constants.MEDIA_TYPE_XML; } else if (containsValidMediaType(fileType, Constants.VALID_MEDIA_TYPES_JSON)) { @@ -210,6 +237,10 @@ public static String getMediaType(String fileType) { } else if (containsValidMediaType(fileType, Constants.VALID_MEDIA_TYPES_YAML)) { return Constants.MEDIA_TYPE_YAML; } + + if (LOG.isDebugEnabled()) { + LOG.debug("Unsupported media type for file type: " + (fileType != null ? fileType : "null")); + } return Constants.MEDIA_TYPE_UNSUPPORTED; } diff --git a/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/function/UserIdtoUser.java b/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/function/UserIdtoUser.java index 5beda25e46..1f06e771cb 100644 --- a/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/function/UserIdtoUser.java +++ b/components/org.wso2.carbon.identity.api.server.common/src/main/java/org/wso2/carbon/identity/api/server/common/function/UserIdtoUser.java @@ -40,15 +40,22 @@ public class UserIdtoUser implements Function { @Override public User apply(String... args) { + if (log.isDebugEnabled()) { + log.debug("Extracting user from provided arguments."); + } return extractUser(args[0], args[1]); } private User extractUser(String userId, String tenantDomain) { try { + if (log.isDebugEnabled()) { + log.debug("Processing user extraction for tenant domain: " + tenantDomain); + } String decodedUsername = new String(Base64.getDecoder().decode(userId), StandardCharsets.UTF_8); if (StringUtils.isBlank(userId)) { + log.warn("Empty or blank userId provided for user extraction."); throw new WebApplicationException("UserID is empty."); } String[] strComponent = decodedUsername.split("/"); @@ -58,10 +65,17 @@ private User extractUser(String userId, String tenantDomain) { if (strComponent.length == 1) { username = strComponent[0]; + if (log.isDebugEnabled()) { + log.debug("Extracted username without realm from userId for tenant: " + tenantDomain); + } } else if (strComponent.length == 2) { realm = strComponent[0]; username = strComponent[1]; + if (log.isDebugEnabled()) { + log.debug("Extracted username and realm from userId for tenant: " + tenantDomain); + } } else { + log.warn("Invalid userId format provided. Expected format: username or realm/username"); throw new WebApplicationException("Provided UserID is " + "not in the correct format."); } @@ -70,8 +84,13 @@ private User extractUser(String userId, String tenantDomain) { user.setUserStoreDomain(realm); user.setTenantDomain(tenantDomain); + if (log.isDebugEnabled()) { + log.debug("Successfully created user object for tenant: " + tenantDomain); + } return user; } catch (Exception e) { + log.error("Failed to extract user from userId for tenant: " + + (tenantDomain != null ? tenantDomain : "null"), e); throw new APIError(Response.Status.BAD_REQUEST, new ErrorResponse.Builder().withCode(Constants.ErrorMessages.ERROR_CODE_INVALID_USERNAME.getCode()) .withMessage(Constants.ErrorMessages.ERROR_CODE_INVALID_USERNAME.getMessage()) diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/ConfigsServiceHolder.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/ConfigsServiceHolder.java index a54538e2d3..1c9726bc53 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/ConfigsServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/ConfigsServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.configs.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.api.ServerConfigurationService; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; @@ -35,6 +37,8 @@ */ public class ConfigsServiceHolder { + private static final Log log = LogFactory.getLog(ConfigsServiceHolder.class); + private ConfigsServiceHolder() {} private static class ApplicationManagementServiceHolder { @@ -101,6 +105,9 @@ private static class ClaimMetaDataManagementServiceHolder { */ public static ApplicationManagementService getApplicationManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ApplicationManagementService from OSGi context."); + } return ApplicationManagementServiceHolder.SERVICE; } @@ -111,6 +118,9 @@ public static ApplicationManagementService getApplicationManagementService() { */ public static IdentityProviderManager getIdentityProviderManager() { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdentityProviderManager from OSGi context."); + } return IdentityProviderManagerHolder.SERVICE; } @@ -121,6 +131,9 @@ public static IdentityProviderManager getIdentityProviderManager() { */ public static CORSManagementService getCorsManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving CORSManagementService from OSGi context."); + } return CORSManagementServiceHolder.SERVICE; } @@ -131,6 +144,9 @@ public static CORSManagementService getCorsManagementService() { */ public static RemoteLoggingConfigService getRemoteLoggingConfigService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving RemoteLoggingConfigService from OSGi context."); + } return RemoteLoggingConfigServiceHolder.SERVICE; } @@ -141,6 +157,9 @@ public static RemoteLoggingConfigService getRemoteLoggingConfigService() { */ public static ImpersonationConfigMgtService getImpersonationConfigMgtService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ImpersonationConfigMgtService from OSGi context."); + } return ImpersonationConfigMgtServiceHolder.SERVICE; } @@ -151,6 +170,9 @@ public static ImpersonationConfigMgtService getImpersonationConfigMgtService() { */ public static DCRConfigurationMgtService getDcrConfigurationMgtService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving DCRConfigurationMgtService from OSGi context."); + } return DCRConfigurationMgtServiceHolder.SERVICE; } @@ -161,6 +183,9 @@ public static DCRConfigurationMgtService getDcrConfigurationMgtService() { */ public static JWTClientAuthenticatorMgtService getJWTClientAuthenticatorMgtService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving JWTClientAuthenticatorMgtService from OSGi context."); + } return JWTClientAuthenticatorMgtServiceHolder.SERVICE; } @@ -171,6 +196,9 @@ public static JWTClientAuthenticatorMgtService getJWTClientAuthenticatorMgtServi */ public static ServerConfigurationService getServerConfigurationService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ServerConfigurationService from OSGi context."); + } return ServerConfigurationServiceHolder.SERVICE; } @@ -181,6 +209,9 @@ public static ServerConfigurationService getServerConfigurationService() { */ public static ClaimMetadataManagementService getClaimMetadataManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ClaimMetadataManagementService from OSGi context."); + } return ClaimMetaDataManagementServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/Utils.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/Utils.java index 3baf469b6a..9940e61989 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/Utils.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.common/src/main/java/org/wso2/carbon/identity/api/server/configs/common/Utils.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.configs.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; import org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim; @@ -28,6 +30,8 @@ */ public class Utils { + private static final Log log = LogFactory.getLog(Utils.class); + private Utils() {} /** @@ -40,10 +44,21 @@ private Utils() {} public static List getExternalClaims(String externalClaimDialect, String tenantDomain) throws ClaimMetadataException { + if (log.isDebugEnabled()) { + log.debug("Retrieving external claims for dialect: " + externalClaimDialect + + " in tenant domain: " + tenantDomain); + } try { - return ConfigsServiceHolder.getClaimMetadataManagementService(). + List externalClaims = ConfigsServiceHolder.getClaimMetadataManagementService(). getExternalClaims(externalClaimDialect, tenantDomain); + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved " + (externalClaims != null ? externalClaims.size() : 0) + + " external claims for dialect: " + externalClaimDialect); + } + return externalClaims; } catch (ClaimMetadataException e) { + log.error("Error while retrieving external claims for dialect: " + externalClaimDialect + + " in tenant domain: " + tenantDomain, e); throw new ClaimMetadataException("Error while retrieving external claims.", e); } } diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java index b420eade8a..97e08bcd10 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/core/ServerConfigManagementService.java @@ -229,6 +229,9 @@ public Authenticator getAuthenticator(String authenticatorId) { */ public ServerConfig getConfigs() { + if (log.isDebugEnabled()) { + log.debug("Retrieving server configurations."); + } IdentityProvider residentIdP = getResidentIdP(); UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm(); @@ -286,6 +289,9 @@ public ServerConfig getConfigs() { */ public void patchConfigs(List patchRequest) { + if (log.isDebugEnabled()) { + log.debug("Patching server configurations with " + patchRequest.size() + " patches."); + } try { if (OrganizationManagementUtil.isOrganization(ContextLoader.getTenantDomainFromContext())) { throw handleException(Response.Status.FORBIDDEN, Constants.ErrorMessage @@ -370,6 +376,9 @@ public ImpersonationConfiguration getImpersonationConfiguration() { // Retrieve the tenant domain from the current context String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Retrieving impersonation configuration for tenant: " + tenantDomain); + } ImpersonationConfiguration impersonationConfiguration = new ImpersonationConfiguration(); try { // Get the impersonation configuration for the tenant domain diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/factories/ServerConfigManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/factories/ServerConfigManagementServiceFactory.java index f4c5e4fc76..d03bdded6c 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/factories/ServerConfigManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/factories/ServerConfigManagementServiceFactory.java @@ -1,5 +1,7 @@ package org.wso2.carbon.identity.api.server.configs.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.configs.common.ConfigsServiceHolder; import org.wso2.carbon.identity.api.server.configs.v1.core.ServerConfigManagementService; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; @@ -17,9 +19,12 @@ */ public class ServerConfigManagementServiceFactory { + private static final Log log = LogFactory.getLog(ServerConfigManagementServiceFactory.class); private static final ServerConfigManagementService SERVICE; static { + log.info("Initializing ServerConfigManagementService factory."); + ApplicationManagementService applicationManagementService = ConfigsServiceHolder .getApplicationManagementService(); IdentityProviderManager identityProviderManager = getIdentityProviderManager(); @@ -32,30 +37,37 @@ public class ServerConfigManagementServiceFactory { DCRConfigurationMgtService dcrConfigurationMgtService = ConfigsServiceHolder.getDcrConfigurationMgtService(); if (applicationManagementService == null) { + log.error("ApplicationManagementService is not available from OSGi context."); throw new IllegalStateException("ApplicationManagementService is not available from OSGi context."); } if (identityProviderManager == null) { + log.error("IdentityProviderManager is not available from OSGi context."); throw new IllegalStateException("IdentityProviderManager is not available from OSGi context."); } if (corsManagementService == null) { + log.error("CORSManagementService is not available from OSGi context."); throw new IllegalStateException("CORSManagementService is not available from OSGi context."); } if (remoteLoggingConfigService == null) { + log.error("RemoteLoggingConfigService is not available from OSGi context."); throw new IllegalStateException("RemoteLoggingConfigService is not available from OSGi context."); } if (impersonationConfigMgtService == null) { + log.error("ImpersonationConfigMgtService is not available from OSGi context."); throw new IllegalStateException("ImpersonationConfigMgtService is not available from OSGi context."); } if (jwtClientAuthenticatorMgtService == null) { + log.error("JWTClientAuthenticatorMgtService is not available from OSGi context."); throw new IllegalStateException("JWTClientAuthenticatorMgtService is not available from OSGi context."); } if (dcrConfigurationMgtService == null) { + log.error("DCRConfigurationMgtService is not available from OSGi context."); throw new IllegalStateException("DCRConfigurationMgtService is not available from OSGi context."); } @@ -65,6 +77,8 @@ public class ServerConfigManagementServiceFactory { impersonationConfigMgtService, dcrConfigurationMgtService, jwtClientAuthenticatorMgtService); + + log.info("ServerConfigManagementService initialized successfully."); } /** diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/CORSConfigurationToCORSConfig.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/CORSConfigurationToCORSConfig.java index 7947adbbeb..f8798dbfbb 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/CORSConfigurationToCORSConfig.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/CORSConfigurationToCORSConfig.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.configs.v1.function; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.configs.v1.model.CORSConfig; import org.wso2.carbon.identity.cors.mgt.core.model.CORSConfiguration; @@ -31,9 +33,15 @@ */ public class CORSConfigurationToCORSConfig implements Function { + private static final Log log = LogFactory.getLog(CORSConfigurationToCORSConfig.class); + @Override public CORSConfig apply(CORSConfiguration corsConfiguration) { + if (log.isDebugEnabled()) { + log.debug("Converting CORSConfiguration to CORSConfig."); + } + CORSConfig corsConfig = new CORSConfig(); corsConfig.setAllowGenericHttpRequests(corsConfiguration.isAllowGenericHttpRequests()); corsConfig.setAllowAnyOrigin(corsConfiguration.isAllowAnyOrigin()); diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/DCRConnectorUtil.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/DCRConnectorUtil.java index fa55d9de57..eea239191a 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/DCRConnectorUtil.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/DCRConnectorUtil.java @@ -48,6 +48,9 @@ public class DCRConnectorUtil { */ public static DCRConfig getDCRConfig(DCRConfigurationMgtService dcrConfigurationMgtService) throws DCRMException { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving DCR configuration."); + } DCRConfiguration dcrConfiguration = dcrConfigurationMgtService.getDCRConfiguration(); return dcrConfigurationToDCRConfig(dcrConfiguration); @@ -62,11 +65,17 @@ public static DCRConfig getDCRConfig(DCRConfigurationMgtService dcrConfiguration public static void setDCRConfig(DCRConfig dcrConfig, DCRConfigurationMgtService dcrConfigurationMgtService) throws DCRMException { + if (LOG.isDebugEnabled()) { + LOG.debug("Setting DCR configuration."); + } dcrConfigurationMgtService.setDCRConfiguration((getDCRConfigurationFromDCRConfig(dcrConfig))); } private static DCRConfig dcrConfigurationToDCRConfig(DCRConfiguration dcrConfiguration) { + if (LOG.isDebugEnabled()) { + LOG.debug("Converting DCRConfiguration to DCRConfig."); + } DCRConfig dcrConfig = new DCRConfig(); dcrConfig.setAuthenticationRequired(dcrConfiguration.getAuthenticationRequired()); dcrConfig.setEnableFapiEnforcement(dcrConfiguration.getEnableFapiEnforcement()); diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/JWTConnectorUtil.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/JWTConnectorUtil.java index 84b49f040d..1598199426 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/JWTConnectorUtil.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/function/JWTConnectorUtil.java @@ -54,7 +54,9 @@ public static JWTValidatorConfig getJWTValidatorConfig(String tenantDomain, JWTClientAuthenticatorMgtService jwtClientAuthenticatorMgtService) throws Exception { - + if (log.isDebugEnabled()) { + log.debug("Retrieving JWT validator configuration for tenant: " + tenantDomain); + } return new JWTValidatorConfig().enableTokenReuse(jwtClientAuthenticatorMgtService. getPrivateKeyJWTClientAuthenticatorConfiguration(tenantDomain).isEnableTokenReuse()); } @@ -67,6 +69,9 @@ public static JWTValidatorConfig getJWTValidatorConfig(String tenantDomain, */ public static JWTClientAuthenticatorConfig getJWTDaoConfig(JWTValidatorConfig jwtValidatorConfig) { + if (log.isDebugEnabled()) { + log.debug("Converting JWTValidatorConfig to JWTClientAuthenticatorConfig."); + } JWTClientAuthenticatorConfig jwtClientAuthenticatorConfig = new JWTClientAuthenticatorConfig(); jwtClientAuthenticatorConfig.setEnableTokenReuse(jwtValidatorConfig.getEnableTokenReuse()); return jwtClientAuthenticatorConfig; diff --git a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/impl/ConfigsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/impl/ConfigsApiServiceImpl.java index 0fb96e454e..a99b035d85 100644 --- a/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/impl/ConfigsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.configs/org.wso2.carbon.identity.api.server.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/configs/v1/impl/ConfigsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.configs.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.configs.v1.ConfigsApiService; import org.wso2.carbon.identity.api.server.configs.v1.core.ServerConfigManagementService; import org.wso2.carbon.identity.api.server.configs.v1.factories.ServerConfigManagementServiceFactory; @@ -43,13 +45,16 @@ */ public class ConfigsApiServiceImpl implements ConfigsApiService { + private static final Log log = LogFactory.getLog(ConfigsApiServiceImpl.class); private final ServerConfigManagementService configManagementService; public ConfigsApiServiceImpl() { try { configManagementService = ServerConfigManagementServiceFactory.getServerConfigManagementService(); + log.info("Server config management service initialized successfully."); } catch (Exception e) { + log.error("Error occurred while initiating server config management services.", e); throw new RuntimeException("Error occurred while initiating server config management services.", e); } } @@ -57,47 +62,55 @@ public ConfigsApiServiceImpl() { @Override public Response getAuthenticator(String authenticatorId) { + log.info("Retrieving authenticator configuration for authenticatorId: " + authenticatorId); return Response.ok().entity(configManagementService.getAuthenticator(authenticatorId)).build(); } @Override public Response getCORSConfiguration() { + log.info("Retrieving CORS configuration."); return Response.ok().entity(configManagementService.getCORSConfiguration()).build(); } @Override public Response getConfigs() { + log.info("Retrieving server configurations."); return Response.ok().entity(configManagementService.getConfigs()).build(); } @Override public Response getHomeRealmIdentifiers() { + log.info("Retrieving home realm identifiers."); return Response.ok().entity(configManagementService.getHomeRealmIdentifiers()).build(); } @Override public Response getImpersonationConfiguration() { + log.info("Retrieving impersonation configuration."); return Response.ok().entity(configManagementService.getImpersonationConfiguration()).build(); } @Override public Response getInboundScimConfigs() { + log.info("Retrieving inbound SCIM configurations."); return Response.ok().entity(configManagementService.getInboundScimConfig()).build(); } @Override public Response getSchema(String schemaId) { + log.info("Retrieving schema configuration for schemaId: " + schemaId); return Response.ok().entity(configManagementService.getSchema(schemaId)).build(); } @Override public Response getPrivatKeyJWTValidationConfiguration() { + log.info("Retrieving private key JWT validation configuration."); return Response.ok().entity(configManagementService.getPrivateKeyJWTValidatorConfiguration()).build(); } @@ -105,6 +118,7 @@ public Response getPrivatKeyJWTValidationConfiguration() { @Override public Response getDCRConfiguration() { + log.info("Retrieving DCR configuration."); return Response.ok().entity(configManagementService.getDCRConfiguration()).build(); } @@ -112,11 +126,15 @@ public Response getDCRConfiguration() { @Override public Response getRemoteLoggingConfig(String logType) { + log.info("Retrieving remote logging configuration for logType: " + logType); RemoteServerLoggerData remoteServerLoggerResponseData = configManagementService.getRemoteServerConfig(logType); if (remoteServerLoggerResponseData != null) { return Response.ok().entity(createRemoteLoggingConfig(remoteServerLoggerResponseData)).build(); } else { + if (log.isDebugEnabled()) { + log.debug("Remote logging configuration not found for logType: " + logType); + } return Response.status(Response.Status.NOT_FOUND).build(); } } @@ -124,6 +142,7 @@ public Response getRemoteLoggingConfig(String logType) { @Override public Response getRemoteLoggingConfigs() { + log.info("Retrieving all remote logging configurations."); List remoteServerLoggerResponseData = configManagementService.getRemoteServerConfigs(); return Response.ok() @@ -134,6 +153,8 @@ public Response getRemoteLoggingConfigs() { @Override public Response patchPrivatKeyJWTValidationConfiguration(List jwTKeyValidatorPatch) { + log.info("Updating private key JWT validation configuration with " + jwTKeyValidatorPatch.size() + + " patches."); configManagementService.patchPrivateKeyJWTValidatorSConfig(jwTKeyValidatorPatch); return Response.ok().build(); } @@ -141,6 +162,7 @@ public Response patchPrivatKeyJWTValidationConfiguration(List dcrPatch) { + log.info("Updating DCR configuration with " + dcrPatch.size() + " patches."); configManagementService.patchDCRConfig(dcrPatch); return Response.ok().build(); } @@ -148,6 +170,7 @@ public Response patchDCRConfiguration(List dcrPatch) { @Override public Response restoreServerRemoteLoggingConfiguration(String logType) { + log.info("Restoring remote logging configuration for logType: " + logType); configManagementService.resetRemoteServerConfig(logType); return Response.noContent().build(); } @@ -155,6 +178,7 @@ public Response restoreServerRemoteLoggingConfiguration(String logType) { @Override public Response restoreServerRemoteLoggingConfigurations() { + log.info("Restoring all remote logging configurations."); configManagementService.resetRemoteServerConfig(); return Response.noContent().build(); } @@ -162,18 +186,21 @@ public Response restoreServerRemoteLoggingConfigurations() { @Override public Response getSchemas() { + log.info("Retrieving all schemas."); return Response.ok().entity(configManagementService.getSchemas()).build(); } @Override public Response listAuthenticators(String type) { + log.info("Retrieving authenticators for type: " + type); return Response.ok().entity(configManagementService.getAuthenticators(type)).build(); } @Override public Response patchCORSConfiguration(List coRSPatch) { + log.info("Updating CORS configuration with " + coRSPatch.size() + " patches."); configManagementService.patchCORSConfig(coRSPatch); return Response.ok().build(); } @@ -181,6 +208,7 @@ public Response patchCORSConfiguration(List coRSPatch) { @Override public Response patchConfigs(List patch) { + log.info("Updating server configurations with " + patch.size() + " patches."); configManagementService.patchConfigs(patch); return Response.ok().build(); } @@ -188,6 +216,7 @@ public Response patchConfigs(List patch) { @Override public Response patchImpersonationConfiguration(List impersonationPatch) { + log.info("Updating impersonation configuration with " + impersonationPatch.size() + " patches."); configManagementService.patchImpersonationConfiguration(impersonationPatch); return Response.ok().build(); } @@ -195,6 +224,7 @@ public Response patchImpersonationConfiguration(List imperso @Override public Response deleteImpersonationConfiguration() { + log.info("Deleting impersonation configuration."); configManagementService.deleteImpersonationConfiguration(); return Response.noContent().build(); } @@ -202,6 +232,7 @@ public Response deleteImpersonationConfiguration() { @Override public Response updateInboundScimConfigs(ScimConfig scimConfig) { + log.info("Updating inbound SCIM configurations."); configManagementService.updateInboundScimConfigs(scimConfig); return Response.ok().build(); } @@ -209,6 +240,7 @@ public Response updateInboundScimConfigs(ScimConfig scimConfig) { @Override public Response updateRemoteLoggingConfig(String logType, RemoteLoggingConfig remoteLoggingConfig) { + log.info("Updating remote logging configuration for logType: " + logType); configManagementService.updateRemoteLoggingConfig(logType, remoteLoggingConfig); return Response.accepted().build(); } @@ -216,6 +248,7 @@ public Response updateRemoteLoggingConfig(String logType, RemoteLoggingConfig re @Override public Response updateRemoteLoggingConfigs(List remoteLoggingConfigListItem) { + log.info("Updating " + remoteLoggingConfigListItem.size() + " remote logging configurations."); configManagementService.updateRemoteLoggingConfigs(remoteLoggingConfigListItem); return Response.accepted().build(); } @@ -223,12 +256,14 @@ public Response updateRemoteLoggingConfigs(List rem @Override public Response getSAMLInboundAuthConfig() { + log.info("Retrieving SAML inbound authentication configuration."); return Response.ok().entity(configManagementService.getSAMLInboundAuthConfig()).build(); } @Override public Response updateSAMLInboundAuthConfig(InboundAuthSAML2Config inboundAuthSAML2Config) { + log.info("Updating SAML inbound authentication configuration."); configManagementService.updateSAMLInboundAuthConfig(inboundAuthSAML2Config); return Response.ok().build(); } @@ -236,12 +271,14 @@ public Response updateSAMLInboundAuthConfig(InboundAuthSAML2Config inboundAuthSA @Override public Response getPassiveSTSInboundAuthConfig() { + log.info("Retrieving Passive STS inbound authentication configuration."); return Response.ok().entity(configManagementService.getPassiveSTSInboundAuthConfig()).build(); } @Override public Response updatePassiveSTSInboundAuthConfig(InboundAuthPassiveSTSConfig inboundAuthPassiveSTSConfig) { + log.info("Updating Passive STS inbound authentication configuration."); configManagementService.updatePassiveSTSInboundAuthConfig(inboundAuthPassiveSTSConfig); return Response.ok().build(); } @@ -254,6 +291,7 @@ public Response updatePassiveSTSInboundAuthConfig(InboundAuthPassiveSTSConfig in @Override public Response deletePassiveSTSInboundAuthConfig() { + log.info("Deleting Passive STS inbound authentication configuration."); configManagementService.deletePassiveSTSInboundAuthConfig(); return Response.noContent().build(); } @@ -266,6 +304,7 @@ public Response deletePassiveSTSInboundAuthConfig() { @Override public Response deleteSAMLInboundAuthConfig() { + log.info("Deleting SAML inbound authentication configuration."); configManagementService.deleteSAMLInboundAuthConfig(); return Response.noContent().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.common/src/main/java/org/wso2/carbon/identity/api/server/cors/common/CORSServiceHolder.java b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.common/src/main/java/org/wso2/carbon/identity/api/server/cors/common/CORSServiceHolder.java index 9f15689a0c..590ab25740 100644 --- a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.common/src/main/java/org/wso2/carbon/identity/api/server/cors/common/CORSServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.common/src/main/java/org/wso2/carbon/identity/api/server/cors/common/CORSServiceHolder.java @@ -16,6 +16,8 @@ package org.wso2.carbon.identity.api.server.cors.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.cors.mgt.core.CORSManagementService; @@ -24,6 +26,8 @@ */ public class CORSServiceHolder { + private static final Log log = LogFactory.getLog(CORSServiceHolder.class); + private CORSServiceHolder() {} private static class CORSManagementServiceHolder { @@ -39,6 +43,12 @@ private static class CORSManagementServiceHolder { */ public static CORSManagementService getCorsManagementService() { - return CORSManagementServiceHolder.SERVICE; + CORSManagementService service = CORSManagementServiceHolder.SERVICE; + if (service == null) { + log.warn("CORSManagementService is not available. CORS configurations may not function properly."); + } else if (log.isDebugEnabled()) { + log.debug("CORSManagementService retrieved successfully."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/core/CORSService.java b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/core/CORSService.java index a04e78b7cd..f58e2eced5 100644 --- a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/core/CORSService.java +++ b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/core/CORSService.java @@ -65,17 +65,28 @@ public List getAssociatedAppsByCORSOrigin(String corsOrig try { String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Retrieving associated applications for CORS origin: " + corsOriginId + + " in tenant: " + tenantDomain); + } List corsOriginIdList = corsManagementService.getTenantCORSOrigins(tenantDomain) .stream().map(CORSOrigin::getId).collect(Collectors.toList()); // Throw an exception if corsOriginId is not valid. if (!corsOriginIdList.contains(corsOriginId)) { + if (log.isDebugEnabled()) { + log.debug("Invalid CORS origin ID provided: " + corsOriginId); + } throw new CORSManagementServiceClientException(String.format(ERROR_CODE_INVALID_CORS_ORIGIN_ID .description(), corsOriginId), ERROR_CODE_INVALID_CORS_ORIGIN_ID.code()); } List applicationList = corsManagementService .getCORSApplicationsByCORSOriginId(corsOriginId, tenantDomain); + if (log.isDebugEnabled()) { + log.debug("Found " + applicationList.size() + " applications associated with CORS origin: " + + corsOriginId); + } return applicationList.stream().map(new CORSApplicationToCORSApplicationObject()) .collect(Collectors.toList()); } catch (CORSManagementServiceException e) { @@ -92,7 +103,13 @@ public List getCORSOrigins() { try { String tenantDomain = ContextLoader.getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Retrieving CORS origins for tenant: " + tenantDomain); + } List corsOriginList = corsManagementService.getTenantCORSOrigins(tenantDomain); + if (log.isDebugEnabled()) { + log.debug("Found " + corsOriginList.size() + " CORS origins for tenant: " + tenantDomain); + } return corsOriginList.stream().map(new CORSOriginToCORSOriginObject()).collect(Collectors.toList()); } catch (CORSManagementServiceException e) { throw handleCORSException(e, Constants.ErrorMessage.ERROR_CODE_CORS_RETRIEVE, null); diff --git a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/factories/CORSServiceFactory.java b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/factories/CORSServiceFactory.java index ed61ef5972..cc7ffea26d 100644 --- a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/factories/CORSServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/factories/CORSServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.cors.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.cors.common.CORSServiceHolder; import org.wso2.carbon.identity.api.server.cors.v1.core.CORSService; import org.wso2.carbon.identity.cors.mgt.core.CORSManagementService; @@ -27,16 +29,24 @@ */ public class CORSServiceFactory { + private static final Log log = LogFactory.getLog(CORSServiceFactory.class); private static final CORSService SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing CORS service factory."); + } CORSManagementService corsManagementService = CORSServiceHolder.getCorsManagementService(); if (corsManagementService == null) { + log.error("CORSManagementService is not available from OSGi context."); throw new IllegalStateException("CORSManagementService is not available from OSGi context."); } SERVICE = new CORSService(corsManagementService); + if (log.isDebugEnabled()) { + log.debug("CORS service factory initialized successfully."); + } } /** @@ -46,6 +56,9 @@ public class CORSServiceFactory { */ public static CORSService getCORSService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving CORS service instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSApplicationToCORSApplicationObject.java b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSApplicationToCORSApplicationObject.java index 792f0e4b56..755192aed1 100644 --- a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSApplicationToCORSApplicationObject.java +++ b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSApplicationToCORSApplicationObject.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.cors.v1.function; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.cors.v1.model.CORSApplicationObject; import org.wso2.carbon.identity.cors.mgt.core.model.CORSApplication; @@ -28,9 +30,21 @@ */ public class CORSApplicationToCORSApplicationObject implements Function { + private static final Log log = LogFactory.getLog(CORSApplicationToCORSApplicationObject.class); + @Override public CORSApplicationObject apply(CORSApplication corsApplication) { + if (corsApplication == null) { + if (log.isDebugEnabled()) { + log.debug("CORS application is null, returning null"); + } + return null; + } + + if (log.isDebugEnabled()) { + log.debug("Converting CORS application: " + corsApplication.getName()); + } CORSApplicationObject corsApplicationObject = new CORSApplicationObject(); corsApplicationObject.setId(corsApplication.getId()); corsApplicationObject.setName(corsApplication.getName()); diff --git a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSOriginToCORSOriginObject.java b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSOriginToCORSOriginObject.java index 12d99623b5..c57a5c217a 100644 --- a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSOriginToCORSOriginObject.java +++ b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/function/CORSOriginToCORSOriginObject.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.cors.v1.function; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.cors.v1.model.CORSOriginObject; import org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin; @@ -28,9 +30,21 @@ */ public class CORSOriginToCORSOriginObject implements Function { + private static final Log log = LogFactory.getLog(CORSOriginToCORSOriginObject.class); + @Override public CORSOriginObject apply(CORSOrigin corsOrigin) { + if (corsOrigin == null) { + if (log.isDebugEnabled()) { + log.debug("CORS origin is null, returning null"); + } + return null; + } + + if (log.isDebugEnabled()) { + log.debug("Converting CORS origin: " + corsOrigin.getOrigin()); + } CORSOriginObject corsOriginGetObject = new CORSOriginObject(); corsOriginGetObject.setId(corsOrigin.getId()); corsOriginGetObject.setUrl(corsOrigin.getOrigin()); diff --git a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/impl/CorsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/impl/CorsApiServiceImpl.java index c0bb7603e0..3ce120841e 100644 --- a/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/impl/CorsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.cors/org.wso2.carbon.identity.api.server.cors.v1/src/main/java/org/wso2/carbon/identity/api/server/cors/v1/impl/CorsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.cors.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.cors.v1.CorsApiService; import org.wso2.carbon.identity.api.server.cors.v1.core.CORSService; import org.wso2.carbon.identity.api.server.cors.v1.factories.CORSServiceFactory; @@ -29,13 +31,21 @@ */ public class CorsApiServiceImpl implements CorsApiService { + private static final Log log = LogFactory.getLog(CorsApiServiceImpl.class); private final CORSService corsService; public CorsApiServiceImpl() { try { + if (log.isDebugEnabled()) { + log.debug("Initializing CORS API service implementation."); + } this.corsService = CORSServiceFactory.getCORSService(); + if (log.isDebugEnabled()) { + log.debug("CORS API service implementation initialized successfully."); + } } catch (IllegalStateException e) { + log.error("Error occurred while initiating API CORS management service.", e); throw new RuntimeException("Error occurred while initiating API CORS management service.", e); } } @@ -43,12 +53,18 @@ public CorsApiServiceImpl() { @Override public Response getAssociatedAppsByCORSOrigin(String corsOriginId) { + if (log.isDebugEnabled()) { + log.debug("Retrieving associated applications for CORS origin ID: " + corsOriginId); + } return Response.ok().entity(corsService.getAssociatedAppsByCORSOrigin(corsOriginId)).build(); } @Override public Response getCORSOrigins() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all CORS origins for the tenant."); + } return Response.ok().entity(corsService.getCORSOrigins()).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/Constants.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/Constants.java index acf47dd186..778274530a 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/Constants.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/Constants.java @@ -108,7 +108,13 @@ public enum ErrorMessage { ERROR_ATTRIBUTE_NOT_SUPPORTED("50006", Status.BAD_REQUEST, "Attribute type not found", "Invalid attribute for email templates. Supported attributes are: 'templates', " + "'templates.id', 'templates.contentType', 'templates.subject', 'templates.body' " + - "and 'templates.footer'."); + "and 'templates.footer'."), + ERROR_EMAIL_TEMPLATE_REQUIRED("50007", Status.BAD_REQUEST, "Email template is required", + "Email template object is required in the request body."), + ERROR_EMAIL_TEMPLATE_TYPE_REQUIRED("50008", Status.BAD_REQUEST, "Email template type is required", + "Email template type object is required in the request body."), + ERROR_EMAIL_TEMPLATES_REQUIRED("50009", Status.BAD_REQUEST, "Email templates list is required", + "Email templates list is required in the request body."); private final String message; private final Status httpStatus; diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/EmailTemplatesServiceHolder.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/EmailTemplatesServiceHolder.java index 6f011fe858..82156f9e7d 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/EmailTemplatesServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.api.server.email.template.common/src/main/java/org/wso2/carbon/identity/api/server/email/template/common/EmailTemplatesServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.email.template.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.email.mgt.EmailTemplateManager; @@ -30,8 +32,20 @@ private EmailTemplatesServiceHolder() {} private static class EmailTemplateManagerHolder { - static final EmailTemplateManager SERVICE = (EmailTemplateManager) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(EmailTemplateManager.class, null); + private static final Log log = LogFactory.getLog(EmailTemplateManagerHolder.class); + static final EmailTemplateManager SERVICE = initializeService(); + + private static EmailTemplateManager initializeService() { + + EmailTemplateManager service = (EmailTemplateManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(EmailTemplateManager.class, null); + if (service == null) { + log.warn("EmailTemplateManager is not available in OSGi context."); + } else { + log.debug("EmailTemplateManager successfully retrieved from OSGi context."); + } + return service; + } } /** diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java index 79028b5f25..28c767e144 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v1/core/ServerEmailTemplatesService.java @@ -84,6 +84,9 @@ public List getAllEmailTemplateTypes(Integer String sortOrder, String sortBy, String requiredAttributes) { + if (log.isDebugEnabled()) { + log.debug("Retrieving all email template types for tenant: " + getTenantDomainFromContext()); + } handleNoteSupportedParameters(limit, offset, sortOrder, sortBy); try { @@ -104,8 +107,13 @@ public List getAllEmailTemplateTypes(Integer allTemplates = emailTemplateManager.getAllEmailTemplates(getTenantDomainFromContext()); } - return buildEmailTemplateTypeWithoutTemplatesList(availableTemplateTypes, allTemplates, - requestedAttributeList); + List result = buildEmailTemplateTypeWithoutTemplatesList( + availableTemplateTypes, allTemplates, requestedAttributeList); + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved " + result.size() + " email template types for tenant: " + + getTenantDomainFromContext()); + } + return result; } catch (I18nEmailMgtException e) { throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE_TYPES); } @@ -127,10 +135,22 @@ public EmailTemplateTypeWithID getEmailTemplateType(String templateTypeId, Integ handleNoteSupportedParameters(limit, offset, sortOrder, sortBy); String decodedTemplateTypeId = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Retrieving email template type: " + decodedTemplateTypeId + " for tenant: " + + getTenantDomainFromContext()); + } try { List internalEmailTemplates = emailTemplateManager .getEmailTemplateType(decodedTemplateTypeId, getTenantDomainFromContext()); + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved email template type: " + decodedTemplateTypeId + + " with " + (internalEmailTemplates != null ? internalEmailTemplates.size() : 0) + + " templates for tenant: " + getTenantDomainFromContext()); + } + if (internalEmailTemplates == null) { + internalEmailTemplates = new ArrayList<>(); + } return buildEmailTemplateTypeWithID(internalEmailTemplates, templateTypeId); } catch (I18nEmailMgtException e) { if (StringUtils.equals(I18nMgtConstants.ErrorCodes.EMAIL_TEMPLATE_TYPE_NOT_FOUND, e.getErrorCode())) { @@ -188,6 +208,10 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa try { String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); templateId = I18nEmailUtil.normalizeLocaleFormat(templateId); + if (log.isDebugEnabled()) { + log.debug("Retrieving email template: " + templateTypeDisplayName + "/" + templateId + + " for tenant: " + getTenantDomainFromContext()); + } EmailTemplate internalEmailTemplate = emailTemplateManager.getEmailTemplate(templateTypeDisplayName, templateId, getTenantDomainFromContext()); // EmailTemplateManager sends the default template if no matching template found. We need to check for @@ -212,7 +236,15 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa */ public EmailTemplateTypeWithoutTemplates addEmailTemplateType(EmailTemplateType emailTemplateType) { + if (emailTemplateType == null) { + throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_TYPE_REQUIRED); + } + String templateTypeDisplayName = emailTemplateType.getDisplayName(); + if (log.isDebugEnabled()) { + log.debug("Adding email template type: " + templateTypeDisplayName + " for tenant: " + + getTenantDomainFromContext()); + } try { // Add email template type without templates, first. emailTemplateManager.addEmailTemplateType(templateTypeDisplayName, getTenantDomainFromContext()); @@ -231,6 +263,8 @@ public EmailTemplateTypeWithoutTemplates addEmailTemplateType(EmailTemplateType response.setId(templateTypeId); response.setSelf(getTemplateTypeLocation(templateTypeId)); + log.info("Successfully added email template type: " + templateTypeDisplayName + + " for tenant: " + getTenantDomainFromContext()); return response; } catch (I18nEmailMgtException e) { throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_ADDING_EMAIL_TEMPLATE_TYPE); @@ -246,7 +280,15 @@ public EmailTemplateTypeWithoutTemplates addEmailTemplateType(EmailTemplateType */ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplateWithID emailTemplateWithID) { + if (emailTemplateWithID == null) { + throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_REQUIRED); + } + String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Adding email template: " + templateTypeDisplayName + "/" + emailTemplateWithID.getId() + + " for tenant: " + getTenantDomainFromContext()); + } try { boolean isTemplateExists = emailTemplateManager.isEmailTemplateExists(templateTypeDisplayName, emailTemplateWithID.getId(), getTenantDomainFromContext()); @@ -258,6 +300,8 @@ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplate SimpleEmailTemplate simpleEmailTemplate = new SimpleEmailTemplate(); simpleEmailTemplate.setSelf(getTemplateLocation(templateTypeId, emailTemplateWithID.getId())); simpleEmailTemplate.setId(emailTemplateWithID.getId()); + log.info("Successfully added email template: " + templateTypeDisplayName + "/" + + emailTemplateWithID.getId() + " for tenant: " + getTenantDomainFromContext()); return simpleEmailTemplate; } else { throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_ALREADY_EXISTS); @@ -281,11 +325,22 @@ public void deleteEmailTemplateType(String templateTypeId) { // Ignoring the delete operation and return 204 response code, since the resource does not exist. return; } + if (log.isDebugEnabled()) { + log.debug("Deleting email template type: " + templateTypeDisplayName + " for tenant: " + + getTenantDomainFromContext()); + } try { boolean isTemplateTypeExists = emailTemplateManager.isEmailTemplateTypeExists(templateTypeDisplayName, getTenantDomainFromContext()); if (isTemplateTypeExists) { emailTemplateManager.deleteEmailTemplateType(templateTypeDisplayName, getTenantDomainFromContext()); + log.info("Successfully deleted email template type: " + templateTypeDisplayName + + " for tenant: " + getTenantDomainFromContext()); + } else { + if (log.isDebugEnabled()) { + log.debug("Email template type: " + templateTypeDisplayName + + " does not exist for tenant: " + getTenantDomainFromContext()); + } } } catch (I18nEmailMgtException e) { throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_DELETING_EMAIL_TEMPLATE_TYPE); @@ -307,12 +362,23 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { // Ignoring the delete operation and return 204 response code, since the resource does not exist. return; } + if (log.isDebugEnabled()) { + log.debug("Deleting email template: " + templateTypeDisplayName + "/" + templateId + + " for tenant: " + getTenantDomainFromContext()); + } try { boolean isTemplateExists = emailTemplateManager.isEmailTemplateExists(templateTypeDisplayName, templateId, getTenantDomainFromContext()); if (isTemplateExists) { emailTemplateManager.deleteEmailTemplate(templateTypeDisplayName, templateId, getTenantDomainFromContext()); + log.info("Successfully deleted email template: " + templateTypeDisplayName + "/" + templateId + + " for tenant: " + getTenantDomainFromContext()); + } else { + if (log.isDebugEnabled()) { + log.debug("Email template: " + templateTypeDisplayName + "/" + templateId + + " does not exist for tenant: " + getTenantDomainFromContext()); + } } } catch (I18nEmailMgtException e) { throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_DELETING_EMAIL_TEMPLATE); @@ -329,12 +395,18 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { public void updateEmailTemplate(String templateTypeId, String templateId, EmailTemplateWithID emailTemplateWithID) { String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Updating email template: " + templateTypeDisplayName + "/" + templateId + + " for tenant: " + getTenantDomainFromContext()); + } try { // Check whether the email template exists, first. boolean isTemplateExists = emailTemplateManager.isEmailTemplateExists(templateTypeDisplayName, templateId, getTenantDomainFromContext()); if (isTemplateExists) { addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID); + log.info("Successfully updated email template: " + templateTypeDisplayName + "/" + templateId + + " for tenant: " + getTenantDomainFromContext()); } else { throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_NOT_FOUND); } @@ -351,7 +423,15 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT */ public void updateEmailTemplateType(String templateTypeId, List emailTemplates) { + if (emailTemplates == null) { + throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATES_REQUIRED); + } + String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Updating email template type: " + templateTypeDisplayName + " with " + + emailTemplates.size() + " templates for tenant: " + getTenantDomainFromContext()); + } try { // Check whether the email template type exists. boolean isTemplateTypeExists = emailTemplateManager.isEmailTemplateTypeExists(templateTypeDisplayName, @@ -368,6 +448,8 @@ public void updateEmailTemplateType(String templateTypeId, List emailTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug("REST API call: updateEmailTemplateType for templateTypeId: " + templateTypeId + + " with " + (emailTemplateWithID != null ? emailTemplateWithID.size() : 0) + " templates"); + } emailTemplatesService.updateEmailTemplateType(templateTypeId, emailTemplateWithID); return Response.ok().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ApplicationEmailTemplatesService.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ApplicationEmailTemplatesService.java index 2d197ab734..ecb9e7ab68 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ApplicationEmailTemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ApplicationEmailTemplatesService.java @@ -79,6 +79,10 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa boolean resolve, Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug(String.format("Retrieving app email template for type: %s, locale: %s, appUuid: %s, resolve: %s", + templateTypeId, templateId, applicationUuid, resolve)); + } handleNotSupportedParameters(limit, offset, sortOrder, sortBy); try { @@ -89,11 +93,17 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa // EmailTemplateManager sends the default template if no matching template found. We need to check for // the locale specifically. if (!internalEmailTemplate.getLocale().equals(templateId)) { + if (log.isDebugEnabled()) { + log.debug(String.format("App email template not found for locale: %s", templateId)); + } throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_NOT_FOUND); } else { + log.info(String.format("Retrieved app email template for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); return buildEmailTemplateWithID(internalEmailTemplate); } } catch (I18nEmailMgtException e) { + log.error("Error retrieving app email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE); } } @@ -116,17 +126,27 @@ public List getTemplatesListOfEmailTemplateType(String temp Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug(String.format("Retrieving app templates list for type: %s, appUuid: %s, resolve: %s", + templateTypeId, applicationUuid, resolve)); + } handleNotSupportedParameters(limit, offset, sortOrder, sortBy); String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); try { List internalEmailTemplates = emailTemplateManager.getEmailTemplateType( templateTypeDisplayName, getTenantDomainFromContext(), applicationUuid, resolve); - return buildSimpleEmailTemplatesList(internalEmailTemplates, templateTypeId, applicationUuid); + List result = buildSimpleEmailTemplatesList(internalEmailTemplates, + templateTypeId, applicationUuid); + log.info(String.format("Retrieved %d app templates for type: %s, appUuid: %s", result.size(), + templateTypeDisplayName, applicationUuid)); + return result; } catch (I18nEmailMgtException e) { if (StringUtils.equals(I18nMgtConstants.ErrorCodes.EMAIL_TEMPLATE_TYPE_NOT_FOUND, e.getErrorCode())) { + log.warn(String.format("App email template type not found: %s", templateTypeDisplayName)); throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_TYPE_NOT_FOUND); } + log.error("Error retrieving app email template type.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE_TYPE); } } @@ -142,7 +162,15 @@ public List getTemplatesListOfEmailTemplateType(String temp public SimpleEmailTemplate addEmailTemplate( String templateTypeId, EmailTemplateWithID emailTemplateWithID, String applicationUuid) { + if (emailTemplateWithID == null) { + throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_REQUIRED); + } + String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Adding app email template for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, emailTemplateWithID.getLocale(), applicationUuid)); + } try { boolean isTemplateExists = emailTemplateManager.isEmailTemplateExists(templateTypeDisplayName, emailTemplateWithID.getLocale(), getTenantDomainFromContext(), applicationUuid, false); @@ -155,11 +183,16 @@ public SimpleEmailTemplate addEmailTemplate( simpleEmailTemplate.setSelf( getTemplateLocation(templateTypeId, emailTemplateWithID.getLocale(), applicationUuid)); simpleEmailTemplate.setLocale(emailTemplateWithID.getLocale()); + log.info(String.format("App email template added successfully for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, emailTemplateWithID.getLocale(), applicationUuid)); return simpleEmailTemplate; } else { + log.warn(String.format("App email template already exists for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, emailTemplateWithID.getLocale(), applicationUuid)); throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_ALREADY_EXISTS); } } catch (I18nEmailMgtException e) { + log.error("Error adding app email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_ADDING_EMAIL_TEMPLATE); } } @@ -176,8 +209,15 @@ public void deleteEmailTemplate(String templateTypeId, String templateId, String String templateTypeDisplayName; try { templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Deleting app email template for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); + } } catch (APIError e) { // Ignoring the delete operation and return 204 response code, since the resource does not exist. + if (log.isDebugEnabled()) { + log.debug(String.format("Template type not found for app template deletion: %s", templateTypeId)); + } return; } try { @@ -186,8 +226,14 @@ public void deleteEmailTemplate(String templateTypeId, String templateId, String if (isTemplateExists) { emailTemplateManager.deleteEmailTemplate(templateTypeDisplayName, templateId, getTenantDomainFromContext(), applicationUuid); + log.info(String.format("App email template deleted successfully for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); + } else if (log.isDebugEnabled()) { + log.debug(String.format("App email template not found for deletion. Type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); } } catch (I18nEmailMgtException e) { + log.error("Error deleting app email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_DELETING_EMAIL_TEMPLATE); } } @@ -230,6 +276,10 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT String applicationUuid) { String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Updating app email template for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); + } try { /* Check whether the email template exists, first. Here, resolve param is specified as true since resolved org templates are returned in GET endpoint, by default. Therefore, resolved template existence @@ -238,10 +288,15 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT getTenantDomainFromContext(), applicationUuid, true); if (isTemplateExists) { addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID, applicationUuid); + log.info(String.format("App email template updated successfully for type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); } else { + log.warn(String.format("App email template not found for update. Type: %s, locale: %s, appUuid: %s", + templateTypeDisplayName, templateId, applicationUuid)); throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_NOT_FOUND); } } catch (I18nEmailMgtException e) { + log.error("Error updating app email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_UPDATING_EMAIL_TEMPLATE); } } diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java index 9af0e826f0..2d2afb2e50 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/core/ServerEmailTemplatesService.java @@ -77,6 +77,9 @@ public ServerEmailTemplatesService(EmailTemplateManager emailTemplateManager) { public List getAllEmailTemplateTypes(Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug("Retrieving all email template types."); + } handleNoteSupportedParameters(limit, offset, sortOrder, sortBy); try { List availableTemplateTypes = emailTemplateManager @@ -95,8 +98,10 @@ public List getAllEmailTemplateTypes(Integer limit, Int emailTemplateType.setSelf(getTemplateTypeLocation(templateTypeId)); templateList.add(emailTemplateType); } + log.info(String.format("Retrieved %d email template types.", templateList.size())); return templateList; } catch (I18nEmailMgtException e) { + log.error("Error retrieving email template types.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE_TYPES); } } @@ -125,6 +130,9 @@ public EmailTemplateTypeWithID getEmailTemplateType(String templateTypeId) { public EmailTemplateTypeWithID getEmailTemplateType(String templateTypeId, Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug(String.format("Retrieving email template type with id: %s", templateTypeId)); + } handleNoteSupportedParameters(limit, offset, sortOrder, sortBy); EmailTemplateTypeWithID emailTemplateTypeWithID = new EmailTemplateTypeWithID(); @@ -132,16 +140,21 @@ public EmailTemplateTypeWithID getEmailTemplateType(String templateTypeId, Integ try { if (!emailTemplateManager.isEmailTemplateTypeExists(decodedTemplateTypeId, getTenantDomainFromContext())) { + if (log.isDebugEnabled()) { + log.debug(String.format("Email template type not found: %s", decodedTemplateTypeId)); + } throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_TYPE_NOT_FOUND); } } catch (I18nEmailMgtException e) { + log.error("Error checking email template type existence.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE_TYPE); } emailTemplateTypeWithID.setId(templateTypeId); emailTemplateTypeWithID.setDisplayName(decodedTemplateTypeId); emailTemplateTypeWithID.setSelf(getTemplateTypeLocation(templateTypeId)); - + + log.info(String.format("Retrieved email template type: %s", decodedTemplateTypeId)); return emailTemplateTypeWithID; } @@ -159,17 +172,25 @@ public List getTemplatesListOfEmailTemplateType(String temp Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug(String.format("Retrieving templates list for template type: %s", templateTypeId)); + } handleNoteSupportedParameters(limit, offset, sortOrder, sortBy); String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); try { List internalEmailTemplates = emailTemplateManager .getEmailTemplateType(templateTypeDisplayName, getTenantDomainFromContext()); - return buildSimpleEmailTemplatesList(internalEmailTemplates, templateTypeId); + List result = buildSimpleEmailTemplatesList(internalEmailTemplates, templateTypeId); + log.info(String.format("Retrieved %d templates for template type: %s", result.size(), + templateTypeDisplayName)); + return result; } catch (I18nEmailMgtException e) { if (StringUtils.equals(I18nMgtConstants.ErrorCodes.EMAIL_TEMPLATE_TYPE_NOT_FOUND, e.getErrorCode())) { + log.warn(String.format("Email template type not found: %s", templateTypeDisplayName)); throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_TYPE_NOT_FOUND); } + log.error("Error retrieving email template type.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE_TYPE); } } @@ -188,6 +209,10 @@ public List getTemplatesListOfEmailTemplateType(String temp public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templateId, Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug(String.format("Retrieving email template for templateTypeId: %s, templateId: %s", + templateTypeId, templateId)); + } handleNoteSupportedParameters(limit, offset, sortOrder, sortBy); try { @@ -198,12 +223,18 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa // EmailTemplateManager sends the default template if no matching template found. We need to check for // the locale specifically. if (!internalEmailTemplate.getLocale().equals(templateId)) { + if (log.isDebugEnabled()) { + log.debug(String.format("Email template not found for locale: %s", templateId)); + } throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_NOT_FOUND); } else { + log.info(String.format("Retrieved email template for type: %s, locale: %s", + templateTypeDisplayName, templateId)); return buildEmailTemplateWithID(internalEmailTemplate); } } catch (I18nEmailMgtException e) { + log.error("Error retrieving email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_RETRIEVING_EMAIL_TEMPLATE); } } @@ -218,6 +249,9 @@ public EmailTemplateWithID getEmailTemplate(String templateTypeId, String templa public EmailTemplateTypeWithID addEmailTemplateType(EmailTemplateTypeOverview emailTemplateTypeOverview) { String templateTypeDisplayName = emailTemplateTypeOverview.getDisplayName(); + if (log.isDebugEnabled()) { + log.debug(String.format("Adding email template type: %s", templateTypeDisplayName)); + } try { emailTemplateManager.addEmailTemplateType(templateTypeDisplayName, getTenantDomainFromContext()); @@ -227,9 +261,11 @@ public EmailTemplateTypeWithID addEmailTemplateType(EmailTemplateTypeOverview em String templateTypeId = getEmailTemplateIdFromDisplayName(templateTypeDisplayName); response.setId(templateTypeId); response.setSelf(getTemplateTypeLocation(templateTypeId)); - + + log.info(String.format("Email template type added successfully: %s", templateTypeDisplayName)); return response; } catch (I18nEmailMgtException e) { + log.error("Error adding email template type.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_ADDING_EMAIL_TEMPLATE_TYPE); } } @@ -243,7 +279,15 @@ public EmailTemplateTypeWithID addEmailTemplateType(EmailTemplateTypeOverview em */ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplateWithID emailTemplateWithID) { + if (emailTemplateWithID == null) { + throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_REQUIRED); + } + String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Adding email template for type: %s, locale: %s", templateTypeDisplayName, + emailTemplateWithID.getLocale())); + } try { boolean isTemplateExists = emailTemplateManager.isEmailTemplateExists(templateTypeDisplayName, emailTemplateWithID.getLocale(), getTenantDomainFromContext()); @@ -255,11 +299,16 @@ public SimpleEmailTemplate addEmailTemplate(String templateTypeId, EmailTemplate SimpleEmailTemplate simpleEmailTemplate = new SimpleEmailTemplate(); simpleEmailTemplate.setSelf(getTemplateLocation(templateTypeId, emailTemplateWithID.getLocale())); simpleEmailTemplate.setLocale(emailTemplateWithID.getLocale()); + log.info(String.format("Email template added successfully for type: %s, locale: %s", + templateTypeDisplayName, emailTemplateWithID.getLocale())); return simpleEmailTemplate; } else { + log.warn(String.format("Email template already exists for type: %s, locale: %s", + templateTypeDisplayName, emailTemplateWithID.getLocale())); throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_ALREADY_EXISTS); } } catch (I18nEmailMgtException e) { + log.error("Error adding email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_ADDING_EMAIL_TEMPLATE); } } @@ -274,8 +323,14 @@ public void deleteEmailTemplateType(String templateTypeId) { String templateTypeDisplayName; try { templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Deleting email template type: %s", templateTypeDisplayName)); + } } catch (APIError e) { // Ignoring the delete operation and return 204 response code, since the resource does not exist. + if (log.isDebugEnabled()) { + log.debug(String.format("Template type not found for deletion: %s", templateTypeId)); + } return; } try { @@ -283,8 +338,12 @@ public void deleteEmailTemplateType(String templateTypeId) { getTenantDomainFromContext()); if (isTemplateTypeExists) { emailTemplateManager.deleteEmailTemplateType(templateTypeDisplayName, getTenantDomainFromContext()); + log.info(String.format("Email template type deleted successfully: %s", templateTypeDisplayName)); + } else if (log.isDebugEnabled()) { + log.debug(String.format("Email template type not found for deletion: %s", templateTypeDisplayName)); } } catch (I18nEmailMgtException e) { + log.error("Error deleting email template type.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_DELETING_EMAIL_TEMPLATE_TYPE); } } @@ -325,8 +384,15 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { String templateTypeDisplayName; try { templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Deleting email template for type: %s, locale: %s", + templateTypeDisplayName, templateId)); + } } catch (APIError e) { // Ignoring the delete operation and return 204 response code, since the resource does not exist. + if (log.isDebugEnabled()) { + log.debug(String.format("Template type not found for template deletion: %s", templateTypeId)); + } return; } try { @@ -335,8 +401,14 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { if (isTemplateExists) { emailTemplateManager.deleteEmailTemplate(templateTypeDisplayName, templateId, getTenantDomainFromContext()); + log.info(String.format("Email template deleted successfully for type: %s, locale: %s", + templateTypeDisplayName, templateId)); + } else if (log.isDebugEnabled()) { + log.debug(String.format("Email template not found for deletion. Type: %s, locale: %s", + templateTypeDisplayName, templateId)); } } catch (I18nEmailMgtException e) { + log.error("Error deleting email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_DELETING_EMAIL_TEMPLATE); } } @@ -351,16 +423,25 @@ public void deleteEmailTemplate(String templateTypeId, String templateId) { public void updateEmailTemplate(String templateTypeId, String templateId, EmailTemplateWithID emailTemplateWithID) { String templateTypeDisplayName = decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug(String.format("Updating email template for type: %s, locale: %s", + templateTypeDisplayName, templateId)); + } try { // Check whether the email template exists, first. boolean isTemplateExists = emailTemplateManager.isEmailTemplateExists(templateTypeDisplayName, templateId, getTenantDomainFromContext()); if (isTemplateExists) { addEmailTemplateToTheSystem(templateTypeDisplayName, emailTemplateWithID); + log.info(String.format("Email template updated successfully for type: %s, locale: %s", + templateTypeDisplayName, templateId)); } else { + log.warn(String.format("Email template not found for update. Type: %s, locale: %s", + templateTypeDisplayName, templateId)); throw handleError(Constants.ErrorMessage.ERROR_EMAIL_TEMPLATE_NOT_FOUND); } } catch (I18nEmailMgtException e) { + log.error("Error updating email template.", e); throw handleI18nEmailMgtException(e, Constants.ErrorMessage.ERROR_UPDATING_EMAIL_TEMPLATE); } } diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ApplicationEmailTemplatesServiceFactory.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ApplicationEmailTemplatesServiceFactory.java index ae8ba75fa6..356a93e0b2 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ApplicationEmailTemplatesServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ApplicationEmailTemplatesServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.email.template.v2.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.email.mgt.EmailTemplateManager; import org.wso2.carbon.identity.api.server.email.template.common.EmailTemplatesServiceHolder; import org.wso2.carbon.identity.rest.api.server.email.template.v2.core.ApplicationEmailTemplatesService; @@ -27,16 +29,20 @@ */ public class ApplicationEmailTemplatesServiceFactory { + private static final Log log = LogFactory.getLog(ApplicationEmailTemplatesServiceFactory.class); private static final ApplicationEmailTemplatesService SERVICE; static { + log.info("Initializing ApplicationEmailTemplatesServiceFactory."); EmailTemplateManager emailTemplateManager = EmailTemplatesServiceHolder.getEmailTemplateManager(); if (emailTemplateManager == null) { + log.error("EmailTemplateManager is not available from OSGi context."); throw new IllegalStateException("EmailTemplateManager is not available from OSGi context."); } SERVICE = new ApplicationEmailTemplatesService(emailTemplateManager); + log.info("ApplicationEmailTemplatesServiceFactory initialized successfully."); } /** @@ -46,6 +52,9 @@ public class ApplicationEmailTemplatesServiceFactory { */ public static ApplicationEmailTemplatesService getApplicationEmailTemplatesService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ApplicationEmailTemplatesService instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ServerEmailTemplatesServiceFactory.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ServerEmailTemplatesServiceFactory.java index 7baa835052..95e2de0e5a 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ServerEmailTemplatesServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/factories/ServerEmailTemplatesServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.email.template.v2.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.email.mgt.EmailTemplateManager; import org.wso2.carbon.identity.api.server.email.template.common.EmailTemplatesServiceHolder; import org.wso2.carbon.identity.rest.api.server.email.template.v2.core.ServerEmailTemplatesService; @@ -27,16 +29,20 @@ */ public class ServerEmailTemplatesServiceFactory { + private static final Log log = LogFactory.getLog(ServerEmailTemplatesServiceFactory.class); private static final ServerEmailTemplatesService SERVICE; static { + log.info("Initializing ServerEmailTemplatesServiceFactory."); EmailTemplateManager emailTemplateManager = EmailTemplatesServiceHolder.getEmailTemplateManager(); if (emailTemplateManager == null) { + log.error("EmailTemplateManager is not available from OSGi context."); throw new IllegalStateException("EmailTemplateManager is not available from OSGi context."); } SERVICE = new ServerEmailTemplatesService(emailTemplateManager); + log.info("ServerEmailTemplatesServiceFactory initialized successfully."); } /** @@ -46,6 +52,9 @@ public class ServerEmailTemplatesServiceFactory { */ public static ServerEmailTemplatesService getServerEmailTemplatesService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ServerEmailTemplatesService instance."); + } return SERVICE; } diff --git a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/impl/EmailApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/impl/EmailApiServiceImpl.java index 6cf73c2f6a..a6a1123f2e 100644 --- a/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/impl/EmailApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.email.template/org.wso2.carbon.identity.rest.api.server.email.template.v2/src/main/java/org/wso2/carbon/identity/rest/api/server/email/template/v2/impl/EmailApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.email.template.v2.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.rest.api.server.email.template.v2.EmailApiService; import org.wso2.carbon.identity.rest.api.server.email.template.v2.core.ApplicationEmailTemplatesService; import org.wso2.carbon.identity.rest.api.server.email.template.v2.core.ServerEmailTemplatesService; @@ -44,16 +46,20 @@ */ public class EmailApiServiceImpl implements EmailApiService { + private static final Log log = LogFactory.getLog(EmailApiServiceImpl.class); private final ServerEmailTemplatesService emailTemplatesService; private final ApplicationEmailTemplatesService applicationEmailTemplatesService; public EmailApiServiceImpl() { try { + log.info("Initializing EmailApiServiceImpl."); this.emailTemplatesService = ServerEmailTemplatesServiceFactory.getServerEmailTemplatesService(); this.applicationEmailTemplatesService = ApplicationEmailTemplatesServiceFactory .getApplicationEmailTemplatesService(); + log.info("EmailApiServiceImpl initialized successfully."); } catch (IllegalStateException e) { + log.error("Error occurred while initiating email template management services."); throw new RuntimeException("Error occurred while initiating email template management services.", e); } } @@ -62,8 +68,13 @@ public EmailApiServiceImpl() { public Response addAppEmailTemplate( String templateTypeId, String appUuid, EmailTemplateWithID emailTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug(String.format("Adding app email template for templateTypeId: %s, appUuid: %s, locale: %s", + templateTypeId, appUuid, emailTemplateWithID != null ? emailTemplateWithID.getLocale() : null)); + } SimpleEmailTemplate simpleEmailTemplate = applicationEmailTemplatesService.addEmailTemplate(templateTypeId, emailTemplateWithID, appUuid); + log.info("App email template added successfully."); URI headerLocation = buildURIForHeader( V2_API_PATH_COMPONENT + EMAIL_TEMPLATES_API_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH + PATH_SEPARATOR + templateTypeId + APP_EMAIL_TEMPLATES_PATH + @@ -74,7 +85,16 @@ public Response addAppEmailTemplate( @Override public Response addEmailTemplateType(EmailTemplateTypeOverview emailTemplateTypeOverview) { + if (log.isDebugEnabled()) { + log.debug(String.format("Adding email template type: %s", + emailTemplateTypeOverview != null ? emailTemplateTypeOverview.getDisplayName() : null)); + } + if (emailTemplateTypeOverview == null) { + log.error("Email template type overview cannot be null."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } EmailTemplateTypeWithID templateType = emailTemplatesService.addEmailTemplateType(emailTemplateTypeOverview); + log.info("Email template type added successfully."); URI headerLocation = buildURIForHeader( V2_API_PATH_COMPONENT + EMAIL_TEMPLATES_API_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH + PATH_SEPARATOR + templateType.getId()); @@ -84,8 +104,13 @@ public Response addEmailTemplateType(EmailTemplateTypeOverview emailTemplateType @Override public Response addOrgEmailTemplate(String templateTypeId, EmailTemplateWithID emailTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug(String.format("Adding org email template for templateTypeId: %s, locale: %s", + templateTypeId, emailTemplateWithID != null ? emailTemplateWithID.getLocale() : null)); + } SimpleEmailTemplate simpleEmailTemplate = emailTemplatesService.addEmailTemplate(templateTypeId, emailTemplateWithID); + log.info("Org email template added successfully."); URI headerLocation = buildURIForHeader( V2_API_PATH_COMPONENT + EMAIL_TEMPLATES_API_BASE_PATH + EMAIL_TEMPLATE_TYPES_PATH + PATH_SEPARATOR + templateTypeId + ORG_EMAIL_TEMPLATES_PATH + @@ -96,27 +121,45 @@ public Response addOrgEmailTemplate(String templateTypeId, EmailTemplateWithID e @Override public Response deleteAppEmailTemplate(String templateTypeId, String appUuid, String locale) { + if (log.isDebugEnabled()) { + log.debug(String.format("Deleting app email template for templateTypeId: %s, appUuid: %s, locale: %s", + templateTypeId, appUuid, locale)); + } applicationEmailTemplatesService.deleteEmailTemplate(templateTypeId, locale, appUuid); + log.info("App email template deleted successfully."); return Response.noContent().build(); } @Override public Response deleteEmailTemplateType(String templateTypeId) { + if (log.isDebugEnabled()) { + log.debug(String.format("Deleting email template type with id: %s", templateTypeId)); + } emailTemplatesService.deleteEmailTemplateType(templateTypeId); + log.info("Email template type deleted successfully."); return Response.noContent().build(); } @Override public Response deleteOrgEmailTemplate(String templateTypeId, String locale) { + if (log.isDebugEnabled()) { + log.debug(String.format("Deleting org email template for templateTypeId: %s, locale: %s", + templateTypeId, locale)); + } emailTemplatesService.deleteEmailTemplate(templateTypeId, locale); + log.info("Org email template deleted successfully."); return Response.noContent().build(); } @Override public Response getAllEmailTemplateTypes(Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug(String.format("Retrieving all email template types with limit: %s, offset: %s", + limit, offset)); + } return Response.ok().entity( emailTemplatesService.getAllEmailTemplateTypes(limit, offset, sortOrder, sortBy)).build(); } @@ -166,7 +209,12 @@ public Response getOrgTemplatesListOfEmailTemplateType( public Response updateAppEmailTemplate( String templateTypeId, String appUuid, String locale, EmailTemplateWithID emailTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug(String.format("Updating app email template for templateTypeId: %s, appUuid: %s, locale: %s", + templateTypeId, appUuid, locale)); + } applicationEmailTemplatesService.updateEmailTemplate(templateTypeId, locale, emailTemplateWithID, appUuid); + log.info("App email template updated successfully."); return Response.ok().build(); } @@ -174,7 +222,12 @@ public Response updateAppEmailTemplate( public Response updateOrgEmailTemplate( String templateTypeId, String locale, EmailTemplateWithID emailTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug(String.format("Updating org email template for templateTypeId: %s, locale: %s", + templateTypeId, locale)); + } emailTemplatesService.updateEmailTemplate(templateTypeId, locale, emailTemplateWithID); + log.info("Org email template updated successfully."); return Response.ok().build(); } }