mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-31 08:14:18 +08:00
✨ Introducing new features. add module pig-common-mybatis
This commit is contained in:
parent
4ed31d354e
commit
b8c76e9003
@ -5,7 +5,7 @@
|
|||||||
<meta charset="UTF-8"/>
|
<meta charset="UTF-8"/>
|
||||||
<meta name="viewport"
|
<meta name="viewport"
|
||||||
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
|
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
|
||||||
<title>PigX第三方授权</title>
|
<title>Pig 第三方授权</title>
|
||||||
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"/>
|
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css"/>
|
||||||
<link rel="stylesheet" type="text/css" href="/css/signin.css"/>
|
<link rel="stylesheet" type="text/css" href="/css/signin.css"/>
|
||||||
</head>
|
</head>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="author" content="">
|
<meta name="author" content="">
|
||||||
|
|
||||||
<title>PigX微服务统一认证</title>
|
<title>Pig 微服务统一认证</title>
|
||||||
|
|
||||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="/css/signin.css" rel="stylesheet">
|
<link href="/css/signin.css" rel="stylesheet">
|
||||||
|
@ -49,21 +49,16 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--mybatis-->
|
<!--数据源-->
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
||||||
<version>${mybatis-plus.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!--多数据源-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.pig4cloud</groupId>
|
<groupId>com.pig4cloud</groupId>
|
||||||
<artifactId>pig-common-datasource</artifactId>
|
<artifactId>pig-common-datasource</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.pig4cloud</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>pig-common-mybatis</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--common-->
|
<!--common-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -21,7 +21,6 @@ package com.pig4cloud.pig.codegen;
|
|||||||
import com.pig4cloud.pig.common.datasource.annotation.EnableDynamicDataSource;
|
import com.pig4cloud.pig.common.datasource.annotation.EnableDynamicDataSource;
|
||||||
import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients;
|
import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients;
|
||||||
import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer;
|
import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer;
|
||||||
import com.pig4cloud.pigx.common.swagger.annotation.EnablePigSwagger2;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.cloud.client.SpringCloudApplication;
|
import org.springframework.cloud.client.SpringCloudApplication;
|
||||||
|
|
||||||
@ -31,13 +30,10 @@ import org.springframework.cloud.client.SpringCloudApplication;
|
|||||||
* 代码生成模块
|
* 代码生成模块
|
||||||
*/
|
*/
|
||||||
@EnableDynamicDataSource
|
@EnableDynamicDataSource
|
||||||
@EnablePigSwagger2
|
|
||||||
@EnablePigFeignClients
|
@EnablePigFeignClients
|
||||||
@SpringCloudApplication
|
@SpringCloudApplication
|
||||||
@EnablePigResourceServer
|
@EnablePigResourceServer
|
||||||
public class PigCodeGenApplication {
|
public class PigCodeGenApplication {
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(PigCodeGenApplication.class, args);
|
SpringApplication.run(PigCodeGenApplication.class, args);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
<version>${swagger.core.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,49 +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.mybatis;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lengleng
|
|
||||||
* @date 2019/2/1
|
|
||||||
* 数据权限查询参数
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class DataScope extends HashMap {
|
|
||||||
/**
|
|
||||||
* 限制范围的字段名称
|
|
||||||
*/
|
|
||||||
private String scopeName = "deptId";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 具体的数据范围
|
|
||||||
*/
|
|
||||||
private List<Integer> deptIds;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否只查询本部门
|
|
||||||
*/
|
|
||||||
private Boolean isOnly = false;
|
|
||||||
}
|
|
@ -1,127 +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.mybatis;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
|
||||||
import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler;
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
|
||||||
import org.apache.ibatis.mapping.BoundSql;
|
|
||||||
import org.apache.ibatis.mapping.MappedStatement;
|
|
||||||
import org.apache.ibatis.mapping.SqlCommandType;
|
|
||||||
import org.apache.ibatis.plugin.*;
|
|
||||||
import org.apache.ibatis.reflection.MetaObject;
|
|
||||||
import org.apache.ibatis.reflection.SystemMetaObject;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lengleng
|
|
||||||
* @date 2019/2/1
|
|
||||||
* <p>
|
|
||||||
* mybatis 数据权限拦截器
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
|
|
||||||
public class DataScopeInterceptor extends AbstractSqlParserHandler implements Interceptor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SneakyThrows
|
|
||||||
public Object intercept(Invocation invocation) {
|
|
||||||
StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
|
|
||||||
MetaObject metaObject = SystemMetaObject.forObject(statementHandler);
|
|
||||||
this.sqlParser(metaObject);
|
|
||||||
// 先判断是不是SELECT操作
|
|
||||||
MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
|
|
||||||
if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
|
|
||||||
return invocation.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
|
|
||||||
String originalSql = boundSql.getSql();
|
|
||||||
Object parameterObject = boundSql.getParameterObject();
|
|
||||||
|
|
||||||
//查找参数中包含DataScope类型的参数
|
|
||||||
DataScope dataScope = findDataScopeObject(parameterObject);
|
|
||||||
|
|
||||||
if (dataScope == null) {
|
|
||||||
return invocation.proceed();
|
|
||||||
} else {
|
|
||||||
String scopeName = dataScope.getScopeName();
|
|
||||||
List<Integer> deptIds = dataScope.getDeptIds();
|
|
||||||
if (StrUtil.isNotBlank(scopeName) && CollectionUtil.isNotEmpty(deptIds)) {
|
|
||||||
String join = CollectionUtil.join(deptIds, ",");
|
|
||||||
originalSql = "select * from (" + originalSql + ") temp_data_scope where temp_data_scope." + scopeName + " in (" + join + ")";
|
|
||||||
metaObject.setValue("delegate.boundSql.sql", originalSql);
|
|
||||||
}
|
|
||||||
return invocation.proceed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成拦截对象的代理
|
|
||||||
*
|
|
||||||
* @param target 目标对象
|
|
||||||
* @return 代理对象
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object plugin(Object target) {
|
|
||||||
if (target instanceof StatementHandler) {
|
|
||||||
return Plugin.wrap(target, this);
|
|
||||||
}
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mybatis配置的属性
|
|
||||||
*
|
|
||||||
* @param properties mybatis配置的属性
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setProperties(Properties properties) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查找参数是否包括DataScope对象
|
|
||||||
*
|
|
||||||
* @param parameterObj 参数列表
|
|
||||||
* @return DataScope
|
|
||||||
*/
|
|
||||||
private DataScope findDataScopeObject(Object parameterObj) {
|
|
||||||
if (parameterObj instanceof DataScope) {
|
|
||||||
return (DataScope) parameterObj;
|
|
||||||
} else if (parameterObj instanceof Map) {
|
|
||||||
for (Object val : ((Map<?, ?>) parameterObj).values()) {
|
|
||||||
if (val instanceof DataScope) {
|
|
||||||
return (DataScope) val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -37,8 +37,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* <p>
|
* <p>
|
||||||
* 动态数据源切换配置
|
* 动态数据源切换配置
|
||||||
*/
|
*/
|
||||||
@Configuration
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||||
@EnableConfigurationProperties(DataSourceProperties.class)
|
@EnableConfigurationProperties(DataSourceProperties.class)
|
||||||
public class DynamicDataSourceAutoConfiguration {
|
public class DynamicDataSourceAutoConfiguration {
|
||||||
|
@ -63,6 +63,7 @@ public class JdbcDynamicDataSourceProvider extends AbstractJdbcDataSourceProvide
|
|||||||
String password = rs.getString(DataSourceConstants.DS_USER_PWD);
|
String password = rs.getString(DataSourceConstants.DS_USER_PWD);
|
||||||
String url = rs.getString(DataSourceConstants.DS_JDBC_URL);
|
String url = rs.getString(DataSourceConstants.DS_JDBC_URL);
|
||||||
DataSourceProperty property = new DataSourceProperty();
|
DataSourceProperty property = new DataSourceProperty();
|
||||||
|
property.setDriverClassName(DataSourceConstants.DS_DRIVER);
|
||||||
property.setUsername(username);
|
property.setUsername(username);
|
||||||
property.setPassword(stringEncryptor.decrypt(password));
|
property.setPassword(stringEncryptor.decrypt(password));
|
||||||
property.setUrl(url);
|
property.setUrl(url);
|
||||||
|
@ -33,9 +33,9 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
|||||||
* 日志自动配置
|
* 日志自动配置
|
||||||
*/
|
*/
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@Configuration
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class LogAutoConfiguration {
|
public class LogAutoConfiguration {
|
||||||
private final RemoteLogService remoteLogService;
|
private final RemoteLogService remoteLogService;
|
||||||
|
|
||||||
|
@ -16,19 +16,20 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.pig4cloud.pig.admin.config;
|
package com.pig4cloud.pig.common.mybatis;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
|
||||||
import com.pig4cloud.pig.common.core.mybatis.DataScopeInterceptor;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
* @date 2019/2/1
|
* @date 2020-03-14
|
||||||
|
* <p>
|
||||||
|
* mybatis plus 统一配置
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class MybatisPlusConfiguration {
|
public class MybatisAutoConfiguration {
|
||||||
/**
|
/**
|
||||||
* 分页插件
|
* 分页插件
|
||||||
*
|
*
|
||||||
@ -39,14 +40,4 @@ public class MybatisPlusConfiguration {
|
|||||||
return new PaginationInterceptor();
|
return new PaginationInterceptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据权限插件
|
|
||||||
*
|
|
||||||
* @return DataScopeInterceptor
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public DataScopeInterceptor dataScopeInterceptor() {
|
|
||||||
return new DataScopeInterceptor();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -15,14 +15,14 @@
|
|||||||
* * limitations under the License.
|
* * limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.pig4cloud.pigx.common.swagger.config;
|
package com.pig4cloud.pig.common.swagger;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import com.pig4cloud.pig.common.swagger.config.SwaggerProperties;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
@ -43,9 +43,9 @@ import java.util.List;
|
|||||||
* @author lengleng
|
* @author lengleng
|
||||||
* swagger配置
|
* swagger配置
|
||||||
*/
|
*/
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
@EnableSwagger2
|
||||||
@EnableAutoConfiguration
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableConfigurationProperties(SwaggerProperties.class)
|
||||||
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
|
||||||
public class SwaggerAutoConfiguration {
|
public class SwaggerAutoConfiguration {
|
||||||
|
|
||||||
@ -55,11 +55,6 @@ public class SwaggerAutoConfiguration {
|
|||||||
private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error","/actuator/**");
|
private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error","/actuator/**");
|
||||||
private static final String BASE_PATH = "/**";
|
private static final String BASE_PATH = "/**";
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public SwaggerProperties swaggerProperties() {
|
|
||||||
return new SwaggerProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket api(SwaggerProperties swaggerProperties) {
|
public Docket api(SwaggerProperties swaggerProperties) {
|
||||||
@ -85,8 +80,8 @@ public class SwaggerAutoConfiguration {
|
|||||||
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
|
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage()))
|
||||||
.paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath)))
|
.paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath)))
|
||||||
.build()
|
.build()
|
||||||
.securitySchemes(Collections.singletonList(securitySchema()))
|
.securitySchemes(Collections.singletonList(securitySchema(swaggerProperties)))
|
||||||
.securityContexts(Collections.singletonList(securityContext()))
|
.securityContexts(Collections.singletonList(securityContext(swaggerProperties)))
|
||||||
.pathMapping("/");
|
.pathMapping("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,10 +90,10 @@ public class SwaggerAutoConfiguration {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private SecurityContext securityContext() {
|
private SecurityContext securityContext(SwaggerProperties swaggerProperties) {
|
||||||
return SecurityContext.builder()
|
return SecurityContext.builder()
|
||||||
.securityReferences(defaultAuth())
|
.securityReferences(defaultAuth(swaggerProperties))
|
||||||
.forPaths(PathSelectors.regex(swaggerProperties().getAuthorization().getAuthRegex()))
|
.forPaths(PathSelectors.regex(swaggerProperties.getAuthorization().getAuthRegex()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,23 +102,23 @@ public class SwaggerAutoConfiguration {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private List<SecurityReference> defaultAuth() {
|
private List<SecurityReference> defaultAuth(SwaggerProperties swaggerProperties) {
|
||||||
ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
||||||
swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
||||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[authorizationScopeList.size()];
|
AuthorizationScope[] authorizationScopes = new AuthorizationScope[authorizationScopeList.size()];
|
||||||
return Collections.singletonList(SecurityReference.builder()
|
return Collections.singletonList(SecurityReference.builder()
|
||||||
.reference(swaggerProperties().getAuthorization().getName())
|
.reference(swaggerProperties.getAuthorization().getName())
|
||||||
.scopes(authorizationScopeList.toArray(authorizationScopes))
|
.scopes(authorizationScopeList.toArray(authorizationScopes))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private OAuth securitySchema() {
|
private OAuth securitySchema(SwaggerProperties swaggerProperties) {
|
||||||
ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
ArrayList<AuthorizationScope> authorizationScopeList = new ArrayList<>();
|
||||||
swaggerProperties().getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
swaggerProperties.getAuthorization().getAuthorizationScopeList().forEach(authorizationScope -> authorizationScopeList.add(new AuthorizationScope(authorizationScope.getScope(), authorizationScope.getDescription())));
|
||||||
ArrayList<GrantType> grantTypes = new ArrayList<>();
|
ArrayList<GrantType> grantTypes = new ArrayList<>();
|
||||||
swaggerProperties().getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl)));
|
swaggerProperties.getAuthorization().getTokenUrlList().forEach(tokenUrl -> grantTypes.add(new ResourceOwnerPasswordCredentialsGrant(tokenUrl)));
|
||||||
return new OAuth(swaggerProperties().getAuthorization().getName(), authorizationScopeList, grantTypes);
|
return new OAuth(swaggerProperties.getAuthorization().getName(), authorizationScopeList, grantTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
|
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
|
@ -15,7 +15,7 @@
|
|||||||
* * limitations under the License.
|
* * limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.pig4cloud.pigx.common.swagger.config;
|
package com.pig4cloud.pig.common.swagger.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
@ -1,37 +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.pigx.common.swagger.annotation;
|
|
||||||
|
|
||||||
import com.pig4cloud.pigx.common.swagger.config.SwaggerAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lengleng
|
|
||||||
* @date 2018/7/21
|
|
||||||
* 开启pig swagger
|
|
||||||
*/
|
|
||||||
@Target({ElementType.TYPE})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
@Inherited
|
|
||||||
@Import({SwaggerAutoConfiguration.class})
|
|
||||||
public @interface EnablePigSwagger2 {
|
|
||||||
}
|
|
@ -0,0 +1,2 @@
|
|||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
com.pig4cloud.pig.common.swagger.SwaggerAutoConfiguration
|
@ -35,6 +35,7 @@
|
|||||||
<module>pig-common-core</module>
|
<module>pig-common-core</module>
|
||||||
<module>pig-common-datasource</module>
|
<module>pig-common-datasource</module>
|
||||||
<module>pig-common-log</module>
|
<module>pig-common-log</module>
|
||||||
|
<module>pig-common-mybatis</module>
|
||||||
<module>pig-common-security</module>
|
<module>pig-common-security</module>
|
||||||
<module>pig-common-swagger</module>
|
<module>pig-common-swagger</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
@ -6,9 +6,9 @@ ENV TZ=Asia/Shanghai
|
|||||||
|
|
||||||
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
RUN mkdir -p /pigx-upms
|
RUN mkdir -p /pig-upms
|
||||||
|
|
||||||
WORKDIR /pigx-upms
|
WORKDIR /pig-upms
|
||||||
|
|
||||||
EXPOSE 4000
|
EXPOSE 4000
|
||||||
|
|
||||||
|
@ -56,6 +56,12 @@
|
|||||||
<artifactId>pig-common-swagger</artifactId>
|
<artifactId>pig-common-swagger</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--mybatis 模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.pig4cloud</groupId>
|
||||||
|
<artifactId>pig-common-mybatis</artifactId>
|
||||||
|
<version>2.7.0</version>
|
||||||
|
</dependency>
|
||||||
<!--注册中心客户端-->
|
<!--注册中心客户端-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
@ -66,17 +72,6 @@
|
|||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--mybatis-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.baomidou</groupId>
|
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
||||||
<version>${mybatis-plus.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!--数据库-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--undertow容器-->
|
<!--undertow容器-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -21,7 +21,6 @@ package com.pig4cloud.pig.admin;
|
|||||||
|
|
||||||
import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients;
|
import com.pig4cloud.pig.common.security.annotation.EnablePigFeignClients;
|
||||||
import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer;
|
import com.pig4cloud.pig.common.security.annotation.EnablePigResourceServer;
|
||||||
import com.pig4cloud.pigx.common.swagger.annotation.EnablePigSwagger2;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.cloud.client.SpringCloudApplication;
|
import org.springframework.cloud.client.SpringCloudApplication;
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ import org.springframework.cloud.client.SpringCloudApplication;
|
|||||||
* @date 2018年06月21日
|
* @date 2018年06月21日
|
||||||
* 用户统一管理系统
|
* 用户统一管理系统
|
||||||
*/
|
*/
|
||||||
@EnablePigSwagger2
|
|
||||||
@EnablePigResourceServer
|
@EnablePigResourceServer
|
||||||
@EnablePigFeignClients
|
@EnablePigFeignClients
|
||||||
@SpringCloudApplication
|
@SpringCloudApplication
|
||||||
|
13
pom.xml
13
pom.xml
@ -49,7 +49,7 @@
|
|||||||
<velocity.version>1.7</velocity.version>
|
<velocity.version>1.7</velocity.version>
|
||||||
<jasypt.version>2.1.0</jasypt.version>
|
<jasypt.version>2.1.0</jasypt.version>
|
||||||
<swagger.fox.version>2.9.2</swagger.fox.version>
|
<swagger.fox.version>2.9.2</swagger.fox.version>
|
||||||
<swagger.core.version>1.5.22</swagger.core.version>
|
<swagger.core.version>1.5.24</swagger.core.version>
|
||||||
<security.oauth.version>2.3.6.RELEASE</security.oauth.version>
|
<security.oauth.version>2.3.6.RELEASE</security.oauth.version>
|
||||||
<docker.plugin.version>0.32.0</docker.plugin.version>
|
<docker.plugin.version>0.32.0</docker.plugin.version>
|
||||||
<docker.host>http://172.17.0.111:2375</docker.host>
|
<docker.host>http://172.17.0.111:2375</docker.host>
|
||||||
@ -141,6 +141,17 @@
|
|||||||
<artifactId>spring-security-oauth2</artifactId>
|
<artifactId>spring-security-oauth2</artifactId>
|
||||||
<version>${security.oauth.version}</version>
|
<version>${security.oauth.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--swagger 最新依赖内置版本-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-models</artifactId>
|
||||||
|
<version>${swagger.core.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
<version>${swagger.core.version}</version>
|
||||||
|
</dependency>
|
||||||
<!--web 模块-->
|
<!--web 模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
Loading…
Reference in New Issue
Block a user