Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
2d68647d
Commit
2d68647d
authored
Mar 06, 2020
by
杨锐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增全局开关,auth.http代码优化。
parent
5793523c
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
30 additions
and
37 deletions
+30
-37
pom.xml
brave-spring-boot-starter/pom.xml
+1
-1
AuthAutoConfiguration.java
...group/tech/brave/configuration/AuthAutoConfiguration.java
+5
-1
RequestInterceptor.java
...quantgroup/tech/brave/interceptor/RequestInterceptor.java
+13
-24
TokenJob.java
.../src/main/java/cn/quantgroup/tech/brave/job/TokenJob.java
+3
-3
pom.xml
commons-core/pom.xml
+1
-1
pom.xml
commons-spring/pom.xml
+1
-1
pom.xml
elastic-job-lite-spring-boot-starter/pom.xml
+1
-1
pom.xml
enoch-agent-spring-boot-starter/pom.xml
+1
-1
pom.xml
idgenerator-spring-boot-starter/pom.xml
+1
-1
pom.xml
pom.xml
+2
-2
pom.xml
shutdown-spring-boot-starter/pom.xml
+1
-1
No files found.
brave-spring-boot-starter/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/configuration/AuthAutoConfiguration.java
View file @
2d68647d
...
@@ -34,25 +34,29 @@ public class AuthAutoConfiguration {
...
@@ -34,25 +34,29 @@ public class AuthAutoConfiguration {
}
}
@Configuration
@Configuration
@ConditionalOnProperty
(
prefix
=
"
quant.auth"
,
name
=
{
"http"
,
"clientId"
,
"secret"
,
"tokenUrl"
}
)
@ConditionalOnProperty
(
prefix
=
"
tech.auth"
,
name
=
"enabled"
,
havingValue
=
"true"
)
public
static
class
AuthConfiguration
{
public
static
class
AuthConfiguration
{
@Bean
@Bean
@ConditionalOnProperty
(
prefix
=
"tech.auth"
,
name
=
{
"http"
,
"clientId"
,
"secret"
,
"tokenUrl"
})
public
HttpClientRequestInterceptor
httpClientRequestInterceptor
()
{
public
HttpClientRequestInterceptor
httpClientRequestInterceptor
()
{
return
new
HttpClientAuthRequestInterceptor
();
return
new
HttpClientAuthRequestInterceptor
();
}
}
@Bean
@Bean
@ConditionalOnProperty
(
prefix
=
"tech.auth"
,
name
=
{
"http"
,
"clientId"
,
"secret"
,
"tokenUrl"
})
public
OkHttpClientInterceptor
okHttpClientInterceptor
()
{
public
OkHttpClientInterceptor
okHttpClientInterceptor
()
{
return
new
OkHttpClientAuthInterceptor
();
return
new
OkHttpClientAuthInterceptor
();
}
}
@Bean
@Bean
@ConditionalOnProperty
(
prefix
=
"tech.auth"
,
name
=
{
"http"
,
"clientId"
,
"secret"
,
"tokenUrl"
})
public
RestTemplateRequestInterceptor
restTemplateRequestInterceptor
()
{
public
RestTemplateRequestInterceptor
restTemplateRequestInterceptor
()
{
return
new
RestTemplateAuthRequestInterceptor
();
return
new
RestTemplateAuthRequestInterceptor
();
}
}
@Bean
@Bean
@ConditionalOnProperty
(
prefix
=
"tech.auth"
,
name
=
{
"http"
,
"clientId"
,
"secret"
,
"tokenUrl"
})
public
TokenJob
tokenJob
()
{
public
TokenJob
tokenJob
()
{
return
new
TokenJob
();
return
new
TokenJob
();
}
}
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/interceptor/RequestInterceptor.java
View file @
2d68647d
package
cn
.
quantgroup
.
tech
.
brave
.
interceptor
;
package
cn
.
quantgroup
.
tech
.
brave
.
interceptor
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -14,35 +12,26 @@ import java.util.stream.Collectors;
...
@@ -14,35 +12,26 @@ import java.util.stream.Collectors;
@Slf4j
@Slf4j
public
abstract
class
RequestInterceptor
{
public
abstract
class
RequestInterceptor
{
@Data
static
class
AuthInfoInMemory
{
private
static
List
<
String
>
hosts
=
new
ArrayList
<>();
private
static
long
expiration
;
}
protected
static
final
String
AUTH
=
"quant-auth"
;
protected
static
final
String
AUTH
=
"quant-auth"
;
// 内网
@Value
(
"#{'${quant.auth.http}'.split(',')}"
)
List
<
String
>
authHttpList
;
protected
boolean
auth
(
String
host
)
{
List
<
String
>
authHttpList
;
if
(
authHttpList
==
null
||
authHttpList
.
isEmpty
())
{
return
false
;
}
if
(
AuthInfoInMemory
.
hosts
.
isEmpty
()
||
System
.
currentTimeMillis
()
>
AuthInfoInMemory
.
expiration
){
hostsCache
();
}
return
AuthInfoInMemory
.
hosts
.
contains
(
host
);
}
private
void
hostsCache
()
{
// 内网
AuthInfoInMemory
.
hosts
=
authHttpList
.
stream
()
@Value
(
"#{'${tech.auth.http}'.split(',')}"
)
public
void
setAuthHttpList
(
List
<
String
>
authHttpList
)
{
this
.
authHttpList
=
authHttpList
.
stream
()
.
map
(
RequestInterceptor:
:
apply
)
.
map
(
RequestInterceptor:
:
apply
)
.
filter
(
Optional:
:
isPresent
)
.
filter
(
Optional:
:
isPresent
)
.
map
(
Optional:
:
get
)
.
map
(
Optional:
:
get
)
.
map
(
URL:
:
getHost
)
.
map
(
URL:
:
getHost
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
AuthInfoInMemory
.
expiration
=
System
.
currentTimeMillis
()
+
30
*
60
*
60
*
1000
;
}
protected
boolean
auth
(
String
host
)
{
if
(
authHttpList
==
null
||
authHttpList
.
isEmpty
())
{
return
false
;
}
return
authHttpList
.
contains
(
host
);
}
}
private
static
Optional
<
URL
>
apply
(
String
http
)
{
private
static
Optional
<
URL
>
apply
(
String
http
)
{
...
@@ -50,7 +39,7 @@ public abstract class RequestInterceptor {
...
@@ -50,7 +39,7 @@ public abstract class RequestInterceptor {
try
{
try
{
url
=
new
URL
(
http
);
url
=
new
URL
(
http
);
}
catch
(
MalformedURLException
e
)
{
}
catch
(
MalformedURLException
e
)
{
log
.
error
(
"无效
quant
.auth.http = 【{}】"
,
http
);
log
.
error
(
"无效
tech
.auth.http = 【{}】"
,
http
);
}
}
return
Optional
.
ofNullable
(
url
);
return
Optional
.
ofNullable
(
url
);
}
}
...
...
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/job/TokenJob.java
View file @
2d68647d
...
@@ -36,11 +36,11 @@ public class TokenJob {
...
@@ -36,11 +36,11 @@ public class TokenJob {
private
static
final
String
CREDENTIAL
=
"credential"
;
private
static
final
String
CREDENTIAL
=
"credential"
;
private
static
final
int
SUCCESS
=
200
;
private
static
final
int
SUCCESS
=
200
;
@Value
(
"${
quant
.auth.clientId}"
)
@Value
(
"${
tech
.auth.clientId}"
)
private
String
clientId
;
private
String
clientId
;
@Value
(
"${
quant
.auth.secret}"
)
@Value
(
"${
tech
.auth.secret}"
)
private
String
secret
;
private
String
secret
;
@Value
(
"${
quant
.auth.tokenUrl}"
)
@Value
(
"${
tech
.auth.tokenUrl}"
)
private
String
tokenUrl
;
private
String
tokenUrl
;
@Resource
@Resource
...
...
commons-core/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
commons-spring/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
elastic-job-lite-spring-boot-starter/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
enoch-agent-spring-boot-starter/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
...
...
idgenerator-spring-boot-starter/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
pom.xml
View file @
2d68647d
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
<parent>
<parent>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<lombok.version>
1.16.20
</lombok.version>
<lombok.version>
1.16.20
</lombok.version>
<guava.version>
23.0
</guava.version>
<guava.version>
23.0
</guava.version>
<apollo.client.version>
0.10.2
</apollo.client.version>
<apollo.client.version>
0.10.2
</apollo.client.version>
<common.parent.version>
0.3.
0
</common.parent.version>
<common.parent.version>
0.3.
1
</common.parent.version>
</properties>
</properties>
<dependencies>
<dependencies>
...
...
shutdown-spring-boot-starter/pom.xml
View file @
2d68647d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<parent>
<parent>
<artifactId>
commons-parent
</artifactId>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.3.
0
</version>
<version>
0.3.
1
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment