Repository navigation
Expand file tree
/
Copy pathAdminPermissionBatchResource.java
More file actions
196 lines (186 loc) · 9.04 KB
/
Copy pathAdminPermissionBatchResource.java
File metadata and controls
196 lines (186 loc) · 9.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*******************************************************************************
* Copyright 2015 Defense Health Agency (DHA)
*
* If your use of this software does not include any GPLv2 components:
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ----------------------------------------------------------------------------
* If your use of this software includes any GPLv2 components:
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*******************************************************************************/
package prerna.semoss.web.services.local.auth;
import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
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;
import prerna.semoss.web.services.local.ResourceUtility;
import prerna.web.services.util.WebUtility;
/**
* Bulk Access Management in admin mode: the same calls as
* {@link PermissionBatchResource}, apart from reading the signed in person's
* own usage limits, for admins only, where an admin can change and read any
* project, engine, insight or custom group whatever their own access. The admin
* check runs once, and the admin utilities it returns prove it to
* {@link SecurityAccessPermissionBatchUtils}.
*/
@Path("/auth/admin/permissionBatch")
@PermitAll
public class AdminPermissionBatchResource {
/**
* Validates batches without saving them.
*/
@POST
@Produces("application/json")
@Path("/validatePermissionBatches")
public Response validatePermissionBatches(@Context HttpServletRequest request) {
String batches = request.getParameter("batches");
return ResourceUtility.respondAsAdmin(request, "validate a permission batch as an admin",
SecurityAdminUtils::getInstance, (user, adminUtils) -> SecurityAccessPermissionBatchUtils
.validateBatches(adminUtils, user, SecurityAccessPermissionBatchUtils.readBatches(batches)));
}
/**
* Saves batches in one transaction, or none of them when any change cannot be
* made.
*/
@POST
@Produces("application/json")
@Path("/savePermissionBatches")
public Response savePermissionBatches(@Context HttpServletRequest request) {
String batches = request.getParameter("batches");
return ResourceUtility.respondAsAdmin(request, "save a permission batch as an admin",
SecurityAdminUtils::getInstance, (user, adminUtils) -> SecurityAccessPermissionBatchUtils
.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.
*
* @param resourceType {@code PROJECT}, {@code ENGINE}, {@code TEAM} or
* {@code TEAM_MANAGERS}
*/
@GET
@Produces("application/json")
@Path("/getPermissions")
public Response getPermissions(@Context HttpServletRequest request, @QueryParam("resourceType") String resourceType,
@QueryParam("id") String id) {
String resource = WebUtility.inputSQLSanitizer(id);
return ResourceUtility.respondAsAdmin(request, "read the permissions on " + resource + " as an admin",
SecurityAdminUtils::getInstance, (user, adminUtils) -> SecurityAccessPermissionBatchUtils
.getPermissions(adminUtils, user, PermissionBatchResource.toTarget(resourceType, resource)));
}
/**
* The people to copy from a project, engine or custom group into another.
*/
@GET
@Produces("application/json")
@Path("/getPermissionsToCopy")
public Response getPermissionsToCopy(@Context HttpServletRequest request,
@QueryParam("sourceResourceType") String sourceResourceType, @QueryParam("sourceId") String sourceId,
@QueryParam("targetResourceType") String targetResourceType, @QueryParam("targetId") String targetId) {
String source = WebUtility.inputSQLSanitizer(sourceId);
String target = WebUtility.inputSQLSanitizer(targetId);
return ResourceUtility.respondAsAdmin(request,
"read the permissions to copy from " + source + " to " + target + " as an admin",
SecurityAdminUtils::getInstance,
(user, adminUtils) -> SecurityAccessPermissionBatchUtils.getPermissionsToCopy(adminUtils, user,
PermissionBatchResource.toTarget(sourceResourceType, source),
PermissionBatchResource.toTarget(targetResourceType, target)));
}
/**
* Everyone who can use a project or an engine in the end, one row per person.
*
* @param resourceType {@code PROJECT} or {@code ENGINE}
*/
@GET
@Produces("application/json")
@Path("/getEffectivePermissions")
public Response getEffectivePermissions(@Context HttpServletRequest request,
@QueryParam("resourceType") String resourceType, @QueryParam("id") String id) {
String resource = WebUtility.inputSQLSanitizer(id);
return ResourceUtility.respondAsAdmin(request, "read the effective permissions on " + resource + " as an admin",
SecurityAdminUtils::getInstance,
(user, adminUtils) -> EffectivePermissionUtils.getEffectivePermissions(adminUtils, user,
PermissionBatchResource.toTarget(resourceType, resource)));
}
/**
* How usage limits apply to one person on a model, with every step's rules and
* each team's total.
*
* @param engineId the model
* @param userId the person
* @param userType the person's login type, required
*/
@GET
@Produces("application/json")
@Path("/getUsageLimitPath")
public Response getUsageLimitPath(@Context HttpServletRequest request, @QueryParam("engineId") String engineId,
@QueryParam("userId") String userId, @QueryParam("userType") String userType) {
String engine = WebUtility.inputSQLSanitizer(engineId);
String person = WebUtility.inputSQLSanitizer(userId);
String type = WebUtility.inputSQLSanitizer(userType);
return ResourceUtility.respondAsAdmin(request,
"read how usage limits apply to " + person + " on model " + engine + " as an admin",
SecurityAdminUtils::getInstance, (user, adminUtils) -> SecurityAccessPermissionBatchUtils
.getUsageLimitPath(adminUtils, user, engine, person, type));
}
}