소스 검색

去掉redis和security

杨杰 6 년 전
부모
커밋
f2ed36891e

+ 0 - 4
pom.xml

@@ -37,10 +37,6 @@
 		</dependency>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-security</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-data-redis</artifactId>
 		</dependency>
 		<dependency>

+ 0 - 12
src/main/java/com/llisoft/service/file/config/ExceptionConfig.java

@@ -3,7 +3,6 @@ package com.llisoft.service.file.config;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.converter.HttpMessageNotReadableException;
-import org.springframework.security.access.AccessDeniedException;
 import org.springframework.web.bind.MethodArgumentNotValidException;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -46,17 +45,6 @@ public class ExceptionConfig {
     }
     
     /**
-     * 无权访问
-     * @param exception
-     * @return
-     */
-    @ExceptionHandler(AccessDeniedException.class)
-    public @ResponseBody ResponseVo<String> exception(AccessDeniedException exception){
-    	logger.warn("无权访问", exception);
-    	return ResponseVo.build(CodeEnum.C403);
-    }
-	
-    /**
      * 业务异常
      * @param exception
      * @return

+ 0 - 36
src/main/java/com/llisoft/service/file/config/SpringRedisConfig.java

@@ -1,36 +0,0 @@
-package com.llisoft.service.file.config;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.CacheManager;
-import org.springframework.cache.annotation.CachingConfigurerSupport;
-import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.cache.RedisCacheConfiguration;
-import org.springframework.data.redis.cache.RedisCacheManager;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.RedisSerializationContext;
-
-/**
- * Redis配置
- * @author YangJie [2018年12月26日]
- */
-@Configuration
-@EnableCaching // 开启缓存
-public class SpringRedisConfig extends CachingConfigurerSupport{
-	
-	@Autowired // 此对象有springboot自动创建
-	private RedisConnectionFactory redisConnectionFactory;
-
-	/**
-	 * 默认序列化方式为 #JdkSerializationRedisSerializer
-	 * 如要使用json需要将序列化方式改为 #GenericJackson2JsonRedisSerializer
-	 */
-	@Override
-	public CacheManager cacheManager() {
-		RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
-		config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
-		return RedisCacheManager.builder(redisConnectionFactory).cacheDefaults(config).build();
-	}
-	
-}

+ 0 - 15
src/main/java/com/llisoft/service/file/config/SpringSecurityConfig.java

@@ -1,15 +0,0 @@
-package com.llisoft.service.file.config;
-
-import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-
-/**
- * 安全配置
- * @author YangJie [2019年1月23日]
- */
-@EnableWebSecurity
-public class SpringSecurityConfig extends WebSecurityConfigurerAdapter{
-
-
-	
-}

+ 0 - 16
src/main/java/com/llisoft/service/file/config/SwaggerConfig.java

@@ -1,18 +1,13 @@
 package com.llisoft.service.file.config;
 
-import java.util.Arrays;
-
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
 import com.google.common.base.Predicates;
-import com.llisoft.common.constant.Constant;
 
 import springfox.documentation.builders.ApiInfoBuilder;
-import springfox.documentation.builders.ParameterBuilder;
 import springfox.documentation.builders.PathSelectors;
-import springfox.documentation.schema.ModelRef;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
@@ -31,17 +26,6 @@ public class SwaggerConfig {
 		return new Docket(DocumentationType.SWAGGER_2)
 			.apiInfo(new ApiInfoBuilder().title("文件服务API").version("v1.0.0").build())
 			.directModelSubstitute(byte.class, int.class) //修正byte转string的Bug
-			.globalOperationParameters( // header
-					Arrays.asList(
-						new ParameterBuilder()
-						.parameterType("header")
-						.name(Constant.HEADER_KEY_TOKEN)
-						.description("token")
-						.modelRef(new ModelRef("string"))
-						.required(false)
-						.build()
-					)
-				)
 			.select()
 			// 文档中需要屏蔽的接口
 			.paths(Predicates.not(PathSelectors.regex("/error.*")))

+ 3 - 2
src/main/java/com/llisoft/service/file/controller/FileController.java

@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.llisoft.service.file.service.OssService;
+import com.llisoft.service.file.vo.RequestDownloadVo;
 import com.llisoft.service.file.vo.RequestUploadVo;
 import com.llisoft.service.file.vo.ResponseUploadVo;
 
@@ -32,8 +33,8 @@ public class FileController {
 	
 	@ApiOperation(value="下载")
 	@PostMapping("/download")
-	public String download(String key) throws Exception{
-		return ossService.download(key);
+	public String download(@Valid @RequestBody RequestDownloadVo downloadVo) throws Exception{
+		return ossService.download(downloadVo.getKey());
 	}
 	
 }

+ 2 - 2
src/main/java/com/llisoft/service/file/service/OssService.java

@@ -64,11 +64,11 @@ public class OssService {
 		PolicyConditions policyConditions = new PolicyConditions();
 		policyConditions.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1024*1024*1024*1); // 内容长度范围1G
 		policyConditions.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, prefix); // key前缀
-		String postPolicy = ossClient.generatePostPolicy(this.getExpiration(10), policyConditions);
+		String postPolicy = ossClient.generatePostPolicy(this.getExpiration(10), policyConditions); // 有效期10分钟
 		String encodedPolicy = BinaryUtil.toBase64String(postPolicy.getBytes("utf-8"));
 		String postSignature = ossClient.calculatePostSignature(postPolicy);
 		ResponseUploadVo uploadBean = new ResponseUploadVo();
-		uploadBean.setKey(prefix + UUID.randomUUID().toString().replace("-", "") + suffix);
+		uploadBean.setKey(prefix + UUID.randomUUID().toString().replace("-", "") + "." + suffix);
 		uploadBean.setAccessid(accessKeyId);
 		uploadBean.setPolicy(encodedPolicy);
 		uploadBean.setSignature(postSignature);

+ 0 - 103
src/main/java/com/llisoft/service/file/util/RedisUtil.java

@@ -1,103 +0,0 @@
-package com.llisoft.service.file.util;
-
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.stereotype.Component;
-
-import com.llisoft.common.util.JsonUtil;
-
-/**
- * redis处理
- * @author YangJie [2018年12月26日]
- */
-@Component
-public class RedisUtil {
-	
-    private static StringRedisTemplate redisTemplate;
-    
-    @Autowired
-    public RedisUtil(StringRedisTemplate redisTemplate) {
-    	RedisUtil.redisTemplate = redisTemplate;
-    }
-    
-	
-	/**
-	 * 获取
-	 * @param key
-	 * @return
-	 */
-    public static String get(String key) {
-        return Objects.isNull(key) ? null : redisTemplate.opsForValue().get(key);
-    }
-	
-    /**
-     * 获取
-     * @param key
-     * @param clazz 目标对象类型
-     * @return
-     */
-    public static <T> T get(String key, Class<T> clazz) {
-    	String value = get(key);
-        return Objects.isNull(value) ? null : JsonUtil.toObject(value, clazz);
-    }
-    
-    /**
-     * 通过正则获取列表
-     * @param pattern
-     * @return
-     */
-    public static Set<String> gets(String pattern) {
-    	return redisTemplate.keys(pattern);
-    }
-    
-    /**
-     * 获取与 key 对应的对象
-     * @param key
-     * @param clazz 目标对象类型
-     * @return
-     */
-    public static long getExpire(String key) {
-    	return redisTemplate.getExpire(key);
-    }
-    
-    /**
-     * 保存
-     * @param key
-     * @param obj
-     */
-    public static void set(String key, Object obj) {
-    	redisTemplate.opsForValue().set(key, JsonUtil.toJson(obj));
-    }
-    
-    /**
-     * 保存
-     * @param key
-     * @param obj
-     * @param timeout 超时时间
-     * @param unit 时间单位
-     */
-    public static void set(String key, Object obj, long timeout, TimeUnit unit) {
-    	redisTemplate.opsForValue().set(key, JsonUtil.toJson(obj), timeout, unit);
-    }
-    
-    /**
-     * 删除
-     * @param key
-     */
-    public static void delete(String key) {
-    	redisTemplate.delete(key);
-    }
-    
-    /**
-     * 删除
-     * @param key
-     */
-    public static void deletes(String pattern) {
-    	redisTemplate.delete(gets(pattern));
-    }
-
-}

+ 0 - 13
src/main/resources/application.yml

@@ -24,19 +24,6 @@ spring:
   boot.admin.client:
     instance.preferIp: true #使用IP注册
     url: http://192.168.0.179:1111 #监控服务地址
-  ##redis配置
-  redis: 
-    host: 192.168.0.172
-    port: 6379
-    database: 10
-    password: 
-    timeout: 1000
-    jedis:
-      pool: 
-        minIdle: 0
-        maxIdle: 8
-        maxActive: 8
-        maxWait: -1
     
 ##注册中心配置
 eureka: