Skip to content

Commit 509421c

Browse files
Davidhua1996jefftlin
authored andcommitted
Support proxy user in restful controller.
1 parent 7b72c7a commit 509421c

9 files changed

Lines changed: 48 additions & 45 deletions

File tree

streamis-jobmanager/streamis-jobmanager-server/src/main/java/com/webank/wedatasphere/streamis/jobmanager/restful/api/JobBulkRestfulApi.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.apache.commons.lang3.StringUtils;
1515
import org.apache.linkis.scheduler.queue.SchedulerEventState;
1616
import org.apache.linkis.server.Message;
17-
import org.apache.linkis.server.security.SecurityFilter;
17+
import org.apache.linkis.server.utils.ModuleUserUtils;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020
import org.springframework.web.bind.annotation.RequestBody;
@@ -60,7 +60,7 @@ public Message bulkExecution(@RequestBody JobBulkRequest execBulkRequest, HttpSe
6060
}
6161
Message result = Message.ok("success");
6262
try{
63-
String username = SecurityFilter.getLoginUsername(request);
63+
String username = ModuleUserUtils.getOperationUser(request, "bulk execute job");
6464
LOG.info("Bulk execution[operator: {} sbj_type: {}, subjects: ({})]", username,
6565
execBulkRequest.getBulkSubjectType(), StringUtils.join(execBulkRequest.getBulkSubject(), ","));
6666
// TODO Check the permission of task id
@@ -113,7 +113,7 @@ public Message bulkPause(@RequestBody JobBulkPauseRequest pauseRequest, HttpServ
113113
}
114114
Message result = Message.ok("success");
115115
try{
116-
String username = SecurityFilter.getLoginUsername(request);
116+
String username = ModuleUserUtils.getOperationUser(request, "bulk pause job");
117117
LOG.info("Bulk pause[operator: {}, sbj_type: {}, snapshot: {}, subjects: ({})]",
118118
username, pauseRequest.getBulkSubjectType(), pauseRequest.isSnapshot(),
119119
StringUtils.join(pauseRequest.getBulkSubject(), ","));

streamis-jobmanager/streamis-jobmanager-server/src/main/java/com/webank/wedatasphere/streamis/jobmanager/restful/api/JobConfExtRestfulApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.lang.StringUtils;
2121
import org.apache.linkis.server.Message;
2222
import org.apache.linkis.server.security.SecurityFilter;
23+
import org.apache.linkis.server.utils.ModuleUserUtils;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,7 +45,7 @@ public Message getWorkspaceUsers(HttpServletRequest req) {
4445
List<String> userList = new ArrayList<>();
4546
String workspaceId = CookieUtils.getCookieWorkspaceId(req);
4647
if (StringUtils.isNotBlank(workspaceId)) {
47-
String userName = SecurityFilter.getLoginUsername(req);
48+
String userName = ModuleUserUtils.getOperationUser(req);
4849
userList.addAll(userService.workspaceUserQuery(req, workspaceId));
4950
} else {
5051
LOG.warn("Cannot find the workspaceID from DSS,perhaps the cookie value has been lost in request from: {}", req.getLocalAddr());

streamis-jobmanager/streamis-jobmanager-server/src/main/java/com/webank/wedatasphere/streamis/jobmanager/restful/api/JobConfRestfulApi.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.linkis.httpclient.dws.DWSHttpClient;
2929
import org.apache.linkis.server.Message;
3030
import org.apache.linkis.server.security.SecurityFilter;
31+
import org.apache.linkis.server.utils.ModuleUserUtils;
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334
import org.springframework.web.bind.annotation.*;
@@ -101,7 +102,7 @@ public Message definitions(){
101102
public Message queryConfig(@PathVariable("jobId") Long jobId, HttpServletRequest request){
102103
Message result = Message.ok("success");
103104
try {
104-
String userName = SecurityFilter.getLoginUsername(request);
105+
String userName = ModuleUserUtils.getOperationUser(request, "query job config json");
105106
StreamJob streamJob = this.streamJobService.getJobById(jobId);
106107
if (!streamJobService.hasPermission(streamJob, userName) &&
107108
!this.privilegeService.hasAccessPrivilege(request, streamJob.getProjectName())){
@@ -128,7 +129,7 @@ public Message saveConfig(@PathVariable("jobId") Long jobId, @RequestBody Map<St
128129
HttpServletRequest request){
129130
Message result = Message.ok("success");
130131
try{
131-
String userName = SecurityFilter.getLoginUsername(request);
132+
String userName = ModuleUserUtils.getOperationUser(request, "save job config json");
132133
StreamJob streamJob = this.streamJobService.getJobById(jobId);
133134
// Accept the developer to modify
134135
if (!streamJobService.isCreator(jobId, userName) &&
@@ -153,7 +154,7 @@ public Message viewConfigTree(@RequestParam(value = "jobId", required = false) L
153154
if (Objects.isNull(jobId)){
154155
throw new JobErrorException(-1, "Params 'jobId' cannot be empty");
155156
}
156-
String userName = SecurityFilter.getLoginUsername(req);
157+
String userName = ModuleUserUtils.getOperationUser(req, "view config tree");
157158
StreamJob streamJob = this.streamJobService.getJobById(jobId);
158159
if (!this.streamJobService.hasPermission(streamJob, userName)
159160
&& !this.privilegeService.hasAccessPrivilege(req, streamJob.getProjectName())){
@@ -172,7 +173,7 @@ public Message viewConfigTree(@RequestParam(value = "jobId", required = false) L
172173
public Message saveConfigTree(@RequestBody JsonNode json, HttpServletRequest req){
173174
Message result = Message.ok("success");
174175
try{
175-
String userName = SecurityFilter.getLoginUsername(req);
176+
String userName = ModuleUserUtils.getOperationUser(req, "save config tree");
176177
JobConfValueSet fullTrees = DWSHttpClient.jacksonJson().readValue(json.get("fullTree").traverse(), JobConfValueSet.class);
177178
// Accept the developer to modify
178179
if (!streamJobService.isCreator(fullTrees.getJobId(), userName) &&

streamis-jobmanager/streamis-jobmanager-server/src/main/java/com/webank/wedatasphere/streamis/jobmanager/restful/api/JobRestfulApi.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.apache.commons.lang3.StringUtils;
4242
import org.apache.linkis.httpclient.dws.DWSHttpClient;
4343
import org.apache.linkis.server.Message;
44-
import org.apache.linkis.server.security.SecurityFilter;
44+
import org.apache.linkis.server.utils.ModuleUserUtils;
4545
import org.slf4j.Logger;
4646
import org.slf4j.LoggerFactory;
4747
import org.springframework.beans.factory.annotation.Autowired;
@@ -80,7 +80,7 @@ public Message getJobList(HttpServletRequest req,
8080
@RequestParam(value = "jobName", required = false) String jobName,
8181
@RequestParam(value = "jobStatus", required = false) Integer jobStatus,
8282
@RequestParam(value = "jobCreator", required = false) String jobCreator) {
83-
String username = SecurityFilter.getLoginUsername(req);
83+
String username = ModuleUserUtils.getOperationUser(req, "list jobs");
8484
if(StringUtils.isBlank(projectName)){
8585
return Message.error("Project name cannot be empty(项目名不能为空,请指定)");
8686
}
@@ -103,7 +103,7 @@ public Message getJobList(HttpServletRequest req,
103103

104104
@RequestMapping(path = "/createOrUpdate", method = RequestMethod.POST)
105105
public Message createOrUpdate(HttpServletRequest req, @Validated @RequestBody MetaJsonInfo metaJsonInfo) {
106-
String username = SecurityFilter.getLoginUsername(req);
106+
String username = ModuleUserUtils.getOperationUser(req, "create or update job");
107107
String projectName = metaJsonInfo.getProjectName();
108108
if (StringUtils.isBlank(projectName)){
109109
return Message.error("Project name cannot be empty(项目名不能为空,请指定)");
@@ -124,7 +124,7 @@ public Message version(HttpServletRequest req, @RequestParam(value = "jobId", re
124124
if (StringUtils.isEmpty(version)) {
125125
throw JobExceptionManager.createException(30301, "version");
126126
}
127-
String username = SecurityFilter.getLoginUsername(req);
127+
String username = ModuleUserUtils.getOperationUser(req, "view the job version");
128128
StreamJob streamJob = this.streamJobService.getJobById(jobId);
129129
if (!streamJobService.hasPermission(streamJob, username) &&
130130
!this.privilegeService.hasAccessPrivilege(req, streamJob.getProjectName())) {
@@ -137,7 +137,7 @@ public Message version(HttpServletRequest req, @RequestParam(value = "jobId", re
137137

138138
@RequestMapping(path = "/execute", method = RequestMethod.POST)
139139
public Message executeJob(HttpServletRequest req, @RequestBody Map<String, Object> json) throws JobException {
140-
String userName = SecurityFilter.getLoginUsername(req);
140+
String userName = ModuleUserUtils.getOperationUser(req, "execute job");
141141
if (!json.containsKey("jobId") || json.get("jobId") == null) {
142142
throw JobExceptionManager.createException(30301, "jobId");
143143
}
@@ -166,7 +166,7 @@ public Message executeJob(HttpServletRequest req, @RequestBody Map<String, Objec
166166
public Message killJob(HttpServletRequest req,
167167
@RequestParam(value = "jobId", required = false) Long jobId,
168168
@RequestParam(value = "snapshot", required = false) Boolean snapshot) throws JobException {
169-
String userName = SecurityFilter.getLoginUsername(req);
169+
String userName = ModuleUserUtils.getOperationUser(req, "stop the job");
170170
snapshot = !Objects.isNull(snapshot) && snapshot;
171171
if (jobId == null) {
172172
throw JobExceptionManager.createException(30301, "jobId");
@@ -200,7 +200,7 @@ public Message detailsJob(HttpServletRequest req, @RequestParam(value = "jobId",
200200
if (jobId == null) {
201201
JobExceptionManager.createException(30301, "jobId");
202202
}
203-
String username = SecurityFilter.getLoginUsername(req);
203+
String username = ModuleUserUtils.getOperationUser(req, "view the job details");
204204
StreamJob streamJob = streamJobService.getJobById(jobId);
205205
if (!streamJobService.hasPermission(streamJob, username) &&
206206
!this.privilegeService.hasAccessPrivilege(req, streamJob.getProjectName())) {
@@ -216,7 +216,7 @@ public Message detailsJob(HttpServletRequest req, @RequestParam(value = "jobId",
216216
public Message executeHistoryJob(HttpServletRequest req,
217217
@RequestParam(value = "jobId", required = false) Long jobId,
218218
@RequestParam(value = "version", required = false) String version) throws JobException {
219-
String username = SecurityFilter.getLoginUsername(req);
219+
String username = ModuleUserUtils.getOperationUser(req, "view the job history");
220220
if (jobId == null) {
221221
throw JobExceptionManager.createException(30301, "jobId");
222222
}
@@ -262,7 +262,7 @@ public Message addTask(HttpServletRequest req,
262262
@RequestParam(value = "jobName") String jobName,
263263
@RequestParam(value = "appId") String appId,
264264
@RequestParam(value = "appUrl") String appUrl) {
265-
String username = SecurityFilter.getLoginUsername(req);
265+
String username = ModuleUserUtils.getOperationUser(req, "add task");
266266
LOG.info("User {} try to add a new task for Streamis job {}.{} with appId: {}, appUrl: {}.", username, projectName, jobName, appId, appUrl);
267267
if(StringUtils.isBlank(appId)) {
268268
return Message.error("appId cannot be empty!");
@@ -343,7 +343,7 @@ public Message updateTask(HttpServletRequest req,
343343
@RequestParam(value = "jobName") String jobName,
344344
@RequestParam(value = "appId") String appId,
345345
@RequestParam(value = "metrics") String metrics) {
346-
String username = SecurityFilter.getLoginUsername(req);
346+
String username = ModuleUserUtils.getOperationUser(req, "update task");
347347
LOG.info("User {} try to update task for Streamis job {}.{} with appId: {}, metrics: {}.", username, projectName, jobName, appId, metrics);
348348
return withStreamJob(req, projectName, jobName, username, streamJob -> {
349349
StreamTask streamTask = streamTaskService.getLatestTaskByJobId(streamJob.getId());
@@ -388,7 +388,7 @@ public Message stopTask(HttpServletRequest req,
388388
@RequestParam(value = "jobName") String jobName,
389389
@RequestParam(value = "appId") String appId,
390390
@RequestParam(value = "appUrl") String appUrl) {
391-
String username = SecurityFilter.getLoginUsername(req);
391+
String username = ModuleUserUtils.getOperationUser(req, "stop task");
392392
LOG.info("User {} try to stop task for Streamis job {}.{} with appId: {}, appUrl: {}.", username, projectName, jobName, appId, appUrl);
393393
return withStreamJob(req, projectName, jobName, username,
394394
streamJob -> tryStopTask(streamJob, appId));
@@ -420,7 +420,7 @@ private Message tryStopTask(StreamJob streamJob, String appId) {
420420
@RequestMapping(path = "/progress", method = RequestMethod.GET)
421421
public Message progressJob(HttpServletRequest req, @RequestParam(value = "jobId", required = false) Long jobId,
422422
@RequestParam(value = "version", required = false) String version) throws JobException {
423-
String username = SecurityFilter.getLoginUsername(req);
423+
String username = ModuleUserUtils.getOperationUser(req, "view the job's progress");
424424
if (jobId == null) {
425425
throw JobExceptionManager.createException(30301, "jobId");
426426
}
@@ -441,7 +441,7 @@ public Message progressJob(HttpServletRequest req, @RequestParam(value = "jobId"
441441
@RequestMapping(path = "/jobContent", method = RequestMethod.GET)
442442
public Message uploadDetailsJob(HttpServletRequest req, @RequestParam(value = "jobId", required = false) Long jobId,
443443
@RequestParam(value = "version", required = false) String version) {
444-
String username = SecurityFilter.getLoginUsername(req);
444+
String username = ModuleUserUtils.getOperationUser(req, "view job content");
445445
StreamJob streamJob = this.streamJobService.getJobById(jobId);
446446
if (!streamJobService.hasPermission(streamJob, username) &&
447447
!this.privilegeService.hasAccessPrivilege(req, streamJob.getProjectName())) {
@@ -454,7 +454,7 @@ public Message uploadDetailsJob(HttpServletRequest req, @RequestParam(value = "j
454454
@RequestMapping(path = "/alert", method = RequestMethod.GET)
455455
public Message getAlert(HttpServletRequest req, @RequestParam(value = "jobId", required = false) Long jobId,
456456
@RequestParam(value = "version", required = false) String version) {
457-
String username = SecurityFilter.getLoginUsername(req);
457+
String username = ModuleUserUtils.getOperationUser(req, "get alert message list");
458458
return Message.ok().data("list", streamJobService.getAlert(username, jobId, version));
459459
}
460460

@@ -472,7 +472,7 @@ public Message getLog(HttpServletRequest req,
472472
throw JobExceptionManager.createException(30301, "jobId");
473473
}
474474
logType = StringUtils.isBlank(logType) ? "client" : logType;
475-
String username = SecurityFilter.getLoginUsername(req);
475+
String username = ModuleUserUtils.getOperationUser(req, "view job logs");
476476
StreamJob streamJob = this.streamJobService.getJobById(jobId);
477477
if(streamJob == null) {
478478
return Message.error("not exists job " + jobId);
@@ -523,7 +523,7 @@ public Message status(@RequestBody Map<String, List<Long>> requestMap){
523523
public Message snapshot(@PathVariable("jobId")Long jobId, HttpServletRequest request){
524524
Message result = Message.ok();
525525
try{
526-
String username = SecurityFilter.getLoginUsername(request);
526+
String username = ModuleUserUtils.getOperationUser(request, "do snapshot of job");
527527
StreamJob streamJob = this.streamJobService.getJobById(jobId);
528528
if(streamJob == null) {
529529
return Message.error("not exists job " + jobId);

streamis-jobmanager/streamis-jobmanager-server/src/main/java/com/webank/wedatasphere/streamis/jobmanager/restful/api/ProjectRestfulApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.lang.StringUtils;
2222
import org.apache.linkis.server.Message;
2323
import org.apache.linkis.server.security.SecurityFilter;
24+
import org.apache.linkis.server.utils.ModuleUserUtils;
2425
import org.springframework.beans.factory.annotation.Autowired;
2526
import org.springframework.web.bind.annotation.RequestMapping;
2627
import org.springframework.web.bind.annotation.RequestMethod;
@@ -41,7 +42,7 @@ public Message getView(HttpServletRequest req, @RequestParam(value= "projectName
4142
if(StringUtils.isBlank(projectName)){
4243
throw new ProjectException("params cannot be empty!");
4344
}
44-
String username = SecurityFilter.getLoginUsername(req);
45+
String username = ModuleUserUtils.getOperationUser(req);
4546
TaskCoreNumVo taskCoreNumVO = streamJobService.countByCores(projectName,username);
4647
return Message.ok().data("taskCore",taskCoreNumVO);
4748
}

streamis-jobmanager/streamis-jobmanager-server/src/main/java/com/webank/wedatasphere/streamis/jobmanager/restful/api/UploadRestfulApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.apache.commons.io.IOUtils;
2828
import org.apache.commons.lang.exception.ExceptionUtils;
2929
import org.apache.linkis.server.Message;
30-
import org.apache.linkis.server.security.SecurityFilter;
30+
import org.apache.linkis.server.utils.ModuleUserUtils;
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
3333
import org.springframework.beans.factory.annotation.Autowired;
@@ -65,7 +65,7 @@ public Message uploadJar(HttpServletRequest request,
6565
@RequestParam(name = "projectName", required = false) String projectName,
6666
@RequestParam(name = "file") List<MultipartFile> files) throws IOException, JobException {
6767

68-
String userName = SecurityFilter.getLoginUsername(request);
68+
String userName = ModuleUserUtils.getOperationUser(request, "upload job zip file");
6969
if (files == null || files.size() <= 0) {
7070
throw JobExceptionManager.createException(30300, "uploaded files");
7171
}

0 commit comments

Comments
 (0)