Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/prerna/semoss/web/services/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public record ServerConfig(@Schema(description = "Whether R is enabled", require
@Schema(description = "Whether only admins may give access to functions", requiredMode = REQUIRED) boolean adminOnlyFunctionAddAccess,
@Schema(description = "Whether only admins may make functions public", requiredMode = REQUIRED) boolean adminOnlyFunctionSetPublic,
@Schema(description = "Whether only admins may make functions discoverable", requiredMode = REQUIRED) boolean adminOnlyFunctionSetDiscoverable,
@Schema(description = "Whether only admins may add guardrails", requiredMode = REQUIRED) boolean adminOnlyGuardrailAdd,
@Schema(description = "Whether only admins may delete guardrails", requiredMode = REQUIRED) boolean adminOnlyGuardrailDelete,
@Schema(description = "Whether only admins may give access to guardrails", requiredMode = REQUIRED) boolean adminOnlyGuardrailAddAccess,
@Schema(description = "Whether only admins may make guardrails public", requiredMode = REQUIRED) boolean adminOnlyGuardrailSetPublic,
@Schema(description = "Whether only admins may make guardrails discoverable", requiredMode = REQUIRED) boolean adminOnlyGuardrailSetDiscoverable,
@Schema(description = "Whether only admins may give access to insights", requiredMode = REQUIRED) boolean adminOnlyInsightAddAccess,
@Schema(description = "Whether only admins may make insights public", requiredMode = REQUIRED) boolean adminOnlyInsightSetPublic,
@Schema(description = "Whether only admins may share insights", requiredMode = REQUIRED) boolean adminOnlyInsightShare,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ private static void loadConfig() {
loadConfig.put("adminOnlyFunctionAddAccess", AbstractSecurityUtils.adminOnlyFunctionAddAccess());
loadConfig.put("adminOnlyFunctionSetPublic", AbstractSecurityUtils.adminOnlyFunctionSetPublic());
loadConfig.put("adminOnlyFunctionSetDiscoverable", AbstractSecurityUtils.adminOnlyFunctionSetDiscoverable());
loadConfig.put("adminOnlyGuardrailAdd", AbstractSecurityUtils.adminOnlyGuardrailAdd());
loadConfig.put("adminOnlyGuardrailDelete", AbstractSecurityUtils.adminOnlyGuardrailDelete());
loadConfig.put("adminOnlyGuardrailAddAccess", AbstractSecurityUtils.adminOnlyGuardrailAddAccess());
loadConfig.put("adminOnlyGuardrailSetPublic", AbstractSecurityUtils.adminOnlyGuardrailSetPublic());
loadConfig.put("adminOnlyGuardrailSetDiscoverable", AbstractSecurityUtils.adminOnlyGuardrailSetDiscoverable());
// admin only for insight actions
loadConfig.put("adminOnlyInsightAddAccess", AbstractSecurityUtils.adminOnlyInsightAddAccess());
loadConfig.put("adminOnlyInsightSetPublic", AbstractSecurityUtils.adminOnlyInsightSetPublic());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import prerna.auth.access.GranteePermissionQuery;
import prerna.auth.utils.EffectivePermissionUtils;
import prerna.auth.utils.SecurityAccessPermissionBatchUtils;
import prerna.auth.utils.SecurityAdminUtils;
Expand Down Expand Up @@ -81,6 +82,41 @@ public Response savePermissionBatches(@Context HttpServletRequest request) {
.saveBatches(adminUtils, user, SecurityAccessPermissionBatchUtils.readBatches(batches)));
}

/**
* Every permission any engine or project gives an app, an agent or an engine,
* in admin mode, each one changeable.
*
* @param search text the name or id of the target or grantee contains
* @param targetKind PROJECT or ENGINE, what gives the permission, or none for
* either
* @param targetType the target's type: a project's type, such as SKILL, or an
* engine's catalog type, such as MODEL
* @param granteeKind PROJECT or ENGINE, what is given the permission, or none
* for either
* @param granteeType the grantee's type in the same way, such as WORKSPACE
* @param limit how many to return; none or 0 for all
* @param offset how many to skip
* @return the page and how many match; 400 for a kind that is neither
*/
@GET
@Produces("application/json")
@Path("/getAllGranteePermissions")
public Response getAllGranteePermissions(@Context HttpServletRequest request, @QueryParam("search") String search,
@QueryParam("targetKind") String targetKind, @QueryParam("targetType") String targetType,
@QueryParam("granteeKind") String granteeKind, @QueryParam("granteeType") String granteeType,
@QueryParam("limit") int limit, @QueryParam("offset") int offset) {
String searchTerm = WebUtility.inputSanitizer(search);
String targetKindName = WebUtility.inputSanitizer(targetKind);
String target = WebUtility.inputSanitizer(targetType);
String granteeKindName = WebUtility.inputSanitizer(granteeKind);
String grantee = WebUtility.inputSanitizer(granteeType);
return ResourceUtility.respondAsAdmin(request, "list every permission engines and projects give as an admin",
SecurityAdminUtils::getInstance,
(user, adminUtils) -> SecurityAccessPermissionBatchUtils.getAllGranteePermissions(adminUtils, user,
new GranteePermissionQuery(searchTerm, targetKindName, target, granteeKindName, grantee, limit,
offset)));
}

/**
* Who can use a project or an engine now, or who is in or manages a custom
* group.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,86 @@ private static Map<String, Object> success() {
return ret;
}

/**
* Lists the apps, agents and engines a project gives a permission to, in admin
* mode.
*
* @param request the request, whose session holds the admin
* @param projectId the project
* @return one entry for each app and engine, with its id, catalog type
* ({@code PROJECT} for an app or an agent), name and subtype, and its
* level and end date; 403 for a user who is not an admin
*/
@GET
@Produces("application/json")
@Path("getProjectGranteePermissions")
public Response getProjectGranteePermissions(@Context HttpServletRequest request,
@QueryParam("projectId") String projectId) {
String id = WebUtility.inputSanitizer(projectId);
return ResourceUtility.respondAsAdmin(request,
"list the apps and engines project " + id + " gives a permission to", SecurityAdminUtils::getInstance,
(user, adminUtils) -> adminUtils.getProjectGranteePermissions(id));
}

/**
* Gives an app or an agent a permission on any project, or changes the one it
* has, in admin mode. A project gives access to apps and agents only.
*
* @param request the request, whose session holds the admin
* @param form {@code projectId}, {@code granteeEngineId},
* {@code granteeEngineType} ({@code PROJECT}),
* {@code permission} (READ_ONLY or EDIT), and optionally
* {@code endDate}
* @return 200 when the permission is saved, 400 with the reason when it cannot
* be, and 403 for a user who is not an admin
*/
@POST
@Produces("application/json")
@Path("setProjectGranteePermission")
public Response setProjectGranteePermission(@Context HttpServletRequest request,
MultivaluedMap<String, String> form) {
String projectId = WebUtility.inputSanitizer(form.getFirst("projectId"));
String granteeEngineId = WebUtility.inputSanitizer(form.getFirst("granteeEngineId"));
String granteeEngineType = WebUtility.inputSanitizer(form.getFirst("granteeEngineType"));
String permission = WebUtility.inputSanitizer(form.getFirst("permission"));
String endDate = WebUtility.inputSanitizer(form.getFirst("endDate"));
String action = "give " + granteeEngineType + " " + granteeEngineId + " " + permission + " access to project "
+ projectId;
return ResourceUtility.respondAsAdmin(request, action, SecurityAdminUtils::getInstance, (user, adminUtils) -> {
String level = AccessPermissionEnum.require(permission);
adminUtils.setProjectGranteePermission(granteeEngineId, granteeEngineType, projectId, level, user, endDate);
Map<String, Object> ret = new HashMap<>();
ret.put("success", true);
return ret;
});
}

/**
* Takes away the permission a project gives an app, an agent or an engine, in
* admin mode.
*
* @param request the request, whose session holds the admin
* @param form {@code projectId}, {@code granteeEngineId} and
* {@code granteeEngineType}
* @return 200 when the permission is taken away, 400 with the reason when it
* cannot be, and 403 for a user who is not an admin
*/
@POST
@Produces("application/json")
@Path("removeProjectGranteePermission")
public Response removeProjectGranteePermission(@Context HttpServletRequest request,
MultivaluedMap<String, String> form) {
String projectId = WebUtility.inputSanitizer(form.getFirst("projectId"));
String granteeEngineId = WebUtility.inputSanitizer(form.getFirst("granteeEngineId"));
String granteeEngineType = WebUtility.inputSanitizer(form.getFirst("granteeEngineType"));
String action = "take away the access of " + granteeEngineType + " " + granteeEngineId + " to project "
+ projectId;
return ResourceUtility.respondAsAdmin(request, action, SecurityAdminUtils::getInstance, (user, adminUtils) -> {
adminUtils.removeProjectGranteePermission(granteeEngineId, granteeEngineType, projectId, user);
Map<String, Object> ret = new HashMap<>();
ret.put("success", true);
return ret;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import prerna.auth.access.GranteePermissionQuery;
import prerna.auth.access.PermissionTargetResource;
import prerna.auth.utils.EffectivePermissionUtils;
import prerna.auth.utils.SecurityAccessPermissionBatchUtils;
Expand Down Expand Up @@ -104,6 +105,43 @@ public Response getPermissions(@Context HttpServletRequest request, @QueryParam(
user -> SecurityAccessPermissionBatchUtils.getPermissions(user, toTarget(resourceType, resource)));
}

/**
* Every permission an engine or a project gives an app, an agent or an engine,
* on the engines and projects the signed in user can edit, for the page that
* lists them all. Each entry has its {@code target}, {@code subject},
* {@code access} and {@code canChange}, true for the target's owners.
*
* @param search text the name or id of the target or grantee contains
* @param targetKind PROJECT or ENGINE, what gives the permission, or none for
* either
* @param targetType the target's type: a project's type, such as SKILL, or an
* engine's catalog type, such as MODEL
* @param granteeKind PROJECT or ENGINE, what is given the permission, or none
* for either
* @param granteeType the grantee's type in the same way, such as WORKSPACE
* @param limit how many to return; none or 0 for all
* @param offset how many to skip
* @return the page and how many match; 400 for a kind that is neither
*/
@GET
@Produces("application/json")
@Path("/getAllGranteePermissions")
public Response getAllGranteePermissions(@Context HttpServletRequest request, @QueryParam("search") String search,
@QueryParam("targetKind") String targetKind, @QueryParam("targetType") String targetType,
@QueryParam("granteeKind") String granteeKind, @QueryParam("granteeType") String granteeType,
@QueryParam("limit") int limit, @QueryParam("offset") int offset) {
String searchTerm = WebUtility.inputSanitizer(search);
String targetKindName = WebUtility.inputSanitizer(targetKind);
String target = WebUtility.inputSanitizer(targetType);
String granteeKindName = WebUtility.inputSanitizer(granteeKind);
String grantee = WebUtility.inputSanitizer(granteeType);
return ResourceUtility
.respond(request, "list the permissions engines and projects give",
user -> SecurityAccessPermissionBatchUtils.getAllGranteePermissions(user,
new GranteePermissionQuery(searchTerm, targetKindName, target, granteeKindName, grantee,
limit, offset)));
}

/**
* The people to copy from a project, engine or custom group into another, with
* the access each has on both.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,92 @@ private static String textOf(Object value) {
return value == null ? null : value.toString();
}

/**
* Lists the apps, agents and engines a project gives a permission to. An app's
* custom reactors, an agent's runs, or an engine's own code, use the permission
* in place of the signed in user's own. The project's editors and owners list
* them.
*
* @param request the request, whose session holds the user
* @param projectId the project
* @return one entry for each app and engine, with its id, catalog type
* ({@code PROJECT} for an app or an agent), name and subtype, and its
* level and end date; 403 for a user who cannot edit the project
*/
@GET
@Produces("application/json")
@Path("getProjectGranteePermissions")
public Response getProjectGranteePermissions(@Context HttpServletRequest request,
@QueryParam("projectId") String projectId) {
String id = WebUtility.inputSanitizer(projectId);
return ResourceUtility.respond(request, "list the apps and engines project " + id + " gives a permission to",
user -> SecurityProjectUtils.getProjectGranteePermissions(user, id));
}

/**
* Gives an app or an agent a permission on a project, or changes the one it
* has, so an app's custom reactors or an agent's runs can use the project for
* people who have no access to it. A project gives access to apps and agents
* only. Only the project's owners can.
*
* @param request the request, whose session holds the user
* @param form {@code projectId}, {@code granteeEngineId},
* {@code granteeEngineType} ({@code PROJECT}),
* {@code permission} (READ_ONLY or EDIT), and optionally
* {@code endDate}
* @return 200 when the permission is saved, 400 with the reason when it cannot
* be, and 403 for a user who is not an owner of the project
*/
@POST
@Produces("application/json")
@Path("setProjectGranteePermission")
public Response setProjectGranteePermission(@Context HttpServletRequest request,
MultivaluedMap<String, String> form) {
String projectId = WebUtility.inputSanitizer(form.getFirst("projectId"));
String granteeEngineId = WebUtility.inputSanitizer(form.getFirst("granteeEngineId"));
String granteeEngineType = WebUtility.inputSanitizer(form.getFirst("granteeEngineType"));
String permission = WebUtility.inputSanitizer(form.getFirst("permission"));
String endDate = WebUtility.inputSanitizer(form.getFirst("endDate"));
String action = "give " + granteeEngineType + " " + granteeEngineId + " " + permission + " access to project "
+ projectId;
return ResourceUtility.respond(request, action, user -> {
String level = AccessPermissionEnum.require(permission);
SecurityProjectUtils.setProjectGranteePermission(user, granteeEngineId, granteeEngineType, projectId, level,
endDate);
Map<String, Object> ret = new HashMap<>();
ret.put("success", true);
return ret;
});
}

/**
* Takes away the permission a project gives an app, an agent or an engine. Only
* the project's owners can.
*
* @param request the request, whose session holds the user
* @param form {@code projectId}, {@code granteeEngineId} and
* {@code granteeEngineType}
* @return 200 when the permission is taken away, 400 with the reason when it
* cannot be, and 403 for a user who is not an owner of the project
*/
@POST
@Produces("application/json")
@Path("removeProjectGranteePermission")
public Response removeProjectGranteePermission(@Context HttpServletRequest request,
MultivaluedMap<String, String> form) {
String projectId = WebUtility.inputSanitizer(form.getFirst("projectId"));
String granteeEngineId = WebUtility.inputSanitizer(form.getFirst("granteeEngineId"));
String granteeEngineType = WebUtility.inputSanitizer(form.getFirst("granteeEngineType"));
String action = "take away the access of " + granteeEngineType + " " + granteeEngineId + " to project "
+ projectId;
return ResourceUtility.respond(request, action, user -> {
SecurityProjectUtils.removeProjectGranteePermission(user, granteeEngineId, granteeEngineType, projectId);
Map<String, Object> ret = new HashMap<>();
ret.put("success", true);
return ret;
});
}

/**
* Refuses a user who cannot edit the project. Propagating a project's
* permissions gives people access to everything it depends on, so it is limited
Expand Down
Loading
Loading