mirror of https://gitee.com/maxjhandsome/pig
🔖 Releasing / Version tags.2.1.0 包装spring security oauth2 使用细节,一个注解接入
This commit is contained in:
parent
137cc8d1d4
commit
fc7e7cb977
|
@ -9,11 +9,11 @@ end_of_line = lf
|
|||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{java,xml}]
|
||||
[*.{java, xml}]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[*.{yml,json}]
|
||||
[*.{yml, json}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
|
|
14
README.md
14
README.md
|
@ -25,10 +25,10 @@
|
|||
依赖 | 版本
|
||||
---|---
|
||||
Spring Boot | 2.0.8.RELEASE
|
||||
Spring Cloud | Finchley.SR2
|
||||
Spring Cloud | Finchley.SR3
|
||||
Spring Security OAuth2 | 2.3.3
|
||||
Mybatis Plus | 3.0.6
|
||||
hutool | 4.3.3
|
||||
Mybatis Plus | 3.1.0
|
||||
hutool | 4.5.0
|
||||
Avue | 1.5.0
|
||||
|
||||
|
||||
|
@ -66,11 +66,7 @@ pig
|
|||
![](http://a.pigx.top/20190201155120.png)
|
||||
|
||||
|
||||
#### 鸣谢
|
||||
#### 关注我们
|
||||
|
||||
avue [@smallwei](https://avue.top)
|
||||
mica-auto [@dreamlu](https://dreamlu.net)
|
||||
bladex [@smallc](http://bladex.vip)
|
||||
mybatis-plus [@青苗](http://mp.baomidou.com)
|
||||
hutool [@路小磊](https://dreamlu.net)
|
||||
|
||||
![](http://pic.pigx.top/20190308224043_luIWau_Screenshot.jpeg)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-auth</artifactId>
|
||||
|
@ -39,13 +39,13 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--security-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-security</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--JDBC相关-->
|
||||
<dependency>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package com.pig4cloud.pig.auth.handler;
|
||||
|
||||
import com.pig4cloud.pig.common.security.handler.AuthenticationFailureEvenHandler;
|
||||
import com.pig4cloud.pig.common.security.handler.AbstractAuthenticationFailureEvenHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
@ -28,7 +28,7 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PigAuthenticationFailureEvenHandler extends AuthenticationFailureEvenHandler {
|
||||
public class PigAuthenticationFailureEvenHandler extends AbstractAuthenticationFailureEvenHandler {
|
||||
|
||||
/**
|
||||
* 处理登录失败方法
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package com.pig4cloud.pig.auth.handler;
|
||||
|
||||
import com.pig4cloud.pig.common.security.handler.AuthenticationSuccessEventHandler;
|
||||
import com.pig4cloud.pig.common.security.handler.AbstractAuthenticationSuccessEventHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -27,7 +27,7 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PigAuthenticationSuccessEventHandler extends AuthenticationSuccessEventHandler {
|
||||
public class PigAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler {
|
||||
|
||||
/**
|
||||
* 处理登录成功方法
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
|
|
|
@ -42,10 +42,10 @@ public class FilterIgnorePropertiesConfig {
|
|||
private List<String> clients = new ArrayList<>();
|
||||
/**
|
||||
* 放行url,放行的url不再被安全框架拦截
|
||||
*/
|
||||
*/
|
||||
private List<String> urls = new ArrayList<>();
|
||||
/**
|
||||
* 不聚合swagger
|
||||
*/
|
||||
private List<String> swaggerProviders =new ArrayList<>();
|
||||
private List<String> swaggerProviders = new ArrayList<>();
|
||||
}
|
||||
|
|
|
@ -67,13 +67,7 @@ public interface SecurityConstants {
|
|||
/**
|
||||
* oauth 客户端信息
|
||||
*/
|
||||
String CLIENT_DETAILS_KEY = PROJECT_PREFIX+OAUTH_PREFIX+"client:details";
|
||||
|
||||
/**
|
||||
* 微信获取OPENID
|
||||
*/
|
||||
String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" +
|
||||
"?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
|
||||
String CLIENT_DETAILS_KEY = PROJECT_PREFIX + OAUTH_PREFIX + "client:details";
|
||||
|
||||
/**
|
||||
* {bcrypt} 加密的特征码
|
||||
|
@ -102,4 +96,8 @@ public interface SecurityConstants {
|
|||
*/
|
||||
String DEFAULT_SELECT_STATEMENT = BASE_FIND_STATEMENT + " where client_id = ?";
|
||||
|
||||
/***
|
||||
* 资源服务器默认bean名称
|
||||
*/
|
||||
String RESOURCE_SERVER_CONFIGURER = "resourceServerConfigurerAdapter";
|
||||
}
|
||||
|
|
|
@ -16,56 +16,57 @@
|
|||
-->
|
||||
|
||||
<configuration debug="false" scan="false">
|
||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||
<property name="log.path" value="logs/${spring.application.name}" />
|
||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||
<property name="log.path" value="logs/${spring.application.name}"/>
|
||||
<!-- 彩色日志格式 -->
|
||||
<property name="CONSOLE_LOG_PATTERN"
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||
<conversionRule conversionWord="wex"
|
||||
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
|
||||
<conversionRule conversionWord="wEx"
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="debug" />
|
||||
<appender-ref ref="error" />
|
||||
</root>
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
</root>
|
||||
</configuration>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-log</artifactId>
|
||||
|
@ -35,13 +35,13 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--UPMS接口模块-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--安全依赖获取上下文信息-->
|
||||
<dependency>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common-security</artifactId>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--安全模块-->
|
||||
<dependency>
|
||||
|
@ -46,7 +46,7 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -14,20 +14,29 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pig.admin.config;
|
||||
package com.pig4cloud.pig.common.security.annotation;
|
||||
|
||||
import com.pig4cloud.pig.common.security.component.BaseResourceServerConfigurerAdapter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import com.pig4cloud.pig.common.security.component.PigResourceServerAutoConfiguration;
|
||||
import com.pig4cloud.pig.common.security.component.PigSecurityBeanDefinitionRegistrar;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/2/1
|
||||
* @date 2019/03/08
|
||||
* <p>
|
||||
* 资源服务注解
|
||||
*/
|
||||
@Configuration
|
||||
@Documented
|
||||
@Inherited
|
||||
@EnableResourceServer
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter {
|
||||
@Import({PigResourceServerAutoConfiguration.class, PigSecurityBeanDefinitionRegistrar.class})
|
||||
public @interface EnablePigResourceServer {
|
||||
|
||||
}
|
|
@ -1,144 +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.security.component;
|
||||
|
||||
import com.pig4cloud.pig.common.core.config.FilterIgnorePropertiesConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
|
||||
import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter;
|
||||
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/2/1
|
||||
* <p>
|
||||
* 1. 支持remoteTokenServices 负载均衡
|
||||
* 2. 支持 获取用户全部信息
|
||||
*/
|
||||
public abstract class BaseResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter {
|
||||
@Autowired
|
||||
protected ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint;
|
||||
@Autowired
|
||||
protected PigAccessDeniedHandler pigAccessDeniedHandler;
|
||||
@Autowired
|
||||
protected RemoteTokenServices remoteTokenServices;
|
||||
@Autowired
|
||||
protected UserDetailsService userDetailsService;
|
||||
@Autowired
|
||||
private FilterIgnorePropertiesConfig filterIgnorePropertiesConfig;
|
||||
|
||||
|
||||
/**
|
||||
* 默认的配置,对外暴露
|
||||
*
|
||||
* @param http
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void configure(HttpSecurity http) throws Exception{
|
||||
//允许使用iframe 嵌套,避免swagger-ui 不被加载的问题
|
||||
http.headers().frameOptions().disable();
|
||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>
|
||||
.ExpressionInterceptUrlRegistry registry = http
|
||||
.authorizeRequests();
|
||||
filterIgnorePropertiesConfig.getUrls()
|
||||
.forEach(url -> registry.antMatchers(url).permitAll());
|
||||
registry.anyRequest().authenticated()
|
||||
.and().csrf().disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供子类重写
|
||||
* <p>
|
||||
* 1. 不重写,默认支持获取雍熙
|
||||
* 2. 重写notGetUser,提供性能
|
||||
* <p>
|
||||
* see codegen ResourceServerConfigurer
|
||||
*
|
||||
* @param resources
|
||||
*/
|
||||
@Override
|
||||
public void configure(ResourceServerSecurityConfigurer resources) {
|
||||
canGetUser(resources);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@LoadBalanced
|
||||
public RestTemplate lbRestTemplate() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) {
|
||||
super.handleError(response);
|
||||
}
|
||||
}
|
||||
});
|
||||
return restTemplate;
|
||||
}
|
||||
/**
|
||||
* 不获取用户详细 只有用户名
|
||||
*
|
||||
* @param resources
|
||||
*/
|
||||
protected void notGetUser(ResourceServerSecurityConfigurer resources) {
|
||||
DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
|
||||
DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter();
|
||||
accessTokenConverter.setUserTokenConverter(userTokenConverter);
|
||||
|
||||
remoteTokenServices.setRestTemplate(lbRestTemplate());
|
||||
remoteTokenServices.setAccessTokenConverter(accessTokenConverter);
|
||||
resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint)
|
||||
.accessDeniedHandler(pigAccessDeniedHandler)
|
||||
.tokenServices(remoteTokenServices);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上下文中获取用户全部信息,两次调用userDetailsService,影响性能
|
||||
*
|
||||
* @param resources
|
||||
*/
|
||||
private void canGetUser(ResourceServerSecurityConfigurer resources) {
|
||||
DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
|
||||
DefaultUserAuthenticationConverter userTokenConverter = new DefaultUserAuthenticationConverter();
|
||||
userTokenConverter.setUserDetailsService(userDetailsService);
|
||||
accessTokenConverter.setUserTokenConverter(userTokenConverter);
|
||||
|
||||
remoteTokenServices.setRestTemplate(lbRestTemplate());
|
||||
remoteTokenServices.setAccessTokenConverter(accessTokenConverter);
|
||||
resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint)
|
||||
.accessDeniedHandler(pigAccessDeniedHandler)
|
||||
.tokenServices(remoteTokenServices);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.security.component;
|
||||
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/03/08
|
||||
*/
|
||||
@ComponentScan("com.pig4cloud.pig.common.security")
|
||||
public class PigResourceServerAutoConfiguration {
|
||||
@Bean
|
||||
@Primary
|
||||
@LoadBalanced
|
||||
public RestTemplate lbRestTemplate() {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
if (response.getRawStatusCode() != HttpStatus.BAD_REQUEST.value()) {
|
||||
super.handleError(response);
|
||||
}
|
||||
}
|
||||
});
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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.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;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
|
||||
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;
|
||||
import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/03/08
|
||||
*
|
||||
* <p>
|
||||
* 1. 支持remoteTokenServices 负载均衡
|
||||
* 2. 支持 获取用户全部信息
|
||||
*/
|
||||
@Slf4j
|
||||
public class PigResourceServerConfigurerAdapter extends ResourceServerConfigurerAdapter {
|
||||
@Autowired
|
||||
protected ResourceAuthExceptionEntryPoint resourceAuthExceptionEntryPoint;
|
||||
@Autowired
|
||||
protected RemoteTokenServices remoteTokenServices;
|
||||
@Autowired
|
||||
private FilterIgnorePropertiesConfig ignorePropertiesConfig;
|
||||
@Autowired
|
||||
private RestTemplate lbRestTemplate;
|
||||
|
||||
/**
|
||||
* 默认的配置,对外暴露
|
||||
*
|
||||
* @param httpSecurity
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void configure(HttpSecurity httpSecurity) {
|
||||
//允许使用iframe 嵌套,避免swagger-ui 不被加载的问题
|
||||
httpSecurity.headers().frameOptions().disable();
|
||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>
|
||||
.ExpressionInterceptUrlRegistry registry = httpSecurity
|
||||
.authorizeRequests();
|
||||
ignorePropertiesConfig.getUrls()
|
||||
.forEach(url -> registry.antMatchers(url).permitAll());
|
||||
registry.anyRequest().authenticated()
|
||||
.and().csrf().disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(ResourceServerSecurityConfigurer resources) {
|
||||
DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();
|
||||
UserAuthenticationConverter userTokenConverter = new PigUserAuthenticationConverter();
|
||||
accessTokenConverter.setUserTokenConverter(userTokenConverter);
|
||||
|
||||
remoteTokenServices.setRestTemplate(lbRestTemplate);
|
||||
remoteTokenServices.setAccessTokenConverter(accessTokenConverter);
|
||||
resources.authenticationEntryPoint(resourceAuthExceptionEntryPoint)
|
||||
.tokenServices(remoteTokenServices);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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.security.component;
|
||||
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/03/08
|
||||
*/
|
||||
@Slf4j
|
||||
public class PigSecurityBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
|
||||
/**
|
||||
* 根据注解值动态注入资源服务器的相关属性
|
||||
*
|
||||
* @param metadata 注解信息
|
||||
* @param registry 注册器
|
||||
*/
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
|
||||
if (registry.isBeanNameInUse(SecurityConstants.RESOURCE_SERVER_CONFIGURER)) {
|
||||
log.warn("本地存在资源服务器配置,覆盖默认配置:" + SecurityConstants.RESOURCE_SERVER_CONFIGURER);
|
||||
return;
|
||||
}
|
||||
|
||||
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
|
||||
beanDefinition.setBeanClass(PigResourceServerConfigurerAdapter.class);
|
||||
registry.registerBeanDefinition(SecurityConstants.RESOURCE_SERVER_CONFIGURER, beanDefinition);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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.security.component;
|
||||
|
||||
import com.pig4cloud.pig.common.security.service.PigUser;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019-03-07
|
||||
* <p>
|
||||
* 根据checktoken 的结果转化用户信息
|
||||
*/
|
||||
public class PigUserAuthenticationConverter implements UserAuthenticationConverter {
|
||||
private static final String USER_ID = "user_id";
|
||||
private static final String DEPT_ID = "dept_id";
|
||||
private static final String TENANT_ID = "tenant_id";
|
||||
private static final String N_A = "N/A";
|
||||
|
||||
/**
|
||||
* Extract information about the user to be used in an access token (i.e. for resource servers).
|
||||
*
|
||||
* @param authentication an authentication representing a user
|
||||
* @return a map of key values representing the unique information about the user
|
||||
*/
|
||||
@Override
|
||||
public Map<String, ?> convertUserAuthentication(Authentication authentication) {
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put(USERNAME, authentication.getName());
|
||||
if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) {
|
||||
response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(authentication.getAuthorities()));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map.
|
||||
*
|
||||
* @param map a map of user information
|
||||
* @return an Authentication representing the user or null if there is none
|
||||
*/
|
||||
@Override
|
||||
public Authentication extractAuthentication(Map<String, ?> map) {
|
||||
if (map.containsKey(USERNAME)) {
|
||||
Collection<? extends GrantedAuthority> authorities = getAuthorities(map);
|
||||
|
||||
String username = (String) map.get(USERNAME);
|
||||
Integer id = (Integer) map.get(USER_ID);
|
||||
Integer deptId = (Integer) map.get(DEPT_ID);
|
||||
PigUser user = new PigUser(id, deptId, username, N_A, true
|
||||
, true, true, true, authorities);
|
||||
return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Collection<? extends GrantedAuthority> getAuthorities(Map<String, ?> map) {
|
||||
Object authorities = map.get(AUTHORITIES);
|
||||
if (authorities instanceof String) {
|
||||
return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities);
|
||||
}
|
||||
if (authorities instanceof Collection) {
|
||||
return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils
|
||||
.collectionToCommaDelimitedString((Collection<?>) authorities));
|
||||
}
|
||||
throw new IllegalArgumentException("Authorities must be either a String or a Collection");
|
||||
}
|
||||
}
|
|
@ -39,6 +39,6 @@ public class PigFeignClientConfiguration {
|
|||
public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext,
|
||||
OAuth2ProtectedResourceDetails resource,
|
||||
AccessTokenContextRelay accessTokenContextRelay) {
|
||||
return new PigFeignClientInterceptor(oAuth2ClientContext, resource,accessTokenContextRelay);
|
||||
return new PigFeignClientInterceptor(oAuth2ClientContext, resource, accessTokenContextRelay);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.springframework.security.core.AuthenticationException;
|
|||
* @date 2019/2/1
|
||||
* 认证失败事件处理器
|
||||
*/
|
||||
public abstract class AuthenticationFailureEvenHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {
|
||||
public abstract class AbstractAuthenticationFailureEvenHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {
|
||||
|
||||
/**
|
||||
* Handle an application event.
|
|
@ -26,7 +26,7 @@ import org.springframework.security.core.Authentication;
|
|||
* @date 2019/2/1
|
||||
* 认证成功事件处理器
|
||||
*/
|
||||
public abstract class AuthenticationSuccessEventHandler implements ApplicationListener<AuthenticationSuccessEvent> {
|
||||
public abstract class AbstractAuthenticationSuccessEventHandler implements ApplicationListener<AuthenticationSuccessEvent> {
|
||||
/**
|
||||
* Handle an application event.
|
||||
*
|
|
@ -1,8 +1,2 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.pig4cloud.pig.common.security.component.PermissionService,\
|
||||
com.pig4cloud.pig.common.security.component.PigAccessDeniedHandler,\
|
||||
com.pig4cloud.pig.common.security.component.PigSecurityInnerAspect,\
|
||||
com.pig4cloud.pig.common.security.component.ResourceAuthExceptionEntryPoint,\
|
||||
com.pig4cloud.pig.common.security.component.PigResourceServerTokenRelayAutoConfiguration,\
|
||||
com.pig4cloud.pig.common.security.feign.PigFeignClientConfiguration,\
|
||||
com.pig4cloud.pig.common.security.service.PigUserDetailsServiceImpl
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-common</artifactId>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-config</artifactId>
|
||||
|
|
|
@ -4,38 +4,38 @@ spring:
|
|||
locator:
|
||||
enabled: true
|
||||
routes:
|
||||
# 认证中心
|
||||
- id: pig-auth
|
||||
uri: lb://pig-auth
|
||||
predicates:
|
||||
- Path=/auth/**
|
||||
filters:
|
||||
# 验证码处理
|
||||
- ValidateCodeGatewayFilter
|
||||
# 前端密码解密
|
||||
- PasswordDecoderFilter
|
||||
#UPMS 模块
|
||||
- id: pig-upms
|
||||
uri: lb://pig-upms
|
||||
predicates:
|
||||
- Path=/admin/**
|
||||
filters:
|
||||
# 限流配置
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
key-resolver: '#{@remoteAddrKeyResolver}'
|
||||
redis-rate-limiter.replenishRate: 10
|
||||
redis-rate-limiter.burstCapacity: 20
|
||||
# 降级配置
|
||||
- name: Hystrix
|
||||
args:
|
||||
name: default
|
||||
fallbackUri: 'forward:/fallback'
|
||||
# 代码生成模块
|
||||
- id: pig-codegen
|
||||
uri: lb://pig-codegen
|
||||
predicates:
|
||||
- Path=/gen/**
|
||||
# 认证中心
|
||||
- id: pig-auth
|
||||
uri: lb://pig-auth
|
||||
predicates:
|
||||
- Path=/auth/**
|
||||
filters:
|
||||
# 验证码处理
|
||||
- ValidateCodeGatewayFilter
|
||||
# 前端密码解密
|
||||
- PasswordDecoderFilter
|
||||
#UPMS 模块
|
||||
- id: pig-upms
|
||||
uri: lb://pig-upms
|
||||
predicates:
|
||||
- Path=/admin/**
|
||||
filters:
|
||||
# 限流配置
|
||||
- name: RequestRateLimiter
|
||||
args:
|
||||
key-resolver: '#{@remoteAddrKeyResolver}'
|
||||
redis-rate-limiter.replenishRate: 10
|
||||
redis-rate-limiter.burstCapacity: 20
|
||||
# 降级配置
|
||||
- name: Hystrix
|
||||
args:
|
||||
name: default
|
||||
fallbackUri: 'forward:/fallback'
|
||||
# 代码生成模块
|
||||
- id: pig-codegen
|
||||
uri: lb://pig-codegen
|
||||
predicates:
|
||||
- Path=/gen/**
|
||||
|
||||
|
||||
security:
|
||||
|
|
|
@ -16,56 +16,57 @@
|
|||
-->
|
||||
|
||||
<configuration debug="false" scan="false">
|
||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||
<property name="log.path" value="logs/${spring.application.name}" />
|
||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||
<property name="log.path" value="logs/${spring.application.name}"/>
|
||||
<!-- 彩色日志格式 -->
|
||||
<property name="CONSOLE_LOG_PATTERN"
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||
<conversionRule conversionWord="wex"
|
||||
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
|
||||
<conversionRule conversionWord="wEx"
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="debug" />
|
||||
<appender-ref ref="error" />
|
||||
</root>
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
</root>
|
||||
</configuration>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-eureka</artifactId>
|
||||
|
|
|
@ -16,56 +16,57 @@
|
|||
-->
|
||||
|
||||
<configuration debug="false" scan="false">
|
||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||
<property name="log.path" value="logs/${spring.application.name}" />
|
||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||
<property name="log.path" value="logs/${spring.application.name}"/>
|
||||
<!-- 彩色日志格式 -->
|
||||
<property name="CONSOLE_LOG_PATTERN"
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}" />
|
||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||
<conversionRule conversionWord="wex"
|
||||
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
|
||||
<conversionRule conversionWord="wEx"
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||
<!-- Console log output -->
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!-- Log file debug output -->
|
||||
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/debug.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console" />
|
||||
<appender-ref ref="debug" />
|
||||
<appender-ref ref="error" />
|
||||
</root>
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
</root>
|
||||
</configuration>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-gateway</artifactId>
|
||||
|
@ -54,7 +54,7 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
|
|||
|
||||
// 不是登录请求,直接向下执行
|
||||
if (!StrUtil.containsAnyIgnoreCase(request.getURI().getPath()
|
||||
, SecurityConstants.OAUTH_TOKEN_URL)) {
|
||||
, SecurityConstants.OAUTH_TOKEN_URL)) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
|
@ -81,9 +81,9 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
|
|||
response.setStatusCode(HttpStatus.PRECONDITION_REQUIRED);
|
||||
try {
|
||||
return response.writeWith(Mono.just(response.bufferFactory()
|
||||
.wrap(objectMapper.writeValueAsBytes(
|
||||
R.builder().msg(e.getMessage())
|
||||
.code(CommonConstants.FAIL).build()))));
|
||||
.wrap(objectMapper.writeValueAsBytes(
|
||||
R.builder().msg(e.getMessage())
|
||||
.code(CommonConstants.FAIL).build()))));
|
||||
} catch (JsonProcessingException e1) {
|
||||
log.error("对象输出异常", e1);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
|
@ -35,7 +35,7 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -107,5 +107,4 @@ public class SysLog implements Serializable {
|
|||
private String delFlag;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package com.pig4cloud.pig.admin.api.feign;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.feign.factory.RemoteUserServiceFallbackFactory;
|
||||
import com.pig4cloud.pig.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pig.admin.api.feign.factory.RemoteUserServiceFallbackFactory;
|
||||
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pig.common.core.constant.ServiceNameConstants;
|
||||
import com.pig4cloud.pig.common.core.util.R;
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package com.pig4cloud.pig.admin.api.feign.factory;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.feign.fallback.RemoteLogServiceFallbackImpl;
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteLogService;
|
||||
import com.pig4cloud.pig.admin.api.feign.fallback.RemoteLogServiceFallbackImpl;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package com.pig4cloud.pig.admin.api.feign.factory;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.feign.fallback.RemoteTokenServiceFallbackImpl;
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteTokenService;
|
||||
import com.pig4cloud.pig.admin.api.feign.fallback.RemoteTokenServiceFallbackImpl;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package com.pig4cloud.pig.admin.api.feign.factory;
|
||||
|
||||
import com.pig4cloud.pig.admin.api.feign.fallback.RemoteUserServiceFallbackImpl;
|
||||
import com.pig4cloud.pig.admin.api.feign.RemoteUserService;
|
||||
import com.pig4cloud.pig.admin.api.feign.fallback.RemoteUserServiceFallbackImpl;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
|
@ -51,7 +51,6 @@ public class RemoteTokenServiceFallbackImpl implements RemoteTokenService {
|
|||
/**
|
||||
* 删除token
|
||||
*
|
||||
*
|
||||
* @param s
|
||||
* @param id
|
||||
* @return
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-upms-biz</artifactId>
|
||||
|
@ -34,19 +34,19 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-upms-api</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--安全模块-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-security</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--日志处理-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-log</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--配置中心客户端-->
|
||||
<dependency>
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.pig4cloud.pig.admin;
|
|||
|
||||
|
||||
import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients;
|
||||
import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
|
|||
* @date 2018年06月21日
|
||||
* 用户统一管理系统
|
||||
*/
|
||||
@EnablePigResourceServer
|
||||
@EnablePigFeignClients
|
||||
@SpringCloudApplication
|
||||
public class PigAdminApplication {
|
||||
|
|
|
@ -57,12 +57,12 @@ public class MenuController {
|
|||
// 获取符合条件的菜单
|
||||
Set<MenuVO> all = new HashSet<>();
|
||||
SecurityUtils.getRoles()
|
||||
.forEach(roleId -> all.addAll(sysMenuService.getMenuByRoleId(roleId)));
|
||||
.forEach(roleId -> all.addAll(sysMenuService.getMenuByRoleId(roleId)));
|
||||
List<MenuTree> menuTreeList = all.stream()
|
||||
.filter(menuVo -> CommonConstants.MENU.equals(menuVo.getType()))
|
||||
.map(MenuTree::new)
|
||||
.sorted(Comparator.comparingInt(MenuTree::getSort))
|
||||
.collect(Collectors.toList());
|
||||
.filter(menuVo -> CommonConstants.MENU.equals(menuVo.getType()))
|
||||
.map(MenuTree::new)
|
||||
.sorted(Comparator.comparingInt(MenuTree::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return new R<>(TreeUtil.buildByLoop(menuTreeList, -1));
|
||||
}
|
||||
|
||||
|
@ -85,9 +85,9 @@ public class MenuController {
|
|||
@GetMapping("/tree/{roleId}")
|
||||
public List getRoleTree(@PathVariable Integer roleId) {
|
||||
return sysMenuService.getMenuByRoleId(roleId)
|
||||
.stream()
|
||||
.map(MenuVO::getMenuId)
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.map(MenuVO::getMenuId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,7 @@ public class UserController {
|
|||
public R info() {
|
||||
String username = SecurityUtils.getUser().getUsername();
|
||||
SysUser user = userService.getOne(Wrappers.<SysUser>query()
|
||||
.lambda().eq(SysUser::getUsername, username));
|
||||
.lambda().eq(SysUser::getUsername, username));
|
||||
if (user == null) {
|
||||
return new R<>(Boolean.FALSE, "获取当前用户信息失败");
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class UserController {
|
|||
@GetMapping("/info/{username}")
|
||||
public R info(@PathVariable String username) {
|
||||
SysUser user = userService.getOne(Wrappers.<SysUser>query()
|
||||
.lambda().eq(SysUser::getUsername, username));
|
||||
.lambda().eq(SysUser::getUsername, username));
|
||||
if (user == null) {
|
||||
return new R<>(Boolean.FALSE, String.format("用户信息为空 %s", username));
|
||||
}
|
||||
|
|
|
@ -60,16 +60,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
public R removeMenuById(Integer id) {
|
||||
// 查询父节点为当前节点的节点
|
||||
List<SysMenu> menuList = this.list(Wrappers.<SysMenu>query()
|
||||
.lambda().eq(SysMenu::getParentId, id));
|
||||
.lambda().eq(SysMenu::getParentId, id));
|
||||
if (CollUtil.isNotEmpty(menuList)) {
|
||||
return R.builder()
|
||||
.code(CommonConstants.FAIL)
|
||||
.msg("菜单含有下级不能删除").build();
|
||||
.code(CommonConstants.FAIL)
|
||||
.msg("菜单含有下级不能删除").build();
|
||||
}
|
||||
|
||||
sysRoleMenuMapper
|
||||
.delete(Wrappers.<SysRoleMenu>query()
|
||||
.lambda().eq(SysRoleMenu::getMenuId, id));
|
||||
.delete(Wrappers.<SysRoleMenu>query()
|
||||
.lambda().eq(SysRoleMenu::getMenuId, id));
|
||||
|
||||
//删除当前菜单及其子菜单
|
||||
return new R(this.removeById(id));
|
||||
|
|
|
@ -112,25 +112,25 @@
|
|||
|
||||
<select id="getUserVoByUsername" resultMap="userVoResultMap">
|
||||
SELECT
|
||||
<include refid="userRoleSql"/>
|
||||
<include refid="userRoleSql"/>
|
||||
FROM
|
||||
sys_user AS `user`
|
||||
LEFT JOIN sys_user_role AS ur ON ur.user_id = `user`.user_id
|
||||
LEFT JOIN sys_role AS r ON r.role_id = ur.role_id
|
||||
WHERE `user`.username = #{username}
|
||||
WHERE `user`.username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="getUserVoById" resultMap="userVoResultMap">
|
||||
SELECT
|
||||
<include refid="userRoleDeptSql"/>
|
||||
FROM
|
||||
sys_user AS `user`
|
||||
LEFT JOIN sys_user_role AS ur ON ur.user_id = `user`.user_id
|
||||
LEFT JOIN sys_role AS r ON r.role_id = ur.role_id
|
||||
LEFT JOIN sys_dept AS d ON d.dept_id = `user`.dept_id
|
||||
WHERE
|
||||
`user`.user_id = #{id}
|
||||
</select>
|
||||
SELECT
|
||||
<include refid="userRoleDeptSql"/>
|
||||
FROM
|
||||
sys_user AS `user`
|
||||
LEFT JOIN sys_user_role AS ur ON ur.user_id = `user`.user_id
|
||||
LEFT JOIN sys_role AS r ON r.role_id = ur.role_id
|
||||
LEFT JOIN sys_dept AS d ON d.dept_id = `user`.dept_id
|
||||
WHERE
|
||||
`user`.user_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getUserVosPage" resultMap="baseResultMap">
|
||||
SELECT
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-upms</artifactId>
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-visual</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-codegen</artifactId>
|
||||
|
@ -50,13 +50,13 @@
|
|||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--安全模块-->
|
||||
<dependency>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-common-security</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<!--代码生成模板引擎-->
|
||||
<dependency>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.pig4cloud.pig.codegen;
|
||||
|
||||
import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients;
|
||||
import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
|
||||
|
@ -25,8 +26,9 @@ import org.springframework.cloud.client.SpringCloudApplication;
|
|||
* @date 2019/2/1
|
||||
* 代码生成模块
|
||||
*/
|
||||
@SpringCloudApplication
|
||||
@EnablePigFeignClients
|
||||
@EnablePigResourceServer
|
||||
@SpringCloudApplication
|
||||
public class PigCodeGenApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,45 +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.codegen.config;
|
||||
|
||||
import com.pig4cloud.pig.common.security.component.BaseResourceServerConfigurerAdapter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
||||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/2/1
|
||||
*/
|
||||
@Configuration
|
||||
@EnableResourceServer
|
||||
@AllArgsConstructor
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class ResourceServerConfigurer extends BaseResourceServerConfigurerAdapter {
|
||||
|
||||
/**
|
||||
* 重写抽象类实现,不需要调用feign 获取 userDetailsService
|
||||
*
|
||||
* @param resources
|
||||
*/
|
||||
@Override
|
||||
public void configure(ResourceServerSecurityConfigurer resources) {
|
||||
notGetUser(resources);
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ public class SysGeneratorController {
|
|||
*/
|
||||
@GetMapping("/page")
|
||||
public R<IPage> list(Page page, String tableName) {
|
||||
return new R<>(sysGeneratorService.queryPage(page,tableName));
|
||||
return new R<>(sysGeneratorService.queryPage(page, tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,7 @@ public interface SysGeneratorService {
|
|||
|
||||
/**
|
||||
* 分页查询表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -20,9 +20,9 @@ import cn.hutool.core.io.IoUtil;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pig.codegen.entity.GenConfig;
|
||||
import com.pig4cloud.pig.codegen.util.GenUtils;
|
||||
import com.pig4cloud.pig.codegen.mapper.SysGeneratorMapper;
|
||||
import com.pig4cloud.pig.codegen.service.SysGeneratorService;
|
||||
import com.pig4cloud.pig.codegen.util.GenUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class SysGeneratorServiceImpl implements SysGeneratorService {
|
|||
*/
|
||||
@Override
|
||||
public IPage<List<Map<String, Object>>> queryPage(Page page, String tableName) {
|
||||
return sysGeneratorMapper.queryList(page,tableName);
|
||||
return sysGeneratorMapper.queryList(page, tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,9 +20,9 @@ import cn.hutool.core.date.DateUtil;
|
|||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pig.codegen.entity.ColumnEntity;
|
||||
import com.pig4cloud.pig.codegen.entity.GenConfig;
|
||||
import com.pig4cloud.pig.codegen.entity.TableEntity;
|
||||
import com.pig4cloud.pig.codegen.entity.ColumnEntity;
|
||||
import com.pig4cloud.pig.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pig.common.core.exception.CheckedException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
|
@ -13,19 +13,15 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
|
||||
|
||||
mainPath=com.pig4cloud.pig
|
||||
#\u5305\u540D
|
||||
package=com.pig4cloud.pig
|
||||
moduleName=generator
|
||||
#\u4F5C\u8005
|
||||
author=pig code generator
|
||||
|
||||
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
|
||||
tablePrefix=tb_
|
||||
|
||||
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
|
||||
tinyint=Integer
|
||||
smallint=Integer
|
||||
|
@ -37,14 +33,12 @@ float=Float
|
|||
double=Double
|
||||
decimal=BigDecimal
|
||||
bit=Boolean
|
||||
|
||||
char=String
|
||||
varchar=String
|
||||
tinytext=String
|
||||
text=String
|
||||
mediumtext=String
|
||||
longtext=String
|
||||
|
||||
date=LocalDateTime
|
||||
datetime=LocalDateTime
|
||||
timestamp=LocalDateTime
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
|
||||
<mapper namespace="com.pig4cloud.pig.codegen.mapper.SysGeneratorMapper">
|
||||
<select id="queryList" resultType="map">
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
select table_name tableName, engine, table_comment tableComment, create_time createTime from
|
||||
information_schema.tables
|
||||
where table_schema = (select database())
|
||||
<if test="tableName != null and tableName.trim() != ''">
|
||||
and table_name like concat('%', #{tableName}, '%')
|
||||
</if>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig-visual</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-monitor</artifactId>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>pig-visual</artifactId>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ public class PigZipkinApplication {
|
|||
public static void main(String[] args) {
|
||||
SpringApplication.run(PigZipkinApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MySQLStorage mySQLStorage(DataSource datasource) {
|
||||
return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build();
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<parent>
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>pig-visual</artifactId>
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -21,7 +21,7 @@
|
|||
|
||||
<groupId>com.pig4cloud</groupId>
|
||||
<artifactId>pig</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>2.1.0</version>
|
||||
<name>${project.artifactId}</name>
|
||||
<packaging>pom</packaging>
|
||||
<url>https://www.pig4cloud.com</url>
|
||||
|
@ -33,7 +33,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<spring-boot-admin.version>2.0.4</spring-boot-admin.version>
|
||||
<spring-boot-admin.version>2.0.5</spring-boot-admin.version>
|
||||
<hutool.version>4.5.0</hutool.version>
|
||||
<mybatis-plus.version>3.1.0</mybatis-plus.version>
|
||||
<kaptcha.version>0.0.9</kaptcha.version>
|
||||
|
|
Loading…
Reference in New Issue