Commit 621f197b by yuwei

2.0.0项目初始化

parent 808294fc
package cn.datax.auth; package cn.datax.auth;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataServerProtect;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
@SpringCloudApplication @SpringCloudApplication
public class DataxAuthApplication { public class DataxAuthApplication {
......
...@@ -8,6 +8,9 @@ import org.springframework.stereotype.Component; ...@@ -8,6 +8,9 @@ import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/**
* 异步处理 分布式获取请求头有问题
*/
@Slf4j @Slf4j
@Component @Component
public class AsyncTask { public class AsyncTask {
......
package cn.datax.common.mybatis.annotation;
import cn.datax.common.mybatis.config.AutoConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({AutoConfiguration.class})
public @interface EnableDataMybatis {
}
package cn.datax.common.mybatis.config;
import org.springframework.context.annotation.Import;
/**
* 扫描注入bean
* @author yuwei
* @since 2019/10/25
*/
@Import({DataBatisPlusConfig.class, DataMetaObjectHandler.class})
public class AutoConfiguration {
}
...@@ -50,4 +50,9 @@ public class DataBatisPlusConfig { ...@@ -50,4 +50,9 @@ public class DataBatisPlusConfig {
public DataLogicSqlInjector myLogicSqlInjector() { public DataLogicSqlInjector myLogicSqlInjector() {
return new DataLogicSqlInjector(); return new DataLogicSqlInjector();
} }
@Bean
public DataMetaObjectHandler dataMetaObjectHandler() {
return new DataMetaObjectHandler();
}
} }
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.datax.common.mybatis.config.DataBatisPlusConfig
package cn.datax.common.redis.annotation;
import cn.datax.common.redis.config.AutoConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({AutoConfiguration.class})
public @interface EnableDataRedis {
}
package cn.datax.common.redis.config;
import org.springframework.context.annotation.Import;
/**
* 扫描注入bean
* @author yuwei
* @since 2019/10/25
*/
@Import({RedisConfig.class})
public class AutoConfiguration {
}
...@@ -35,7 +35,7 @@ public class RedisConfig { ...@@ -35,7 +35,7 @@ public class RedisConfig {
* *
* @return * @return
*/ */
@Bean @Bean(name = "redisTemplate")
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.datax.common.redis.config.RedisConfig
package cn.datax.common.security.annotation;
import cn.datax.common.security.config.DataAuthExceptionConfiguration;
import cn.datax.common.security.config.DataServerProtectConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({DataServerProtectConfiguration.class, DataAuthExceptionConfiguration.class})
public @interface EnableDataServerProtect {
}
package cn.datax.common.security.config;
import cn.datax.common.security.handler.DataAccessDeniedHandler;
import cn.datax.common.security.handler.DataAuthExceptionEntryPoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
/**
* 异常翻译配置
*
* @author yuwei
* @since 2019/10/30
*/
public class DataAuthExceptionConfiguration {
@Bean
@ConditionalOnMissingBean(name = "accessDeniedHandler")
public DataAccessDeniedHandler accessDeniedHandler() {
return new DataAccessDeniedHandler();
}
@Bean
@ConditionalOnMissingBean(name = "authenticationEntryPoint")
public DataAuthExceptionEntryPoint authenticationEntryPoint() {
return new DataAuthExceptionEntryPoint();
}
}
...@@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j; ...@@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
/** /**
* 服务间接口不鉴权处理逻辑 * 服务间接口不鉴权处理逻辑
...@@ -16,7 +15,6 @@ import org.springframework.stereotype.Component; ...@@ -16,7 +15,6 @@ import org.springframework.stereotype.Component;
*/ */
@Slf4j @Slf4j
@Aspect @Aspect
@Component
public class DataSecurityInnerAspect { public class DataSecurityInnerAspect {
@SneakyThrows @SneakyThrows
......
package cn.datax.common.security.config;
import cn.datax.common.security.interceptor.DataServerProtectInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class DataSecurityInteceptorConfig implements WebMvcConfigurer {
@Bean
public HandlerInterceptor dataServerProtectInterceptor() {
return new DataServerProtectInterceptor();
}
@Override
@SuppressWarnings("all")
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(dataServerProtectInterceptor());
}
}
package cn.datax.common.security.feign; package cn.datax.common.security.config;
import cn.datax.common.core.DataConstant; import cn.datax.common.core.DataConstant;
import cn.datax.common.security.handler.DataAccessDeniedHandler;
import cn.datax.common.security.handler.DataAuthExceptionEntryPoint;
import feign.RequestInterceptor; import feign.RequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.util.Base64Utils; import org.springframework.util.Base64Utils;
/** public class DataSecurityProtectConfig {
* 解决服务之间调用传递token问题
* @Bean
* @author yuwei @ConditionalOnMissingBean(name = "accessDeniedHandler")
* @since 2019/10/30 public DataAccessDeniedHandler accessDeniedHandler() {
*/ return new DataAccessDeniedHandler();
public class DataFeignRequestInterceptor { }
@Bean
@ConditionalOnMissingBean(name = "authenticationEntryPoint")
public DataAuthExceptionEntryPoint authenticationEntryPoint() {
return new DataAuthExceptionEntryPoint();
}
@Bean
@ConditionalOnMissingBean(value = PasswordEncoder.class)
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public DataSecurityInnerAspect dataSecurityInnerAspect() {
return new DataSecurityInnerAspect();
}
@Bean
public DataSecurityInteceptorConfig dataSecurityInteceptorConfig() {
return new DataSecurityInteceptorConfig();
}
@Bean @Bean
public RequestInterceptor oauth2FeignRequestInterceptor() { public RequestInterceptor oauth2FeignRequestInterceptor() {
...@@ -22,7 +50,8 @@ public class DataFeignRequestInterceptor { ...@@ -22,7 +50,8 @@ public class DataFeignRequestInterceptor {
String gatewayToken = new String(Base64Utils.encode(DataConstant.Security.TOKENVALUE.getVal().getBytes())); String gatewayToken = new String(Base64Utils.encode(DataConstant.Security.TOKENVALUE.getVal().getBytes()));
requestTemplate.header(DataConstant.Security.TOKENHEADER.getVal(), gatewayToken); requestTemplate.header(DataConstant.Security.TOKENHEADER.getVal(), gatewayToken);
// 请求头中添加原请求头中的 Token // 请求头中添加原请求头中的 Token
Object details = SecurityContextHolder.getContext().getAuthentication().getDetails(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) { if (details instanceof OAuth2AuthenticationDetails) {
String authorizationToken = ((OAuth2AuthenticationDetails) details).getTokenValue(); String authorizationToken = ((OAuth2AuthenticationDetails) details).getTokenValue();
requestTemplate.header(DataConstant.Security.AUTHORIZATION.getVal(), DataConstant.Security.TOKENTYPE.getVal() + authorizationToken); requestTemplate.header(DataConstant.Security.AUTHORIZATION.getVal(), DataConstant.Security.TOKENTYPE.getVal() + authorizationToken);
......
package cn.datax.common.security.config;
import cn.datax.common.security.interceptor.DataServerProtectInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 微服务防护配置
*
* @author yuwei
* @since 2019/10/30
*/
@Import({DataServerProtectInterceptor.class})
public class DataServerProtectConfiguration implements WebMvcConfigurer {
@Autowired
private DataServerProtectInterceptor dataServerProtectInterceptor;
@Bean
@ConditionalOnMissingBean(value = PasswordEncoder.class)
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(dataServerProtectInterceptor);
}
}
...@@ -7,11 +7,9 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore; ...@@ -7,11 +7,9 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration; import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Configuration
@ConditionalOnClass(Feign.class) @ConditionalOnClass(Feign.class)
@AutoConfigureBefore(FeignAutoConfiguration.class) @AutoConfigureBefore(FeignAutoConfiguration.class)
public class FeignOkHttpConfig { public class FeignOkHttpConfig {
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.datax.common.security.feign.DataFeignRequestInterceptor cn.datax.common.security.config.DataSecurityProtectConfig,\
cn.datax.common.security.feign.FeignOkHttpConfig
package cn.datax.service.data.factory.sql.console; package cn.datax.service.data.factory.sql.console;
import cn.datax.common.log.annotation.EnableDataLog; import cn.datax.common.log.annotation.EnableDataLog;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataServerProtect;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign", "cn.datax.service.data.factory.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign", "cn.datax.service.data.factory.api.feign"})
@SpringCloudApplication @SpringCloudApplication
......
package cn.datax.service.data.factory; package cn.datax.service.data.factory;
import cn.datax.common.log.annotation.EnableDataLog; import cn.datax.common.log.annotation.EnableDataLog;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataServerProtect;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign", "cn.datax.service.data.factory.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign", "cn.datax.service.data.factory.api.feign"})
@SpringCloudApplication @SpringCloudApplication
......
package cn.datax.service.data.market.api.call; package cn.datax.service.data.market.api.call;
import cn.datax.common.log.annotation.EnableDataLog; import cn.datax.common.log.annotation.EnableDataLog;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataServerProtect;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign", "cn.datax.service.data.factory.api.feign", "cn.datax.service.data.market.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign", "cn.datax.service.data.factory.api.feign", "cn.datax.service.data.market.api.feign"})
@SpringCloudApplication @SpringCloudApplication
......
package cn.datax.service.data.market; package cn.datax.service.data.market;
import cn.datax.common.log.annotation.EnableDataLog; import cn.datax.common.log.annotation.EnableDataLog;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataServerProtect;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
@SpringCloudApplication @SpringCloudApplication
......
package cn.datax.service.system; package cn.datax.service.system;
import cn.datax.common.log.annotation.EnableDataLog; import cn.datax.common.log.annotation.EnableDataLog;
import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataServerProtect;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableDataServerProtect
@EnableDataMybatis
@EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
@SpringCloudApplication @SpringCloudApplication
......
package cn.datax.service.system.controller; package cn.datax.service.system.controller;
import cn.datax.common.base.BaseController; import cn.datax.common.base.BaseController;
import cn.datax.common.core.R;
import cn.datax.common.security.annotation.DataInner;
import cn.datax.service.system.api.dto.LogDto;
import cn.datax.service.system.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/inner") @RequestMapping("/inner")
public class InnerController extends BaseController { public class InnerController extends BaseController {
@Autowired
private LogService logService;
@DataInner
@PostMapping("/logs")
public R saveLog(@RequestBody LogDto log) {
logService.saveLog(log);
return R.ok();
}
} }
...@@ -3,8 +3,6 @@ package cn.datax.service.system.controller; ...@@ -3,8 +3,6 @@ package cn.datax.service.system.controller;
import cn.datax.common.base.BaseController; import cn.datax.common.base.BaseController;
import cn.datax.common.core.JsonPage; import cn.datax.common.core.JsonPage;
import cn.datax.common.core.R; import cn.datax.common.core.R;
import cn.datax.common.security.annotation.DataInner;
import cn.datax.service.system.api.dto.LogDto;
import cn.datax.service.system.api.entity.LogEntity; import cn.datax.service.system.api.entity.LogEntity;
import cn.datax.service.system.api.query.LogQuery; import cn.datax.service.system.api.query.LogQuery;
import cn.datax.service.system.api.vo.LogVo; import cn.datax.service.system.api.vo.LogVo;
...@@ -34,6 +32,7 @@ import java.util.stream.Collectors; ...@@ -34,6 +32,7 @@ import java.util.stream.Collectors;
*/ */
@Api(value="系统管理接口", tags = {"系统管理"}) @Api(value="系统管理接口", tags = {"系统管理"})
@RestController @RestController
@RequestMapping("/logs")
public class LogController extends BaseController { public class LogController extends BaseController {
@Autowired @Autowired
...@@ -42,21 +41,12 @@ public class LogController extends BaseController { ...@@ -42,21 +41,12 @@ public class LogController extends BaseController {
@Autowired @Autowired
private LogMapper logMapper; private LogMapper logMapper;
@DataInner
@ApiOperation(value = "创建日志", notes = "根据log对象创建日志")
@ApiImplicitParam(name = "log", value = "日志详细实体log", required = true, dataType = "logDto")
@PostMapping("/inner/logs")
public R saveLog(@RequestBody LogDto log) {
logService.saveLog(log);
return R.ok();
}
@ApiOperation(value = "日志分页查询", notes = "") @ApiOperation(value = "日志分页查询", notes = "")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "logQuery", value = "查询实体logQuery", required = true, dataTypeClass = LogQuery.class) @ApiImplicitParam(name = "logQuery", value = "查询实体logQuery", required = true, dataTypeClass = LogQuery.class)
}) })
@GetMapping("/logs/page") @GetMapping("/page")
public R getPostPage(LogQuery logQuery) { public R getLogPage(LogQuery logQuery) {
QueryWrapper<LogEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<LogEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.like(StrUtil.isNotBlank(logQuery.getTitle()), "title", logQuery.getTitle()); queryWrapper.like(StrUtil.isNotBlank(logQuery.getTitle()), "title", logQuery.getTitle());
IPage<LogEntity> page = logService.page(new Page<>(logQuery.getPageNum(), logQuery.getPageSize()), queryWrapper); IPage<LogEntity> page = logService.page(new Page<>(logQuery.getPageNum(), logQuery.getPageSize()), queryWrapper);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment