File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
src/main/java/info/unterrainer/commons/httpserver Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 88import java .net .http .HttpRequest ;
99import java .net .http .HttpResponse .BodyHandlers ;
1010import java .security .PublicKey ;
11+ import java .util .HashSet ;
1112import java .util .Set ;
1213import java .util .function .Consumer ;
1314
@@ -170,6 +171,7 @@ private TokenVerifier<AccessToken> persistUserInfoInContext(final Context ctx) {
170171
171172 String tenant = (String ) token .getOtherClaims ().get ("tenant" );
172173 ctx .attribute (Attribute .USER_CLIENT_ATTRIBUTE_TENANT , tenant );
174+ ctx .attribute (Attribute .USER_TENANT_SET , createTenantSetFrom (tenant ));
173175
174176 Set <String > clientRoles = Set .of ();
175177 String key = token .getIssuedFor ();
@@ -215,6 +217,20 @@ private TokenVerifier<AccessToken> persistUserInfoInContext(final Context ctx) {
215217 }
216218 }
217219
220+ private Object createTenantSetFrom (final String tenant ) {
221+ Set <String > tenantSet = new HashSet <>();
222+ if (tenant == null || tenant .isBlank ())
223+ return tenantSet ;
224+
225+ String [] tenants = tenant .split ("," );
226+ for (String t : tenants ) {
227+ if (t .isBlank ())
228+ continue ;
229+ tenantSet .add (t .trim ());
230+ }
231+ return tenantSet ;
232+ }
233+
218234 private void setTokenRejectionReason (final Context ctx , final String reason ) {
219235 ctx .attribute (Attribute .KEYCLOAK_TOKEN_REJECTION_REASON , reason );
220236 }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public class Attribute {
1616 public static final String USER_CLIENT_ROLES = "user_client_roles" ;
1717 public static final String USER_REALM_ROLES = "user_realm_roles" ;
1818 public static final String USER_CLIENT_ATTRIBUTE_TENANT = "user_client_attribute_tenant" ;
19+ public static final String USER_TENANT_SET = "user_tenant_set" ;
1920
2021 public static final String KEYCLOAK_TOKEN_REJECTION_REASON = "kc_token_rejection_reason" ;
2122}
You can’t perform that action at this time.
0 commit comments