Commit 93073a89 by yuwei

2.0.0项目初始化

parent 10866ad3
...@@ -2,19 +2,15 @@ package cn.datax.auth; ...@@ -2,19 +2,15 @@ package cn.datax.auth;
import cn.datax.common.mybatis.annotation.EnableDataMybatis; import cn.datax.common.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis; import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataAuthExceptionHandler;
import cn.datax.common.security.annotation.EnableDataServerProtect; 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;
import org.springframework.context.annotation.ComponentScan;
@EnableDataAuthExceptionHandler
@EnableDataServerProtect @EnableDataServerProtect
@EnableDataMybatis @EnableDataMybatis
@EnableDataRedis @EnableDataRedis
@EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"}) @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
@ComponentScan(basePackages = {"cn.datax"})
@SpringCloudApplication @SpringCloudApplication
public class DataxAuthApplication { public class DataxAuthApplication {
......
...@@ -9,7 +9,6 @@ spring: ...@@ -9,7 +9,6 @@ spring:
cloud: cloud:
config: config:
fail-fast: true fail-fast: true
# uri: http://localhost:8611
name: ${spring.application.name} name: ${spring.application.name}
profile: ${spring.profiles.active} profile: ${spring.profiles.active}
discovery: discovery:
......
package cn.datax.common.database.annotation;
import cn.datax.common.database.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 EnableDatabase {
}
package cn.datax.common.database.config;
import cn.datax.common.database.DataSourceFactory;
import cn.datax.common.database.datasource.CacheDataSourceFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/**
* 扫描注入bean
*
* @author yuwei
* @since 2019/10/30
*/
@ComponentScan({"cn.datax.common.database"})
public class AutoConfiguration {
@Bean
public DataSourceFactory dataSourceFactory(){
return new CacheDataSourceFactoryBean();
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.datax.common.database.datasource.CacheDataSourceFactoryBean
...@@ -3,10 +3,9 @@ package cn.datax.common.log.aspectj; ...@@ -3,10 +3,9 @@ package cn.datax.common.log.aspectj;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import cn.datax.common.log.annotation.LogAop; import cn.datax.common.log.annotation.LogAop;
import cn.datax.common.log.event.LogEvent; import cn.datax.common.log.async.AsyncTask;
import cn.datax.common.utils.RequestHolder; import cn.datax.common.utils.RequestHolder;
import cn.datax.common.utils.SecurityUtil; import cn.datax.common.utils.SecurityUtil;
import cn.datax.common.utils.SpringContextHolder;
import cn.datax.service.system.api.dto.LogDto; import cn.datax.service.system.api.dto.LogDto;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
...@@ -20,6 +19,7 @@ import org.aspectj.lang.annotation.*; ...@@ -20,6 +19,7 @@ import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.MethodSignature;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -27,6 +27,9 @@ import javax.servlet.http.HttpServletRequest; ...@@ -27,6 +27,9 @@ import javax.servlet.http.HttpServletRequest;
@Aspect @Aspect
public class LogAspect { public class LogAspect {
@Autowired
private AsyncTask asyncTask;
// 配置织入点 // 配置织入点
@Pointcut("@annotation(cn.datax.common.log.annotation.LogAop)") @Pointcut("@annotation(cn.datax.common.log.annotation.LogAop)")
public void logPointCut() {} public void logPointCut() {}
...@@ -86,8 +89,8 @@ public class LogAspect { ...@@ -86,8 +89,8 @@ public class LogAspect {
logDto.setModule(logAop.module()).setTitle(logAop.value()) logDto.setModule(logAop.module()).setTitle(logAop.value())
.setClassName(className).setMethodName(methodName); .setClassName(className).setMethodName(methodName);
// 异步保存会造成DataFeignRequestInterceptor报错,后期采用kafka // 异步保存数据库
SpringContextHolder.publishEvent(new LogEvent(logDto)); asyncTask.doTask(logDto);
} }
/** /**
......
package cn.datax.common.log.event; package cn.datax.common.log.async;
import cn.datax.service.system.api.dto.LogDto; import cn.datax.service.system.api.dto.LogDto;
import cn.datax.service.system.api.feign.LogServiceFeign; import cn.datax.service.system.api.feign.LogServiceFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
/**
* 异步监听日志事件
*
* @author yuwei
* @since 2019/10/30
*/
@Slf4j @Slf4j
public class LogListener { @Component
public class AsyncTask {
@Autowired @Autowired
private LogServiceFeign logServiceFeign; private LogServiceFeign logServiceFeign;
@EventListener(LogEvent.class) @Async("dataLogExecutor")
public void saveSysLog(LogEvent event) { public void doTask(LogDto logDto) {
LogDto logDto = (LogDto) event.getSource();
log.info("日志{}", logDto);
logServiceFeign.saveLog(logDto); logServiceFeign.saveLog(logDto);
} }
}
}
\ No newline at end of file
package cn.datax.common.log.config; package cn.datax.common.log.config;
import cn.datax.common.log.aspectj.LogAspect; import cn.datax.common.log.aspectj.LogAspect;
import cn.datax.common.log.event.LogListener; import cn.datax.common.log.async.AsyncTask;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
/** /**
...@@ -11,8 +10,7 @@ import org.springframework.context.annotation.Import; ...@@ -11,8 +10,7 @@ import org.springframework.context.annotation.Import;
* @author yuwei * @author yuwei
* @since 2019/10/30 * @since 2019/10/30
*/ */
@ComponentScan({"cn.datax.common.log"}) @Import({LogAspect.class, AsyncTask.class, LogAsyncConfig.class})
@Import({LogAspect.class, LogListener.class})
public class AutoConfiguration { public class AutoConfiguration {
} }
package cn.datax.common.log.config;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@EnableAsync
public class LogAsyncConfig {
private static int corePoolSize = 5;
private static int maxPoolSize = 10;
private static int queueCapacity = 20;
@Bean("dataLogExecutor")
public Executor dataLogExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setKeepAliveSeconds(60);
executor.setThreadNamePrefix("dataLogExecutor-");
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(60);
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize();
return executor;
}
}
\ No newline at end of file
package cn.datax.common.log.event;
import cn.datax.service.system.api.dto.LogDto;
import org.springframework.context.ApplicationEvent;
/**
* 系统日志事件
*
* @author yuwei
* @since 2019/10/30
*/
public class LogEvent extends ApplicationEvent {
public LogEvent(LogDto logDto) {
super(logDto);
}
}
package cn.datax.common.mybatis.config; package cn.datax.common.mybatis.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
/** /**
...@@ -9,7 +7,6 @@ import org.springframework.context.annotation.Import; ...@@ -9,7 +7,6 @@ import org.springframework.context.annotation.Import;
* @author yuwei * @author yuwei
* @since 2019/10/25 * @since 2019/10/25
*/ */
@ComponentScan({"cn.datax.common.mybatis"})
@Import({DataBatisPlusConfig.class, DataMetaObjectHandler.class}) @Import({DataBatisPlusConfig.class, DataMetaObjectHandler.class})
public class AutoConfiguration { public class AutoConfiguration {
} }
package cn.datax.common.redis.config; package cn.datax.common.redis.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
/** /**
...@@ -8,7 +7,6 @@ import org.springframework.context.annotation.Import; ...@@ -8,7 +7,6 @@ import org.springframework.context.annotation.Import;
* @author yuwei * @author yuwei
* @since 2019/10/25 * @since 2019/10/25
*/ */
@ComponentScan({"cn.datax.common.redis"})
@Import({RedisConfig.class}) @Import({RedisConfig.class})
public class AutoConfiguration { public class AutoConfiguration {
} }
package cn.datax.common.security.annotation;
import cn.datax.common.security.config.DataAuthExceptionConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({DataAuthExceptionConfiguration.class})
public @interface EnableDataAuthExceptionHandler {
}
package cn.datax.common.security.annotation;
import org.springframework.cloud.openfeign.EnableFeignClients;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@EnableFeignClients
public @interface EnableDataFeignClients {
String[] value() default {};
String[] basePackages() default {"cn.datax.service"};
Class<?>[] basePackageClasses() default {};
Class<?>[] defaultConfiguration() default {};
Class<?>[] clients() default {};
}
package cn.datax.common.security.annotation;
import cn.datax.common.security.config.DataOAuth2FeignConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({DataOAuth2FeignConfiguration.class})
public @interface EnableDataOauth2FeignClient {
}
package cn.datax.common.security.annotation;
import cn.datax.common.security.config.DataAuthExceptionConfiguration;
import cn.datax.common.security.config.DataOAuth2FeignConfiguration;
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({DataAuthExceptionConfiguration.class, DataOAuth2FeignConfiguration.class, DataServerProtectConfiguration.class})
public @interface EnableDataSecurity {
}
package cn.datax.common.security.annotation; package cn.datax.common.security.annotation;
import cn.datax.common.security.config.DataAuthExceptionConfiguration;
import cn.datax.common.security.config.DataServerProtectConfiguration; import cn.datax.common.security.config.DataServerProtectConfiguration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
...@@ -9,6 +10,6 @@ import java.lang.annotation.*; ...@@ -9,6 +10,6 @@ import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Inherited @Inherited
@Import({DataServerProtectConfiguration.class}) @Import({DataServerProtectConfiguration.class, DataAuthExceptionConfiguration.class})
public @interface EnableDataServerProtect { public @interface EnableDataServerProtect {
} }
...@@ -4,7 +4,6 @@ import cn.datax.common.security.handler.DataAccessDeniedHandler; ...@@ -4,7 +4,6 @@ import cn.datax.common.security.handler.DataAccessDeniedHandler;
import cn.datax.common.security.handler.DataAuthExceptionEntryPoint; import cn.datax.common.security.handler.DataAuthExceptionEntryPoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
/** /**
* 异常翻译配置 * 异常翻译配置
...@@ -12,7 +11,6 @@ import org.springframework.context.annotation.ComponentScan; ...@@ -12,7 +11,6 @@ import org.springframework.context.annotation.ComponentScan;
* @author yuwei * @author yuwei
* @since 2019/10/30 * @since 2019/10/30
*/ */
@ComponentScan({"cn.datax.common.security.handler"})
public class DataAuthExceptionConfiguration { public class DataAuthExceptionConfiguration {
@Bean @Bean
......
package cn.datax.common.security.config;
import org.springframework.context.annotation.ComponentScan;
/**
* OAuth2 Feign配置
*
* @author yuwei
* @since 2019/10/30
*/
@ComponentScan({"cn.datax.common.security.feign"})
public class DataOAuth2FeignConfiguration {
}
...@@ -4,7 +4,6 @@ import cn.datax.common.security.interceptor.DataServerProtectInterceptor; ...@@ -4,7 +4,6 @@ import cn.datax.common.security.interceptor.DataServerProtectInterceptor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
...@@ -17,7 +16,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; ...@@ -17,7 +16,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author yuwei * @author yuwei
* @since 2019/10/30 * @since 2019/10/30
*/ */
@ComponentScan({"cn.datax.common.security.interceptor"})
@Import({DataServerProtectInterceptor.class}) @Import({DataServerProtectInterceptor.class})
public class DataServerProtectConfiguration implements WebMvcConfigurer { public class DataServerProtectConfiguration implements WebMvcConfigurer {
......
...@@ -3,7 +3,6 @@ package cn.datax.common.security.feign; ...@@ -3,7 +3,6 @@ package cn.datax.common.security.feign;
import cn.datax.common.core.DataConstant; import cn.datax.common.core.DataConstant;
import feign.RequestInterceptor; import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
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;
...@@ -14,7 +13,6 @@ import org.springframework.util.Base64Utils; ...@@ -14,7 +13,6 @@ import org.springframework.util.Base64Utils;
* @author yuwei * @author yuwei
* @since 2019/10/30 * @since 2019/10/30
*/ */
@Configuration
public class DataFeignRequestInterceptor { public class DataFeignRequestInterceptor {
@Bean @Bean
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.datax.common.security.feign.DataFeignRequestInterceptor
package cn.datax.service.data.factory; package cn.datax.service.data.factory;
import cn.datax.common.database.annotation.EnableDatabase;
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.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis; import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataFeignClients; import cn.datax.common.security.annotation.EnableDataServerProtect;
import cn.datax.common.security.annotation.EnableDataSecurity;
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;
@EnableDataSecurity @EnableDataServerProtect
@EnableDataMybatis @EnableDataMybatis
@EnableDataRedis @EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableDataFeignClients @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
@EnableDatabase
@SpringCloudApplication @SpringCloudApplication
public class DataFactoryApplication { public class DataFactoryApplication {
......
...@@ -10,6 +10,6 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -10,6 +10,6 @@ import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(contextId = "logServiceFeign", value = "datax-service-system", fallbackFactory = LogServiceFeignFallbackFactory.class) @FeignClient(contextId = "logServiceFeign", value = "datax-service-system", fallbackFactory = LogServiceFeignFallbackFactory.class)
public interface LogServiceFeign { public interface LogServiceFeign {
@PostMapping("/logs") @PostMapping("/inner/logs")
R saveLog(@RequestBody LogDto logDto); R saveLog(@RequestBody LogDto logDto);
} }
...@@ -9,6 +9,6 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -9,6 +9,6 @@ import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(contextId = "userServiceFeign", value = "datax-service-system", fallbackFactory = UserServiceFeignFallbackFactory.class) @FeignClient(contextId = "userServiceFeign", value = "datax-service-system", fallbackFactory = UserServiceFeignFallbackFactory.class)
public interface UserServiceFeign { public interface UserServiceFeign {
@GetMapping("/inner/login/username/{username}") @GetMapping("/login/username/{username}")
R loginByUsername(@PathVariable("username") String username); R loginByUsername(@PathVariable("username") String username);
} }
...@@ -3,16 +3,16 @@ package cn.datax.service.system; ...@@ -3,16 +3,16 @@ 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.mybatis.annotation.EnableDataMybatis;
import cn.datax.common.redis.annotation.EnableDataRedis; import cn.datax.common.redis.annotation.EnableDataRedis;
import cn.datax.common.security.annotation.EnableDataFeignClients; import cn.datax.common.security.annotation.EnableDataServerProtect;
import cn.datax.common.security.annotation.EnableDataSecurity;
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;
@EnableDataSecurity @EnableDataServerProtect
@EnableDataMybatis @EnableDataMybatis
@EnableDataRedis @EnableDataRedis
@EnableDataLog @EnableDataLog
@EnableDataFeignClients @EnableFeignClients(basePackages = {"cn.datax.service.system.api.feign"})
@SpringCloudApplication @SpringCloudApplication
public class DataxSystemApplication { public class DataxSystemApplication {
......
...@@ -59,7 +59,8 @@ public class DataResourceServerConfig extends ResourceServerConfigurerAdapter { ...@@ -59,7 +59,8 @@ public class DataResourceServerConfig extends ResourceServerConfigurerAdapter {
"/swagger-resources/**", "/swagger-resources/**",
"/webjars/**", "/webjars/**",
// feign 内部调用不用授权 // feign 内部调用不用授权
"/inner/**" "/inner/**",
"/login/**"
).permitAll() ).permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
.and().csrf().disable(); .and().csrf().disable();
......
...@@ -3,6 +3,7 @@ package cn.datax.service.system.controller; ...@@ -3,6 +3,7 @@ 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.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;
...@@ -33,7 +34,6 @@ import java.util.stream.Collectors; ...@@ -33,7 +34,6 @@ 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,9 +42,10 @@ public class LogController extends BaseController { ...@@ -42,9 +42,10 @@ public class LogController extends BaseController {
@Autowired @Autowired
private LogMapper logMapper; private LogMapper logMapper;
@DataInner
@ApiOperation(value = "创建日志", notes = "根据log对象创建日志") @ApiOperation(value = "创建日志", notes = "根据log对象创建日志")
@ApiImplicitParam(name = "log", value = "日志详细实体log", required = true, dataType = "logDto") @ApiImplicitParam(name = "log", value = "日志详细实体log", required = true, dataType = "logDto")
@PostMapping() @PostMapping("/inner/logs")
public R saveLog(@RequestBody LogDto log) { public R saveLog(@RequestBody LogDto log) {
logService.saveLog(log); logService.saveLog(log);
return R.ok(); return R.ok();
...@@ -54,7 +55,7 @@ public class LogController extends BaseController { ...@@ -54,7 +55,7 @@ public class LogController extends BaseController {
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "logQuery", value = "查询实体logQuery", required = true, dataTypeClass = LogQuery.class) @ApiImplicitParam(name = "logQuery", value = "查询实体logQuery", required = true, dataTypeClass = LogQuery.class)
}) })
@GetMapping("/page") @GetMapping("/logs/page")
public R getPostPage(LogQuery logQuery) { public R getPostPage(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());
......
...@@ -8,14 +8,18 @@ import cn.datax.service.system.service.UserService; ...@@ -8,14 +8,18 @@ import cn.datax.service.system.service.UserService;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken; import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/inner")
public class LoginController extends BaseController { public class LoginController extends BaseController {
@Autowired @Autowired
...@@ -24,6 +28,18 @@ public class LoginController extends BaseController { ...@@ -24,6 +28,18 @@ public class LoginController extends BaseController {
@Autowired @Autowired
private TokenStore tokenStore; private TokenStore tokenStore;
@Autowired
private RestTemplate restTemplate;
@Value("${security.oauth2.client.access-token-uri}")
private String accessTokenUri;
@Value("${security.oauth2.client.client-id}")
private String clientId;
@Value("${security.oauth2.client.client-secret}")
private String clientSecret;
@Value("${security.oauth2.client.scope}")
private String scope;
@DataInner @DataInner
@GetMapping("/login/username/{username}") @GetMapping("/login/username/{username}")
public R loginByUsername(@PathVariable String username) { public R loginByUsername(@PathVariable String username) {
...@@ -31,6 +47,19 @@ public class LoginController extends BaseController { ...@@ -31,6 +47,19 @@ public class LoginController extends BaseController {
return R.ok().setData(userInfo); return R.ok().setData(userInfo);
} }
@PostMapping("/login")
public R login(String username, String password) {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.set("username", username);
paramsMap.set("password", password);
paramsMap.set("grant_type", "password");
paramsMap.set("scope", scope);
paramsMap.set("client_id", clientId);
paramsMap.set("client_secret", clientSecret);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(paramsMap, null);
return restTemplate.postForObject(accessTokenUri, request, R.class);
}
@DeleteMapping("/logout/{token}") @DeleteMapping("/logout/{token}")
public R logout(@PathVariable("token") String token) { public R logout(@PathVariable("token") String token) {
if (StrUtil.isBlank(token)) { if (StrUtil.isBlank(token)) {
......
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