feat: publish application permissions to DDS grants
This commit is contained in:
@@ -14,7 +14,8 @@ public record DdsProperties(
|
||||
String pgObject,
|
||||
String myObject,
|
||||
String vectorObject,
|
||||
Map<String, User> users
|
||||
Map<String, User> users,
|
||||
Map<String, String> objectMappings
|
||||
) {
|
||||
|
||||
private static final Pattern OBJECT_NAME = Pattern.compile(
|
||||
@@ -37,6 +38,15 @@ public record DdsProperties(
|
||||
});
|
||||
}
|
||||
users = Map.copyOf(normalizedUsers);
|
||||
var normalizedMappings = new LinkedHashMap<String, String>();
|
||||
if (objectMappings != null) {
|
||||
objectMappings.forEach((key, value) -> {
|
||||
if (key != null && value != null && !key.isBlank() && !value.isBlank()) {
|
||||
normalizedMappings.put(key.trim().toUpperCase(), normalizeObject(value, ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
objectMappings = Map.copyOf(normalizedMappings);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +62,19 @@ public record DdsProperties(
|
||||
Map<String, User> users
|
||||
) {
|
||||
this(dbUrl, queryTimeout, pgObject, myObject,
|
||||
"ADMIN.CB_DDS_VECTOR_SEARCH_DOCUMENTS", users);
|
||||
"ADMIN.CB_DDS_VECTOR_SEARCH_DOCUMENTS", users, Map.of(
|
||||
"CB_VECTOR_SEARCH_DOCUMENTS", "ADMIN.CB_DDS_VECTOR_SEARCH_DOCUMENTS"));
|
||||
}
|
||||
|
||||
public DdsProperties(
|
||||
String dbUrl,
|
||||
Duration queryTimeout,
|
||||
String pgObject,
|
||||
String myObject,
|
||||
String vectorObject,
|
||||
Map<String, User> users
|
||||
) {
|
||||
this(dbUrl, queryTimeout, pgObject, myObject, vectorObject, users, Map.of());
|
||||
}
|
||||
|
||||
public String objectFor(String sourceKey) {
|
||||
@@ -73,11 +95,37 @@ public record DdsProperties(
|
||||
return candidate.toUpperCase();
|
||||
}
|
||||
|
||||
public record User(String label, String description, String username, String password) {
|
||||
public record User(
|
||||
String label,
|
||||
String description,
|
||||
String username,
|
||||
String password,
|
||||
long applicationUserId,
|
||||
String dataRole
|
||||
) {
|
||||
|
||||
/**
|
||||
* Keep the six-field constructor as the configuration binding target.
|
||||
* The four-field overload below exists only for the small query-service
|
||||
* tests and older local callers; without an explicit binding marker,
|
||||
* Spring Boot can select that overload and silently leave the application
|
||||
* user/data-role mapping at its default values.
|
||||
*/
|
||||
@ConstructorBinding
|
||||
public User {
|
||||
}
|
||||
|
||||
public User(String label, String description, String username, String password) {
|
||||
this(label, description, username, password, 0L, "");
|
||||
}
|
||||
|
||||
public boolean configured() {
|
||||
return username != null && !username.isBlank()
|
||||
&& password != null && !password.isBlank();
|
||||
}
|
||||
|
||||
public boolean mapped() {
|
||||
return applicationUserId > 0 && dataRole != null && !dataRole.isBlank();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user