Skip to content

Add device registration support and email template for notifications#390

Merged
ZiyamSanthosh merged 1 commit into
wso2-extensions:masterfrom
raviendalpatadu:feature/multiple-device-support-for-push-auth
Jul 17, 2026
Merged

Add device registration support and email template for notifications#390
ZiyamSanthosh merged 1 commit into
wso2-extensions:masterfrom
raviendalpatadu:feature/multiple-device-support-for-push-auth

Conversation

@raviendalpatadu

@raviendalpatadu raviendalpatadu commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This pull request adds support for push notification templates and placeholders related to device registration events. It introduces new constants, templates, and data fields to handle notifications when a new device is registered to a user's account.

Push Notification Template and Placeholder Enhancements:

  • Added a new push notification scenario constant for device registration in PushNotification (PUSH_DEVICE_REGISTRATION_SCENARIO).
  • Introduced a new template in PushNotificationTemplate for device registration, including a title and message with placeholders for device name, model, and registration time.
  • Added new placeholders (push-device-name, push-device-model, registration-time) to PushNotificationPlaceholder for use in device registration notifications.

Push Notification Data Handling:

  • Updated buildPushNotificationData in PushNotificationHandler.java to populate the new device registration fields (pushDeviceName, pushDeviceModel, registrationTime) from event properties.

Related Issues

Summary by CodeRabbit

Release Notes

New Features

  • Added push notification support for new device registrations, including a dedicated scenario, notification template, and new placeholders (tenant, device name/model, registration time).
  • Introduced a branded HTML email template (“A new device has been registered”) featuring device details, registration time, IP address, and organization styling/logo, with support contact and footer.

Bug Fixes

  • Improved push notification placeholder handling by treating missing placeholder values as empty strings to avoid template rendering issues.

@CLAassistant

CLAassistant commented Jun 17, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds push device registration notification support: new scenario, template, and placeholder constants are defined; the handler validates and maps device registration fields while normalizing missing placeholder values; and a PushDeviceRegistration email template is added.

Changes

Push Device Registration Notification

Layer / File(s) Summary
Constants, template, and placeholder definitions
components/.../NotificationConstants.java
Adds PUSH_DEVICE_REGISTRATION_SCENARIO to PushNotification, defines DEVICE_REGISTRATION with device and registration placeholders, and extends PushNotificationPlaceholder with TENANT_DOMAIN, PUSH_DEVICE_NAME, PUSH_DEVICE_MODEL, and REGISTRATION_TIME.
Handler validation, data population, and placeholder normalization
components/.../PushNotificationHandler.java
validatePushEventProperties adds scenario-specific validation for PUSH_DEVICE_REGISTRATION_SCENARIO; buildPushNotificationData sets device name, model, and registration time fields; getPlaceHolderValues stores StringUtils.EMPTY for missing values.
PushDeviceRegistration email template
features/.../email-admin-config.xml
Inserts a PushDeviceRegistration configuration block with subject and a full HTML/CDATA body using device, branding, support, and footer placeholders.

Sequence Diagram

sequenceDiagram
  participant EventData as Push Event
  participant Validate as validatePushEventProperties()
  participant BuildData as buildPushNotificationData()
  participant GetPlaceholders as getPlaceHolderValues()
  participant Builder as PushNotificationData.Builder

  EventData->>Validate: check PUSH_DEVICE_REGISTRATION_SCENARIO
  Validate->>Validate: require device name, model, and registration time
  EventData->>BuildData: populate builder from event properties
  BuildData->>GetPlaceholders: resolve placeholder values
  GetPlaceholders->>GetPlaceholders: convert null to EMPTY
  GetPlaceholders-->>BuildData: placeholder map
  BuildData->>Builder: set pushDeviceName, pushDeviceModel, registrationTime
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • ZiyamSanthosh

Poem

🐇 A new device hops into the light,
With name and model set just right.
The rabbit sends a polished note,
With placeholders tucked in every quote.
New device registered — ears up, hooray! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the required template sections like Purpose, Goals, Approach, Testing, and Security checks. Rewrite the PR description using the repository template and fill in the required sections, especially purpose, goals, approach, tests, and security checks.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding device registration support and an email template for notifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java`:
- Line 205: The last enum constant REGISTRATION_TIME in the
PushNotificationPlaceholder enum has invalid syntax with a trailing comma before
the semicolon (,;). Remove the trailing comma after
REGISTRATION_TIME("registration-time") so that only the semicolon remains,
making it REGISTRATION_TIME("registration-time");

In
`@components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java`:
- Around line 324-329: The setPushDeviceName, setPushDeviceModel, and
setRegistrationTime methods are receiving values directly from eventProperties
without validation, which can result in null values being set. These null values
will cause a NullPointerException when placeholder replacement occurs later at
line 392 during String#replace operations. Add validation in the
validatePushEventProperties method to check that the
NotificationConstants.PushNotificationPlaceholder.PUSH_DEVICE_NAME,
PUSH_DEVICE_MODEL, and REGISTRATION_TIME fields are present and not null when
the event scenario is DEVICE_REGISTRATION, and throw an appropriate exception if
any are missing to prevent the event flow from reaching the placeholder
replacement logic with incomplete data.

In
`@features/org.wso2.carbon.email.mgt.server.feature/resources/email-admin-config.xml`:
- Line 26127: The XML document has duplicate id attributes with the value
templateBody appearing multiple times, which violates XML/HTML uniqueness
requirements and breaks DOM and CSS targeting in mail clients. Locate all
instances of id="templateBody" in the email-admin-config.xml file (specifically
at the noted line ranges) and make each ID unique by appending a descriptive
suffix or number to each occurrence, such as templateBody1, templateBody2, etc.,
ensuring each id attribute value appears only once in the document.
- Line 26128: The style attribute contains an invalid CSS unit for the
padding-top property. Change `padding-top: 0p` to `padding-top: 0` or
`padding-top: 0px` since "p" is not a valid CSS unit. The zero value is valid
without a unit, or use the standard pixel unit "px" instead.
- Around line 26104-26110: The device metadata placeholders
({{push-device-name}} and {{push-device-model}}) in the email template are being
inserted into HTML content without proper HTML entity encoding. The replaceTags
method in Notification.java currently uses Matcher.quoteReplacement() which only
escapes regex special characters but not HTML entities. Apply HTML entity
encoding (such as StringEscapeUtils.escapeHtml4() from Apache Commons Lang) to
the device metadata values before they are substituted into the email body in
the replaceTags method or at the point where PushNotificationHandler.java
populates these values into event properties. This prevents HTML/JavaScript
injection attacks when unescaped user-controllable device names or models are
rendered in email clients.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a44f6076-0dd3-4d41-9dda-396178943a23

📥 Commits

Reviewing files that changed from the base of the PR and between c4d0ec5 and 614625f.

📒 Files selected for processing (3)
  • components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/NotificationConstants.java
  • components/event-handler-notification/org.wso2.carbon.identity.event.handler.notification/src/main/java/org/wso2/carbon/identity/event/handler/notification/PushNotificationHandler.java
  • features/org.wso2.carbon.email.mgt.server.feature/resources/email-admin-config.xml

Comment on lines +26104 to +26110
<li><b>Device name:</b> {{push-device-name}}</li>
<li><b>Model:</b> {{push-device-model}}</li>
<li>
<b>Registered at:</b> {{registration-time}}
</li>
</ul>
</td>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read-only verification: locate rendering and escaping path for email placeholders.

set -e

echo "== Find placeholder and scenario wiring =="
rg -n -C3 'push-device-name|push-device-model|registration-time|PushDeviceRegistration|PUSH_DEVICE_REGISTRATION_SCENARIO'

echo
echo "== Find notification template rendering/placeholder replacement code =="
rg -n -C3 'replace|interpolate|placeholder|mustache|velocity|template engine|escapeHtml|htmlEscape|StringEscapeUtils'

echo
echo "== Focus on handler path for device registration payload construction =="
rg -n -C5 'buildPushNotificationData|pushDeviceName|pushDeviceModel|registrationTime|event properties'

Repository: wso2-extensions/identity-event-handler-notification

Length of output: 50408


🏁 Script executed:

#!/bin/bash

# Find where placeholders are actually replaced/interpolated in templates
echo "== Find template rendering/interpolation implementation =="
rg -n "resolveTemplate|renderTemplate|interpolate|replaceAll|replace.*placeholder|setBody|setContent" -A 5 --max-count=20

echo
echo "== Find PushNotificationHandler and device registration data flow =="
fd -t f "PushNotificationHandler\|DeviceRegistration" --max-results=10
rg -n "PushNotificationHandler\|buildNotification\|buildEventProperties" -B 2 -A 8 --max-count=15

echo
echo "== Check for HTML escaping in NotificationUtil =="
rg -n "htmlEscape|StringEscapeUtils|HtmlUtils|Apache.*escape|escape.*Html" -B 2 -A 5

Repository: wso2-extensions/identity-event-handler-notification

Length of output: 50407


🏁 Script executed:

#!/bin/bash

# Search more specifically for template body rendering
echo "== Find where email body/template is rendered with placeholders =="
rg -n "setBody|setText|setHtmlBody|emailTemplate\.getBody|template\.getBody" -B 3 -A 8 --max-count=25

echo
echo "== Look for velocity, freemarker, or mustache templating =="
rg -n "VelocityEngine|Template\.process|evaluate|render" -B 2 -A 5 --max-count=20

Repository: wso2-extensions/identity-event-handler-notification

Length of output: 50407


🏁 Script executed:

#!/bin/bash

# Find the complete replaceTags method in Notification.java
fd -t f "Notification.java" -x rg -l "class Notification|replaceTags" {} \; 2>/dev/null | head -1 | xargs cat -n | head -150

echo
echo "== Search for replaceTags method signature and full implementation =="
rg -n "private.*replaceTags|public.*replaceTags" -A 30 components/event-handler-notification/

Repository: wso2-extensions/identity-event-handler-notification

Length of output: 12399


🏁 Script executed:

#!/bin/bash

# Find where device properties come from - look at device registration event handlers
echo "== Find device registration event handling =="
fd -t f -i "device.*registration\|registration.*handler" --max-results=10

echo
echo "== Search for where push-device-name and push-device-model are populated in event properties =="
rg -n "push-device-name|push-device-model|PUSH_DEVICE_NAME|PUSH_DEVICE_MODEL" -B 5 -A 5 \
  components/event-handler-notification/ --max-count=20

Repository: wso2-extensions/identity-event-handler-notification

Length of output: 8855


Confirm: Device metadata placeholders require HTML escaping before email rendering.

The replaceTags method in Notification.java (line 70-71) uses Matcher.quoteReplacement(), which only escapes regex special characters (backslashes and dollar signs) but does NOT perform HTML escaping. Device metadata values for {{push-device-name}} and {{push-device-model}} are sourced from event properties (PushNotificationHandler.java, lines 324-327) and inserted directly into the email body without HTML entity encoding. Since the email content type is text/html, unescaped user-controllable device names/models could enable HTML/JavaScript injection in email clients that render the content.

Recommendation: Apply HTML entity encoding (e.g., StringEscapeUtils.escapeHtml4() from Apache Commons Lang) to device metadata values before placeholder substitution, or use a templating engine that provides context-aware auto-escaping.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@features/org.wso2.carbon.email.mgt.server.feature/resources/email-admin-config.xml`
around lines 26104 - 26110, The device metadata placeholders
({{push-device-name}} and {{push-device-model}}) in the email template are being
inserted into HTML content without proper HTML entity encoding. The replaceTags
method in Notification.java currently uses Matcher.quoteReplacement() which only
escapes regex special characters but not HTML entities. Apply HTML entity
encoding (such as StringEscapeUtils.escapeHtml4() from Apache Commons Lang) to
the device metadata values before they are substituted into the email body in
the replaceTags method or at the point where PushNotificationHandler.java
populates these values into event properties. This prevents HTML/JavaScript
injection attacks when unescaped user-controllable device names or models are
rendered in email clients.

>
<!-- BEGIN BODY // -->
<table
id="templateBody"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use unique IDs instead of repeating templateBody.

id="templateBody" is declared twice in the same document, which is invalid HTML and can cause inconsistent CSS/DOM targeting in mail clients.

Suggested fix
-                    <table
-                      id="templateBody"
+                    <table
+                      id="templateFooter"

Also applies to: 26257-26257

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@features/org.wso2.carbon.email.mgt.server.feature/resources/email-admin-config.xml`
at line 26127, The XML document has duplicate id attributes with the value
templateBody appearing multiple times, which violates XML/HTML uniqueness
requirements and breaks DOM and CSS targeting in mail clients. Locate all
instances of id="templateBody" in the email-admin-config.xml file (specifically
at the noted line ranges) and make each ID unique by appending a descriptive
suffix or number to each occurrence, such as templateBody1, templateBody2, etc.,
ensuring each id attribute value appears only once in the document.

@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch from 614625f to 364de0e Compare June 18, 2026 13:04
TENANT_DOMAIN("tenant-domain"),
PUSH_DEVICE_NAME("push-device-name"),
PUSH_DEVICE_MODEL("push-device-model"),
REGISTRATION_TIME("registration-time");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check on the IP address

if (matchedKey != null) {
String value = (String) eventProperties.get(matchedKey.getPlaceholder());
placeholderValues.put(placeHolder, value);
placeholderValues.put(placeHolder, value != null ? value : StringUtils.EMPTY);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this and add it in the Provider

@jenkins-is-staging

Copy link
Copy Markdown

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/29421849417

@jenkins-is-staging

Copy link
Copy Markdown

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/29421849417
Status: failure

@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch 2 times, most recently from b7dbc6b to 34fc2a6 Compare July 15, 2026 15:51
@raviendalpatadu
raviendalpatadu force-pushed the feature/multiple-device-support-for-push-auth branch from 34fc2a6 to 7dbec08 Compare July 16, 2026 11:51
@jenkins-is-staging

Copy link
Copy Markdown

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/29496088613

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.35%. Comparing base (c4d0ec5) to head (7dbec08).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
.../handler/notification/PushNotificationHandler.java 33.33% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #390      +/-   ##
============================================
+ Coverage     40.32%   40.35%   +0.02%     
+ Complexity      673      668       -5     
============================================
  Files            78       78              
  Lines          5986     6002      +16     
  Branches        896      899       +3     
============================================
+ Hits           2414     2422       +8     
- Misses         3311     3318       +7     
- Partials        261      262       +1     
Flag Coverage Δ
unit 28.34% <52.94%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jenkins-is-staging

Copy link
Copy Markdown

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/29496088613
Status: success

@jenkins-is-staging jenkins-is-staging left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/29496088613

@ZiyamSanthosh
ZiyamSanthosh merged commit 3fe7859 into wso2-extensions:master Jul 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants