Skip to content

Traceable MDC display of JwtPrincipal #54

@andrus

Description

@andrus

It is helpful to identify request users in app logs using SLF4J MDC. Currently, the mechanism is generic and also rather blind. Since "principal" is an Object, the MDC handler simply calls principal.toString():

// in PrincipalMDC.java

MDC.put(MDC_KEY, String.valueOf(principal));

In case of JwtPrincipal, toString() returns sub claim, which is pretty universal and stable for each client or user token. But it is often not traceable back to the actual account (at least with MS Entra IDP), making logs much less useful. Would be great to have a custom mechanism for MDC identifier extraction out of JWTs.

Perhaps let's do the same thing we did for roles - a custom parser factory:

shirojwt:
   trustedServers:
      s1:
        roles:
           type: jsonList
           claim: roles

In case of MDC config, it might look like:

shirojwt:
   trustedServers:
      s1:
        principalId:
           type: myIdExtractor # the default would be "sub" claim

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions