File tree 2 files changed +17
-0
lines changed
src/main/java/info/unterrainer/commons/httpserver
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 8
8
import java .net .http .HttpRequest ;
9
9
import java .net .http .HttpResponse .BodyHandlers ;
10
10
import java .security .PublicKey ;
11
+ import java .util .HashSet ;
11
12
import java .util .Set ;
12
13
import java .util .function .Consumer ;
13
14
@@ -170,6 +171,7 @@ private TokenVerifier<AccessToken> persistUserInfoInContext(final Context ctx) {
170
171
171
172
String tenant = (String ) token .getOtherClaims ().get ("tenant" );
172
173
ctx .attribute (Attribute .USER_CLIENT_ATTRIBUTE_TENANT , tenant );
174
+ ctx .attribute (Attribute .USER_TENANT_SET , createTenantSetFrom (tenant ));
173
175
174
176
Set <String > clientRoles = Set .of ();
175
177
String key = token .getIssuedFor ();
@@ -215,6 +217,20 @@ private TokenVerifier<AccessToken> persistUserInfoInContext(final Context ctx) {
215
217
}
216
218
}
217
219
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
+
218
234
private void setTokenRejectionReason (final Context ctx , final String reason ) {
219
235
ctx .attribute (Attribute .KEYCLOAK_TOKEN_REJECTION_REASON , reason );
220
236
}
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public class Attribute {
16
16
public static final String USER_CLIENT_ROLES = "user_client_roles" ;
17
17
public static final String USER_REALM_ROLES = "user_realm_roles" ;
18
18
public static final String USER_CLIENT_ATTRIBUTE_TENANT = "user_client_attribute_tenant" ;
19
+ public static final String USER_TENANT_SET = "user_tenant_set" ;
19
20
20
21
public static final String KEYCLOAK_TOKEN_REJECTION_REASON = "kc_token_rejection_reason" ;
21
22
}
You can’t perform that action at this time.
0 commit comments