Browse Source

🎉 oss敏感操作增加权限校验

test
smallchill 5 years ago
parent
commit
9d2e795740
  1. 58
      blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/DiscoveryEndpoint.java
  2. 6
      blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/OssEndpoint.java

58
blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/DiscoveryEndpoint.java

@ -1,58 +0,0 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.endpoint;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 服务发现控制器
*
* @author Chill
*/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/discovery")
public class DiscoveryEndpoint {
private final DiscoveryClient discoveryClient;
/**
* 获取服务实例
*/
@GetMapping("/instances")
public Map<String, List<ServiceInstance>> instances() {
Map<String, List<ServiceInstance>> instances = new HashMap<>(16);
List<String> services = discoveryClient.getServices();
services.forEach(s -> {
List<ServiceInstance> list = discoveryClient.getInstances(s);
instances.put(s, list);
});
return instances;
}
}

6
blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/OssEndpoint.java

@ -21,7 +21,9 @@ import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.oss.model.OssFile;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.builder.OssBuilder;
import org.springframework.web.bind.annotation.*;
@ -48,6 +50,7 @@ public class OssEndpoint {
*/
@SneakyThrows
@PostMapping("/make-bucket")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R makeBucket(@RequestParam String bucketName) {
ossBuilder.template().makeBucket(bucketName);
return R.success("创建成功");
@ -61,6 +64,7 @@ public class OssEndpoint {
*/
@SneakyThrows
@PostMapping("/remove-bucket")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R removeBucket(@RequestParam String bucketName) {
ossBuilder.template().removeBucket(bucketName);
return R.success("删除成功");
@ -153,6 +157,7 @@ public class OssEndpoint {
*/
@SneakyThrows
@PostMapping("/remove-file")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R removeFile(@RequestParam String fileName) {
ossBuilder.template().removeFile(fileName);
return R.success("操作成功");
@ -166,6 +171,7 @@ public class OssEndpoint {
*/
@SneakyThrows
@PostMapping("/remove-files")
@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
public R removeFiles(@RequestParam String fileNames) {
ossBuilder.template().removeFiles(Func.toStrList(fileNames));
return R.success("操作成功");

Loading…
Cancel
Save