✨ 添加新特性。支持国际化、重构pigxresourceserver注解

This commit is contained in:
冷冷 committed 2018-11-14 21:02:26 +08:00
1 parent f8a9c21901
commit 0cd3f3fa65
53 files changed
+353 -101

No files matched your search

@@ -19,6 +19,7 @@ package com.pig4cloud.pigx.gateway.config;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -49,10 +50,6 @@ public class KaptchaConfiguration {
*/
private static final String DEFAULT_IMAGE_HEIGHT = "40";
/**
* 默认生成图形验证码长度
*/
private static final String DEFAULT_IMAGE_LENGTH = "4";
/**
* 边框颜色,合法值: r,g,b (and optional alpha) 或者 white,black,blue.
*/
@@ -80,7 +77,7 @@ public class KaptchaConfiguration {
properties.put(KAPTCHA_IMAGE_WIDTH, DEFAULT_IMAGE_WIDTH);
properties.put(KAPTCHA_IMAGE_HEIGHT, DEFAULT_IMAGE_HEIGHT);
properties.put(KAPTCHA_IMAGE_FONT_SIZE, DEFAULT_IMAGE_FONT_SIZE);
properties.put(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, DEFAULT_IMAGE_LENGTH);
properties.put(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, SecurityConstants.CODE_SIZE);
Config config = new Config(properties);
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
defaultKaptcha.setConfig(config);
@@ -20,6 +20,7 @@ package com.pig4cloud.pigx.gateway.filter;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.exception.CheckedException;
import com.pig4cloud.pigx.common.core.exception.ValidateCodeException;
import com.pig4cloud.pigx.gateway.config.FilterIgnorePropertiesConfig;
@@ -45,8 +46,7 @@ import java.io.IOException;
@Component
@AllArgsConstructor
public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
public static final String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY";
public static final String OAUTH_TOKEN_URL = "/oauth/token";
static final String OAUTH_TOKEN_URL = "/oauth/token";
private static final String BASIC_ = "Basic ";
private final RedisTemplate redisTemplate;
private final FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;
@@ -157,7 +157,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
throw new ValidateCodeException();
}
String key = DEFAULT_CODE_KEY + randomStr;
String key = CommonConstant.DEFAULT_CODE_KEY + randomStr;
if (!redisTemplate.hasKey(key)) {
throw new ValidateCodeException();
}
@@ -18,7 +18,8 @@
package com.pig4cloud.pigx.gateway.handler;
import com.google.code.kaptcha.Producer;
import com.pig4cloud.pigx.gateway.filter.ValidateCodeGatewayFilter;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ByteArrayResource;
@@ -58,7 +59,8 @@ public class ImageCodeHandler implements HandlerFunction<ServerResponse> {
//保存验证码信息
String randomStr = serverRequest.queryParam("randomStr").get();
redisTemplate.opsForValue().set(ValidateCodeGatewayFilter.DEFAULT_CODE_KEY + randomStr, text, 60, TimeUnit.SECONDS);
redisTemplate.opsForValue().set(CommonConstant.DEFAULT_CODE_KEY + randomStr, text
, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
// 转换流信息写出
FastByteArrayOutputStream os = new FastByteArrayOutputStream();