<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohamed Abshan on Medium]]></title>
        <description><![CDATA[Stories by Mohamed Abshan on Medium]]></description>
        <link>https://medium.com/@m.abshan?source=rss-f4fc0ebc8c09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4oI_YvVLWNW7szkMdkPLww.jpeg</url>
            <title>Stories by Mohamed Abshan on Medium</title>
            <link>https://medium.com/@m.abshan?source=rss-f4fc0ebc8c09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:46:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@m.abshan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Migrating WSO2 APIM + IS from Shared DB: What Breaks in Portal SSO and How to Fix It]]></title>
            <link>https://medium.com/@m.abshan/migrating-wso2-apim-is-from-shared-db-what-breaks-in-portal-sso-and-how-to-fix-it-014a70c96313?source=rss-f4fc0ebc8c09------2</link>
            <guid isPermaLink="false">https://medium.com/p/014a70c96313</guid>
            <dc:creator><![CDATA[Mohamed Abshan]]></dc:creator>
            <pubDate>Sun, 19 Apr 2026 19:52:05 GMT</pubDate>
            <atom:updated>2026-08-16T17:15:27.108Z</atom:updated>
            <content:encoded><![CDATA[<h4>A short guide to restoring portal SSO after decoupling your APIM and IS databases during migration to APIM 4.6.0 and IS 7.2.0</h4><blockquote><strong><em>Versions:</em></strong><em> Written and tested against APIM 4.6.0 with IS 7.2.0. The same steps apply to APIM 4.7.0 with IS 7.3.0, and generally to any APIM 4.6.0+ with IS 7.x — only minor console layout differences. Version-specific notes are called out where they matter.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fBsc3ATHZtN_ibLnAFSI9A.png" /></figure><p>If you have been running <strong>WSO2 API Manager with WSO2 Identity Server as a Resident Key Manager on a shared database</strong>, and you are now migrating to <strong>APIM 4.6.0 and IS 7.X.X</strong>, your portal OIDC SSO will need a few tweaks to keep working.</p><p>This is a short follow-up to <a href="https://sumudusahanweerasuriya.medium.com/wso2-api-manager-portal-oidc-sso-with-wso2-identity-server-7-0-0-c2c786c588f1">Sumudu Sahan Weerasuriya’s blog</a> on configuring IS as a Federated IDP for APIM portals. If you are setting up SSO on a fresh deployment, that blog covers everything. If you are migrating from a shared DB setup, this post fills in the extra bits.</p><h3>Who This Post Is For</h3><p>Before you start, work out which of these describes your deployment. It determines where you begin.</p><p><strong>1. You had shared DB, and portal OIDC SSO was already configured.</strong> This post is your delta. Start at “Why the Extra Steps?” below and work through steps 1–5.</p><p><strong>2. You had shared DB, but no portal SSO — users logged in with the native portal login page.</strong> This is the most common case coming off a Resident Key Manager setup, and it is easy to misdiagnose. Portal login worked without any SSO configuration because APIM and IS were reading the <em>same</em> UM_* tables. Once the databases separate, that shortcut is gone and there is no IdP configured to replace it. <strong>You need the base SSO setup first</strong> — follow <a href="https://sumudusahanweerasuriya.medium.com/wso2-api-manager-portal-oidc-sso-with-wso2-identity-server-7-0-0-c2c786c588f1">Sumudu&#39;s post</a> end to end, then come back here and apply steps 3–5 if you want roles rather than groups driving portal access (see the &quot;Groups or roles?&quot; note in step 3).</p><p>The symptom that identifies this case: newly created IS users <strong>cannot log in at all</strong>, while users that came across in the migration still can. The migrated users exist in APIM’s user store; the new ones only exist in IS.</p><p><strong>3. Fresh deployment, no migration.</strong> <a href="https://sumudusahanweerasuriya.medium.com/wso2-api-manager-portal-oidc-sso-with-wso2-identity-server-7-0-0-c2c786c588f1">Sumudu’s post</a> alone is sufficient. Nothing here is required — treat steps 3–5 as an optional variant if you prefer roles over groups.</p><h3>Why the Extra Steps?</h3><p>In the old shared DB setup, APIM and IS read user and role data from the same tables. When a user logged into the Publisher or DevPortal, APIM could just look up their roles directly — no OIDC claim plumbing needed. It just worked.</p><p>After migration, the databases are <strong>decoupled</strong>. Both products now run on independent schemas, which is the recommended architecture going forward. The trade-off is that APIM no longer has direct access to IS’s user store, so roles must now travel from IS to APIM <strong>inside the OIDC token</strong>.</p><p>This means two things need to happen:</p><ol><li>IS needs to be told to <strong>include roles in the token</strong>.</li><li>APIM needs to be told to <strong>read those roles from the token</strong> and map them to its internal roles.</li></ol><p>That’s the whole story. Everything below is just wiring that up.</p><h3>Identity Server Side</h3><p>Log into the IS console and open your existing OIDC SSO application.</p><h3>1. Add roles as a requested attribute</h3><p>Go to the <strong>User Attributes</strong> tab.</p><p>Check the <strong>Roles</strong> scope. If it is not listed as a named scope, expand <strong>Attributes without a scope</strong> and select roles from there.</p><p><strong>Why we do this:</strong> User attributes control what IS puts into the ID token. Previously, only groups and profile were selected because group membership was enough to drive portal access. Now that we need roles to flow through the token, we have to explicitly tell IS to include them. Without this step, the roles claim simply will not exist in the token APIM receives, and the user will log in with no permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axTw0KbXlbUqU6QdA619yA.png" /></figure><h3>2. Set Role Audience to Organization</h3><p>Go to the <strong>Roles</strong> tab and set <strong>Role Audience</strong> to <strong>Organization</strong>.</p><p><strong>Why we do this:</strong> In IS 7.x, roles can be scoped to a single application or to the whole organization. APIM portal roles like creator, publisher, and subscriber are organization-level roles — they apply across the organization, not just to this one OIDC application. If you leave this as &quot;Application&quot;, IS will only send back roles explicitly assigned to this specific app (usually none), and the roles claim in the token will be empty even though everything else looks correct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6a-4UZ7YU4Sd-1mQArje-Q.png" /></figure><h3>APIM Side</h3><p>Go to the APIM carbon console → <strong>Identity Providers</strong> → edit your IS IDP.</p><h3>3. Update the claim mapping from groups to roles</h3><p>Expand <strong>Claim Configuration → Basic Claim Configuration</strong> and update the mapping:</p><ul><li><strong>Identity Provider Claim URI:</strong> roles</li><li><strong>Local Claim URI:</strong> <a href="http://wso2.org/claims/role">http://wso2.org/claims/role</a></li><li><strong>Role Claim URI:</strong> roles</li></ul><p><strong>Why we do this:</strong> This mapping tells APIM which claim in the incoming token carries the user’s role information. Previously it pointed to groups, because IS was sending group names through that claim. Now that IS is sending actual roles through the roles claim, APIM needs to be redirected to look there instead. If you skip this, the token will contain the roles but APIM will keep looking at the empty groups claim and find nothing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdQdtXcyR7NvETdKcknPoQ.png" /></figure><h3>4. Map IS roles to APIM internal roles</h3><p>Expand <strong>Role Configuration</strong> and add a mapping row for each role your users can have:</p><blockquote><strong>You probably don’t need to create these roles in IS.</strong> After migration, the Internal/* roles APIM created automatically are already in IS with the Internal/ prefix dropped — Internal/publisher is just publisher. Check <strong>User Management → Roles in the IS console</strong> before creating anything; you can map to the existing ones directly.</blockquote><p>IS Role : APIM Local Role</p><p>creator : Internal/creator <br>publisher : Internal/publisher <br>subscriber : Internal/subscriber <br>devops : Internal/devops</p><p><strong>Why we do this:</strong> APIM and IS use different role names. A role called creator in IS means nothing to APIM unless we explicitly say it maps to Internal/creator. This is the translation layer. Without these mappings, federated users will authenticate successfully but will land in the portal with no effective permissions — they will see no APIs, no publish options, no subscriptions, depending on which role is missing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NtVJSeA_qjThTgy8aAL5fw.png" /></figure><h3>5. Add roles to the requested scopes</h3><p>Expand <strong>Federated Authenticators → OAuth2/OpenID Connect Configuration</strong> and update the <strong>Scopes</strong> field:</p><pre>openid groups profile roles</pre><p><strong>Why we do this:</strong> APIM only gets the claims it asks for. The Scopes field is the list of OIDC scopes APIM requests from IS during login. If roles was selected as a <strong>named OIDC scope</strong> on the IS side (step 1), you have to request it here as well — otherwise IS will not include it, regardless of the application-level config.</p><p><strong>When to skip this step:</strong> If you added roles from the <strong>Attributes without a scope</strong> section in IS, it is not backed by a named scope, so IS will include it in the token automatically and this field does not need to change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wVO7OTQ8NaI_RtsRNWT8A.png" /></figure><h3>That’s It</h3><p>Save everything, log into the Publisher or DevPortal, and your federated users should land with the correct roles.</p><p>If a user authenticates but has no permissions, 99% of the time it’s one of these:</p><ul><li>roles claim missing from the token → check IS User Attributes</li><li>Role Audience set to Application instead of Organization → check IS Roles tab</li><li>Claim mapping in APIM still says groups → check APIM IDP Claim Configuration</li><li>Role names don’t match exactly between IS and the APIM Role mapping table</li></ul><p>The shared DB decoupling is the right move for the long term — it keeps both products clean and independently upgradeable. You just have to pay the OIDC plumbing tax once, and after that portal SSO works the same as it always did.</p><p>Happy migrating 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=014a70c96313" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filling the Gaps: How to Add Tracing to Custom Handlers in WSO2 API Manager 4.x.x]]></title>
            <link>https://medium.com/@m.abshan/filling-the-gaps-how-to-add-tracing-to-custom-handlers-in-wso2-api-manager-4-x-x-68065fc6c82b?source=rss-f4fc0ebc8c09------2</link>
            <guid isPermaLink="false">https://medium.com/p/68065fc6c82b</guid>
            <dc:creator><![CDATA[Mohamed Abshan]]></dc:creator>
            <pubDate>Wed, 17 Dec 2025 15:02:23 GMT</pubDate>
            <atom:updated>2025-12-17T15:15:08.035Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAIWevys_LBEqSBVL5kjQA.png" /></figure><h3>The Hidden Performance Mystery in Your API Gateway 🔍</h3><p>Picture this: You’ve enabled tracing in your WSO2 API Manager, connected it to your observability platform, and you’re ready to optimize your API performance. But when you look at the traces, something’s off. There are mysterious gaps in your latency timeline — unaccounted time that seems to vanish into thin air.</p><p><strong>The culprit?</strong> Your custom handlers are running in stealth mode.</p><p>If you’re using custom Synapse or API handlers in WSO2 APIM 4.x, you’ve likely encountered this frustrating blind spot. Today, we’re going to solve this mystery and give you complete visibility into your API request lifecycle.</p><h3>Why Custom Handlers Go Unnoticed 🕵️</h3><p>By default, WSO2 APIM’s tracing capabilities don’t account for time spent in custom handlers. This isn’t a bug — it’s by design. Since custom handlers are, well, <em>custom</em>, the platform can’t automatically know what to trace or how to label it.</p><p>This results in:</p><ul><li><strong>Incomplete latency traces</strong> in your observability platform</li><li><strong>Gaps in request flow visualization</strong> that make debugging harder</li><li><strong>Missing performance data</strong> for critical custom logic</li></ul><p>But here’s the good news: with a few strategic code additions, you can make your custom handlers fully observable.</p><h3>Understanding the Two Handler Types 📚</h3><p>Before we dive into the solution, let’s clarify the two types of handlers you might be working with:</p><h3>1. Synapse Handlers</h3><p>These are the gatekeepers of your API flow:</p><ul><li><strong>First to execute</strong> when a request arrives</li><li><strong>Last to execute</strong> before a response leaves</li><li>Handle four distinct flows: Request In, Request Out, Response In, Response Out</li><li>Traces inject under the main RESPONSE_LATENCY span</li></ul><h3>2. API Handlers</h3><p>These operate at the API resource level:</p><ul><li>Execute after Synapse handlers in the request flow</li><li>More granular control over specific API operations</li><li>Traces inject under the RESOURCE_SPAN for better categorization</li></ul><h3>The Solution: Injecting Custom Spans 💉</h3><p>The key to visibility is creating and managing trace spans within your handler code. Let’s break down the approach:</p><h3>Step 1: Create Helper Methods</h3><p>For any custom handler, you’ll need two essential methods:</p><pre>private void startHandlerSpan(MessageContext context)<br>private void finishHandlerSpan(MessageContext context)</pre><p>These methods will:</p><ol><li>Check if tracing is enabled (supporting both Telemetry and Legacy tracing)</li><li>Create a new span with a descriptive name</li><li>Attach it to the appropriate parent span</li><li>Store it in the message context for later retrieval</li></ol><h3>Step 2: Implement Synapse Handler Tracing</h3><p>Here’s how to make your Synapse handler observable:</p><pre>public class CustomSynapseHandler extends AbstractSynapseHandler {<br>    <br>    // Give your handler a unique, descriptive span name<br>    private static final String SPAN_NAME = &quot;Synapse_Handler:CustomSynapseHandler&quot;;<br>    <br>    public boolean handleRequestInFlow(MessageContext synCtx) {<br>        // Start tracing before your logic<br>        startHandlerSpan(synCtx);<br>        try {<br>            // Your custom handler logic here<br>            // This time is now being tracked!<br>            <br>            return true;<br>        } finally {<br>            // Always finish the span, even if exceptions occur<br>            finishHandlerSpan(synCtx);<br>        }<br>    }<br>    <br>    private void startHandlerSpan(MessageContext synCtx) {<br>        if (TelemetryUtil.telemetryEnabled()) {<br>            // Telemetry tracing implementation<br>            TelemetryTracer tracer = GatewayUtils.getTelemetryTracer();<br>            TelemetrySpan parentSpan = (TelemetrySpan) synCtx<br>                .getProperty(APIMgtGatewayConstants.RESPONSE_LATENCY);<br>            <br>            TelemetrySpan handlerSpan = TelemetryUtil.startSpan(<br>                SPAN_NAME, parentSpan, tracer<br>            );<br>            TelemetryUtil.setTag(handlerSpan, <br>                APIMgtGatewayConstants.SPAN_KIND, <br>                APIMgtGatewayConstants.SERVER<br>            );<br>            <br>            synCtx.setProperty(SPAN_NAME, handlerSpan);<br>            <br>        } else if (Util.tracingEnabled()) {<br>            // Legacy tracing implementation<br>            // Similar logic with TracingSpan instead<br>        }<br>    }<br>    <br>    private void finishHandlerSpan(MessageContext synCtx) {<br>        // Retrieve and finish the span<br>        if (TelemetryUtil.telemetryEnabled()) {<br>            TelemetrySpan span = (TelemetrySpan) synCtx.getProperty(SPAN_NAME);<br>            if (span != null) {<br>                TelemetryUtil.finishSpan(span);<br>            }<br>        }<br>        // Similar for legacy tracing<br>    }<br>}</pre><h3>Step 3: Implement API Handler Tracing</h3><p>API handlers follow the same pattern but with one key difference — they attach to the RESOURCE_SPAN:</p><pre>public class CustomApiHandler extends AbstractHandler {<br>    <br>    private static final String SPAN_NAME = &quot;API_Handler:CustomApiHandler&quot;;<br>    <br>    public boolean handleRequest(MessageContext msgCtx) {<br>        startHandlerSpan(msgCtx);<br>        try {<br>            // Your API handler logic<br>            return true;<br>        } finally {<br>            finishHandlerSpan(msgCtx);<br>        }<br>    }<br>    <br>    private void startHandlerSpan(MessageContext msgCtx) {<br>        if (TelemetryUtil.telemetryEnabled()) {<br>            TelemetryTracer tracer = GatewayUtils.getTelemetryTracer();<br>            // Note: Using RESOURCE_SPAN instead of RESPONSE_LATENCY<br>            TelemetrySpan parentSpan = (TelemetrySpan) msgCtx<br>                .getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);<br>            <br>            // Rest of the implementation is similar<br>        }<br>    }<br>}</pre><h3>Best Practices for Handler Tracing 🎯</h3><h3>1. Use Descriptive Span Names</h3><p>Make your spans easily identifiable:</p><pre>// Good<br>&quot;Synapse_Handler:RateLimitingHandler&quot;<br>&quot;API_Handler:CustomAuthenticationHandler&quot;<br><br>// Not so good<br>&quot;Handler1&quot;<br>&quot;CustomHandler&quot;</pre><h3>2. Always Use Try-Finally</h3><p>Ensure spans are closed even when exceptions occur:</p><pre>startHandlerSpan(context);<br>try {<br>    // Your logic<br>} finally {<br>    finishHandlerSpan(context);  // This always runs<br>}</pre><h3>3. Support Both Tracing Modes</h3><p>WSO2 APIM supports both Telemetry and Legacy tracing. Your code should handle both:</p><pre>if (TelemetryUtil.telemetryEnabled()) {<br>    // Telemetry implementation<br>} else if (Util.tracingEnabled()) {<br>    // Legacy tracing implementation<br>}</pre><h3>4. Add Meaningful Tags</h3><p>Enhance your spans with contextual information:</p><pre>TelemetryUtil.setTag(handlerSpan, &quot;handler.type&quot;, &quot;authentication&quot;);<br>TelemetryUtil.setTag(handlerSpan, &quot;api.name&quot;, apiName);</pre><h3>The Result: Complete Observability 📊</h3><p>After implementing these changes, your observability platform will show:</p><ul><li><strong>Complete request flow</strong> with no mysterious gaps</li><li><strong>Accurate latency attribution</strong> showing exactly where time is spent</li><li><strong>Handler-specific metrics</strong> that help identify bottlenecks</li><li><strong>Better debugging capabilities</strong> with full trace context</li></ul><p>Your traces will transform from this:</p><pre>[Gateway Entry] → [???Gap???] → [Backend Call] → [???Gap???] → [Response]</pre><p>To this:</p><pre>[Gateway Entry] → [CustomSynapseHandler: 15ms] → [CustomApiHandler: 8ms] → <br>[Backend Call: 200ms] → [Response Transform: 5ms] → [Response]</pre><h3>Common Pitfalls to Avoid ⚠️</h3><ol><li><strong>Don’t forget the parent span reference</strong>: Synapse handlers use RESPONSE_LATENCY, API handlers use RESOURCE_SPAN</li><li><strong>Always check for null spans</strong> before finishing them</li><li><strong>Use unique span names</strong> to avoid property conflicts in the message context</li><li><strong>Test with both tracing modes</strong> enabled and disabled</li></ol><h3>Conclusion: No More Blind Spots 🎉</h3><p>Custom handlers no longer need to be black boxes in your API infrastructure. With these simple additions to your handler code, you gain complete visibility into every millisecond of your API request lifecycle.</p><p>The next time you’re investigating a performance issue or optimizing your API gateway, you’ll have the full picture — no gaps, no mysteries, just clear, actionable data.</p><p>Remember: <strong>What you can’t measure, you can’t improve.</strong> Now you can measure everything.</p><h3>Quick Reference Code Snippets 📝</h3><p>To make it easier to get started, I’ve added <strong>ready-to-use sample implementations</strong> in my GitHub repository that you can directly adapt to your setup:</p><p>👉 <strong>Sample code repository:</strong><br><a href="https://github.com/Abshan/blog-samples/tree/main/trace-injector-samples">https://github.com/Abshan/blog-samples/tree/main/trace-injector-samples</a></p><p>The repository includes:</p><ul><li><strong>Synapse Handler examples</strong> showing how to start and finish tracing spans using startHandlerSpan and finishHandlerSpan</li><li><strong>API Handler samples</strong> demonstrating the same tracing approach applied at the API layer</li></ul><p>Follow me for more WSO2 APIM tips, deep dives, and hands-on guidance to improve observability and performance across your API management infrastructure.</p><p>#WSO2 #APIManagement #Observability #Performance #Tracing #OpenTelemetry</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68065fc6c82b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>