fix(security): accept overseas token subject identity
This commit is contained in:
+3
@@ -35,6 +35,9 @@ public final class GatewayAccessTokenSessionValidator implements AccessTokenSess
|
|||||||
throw new IllegalArgumentException("Untrusted overseas gateway authorization context");
|
throw new IllegalArgumentException("Untrusted overseas gateway authorization context");
|
||||||
}
|
}
|
||||||
Long userId = number(jwt.getClaims().getOrDefault("userId", jwt.getClaims().get("user_id")));
|
Long userId = number(jwt.getClaims().getOrDefault("userId", jwt.getClaims().get("user_id")));
|
||||||
|
if (userId == null) {
|
||||||
|
userId = number(jwt.getSubject());
|
||||||
|
}
|
||||||
return new AccessTokenSession(1, userId, values(request.getHeader(ROLES_HEADER)),
|
return new AccessTokenSession(1, userId, values(request.getHeader(ROLES_HEADER)),
|
||||||
values(request.getHeader(AUTHORITIES_HEADER)));
|
values(request.getHeader(AUTHORITIES_HEADER)));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ class GatewayAccessTokenSessionValidatorTest {
|
|||||||
private Jwt jwt() {
|
private Jwt jwt() {
|
||||||
return Jwt.withTokenValue("small-overseas-token").header("alg", "RS256").subject("42")
|
return Jwt.withTokenValue("small-overseas-token").header("alg", "RS256").subject("42")
|
||||||
.issuedAt(Instant.now()).expiresAt(Instant.now().plusSeconds(300))
|
.issuedAt(Instant.now()).expiresAt(Instant.now().plusSeconds(300))
|
||||||
.claim("user_id", 42L).claim("tenant_id", 0L).claim("app_code", "PLATFORM")
|
.claim("tenant_id", 0L).claim("app_code", "PLATFORM")
|
||||||
.claim("permission_version", 7L).claim("token_version", 1).build();
|
.claim("permission_version", 7L).claim("token_version", 1).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user