-
Notifications
You must be signed in to change notification settings - Fork 170
Onboarding notification-senders/email PATCH endpoint #1034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -255,6 +255,24 @@ public EmailSender updateEmailSender(String senderName, EmailSenderUpdateRequest | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Patch email sender details by name. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
| * @param senderName Email sender's name. | ||||||||||||||||||||||||||||||||||||||
| * @param emailSenderUpdateRequest Email sender's updated configurations. | ||||||||||||||||||||||||||||||||||||||
| * @return Updated email sender. | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| public EmailSender patchEmailSender(String senderName, EmailSenderUpdateRequest emailSenderUpdateRequest) { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| EmailSenderDTO dto = updateEmailSenderDTOFromPatchRequest(senderName, emailSenderUpdateRequest); | ||||||||||||||||||||||||||||||||||||||
| EmailSenderDTO emailSenderDTO = notificationSenderManagementService.updateEmailSender(dto); | ||||||||||||||||||||||||||||||||||||||
| return buildEmailSenderFromDTO(emailSenderDTO); | ||||||||||||||||||||||||||||||||||||||
| } catch (NotificationSenderManagementException e) { | ||||||||||||||||||||||||||||||||||||||
| throw handleException(e); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Update sms sender details by name. | ||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -333,6 +351,43 @@ private EmailSenderDTO buildEmailSenderDTO(String senderName, EmailSenderUpdateR | |||||||||||||||||||||||||||||||||||||
| return dto; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private EmailSenderDTO updateEmailSenderDTOFromPatchRequest(String senderName, | ||||||||||||||||||||||||||||||||||||||
| EmailSenderUpdateRequest emailSenderUpdateRequest) { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| EmailSenderDTO existingEmailSenderDTO; | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO = notificationSenderManagementService.getEmailSender(senderName); | ||||||||||||||||||||||||||||||||||||||
| } catch (NotificationSenderManagementException e) { | ||||||||||||||||||||||||||||||||||||||
lashinijay marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
| throw handleException(e); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setName(senderName); | ||||||||||||||||||||||||||||||||||||||
| if (emailSenderUpdateRequest == null) { | ||||||||||||||||||||||||||||||||||||||
| return existingEmailSenderDTO; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setFromAddress(emailSenderUpdateRequest.getFromAddress() != null ? | ||||||||||||||||||||||||||||||||||||||
| emailSenderUpdateRequest.getFromAddress() : existingEmailSenderDTO.getFromAddress()); | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setSmtpPort(emailSenderUpdateRequest.getSmtpPort() != null ? | ||||||||||||||||||||||||||||||||||||||
| emailSenderUpdateRequest.getSmtpPort() : existingEmailSenderDTO.getSmtpPort()); | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setSmtpServerHost(emailSenderUpdateRequest.getSmtpServerHost() != null ? | ||||||||||||||||||||||||||||||||||||||
| emailSenderUpdateRequest.getSmtpServerHost() : existingEmailSenderDTO.getSmtpServerHost()); | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setAuthType(emailSenderUpdateRequest.getAuthType() != null ? | ||||||||||||||||||||||||||||||||||||||
| emailSenderUpdateRequest.getAuthType() : existingEmailSenderDTO.getAuthType()); | ||||||||||||||||||||||||||||||||||||||
| if (emailSenderUpdateRequest.getProperties() != null && !emailSenderUpdateRequest.getProperties().isEmpty()) { | ||||||||||||||||||||||||||||||||||||||
| emailSenderUpdateRequest.getProperties().forEach((prop) -> { | ||||||||||||||||||||||||||||||||||||||
| if (StringUtils.isNotBlank(prop.getKey()) && StringUtils.isNotBlank(prop.getValue())) { | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.getProperties().put(prop.getKey(), prop.getValue()); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+375
to
+381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for property deletion or removal patterns in the codebase
rg -nP -C3 'property.*delet|remov.*property|Properties.*clear|properties\.remove' --type=javaRepository: wso2/identity-api-server Length of output: 19723 🏁 Script executed: # Also check the API specification files
fd -e yaml -e yml -e json | xargs rg -l 'notification.*sender|NotificationSender' 2>/dev/null | head -20Repository: wso2/identity-api-server Length of output: 407 🏁 Script executed: # Look for OpenAPI/Swagger specifications
fd -e yaml -e yml | head -30Repository: wso2/identity-api-server Length of output: 5079 🏁 Script executed: # Examine the NotificationSenderManagementService file more broadly to understand the update pattern
wc -l "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"Repository: wso2/identity-api-server Length of output: 316 🏁 Script executed: # Get context around the property merge logic and the update method signature
cat -n "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" | sed -n '350,400p'Repository: wso2/identity-api-server Length of output: 3260 🏁 Script executed: # Check the OpenAPI spec for the PATCH operation
cat "components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/resources/notification-sender.yaml" | head -200Repository: wso2/identity-api-server Length of output: 6233 🏁 Script executed: # Search for PATCH operation in the spec
rg -A 20 'patch:' "components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/resources/notification-sender.yaml"Repository: wso2/identity-api-server Length of output: 777 🏁 Script executed: # Check for test files that demonstrate expected property removal behavior
fd -e java -path '*test*' | xargs rg -l 'updateEmailSender|NotificationSenderManagementService' 2>/dev/null | head -10Repository: wso2/identity-api-server Length of output: 2542 🏁 Script executed: # Look at the broader context - check if there's any null handling or clearing logic for properties
cat -n "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" | sed -n '340,390p'Repository: wso2/identity-api-server Length of output: 3275 🏁 Script executed: # Get the complete PATCH operation definition including requestBody
rg -A 40 'patch:' "components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/resources/notification-sender.yaml"Repository: wso2/identity-api-server Length of output: 1372 🏁 Script executed: # Check v1 implementation for property handling
cat "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" | grep -A 20 "updateEmailSenderDTOFromPatchRequest" | head -30Repository: wso2/identity-api-server Length of output: 50 🏁 Script executed: # Check if there's any documentation or comments about property behavior
rg -B 5 -A 10 "properties.*forEach|properties.*put" "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"Repository: wso2/identity-api-server Length of output: 4075 🏁 Script executed: # Search for any comments or documentation about property behavior in the context of PATCH
rg -B 10 'updateEmailSenderDTOFromPatchRequest' "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" | head -20Repository: wso2/identity-api-server Length of output: 839 🏁 Script executed: # Check the schema definition for EmailSenderUpdateRequest to understand property semantics
rg -A 30 'EmailSenderUpdateRequest:' "components/org.wso2.carbon.identity.api.server.notification.sender/org.wso2.carbon.identity.api.server.notification.sender.v2/src/main/resources/notification-sender.yaml"Repository: wso2/identity-api-server Length of output: 857 The property merge logic does not support property removal via PATCH requests. The forEach loop (lines 375-381) only adds or updates properties; there is no mechanism to remove existing properties. This is inconsistent with standard PATCH semantics where clients should be able to modify properties completely. Consider whether the API should support property removal by:
Note that scalar fields use conditional preservation ( 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| if (BASIC.equalsIgnoreCase(existingEmailSenderDTO.getAuthType())) { | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.getProperties().put(USERNAME, existingEmailSenderDTO.getUsername()); | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.getProperties().put(PASSWORD, existingEmailSenderDTO.getPassword()); | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setUsername(null); | ||||||||||||||||||||||||||||||||||||||
| existingEmailSenderDTO.setPassword(null); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+382
to
+387
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential credential leak when switching auth types. When the auth type is changed from BASIC to another type (e.g., OAUTH), the old username/password credentials remain in the properties map since this cleanup only executes when the final authType is BASIC. Old credentials could be returned in API responses or persisted unnecessarily. Consider adding cleanup logic before the BASIC check: + // Clean up BASIC auth credentials if switching away from BASIC
+ if (!BASIC.equalsIgnoreCase(existingEmailSenderDTO.getAuthType())) {
+ existingEmailSenderDTO.getProperties().remove(USERNAME);
+ existingEmailSenderDTO.getProperties().remove(PASSWORD);
+ }
+
if (BASIC.equalsIgnoreCase(existingEmailSenderDTO.getAuthType())) {
existingEmailSenderDTO.getProperties().put(USERNAME, existingEmailSenderDTO.getUsername());
existingEmailSenderDTO.getProperties().put(PASSWORD, existingEmailSenderDTO.getPassword());
existingEmailSenderDTO.setUsername(null);
existingEmailSenderDTO.setPassword(null);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| return existingEmailSenderDTO; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private EmailSender buildEmailSenderFromDTO(EmailSenderDTO dto) { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| EmailSender emailSender = new EmailSender(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.