Skip to content

Commit 7811680

Browse files
committed
#359 #357 add @RequiresPermissions to Controllers
1 parent a8e8771 commit 7811680

14 files changed

+238
-126
lines changed

pom.xml

+25
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
<spring.data.commons.version>1.12.1.RELEASE</spring.data.commons.version>
5555
<druid.version>0.2.9</druid.version>
5656

57+
<shiro.version>1.3.2</shiro.version>
58+
5759
<lombok.version>1.16.6</lombok.version>
5860
<gson.version>2.5</gson.version>
5961
<fastjson.version>1.2.29</fastjson.version>
@@ -378,6 +380,29 @@
378380
</dependency>
379381
<!-- DB end -->
380382

383+
<!-- Shiro begin -->
384+
<dependency>
385+
<groupId>org.apache.shiro</groupId>
386+
<artifactId>shiro-core</artifactId>
387+
<version>${shiro.version}</version>
388+
</dependency>
389+
<dependency>
390+
<groupId>org.apache.shiro</groupId>
391+
<artifactId>shiro-spring</artifactId>
392+
<version>${shiro.version}</version>
393+
</dependency>
394+
<dependency>
395+
<groupId>org.apache.shiro</groupId>
396+
<artifactId>shiro-web</artifactId>
397+
<version>${shiro.version}</version>
398+
</dependency>
399+
<dependency>
400+
<groupId>org.apache.shiro</groupId>
401+
<artifactId>shiro-cas</artifactId>
402+
<version>${shiro.version}</version>
403+
</dependency>
404+
<!-- Shiro end -->
405+
381406
<!-- Swagger begin -->
382407
<dependency>
383408
<groupId>io.springfox</groupId>

saturn-console-api/pom.xml

+19
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@
172172
</dependency>
173173
<!-- DB end -->
174174

175+
<!-- Shiro begin -->
176+
<dependency>
177+
<groupId>org.apache.shiro</groupId>
178+
<artifactId>shiro-core</artifactId>
179+
</dependency>
180+
<dependency>
181+
<groupId>org.apache.shiro</groupId>
182+
<artifactId>shiro-spring</artifactId>
183+
</dependency>
184+
<dependency>
185+
<groupId>org.apache.shiro</groupId>
186+
<artifactId>shiro-web</artifactId>
187+
</dependency>
188+
<dependency>
189+
<groupId>org.apache.shiro</groupId>
190+
<artifactId>shiro-cas</artifactId>
191+
</dependency>
192+
<!-- Shiro end -->
193+
175194
<!-- utils begin -->
176195
<dependency>
177196
<groupId>com.google.guava</groupId>

saturn-console-api/src/main/java/com/vip/saturn/job/console/controller/gui/DashboardController.java

+22-21
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
import com.vip.saturn.job.console.exception.SaturnJobConsoleGUIException;
2020
import com.vip.saturn.job.console.mybatis.entity.SaturnStatistics;
2121
import com.vip.saturn.job.console.service.DashboardService;
22+
import com.vip.saturn.job.console.utils.Permissions;
2223
import io.swagger.annotations.ApiResponse;
2324
import io.swagger.annotations.ApiResponses;
24-
import java.util.Collection;
25-
import java.util.Map;
2625
import org.apache.commons.lang3.StringUtils;
26+
import org.apache.shiro.authz.annotation.RequiresPermissions;
2727
import org.springframework.beans.factory.annotation.Autowired;
28-
import org.springframework.web.bind.annotation.GetMapping;
29-
import org.springframework.web.bind.annotation.PathVariable;
30-
import org.springframework.web.bind.annotation.PostMapping;
31-
import org.springframework.web.bind.annotation.RequestMapping;
32-
import org.springframework.web.bind.annotation.RequestParam;
28+
import org.springframework.web.bind.annotation.*;
29+
30+
import java.util.Collection;
31+
import java.util.Map;
3332

3433
@RequestMapping("/console/dashboard")
3534
public class DashboardController extends AbstractGUIController {
@@ -137,8 +136,8 @@ public SuccessResponseEntity top10LoadJob(@RequestParam(required = false) String
137136

138137
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
139138
@GetMapping(value = "/top10FailDomain")
140-
public SuccessResponseEntity top10FailDomain(
141-
@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
139+
public SuccessResponseEntity top10FailDomain(@RequestParam(required = false) String zkClusterKey)
140+
throws SaturnJobConsoleException {
142141
if (StringUtils.isNotBlank(zkClusterKey)) {
143142
ZkCluster zkCluster = checkAndGetZkCluster(zkClusterKey);
144143
SaturnStatistics ss = dashboardService.top10FailureDomain(zkCluster.getZkAddr());
@@ -149,8 +148,8 @@ public SuccessResponseEntity top10FailDomain(
149148

150149
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
151150
@GetMapping(value = "/top10UnstableDomain")
152-
public SuccessResponseEntity top10UnstableDomain(
153-
@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
151+
public SuccessResponseEntity top10UnstableDomain(@RequestParam(required = false) String zkClusterKey)
152+
throws SaturnJobConsoleException {
154153
if (StringUtils.isNotBlank(zkClusterKey)) {
155154
ZkCluster zkCluster = checkAndGetZkCluster(zkClusterKey);
156155
SaturnStatistics ss = dashboardService.top10UnstableDomain(zkCluster.getZkAddr());
@@ -161,8 +160,8 @@ public SuccessResponseEntity top10UnstableDomain(
161160

162161
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
163162
@GetMapping(value = "/top10LoadExecutor")
164-
public SuccessResponseEntity top10LoadExecutor(
165-
@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
163+
public SuccessResponseEntity top10LoadExecutor(@RequestParam(required = false) String zkClusterKey)
164+
throws SaturnJobConsoleException {
166165
if (StringUtils.isNotBlank(zkClusterKey)) {
167166
ZkCluster zkCluster = checkAndGetZkCluster(zkClusterKey);
168167
SaturnStatistics ss = dashboardService.top10LoadExecutor(zkCluster.getZkAddr());
@@ -195,8 +194,8 @@ public SuccessResponseEntity loadDomainRank(@RequestParam(required = false) Stri
195194

196195
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
197196
@GetMapping(value = "/jobRank")
198-
public SuccessResponseEntity loadJobRank(
199-
@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
197+
public SuccessResponseEntity loadJobRank(@RequestParam(required = false) String zkClusterKey)
198+
throws SaturnJobConsoleException {
200199
if (StringUtils.isNotBlank(zkClusterKey)) {
201200
ZkCluster zkCluster = checkAndGetZkCluster(zkClusterKey);
202201
return new SuccessResponseEntity(dashboardService.loadJobRankDistribution(zkCluster.getZkAddr()));
@@ -217,8 +216,8 @@ public SuccessResponseEntity versionDomainNumber(@RequestParam(required = false)
217216

218217
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
219218
@GetMapping(value = "/executorVersionNumber")
220-
public SuccessResponseEntity versionExecutorNumber(
221-
@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
219+
public SuccessResponseEntity versionExecutorNumber(@RequestParam(required = false) String zkClusterKey)
220+
throws SaturnJobConsoleException {
222221
if (StringUtils.isNotBlank(zkClusterKey)) {
223222
ZkCluster zkCluster = checkAndGetZkCluster(zkClusterKey);
224223
return new SuccessResponseEntity(dashboardService.versionExecutorNumber(zkCluster.getZkAddr()));
@@ -228,6 +227,7 @@ public SuccessResponseEntity versionExecutorNumber(
228227

229228
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
230229
@Audit
230+
@RequiresPermissions(Permissions.dashboardCleanShardingCount)
231231
@PostMapping(value = "/namespaces/{namespace:.+}/shardingCount/clean")
232232
public SuccessResponseEntity cleanShardingCount(@PathVariable String namespace) throws SaturnJobConsoleException {
233233
dashboardService.cleanShardingCount(namespace);
@@ -236,16 +236,17 @@ public SuccessResponseEntity cleanShardingCount(@PathVariable String namespace)
236236

237237
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
238238
@Audit
239+
@RequiresPermissions(Permissions.dashboardCleanOneJobAnalyse)
239240
@PostMapping(value = "/namespaces/{namespace:.+}/jobs/{jobName}/jobAnalyse/clean")
240241
public SuccessResponseEntity cleanJobAnalyse(@AuditParam("namespace") @PathVariable String namespace,
241-
@AuditParam("jobName") @PathVariable String jobName)
242-
throws SaturnJobConsoleException {
242+
@AuditParam("jobName") @PathVariable String jobName) throws SaturnJobConsoleException {
243243
dashboardService.cleanOneJobAnalyse(namespace, jobName);
244244
return new SuccessResponseEntity();
245245
}
246246

247247
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
248248
@Audit
249+
@RequiresPermissions(Permissions.dashboardCleanAllJobAnalyse)
249250
@PostMapping(value = "/namespaces/{namespace:.+}/jobAnalyse/clean")
250251
public SuccessResponseEntity cleanJobsAnalyse(@AuditParam("namespace") @PathVariable String namespace)
251252
throws SaturnJobConsoleException {
@@ -255,10 +256,10 @@ public SuccessResponseEntity cleanJobsAnalyse(@AuditParam("namespace") @PathVari
255256

256257
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
257258
@Audit
259+
@RequiresPermissions(Permissions.dashboardCleanOneJobExecutorCount)
258260
@PostMapping(value = "/namespaces/{namespace:.+}/jobs/{jobName}/jobExecutorCount/clean")
259261
public SuccessResponseEntity cleanJobExecutorCount(@AuditParam("namespace") @PathVariable String namespace,
260-
@AuditParam("jobName") @PathVariable String jobName)
261-
throws SaturnJobConsoleException {
262+
@AuditParam("jobName") @PathVariable String jobName) throws SaturnJobConsoleException {
262263
dashboardService.cleanOneJobExecutorCount(namespace, jobName);
263264
return new SuccessResponseEntity();
264265
}

saturn-console-api/src/main/java/com/vip/saturn/job/console/controller/gui/ExecutorOverviewController.java

+27-31
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
import com.vip.saturn.job.console.exception.SaturnJobConsoleException;
1111
import com.vip.saturn.job.console.exception.SaturnJobConsoleGUIException;
1212
import com.vip.saturn.job.console.service.ExecutorService;
13+
import com.vip.saturn.job.console.utils.Permissions;
1314
import io.swagger.annotations.ApiResponse;
1415
import io.swagger.annotations.ApiResponses;
15-
import java.util.List;
16-
import javax.annotation.Resource;
17-
import javax.servlet.http.HttpServletRequest;
16+
import org.apache.shiro.authz.annotation.RequiresPermissions;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
20-
import org.springframework.web.bind.annotation.DeleteMapping;
21-
import org.springframework.web.bind.annotation.GetMapping;
22-
import org.springframework.web.bind.annotation.PathVariable;
23-
import org.springframework.web.bind.annotation.PostMapping;
24-
import org.springframework.web.bind.annotation.RequestMapping;
25-
import org.springframework.web.bind.annotation.RequestParam;
19+
import org.springframework.web.bind.annotation.*;
20+
21+
import javax.annotation.Resource;
22+
import javax.servlet.http.HttpServletRequest;
23+
import java.util.List;
2624

2725
/**
2826
* Executor overview related operations.
@@ -46,9 +44,8 @@ public class ExecutorOverviewController extends AbstractGUIController {
4644
*/
4745
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
4846
@GetMapping
49-
public SuccessResponseEntity getExecutors(final HttpServletRequest request,
50-
@PathVariable String namespace, @RequestParam(required = false) String status)
51-
throws SaturnJobConsoleException {
47+
public SuccessResponseEntity getExecutors(final HttpServletRequest request, @PathVariable String namespace,
48+
@RequestParam(required = false) String status) throws SaturnJobConsoleException {
5249
if ("online".equalsIgnoreCase(status)) {
5350
return new SuccessResponseEntity(executorService.getExecutors(namespace, ServerStatus.ONLINE));
5451
}
@@ -61,8 +58,8 @@ public SuccessResponseEntity getExecutors(final HttpServletRequest request,
6158
*/
6259
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
6360
@GetMapping(value = "/{executorName}/allocation")
64-
public SuccessResponseEntity getExecutorAllocation(final HttpServletRequest request,
65-
@PathVariable String namespace, @PathVariable String executorName) throws SaturnJobConsoleException {
61+
public SuccessResponseEntity getExecutorAllocation(final HttpServletRequest request, @PathVariable String namespace,
62+
@PathVariable String executorName) throws SaturnJobConsoleException {
6663
return new SuccessResponseEntity(executorService.getExecutorAllocation(namespace, executorName));
6764
}
6865

@@ -71,10 +68,10 @@ public SuccessResponseEntity getExecutorAllocation(final HttpServletRequest requ
7168
*/
7269
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
7370
@Audit
71+
@RequiresPermissions(Permissions.executorShardAllAtOnce)
7472
@PostMapping(value = "/shardAll")
7573
public SuccessResponseEntity shardAll(final HttpServletRequest request,
76-
@AuditParam("namespace") @PathVariable String namespace)
77-
throws SaturnJobConsoleException {
74+
@AuditParam("namespace") @PathVariable String namespace) throws SaturnJobConsoleException {
7875
executorService.shardAll(namespace);
7976
return new SuccessResponseEntity();
8077
}
@@ -84,12 +81,12 @@ public SuccessResponseEntity shardAll(final HttpServletRequest request,
8481
*/
8582
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
8683
@Audit
84+
@RequiresPermissions(Permissions.executorExtractOrRecoverTraffic)
8785
@PostMapping(value = "/{executorName}/traffic")
8886
public SuccessResponseEntity extractOrRecoverTraffic(final HttpServletRequest request,
8987
@AuditParam("namespace") @PathVariable String namespace,
9088
@AuditParam("executorName") @PathVariable String executorName,
91-
@AuditParam("operation") @RequestParam String operation)
92-
throws SaturnJobConsoleException {
89+
@AuditParam("operation") @RequestParam String operation) throws SaturnJobConsoleException {
9390
extractOrRecoverTraffic(namespace, executorName, operation);
9491
return new SuccessResponseEntity();
9592
}
@@ -99,12 +96,12 @@ public SuccessResponseEntity extractOrRecoverTraffic(final HttpServletRequest re
9996
*/
10097
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
10198
@Audit
99+
@RequiresPermissions(Permissions.executorBatchExtractOrRecoverTraffic)
102100
@PostMapping(value = "/traffic")
103101
public SuccessResponseEntity batchExtractOrRecoverTraffic(final HttpServletRequest request,
104102
@AuditParam("namespace") @PathVariable String namespace,
105103
@AuditParam("executorNames") @RequestParam List<String> executorNames,
106-
@AuditParam("operation") @RequestParam String operation)
107-
throws SaturnJobConsoleException {
104+
@AuditParam("operation") @RequestParam String operation) throws SaturnJobConsoleException {
108105
List<String> success2ExtractOrRecoverTrafficExecutors = Lists.newArrayList();
109106
List<String> fail2ExtractOrRecoverTrafficExecutors = Lists.newArrayList();
110107
for (String executorName : executorNames) {
@@ -120,8 +117,7 @@ public SuccessResponseEntity batchExtractOrRecoverTraffic(final HttpServletReque
120117
if (!fail2ExtractOrRecoverTrafficExecutors.isEmpty()) {
121118
StringBuilder message = new StringBuilder();
122119
message.append("操作成功的executor:" + success2ExtractOrRecoverTrafficExecutors.toString()).append(",")
123-
.append("操作失败的executor:")
124-
.append(fail2ExtractOrRecoverTrafficExecutors.toString());
120+
.append("操作失败的executor:").append(fail2ExtractOrRecoverTrafficExecutors.toString());
125121
throw new SaturnJobConsoleGUIException(message.toString());
126122
}
127123

@@ -144,11 +140,11 @@ private void extractOrRecoverTraffic(String namespace, String executorName, Stri
144140
*/
145141
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
146142
@Audit
143+
@RequiresPermissions(Permissions.executorRemove)
147144
@DeleteMapping(value = "/{executorName}")
148145
public SuccessResponseEntity removeExecutor(final HttpServletRequest request,
149146
@AuditParam("namespace") @PathVariable String namespace,
150-
@AuditParam("executorName") @PathVariable String executorName)
151-
throws SaturnJobConsoleException {
147+
@AuditParam("executorName") @PathVariable String executorName) throws SaturnJobConsoleException {
152148
// check executor is existed and online.
153149
checkExecutorStatus(namespace, executorName, ServerStatus.OFFLINE, "Executor在线,不能移除");
154150
executorService.removeExecutor(namespace, executorName);
@@ -160,11 +156,11 @@ public SuccessResponseEntity removeExecutor(final HttpServletRequest request,
160156
*/
161157
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
162158
@Audit
159+
@RequiresPermissions(Permissions.executorBatchRemove)
163160
@DeleteMapping
164161
public SuccessResponseEntity batchRemoveExecutors(final HttpServletRequest request,
165162
@AuditParam("namespace") @PathVariable String namespace,
166-
@AuditParam("executorNames") @RequestParam List<String> executorNames)
167-
throws SaturnJobConsoleException {
163+
@AuditParam("executorNames") @RequestParam List<String> executorNames) throws SaturnJobConsoleException {
168164
// check executor is existed and online.
169165
List<String> success2RemoveExecutors = Lists.newArrayList();
170166
List<String> fail2RemoveExecutors = Lists.newArrayList();
@@ -204,11 +200,11 @@ private void checkExecutorStatus(String namespace, String executorName, ServerSt
204200
*/
205201
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
206202
@Audit
203+
@RequiresPermissions(Permissions.executorDump)
207204
@PostMapping(value = "/{executorName}/dump")
208205
public SuccessResponseEntity dump(final HttpServletRequest request,
209206
@AuditParam("namespace") @PathVariable String namespace,
210-
@AuditParam("executorName") @PathVariable String executorName)
211-
throws SaturnJobConsoleException {
207+
@AuditParam("executorName") @PathVariable String executorName) throws SaturnJobConsoleException {
212208
// check executor is existed and online.
213209
checkExecutorStatus(namespace, executorName, ServerStatus.ONLINE, "Executor必须在线才可以dump");
214210
executorService.dump(namespace, executorName);
@@ -220,11 +216,11 @@ public SuccessResponseEntity dump(final HttpServletRequest request,
220216
*/
221217
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
222218
@Audit
219+
@RequiresPermissions(Permissions.executorRestart)
223220
@PostMapping(value = "/{executorName}/restart")
224221
public SuccessResponseEntity restart(final HttpServletRequest request,
225-
@AuditParam("namespace") @PathVariable String namespace,
226-
@AuditParam("executorName") @PathVariable String executorName)
227-
throws SaturnJobConsoleException {
222+
@AuditParam("namespace") @PathVariable String namespace,
223+
@AuditParam("executorName") @PathVariable String executorName) throws SaturnJobConsoleException {
228224
// check executor is existed and online.
229225
checkExecutorStatus(namespace, executorName, ServerStatus.ONLINE, "Executor必须在线才可以重启");
230226
executorService.restart(namespace, executorName);

0 commit comments

Comments
 (0)