4141import org .apache .commons .lang3 .StringUtils ;
4242import org .apache .linkis .httpclient .dws .DWSHttpClient ;
4343import org .apache .linkis .server .Message ;
44- import org .apache .linkis .server .security . SecurityFilter ;
44+ import org .apache .linkis .server .utils . ModuleUserUtils ;
4545import org .slf4j .Logger ;
4646import org .slf4j .LoggerFactory ;
4747import 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 );
0 commit comments