♻️ 重构代码。重写feign oauth interceptor

This commit is contained in:
冷冷 committed 2018-08-14 12:54:36 +08:00
1 parent 9f6f4bc80e
commit d2be4393c5
7 files changed
+98 -9

No files matched your search

+13 -3
View File
@@ -43,7 +43,7 @@ services:
ports:
- 3000:3000
pig-upms:
pigx-upms:
links:
- pigx-eureka
- pigx-redis
@@ -53,7 +53,7 @@ services:
dockerfile: ./pigx-upms/pigx-upms-biz/Dockerfile
restart: always
pig-monitor:
pigx-monitor:
links:
- pigx-eureka
build:
@@ -63,7 +63,7 @@ services:
ports:
- 5001:5001
pig-daemon:
pigx-daemon:
links:
- pigx-eureka
build:
@@ -72,3 +72,13 @@ services:
restart: always
ports:
- 5002:5002
pigx-codegen:
links:
- pigx-eureka
build:
context: ./
dockerfile: ./pigx-visual/pigx-codegen/Dockerfile
restart: always
ports:
- 5003:5003
@@ -17,11 +17,11 @@
*
*/
package com.pig4cloud.pigx.common.security.interceptor;
package com.pig4cloud.pigx.common.security.feign;
import feign.RequestInterceptor;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
@@ -34,11 +34,13 @@ import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResour
* 使用hystrix 的信号量模式
*/
@Configuration
@AllArgsConstructor
@ConditionalOnProperty("security.oauth2.client.client-id")
public class PigxFeignClientInterceptor {
public class PigxFeignClientConfiguration {
@Bean
public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext,
OAuth2ProtectedResourceDetails resource) {
return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, resource);
return new PigxFeignClientInterceptor(oAuth2ClientContext, resource);
}
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.security.feign;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
/**
* @author lengleng
* @date 2018/8/13
* 扩展OAuth2FeignRequestInterceptor
*/
@Slf4j
public class PigxFeignClientInterceptor extends OAuth2FeignRequestInterceptor {
private final OAuth2ClientContext oAuth2ClientContext;
/**
* Default constructor which uses the provided OAuth2ClientContext and Bearer tokens
* within Authorization header
*
* @param oAuth2ClientContext provided context
* @param resource type of resource to be accessed
*/
public PigxFeignClientInterceptor(OAuth2ClientContext oAuth2ClientContext
, OAuth2ProtectedResourceDetails resource) {
super(oAuth2ClientContext, resource);
this.oAuth2ClientContext = oAuth2ClientContext;
}
/**
* Create a template with the header of provided name and extracted extract
*
* @param template
*/
@Override
public void apply(RequestTemplate template) {
if (oAuth2ClientContext != null
&& oAuth2ClientContext.getAccessToken() != null) {
super.apply(template);
}
}
}
@@ -2,4 +2,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.pig4cloud.pigx.common.security.component.PermissionService,\
com.pig4cloud.pigx.common.security.component.PigAccessDeniedHandler,\
com.pig4cloud.pigx.common.security.component.ResourceAuthExceptionEntryPoint,\
com.pig4cloud.pigx.common.security.interceptor.PigxFeignClientInterceptor
com.pig4cloud.pigx.common.security.feign.PigxFeignClientConfiguration
+13
View File
@@ -0,0 +1,13 @@
FROM anapsix/alpine-java:8_server-jre_unlimited
MAINTAINER wangiegie@gmail.com
RUN mkdir -p /pigx/bin/com.pig4cloud/pigx-codegen
WORKDIR /pigx/bin/com.pig4cloud/pigx-codegen
EXPOSE 5001
ADD ./pigx-visual/pigx-codegen/target/pigx-codegen.jar ./
CMD java -Djava.security.egd=file:/dev/./urandom -jar pigx-codegen.jar
+3
View File
@@ -73,6 +73,9 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>${project.name}</finalName>
</configuration>
</plugin>
</plugins>
</build>
@@ -117,7 +117,7 @@
},
rowDel: function(row, index) {
var _this = this
this.$confirm('是否确认删除ID为' + row.clientId, '提示', {
this.$confirm('是否确认删除ID为' + row.$pk.lowerAttrName, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'