refs #739: unify Smilegate game target planning

This commit is contained in:
devmrko
2026-07-28 10:09:12 +09:00
parent 57f6677afb
commit d13d6d48ca
9 changed files with 664 additions and 138 deletions

View File

@@ -16,6 +16,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.stereotype.Service;
@@ -109,6 +110,16 @@ public class GameScopeService {
* name is embedded in application code.
*/
public boolean referencesGameScopedObject(String bearerToken, String sql) {
return referencesGameScopedObjectOutsidePrefixes(bearerToken, sql, Set.of());
}
/**
* Returns true when SQL references a DB-declared game-prefix object whose
* prefix is not present in the authoritative query plan.
*/
public boolean referencesGameScopedObjectOutsidePrefixes(
String bearerToken, String sql, Set<String> allowedPrefixes
) {
requireActiveToken(bearerToken);
if (!gameScopeProperties.configured() || sql == null || sql.isBlank()) {
return false;
@@ -124,11 +135,17 @@ public class GameScopeService {
statement.setString(1, selectAi.profile());
try (ResultSet rows = statement.executeQuery()) {
String normalizedSql = sql.toUpperCase(Locale.ROOT);
Set<String> normalizedAllowed = allowedPrefixes == null ? Set.of()
: allowedPrefixes.stream()
.filter(value -> value != null && !value.isBlank())
.map(value -> value.trim().toUpperCase(Locale.ROOT))
.collect(java.util.stream.Collectors.toUnmodifiableSet());
while (rows.next()) {
String prefix = rows.getString("GAME_PREFIX");
if (prefix != null && Pattern.compile(
"(?<![A-Z0-9_$#])" + Pattern.quote(prefix.toUpperCase(Locale.ROOT))
+ "_[A-Z0-9_$#]+(?![A-Z0-9_$#])").matcher(normalizedSql).find()) {
+ "_[A-Z0-9_$#]+(?![A-Z0-9_$#])").matcher(normalizedSql).find()
&& !normalizedAllowed.contains(prefix.toUpperCase(Locale.ROOT))) {
return true;
}
}