Skip to content

Commit 2865962

Browse files
author
Gerald Unterrainer
committed
Merge branch 'develop'
2 parents b42be57 + b6a3bab commit 2865962

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<modelVersion>4.0.0</modelVersion>
1717
<artifactId>http-server</artifactId>
18-
<version>0.3.9</version>
18+
<version>0.3.10</version>
1919
<name>HttpServer</name>
2020
<packaging>jar</packaging>
2121

src/main/java/info/unterrainer/commons/httpserver/accessmanager/HttpAccessManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ private TokenVerifier<AccessToken> persistUserInfoInContext(final Context ctx) {
171171
String readTenants = (String) token.getOtherClaims().get("tenants_read");
172172
ctx.attribute(Attribute.USER_CLIENT_ATTRIBUTE_TENANTS_READ, readTenants);
173173
ctx.attribute(Attribute.USER_TENANTS_READ_SET, createTenantSetFrom(readTenants));
174+
ctx.attribute(Attribute.USER_TENANT_READ, getFirstTenantFrom(readTenants));
174175

175176
String writeTenants = (String) token.getOtherClaims().get("tenants_write");
176177
ctx.attribute(Attribute.USER_CLIENT_ATTRIBUTE_TENANTS_WRITE, writeTenants);
177178
ctx.attribute(Attribute.USER_TENANTS_WRITE_SET, createTenantSetFrom(writeTenants));
179+
ctx.attribute(Attribute.USER_TENANT_WRITE, getFirstTenantFrom(writeTenants));
178180

179181
Set<String> clientRoles = Set.of();
180182
String key = token.getIssuedFor();
@@ -240,6 +242,23 @@ private Object createTenantSetFrom(final String tenant) {
240242
return tenantSet;
241243
}
242244

245+
private Long getFirstTenantFrom(final String tenant) {
246+
if (tenant == null || tenant.isBlank())
247+
return null;
248+
249+
String[] tenants = tenant.split(",");
250+
for (String t : tenants) {
251+
if (t.isBlank())
252+
continue;
253+
try {
254+
return Long.parseLong(t.trim());
255+
} catch (NumberFormatException e) {
256+
// NOOP
257+
}
258+
}
259+
return null;
260+
}
261+
243262
private void setTokenRejectionReason(final Context ctx, final String reason) {
244263
ctx.attribute(Attribute.KEYCLOAK_TOKEN_REJECTION_REASON, reason);
245264
}

src/main/java/info/unterrainer/commons/httpserver/enums/Attribute.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Attribute {
2222
public static final String USER_CLIENT_ATTRIBUTE_TENANTS_WRITE = "user_client_attribute_tenants_write";
2323
public static final String USER_TENANTS_READ_SET = "user_tenant_read_set";
2424
public static final String USER_TENANTS_WRITE_SET = "user_tenant_write_set";
25+
public static final String USER_TENANT_READ = "user_tenant_read";
26+
public static final String USER_TENANT_WRITE = "user_tenant_write";
2527

2628
public static final String KEYCLOAK_TOKEN_REJECTION_REASON = "kc_token_rejection_reason";
2729
}

src/main/java/info/unterrainer/commons/httpserver/extensions/AsyncExtensionContextBaseMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public AsyncExtensionContext map(final Context ctx, final AsyncExtensionContext
1111
asyncCtx.addParameter(ctx, Attribute.USER_CLIENT_ATTRIBUTE_TENANTS_WRITE);
1212
asyncCtx.addParameter(ctx, Attribute.USER_TENANTS_READ_SET);
1313
asyncCtx.addParameter(ctx, Attribute.USER_TENANTS_WRITE_SET);
14+
asyncCtx.addParameter(ctx, Attribute.USER_TENANT_READ);
15+
asyncCtx.addParameter(ctx, Attribute.USER_TENANT_WRITE);
1416
asyncCtx.addParameter(ctx, Attribute.JAVALIN_SERVER);
1517
asyncCtx.addParameter(ctx, Attribute.RESPONSE_OBJECT);
1618
asyncCtx.addParameter(ctx, Attribute.RESPONSE_STATUS);

0 commit comments

Comments
 (0)