diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.common/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/common/NotificationSenderServiceHolder.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.common/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/common/NotificationSenderServiceHolder.java index f294d756da..f1d0a8ecca 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.common/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/common/NotificationSenderServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.common/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/common/NotificationSenderServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.notification.sender.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService; @@ -26,6 +28,8 @@ */ public class NotificationSenderServiceHolder { + private static final Log log = LogFactory.getLog(NotificationSenderServiceHolder.class); + private NotificationSenderServiceHolder() {} private static class NotificationSenderManagementServiceHolder { @@ -42,6 +46,13 @@ private static class NotificationSenderManagementServiceHolder { */ public static NotificationSenderManagementService getNotificationSenderManagementService() { - return NotificationSenderManagementServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving NotificationSenderManagementService from OSGi service registry."); + } + NotificationSenderManagementService service = NotificationSenderManagementServiceHolder.SERVICE; + if (service == null) { + log.warn("NotificationSenderManagementService is not available in OSGi service registry."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/core/NotificationSenderManagementService.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/core/NotificationSenderManagementService.java index b325dfa818..1120b29c3b 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/core/NotificationSenderManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/core/NotificationSenderManagementService.java @@ -72,11 +72,22 @@ public NotificationSenderManagementService( */ public EmailSender addEmailSender(EmailSenderAdd emailSenderAdd) { + if (log.isDebugEnabled()) { + log.debug("Adding email sender: " + (emailSenderAdd != null ? emailSenderAdd.getName() : "null")); + } + + if (emailSenderAdd == null) { + log.error("Email sender add request cannot be null."); + throw new IllegalArgumentException("Email sender add request cannot be null."); + } + EmailSenderDTO dto = buildEmailSenderDTO(emailSenderAdd); try { EmailSenderDTO emailSenderDTO = notificationSenderManagementService.addEmailSender(dto); + log.info("Email sender added successfully: " + emailSenderDTO.getName()); return buildEmailSenderFromDTO(emailSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to add email sender: " + emailSenderAdd.getName()); throw handleException(e); } } @@ -89,11 +100,22 @@ public EmailSender addEmailSender(EmailSenderAdd emailSenderAdd) { */ public SMSSender addSMSSender(SMSSenderAdd smsSenderAdd) { + if (log.isDebugEnabled()) { + log.debug("Adding SMS sender: " + (smsSenderAdd != null ? smsSenderAdd.getName() : "null")); + } + + if (smsSenderAdd == null) { + log.error("SMS sender add request cannot be null."); + throw new IllegalArgumentException("SMS sender add request cannot be null."); + } + SMSSenderDTO dto = buildSMSSenderDTO(smsSenderAdd); try { SMSSenderDTO smsSenderDTO = notificationSenderManagementService.addSMSSender(dto); + log.info("SMS sender added successfully: " + smsSenderDTO.getName()); return buildSMSSenderFromDTO(smsSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to add SMS sender: " + smsSenderAdd.getName()); throw handleException(e); } } @@ -106,12 +128,23 @@ public SMSSender addSMSSender(SMSSenderAdd smsSenderAdd) { */ public PushSender addPushSender(PushSenderAdd pushSenderAdd) { + if (log.isDebugEnabled()) { + log.debug("Adding push sender: " + (pushSenderAdd != null ? pushSenderAdd.getName() : "null")); + } + + if (pushSenderAdd == null) { + log.error("Push sender add request cannot be null."); + throw new IllegalArgumentException("Push sender add request cannot be null."); + } + PushSenderDTO dto = buildPushSenderDTO(pushSenderAdd); try { PushSenderDTO pushSenderDTO = NotificationSenderServiceHolder.getNotificationSenderManagementService() .addPushSender(dto); + log.info("Push sender added successfully: " + pushSenderDTO.getName()); return buildPushSenderFromDTO(pushSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to add push sender: " + pushSenderAdd.getName()); throw handleException(e); } } @@ -123,10 +156,16 @@ public PushSender addPushSender(PushSenderAdd pushSenderAdd) { */ public void deleteNotificationSender(String notificationSenderName) { + if (log.isDebugEnabled()) { + log.debug("Deleting notification sender: " + notificationSenderName); + } + try { notificationSenderManagementService.deleteNotificationSender(notificationSenderName); + log.info("Notification sender deleted successfully: " + notificationSenderName); } catch (NotificationSenderManagementException e) { - throw handleException(e); + log.error("Failed to delete notification sender: " + notificationSenderName); + throw handleException(e); } } @@ -138,10 +177,15 @@ public void deleteNotificationSender(String notificationSenderName) { */ public EmailSender getEmailSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving email sender: " + senderName); + } + try { EmailSenderDTO emailSenderDTO = notificationSenderManagementService.getEmailSender(senderName); return buildEmailSenderFromDTO(emailSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to retrieve email sender: " + senderName); throw handleException(e); } } @@ -154,10 +198,15 @@ public EmailSender getEmailSender(String senderName) { */ public SMSSender getSMSSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving SMS sender: " + senderName); + } + try { SMSSenderDTO smsSenderDTO = notificationSenderManagementService.getSMSSender(senderName, false); return buildSMSSenderFromDTO(smsSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to retrieve SMS sender: " + senderName); throw handleException(e); } } @@ -170,11 +219,16 @@ public SMSSender getSMSSender(String senderName) { */ public PushSender getPushSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving push sender: " + senderName); + } + try { PushSenderDTO pushSenderDTO = NotificationSenderServiceHolder.getNotificationSenderManagementService() .getPushSender(senderName, false); return buildPushSenderFromDTO(pushSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to retrieve push sender: " + senderName); throw handleException(e); } } @@ -186,10 +240,15 @@ public PushSender getPushSender(String senderName) { */ public List getEmailSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all email senders"); + } + try { List emailSenders = notificationSenderManagementService.getEmailSenders(); return emailSenders.stream().map(this::buildEmailSenderFromDTO).collect(Collectors.toList()); } catch (NotificationSenderManagementException e) { + log.error("Failed to retrieve email senders"); throw handleException(e); } } @@ -201,10 +260,15 @@ public List getEmailSenders() { */ public List getSMSSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all SMS senders"); + } + try { List smsSenders = notificationSenderManagementService.getSMSSenders(false); return smsSenders.stream().map(this::buildSMSSenderFromDTO).collect(Collectors.toList()); } catch (NotificationSenderManagementException e) { + log.error("Failed to retrieve SMS senders"); throw handleException(e); } } @@ -216,11 +280,16 @@ public List getSMSSenders() { */ public List getPushSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all push senders"); + } + try { List pushSenders = NotificationSenderServiceHolder.getNotificationSenderManagementService() .getPushSenders(false); return pushSenders.stream().map(this::buildPushSenderFromDTO).collect(Collectors.toList()); } catch (NotificationSenderManagementException e) { + log.error("Failed to retrieve push senders"); throw handleException(e); } } @@ -234,11 +303,17 @@ public List getPushSenders() { */ public EmailSender updateEmailSender(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating email sender: " + senderName); + } + EmailSenderDTO dto = buildEmailSenderDTO(senderName, emailSenderUpdateRequest); try { EmailSenderDTO emailSenderDTO = notificationSenderManagementService.updateEmailSender(dto); + log.info("Email sender updated successfully: " + senderName); return buildEmailSenderFromDTO(emailSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to update email sender: " + senderName); throw handleException(e); } } @@ -252,11 +327,17 @@ public EmailSender updateEmailSender(String senderName, EmailSenderUpdateRequest */ public SMSSender updateSMSSender(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating SMS sender: " + senderName); + } + SMSSenderDTO dto = buildSMSSenderDTO(senderName, smsSenderUpdateRequest); try { SMSSenderDTO smsSenderDTO = notificationSenderManagementService.updateSMSSender(dto); + log.info("SMS sender updated successfully: " + senderName); return buildSMSSenderFromDTO(smsSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to update SMS sender: " + senderName); throw handleException(e); } } @@ -270,12 +351,18 @@ public SMSSender updateSMSSender(String senderName, SMSSenderUpdateRequest smsSe */ public PushSender updatePushSender(String senderName, PushSenderUpdateRequest pushSenderUpdateRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating push sender: " + senderName); + } + PushSenderDTO dto = buildPushSenderDTO(senderName, pushSenderUpdateRequest); try { PushSenderDTO pushSenderDTO = NotificationSenderServiceHolder.getNotificationSenderManagementService() .updatePushSender(dto); + log.info("Push sender updated successfully: " + senderName); return buildPushSenderFromDTO(pushSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to update push sender: " + senderName); throw handleException(e); } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/factories/NotificationSenderManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/factories/NotificationSenderManagementServiceFactory.java index 39a26e4e1e..b9e80dbdfd 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/factories/NotificationSenderManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/factories/NotificationSenderManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.notification.sender.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderServiceHolder; import org.wso2.carbon.identity.api.server.notification.sender.v1.core.NotificationSenderManagementService; @@ -26,18 +28,27 @@ */ public class NotificationSenderManagementServiceFactory { + private static final Log log = LogFactory.getLog(NotificationSenderManagementServiceFactory.class); private static final NotificationSenderManagementService SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing NotificationSenderManagementServiceFactory"); + } + org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService notificationSenderManagementService = NotificationSenderServiceHolder .getNotificationSenderManagementService(); if (notificationSenderManagementService == null) { + log.error("NotificationSenderManagementService is not available from OSGi context."); throw new IllegalStateException("NotificationSenderManagementService is not available from OSGi context."); } SERVICE = new NotificationSenderManagementService(notificationSenderManagementService); + if (log.isDebugEnabled()) { + log.debug("NotificationSenderManagementServiceFactory initialized successfully"); + } } /** @@ -47,6 +58,9 @@ public class NotificationSenderManagementServiceFactory { */ public static NotificationSenderManagementService getNotificationSenderManagementService() { + if (log.isDebugEnabled()) { + log.debug("Returning NotificationSenderManagementService instance"); + } return SERVICE; } diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/impl/NotificationSendersApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/impl/NotificationSendersApiServiceImpl.java index 0d15f372ed..405fb1fa48 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/impl/NotificationSendersApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v1/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v1/impl/NotificationSendersApiServiceImpl.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.notification.sender.v1.impl; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.identity.api.server.common.ContextLoader; @@ -58,6 +60,7 @@ */ public class NotificationSendersApiServiceImpl implements NotificationSendersApiService { + private static final Log log = LogFactory.getLog(NotificationSendersApiServiceImpl.class); private final NotificationSenderManagementService notificationSenderManagementService; public NotificationSendersApiServiceImpl() { @@ -65,7 +68,11 @@ public NotificationSendersApiServiceImpl() { try { this.notificationSenderManagementService = NotificationSenderManagementServiceFactory .getNotificationSenderManagementService(); + if (log.isDebugEnabled()) { + log.debug("NotificationSenderManagementService initialized successfully."); + } } catch (IllegalStateException e) { + log.error("Error occurred while initiating notification sender service.", e); throw new RuntimeException("Error occurred while initiating notification sender service.", e); } } @@ -73,10 +80,19 @@ public NotificationSendersApiServiceImpl() { @Override public Response createEmailSender(EmailSenderAdd emailSenderAdd) { - if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Creating email sender: " + (emailSenderAdd != null ? emailSenderAdd.getName() : "null") + + " for tenant: " + tenantDomain); + } + + if (StringUtils.equals(tenantDomain, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + log.warn("Email sender creation not allowed for super tenant domain."); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } EmailSender emailSender = notificationSenderManagementService.addEmailSender(emailSenderAdd); + log.info("Email sender created successfully: " + emailSender.getName() + " for tenant: " + tenantDomain); + URI location = null; try { location = ContextLoader.buildURIForHeader( @@ -84,6 +100,7 @@ public Response createEmailSender(EmailSenderAdd emailSenderAdd) { URLEncoder.encode(emailSender.getName(), StandardCharsets.UTF_8.name()) .replace(PLUS, URL_ENCODED_SPACE)); } catch (UnsupportedEncodingException e) { + log.error("Error occurred while encoding email sender name: " + emailSender.getName(), e); ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build(); throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse); @@ -94,7 +111,22 @@ public Response createEmailSender(EmailSenderAdd emailSenderAdd) { @Override public Response createPushSender(PushSenderAdd pushSenderAdd) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Creating push sender: " + (pushSenderAdd != null ? pushSenderAdd.getName() : "null") + + " for tenant: " + tenantDomain); + } + + if (pushSenderAdd == null) { + log.error("Push sender add request cannot be null for tenant: " + tenantDomain); + ErrorResponse errorResponse = + new ErrorResponse.Builder().withMessage("Push sender add request cannot be null.").build(); + throw new APIError(Response.Status.BAD_REQUEST, errorResponse); + } + PushSender pushSender = notificationSenderManagementService.addPushSender(pushSenderAdd); + log.info("Push sender created successfully: " + pushSender.getName() + " for tenant: " + tenantDomain); + URI location = null; try { location = ContextLoader.buildURIForHeader( @@ -102,6 +134,7 @@ public Response createPushSender(PushSenderAdd pushSenderAdd) { URLEncoder.encode(pushSender.getName(), StandardCharsets.UTF_8.name()) .replace(PLUS, URL_ENCODED_SPACE)); } catch (UnsupportedEncodingException e) { + log.error("Error occurred while encoding push sender name: " + pushSender.getName(), e); ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build(); throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse); @@ -112,7 +145,22 @@ public Response createPushSender(PushSenderAdd pushSenderAdd) { @Override public Response createSMSSender(SMSSenderAdd smSSenderAdd) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Creating SMS sender: " + (smSSenderAdd != null ? smSSenderAdd.getName() : "null") + + " for tenant: " + tenantDomain); + } + + if (smSSenderAdd == null) { + log.error("SMS sender add request cannot be null for tenant: " + tenantDomain); + ErrorResponse errorResponse = + new ErrorResponse.Builder().withMessage("SMS sender add request cannot be null.").build(); + throw new APIError(Response.Status.BAD_REQUEST, errorResponse); + } + SMSSender smsSender = notificationSenderManagementService.addSMSSender(smSSenderAdd); + log.info("SMS sender created successfully: " + smsSender.getName() + " for tenant: " + tenantDomain); + URI location = null; try { location = ContextLoader.buildURIForHeader( @@ -120,6 +168,7 @@ public Response createSMSSender(SMSSenderAdd smSSenderAdd) { URLEncoder.encode(smsSender.getName(), StandardCharsets.UTF_8.name()) .replace(PLUS, URL_ENCODED_SPACE)); } catch (UnsupportedEncodingException e) { + log.error("Error occurred while encoding SMS sender name: " + smsSender.getName(), e); ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build(); throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse); @@ -130,31 +179,57 @@ public Response createSMSSender(SMSSenderAdd smSSenderAdd) { @Override public Response deleteEmailSender(String senderName) { - if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Deleting email sender: " + senderName + " for tenant: " + tenantDomain); + } + + if (StringUtils.equals(tenantDomain, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + log.warn("Email sender deletion not allowed for super tenant domain."); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + notificationSenderManagementService.deleteNotificationSender(senderName); + log.info("Email sender deleted successfully: " + senderName + " for tenant: " + tenantDomain); return Response.noContent().build(); } @Override public Response deletePushSender(String senderName) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Deleting push sender: " + senderName + " for tenant: " + tenantDomain); + } + notificationSenderManagementService.deleteNotificationSender(senderName); + log.info("Push sender deleted successfully: " + senderName + " for tenant: " + tenantDomain); return Response.noContent().build(); } @Override public Response deleteSMSSender(String senderName) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Deleting SMS sender: " + senderName + " for tenant: " + tenantDomain); + } + notificationSenderManagementService.deleteNotificationSender(senderName); + log.info("SMS sender deleted successfully: " + senderName + " for tenant: " + tenantDomain); return Response.noContent().build(); } @Override public Response getEmailSender(String senderName) { - if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Retrieving email sender: " + senderName + " for tenant: " + tenantDomain); + } + + if (StringUtils.equals(tenantDomain, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + log.warn("Email sender retrieval not allowed for super tenant domain."); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } return Response.ok().entity(notificationSenderManagementService.getEmailSender(senderName)).build(); @@ -163,7 +238,13 @@ public Response getEmailSender(String senderName) { @Override public Response getEmailSenders() { - if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Retrieving all email senders for tenant: " + tenantDomain); + } + + if (StringUtils.equals(tenantDomain, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + log.warn("Email senders retrieval not allowed for super tenant domain."); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } return Response.ok().entity(notificationSenderManagementService.getEmailSenders()).build(); @@ -172,51 +253,83 @@ public Response getEmailSenders() { @Override public Response getPushSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving push sender: " + senderName + " for tenant: " + getTenantDomainFromContext()); + } return Response.ok().entity(notificationSenderManagementService.getPushSender(senderName)).build(); } @Override public Response getPushSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all push senders for tenant: " + getTenantDomainFromContext()); + } return Response.ok().entity(notificationSenderManagementService.getPushSenders()).build(); } @Override public Response getSMSSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving SMS sender: " + senderName + " for tenant: " + getTenantDomainFromContext()); + } return Response.ok().entity(notificationSenderManagementService.getSMSSender(senderName)).build(); } @Override public Response getSMSSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all SMS senders for tenant: " + getTenantDomainFromContext()); + } return Response.ok().entity(notificationSenderManagementService.getSMSSenders()).build(); } @Override public Response updateEmailSender(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) { - if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Updating email sender: " + senderName + " for tenant: " + tenantDomain); + } + + if (StringUtils.equals(tenantDomain, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + log.warn("Email sender update not allowed for super tenant domain."); return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } - return Response.ok() - .entity(notificationSenderManagementService.updateEmailSender(senderName, emailSenderUpdateRequest)) - .build(); + + EmailSender updatedEmailSender = notificationSenderManagementService.updateEmailSender(senderName, + emailSenderUpdateRequest); + log.info("Email sender updated successfully: " + senderName + " for tenant: " + tenantDomain); + return Response.ok().entity(updatedEmailSender).build(); } @Override public Response updatePushSender(String senderName, PushSenderUpdateRequest pushSenderUpdateRequest) { - return Response.ok() - .entity(notificationSenderManagementService.updatePushSender(senderName, pushSenderUpdateRequest)) - .build(); + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Updating push sender: " + senderName + " for tenant: " + tenantDomain); + } + + PushSender updatedPushSender = notificationSenderManagementService.updatePushSender(senderName, + pushSenderUpdateRequest); + log.info("Push sender updated successfully: " + senderName + " for tenant: " + tenantDomain); + return Response.ok().entity(updatedPushSender).build(); } @Override public Response updateSMSSender(String senderName, SMSSenderUpdateRequest smSSenderUpdateRequest) { - return Response.ok() - .entity(notificationSenderManagementService.updateSMSSender(senderName, smSSenderUpdateRequest)) - .build(); + String tenantDomain = getTenantDomainFromContext(); + if (log.isDebugEnabled()) { + log.debug("Updating SMS sender: " + senderName + " for tenant: " + tenantDomain); + } + + SMSSender updatedSMSSender = notificationSenderManagementService.updateSMSSender(senderName, + smSSenderUpdateRequest); + log.info("SMS sender updated successfully: " + senderName + " for tenant: " + tenantDomain); + return Response.ok().entity(updatedSMSSender).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/core/NotificationSenderManagementService.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/core/NotificationSenderManagementService.java index 4f1af83560..f21c3940e9 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/core/NotificationSenderManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/core/NotificationSenderManagementService.java @@ -81,11 +81,24 @@ public NotificationSenderManagementService( */ public EmailSender addEmailSender(EmailSenderAdd emailSenderAdd) { + if (emailSenderAdd == null) { + log.error("Email sender add request is null"); + throw new IllegalArgumentException("Email sender add request cannot be null"); + } + if (log.isDebugEnabled()) { + log.debug("Adding email sender: " + emailSenderAdd.getName()); + } EmailSenderDTO dto = buildEmailSenderDTO(emailSenderAdd); try { EmailSenderDTO emailSenderDTO = notificationSenderManagementService.addEmailSender(dto); + if (emailSenderDTO == null) { + log.warn("Received null email sender DTO from service"); + throw new IllegalStateException("Failed to create email sender"); + } + log.info("Email sender added successfully: " + emailSenderDTO.getName()); return buildEmailSenderFromDTO(emailSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to add email sender: " + emailSenderAdd.getName() + ". Error: " + e.getMessage()); throw handleException(e); } } @@ -98,11 +111,24 @@ public EmailSender addEmailSender(EmailSenderAdd emailSenderAdd) { */ public SMSSender addSMSSender(SMSSenderAdd smsSenderAdd) { + if (smsSenderAdd == null) { + log.error("SMS sender add request is null"); + throw new IllegalArgumentException("SMS sender add request cannot be null"); + } + if (log.isDebugEnabled()) { + log.debug("Adding SMS sender: " + smsSenderAdd.getName()); + } SMSSenderDTO dto = buildSMSSenderDTO(smsSenderAdd); try { SMSSenderDTO smsSenderDTO = notificationSenderManagementService.addSMSSender(dto); + if (smsSenderDTO == null) { + log.warn("Received null SMS sender DTO from service"); + throw new IllegalStateException("Failed to create SMS sender"); + } + log.info("SMS sender added successfully: " + smsSenderDTO.getName()); return buildSMSSenderFromDTO(smsSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to add SMS sender: " + smsSenderAdd.getName() + ". Error: " + e.getMessage()); throw handleException(e); } } @@ -115,12 +141,25 @@ public SMSSender addSMSSender(SMSSenderAdd smsSenderAdd) { */ public PushSender addPushSender(PushSenderAdd pushSenderAdd) { + if (pushSenderAdd == null) { + log.error("Push sender add request is null"); + throw new IllegalArgumentException("Push sender add request cannot be null"); + } + if (log.isDebugEnabled()) { + log.debug("Adding push sender: " + pushSenderAdd.getName()); + } PushSenderDTO dto = buildPushSenderDTO(pushSenderAdd); try { PushSenderDTO pushSenderDTO = NotificationSenderServiceHolder.getNotificationSenderManagementService() .addPushSender(dto); + if (pushSenderDTO == null) { + log.warn("Received null push sender DTO from service"); + throw new IllegalStateException("Failed to create push sender"); + } + log.info("Push sender added successfully: " + pushSenderDTO.getName()); return buildPushSenderFromDTO(pushSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to add push sender: " + pushSenderAdd.getName() + ". Error: " + e.getMessage()); throw handleException(e); } } @@ -132,9 +171,15 @@ public PushSender addPushSender(PushSenderAdd pushSenderAdd) { */ public void deleteNotificationSender(String notificationSenderName) { + if (log.isDebugEnabled()) { + log.debug("Deleting notification sender: " + notificationSenderName); + } try { notificationSenderManagementService.deleteNotificationSender(notificationSenderName); + log.info("Notification sender deleted successfully: " + notificationSenderName); } catch (NotificationSenderManagementException e) { + log.error("Failed to delete notification sender: " + notificationSenderName + ". Error: " + + e.getMessage()); throw handleException(e); } } @@ -243,11 +288,16 @@ public List getPushSenders() { */ public EmailSender updateEmailSender(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating email sender: " + senderName); + } EmailSenderDTO dto = buildEmailSenderDTO(senderName, emailSenderUpdateRequest); try { EmailSenderDTO emailSenderDTO = notificationSenderManagementService.updateEmailSender(dto); + log.info("Email sender updated successfully: " + senderName); return buildEmailSenderFromDTO(emailSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to update email sender: " + senderName + ". Error: " + e.getMessage()); throw handleException(e); } } @@ -261,11 +311,16 @@ public EmailSender updateEmailSender(String senderName, EmailSenderUpdateRequest */ public SMSSender updateSMSSender(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating SMS sender: " + senderName); + } SMSSenderDTO dto = buildSMSSenderDTO(senderName, smsSenderUpdateRequest); try { SMSSenderDTO smsSenderDTO = notificationSenderManagementService.updateSMSSender(dto); + log.info("SMS sender updated successfully: " + senderName); return buildSMSSenderFromDTO(smsSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to update SMS sender: " + senderName + ". Error: " + e.getMessage()); throw handleException(e); } } @@ -279,18 +334,26 @@ public SMSSender updateSMSSender(String senderName, SMSSenderUpdateRequest smsSe */ public PushSender updatePushSender(String senderName, PushSenderUpdateRequest pushSenderUpdateRequest) { + if (log.isDebugEnabled()) { + log.debug("Updating push sender: " + senderName); + } PushSenderDTO dto = buildPushSenderDTO(senderName, pushSenderUpdateRequest); try { PushSenderDTO pushSenderDTO = NotificationSenderServiceHolder.getNotificationSenderManagementService() .updatePushSender(dto); + log.info("Push sender updated successfully: " + senderName); return buildPushSenderFromDTO(pushSenderDTO); } catch (NotificationSenderManagementException e) { + log.error("Failed to update push sender: " + senderName + ". Error: " + e.getMessage()); throw handleException(e); } } private EmailSenderDTO buildEmailSenderDTO(EmailSenderAdd emailSenderAdd) { + if (emailSenderAdd == null) { + throw new IllegalArgumentException("EmailSenderAdd cannot be null"); + } EmailSenderDTO dto = new EmailSenderDTO(); dto.setName(emailSenderAdd.getName()); dto.setFromAddress(emailSenderAdd.getFromAddress()); @@ -332,6 +395,9 @@ private EmailSenderDTO buildEmailSenderDTO(String senderName, EmailSenderUpdateR private EmailSender buildEmailSenderFromDTO(EmailSenderDTO dto) { + if (dto == null) { + throw new IllegalArgumentException("EmailSenderDTO cannot be null"); + } EmailSender emailSender = new EmailSender(); emailSender.setName(dto.getName()); emailSender.setFromAddress(dto.getFromAddress()); @@ -370,6 +436,9 @@ a first class attribute. As V2 doesn't support credentials as first class attrib private SMSSenderDTO buildSMSSenderDTO(SMSSenderAdd smsSenderAdd) { + if (smsSenderAdd == null) { + throw new IllegalArgumentException("SMSSenderAdd cannot be null"); + } SMSSenderDTO dto = new SMSSenderDTO(); dto.setName(smsSenderAdd.getName()); dto.setProvider(smsSenderAdd.getProvider()); @@ -413,6 +482,9 @@ private APIError handleException(NotificationSenderManagementException e) { private SMSSender buildSMSSenderFromDTO(SMSSenderDTO dto) { + if (dto == null) { + throw new IllegalArgumentException("SMSSenderDTO cannot be null"); + } SMSSender smsSender = new SMSSender(); smsSender.setName(dto.getName()); smsSender.setProvider(dto.getProvider()); @@ -434,11 +506,20 @@ private SMSSender buildSMSSenderFromDTO(SMSSenderDTO dto) { private PushSenderDTO buildPushSenderDTO(PushSenderAdd pushSenderAdd) { + if (pushSenderAdd == null) { + throw new IllegalArgumentException("PushSenderAdd cannot be null"); + } PushSenderDTO dto = new PushSenderDTO(); dto.setName(pushSenderAdd.getName()); dto.setProvider(pushSenderAdd.getProvider()); List properties = pushSenderAdd.getProperties(); - properties.forEach((prop) -> dto.getProperties().put(prop.getKey(), prop.getValue())); + if (properties != null) { + properties.forEach((prop) -> { + if (prop != null && prop.getKey() != null && prop.getValue() != null) { + dto.getProperties().put(prop.getKey(), prop.getValue()); + } + }); + } return dto; } @@ -454,6 +535,9 @@ private PushSenderDTO buildPushSenderDTO(String senderName, PushSenderUpdateRequ private PushSender buildPushSenderFromDTO(PushSenderDTO dto) { + if (dto == null) { + throw new IllegalArgumentException("PushSenderDTO cannot be null"); + } PushSender pushSender = new PushSender(); pushSender.setName(dto.getName()); pushSender.setProvider(dto.getProvider()); diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/factories/NotificationSenderManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/factories/NotificationSenderManagementServiceFactory.java index 082b4da3f2..c415d7a117 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/factories/NotificationSenderManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/factories/NotificationSenderManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.notification.sender.v2.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderServiceHolder; import org.wso2.carbon.identity.api.server.notification.sender.v2.core.NotificationSenderManagementService; @@ -26,18 +28,24 @@ */ public class NotificationSenderManagementServiceFactory { + private static final Log log = LogFactory.getLog(NotificationSenderManagementServiceFactory.class); private static final NotificationSenderManagementService SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing NotificationSenderManagementServiceFactory."); + } org.wso2.carbon.identity.notification.sender.tenant.config.NotificationSenderManagementService notificationSenderManagementService = NotificationSenderServiceHolder .getNotificationSenderManagementService(); if (notificationSenderManagementService == null) { + log.error("NotificationSenderManagementService is not available from OSGi context."); throw new IllegalStateException("NotificationSenderManagementService is not available from OSGi context."); } SERVICE = new NotificationSenderManagementService(notificationSenderManagementService); + log.info("NotificationSenderManagementServiceFactory initialized successfully."); } /** @@ -47,6 +55,9 @@ public class NotificationSenderManagementServiceFactory { */ public static NotificationSenderManagementService getNotificationSenderManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving NotificationSenderManagementService instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/impl/NotificationSendersApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/impl/NotificationSendersApiServiceImpl.java index 6be40dc1e8..889d4306f2 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/impl/NotificationSendersApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/java/org/wso2/carbon/identity/api/server/notification/sender/v2/impl/NotificationSendersApiServiceImpl.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.notification.sender.v2.impl; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.common.error.APIError; @@ -57,6 +59,7 @@ */ public class NotificationSendersApiServiceImpl implements NotificationSendersApiService { + private static final Log log = LogFactory.getLog(NotificationSendersApiServiceImpl.class); private final NotificationSenderManagementService notificationSenderManagementService; public NotificationSendersApiServiceImpl() { @@ -64,7 +67,11 @@ public NotificationSendersApiServiceImpl() { try { this.notificationSenderManagementService = NotificationSenderManagementServiceFactory .getNotificationSenderManagementService(); + if (log.isDebugEnabled()) { + log.debug("NotificationSenderManagementService initialized successfully."); + } } catch (IllegalStateException e) { + log.error("Error occurred while initiating notification sender service.", e); throw new RuntimeException("Error occurred while initiating notification sender service.", e); } } @@ -72,9 +79,21 @@ public NotificationSendersApiServiceImpl() { @Override public Response createEmailSender(EmailSenderAdd emailSenderAdd) { + if (emailSenderAdd == null) { + log.error("Email sender add request is null"); + ErrorResponse errorResponse = new ErrorResponse.Builder() + .withMessage("Email sender add request cannot be null").build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorResponse).build(); + } if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if (log.isDebugEnabled()) { + log.debug("Email sender creation not allowed for super tenant."); + } return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + if (log.isDebugEnabled()) { + log.debug("Creating email sender: " + emailSenderAdd.getName()); + } EmailSender emailSender = notificationSenderManagementService.addEmailSender(emailSenderAdd); URI location = null; try { @@ -83,16 +102,28 @@ public Response createEmailSender(EmailSenderAdd emailSenderAdd) { URLEncoder.encode(emailSender.getName(), StandardCharsets.UTF_8.name()) .replace(PLUS, URL_ENCODED_SPACE)); } catch (UnsupportedEncodingException e) { + log.warn("Unsupported encoding encountered while creating location header for email sender: " + + emailSender.getName()); ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build(); throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse); } + log.info("Email sender created successfully: " + emailSender.getName()); return Response.created(location).entity(emailSender).build(); } @Override public Response createPushSender(PushSenderAdd pushSenderAdd) { + if (pushSenderAdd == null) { + log.error("Push sender add request is null"); + ErrorResponse errorResponse = new ErrorResponse.Builder() + .withMessage("Push sender add request cannot be null").build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorResponse).build(); + } + if (log.isDebugEnabled()) { + log.debug("Creating push sender: " + pushSenderAdd.getName()); + } PushSender pushSender = notificationSenderManagementService.addPushSender(pushSenderAdd); URI location = null; try { @@ -101,16 +132,28 @@ public Response createPushSender(PushSenderAdd pushSenderAdd) { URLEncoder.encode(pushSender.getName(), StandardCharsets.UTF_8.name()) .replace(PLUS, URL_ENCODED_SPACE)); } catch (UnsupportedEncodingException e) { + log.warn("Unsupported encoding encountered while creating location header for push sender: " + + pushSender.getName()); ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build(); throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse); } + log.info("Push sender created successfully: " + pushSender.getName()); return Response.created(location).entity(pushSender).build(); } @Override public Response createSMSSender(SMSSenderAdd smSSenderAdd) { + if (smSSenderAdd == null) { + log.error("SMS sender add request is null"); + ErrorResponse errorResponse = new ErrorResponse.Builder() + .withMessage("SMS sender add request cannot be null").build(); + return Response.status(Response.Status.BAD_REQUEST).entity(errorResponse).build(); + } + if (log.isDebugEnabled()) { + log.debug("Creating SMS sender: " + smSSenderAdd.getName()); + } SMSSender smsSender = notificationSenderManagementService.addSMSSender(smSSenderAdd); URI location = null; try { @@ -119,10 +162,13 @@ public Response createSMSSender(SMSSenderAdd smSSenderAdd) { URLEncoder.encode(smsSender.getName(), StandardCharsets.UTF_8.name()) .replace(PLUS, URL_ENCODED_SPACE)); } catch (UnsupportedEncodingException e) { + log.warn("Unsupported encoding encountered while creating location header for SMS sender: " + + smsSender.getName()); ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build(); throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse); } + log.info("SMS sender created successfully: " + smsSender.getName()); return Response.created(location).entity(smsSender).build(); } @@ -130,23 +176,38 @@ public Response createSMSSender(SMSSenderAdd smSSenderAdd) { public Response deleteEmailSender(String senderName) { if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if (log.isDebugEnabled()) { + log.debug("Email sender deletion not allowed for super tenant."); + } return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + if (log.isDebugEnabled()) { + log.debug("Deleting email sender: " + senderName); + } notificationSenderManagementService.deleteNotificationSender(senderName); + log.info("Email sender deleted successfully: " + senderName); return Response.noContent().build(); } @Override public Response deletePushSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Deleting push sender: " + senderName); + } notificationSenderManagementService.deleteNotificationSender(senderName); + log.info("Push sender deleted successfully: " + senderName); return Response.noContent().build(); } @Override public Response deleteSMSSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Deleting SMS sender: " + senderName); + } notificationSenderManagementService.deleteNotificationSender(senderName); + log.info("SMS sender deleted successfully: " + senderName); return Response.noContent().build(); } @@ -154,8 +215,14 @@ public Response deleteSMSSender(String senderName) { public Response getEmailSender(String senderName) { if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if (log.isDebugEnabled()) { + log.debug("Email sender retrieval not allowed for super tenant."); + } return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + if (log.isDebugEnabled()) { + log.debug("Retrieving email sender: " + senderName); + } return Response.ok().entity(notificationSenderManagementService.getEmailSender(senderName)).build(); } @@ -163,32 +230,50 @@ public Response getEmailSender(String senderName) { public Response getEmailSenders() { if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if (log.isDebugEnabled()) { + log.debug("Email senders retrieval not allowed for super tenant."); + } return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } + if (log.isDebugEnabled()) { + log.debug("Retrieving all email senders."); + } return Response.ok().entity(notificationSenderManagementService.getEmailSenders()).build(); } @Override public Response getPushSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving push sender: " + senderName); + } return Response.ok().entity(notificationSenderManagementService.getPushSender(senderName)).build(); } @Override public Response getPushSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all push senders."); + } return Response.ok().entity(notificationSenderManagementService.getPushSenders()).build(); } @Override public Response getSMSSender(String senderName) { + if (log.isDebugEnabled()) { + log.debug("Retrieving SMS sender: " + senderName); + } return Response.ok().entity(notificationSenderManagementService.getSMSSender(senderName)).build(); } @Override public Response getSMSSenders() { + if (log.isDebugEnabled()) { + log.debug("Retrieving all SMS senders."); + } return Response.ok().entity(notificationSenderManagementService.getSMSSenders()).build(); } @@ -196,26 +281,41 @@ public Response getSMSSenders() { public Response updateEmailSender(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) { if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + if (log.isDebugEnabled()) { + log.debug("Email sender update not allowed for super tenant."); + } return Response.status(Response.Status.METHOD_NOT_ALLOWED).build(); } - return Response.ok() - .entity(notificationSenderManagementService.updateEmailSender(senderName, emailSenderUpdateRequest)) - .build(); + if (log.isDebugEnabled()) { + log.debug("Updating email sender: " + senderName); + } + EmailSender updatedEmailSender = notificationSenderManagementService.updateEmailSender(senderName, + emailSenderUpdateRequest); + log.info("Email sender updated successfully: " + senderName); + return Response.ok().entity(updatedEmailSender).build(); } @Override public Response updatePushSender(String senderName, PushSenderUpdateRequest pushSenderUpdateRequest) { - return Response.ok() - .entity(notificationSenderManagementService.updatePushSender(senderName, pushSenderUpdateRequest)) - .build(); + if (log.isDebugEnabled()) { + log.debug("Updating push sender: " + senderName); + } + PushSender updatedPushSender = notificationSenderManagementService.updatePushSender(senderName, + pushSenderUpdateRequest); + log.info("Push sender updated successfully: " + senderName); + return Response.ok().entity(updatedPushSender).build(); } @Override public Response updateSMSSender(String senderName, SMSSenderUpdateRequest smSSenderUpdateRequest) { - return Response.ok() - .entity(notificationSenderManagementService.updateSMSSender(senderName, smSSenderUpdateRequest)) - .build(); + if (log.isDebugEnabled()) { + log.debug("Updating SMS sender: " + senderName); + } + SMSSender updatedSMSSender = notificationSenderManagementService.updateSMSSender(senderName, + smSSenderUpdateRequest); + log.info("SMS sender updated successfully: " + senderName); + return Response.ok().entity(updatedSMSSender).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.api.server.notification.template.common/src/main/java/org/wso2/carbon/identity/api/server/notification/template/common/TemplatesServiceHolder.java b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.api.server.notification.template.common/src/main/java/org/wso2/carbon/identity/api/server/notification/template/common/TemplatesServiceHolder.java index 564b72e73a..30e8f47c16 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.api.server.notification.template.common/src/main/java/org/wso2/carbon/identity/api/server/notification/template/common/TemplatesServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.api.server.notification.template.common/src/main/java/org/wso2/carbon/identity/api/server/notification/template/common/TemplatesServiceHolder.java @@ -45,13 +45,18 @@ private static class NotificationTemplateManagerHolder { private static NotificationTemplateManager resolveNotificationTemplateManager() { + if (LOG.isDebugEnabled()) { + LOG.debug("Starting to resolve NotificationTemplateManager service."); + } Hashtable serviceProperties = new Hashtable<>(); serviceProperties.put(I18nMgtConstants.SERVICE_PROPERTY_KEY_SERVICE_NAME, I18nMgtConstants.SERVICE_PROPERTY_VAL_NOTIFICATION_TEMPLATE_MANAGER); NotificationTemplateManager taskOperationService = (NotificationTemplateManager) PrivilegedCarbonContext. getThreadLocalCarbonContext().getOSGiService(NotificationTemplateManager.class, serviceProperties); if (taskOperationService == null) { - LOG.debug("Unable to retrieve NotificationTemplateManager service."); + LOG.error("Unable to retrieve NotificationTemplateManager service from OSGi service registry."); + } else { + LOG.info("Successfully resolved NotificationTemplateManager service."); } return taskOperationService; } @@ -63,6 +68,13 @@ private static NotificationTemplateManager resolveNotificationTemplateManager() */ public static NotificationTemplateManager getNotificationTemplateManager() { - return NotificationTemplateManagerHolder.SERVICE; + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving NotificationTemplateManager service from holder."); + } + NotificationTemplateManager service = NotificationTemplateManagerHolder.SERVICE; + if (service == null) { + LOG.warn("NotificationTemplateManager service is not available."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplateTypeService.java b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplateTypeService.java index c4b0348253..1a7d1d9e0c 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplateTypeService.java +++ b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplateTypeService.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.notification.template.v1.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.notification.template.common.Constants; import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerException; import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager; @@ -36,11 +38,15 @@ */ public class TemplateTypeService { + private static final Log log = LogFactory.getLog(TemplateTypeService.class); private final NotificationTemplateManager notificationTemplateManager; public TemplateTypeService(NotificationTemplateManager notificationTemplateManager) { this.notificationTemplateManager = notificationTemplateManager; + if (log.isDebugEnabled()) { + log.debug("TemplateTypeService initialized successfully."); + } } /** * Add a new template type for a given channel. @@ -53,6 +59,9 @@ public TemplateTypeWithID addNotificationTemplateType(String notificationChannel TemplateTypeOverview templateTypeOverview) { String templateTypeDisplayName = templateTypeOverview.getDisplayName(); + if (log.isDebugEnabled()) { + log.debug("Adding template type: " + templateTypeDisplayName + ", Channel: " + notificationChannel); + } try { notificationTemplateManager.addNotificationTemplateType(notificationChannel, templateTypeDisplayName, getTenantDomainFromContext()); @@ -62,6 +71,8 @@ public TemplateTypeWithID addNotificationTemplateType(String notificationChannel String templateTypeId = Util.resolveTemplateIdFromDisplayName(templateTypeDisplayName); response.setId(templateTypeId); response.setSelf(Util.getTemplateTypeLocation(templateTypeId, notificationChannel)); + log.info("Successfully added template type: " + templateTypeDisplayName + ", Channel: " + + notificationChannel); return response; } catch (NotificationTemplateManagerException e) { throw Util.handleNotificationTemplateManagerException(e, @@ -77,6 +88,9 @@ public TemplateTypeWithID addNotificationTemplateType(String notificationChannel */ public List getAllNotificationTemplateTypes(String notificationChannel) { + if (log.isDebugEnabled()) { + log.debug("Retrieving all template types for channel: " + notificationChannel); + } try { List templateTypes = notificationTemplateManager.getAllNotificationTemplateTypes( notificationChannel, getTenantDomainFromContext()); @@ -109,13 +123,21 @@ public void deleteNotificationTemplateType(String notificationChannel, String te String templateTypeDisplayName; templateTypeDisplayName = Util.decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Deleting template type: " + templateTypeDisplayName + ", Channel: " + notificationChannel); + } try { boolean isTemplateTypeExists = notificationTemplateManager.isNotificationTemplateTypeExists( notificationChannel, templateTypeDisplayName, getTenantDomainFromContext()); if (isTemplateTypeExists) { notificationTemplateManager.deleteNotificationTemplateType(notificationChannel, templateTypeDisplayName, getTenantDomainFromContext()); + log.info("Successfully deleted template type: " + templateTypeDisplayName + ", Channel: " + + notificationChannel); } else { + if (log.isDebugEnabled()) { + log.debug("Template type not found for deletion: " + templateTypeDisplayName); + } throw Util.handleError(Constants.ErrorMessage.ERROR_TEMPLATE_TYPE_NOT_FOUND); } } catch (NotificationTemplateManagerException e) { diff --git a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplatesService.java b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplatesService.java index 7ca86e601b..b7b9ea43c7 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplatesService.java +++ b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/core/TemplatesService.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.rest.api.server.notification.template.v1.core; 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.notification.template.common.Constants; import org.wso2.carbon.identity.governance.exceptions.notiification.NotificationTemplateManagerException; import org.wso2.carbon.identity.governance.model.NotificationTemplate; @@ -39,11 +41,15 @@ */ public class TemplatesService { + private static final Log log = LogFactory.getLog(TemplatesService.class); private final NotificationTemplateManager notificationTemplateManager; public TemplatesService(NotificationTemplateManager notificationTemplateManager) { this.notificationTemplateManager = notificationTemplateManager; + if (log.isDebugEnabled()) { + log.debug("TemplatesService initialized successfully."); + } } /** * Adds a new organization email template to the given template type. Template ID should not exist in the system. @@ -68,6 +74,10 @@ public SimpleTemplate addEmailTemplate(String templateTypeId, EmailTemplateWithI public SimpleTemplate addEmailTemplate(String templateTypeId, EmailTemplateWithID emailTemplateWithID, String applicationUuid) { + if (log.isDebugEnabled()) { + log.debug("Adding email template. TemplateTypeId: " + templateTypeId + ", Locale: " + + emailTemplateWithID.getLocale()); + } try { NotificationTemplate notificationTemplate = Util.buildNotificationTemplateWithEmailTemplateWithID( templateTypeId, emailTemplateWithID); @@ -84,6 +94,8 @@ public SimpleTemplate addEmailTemplate(String templateTypeId, EmailTemplateWithI SimpleTemplate simpleEmailTemplate = new SimpleTemplate(); simpleEmailTemplate.setSelf(templateLocation); simpleEmailTemplate.setLocale(notificationTemplate.getLocale()); + log.info("Successfully added email template. TemplateTypeId: " + templateTypeId + ", Locale: " + + notificationTemplate.getLocale()); return simpleEmailTemplate; } catch (NotificationTemplateManagerException e) { throw Util.handleNotificationTemplateManagerException(e, @@ -114,6 +126,10 @@ public SimpleTemplate addSMSTemplate(String templateTypeId, SMSTemplateWithID sm public SimpleTemplate addSMSTemplate(String templateTypeId, SMSTemplateWithID smsTemplateWithID, String applicationUuid) { + if (log.isDebugEnabled()) { + log.debug("Adding SMS template. TemplateTypeId: " + templateTypeId + ", Locale: " + + smsTemplateWithID.getLocale()); + } try { NotificationTemplate notificationTemplate = Util.buildNotificationTemplateWithSMSTemplateWithID( templateTypeId, smsTemplateWithID); @@ -130,6 +146,8 @@ public SimpleTemplate addSMSTemplate(String templateTypeId, SMSTemplateWithID sm SimpleTemplate simpleSMSTemplate = new SimpleTemplate(); simpleSMSTemplate.setSelf(templateLocation); simpleSMSTemplate.setLocale(notificationTemplate.getLocale()); + log.info("Successfully added SMS template. TemplateTypeId: " + templateTypeId + ", Locale: " + + notificationTemplate.getLocale()); return simpleSMSTemplate; } catch (NotificationTemplateManagerException e) { throw Util.handleNotificationTemplateManagerException(e, @@ -166,6 +184,10 @@ public List getAllTemplatesOfTemplateType(String templateTypeId, String notificationChannel, boolean resolve) { String templateTypeDisplayName = Util.decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Retrieving all templates of type: " + templateTypeDisplayName + ", Channel: " + + notificationChannel); + } try { List templates = notificationTemplateManager.getNotificationTemplatesOfType( notificationChannel, templateTypeDisplayName, getTenantDomainFromContext(), applicationUuid, @@ -363,11 +385,16 @@ public void updateEmailTemplate(String templateTypeId, String templateId, EmailT EmailTemplateWithID emailTemplateWithID = Util.buildEmailTemplateWithIdUsingEmailTemplate(emailTemplate, templateId); + if (log.isDebugEnabled()) { + log.debug("Updating email template. TemplateTypeId: " + templateTypeId + ", Locale: " + templateId); + } try { NotificationTemplate notificationTemplate = Util.buildNotificationTemplateWithEmailTemplateWithID( templateTypeId, emailTemplateWithID); notificationTemplateManager.updateNotificationTemplate(notificationTemplate, getTenantDomainFromContext(), applicationUuid); + log.info("Successfully updated email template. TemplateTypeId: " + templateTypeId + ", Locale: " + + templateId); } catch (NotificationTemplateManagerException e) { throw Util.handleNotificationTemplateManagerException(e, Constants.ErrorMessage.ERROR_ERROR_UPDATING_TEMPLATE); @@ -399,11 +426,16 @@ public void updateSMSTemplate(String templateTypeId, String templateId, SMSTempl SMSTemplateWithID smsTemplateWithID = Util.buildSMSTemplateWithIdUsingSMSTemplate(smsTemplate, templateId); + if (log.isDebugEnabled()) { + log.debug("Updating SMS template. TemplateTypeId: " + templateTypeId + ", Locale: " + templateId); + } try { NotificationTemplate notificationTemplate = Util.buildNotificationTemplateWithSMSTemplateWithID( templateTypeId, smsTemplateWithID); notificationTemplateManager.updateNotificationTemplate(notificationTemplate, getTenantDomainFromContext(), applicationUuid); + log.info("Successfully updated SMS template. TemplateTypeId: " + templateTypeId + ", Locale: " + + templateId); } catch (NotificationTemplateManagerException e) { throw Util.handleNotificationTemplateManagerException(e, Constants.ErrorMessage.ERROR_ERROR_UPDATING_TEMPLATE); @@ -431,6 +463,9 @@ public void deleteEmailTemplate(String templateTypeId, String locale) { public void deleteEmailTemplate(String templateTypeId, String locale, String applicationUuid) { String templateTypeDisplayName = Util.decodeTemplateTypeId(templateTypeId); + if (log.isDebugEnabled()) { + log.debug("Deleting email template. TemplateTypeId: " + templateTypeId + ", Locale: " + locale); + } try { Util.verifyTemplateTypeExists(Constants.NOTIFICATION_CHANNEL_EMAIL, templateTypeDisplayName); boolean notificationTemplateExists = notificationTemplateManager.isNotificationTemplateExists( @@ -439,7 +474,13 @@ public void deleteEmailTemplate(String templateTypeId, String locale, String app if (notificationTemplateExists) { notificationTemplateManager.deleteNotificationTemplate(Constants.NOTIFICATION_CHANNEL_EMAIL, templateTypeDisplayName, locale, getTenantDomainFromContext(), applicationUuid); + log.info("Successfully deleted email template. TemplateTypeId: " + templateTypeId + ", Locale: " + + locale); } else { + if (log.isDebugEnabled()) { + log.debug("Email template not found for deletion. TemplateTypeId: " + templateTypeId + + ", Locale: " + locale); + } throw Util.handleError(Constants.ErrorMessage.ERROR_TEMPLATE_NOT_FOUND); } } catch (NotificationTemplateManagerException e) { diff --git a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplateTypeServiceFactory.java b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplateTypeServiceFactory.java index 0ee6ed63f2..bf48086179 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplateTypeServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplateTypeServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.notification.template.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.notification.template.common.TemplatesServiceHolder; import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager; import org.wso2.carbon.identity.rest.api.server.notification.template.v1.core.TemplateTypeService; @@ -27,15 +29,20 @@ */ public class TemplateTypeServiceFactory { + private static final Log log = LogFactory.getLog(TemplateTypeServiceFactory.class); private static final TemplateTypeService SERVICE; static { NotificationTemplateManager notificationTemplateManager = TemplatesServiceHolder .getNotificationTemplateManager(); if (notificationTemplateManager == null) { + log.error("NotificationTemplateManager is not available from OSGi context."); throw new IllegalStateException("NotificationTemplateManager is not available from OSGi context."); } SERVICE = new TemplateTypeService(notificationTemplateManager); + if (log.isDebugEnabled()) { + log.debug("TemplateTypeService instance created successfully."); + } } /** @@ -45,6 +52,9 @@ public class TemplateTypeServiceFactory { */ public static TemplateTypeService getTemplateTypeService() { + if (log.isDebugEnabled()) { + log.debug("Returning TemplateTypeService instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplatesServiceFactory.java b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplatesServiceFactory.java index f653b60b56..5ee57979d4 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplatesServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/factories/TemplatesServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.notification.template.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.notification.template.common.TemplatesServiceHolder; import org.wso2.carbon.identity.governance.service.notification.NotificationTemplateManager; import org.wso2.carbon.identity.rest.api.server.notification.template.v1.core.TemplatesService; @@ -27,15 +29,20 @@ */ public class TemplatesServiceFactory { + private static final Log log = LogFactory.getLog(TemplatesServiceFactory.class); private static final TemplatesService SERVICE; static { NotificationTemplateManager notificationTemplateManager = TemplatesServiceHolder .getNotificationTemplateManager(); if (notificationTemplateManager == null) { + log.error("NotificationTemplateManager is not available from OSGi context."); throw new IllegalStateException("NotificationTemplateManager is not available from OSGi context."); } SERVICE = new TemplatesService(notificationTemplateManager); + if (log.isDebugEnabled()) { + log.debug("TemplatesService instance created successfully."); + } } /** @@ -45,6 +52,9 @@ public class TemplatesServiceFactory { */ public static TemplatesService getTemplatesService() { + if (log.isDebugEnabled()) { + log.debug("Returning TemplatesService instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/impl/NotificationApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/impl/NotificationApiServiceImpl.java index a410186e25..82cf1a5dc0 100644 --- a/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/impl/NotificationApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.notification.template/org.wso2.carbon.identity.rest.api.server.notification.template.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/notification/template/v1/impl/NotificationApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.rest.api.server.notification.template.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.notification.template.common.Constants; import org.wso2.carbon.identity.rest.api.server.notification.template.v1.NotificationApiService; import org.wso2.carbon.identity.rest.api.server.notification.template.v1.core.TemplateTypeService; @@ -52,6 +54,7 @@ */ public class NotificationApiServiceImpl implements NotificationApiService { + private static final Log log = LogFactory.getLog(NotificationApiServiceImpl.class); private final TemplatesService templatesService; private final TemplateTypeService templateTypeService; @@ -59,42 +62,59 @@ public NotificationApiServiceImpl() { templatesService = TemplatesServiceFactory.getTemplatesService(); templateTypeService = TemplateTypeServiceFactory.getTemplateTypeService(); + if (log.isDebugEnabled()) { + log.debug("NotificationApiServiceImpl initialized successfully."); + } } @Override public Response addAppEmailTemplate(String templateTypeId, String appUuid, EmailTemplateWithID emailTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug("Adding email template for app. TemplateTypeId: " + templateTypeId + ", AppUuid: " + appUuid); + } SimpleTemplate simpleEmailTemplate = templatesService.addEmailTemplate(templateTypeId, emailTemplateWithID, appUuid); URI headerLocation = buildURIForHeader(V1_API_PATH_COMPONENT + NOTIFICATION_TEMPLATES_API_PATH + NOTIFICATION_TEMPLATES_API_BASE_PATH_EMAIL + TEMPLATE_TYPES_PATH + PATH_SEPARATOR + templateTypeId + APP_TEMPLATES_PATH + PATH_SEPARATOR + appUuid + PATH_SEPARATOR + simpleEmailTemplate.getLocale()); + log.info("Successfully added email template for app. TemplateTypeId: " + templateTypeId + ", Locale: " + + simpleEmailTemplate.getLocale()); return Response.created(headerLocation).entity(simpleEmailTemplate).build(); } @Override public Response addAppSMSTemplate(String templateTypeId, String appUuid, SMSTemplateWithID smSTemplateWithID) { + if (log.isDebugEnabled()) { + log.debug("Adding SMS template for app. TemplateTypeId: " + templateTypeId + ", AppUuid: " + appUuid); + } SimpleTemplate simpleSMSTemplate = templatesService.addSMSTemplate(templateTypeId, smSTemplateWithID, appUuid); URI headerLocation = buildURIForHeader(V1_API_PATH_COMPONENT + NOTIFICATION_TEMPLATES_API_PATH + NOTIFICATION_TEMPLATES_API_BASE_PATH_SMS + TEMPLATE_TYPES_PATH + PATH_SEPARATOR + templateTypeId + APP_TEMPLATES_PATH + PATH_SEPARATOR + appUuid + PATH_SEPARATOR + smSTemplateWithID.getLocale()); + log.info("Successfully added SMS template for app. TemplateTypeId: " + templateTypeId + ", Locale: " + + simpleSMSTemplate.getLocale()); return Response.created(headerLocation).entity(simpleSMSTemplate).build(); } @Override public Response addEmailTemplateType(TemplateTypeOverview templateTypeOverview) { + if (log.isDebugEnabled()) { + log.debug("Adding email template type: " + templateTypeOverview.getDisplayName()); + } TemplateTypeWithID templateType = templateTypeService .addNotificationTemplateType(Constants.NOTIFICATION_CHANNEL_EMAIL, templateTypeOverview); URI headerLocation = buildURIForHeader( V1_API_PATH_COMPONENT + NOTIFICATION_TEMPLATES_API_PATH + NOTIFICATION_TEMPLATES_API_BASE_PATH_EMAIL + TEMPLATE_TYPES_PATH + PATH_SEPARATOR + templateType.getId()); + log.info("Successfully added email template type: " + templateTypeOverview.getDisplayName()); return Response.created(headerLocation).entity(templateType).build(); } @@ -137,7 +157,11 @@ public Response addSMSTemplateType(TemplateTypeOverview templateTypeOverview) { @Override public Response deleteAppEmailTemplate(String templateTypeId, String appUuid, String locale) { + if (log.isDebugEnabled()) { + log.debug("Deleting email template. TemplateTypeId: " + templateTypeId + ", Locale: " + locale); + } templatesService.deleteEmailTemplate(templateTypeId, locale, appUuid); + log.info("Successfully deleted email template. TemplateTypeId: " + templateTypeId + ", Locale: " + locale); return Response.noContent().build(); } @@ -151,7 +175,11 @@ public Response deleteAppSMSTemplate(String templateTypeId, String appUuid, Stri @Override public Response deleteEmailTemplateType(String templateTypeId) { + if (log.isDebugEnabled()) { + log.debug("Deleting email template type with ID: " + templateTypeId); + } templateTypeService.deleteNotificationTemplateType(Constants.NOTIFICATION_CHANNEL_EMAIL, templateTypeId); + log.info("Successfully deleted email template type with ID: " + templateTypeId); return Response.noContent().build(); } @@ -289,8 +317,14 @@ public Response getSystemSMSTemplate(String templateTypeId, String locale) { @Override public Response resetTemplateType(SimpleTemplateTypeID simpleTemplateTypeID) { + if (log.isDebugEnabled()) { + log.debug("Resetting template type. Channel: " + simpleTemplateTypeID.getChannel() + + ", TemplateTypeId: " + simpleTemplateTypeID.getTemplateTypeId()); + } templateTypeService.resetTemplateType(simpleTemplateTypeID.getChannel(), simpleTemplateTypeID.getTemplateTypeId()); + log.info("Successfully reset template type. Channel: " + simpleTemplateTypeID.getChannel() + + ", TemplateTypeId: " + simpleTemplateTypeID.getTemplateTypeId()); return Response.noContent().build(); } @@ -298,7 +332,11 @@ public Response resetTemplateType(SimpleTemplateTypeID simpleTemplateTypeID) { public Response updateAppEmailTemplate(String templateTypeId, String appUuid, String locale, EmailTemplate emailTemplate) { + if (log.isDebugEnabled()) { + log.debug("Updating email template. TemplateTypeId: " + templateTypeId + ", Locale: " + locale); + } templatesService.updateEmailTemplate(templateTypeId, locale, emailTemplate, appUuid); + log.info("Successfully updated email template. TemplateTypeId: " + templateTypeId + ", Locale: " + locale); return Response.ok().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.common/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/common/OIDCScopeManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.common/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/common/OIDCScopeManagementServiceHolder.java index d8aa35b772..7b3004c686 100644 --- a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.common/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/common/OIDCScopeManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.common/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/common/OIDCScopeManagementServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.oidc.scope.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.oauth.OAuthAdminServiceImpl; @@ -26,6 +28,8 @@ */ public class OIDCScopeManagementServiceHolder { + private static final Log log = LogFactory.getLog(OIDCScopeManagementServiceHolder.class); + private OIDCScopeManagementServiceHolder () {} private static class OAuthAdminServiceImplServiceHolder { @@ -41,6 +45,13 @@ private static class OAuthAdminServiceImplServiceHolder { */ public static OAuthAdminServiceImpl getOAuthAdminService() { - return OAuthAdminServiceImplServiceHolder.SERVICE; + OAuthAdminServiceImpl service = OAuthAdminServiceImplServiceHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieved OAuthAdminService from OSGi context."); + } + if (service == null) { + log.warn("OAuthAdminService is not available in the OSGi context."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/core/OidcScopeManagementService.java b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/core/OidcScopeManagementService.java index 37289d03a1..9bf9e3ce7c 100644 --- a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/core/OidcScopeManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/core/OidcScopeManagementService.java @@ -57,15 +57,27 @@ public OidcScopeManagementService(OAuthAdminServiceImpl oauthAdminService) { */ public String addScope(Scope scopeObject) { + if (LOG.isDebugEnabled()) { + LOG.debug("Adding OIDC scope: " + + (scopeObject != null ? scopeObject.getName() : "null")); + } + + if (scopeObject == null) { + LOG.error("Cannot add OIDC scope: scopeObject is null"); + throw new IllegalArgumentException("Scope object cannot be null"); + } try { List claimList = scopeObject.getClaims(); - String[] claimArray = claimList.toArray(new String[claimList.size()]); + String[] claimArray = claimList != null ? + claimList.toArray(new String[claimList.size()]) : new String[0]; ScopeDTO scopeDTO = new ScopeDTO(scopeObject.getName(), scopeObject.getDisplayName(), scopeObject.getDescription(), claimArray); oauthAdminService.addScope(scopeDTO); + LOG.info("Successfully added OIDC scope: " + scopeDTO.getName()); return scopeDTO.getName(); } catch (IdentityOAuthAdminException e) { - throw handleException(e, "Server encountered an error while adding OIDC scope: " + scopeObject.getName()); + throw handleException(e, "Server encountered an error while adding OIDC scope: " + + scopeObject.getName()); } } @@ -76,11 +88,15 @@ public String addScope(Scope scopeObject) { */ public void deleteScope(String id) { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting OIDC scope: " + id); + } try { oauthAdminService.deleteScope(id); + LOG.info("Successfully deleted OIDC scope: " + id); } catch (IdentityOAuthClientException e) { if (LOG.isDebugEnabled()) { - LOG.debug(e); + LOG.debug("Client exception occurred while deleting OIDC scope: " + id, e); } } catch (IdentityOAuthAdminException e) { throw handleException(e, "Server encountered an error while deleting OIDC scope: " + id); @@ -95,6 +111,9 @@ public void deleteScope(String id) { */ public Scope getScope(String id) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving OIDC scope: " + id); + } try { ScopeDTO scopeDTO = oauthAdminService.getScope(id); return convertScopeDTOObjectToScope(scopeDTO); @@ -110,9 +129,16 @@ public Scope getScope(String id) { */ public List getScopes() { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving all OIDC scopes"); + } try { ScopeDTO[] scopes = oauthAdminService.getScopes(); - return buildScopeList(scopes); + List scopeList = buildScopeList(scopes); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved " + (scopes != null ? scopes.length : 0) + " OIDC scopes"); + } + return scopeList; } catch (IdentityOAuthAdminException e) { throw handleException(e, "Server encountered an error while listing OIDC scopes."); } @@ -127,12 +153,16 @@ public List getScopes() { */ public void updateScope(String id, ScopeUpdateRequest scopeUpdateObject) { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating OIDC scope: " + id); + } try { List claimList = scopeUpdateObject.getClaims(); String[] claimArray = claimList.toArray(new String[claimList.size()]); ScopeDTO scopeDTO = new ScopeDTO(id, scopeUpdateObject.getDisplayName(), scopeUpdateObject.getDescription(), claimArray); oauthAdminService.updateScope(scopeDTO); + LOG.info("Successfully updated OIDC scope: " + id); } catch (IdentityOAuthAdminException e) { throw handleException(e, "Server encountered an error while updating OIDC scope: " + id); } diff --git a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/factories/OidcScopeManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/factories/OidcScopeManagementServiceFactory.java index 4e8e41f344..745bc43f8e 100644 --- a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/factories/OidcScopeManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/factories/OidcScopeManagementServiceFactory.java @@ -17,6 +17,8 @@ */ package org.wso2.carbon.identity.api.server.oidc.scope.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.oidc.scope.management.common.OIDCScopeManagementServiceHolder; import org.wso2.carbon.identity.api.server.oidc.scope.management.v1.core.OidcScopeManagementService; import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; @@ -25,17 +27,23 @@ * Factory class for OidcScopeManagementService. */ public class OidcScopeManagementServiceFactory { + private static final Log LOG = LogFactory.getLog(OidcScopeManagementServiceFactory.class); private static final OidcScopeManagementService SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing OidcScopeManagementService"); + } OAuthAdminServiceImpl oAuthAdminService = OIDCScopeManagementServiceHolder .getOAuthAdminService(); if (oAuthAdminService == null) { + LOG.warn("OAuthAdminServiceImpl is not available from OSGi context"); throw new IllegalStateException("OAuthAdminServiceImpl is not available from OSGi context."); } SERVICE = new OidcScopeManagementService(oAuthAdminService); + LOG.info("OidcScopeManagementService initialized successfully"); } /** @@ -45,6 +53,9 @@ public class OidcScopeManagementServiceFactory { */ public static OidcScopeManagementService getPermissionManagementService() { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving OidcScopeManagementService instance"); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/impl/OidcApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/impl/OidcApiServiceImpl.java index fe7391dcb8..88b225eb31 100644 --- a/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/impl/OidcApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.oidc.scope.management/org.wso2.carbon.identity.api.server.oidc.scope.management.v1/src/main/java/org/wso2/carbon/identity/api/server/oidc/scope/management/v1/impl/OidcApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.oidc.scope.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.Constants; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.oidc.scope.management.common.OidcScopeConstants; @@ -36,13 +38,19 @@ */ public class OidcApiServiceImpl implements OidcApiService { + private static final Log LOG = LogFactory.getLog(OidcApiServiceImpl.class); private final OidcScopeManagementService oidcScopeManagementService; public OidcApiServiceImpl() { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing OidcApiServiceImpl"); + } this.oidcScopeManagementService = OidcScopeManagementServiceFactory.getPermissionManagementService(); + LOG.info("OidcApiServiceImpl initialized successfully"); } catch (IllegalStateException e) { + LOG.warn("Error occurred while initiating OidcScopeManagementService", e); throw new RuntimeException("Error occurred while initiating OidcScopeManagementService.", e); } } @@ -50,33 +58,57 @@ public OidcApiServiceImpl() { @Override public Response addScope(Scope scope) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing add scope request for: " + + (scope != null ? scope.getName() : "null")); + } + + if (scope == null) { + LOG.error("Cannot process add scope request: scope parameter is null"); + return Response.status(Response.Status.BAD_REQUEST).build(); + } String resourceId = oidcScopeManagementService.addScope(scope); + LOG.info("Scope added successfully with ID: " + resourceId); return Response.created(getResourceLocation(resourceId)).build(); } @Override public Response deleteScope(String id) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing delete scope request for ID: " + id); + } oidcScopeManagementService.deleteScope(id); + LOG.info("Scope deletion processed for ID: " + id); return Response.noContent().build(); } @Override public Response getScope(String id) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing get scope request for ID: " + id); + } return Response.ok().entity(oidcScopeManagementService.getScope(id)).build(); } @Override public Response getScopes() { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing get all scopes request"); + } return Response.ok().entity(oidcScopeManagementService.getScopes()).build(); } @Override public Response updateScope(String id, ScopeUpdateRequest scopeUpdateRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing update scope request for ID: " + id); + } oidcScopeManagementService.updateScope(id, scopeUpdateRequest); + LOG.info("Scope updated successfully for ID: " + id); return Response.ok().build(); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java index 5f60f7d28e..ab04adf503 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.common/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/common/OrganizationConfigsServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.configs.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager; @@ -26,6 +28,8 @@ */ public class OrganizationConfigsServiceHolder { + private static final Log log = LogFactory.getLog(OrganizationConfigsServiceHolder.class); + public OrganizationConfigsServiceHolder() {} private static class OrganizationConfigManagerHolder { @@ -41,6 +45,13 @@ private static class OrganizationConfigManagerHolder { */ public static OrganizationConfigManager getOrganizationConfigManager() { - return OrganizationConfigManagerHolder.SERVICE; + if (log.isDebugEnabled()) { + log.debug("Retrieving OrganizationConfigManager OSGi service."); + } + OrganizationConfigManager configManager = OrganizationConfigManagerHolder.SERVICE; + if (configManager == null) { + log.warn("OrganizationConfigManager OSGi service is not available."); + } + return configManager; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java index 3d3d056ae7..98ec19dcee 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/core/OrganizationConfigsService.java @@ -59,11 +59,27 @@ public OrganizationConfigsService(OrganizationConfigManager organizationConfigMa */ public void addDiscoveryConfiguration(Config config) { + if (config == null) { + LOG.error("Configuration object is null. Cannot add discovery configuration."); + throw new IllegalArgumentException("Configuration object cannot be null."); + } + + if (config.getProperties() == null) { + LOG.error("Configuration properties are null. Cannot add discovery configuration."); + throw new IllegalArgumentException("Configuration properties cannot be null."); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Adding organization discovery configuration with " + config.getProperties().size() + + " properties."); + } + List configProperties = config.getProperties().stream() .map(property -> new ConfigProperty(property.getKey(), property.getValue())) .collect(Collectors.toList()); try { organizationConfigManager.addDiscoveryConfiguration(new DiscoveryConfig(configProperties)); + LOG.info("Successfully added organization discovery configuration."); } catch (OrganizationConfigException e) { throw handleException(e); } @@ -76,12 +92,28 @@ public void addDiscoveryConfiguration(Config config) { */ public void updateDiscoveryConfiguration(Config config) { + if (config == null) { + LOG.error("Configuration object is null. Cannot update discovery configuration."); + throw new IllegalArgumentException("Configuration object cannot be null."); + } + + if (config.getProperties() == null) { + LOG.error("Configuration properties are null. Cannot update discovery configuration."); + throw new IllegalArgumentException("Configuration properties cannot be null."); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Updating organization discovery configuration with " + config.getProperties().size() + + " properties."); + } + List configProperties = config.getProperties().stream() .map(property -> new ConfigProperty(property.getKey(), property.getValue())) .collect(Collectors.toList()); try { organizationConfigManager.updateDiscoveryConfiguration (new DiscoveryConfig(configProperties)); + LOG.info("Successfully updated organization discovery configuration."); } catch (OrganizationConfigException e) { throw handleException(e); } @@ -94,6 +126,10 @@ public void updateDiscoveryConfiguration(Config config) { */ public Config getDiscoveryConfiguration() { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving organization discovery configuration."); + } + try { DiscoveryConfig discoveryConfig = organizationConfigManager.getDiscoveryConfiguration(); @@ -106,6 +142,11 @@ public Config getDiscoveryConfiguration() { }).collect(Collectors.toList()); Config config = new Config(); config.setProperties(properties); + + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved organization discovery configuration with " + properties.size() + " properties."); + } + return config; } catch (OrganizationConfigException e) { throw handleException(e); @@ -117,8 +158,13 @@ public Config getDiscoveryConfiguration() { */ public void deleteDiscoveryConfiguration() { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting organization discovery configuration."); + } + try { organizationConfigManager.deleteDiscoveryConfiguration(); + LOG.info("Successfully deleted organization discovery configuration."); } catch (OrganizationConfigException e) { throw handleException(e); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsServiceFactory.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsServiceFactory.java index 85f95eca79..3fddbb139b 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/factories/OrganizationConfigsServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.configs.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.configs.common.OrganizationConfigsServiceHolder; import org.wso2.carbon.identity.api.server.organization.configs.v1.core.OrganizationConfigsService; import org.wso2.carbon.identity.organization.config.service.OrganizationConfigManager; @@ -27,17 +29,24 @@ */ public class OrganizationConfigsServiceFactory { + private static final Log LOG = LogFactory.getLog(OrganizationConfigsServiceFactory.class); private static final OrganizationConfigsService SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing OrganizationConfigsService factory."); + } + OrganizationConfigManager organizationConfigManager = OrganizationConfigsServiceHolder .getOrganizationConfigManager(); if (organizationConfigManager == null) { + LOG.error("OrganizationConfigManager service is not available from OSGi context."); throw new IllegalStateException("OrganizationConfigManager service is not available from OSGi context."); } SERVICE = new OrganizationConfigsService(organizationConfigManager); + LOG.info("OrganizationConfigsService factory initialized successfully."); } /** diff --git a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java index 7ac6f45a81..bd35f22935 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.organization.configs/org.wso2.carbon.identity.api.server.organization.configs.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/configs/v1/impl/OrganizationConfigsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.configs.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.configs.v1.OrganizationConfigsApiService; import org.wso2.carbon.identity.api.server.organization.configs.v1.core.OrganizationConfigsService; import org.wso2.carbon.identity.api.server.organization.configs.v1.factories.OrganizationConfigsServiceFactory; @@ -30,13 +32,18 @@ */ public class OrganizationConfigsApiServiceImpl implements OrganizationConfigsApiService { + private static final Log LOG = LogFactory.getLog(OrganizationConfigsApiServiceImpl.class); private final OrganizationConfigsService organizationConfigsService; public OrganizationConfigsApiServiceImpl() { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing OrganizationConfigsApiServiceImpl."); + } this.organizationConfigsService = OrganizationConfigsServiceFactory.getOrganizationConfigsService(); } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating organization configuration service.", e); throw new RuntimeException("Error occurred while initiating organization configuration service.", e); } } @@ -44,6 +51,9 @@ public OrganizationConfigsApiServiceImpl() { @Override public Response createDiscoveryConfig(Config config) { + if (LOG.isDebugEnabled()) { + LOG.debug("Received request to create discovery configuration."); + } organizationConfigsService.addDiscoveryConfiguration(config); return Response.status(Response.Status.CREATED).entity(config).build(); } @@ -51,6 +61,9 @@ public Response createDiscoveryConfig(Config config) { @Override public Response deleteDiscoveryConfig() { + if (LOG.isDebugEnabled()) { + LOG.debug("Received request to delete discovery configuration."); + } organizationConfigsService.deleteDiscoveryConfiguration(); return Response.noContent().build(); } @@ -58,12 +71,18 @@ public Response deleteDiscoveryConfig() { @Override public Response getDiscoveryConfig() { + if (LOG.isDebugEnabled()) { + LOG.debug("Received request to get discovery configuration."); + } return Response.ok().entity(organizationConfigsService.getDiscoveryConfiguration()).build(); } @Override public Response updateDiscoveryConfig(Config config) { + if (LOG.isDebugEnabled()) { + LOG.debug("Received request to update discovery configuration."); + } organizationConfigsService.updateDiscoveryConfiguration(config); return Response.ok().entity(config).build(); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/management/common/OrganizationManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/management/common/OrganizationManagementServiceHolder.java index 8598e82b67..cbb41c7131 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/management/common/OrganizationManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/management/common/OrganizationManagementServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.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.organization.discovery.service.OrganizationDiscoveryManager; import org.wso2.carbon.identity.organization.management.application.OrgApplicationManager; @@ -28,6 +30,8 @@ */ public class OrganizationManagementServiceHolder { + private static final Log LOG = LogFactory.getLog(OrganizationManagementServiceHolder.class); + private OrganizationManagementServiceHolder() {} private static class OrgApplicationManagerHolder { @@ -55,7 +59,13 @@ private static class OrganizationDiscoveryManagerHolder { */ public static OrgApplicationManager getOrgApplicationManager() { - return OrgApplicationManagerHolder.SERVICE; + OrgApplicationManager service = OrgApplicationManagerHolder.SERVICE; + if (service == null) { + LOG.warn("OrgApplicationManager service is not available."); + } else if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved OrgApplicationManager service successfully."); + } + return service; } /** @@ -65,7 +75,13 @@ public static OrgApplicationManager getOrgApplicationManager() { */ public static OrganizationManager getOrganizationManager() { - return OrganizationManagerHolder.SERVICE; + OrganizationManager service = OrganizationManagerHolder.SERVICE; + if (service == null) { + LOG.warn("OrganizationManager service is not available."); + } else if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved OrganizationManager service successfully."); + } + return service; } /** @@ -75,6 +91,12 @@ public static OrganizationManager getOrganizationManager() { */ public static OrganizationDiscoveryManager getOrganizationDiscoveryManager() { - return OrganizationDiscoveryManagerHolder.SERVICE; + OrganizationDiscoveryManager service = OrganizationDiscoveryManagerHolder.SERVICE; + if (service == null) { + LOG.warn("OrganizationDiscoveryManager service is not available."); + } else if (LOG.isDebugEnabled()) { + LOG.debug("Retrieved OrganizationDiscoveryManager service successfully."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/factories/OrganizationManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/factories/OrganizationManagementServiceFactory.java index 9e46615d3b..3d8915dbcf 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/factories/OrganizationManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/factories/OrganizationManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.management.common.OrganizationManagementServiceHolder; import org.wso2.carbon.identity.api.server.organization.management.v1.service.OrganizationManagementService; import org.wso2.carbon.identity.organization.discovery.service.OrganizationDiscoveryManager; @@ -29,28 +31,38 @@ */ public class OrganizationManagementServiceFactory { + private static final Log LOG = LogFactory.getLog(OrganizationManagementServiceFactory.class); private static final OrganizationManagementService SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing OrganizationManagementService factory."); + } OrgApplicationManager orgApplicationManager = OrganizationManagementServiceHolder.getOrgApplicationManager(); OrganizationManager organizationManager = OrganizationManagementServiceHolder.getOrganizationManager(); OrganizationDiscoveryManager organizationDiscoveryManager = OrganizationManagementServiceHolder .getOrganizationDiscoveryManager(); if (orgApplicationManager == null) { + LOG.error("OrgApplicationManager service is not available from OSGi context."); throw new IllegalStateException("OrgApplicationManager service is not available from OSGi context."); } if (organizationManager == null) { + LOG.error("OrganizationManager service is not available from OSGi context."); throw new IllegalStateException("OrganizationManager service is not available from OSGi context."); } if (organizationDiscoveryManager == null) { + LOG.error("OrganizationDiscoveryManager service is not available from OSGi context."); throw new IllegalStateException("OrganizationDiscoveryManager service is not available from OSGi context."); } SERVICE = new OrganizationManagementService(orgApplicationManager, organizationManager, organizationDiscoveryManager); + if (LOG.isDebugEnabled()) { + LOG.debug("OrganizationManagementService factory initialization completed successfully."); + } } /** diff --git a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/impl/OrganizationsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/impl/OrganizationsApiServiceImpl.java index b540252d43..185f862fa6 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/impl/OrganizationsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/impl/OrganizationsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.management.v1.OrganizationsApiService; import org.wso2.carbon.identity.api.server.organization.management.v1.factories.OrganizationManagementServiceFactory; import org.wso2.carbon.identity.api.server.organization.management.v1.model.ApplicationSharePOSTRequest; @@ -40,14 +42,22 @@ */ public class OrganizationsApiServiceImpl implements OrganizationsApiService { + private static final Log LOG = LogFactory.getLog(OrganizationsApiServiceImpl.class); private final OrganizationManagementService organizationManagementService; public OrganizationsApiServiceImpl() { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing OrganizationsApiServiceImpl."); + } this.organizationManagementService = OrganizationManagementServiceFactory .getOrganizationManagementService(); + if (LOG.isDebugEnabled()) { + LOG.debug("OrganizationsApiServiceImpl initialized successfully."); + } } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating organization management service.", e); throw new RuntimeException("Error occurred while initiating organization management service.", e); } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/service/OrganizationManagementService.java b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/service/OrganizationManagementService.java index 3c91cd71c3..4538fef8ba 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/service/OrganizationManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/service/OrganizationManagementService.java @@ -138,11 +138,18 @@ public OrganizationManagementService(OrgApplicationManager orgApplicationManager */ public Response getOrganizations(String filter, Integer limit, String after, String before, Boolean recursive) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving organizations with filter: %s, limit: %d, recursive: %s", + filter, limit, recursive)); + } try { limit = validateLimit(limit); String sortOrder = StringUtils.isNotBlank(before) ? ASC_SORT_ORDER : DESC_SORT_ORDER; List organizations = organizationManager.getOrganizationsList(limit + 1, after, before, sortOrder, filter, Boolean.TRUE.equals(recursive)); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Successfully retrieved %d organizations", organizations.size())); + } return Response.ok().entity(getOrganizationsResponse(limit, after, before, filter, organizations, Boolean.TRUE.equals(recursive))).build(); } catch (OrganizationManagementClientException e) { @@ -160,6 +167,9 @@ public Response getOrganizations(String filter, Integer limit, String after, Str */ public Response checkOrganizationName(String organizationName) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Checking organization name availability: %s", organizationName)); + } boolean nameExist = organizationManager.isOrganizationExistByNameInGivenHierarchy(organizationName); OrganizationNameCheckPOSTResponse response = new OrganizationNameCheckPOSTResponse().available(false); if (!nameExist) { @@ -193,8 +203,12 @@ public Response checkOrganizationHandle(String orgHandle) { */ public Response deleteOrganization(String organizationId) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Deleting organization with ID: %s", organizationId)); + } try { organizationManager.deleteOrganization(organizationId); + LOG.info(String.format("Organization deleted successfully. Organization ID: %s", organizationId)); return Response.noContent().build(); } catch (OrganizationManagementClientException e) { return OrganizationManagementEndpointUtil.handleClientErrorResponse(e, LOG); @@ -211,6 +225,10 @@ public Response deleteOrganization(String organizationId) { */ public Response getOrganization(String organizationId, Boolean includePermissions) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Retrieving organization with ID: %s, includePermissions: %s", + organizationId, includePermissions)); + } try { Organization organization = organizationManager.getOrganization(organizationId, false, Boolean.TRUE.equals(includePermissions), true); @@ -272,10 +290,16 @@ public Response updateOrganization(String organizationId, OrganizationPUTRequest */ public Response addOrganization(OrganizationPOSTRequest organizationPOSTRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Creating organization with name: %s, type: %s", + organizationPOSTRequest.getName(), organizationPOSTRequest.getType())); + } try { Organization organization = organizationManager.addOrganization(getOrganizationFromPostRequest (organizationPOSTRequest)); String organizationId = organization.getId(); + LOG.info(String.format("Organization created successfully. Organization ID: %s, Name: %s", + organizationId, organization.getName())); return Response.created(OrganizationManagementEndpointUtil.getResourceLocation(organizationId)).entity (getOrganizationResponse(organization)).build(); } catch (OrganizationManagementClientException e) { @@ -302,6 +326,10 @@ public Response shareOrganizationApplication(String organizationId, String appli ? requestBody.getShareWithAllChildren() : false; orgApplicationManager.shareOrganizationApplication(organizationId, applicationId, shareWithAllChildren, requestBody.getSharedOrganizations()); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Application shared successfully. Organization ID: %s, Application ID: %s", + organizationId, applicationId)); + } return Response.ok().build(); } catch (OrganizationManagementClientException e) { return OrganizationManagementEndpointUtil.handleClientErrorResponse(e, LOG); @@ -338,6 +366,10 @@ public Response deleteSharedApplication(String organizationId, String applicatio try { orgApplicationManager.deleteSharedApplication(organizationId, applicationId, sharedOrganizationId); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Shared application deleted. Organization ID: %s, Application ID: %s", + organizationId, applicationId)); + } return Response.noContent().build(); } catch (OrganizationManagementClientException e) { return OrganizationManagementEndpointUtil.handleClientErrorResponse(e, LOG); @@ -419,6 +451,9 @@ public Response addOrganizationDiscoveryAttributes(OrganizationDiscoveryPostRequ .addOrganizationDiscoveryAttributes(organizationDiscoveryPostRequest.getOrganizationId(), getOrgDiscoveryAttributesFromPostRequest(organizationDiscoveryPostRequest), true); String organizationId = organizationDiscoveryPostRequest.getOrganizationId(); + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Discovery attributes added for organization ID: %s", organizationId)); + } return Response.created(OrganizationManagementEndpointUtil.getDiscoveryResourceLocation(organizationId)) .entity(getOrganizationDiscoveryAttributesResponse(orgDiscoveryAttributeList)).build(); } catch (OrganizationManagementClientException e) { diff --git a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/util/OrganizationManagementEndpointUtil.java b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/util/OrganizationManagementEndpointUtil.java index 6eee086ab7..0d49459625 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/util/OrganizationManagementEndpointUtil.java +++ b/components/org.wso2.carbon.identity.api.server.organization.management/org.wso2.carbon.identity.api.server.organization.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/management/v1/util/OrganizationManagementEndpointUtil.java @@ -56,6 +56,9 @@ public class OrganizationManagementEndpointUtil { */ public static Response handleClientErrorResponse(OrganizationManagementClientException e, Log log) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Handling client error with code: %s", e.getErrorCode())); + } if (isNotFoundError(e)) { throw buildException(Response.Status.NOT_FOUND, log, e); } @@ -76,6 +79,9 @@ public static Response handleClientErrorResponse(OrganizationManagementClientExc */ public static Response handleServerErrorResponse(OrganizationManagementException e, Log log) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Handling server error with code: %s", e.getErrorCode())); + } throw buildException(Response.Status.INTERNAL_SERVER_ERROR, log, e); } @@ -145,6 +151,9 @@ private static void logError(Log log, OrganizationManagementException e) { */ public static URI getResourceLocation(String organizationId) { + if (LOG.isDebugEnabled()) { + LOG.debug(String.format("Building resource location for organization ID: %s", organizationId)); + } return buildURIForHeader(V1_API_PATH_COMPONENT + PATH_SEPARATOR + ORGANIZATION_PATH + PATH_SEPARATOR + organizationId); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/common/OrganizationRoleManagementServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/common/OrganizationRoleManagementServiceHolder.java index e1f85c9da9..126bdd2aa0 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/common/OrganizationRoleManagementServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/common/OrganizationRoleManagementServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.role.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.organization.management.role.management.service.RoleManager; import org.wso2.carbon.identity.organization.management.service.OrganizationUserResidentResolverService; @@ -27,6 +29,8 @@ */ public class OrganizationRoleManagementServiceHolder { + private static final Log LOG = LogFactory.getLog(OrganizationRoleManagementServiceHolder.class); + private OrganizationRoleManagementServiceHolder() {} private static class RoleManagerServiceHolder { @@ -49,7 +53,14 @@ private static class OrganizationUserResidentResolverServiceHolder { */ public static RoleManager getRoleManager() { - return RoleManagerServiceHolder.SERVICE; + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving RoleManager OSGi service."); + } + RoleManager roleManager = RoleManagerServiceHolder.SERVICE; + if (roleManager == null) { + LOG.warn("RoleManager OSGi service is not available."); + } + return roleManager; } /** @@ -59,6 +70,13 @@ public static RoleManager getRoleManager() { */ public static OrganizationUserResidentResolverService getOrganizationUserResidentResolverService() { - return OrganizationUserResidentResolverServiceHolder.SERVICE; + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving OrganizationUserResidentResolverService OSGi service."); + } + OrganizationUserResidentResolverService service = OrganizationUserResidentResolverServiceHolder.SERVICE; + if (service == null) { + LOG.warn("OrganizationUserResidentResolverService OSGi service is not available."); + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/factories/RoleManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/factories/RoleManagementServiceFactory.java index 4f6dae8ac3..e873dd9576 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/factories/RoleManagementServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/factories/RoleManagementServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.role.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.role.management.common.OrganizationRoleManagementServiceHolder; import org.wso2.carbon.identity.api.server.organization.role.management.v1.service.RoleManagementService; import org.wso2.carbon.identity.organization.management.role.management.service.RoleManager; @@ -28,6 +30,7 @@ */ public class RoleManagementServiceFactory { + private static final Log LOG = LogFactory.getLog(RoleManagementServiceFactory.class); private static final RoleManagementService SERVICE; static { @@ -36,10 +39,12 @@ public class RoleManagementServiceFactory { OrganizationRoleManagementServiceHolder.getOrganizationUserResidentResolverService(); if (roleManager == null) { + LOG.error("RoleManager service is not available from OSGi context"); throw new IllegalStateException("RoleManager service is not available from OSGi context."); } if (organizationUserResidentResolverService == null) { + LOG.error("OrganizationUserResidentResolverService is not available from OSGi context"); throw new IllegalStateException("OrganizationUserResidentResolverService is not available " + "from OSGi context."); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/impl/OrganizationsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/impl/OrganizationsApiServiceImpl.java index d61505ba32..48bf6c156e 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/impl/OrganizationsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/impl/OrganizationsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.role.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.role.management.v1.OrganizationsApiService; import org.wso2.carbon.identity.api.server.organization.role.management.v1.factories.RoleManagementServiceFactory; import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolePatchRequest; @@ -32,6 +34,7 @@ */ public class OrganizationsApiServiceImpl implements OrganizationsApiService { + private static final Log LOG = LogFactory.getLog(OrganizationsApiServiceImpl.class); private final RoleManagementService roleManagementService; public OrganizationsApiServiceImpl() { @@ -39,6 +42,7 @@ public OrganizationsApiServiceImpl() { try { this.roleManagementService = RoleManagementServiceFactory.getRoleManagementService(); } catch (IllegalStateException e) { + LOG.error("Error occurred while initiating role management service", e); throw new RuntimeException("Error occurred while initiating role management service.", e); } } @@ -46,6 +50,9 @@ public OrganizationsApiServiceImpl() { @Override public Response createRole(String organizationId, RolePostRequest rolePostRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating role for organization: " + organizationId); + } return roleManagementService.createRole(organizationId, rolePostRequest); } @@ -53,18 +60,27 @@ public Response createRole(String organizationId, RolePostRequest rolePostReques public Response organizationsOrganizationIdRolesGet(String organizationId, String filter, Integer count, String cursor) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving roles for organization: " + organizationId); + } return roleManagementService.getRolesOfOrganization(organizationId, filter, count, cursor); } @Override public Response organizationsOrganizationIdRolesRoleIdDelete(String roleId, String organizationId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting role: " + roleId + " from organization: " + organizationId); + } return roleManagementService.deleteRole(organizationId, roleId); } @Override public Response organizationsOrganizationIdRolesRoleIdGet(String roleId, String organizationId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving role: " + roleId + " from organization: " + organizationId); + } return roleManagementService.getRoleUsingOrganizationIdAndRoleId(organizationId, roleId); } @@ -72,6 +88,9 @@ public Response organizationsOrganizationIdRolesRoleIdGet(String roleId, String public Response organizationsOrganizationIdRolesRoleIdPatch(String roleId, String organizationId, RolePatchRequest rolePatchRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Patching role: " + roleId + " in organization: " + organizationId); + } return roleManagementService.patchRole(organizationId, roleId, rolePatchRequest); } @@ -79,12 +98,18 @@ public Response organizationsOrganizationIdRolesRoleIdPatch(String roleId, Strin public Response organizationsOrganizationIdRolesRoleIdPut(String roleId, String organizationId, RolePutRequest rolePutRequest) { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating role: " + roleId + " in organization: " + organizationId); + } return roleManagementService.putRole(organizationId, roleId, rolePutRequest); } @Override public Response organizationsOrganizationIdUsersUserIdRolesGet(String userId, String organizationId) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving roles for user: " + userId + " in organization: " + organizationId); + } return roleManagementService.getUserRolesOfOrganization(organizationId, userId); } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/service/RoleManagementService.java b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/service/RoleManagementService.java index f83e3dfa4b..a39605f6a0 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/service/RoleManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/service/RoleManagementService.java @@ -100,11 +100,16 @@ public RoleManagementService(RoleManager roleManager, public Response createRole(String organizationId, RolePostRequest rolePostRequest) { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating role in organization: " + organizationId + + " with display name: " + rolePostRequest.getDisplayName()); + } Role role = roleManager.createRole(organizationId, generateRoleFromPostRequest(rolePostRequest)); URI roleURI = RoleManagementEndpointUtils.getUri(organizationId, role.getId(), RoleManagementEndpointConstants.ROLE_PATH, ERROR_CODE_ERROR_BUILDING_ROLE_URI); + LOG.info("Role created successfully in organization: " + organizationId + " with ID: " + role.getId()); return Response.created(roleURI).entity(getRolePostResponse(role, roleURI)).build(); } catch (OrganizationManagementClientException e) { return RoleManagementEndpointUtils.handleClientErrorResponse(e, LOG); @@ -123,7 +128,11 @@ public Response createRole(String organizationId, RolePostRequest rolePostReques public Response deleteRole(String organizationId, String roleId) { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting role: " + roleId + " from organization: " + organizationId); + } roleManager.deleteRole(organizationId, roleId); + LOG.info("Role deleted successfully from organization: " + organizationId + " with ID: " + roleId); return Response.noContent().build(); } catch (OrganizationManagementClientException e) { return RoleManagementEndpointUtils.handleClientErrorResponse(e, LOG); @@ -166,6 +175,9 @@ public Response getRoleUsingOrganizationIdAndRoleId(String organizationId, Strin public Response getRolesOfOrganization(String organizationId, String filter, Integer count, String cursor) { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving roles for organization: " + organizationId + " with filter: " + filter); + } int limitValue = validateCount(count); RolesResponse rolesResponse = roleManager.getOrganizationRoles(limitValue, filter, organizationId, cursor); return Response.ok().entity(getRoleListResponse(organizationId, rolesResponse)).build(); @@ -186,6 +198,9 @@ public Response getRolesOfOrganization(String organizationId, String filter, Int public Response getUserRolesOfOrganization(String organizationId, String userId) { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving roles for user: " + userId + " in organization: " + organizationId); + } String userResidentOrgId = String.valueOf(organizationUserResidentResolverService .resolveResidentOrganization(userId, organizationId) .orElseThrow(() -> handleClientException(ERROR_CODE_USER_ROOT_ORGANIZATION_NOT_FOUND, userId))); @@ -214,6 +229,9 @@ public Response getUserRolesOfOrganization(String organizationId, String userId) public Response patchRole(String organizationId, String roleId, RolePatchRequest rolePatchRequest) { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Patching role: " + roleId + " in organization: " + organizationId); + } List patchOperationList = rolePatchRequest.getOperations(); List patchOperations = new ArrayList<>(); @@ -239,6 +257,7 @@ public Response patchRole(String organizationId, String roleId, RolePatchRequest URI roleURI = RoleManagementEndpointUtils.getUri(organizationId, roleId, RoleManagementEndpointConstants.ROLE_PATH, ERROR_CODE_ERROR_BUILDING_ROLE_URI); + LOG.info("Role patched successfully in organization: " + organizationId + " with ID: " + roleId); return Response.ok().entity(getRolePatchResponse(role, roleURI)).build(); } catch (OrganizationManagementClientException e) { return RoleManagementEndpointUtils.handleClientErrorResponse(e, LOG); @@ -258,6 +277,9 @@ public Response patchRole(String organizationId, String roleId, RolePatchRequest public Response putRole(String organizationId, String roleId, RolePutRequest rolePutRequest) { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating role: " + roleId + " in organization: " + organizationId); + } if (StringUtils.isBlank(rolePutRequest.getDisplayName())) { throw handleClientException(ERROR_CODE_ROLE_DISPLAY_NAME_NULL); } @@ -276,7 +298,7 @@ public Response putRole(String organizationId, String roleId, RolePutRequest rol URI roleURI = RoleManagementEndpointUtils.getUri(organizationId, roleId, RoleManagementEndpointConstants.ROLE_PATH, ERROR_CODE_ERROR_BUILDING_ROLE_URI); - + LOG.info("Role updated successfully in organization: " + organizationId + " with ID: " + roleId); return Response.ok().entity(getRolePutResponse(role, roleURI)).build(); } catch (OrganizationManagementClientException e) { return RoleManagementEndpointUtils.handleClientErrorResponse(e, LOG); diff --git a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/util/RoleManagementEndpointUtils.java b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/util/RoleManagementEndpointUtils.java index a08922d906..c3765a5bb6 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/util/RoleManagementEndpointUtils.java +++ b/components/org.wso2.carbon.identity.api.server.organization.role.management/org.wso2.carbon.identity.api.server.organization.role.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/role/management/v1/util/RoleManagementEndpointUtils.java @@ -138,8 +138,8 @@ public static URI getUri(String organizationId, String id, String resourcePath, } catch (URLBuilderException e) { Error error = getError(errorMessage.getCode(), errorMessage.getMessage(), String.format(errorMessage.getDescription(), id)); - LOG.error(String.format("Server encountered an error while building URL for %s ", - resourcePath.substring(0, resourcePath.length() - 1)) + id); + LOG.error("Server encountered an error while building URL for " + + resourcePath.substring(0, resourcePath.length() - 1) + " ID: " + id); throw new RoleManagementEndpointException(Response.Status.INTERNAL_SERVER_ERROR, error); } } @@ -161,6 +161,7 @@ public static URI buildSCIM2Uri(String id, String resourcePath, ErrorMessages er } catch (URLBuilderException e) { Error error = getError(errorMessage.getCode(), errorMessage.getMessage(), String.format(errorMessage.getDescription(), id)); + LOG.error("Error building SCIM2 URI for resource: " + resourcePath + " with ID: " + id); throw new RoleManagementEndpointException(Response.Status.INTERNAL_SERVER_ERROR, error); } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/SelfServiceMgtServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/SelfServiceMgtServiceHolder.java index 9cbf54e4f8..98cb9a957e 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/SelfServiceMgtServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/SelfServiceMgtServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.selfservice.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; @@ -29,6 +31,8 @@ */ public class SelfServiceMgtServiceHolder { + private static final Log log = LogFactory.getLog(SelfServiceMgtServiceHolder.class); + private SelfServiceMgtServiceHolder() { } @@ -64,6 +68,12 @@ private static class AuthorizedAPIManagementServiceHolder { */ public static ApplicationManagementService getApplicationManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving ApplicationManagementService from service holder."); + } + if (ApplicationManagementServiceHolder.SERVICE == null) { + log.warn("ApplicationManagementService is not available."); + } return ApplicationManagementServiceHolder.SERVICE; } @@ -74,6 +84,12 @@ public static ApplicationManagementService getApplicationManagementService() { */ public static IdentityGovernanceService getIdentityGovernanceService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving IdentityGovernanceService from service holder."); + } + if (IdentityGovernanceServiceHolder.SERVICE == null) { + log.warn("IdentityGovernanceService is not available."); + } return IdentityGovernanceServiceHolder.SERVICE; } @@ -84,6 +100,12 @@ public static IdentityGovernanceService getIdentityGovernanceService() { */ public static APIResourceManager getAPIResourceManager() { + if (log.isDebugEnabled()) { + log.debug("Retrieving APIResourceManager from service holder."); + } + if (APIResourceManagerServiceHolder.SERVICE == null) { + log.warn("APIResourceManager is not available."); + } return APIResourceManagerServiceHolder.SERVICE; } @@ -94,6 +116,12 @@ public static APIResourceManager getAPIResourceManager() { */ public static AuthorizedAPIManagementService getAuthorizedAPIManagementService() { + if (log.isDebugEnabled()) { + log.debug("Retrieving AuthorizedAPIManagementService from service holder."); + } + if (AuthorizedAPIManagementServiceHolder.SERVICE == null) { + log.warn("AuthorizedAPIManagementService is not available."); + } return AuthorizedAPIManagementServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtService.java b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtService.java index 948ba3068d..c0b08e0bfe 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtService.java +++ b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtService.java @@ -98,9 +98,17 @@ public List getOrganizationGovernanceConfigs() { try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving organization governance configs for tenant domain: " + tenantDomain); + } ConnectorConfig connectorConfig = identityGovernanceService.getConnectorWithConfigs(tenantDomain, SelfServiceMgtConstants.SELF_SERVICE_GOVERNANCE_CONNECTOR); - return buildConnectorResDTO(connectorConfig); + List properties = buildConnectorResDTO(connectorConfig); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved " + properties.size() + + " governance configurations for tenant: " + tenantDomain); + } + return properties; } catch (IdentityGovernanceException e) { LOG.error(SelfServiceMgtConstants.ErrorMessage.ERROR_RETRIEVING_SELF_SERVICE_CONFIG.getDescription(), e); throw new SelfServiceMgtEndpointException(Response.Status.INTERNAL_SERVER_ERROR, @@ -125,10 +133,20 @@ public void updateOrganizationGovernanceConfigs(PropertyPatchReq governanceConne } Map copiedConfigurationDetails = new HashMap<>(configurationDetails); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + if (LOG.isDebugEnabled()) { + LOG.debug("Updating " + configurationDetails.size() + " governance configurations for tenant: " + + tenantDomain); + } identityGovernanceService.updateConfiguration(tenantDomain, configurationDetails); if (enablePostListener) { + if (LOG.isDebugEnabled()) { + LOG.debug("Executing post configuration update listeners for tenant: " + tenantDomain); + } doPostConfigurationUpdate(copiedConfigurationDetails); } + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully updated governance configurations for tenant: " + tenantDomain); + } } catch (Exception e) { LOG.error(SelfServiceMgtConstants.ErrorMessage.ERROR_UPDATING_SELF_SERVICE_CONFIG.getDescription(), e); throw new SelfServiceMgtEndpointException(Response.Status.INTERNAL_SERVER_ERROR, @@ -152,11 +170,22 @@ private void processSelfServiceEnablement(Map configurationDetai boolean isEnableSelfServiceUpdated = configurationDetails.containsKey(SelfServiceMgtConstants.SELF_SERVICE_ENABLE_PROPERTY_NAME); + if (LOG.isDebugEnabled()) { + LOG.debug("Processing self-service enablement. Enable: " + enableSelfService + + ", Updated: " + isEnableSelfServiceUpdated); + } + // Create or remove self-service application. if (isEnableSelfServiceUpdated) { if (enableSelfService) { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating self-service system application."); + } createSystemApplication(); } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting self-service system application."); + } deleteSystemApplication(); } } @@ -197,8 +226,15 @@ private void processEmailVerification(Map configurationDetails) } if (enableOnboardToSubOrganization && enableAdminEmailVerification) { + if (LOG.isDebugEnabled()) { + LOG.debug("Onboarding lite user store as both sub-org onboard and email verification are enabled."); + } onboardLiteUserStore(); } else { + if (LOG.isDebugEnabled()) { + LOG.debug("Removing lite user store as conditions are not met. Sub-org onboard: " + + enableOnboardToSubOrganization + ", Email verification: " + enableAdminEmailVerification); + } removeLiteUserStore(); } } @@ -206,15 +242,24 @@ private void processEmailVerification(Map configurationDetails) private void removeLiteUserStore() { String userStoreName = getConfigProperty(SelfServiceMgtConstants.LITE_USER_USER_STORE_NAME); + if (LOG.isDebugEnabled()) { + LOG.debug("Removing lite user store: " + userStoreName); + } String domainId = new String(Base64.getEncoder().encode(userStoreName.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); getServerUserStoreService().deleteUserStore(domainId); updateLiteUserStoreConnectorConfigs(false); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully removed lite user store: " + userStoreName); + } } private void onboardLiteUserStore() { try { + if (LOG.isDebugEnabled()) { + LOG.debug("Starting lite user store onboarding process."); + } InputStream inputStream = loadResourceFromClasspath(SelfServiceMgtConstants .CREATE_LITE_USER_STORE_REQUEST_JSON); ObjectMapper objectMapper = new ObjectMapper(); @@ -226,6 +271,9 @@ private void onboardLiteUserStore() { UserStoreReq userStoreReq = objectMapper.readValue(requestBody, UserStoreReq.class); getServerUserStoreService().addUserStore(userStoreReq); updateLiteUserStoreConnectorConfigs(true); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully onboarded lite user store."); + } } catch (IOException e) { LOG.error(SelfServiceMgtConstants.ErrorMessage.ERROR_ONBOARDING_LITE_USER_STORE.getDescription(), e); throw new SelfServiceMgtEndpointException(Response.Status.INTERNAL_SERVER_ERROR, @@ -266,8 +314,14 @@ private void createSystemApplication() { String appName = getConfigProperty(SelfServiceMgtConstants.SELF_SERVICE_DEFAULT_APP_NAME); try { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating system application '" + appName + "' for tenant: " + tenantDomain); + } // Check if the self-service app already exists, if yes, then return. if (isSSAppExists(tenantDomain, userName, appName)) { + if (LOG.isDebugEnabled()) { + LOG.debug("System application '" + appName + "' already exists for tenant: " + tenantDomain); + } return; } @@ -286,9 +340,15 @@ private void createSystemApplication() { // Create the application using the Application Management Service. getServerApplicationManagementService().createApplication(model, null); + if (LOG.isInfoEnabled()) { + LOG.info("Successfully created system application '" + appName + "' for tenant: " + tenantDomain); + } // If legacy authorization runtime is enabled, skip subscribing to APIs. if (isLegacyAuthzRuntime()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Legacy authorization runtime is enabled, skipping API subscriptions."); + } return; } @@ -307,6 +367,9 @@ private void createSystemApplication() { Map> authorizedAPIAndScopeNames = getAuthorizedAPIsAndScopeNamesForSSApp(); + if (LOG.isDebugEnabled()) { + LOG.debug("Authorizing " + authorizedAPIAndScopeNames.size() + " APIs for system application."); + } // Loop through the APIs and subscribe to them. for (Map.Entry> entry : authorizedAPIAndScopeNames.entrySet()) { String apiId = entry.getKey(); @@ -318,6 +381,9 @@ private void createSystemApplication() { ServiceProvider serviceProvider = applicationManagementService.getServiceProvider(sSApplicationBasicInfo .getApplicationId()); applicationManagementService.updateApplication(serviceProvider, tenantDomain, userName); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully shared system application with child organizations."); + } } catch (IOException | IdentityApplicationManagementException e) { LOG.error(SelfServiceMgtConstants.ErrorMessage.ERROR_CREATING_SYSTEM_APP.getDescription(), e); @@ -335,9 +401,19 @@ private void deleteSystemApplication() { String appName = getConfigProperty(SelfServiceMgtConstants.SELF_SERVICE_DEFAULT_APP_NAME); try { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting system application '" + appName + "' for tenant: " + tenantDomain); + } // Check if the self-service app exists, if yes, then delete it. if (isSSAppExists(tenantDomain, userName, appName)) { applicationManagementService.deleteApplication(appName, tenantDomain, userName); + if (LOG.isInfoEnabled()) { + LOG.info("Successfully deleted system application '" + appName + "' for tenant: " + tenantDomain); + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("System application '" + appName + "' does not exist for tenant: " + tenantDomain); + } } } catch (IdentityApplicationManagementException e) { LOG.error(SelfServiceMgtConstants.ErrorMessage.ERROR_DELETING_SYSTEM_APP.getDescription(), e); diff --git a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/factories/SelfServiceMgtServiceFactory.java b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/factories/SelfServiceMgtServiceFactory.java index d24fd70e7b..c699786653 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/factories/SelfServiceMgtServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/factories/SelfServiceMgtServiceFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.selfservice.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager; import org.wso2.carbon.identity.api.server.organization.selfservice.common.SelfServiceMgtServiceHolder; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.core.SelfServiceMgtService; @@ -30,6 +32,8 @@ */ public class SelfServiceMgtServiceFactory { + private static final Log LOG = LogFactory.getLog(SelfServiceMgtServiceFactory.class); + private SelfServiceMgtServiceFactory() { } @@ -51,21 +55,32 @@ public static SelfServiceMgtService getSelfServiceMgtService() { private static SelfServiceMgtService createServiceInstance() { + if (LOG.isDebugEnabled()) { + LOG.debug("Creating SelfServiceMgtService instance."); + } IdentityGovernanceService identityGovernanceService = getIdentityGovernanceService(); ApplicationManagementService applicationManagementService = getApplicationManagementService(); APIResourceManager apiResourceManager = getAPIResourceManager(); AuthorizedAPIManagementService authorizedAPIManagementService = getAuthorizedAPIManagementService(); - return new SelfServiceMgtService(identityGovernanceService, applicationManagementService, apiResourceManager, - authorizedAPIManagementService); + SelfServiceMgtService service = new SelfServiceMgtService(identityGovernanceService, + applicationManagementService, apiResourceManager, authorizedAPIManagementService); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully created SelfServiceMgtService instance."); + } + return service; } private static IdentityGovernanceService getIdentityGovernanceService() { IdentityGovernanceService service = SelfServiceMgtServiceHolder.getIdentityGovernanceService(); if (service == null) { + LOG.error("IdentityGovernanceService is not available from OSGi context."); throw new IllegalStateException("IdentityGovernanceService is not available from OSGi context."); } + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved IdentityGovernanceService from OSGi context."); + } return service; } @@ -73,8 +88,12 @@ private static ApplicationManagementService getApplicationManagementService() { ApplicationManagementService service = SelfServiceMgtServiceHolder.getApplicationManagementService(); if (service == null) { + LOG.error("ApplicationManagementService is not available from OSGi context."); throw new IllegalStateException("ApplicationManagementService is not available from OSGi context."); } + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved ApplicationManagementService from OSGi context."); + } return service; } @@ -82,8 +101,12 @@ private static APIResourceManager getAPIResourceManager() { APIResourceManager service = SelfServiceMgtServiceHolder.getAPIResourceManager(); if (service == null) { + LOG.error("APIResourceManager is not available from OSGi context."); throw new IllegalStateException("APIResourceManager is not available from OSGi context."); } + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved APIResourceManager from OSGi context."); + } return service; } @@ -91,8 +114,12 @@ private static AuthorizedAPIManagementService getAuthorizedAPIManagementService( AuthorizedAPIManagementService service = SelfServiceMgtServiceHolder.getAuthorizedAPIManagementService(); if (service == null) { + LOG.error("AuthorizedAPIManagementService is not available from OSGi context."); throw new IllegalStateException("AuthorizedAPIManagementService is not available from OSGi context."); } + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved AuthorizedAPIManagementService from OSGi context."); + } return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/impl/SelfServiceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/impl/SelfServiceApiServiceImpl.java index 1cda255578..4298c41ec6 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/impl/SelfServiceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/impl/SelfServiceApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.selfservice.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.SelfServiceApiService; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.core.SelfServiceMgtService; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.factories.SelfServiceMgtServiceFactory; @@ -30,13 +32,21 @@ */ public class SelfServiceApiServiceImpl implements SelfServiceApiService { + private static final Log LOG = LogFactory.getLog(SelfServiceApiServiceImpl.class); private final SelfServiceMgtService selfServiceMgtService; public SelfServiceApiServiceImpl() { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing SelfServiceApiServiceImpl."); + } try { this.selfServiceMgtService = SelfServiceMgtServiceFactory.getSelfServiceMgtService(); + if (LOG.isDebugEnabled()) { + LOG.debug("SelfServiceMgtService initialized successfully."); + } } catch (IllegalStateException e) { + LOG.error("SelfServiceMgtService is not available from OSGi context.", e); throw new RuntimeException("SelfServiceMgtService is not available from OSGi context.", e); } } @@ -44,14 +54,26 @@ public SelfServiceApiServiceImpl() { @Override public Response organizationPreferenceGet() { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving organization governance configurations."); + } Object body = selfServiceMgtService.getOrganizationGovernanceConfigs(); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved organization governance configurations."); + } return Response.ok().entity(body).build(); } @Override public Response organizationPreferencePatch(PropertyPatchReq propertyPatchReq) { + if (LOG.isDebugEnabled()) { + LOG.debug("Updating organization governance configurations."); + } selfServiceMgtService.updateOrganizationGovernanceConfigs(propertyPatchReq, true); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully updated organization governance configurations."); + } return Response.ok().build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtServiceHolder.java index 32506bbedd..482bdf581d 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/common/UserInvitationMgtServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.invitation.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.organization.user.invitation.management.InvitationCoreService; @@ -26,6 +28,8 @@ */ public class UserInvitationMgtServiceHolder { + private static final Log log = LogFactory.getLog(UserInvitationMgtServiceHolder.class); + private UserInvitationMgtServiceHolder() { } @@ -43,6 +47,16 @@ private static class InvitationCoreServiceHolder { */ public static InvitationCoreService getInvitationCoreService() { - return InvitationCoreServiceHolder.SERVICE; + InvitationCoreService service = InvitationCoreServiceHolder.SERVICE; + if (service == null) { + if (log.isDebugEnabled()) { + log.debug("InvitationCoreService is not available."); + } + } else { + if (log.isDebugEnabled()) { + log.debug("InvitationCoreService retrieved successfully."); + } + } + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java index 0848b1d3ea..55d4ef6dbf 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/core/GuestApiServiceCore.java @@ -19,6 +19,8 @@ package org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.core; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.common.error.APIError; import org.wso2.carbon.identity.api.server.common.error.ErrorResponse; import org.wso2.carbon.identity.api.server.organization.user.invitation.management.common.UserInvitationMgtConstants; @@ -63,11 +65,15 @@ */ public class GuestApiServiceCore { + private static final Log log = LogFactory.getLog(GuestApiServiceCore.class); private final InvitationCoreService invitationCoreService; public GuestApiServiceCore(InvitationCoreService invitationCoreService) { this.invitationCoreService = invitationCoreService; + if (log.isDebugEnabled()) { + log.debug("GuestApiServiceCore initialized with InvitationCoreService."); + } } private static List buildRoleAssignmentResponse(Invitation invitationRecord) { @@ -111,6 +117,16 @@ private static List buildGroupAssignmentResponse(Invita */ public List createInvitation(InvitationRequestBody invitationRequestBody) { + if (invitationRequestBody == null) { + log.error("InvitationRequestBody cannot be null."); + throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_CREATE_INVITATION, "InvitationRequestBody cannot be null"); + } + if (log.isDebugEnabled()) { + log.debug("Creating invitations for users: " + + (invitationRequestBody.getUsernames() != null ? + invitationRequestBody.getUsernames().size() : 0)); + } InvitationDO invitation = new InvitationDO(); invitation.setUsernamesList(invitationRequestBody.getUsernames()); invitation.setUserDomain(invitationRequestBody.getUserDomain()); @@ -139,17 +155,22 @@ public List createInvitation(InvitationRequestBody in List invitationResponse; try { invitationResponse = invitationCoreService.createInvitations(invitation); + log.info("Invitations created successfully for " + invitation.getUsernamesList().size() + " users."); } catch (UserInvitationMgtException e) { if (ERROR_CODE_MULTIPLE_INVITATIONS_FOR_USER.getCode().equals(e.getErrorCode())) { + log.warn("Multiple invitations found for users: " + invitation.getUsernamesList().toString()); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_MULTIPLE_INVITATIONS_FOR_USER, invitation.getUsernamesList().toString()); } else if (ERROR_CODE_INVALID_ROLE.getCode().equals(e.getErrorCode())) { + log.warn("Invalid role specified in invitation request."); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_ROLE, StringUtils.EMPTY); } else if (ERROR_CODE_INVALID_GROUP.getCode().equals(e.getErrorCode())) { + log.warn("Invalid group specified in invitation request."); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_GROUP, StringUtils.EMPTY); } + log.error("Error creating invitations for users: " + invitation.getUsernamesList().toString(), e); throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_CREATE_INVITATION, invitation.getUsernamesList().toString()); @@ -166,20 +187,33 @@ public List createInvitation(InvitationRequestBody in public InvitationsListResponse getInvitations(String filter, Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug("Retrieving invitations with filter: " + filter); + } if (!isUnsupportedParamAvailable(limit, offset, sortOrder, sortBy)) { try { - return buildInvitationsListResponse(invitationCoreService.getInvitations(filter)); + List invitations = invitationCoreService.getInvitations(filter); + log.info("Retrieved " + (invitations != null ? invitations.size() : 0) + " invitations."); + if (invitations == null) { + log.warn("Received null invitations list from core service."); + invitations = new ArrayList<>(); + } + return buildInvitationsListResponse(invitations); } catch (UserInvitationMgtException e) { if (ERROR_CODE_INVALID_FILTER.getCode().equals(e.getErrorCode())) { + log.warn("Invalid filter provided: " + filter); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_FILTER, filter); } else if (ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE_VALUE.getCode().equals(e.getErrorCode())) { + log.warn("Unsupported filter attribute value in filter: " + filter); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_FILTER, filter); } else if (ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE.getCode().equals(e.getErrorCode())) { + log.warn("Unsupported filter attribute in filter: " + filter); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_FILTER, filter); } + log.error("Error retrieving invitations.", e); throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_GET_INVITATIONS, StringUtils.EMPTY); } @@ -195,13 +229,26 @@ public InvitationsListResponse getInvitations(String filter, Integer limit, Inte */ public IntrospectSuccessResponse introspectInvitation(String confirmationCode) { + if (log.isDebugEnabled()) { + log.debug("Introspecting invitation with confirmation code."); + } try { - return buildValidateResponse(invitationCoreService.introspectInvitation(confirmationCode)); + Invitation invitation = invitationCoreService.introspectInvitation(confirmationCode); + log.info("Invitation introspection completed for user: " + + (invitation != null ? invitation.getUsername() : "unknown")); + if (invitation == null) { + log.error("Received null invitation from core service for confirmation code."); + throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage + .ERROR_CODE_INVALID_CONFIRMATION_CODE, confirmationCode); + } + return buildValidateResponse(invitation); } catch (UserInvitationMgtException e) { if (ERROR_CODE_INVALID_CONFIRMATION_CODE.getCode().equals(e.getErrorCode())) { + log.warn("Invalid confirmation code provided for introspection."); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_CONFIRMATION_CODE, confirmationCode); } + log.error("Error introspecting invitation.", e); throw handleException(Response.Status.INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_VALIDATE_INVITATION, confirmationCode); } @@ -215,13 +262,24 @@ public IntrospectSuccessResponse introspectInvitation(String confirmationCode) { */ public boolean deleteInvitation(String invitationId) { + if (log.isDebugEnabled()) { + log.debug("Deleting invitation with ID: " + invitationId); + } try { - return invitationCoreService.deleteInvitation(invitationId); + boolean deleted = invitationCoreService.deleteInvitation(invitationId); + if (deleted) { + log.info("Invitation deleted successfully for ID: " + invitationId); + } else { + log.warn("Invitation deletion failed for ID: " + invitationId); + } + return deleted; } catch (UserInvitationMgtException e) { if (ERROR_CODE_INVALID_INVITATION_ID.getCode().equals(e.getErrorCode())) { + log.warn("Invalid invitation ID provided for deletion: " + invitationId); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage.ERROR_CODE_INVALID_INVITATION, invitationId); } + log.error("Error deleting invitation with ID: " + invitationId, e); throw handleException(INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_DELETE_INVITATION, invitationId); } @@ -236,20 +294,28 @@ public boolean deleteInvitation(String invitationId) { */ public void acceptInvitation(AcceptanceRequestBody acceptanceRequestBody) { + if (log.isDebugEnabled()) { + log.debug("Processing invitation acceptance."); + } try { invitationCoreService.acceptInvitation(acceptanceRequestBody.getConfirmationCode()); + log.info("Invitation accepted successfully."); } catch (UserInvitationMgtException e) { if (ERROR_CODE_INVALID_CONFIRMATION_CODE.getCode().equals(e.getErrorCode())) { + log.warn("Invalid confirmation code provided for acceptance."); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_CONFIRMATION_CODE_FOR_ACCEPTANCE, acceptanceRequestBody .getConfirmationCode()); } else if (ERROR_CODE_INVALID_USER.getCode().equals(e.getErrorCode())) { + log.warn("Invalid user provided for invitation acceptance."); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_INVALID_USER, StringUtils.EMPTY); } else if (ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) { + log.warn("User already exists in the organization."); throw handleException(BAD_REQUEST, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_EXISTING_USER, StringUtils.EMPTY); } + log.error("Error accepting invitation.", e); throw handleException(INTERNAL_SERVER_ERROR, UserInvitationMgtConstants.ErrorMessage .ERROR_CODE_ACCEPT_INVITATION, acceptanceRequestBody.getConfirmationCode()); } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/factories/GuestApiServiceCoreFactory.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/factories/GuestApiServiceCoreFactory.java index d8f90af568..3991575a99 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/factories/GuestApiServiceCoreFactory.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/factories/GuestApiServiceCoreFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.user.invitation.management.common.UserInvitationMgtServiceHolder; import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.core.GuestApiServiceCore; import org.wso2.carbon.identity.organization.user.invitation.management.InvitationCoreService; @@ -27,16 +29,22 @@ */ public class GuestApiServiceCoreFactory { + private static final Log log = LogFactory.getLog(GuestApiServiceCoreFactory.class); private static final GuestApiServiceCore SERVICE; static { + if (log.isDebugEnabled()) { + log.debug("Initializing GuestApiServiceCoreFactory."); + } InvitationCoreService invitationCoreService = UserInvitationMgtServiceHolder.getInvitationCoreService(); if (invitationCoreService == null) { + log.error("InvitationCoreService is not available from OSGi context."); throw new IllegalStateException("InvitationCoreService is not available from OSGi context."); } SERVICE = new GuestApiServiceCore(invitationCoreService); + log.info("GuestApiServiceCoreFactory initialized successfully."); } /** @@ -46,6 +54,9 @@ public class GuestApiServiceCoreFactory { */ public static GuestApiServiceCore getGuestApiServiceCore() { + if (log.isDebugEnabled()) { + log.debug("Retrieving GuestApiServiceCore instance."); + } return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/impl/GuestsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/impl/GuestsApiServiceImpl.java index 92fed9ee2b..598e9d1ae6 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/impl/GuestsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.invitation.management/org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/invitation/management/v1/impl/GuestsApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.GuestsApiService; import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.core.GuestApiServiceCore; import org.wso2.carbon.identity.api.server.organization.user.invitation.management.v1.factories.GuestApiServiceCoreFactory; @@ -36,13 +38,18 @@ */ public class GuestsApiServiceImpl implements GuestsApiService { + private static final Log log = LogFactory.getLog(GuestsApiServiceImpl.class); private final GuestApiServiceCore guestApiServiceCore; public GuestsApiServiceImpl() { try { this.guestApiServiceCore = GuestApiServiceCoreFactory.getGuestApiServiceCore(); + if (log.isDebugEnabled()) { + log.debug("GuestsApiServiceImpl initialized successfully."); + } } catch (IllegalStateException e) { + log.error("Error occurred while initiating user invitation management services.", e); throw new RuntimeException("Error occurred while initiating user invitation management services.", e); } } @@ -50,38 +57,64 @@ public GuestsApiServiceImpl() { @Override public Response invitationAcceptPost(AcceptanceRequestBody acceptanceRequestBody) { + if (log.isDebugEnabled()) { + log.debug("Processing invitation acceptance request."); + } guestApiServiceCore.acceptInvitation(acceptanceRequestBody); + log.info("Invitation acceptance processed successfully."); return Response.noContent().build(); } @Override public Response invitationDelete(String invitationId) { + if (log.isDebugEnabled()) { + log.debug("Processing invitation deletion request for invitationId: " + invitationId); + } guestApiServiceCore.deleteInvitation(invitationId); + log.info("Invitation deleted successfully for invitationId: " + invitationId); return Response.noContent().build(); } @Override public Response invitationIntrospectPost(IntrospectRequestBody introspectRequestBody) { + if (log.isDebugEnabled()) { + log.debug("Processing invitation introspection request."); + } IntrospectSuccessResponse introspectSuccessResponse = guestApiServiceCore.introspectInvitation(introspectRequestBody.getConfirmationCode()); + log.info("Invitation introspection completed successfully."); return Response.ok().entity(introspectSuccessResponse).build(); } @Override public Response invitationListGet(String filter, Integer limit, Integer offset, String sortOrder, String sortBy) { + if (log.isDebugEnabled()) { + log.debug("Processing invitations list request with filter: " + filter); + } InvitationsListResponse invitationsListResponse = guestApiServiceCore.getInvitations(filter, limit, offset, sortOrder, sortBy); + log.info("Invitations list retrieved successfully."); return Response.ok().entity(invitationsListResponse).build(); } @Override public Response invitationTriggerPost(InvitationRequestBody invitationRequestBody) { + if (invitationRequestBody == null) { + log.error("InvitationRequestBody cannot be null in invitation creation request."); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + if (log.isDebugEnabled()) { + log.debug("Processing invitation creation request for usernames: " + + (invitationRequestBody.getUsernames() != null ? + invitationRequestBody.getUsernames().size() + " users" : "unknown users")); + } List invitationSuccessResponse = guestApiServiceCore.createInvitation(invitationRequestBody); + log.info("Invitation creation processed successfully."); return Response.ok().entity(invitationSuccessResponse).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java index a794fb3bac..b0255b0563 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.common/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/common/UserSharingMgtServiceHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.sharing.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.organization.management.organization.user.sharing.UserSharingPolicyHandlerService; @@ -26,6 +28,8 @@ */ public class UserSharingMgtServiceHolder { + private static final Log LOG = LogFactory.getLog(UserSharingMgtServiceHolder.class); + private UserSharingMgtServiceHolder() { } @@ -44,6 +48,19 @@ private static class UserSharingPolicyHandlerServiceHolder { */ public static UserSharingPolicyHandlerService getUserSharingPolicyHandlerService() { - return UserSharingMgtServiceHolder.UserSharingPolicyHandlerServiceHolder.SERVICE; + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving UserSharingPolicyHandlerService from OSGi service registry."); + } + + UserSharingPolicyHandlerService service = + UserSharingMgtServiceHolder.UserSharingPolicyHandlerServiceHolder.SERVICE; + + if (service == null) { + LOG.warn("UserSharingPolicyHandlerService is not available in the OSGi service registry."); + } else if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved UserSharingPolicyHandlerService from OSGi service registry."); + } + + return service; } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/core/UsersApiServiceCore.java b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/core/UsersApiServiceCore.java index 0b5c04d259..96b7769549 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/core/UsersApiServiceCore.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/core/UsersApiServiceCore.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.constants.UserSharingMgtConstants; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.model.Error; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.model.ProcessSuccessResponse; @@ -72,6 +74,7 @@ */ public class UsersApiServiceCore { + private static final Log LOG = LogFactory.getLog(UsersApiServiceCore.class); private final UserSharingPolicyHandlerService userSharingPolicyHandlerService; public UsersApiServiceCore(UserSharingPolicyHandlerService userSharingPolicyHandlerService) { @@ -86,7 +89,14 @@ public UsersApiServiceCore(UserSharingPolicyHandlerService userSharingPolicyHand */ public Response shareUser(UserShareRequestBody userShareRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Initiating selective user sharing process."); + } + if (userShareRequestBody == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid selective user share request. Request body is null."); + } return Response.status(Response.Status.BAD_REQUEST) .entity(buildErrorResponse(makeRequestError(INVALID_SELECTIVE_USER_SHARE_REQUEST_BODY))).build(); } @@ -96,11 +106,18 @@ public Response shareUser(UserShareRequestBody userShareRequestBody) { try { userSharingPolicyHandlerService.populateSelectiveUserShare(selectiveUserShareDO); + LOG.info("Selective user sharing process initiated successfully."); return Response.status(Response.Status.ACCEPTED) .entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_SHARE)).build(); } catch (UserSharingMgtClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Client error occurred during selective user sharing: " + e.getMessage()); + } return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorResponse(e)).build(); } catch (UserSharingMgtException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Server error occurred during selective user sharing: " + e.getMessage()); + } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorResponse(e)).build(); } } @@ -112,7 +129,14 @@ public Response shareUser(UserShareRequestBody userShareRequestBody) { */ public Response shareUserWithAll(UserShareWithAllRequestBody userShareWithAllRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Initiating general user sharing process with all organizations."); + } + if (userShareWithAllRequestBody == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid general user share request. Request body is null."); + } return Response.status(Response.Status.BAD_REQUEST) .entity(buildErrorResponse(makeRequestError(INVALID_GENERAL_USER_SHARE_REQUEST_BODY))).build(); } @@ -122,11 +146,18 @@ public Response shareUserWithAll(UserShareWithAllRequestBody userShareWithAllReq try { userSharingPolicyHandlerService.populateGeneralUserShare(generalUserShareDO); + LOG.info("General user sharing process with all organizations initiated successfully."); return Response.status(Response.Status.ACCEPTED) .entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_SHARE)).build(); } catch (UserSharingMgtClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Client error occurred during general user sharing: " + e.getMessage()); + } return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorResponse(e)).build(); } catch (UserSharingMgtException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Server error occurred during general user sharing: " + e.getMessage()); + } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorResponse(e)).build(); } } @@ -138,7 +169,14 @@ public Response shareUserWithAll(UserShareWithAllRequestBody userShareWithAllReq */ public Response unshareUser(UserUnshareRequestBody userUnshareRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Initiating selective user unsharing process."); + } + if (userUnshareRequestBody == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid selective user unshare request. Request body is null."); + } return Response.status(Response.Status.BAD_REQUEST) .entity(buildErrorResponse(makeRequestError(INVALID_SELECTIVE_USER_UNSHARE_REQUEST_BODY))).build(); } @@ -148,12 +186,19 @@ public Response unshareUser(UserUnshareRequestBody userUnshareRequestBody) { try { userSharingPolicyHandlerService.populateSelectiveUserUnshare(selectiveUserUnshareDO); + LOG.info("Selective user unsharing process initiated successfully."); return Response.status(Response.Status.ACCEPTED) .entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_UNSHARE)) .build(); } catch (UserSharingMgtClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Client error occurred during selective user unsharing: " + e.getMessage()); + } return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorResponse(e)).build(); } catch (UserSharingMgtException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Server error occurred during selective user unsharing: " + e.getMessage()); + } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorResponse(e)).build(); } } @@ -165,7 +210,14 @@ public Response unshareUser(UserUnshareRequestBody userUnshareRequestBody) { */ public Response unshareUserWithAll(UserUnshareWithAllRequestBody userUnshareWithAllRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Initiating general user unsharing process from all organizations."); + } + if (userUnshareWithAllRequestBody == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid general user unshare request. Request body is null."); + } return Response.status(Response.Status.BAD_REQUEST) .entity(buildErrorResponse(makeRequestError(INVALID_GENERAL_USER_UNSHARE_REQUEST_BODY))).build(); } @@ -175,12 +227,19 @@ public Response unshareUserWithAll(UserUnshareWithAllRequestBody userUnshareWith try { userSharingPolicyHandlerService.populateGeneralUserUnshare(generalUserUnshareDO); + LOG.info("General user unsharing process from all organizations initiated successfully."); return Response.status(Response.Status.ACCEPTED) .entity(getProcessSuccessResponse(RESPONSE_DETAIL_USER_UNSHARE)) .build(); } catch (UserSharingMgtClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Client error occurred during general user unsharing: " + e.getMessage()); + } return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorResponse(e)).build(); } catch (UserSharingMgtException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Server error occurred during general user unsharing: " + e.getMessage()); + } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorResponse(e)).build(); } } @@ -199,7 +258,14 @@ public Response unshareUserWithAll(UserUnshareWithAllRequestBody userUnshareWith public Response getSharedOrganizations(String userId, String after, String before, Integer limit, String filter, Boolean recursive) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving shared organizations for user: " + (userId != null ? userId : "null")); + } + if (userId == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid user ID provided for retrieving shared organizations."); + } return Response.status(Response.Status.BAD_REQUEST) .entity(buildErrorResponse(makeRequestError(INVALID_UUID_FORMAT))).build(); } @@ -210,10 +276,21 @@ public Response getSharedOrganizations(String userId, String after, String befor recursive); UserSharedOrganizationsResponse response = populateUserSharedOrganizationsResponse(result); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved " + + (result.getSharedOrgs() != null ? result.getSharedOrgs().size() : 0) + + " shared organizations for user: " + userId); + } return Response.ok().entity(response).build(); } catch (UserSharingMgtClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Client error occurred while retrieving shared organizations: " + e.getMessage()); + } return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorResponse(e)).build(); } catch (UserSharingMgtException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Server error occurred while retrieving shared organizations: " + e.getMessage()); + } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorResponse(e)).build(); } } @@ -233,7 +310,15 @@ public Response getSharedOrganizations(String userId, String after, String befor public Response getSharedRoles(String userId, String orgId, String after, String before, Integer limit, String filter, Boolean recursive) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving shared roles for user: " + (userId != null ? userId : "null") + + " in organization: " + (orgId != null ? orgId : "null")); + } + if (userId == null || orgId == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("Invalid user ID or organization ID provided for retrieving shared roles."); + } return Response.status(Response.Status.BAD_REQUEST) .entity(buildErrorResponse(makeRequestError(INVALID_UUID_FORMAT))).build(); } @@ -244,10 +329,21 @@ public Response getSharedRoles(String userId, String orgId, String after, String limit, filter, recursive); UserSharedRolesResponse response = populateUserSharedRolesResponse(result); + if (LOG.isDebugEnabled()) { + LOG.debug("Successfully retrieved " + + (result.getSharedRoles() != null ? result.getSharedRoles().size() : 0) + + " shared roles for user: " + userId + " in organization: " + orgId); + } return Response.ok().entity(response).build(); } catch (UserSharingMgtClientException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Client error occurred while retrieving shared roles: " + e.getMessage()); + } return Response.status(Response.Status.BAD_REQUEST).entity(buildErrorResponse(e)).build(); } catch (UserSharingMgtException e) { + if (LOG.isDebugEnabled()) { + LOG.debug("Server error occurred while retrieving shared roles: " + e.getMessage()); + } return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(buildErrorResponse(e)).build(); } } diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/factories/UsersApiServiceCoreFactory.java b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/factories/UsersApiServiceCoreFactory.java index 9812374312..c62887792d 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/factories/UsersApiServiceCoreFactory.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/factories/UsersApiServiceCoreFactory.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.factories; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.common.UserSharingMgtServiceHolder; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.core.UsersApiServiceCore; import org.wso2.carbon.identity.organization.management.organization.user.sharing.UserSharingPolicyHandlerService; @@ -27,15 +29,21 @@ */ public class UsersApiServiceCoreFactory { + private static final Log LOG = LogFactory.getLog(UsersApiServiceCoreFactory.class); private static final UsersApiServiceCore SERVICE; static { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing UsersApiServiceCore factory."); + } UserSharingPolicyHandlerService userSharingPolicyHandlerService = UserSharingMgtServiceHolder .getUserSharingPolicyHandlerService(); if (userSharingPolicyHandlerService == null) { + LOG.error("UserSharingPolicyHandlerService is not available from the OSGi context."); throw new IllegalStateException("UserSharingPolicyHandlerService is not available from the OSGi context."); } SERVICE = new UsersApiServiceCore(userSharingPolicyHandlerService); + LOG.info("UsersApiServiceCore factory initialized successfully."); } /** diff --git a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/impl/UsersApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/impl/UsersApiServiceImpl.java index 66cb1b012b..7cd0612502 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/impl/UsersApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.organization.user.sharing.management/org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/user/sharing/management/v1/impl/UsersApiServiceImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.impl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.UsersApiService; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.core.UsersApiServiceCore; import org.wso2.carbon.identity.api.server.organization.user.sharing.management.v1.factories.UsersApiServiceCoreFactory; @@ -35,13 +37,21 @@ */ public class UsersApiServiceImpl implements UsersApiService { + private static final Log LOG = LogFactory.getLog(UsersApiServiceImpl.class); private final UsersApiServiceCore usersApiServiceCore; public UsersApiServiceImpl() { + if (LOG.isDebugEnabled()) { + LOG.debug("Initializing UsersApiServiceImpl."); + } try { this.usersApiServiceCore = UsersApiServiceCoreFactory.getUsersApiServiceCore(); + if (LOG.isDebugEnabled()) { + LOG.debug("UsersApiServiceImpl initialized successfully."); + } } catch (IllegalStateException e) { + LOG.error("Error initializing UsersApiService: " + e.getMessage()); throw new RuntimeException(ERROR_INITIATING_USERS_API_SERVICE.getMessage(), e); } } @@ -49,24 +59,36 @@ public UsersApiServiceImpl() { @Override public Response processUserSharing(UserShareRequestBody userShareRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing user sharing request."); + } return usersApiServiceCore.shareUser(userShareRequestBody); } @Override public Response processUserSharingAll(UserShareWithAllRequestBody userShareWithAllRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing user sharing with all organizations request."); + } return usersApiServiceCore.shareUserWithAll(userShareWithAllRequestBody); } @Override public Response processUserUnsharing(UserUnshareRequestBody userUnshareRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing user unsharing request."); + } return usersApiServiceCore.unshareUser(userUnshareRequestBody); } @Override public Response removeUserSharing(UserUnshareWithAllRequestBody userUnshareWithAllRequestBody) { + if (LOG.isDebugEnabled()) { + LOG.debug("Processing user unsharing from all organizations request."); + } return usersApiServiceCore.unshareUserWithAll(userUnshareWithAllRequestBody); } @@ -74,6 +96,9 @@ public Response removeUserSharing(UserUnshareWithAllRequestBody userUnshareWithA public Response usersUserIdSharedOrganizationsGet(String userId, String after, String before, Integer limit, String filter, Boolean recursive) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving shared organizations for user."); + } return usersApiServiceCore.getSharedOrganizations(userId, after, before, limit, filter, recursive); } @@ -81,6 +106,9 @@ public Response usersUserIdSharedOrganizationsGet(String userId, String after, S public Response usersUserIdSharedRolesGet(String userId, String orgId, String after, String before, Integer limit, String filter, Boolean recursive) { + if (LOG.isDebugEnabled()) { + LOG.debug("Retrieving shared roles for user in organization."); + } return usersApiServiceCore.getSharedRoles(userId, orgId, after, before, limit, filter, recursive); } }