Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datax-cloud
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄营
datax-cloud
Commits
9756c739
Commit
9756c739
authored
Dec 27, 2019
by
yuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目初始化
parent
83c88b1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
AuthTokenAspect.java
...h/src/main/java/cn/datax/auth/aspect/AuthTokenAspect.java
+38
-0
DataOauthResponse.java
...src/main/java/cn/datax/auth/aspect/DataOauthResponse.java
+19
-0
DataOauthResponseSerializer.java
...ava/cn/datax/auth/aspect/DataOauthResponseSerializer.java
+39
-0
No files found.
datax-auth/src/main/java/cn/datax/auth/aspect/AuthTokenAspect.java
0 → 100644
View file @
9756c739
package
cn
.
datax
.
auth
.
aspect
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.oauth2.common.OAuth2AccessToken
;
import
org.springframework.stereotype.Component
;
@Component
@Aspect
@Slf4j
public
class
AuthTokenAspect
{
@Around
(
"execution(* org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(..))"
)
public
Object
handleControllerMethod
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
DataOauthResponse
dataOauthResponse
=
new
DataOauthResponse
();
Object
proceed
=
joinPoint
.
proceed
();
if
(
proceed
!=
null
)
{
ResponseEntity
<
OAuth2AccessToken
>
responseEntity
=
(
ResponseEntity
<
OAuth2AccessToken
>)
proceed
;
OAuth2AccessToken
body
=
responseEntity
.
getBody
();
if
(
responseEntity
.
getStatusCode
().
is2xxSuccessful
())
{
dataOauthResponse
.
setCode
(
200
);
dataOauthResponse
.
setSuccess
(
true
);
dataOauthResponse
.
setData
(
body
);
}
else
{
log
.
error
(
"error:{}"
,
responseEntity
.
getStatusCode
().
toString
());
dataOauthResponse
.
setCode
(
500
);
dataOauthResponse
.
setMsg
(
"客户端授权失败"
);
dataOauthResponse
.
setSuccess
(
false
);
}
}
return
ResponseEntity
.
status
(
200
)
.
body
(
dataOauthResponse
);
}
}
datax-auth/src/main/java/cn/datax/auth/aspect/DataOauthResponse.java
0 → 100644
View file @
9756c739
package
cn
.
datax
.
auth
.
aspect
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
lombok.Data
;
import
java.io.Serializable
;
@JsonSerialize
(
using
=
DataOauthResponseSerializer
.
class
)
@Data
public
class
DataOauthResponse
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
boolean
success
;
private
int
code
;
private
String
msg
;
private
Object
data
;
}
datax-auth/src/main/java/cn/datax/auth/aspect/DataOauthResponseSerializer.java
0 → 100644
View file @
9756c739
package
cn
.
datax
.
auth
.
aspect
;
import
cn.hutool.core.util.StrUtil
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
com.fasterxml.jackson.databind.ser.std.StdSerializer
;
import
org.springframework.security.oauth2.common.OAuth2AccessToken
;
import
java.io.IOException
;
import
java.util.Map
;
public
class
DataOauthResponseSerializer
extends
StdSerializer
<
DataOauthResponse
>
{
public
DataOauthResponseSerializer
()
{
super
(
DataOauthResponse
.
class
);
}
@Override
public
void
serialize
(
DataOauthResponse
value
,
JsonGenerator
gen
,
SerializerProvider
provider
)
throws
IOException
{
OAuth2AccessToken
oAuth2AccessToken
=
(
OAuth2AccessToken
)
value
.
getData
();
gen
.
writeStartObject
();
gen
.
writeNumberField
(
"code"
,
value
.
getCode
());
if
(
StrUtil
.
isNotBlank
(
value
.
getMsg
())){
gen
.
writeStringField
(
"msg"
,
value
.
getMsg
());
}
gen
.
writeBooleanField
(
"success"
,
value
.
isSuccess
());
gen
.
writeNumberField
(
"timestamp"
,
System
.
currentTimeMillis
());
if
(
null
!=
oAuth2AccessToken
){
Map
<
String
,
Object
>
map
=
oAuth2AccessToken
.
getAdditionalInformation
();
map
.
put
(
"access_token"
,
oAuth2AccessToken
.
getValue
());
map
.
put
(
"token_type"
,
oAuth2AccessToken
.
getTokenType
());
map
.
put
(
"refresh_token"
,
oAuth2AccessToken
.
getRefreshToken
().
getValue
());
map
.
put
(
"expires_in"
,
oAuth2AccessToken
.
getExpiresIn
());
map
.
put
(
"scope"
,
oAuth2AccessToken
.
getScope
());
gen
.
writeObjectField
(
"data"
,
map
);
}
gen
.
writeEndObject
();
}
}
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