public class PrincipalExtractor
extends java.lang.Object
First a claim configured as usernameClaim is looked up.
If found, and the usernamePrefix is configured, it is prepended to the value of the claim.
If not found, the claim configured as fallbackUsernameClaim is looked up. If that one is found and if
the fallbackUsernamePrefix is configured prefix the found value with the prefix, otherwise not.
The claim specification uses the following rules:
A JsonPath query is resolved relative to JSON object containing info to identify user (a JWT payload, a response from Introspection Endpoint or a response from User Info Endpoint).
For more on JsonPath syntax see https://github.com/json-path/JsonPath.
Examples of claim specification:
userId ... use top level attribute named 'userId'
user.id ... use top level attribute named 'user.id'
$userid ... use top level attribute named '$userid'
['userInfo']['id'] ... use nested attribute 'id' under 'userInfo' top level attribute
['userInfo'].id ... use nested attribute 'id' under 'userInfo' top level attribute (second segment not using brackets)
['user.info']['user.id'] ... use nested attribute 'user.id' under 'user.info' top level attribute
['user.info'].['user.id'] ... use nested attribute 'user.id' under 'user.info' top level attribute (optional dot)
See PrincipalExtractorTest.java for more working and non-working examples of claim specification.| Constructor and Description |
|---|
PrincipalExtractor()
Create a new instance
|
PrincipalExtractor(java.lang.String usernameClaim)
Create a new instance
|
PrincipalExtractor(java.lang.String usernameClaim,
java.lang.String usernamePrefix,
java.lang.String fallbackUsernameClaim,
java.lang.String fallbackUsernamePrefix)
Create a new instance
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getPrincipal(com.fasterxml.jackson.databind.JsonNode json)
Get the principal name
|
java.lang.String |
getSub(com.fasterxml.jackson.databind.JsonNode json)
Get the value of
sub claim |
boolean |
isConfigured()
Return true if any of the configuration options is configured
|
java.lang.String |
toString() |
public PrincipalExtractor()
public PrincipalExtractor(java.lang.String usernameClaim)
usernameClaim - Attribute name for an attribute containing the user id to lookup first.public PrincipalExtractor(java.lang.String usernameClaim,
java.lang.String usernamePrefix,
java.lang.String fallbackUsernameClaim,
java.lang.String fallbackUsernamePrefix)
usernameClaim - Attribute name for an attribute containing the user id to lookup first.usernamePrefix - A prefix to prepend to the user idfallbackUsernameClaim - Attribute name for an attribute containg the user id to lookup as a fallbackfallbackUsernamePrefix - A prefix to prepend to the value of the fallback attribute value if setpublic java.lang.String getPrincipal(com.fasterxml.jackson.databind.JsonNode json)
json - JWT token as a JsonNode objectpublic java.lang.String getSub(com.fasterxml.jackson.databind.JsonNode json)
sub claimjson - JWT token as a JsonNode objectsub attributepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean isConfigured()
Copyright © 2024. All rights reserved.