refactor: 重构部分代码,修改过期类引用

Closes #I14NWH
This commit is contained in:
冷冷 2019-11-09 10:46:46 +08:00
parent d656146bfb
commit fb60b8d000
26 changed files with 125 additions and 127 deletions

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-auth</artifactId>
@ -39,13 +39,13 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-upms-api</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--security-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-security</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--JDBC相关-->
<dependency>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-common-core</artifactId>

View File

@ -1,51 +0,0 @@
/*
* Copyright (c) 2019-2020, 冷冷 (wangiegie@gmail.com).
* <p>
* Licensed under the GNU Lesser General Public License 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.pig4cloud.pig.common.core.config;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* @author lengleng
* @date 2019/2/1
* 放行参数配置
*/
@Data
@Configuration
@RefreshScope
@ConditionalOnExpression("!'${ignore}'.isEmpty()")
@ConfigurationProperties(prefix = "ignore")
public class FilterIgnorePropertiesConfig {
/**
* 放行终端配置网关不校验此处的终端
*/
private List<String> clients = new ArrayList<>();
/**
* 放行url,放行的url不再被安全框架拦截
*/
private List<String> urls = new ArrayList<>();
/**
* 不聚合swagger
*/
private List<String> swaggerProviders = new ArrayList<>();
}

View File

@ -138,7 +138,7 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
* @param result 结果对象
*/
public void renderJson(HttpServletResponse response, Object result) {
renderJson(response, result, MediaType.APPLICATION_JSON_UTF8_VALUE);
renderJson(response, result, MediaType.APPLICATION_JSON_VALUE);
}
/**
@ -158,44 +158,6 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
}
}
/**
* 获取ip
*
* @return {String}
*/
public String getIP() {
return getIP(WebUtils.getRequest());
}
/**
* 获取ip
*
* @param request HttpServletRequest
* @return {String}
*/
public String getIP(HttpServletRequest request) {
Assert.notNull(request, "HttpServletRequest is null");
String ip = request.getHeader("X-Requested-For");
if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Forwarded-For");
}
if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return StringUtils.isBlank(ip) ? null : ip.split(",")[0];
}
/**
* 从request 获取CLIENT_ID

View File

@ -2,7 +2,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pig.common.core.config.JacksonConfig,\
com.pig4cloud.pig.common.core.config.RedisTemplateConfig,\
com.pig4cloud.pig.common.core.config.RestTemplateConfig,\
com.pig4cloud.pig.common.core.config.FilterIgnorePropertiesConfig,\
com.pig4cloud.pig.common.core.exception.GlobalExceptionHandler,\
com.pig4cloud.pig.common.core.util.SpringContextHolder,\
com.pig4cloud.pig.common.core.mybatis.WebMvcConfig

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-common-log</artifactId>
@ -35,13 +35,13 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-core</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--UPMS接口模块-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-upms-api</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--安全依赖获取上下文信息-->
<dependency>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-common-security</artifactId>
@ -35,7 +35,7 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-core</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--安全模块-->
<dependency>
@ -50,7 +50,7 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-upms-api</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pig.common.security.component;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import java.util.ArrayList;
import java.util.List;
/**
* @author lengleng
* @date 2019-11-09
* <p>
* 放行接口配置
*/
@Data
@RefreshScope
@ConfigurationProperties(prefix = "ignore")
public class PermitAllUrlConfiguration {
/**
* 放行url,支持 ant 表达式
*/
private List<String> urls = new ArrayList<>();
}

View File

@ -17,6 +17,7 @@
package com.pig4cloud.pig.common.security.component;
import lombok.SneakyThrows;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -30,6 +31,7 @@ import org.springframework.web.client.RestTemplate;
* @author lengleng
* @date 2019/03/08
*/
@ConfigurationPropertiesScan
@ComponentScan("com.pig4cloud.pig.common.security")
public class PigResourceServerAutoConfiguration {
@Bean

View File

@ -16,7 +16,6 @@
package com.pig4cloud.pig.common.security.component;
import com.pig4cloud.pig.common.core.config.FilterIgnorePropertiesConfig;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,10 +44,10 @@ public class PigResourceServerConfigurerAdapter extends ResourceServerConfigurer
@Autowired
protected RemoteTokenServices remoteTokenServices;
@Autowired
private FilterIgnorePropertiesConfig ignorePropertiesConfig;
@Autowired
private AccessDeniedHandler pigAccessDeniedHandler;
@Autowired
private PermitAllUrlConfiguration permitAllUrl;
@Autowired
private RestTemplate lbRestTemplate;
/**
@ -64,7 +63,7 @@ public class PigResourceServerConfigurerAdapter extends ResourceServerConfigurer
ExpressionUrlAuthorizationConfigurer<HttpSecurity>
.ExpressionInterceptUrlRegistry registry = httpSecurity
.authorizeRequests();
ignorePropertiesConfig.getUrls()
permitAllUrl.getUrls()
.forEach(url -> registry.antMatchers(url).permitAll());
registry.anyRequest().authenticated()
.and().csrf().disable();

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-common</artifactId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-config</artifactId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-eureka</artifactId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-gateway</artifactId>
@ -54,7 +54,7 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-core</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
</dependencies>

View File

@ -18,6 +18,7 @@ package com.pig4cloud.pig.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cloud.client.SpringCloudApplication;
/**
@ -27,6 +28,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
* 网关应用
*/
@SpringCloudApplication
@ConfigurationPropertiesScan
public class PigGatewayApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2025, lengleng 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 pig4cloud.com 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: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pig.gateway.config;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* @author lengleng
* @date 2019/2/1
* 放行参数配置
*/
@Data
@RefreshScope
@ConfigurationProperties(prefix = "ignore")
public class IgnoreClientConfiguration {
/**
* 放行终端配置网关不校验此处的终端
*/
private List<String> clients = new ArrayList<>();
}

View File

@ -19,12 +19,12 @@ package com.pig4cloud.pig.gateway.filter;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pig.common.core.config.FilterIgnorePropertiesConfig;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
import com.pig4cloud.pig.common.core.exception.ValidateCodeException;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.core.util.WebUtils;
import com.pig4cloud.pig.gateway.config.IgnoreClientConfiguration;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@ -46,9 +46,9 @@ import reactor.core.publisher.Mono;
@Component
@AllArgsConstructor
public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
private final IgnoreClientConfiguration ignoreClient;
private final ObjectMapper objectMapper;
private final RedisTemplate redisTemplate;
private final FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;
@Override
public GatewayFilter apply(Object config) {
@ -70,7 +70,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
// 终端设置不校验 直接向下执行
try {
String[] clientInfos = WebUtils.getClientId(request);
if (filterIgnorePropertiesConfig.getClients().contains(clientInfos[0])) {
if (ignoreClient.getClients().contains(clientInfos[0])) {
return chain.filter(exchange);
}

View File

@ -45,6 +45,6 @@ public class HystrixFallbackHandler implements HandlerFunction<ServerResponse> {
originalUris.ifPresent(originalUri -> log.error("网关执行请求:{}失败,hystrix服务降级处理", originalUri));
return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
.contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("服务异常"));
.contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromValue("服务异常"));
}
}

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-upms</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-upms-api</artifactId>
@ -35,7 +35,7 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-core</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
</dependencies>
</project>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-upms</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-upms-biz</artifactId>
@ -34,19 +34,19 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-upms-api</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--安全模块-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-security</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--日志处理-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-log</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--配置中心客户端-->
<dependency>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-upms</artifactId>

View File

@ -22,7 +22,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-visual</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-codegen</artifactId>
@ -50,13 +50,13 @@
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-core</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--安全模块-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-common-security</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</dependency>
<!--代码生成模板引擎-->
<dependency>

View File

@ -39,6 +39,7 @@ public interface SysGeneratorService {
/**
* 分页查询表
*
* @param page 分页参数
* @param tableName 表名
* @return
*/

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig-visual</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-monitor</artifactId>

View File

@ -21,7 +21,7 @@
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
</parent>
<artifactId>pig-visual</artifactId>

View File

@ -27,7 +27,7 @@
<groupId>com.pig4cloud</groupId>
<artifactId>pig</artifactId>
<version>2.5.1</version>
<version>2.5.2.snapshot</version>
<name>${project.artifactId}</name>
<packaging>pom</packaging>
<url>https://www.pig4cloud.com</url>