19 changed files with 409 additions and 98 deletions
@ -0,0 +1,55 @@ |
|||||
|
//package com.ccsens.cloudutil.config;
|
||||
|
//
|
||||
|
//import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
|
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
//import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
//import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
|
//import feign.codec.Decoder;
|
||||
|
//import feign.codec.Encoder;
|
||||
|
//import feign.form.spring.SpringFormEncoder;
|
||||
|
//import org.springframework.beans.factory.ObjectFactory;
|
||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
//import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
|
//import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
|
||||
|
//import org.springframework.cloud.openfeign.support.SpringDecoder;
|
||||
|
//import org.springframework.cloud.openfeign.support.SpringEncoder;
|
||||
|
//import org.springframework.context.annotation.Bean;
|
||||
|
//import org.springframework.context.annotation.Configuration;
|
||||
|
//import org.springframework.http.MediaType;
|
||||
|
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
//
|
||||
|
//import java.util.ArrayList;
|
||||
|
//import java.util.List;
|
||||
|
//
|
||||
|
///**
|
||||
|
// * @description:
|
||||
|
// * @author: wuHuiJuan
|
||||
|
// * @create: 2019/12/09 15:27
|
||||
|
// */
|
||||
|
//@Configuration
|
||||
|
//public class FeignConfig {
|
||||
|
//
|
||||
|
// @Autowired
|
||||
|
// private ObjectFactory<HttpMessageConverters> messageConverters;
|
||||
|
//
|
||||
|
// @Bean
|
||||
|
// public Encoder feignFormEncoder() {
|
||||
|
// return new SpringFormEncoder(new SpringEncoder(messageConverters));
|
||||
|
// }
|
||||
|
//
|
||||
|
// @Bean
|
||||
|
// public Decoder feignDecoder() {
|
||||
|
// return new ResponseEntityDecoder(new SpringDecoder(() -> {
|
||||
|
// MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
|
// List<MediaType> mediaTypeList = new ArrayList<>();
|
||||
|
// mediaTypeList.add(MediaType.TEXT_HTML);
|
||||
|
// mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
|
// converter.setSupportedMediaTypes(mediaTypeList);
|
||||
|
//
|
||||
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
// converter.setObjectMapper(objectMapper); return new HttpMessageConverters(converter);
|
||||
|
// }));
|
||||
|
// }
|
||||
|
//
|
||||
|
//}
|
||||
@ -0,0 +1,16 @@ |
|||||
|
package com.ccsens.ht.annotation; |
||||
|
|
||||
|
import java.lang.annotation.*; |
||||
|
|
||||
|
/** |
||||
|
* @description: 用于标识方法需要登录,获取userId |
||||
|
* 如果未登录,直接返回用户未登录 |
||||
|
* @author: wuHuiJuan |
||||
|
* @create: 2019/12/09 09:48 |
||||
|
*/ |
||||
|
@Documented |
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
@Target(ElementType.METHOD) |
||||
|
public @interface MustLogin { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,80 @@ |
|||||
|
package com.ccsens.ht.aspect; |
||||
|
|
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.alibaba.fastjson.JSON; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.ccsens.cloudutil.feign.TallFeignClient; |
||||
|
import com.ccsens.ht.bean.dto.QueryDto; |
||||
|
import com.ccsens.util.CodeEnum; |
||||
|
import com.ccsens.util.JsonResponse; |
||||
|
import com.ccsens.util.WebConstant; |
||||
|
import com.ccsens.util.exception.BaseException; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.aspectj.lang.ProceedingJoinPoint; |
||||
|
import org.aspectj.lang.annotation.Around; |
||||
|
import org.aspectj.lang.annotation.Aspect; |
||||
|
import org.aspectj.lang.annotation.Pointcut; |
||||
|
import org.aspectj.lang.reflect.MethodSignature; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.core.annotation.Order; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.web.context.request.RequestContextHolder; |
||||
|
import org.springframework.web.context.request.ServletRequestAttributes; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
/** |
||||
|
* @description: |
||||
|
* @author: wuHuiJuan |
||||
|
* @create: 2019/12/09 09:54 |
||||
|
*/ |
||||
|
@Order(1) |
||||
|
@Slf4j |
||||
|
@Aspect |
||||
|
@Component |
||||
|
public class MustLoginAspect { |
||||
|
@Autowired |
||||
|
private TallFeignClient tallFeignClient; |
||||
|
|
||||
|
@Pointcut("@annotation(com.ccsens.ht.annotation.MustLogin)") |
||||
|
public void loginAdvice(){} |
||||
|
|
||||
|
@Around("loginAdvice()") |
||||
|
public Object around(ProceedingJoinPoint pjp){ |
||||
|
|
||||
|
// HttpServletRequest request = ((ServletRequestAttributes)
|
||||
|
// RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
|
// final String authHeader = request.getHeader(WebConstant.HEADER_KEY_TOKEN);
|
||||
|
|
||||
|
Object[] args = pjp.getArgs(); |
||||
|
QueryDto dto = (QueryDto) args[0]; |
||||
|
final String authHeader = dto.getToken(); |
||||
|
|
||||
|
JsonResponse response = tallFeignClient.getUserIdByToken(authHeader); |
||||
|
log.info("{}获取userId:{}", authHeader, response); |
||||
|
if (response.getCode().intValue() != CodeEnum.SUCCESS.getCode().intValue()) { |
||||
|
return response; |
||||
|
} |
||||
|
if (response.getData() == null) { |
||||
|
return JsonResponse.newInstance().ok(CodeEnum.NOT_LOGIN); |
||||
|
} |
||||
|
JSONObject json = JSONObject.parseObject(JSON.toJSONString(response.getData())); |
||||
|
Long userId = json.getLong("id"); |
||||
|
if (userId == null || userId == 0) { |
||||
|
return JsonResponse.newInstance().ok(CodeEnum.NOT_LOGIN); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
dto.setUserId(userId); |
||||
|
Object result; |
||||
|
try { |
||||
|
result = pjp.proceed(); |
||||
|
} catch (Throwable throwable) { |
||||
|
log.error("doctorAudit运行异常", throwable); |
||||
|
throw new BaseException(CodeEnum.SYS_ERROR); |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
package com.ccsens.ht.config; |
||||
|
|
||||
|
import com.ccsens.util.WebConstant; |
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import springfox.documentation.builders.ParameterBuilder; |
||||
|
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
|
import springfox.documentation.schema.ModelRef; |
||||
|
import springfox.documentation.service.ApiInfo; |
||||
|
import springfox.documentation.service.Parameter; |
||||
|
import springfox.documentation.spi.DocumentationType; |
||||
|
import springfox.documentation.spring.web.plugins.Docket; |
||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Configuration |
||||
|
@EnableSwagger2 |
||||
|
@ConditionalOnExpression("${swagger.enable}") |
||||
|
//public class SwaggerConfigure extends WebMvcConfigurationSupport {
|
||||
|
public class SwaggerConfigure /*implements WebMvcConfigurer*/ { |
||||
|
@Bean |
||||
|
public Docket customDocket() { |
||||
|
//
|
||||
|
return new Docket(DocumentationType.SWAGGER_2) |
||||
|
.apiInfo(apiInfo()) |
||||
|
.select() |
||||
|
.apis(RequestHandlerSelectors |
||||
|
.basePackage("com.ccsens.ht.api")) |
||||
|
.build() |
||||
|
.globalOperationParameters(setHeaderToken()); |
||||
|
} |
||||
|
|
||||
|
private ApiInfo apiInfo() { |
||||
|
return new ApiInfo("Swagger Tall-ptpro",//大标题 title
|
||||
|
"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",//小标题
|
||||
|
"1.0.0",//版本
|
||||
|
"http://swagger.io/terms/",//termsOfServiceUrl
|
||||
|
"zhangsan",//作者
|
||||
|
"Apache 2.0",//链接显示文字
|
||||
|
"http://www.apache.org/licenses/LICENSE-2.0.html"//网站链接
|
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private List<Parameter> setHeaderToken() { |
||||
|
ParameterBuilder tokenPar = new ParameterBuilder(); |
||||
|
List<Parameter> pars = new ArrayList<>(); |
||||
|
tokenPar.name(WebConstant.HEADER_KEY_TOKEN).description("token") |
||||
|
.defaultValue(WebConstant.HEADER_KEY_TOKEN_PREFIX) |
||||
|
.modelRef(new ModelRef("string")).parameterType("header").required(false).build(); |
||||
|
pars.add(tokenPar.build()); |
||||
|
return pars; |
||||
|
} |
||||
|
} |
||||
@ -1,4 +1,4 @@ |
|||||
spring: |
spring: |
||||
profiles: |
profiles: |
||||
active: test |
active: dev |
||||
include: common, util-test |
include: common, util-dev |
||||
@ -0,0 +1,56 @@ |
|||||
|
package com.ccsens.tall.config; |
||||
|
|
||||
|
import com.ccsens.util.WebConstant; |
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import springfox.documentation.builders.ParameterBuilder; |
||||
|
import springfox.documentation.builders.RequestHandlerSelectors; |
||||
|
import springfox.documentation.schema.ModelRef; |
||||
|
import springfox.documentation.service.ApiInfo; |
||||
|
import springfox.documentation.service.Parameter; |
||||
|
import springfox.documentation.spi.DocumentationType; |
||||
|
import springfox.documentation.spring.web.plugins.Docket; |
||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Configuration |
||||
|
@EnableSwagger2 |
||||
|
@ConditionalOnExpression("${swagger.enable}") |
||||
|
//public class SwaggerConfigure extends WebMvcConfigurationSupport {
|
||||
|
public class SwaggerConfigure /*implements WebMvcConfigurer*/ { |
||||
|
@Bean |
||||
|
public Docket customDocket() { |
||||
|
//
|
||||
|
return new Docket(DocumentationType.SWAGGER_2) |
||||
|
.apiInfo(apiInfo()) |
||||
|
.select() |
||||
|
.apis(RequestHandlerSelectors |
||||
|
.basePackage("com.ccsens.tall.web")) |
||||
|
.build() |
||||
|
.globalOperationParameters(setHeaderToken()); |
||||
|
} |
||||
|
|
||||
|
private ApiInfo apiInfo() { |
||||
|
return new ApiInfo("Swagger Tall-ptpro",//大标题 title
|
||||
|
"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",//小标题
|
||||
|
"1.0.0",//版本
|
||||
|
"http://swagger.io/terms/",//termsOfServiceUrl
|
||||
|
"zhangsan",//作者
|
||||
|
"Apache 2.0",//链接显示文字
|
||||
|
"http://www.apache.org/licenses/LICENSE-2.0.html"//网站链接
|
||||
|
); |
||||
|
} |
||||
|
|
||||
|
private List<Parameter> setHeaderToken() { |
||||
|
ParameterBuilder tokenPar = new ParameterBuilder(); |
||||
|
List<Parameter> pars = new ArrayList<>(); |
||||
|
tokenPar.name(WebConstant.HEADER_KEY_TOKEN).description("token") |
||||
|
.defaultValue(WebConstant.HEADER_KEY_TOKEN_PREFIX) |
||||
|
.modelRef(new ModelRef("string")).parameterType("header").required(false).build(); |
||||
|
pars.add(tokenPar.build()); |
||||
|
return pars; |
||||
|
} |
||||
|
} |
||||
@ -1,56 +1,56 @@ |
|||||
package com.ccsens.util.config; |
//package com.ccsens.util.config;
|
||||
|
|
||||
import com.ccsens.util.WebConstant; |
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|
||||
import org.springframework.context.annotation.Bean; |
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
import springfox.documentation.builders.ParameterBuilder; |
|
||||
import springfox.documentation.builders.RequestHandlerSelectors; |
|
||||
import springfox.documentation.schema.ModelRef; |
|
||||
import springfox.documentation.service.ApiInfo; |
|
||||
import springfox.documentation.service.Parameter; |
|
||||
import springfox.documentation.spi.DocumentationType; |
|
||||
import springfox.documentation.spring.web.plugins.Docket; |
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.List; |
|
||||
|
|
||||
@Configuration |
|
||||
@EnableSwagger2 |
|
||||
@ConditionalOnExpression("${swagger.enable}") |
|
||||
//public class SwaggerConfigure extends WebMvcConfigurationSupport {
|
|
||||
public class SwaggerConfigure /*implements WebMvcConfigurer*/ { |
|
||||
@Bean |
|
||||
public Docket customDocket() { |
|
||||
//
|
//
|
||||
return new Docket(DocumentationType.SWAGGER_2) |
//import com.ccsens.util.WebConstant;
|
||||
.apiInfo(apiInfo()) |
//import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
.select() |
//import org.springframework.context.annotation.Bean;
|
||||
.apis(RequestHandlerSelectors |
//import org.springframework.context.annotation.Configuration;
|
||||
.basePackage("com.ccsens.ptpro.web")) |
//import springfox.documentation.builders.ParameterBuilder;
|
||||
.build() |
//import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
.globalOperationParameters(setHeaderToken()); |
//import springfox.documentation.schema.ModelRef;
|
||||
} |
//import springfox.documentation.service.ApiInfo;
|
||||
|
//import springfox.documentation.service.Parameter;
|
||||
private ApiInfo apiInfo() { |
//import springfox.documentation.spi.DocumentationType;
|
||||
return new ApiInfo("Swagger Tall-ptpro",//大标题 title
|
//import springfox.documentation.spring.web.plugins.Docket;
|
||||
"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",//小标题
|
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
"1.0.0",//版本
|
//
|
||||
"http://swagger.io/terms/",//termsOfServiceUrl
|
//import java.util.ArrayList;
|
||||
"zhangsan",//作者
|
//import java.util.List;
|
||||
"Apache 2.0",//链接显示文字
|
//
|
||||
"http://www.apache.org/licenses/LICENSE-2.0.html"//网站链接
|
//@Configuration
|
||||
); |
//@EnableSwagger2
|
||||
} |
//@ConditionalOnExpression("${swagger.enable}")
|
||||
|
////public class SwaggerConfigure extends WebMvcConfigurationSupport {
|
||||
private List<Parameter> setHeaderToken() { |
//public class SwaggerConfigure /*implements WebMvcConfigurer*/ {
|
||||
ParameterBuilder tokenPar = new ParameterBuilder(); |
// @Bean
|
||||
List<Parameter> pars = new ArrayList<>(); |
// public Docket customDocket() {
|
||||
tokenPar.name(WebConstant.HEADER_KEY_TOKEN).description("token") |
// //
|
||||
.defaultValue(WebConstant.HEADER_KEY_TOKEN_PREFIX) |
// return new Docket(DocumentationType.SWAGGER_2)
|
||||
.modelRef(new ModelRef("string")).parameterType("header").required(false).build(); |
// .apiInfo(apiInfo())
|
||||
pars.add(tokenPar.build()); |
// .select()
|
||||
return pars; |
// .apis(RequestHandlerSelectors
|
||||
} |
// .basePackage("com.ccsens.tall.web,com.ccsens.ht.api"))
|
||||
} |
// .build()
|
||||
|
// .globalOperationParameters(setHeaderToken());
|
||||
|
// }
|
||||
|
//
|
||||
|
// private ApiInfo apiInfo() {
|
||||
|
// return new ApiInfo("Swagger Tall-ptpro",//大标题 title
|
||||
|
// "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.",//小标题
|
||||
|
// "1.0.0",//版本
|
||||
|
// "http://swagger.io/terms/",//termsOfServiceUrl
|
||||
|
// "zhangsan",//作者
|
||||
|
// "Apache 2.0",//链接显示文字
|
||||
|
// "http://www.apache.org/licenses/LICENSE-2.0.html"//网站链接
|
||||
|
// );
|
||||
|
// }
|
||||
|
//
|
||||
|
// private List<Parameter> setHeaderToken() {
|
||||
|
// ParameterBuilder tokenPar = new ParameterBuilder();
|
||||
|
// List<Parameter> pars = new ArrayList<>();
|
||||
|
// tokenPar.name(WebConstant.HEADER_KEY_TOKEN).description("token")
|
||||
|
// .defaultValue(WebConstant.HEADER_KEY_TOKEN_PREFIX)
|
||||
|
// .modelRef(new ModelRef("string")).parameterType("header").required(false).build();
|
||||
|
// pars.add(tokenPar.build());
|
||||
|
// return pars;
|
||||
|
// }
|
||||
|
//}
|
||||
|
|||||
Loading…
Reference in new issue