Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sso
Project
Project
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
曲欣亮
sso
Commits
57d14644
Commit
57d14644
authored
Jul 29, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
ba192c5a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
22 deletions
+31
-22
OAuthApi.java
src/main/java/com/egolm/sso/oauth/OAuthApi.java
+31
-22
No files found.
src/main/java/com/egolm/sso/oauth/OAuthApi.java
View file @
57d14644
...
...
@@ -33,7 +33,7 @@ public interface OAuthApi {
default
boolean
isLogin
()
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
return
token
!=
null
;
}
...
...
@@ -41,7 +41,12 @@ public interface OAuthApi {
try
{
HttpServletResponse
response
=
this
.
getHttpServletResponse
();
OAuthConfig
config
=
this
.
getOAuthConfig
();
UrlBuilder
split
=
new
UrlBuilder
(
config
.
getAuthorizeUrl
()).
setParameter
(
"scope"
,
config
.
getScope
()).
setParameter
(
"response_type"
,
OAuth
.
OAUTH_CODE
).
setParameter
(
"realm"
,
config
.
getRealm
()).
setParameter
(
"client_id"
,
config
.
getClientId
()).
setParameter
(
"redirect_uri"
,
config
.
getRediretUrl
());
UrlBuilder
split
=
new
UrlBuilder
(
config
.
getAuthorizeUrl
())
.
setParameter
(
"scope"
,
config
.
getScope
())
.
setParameter
(
"response_type"
,
OAuth
.
OAUTH_CODE
)
.
setParameter
(
"realm"
,
config
.
getRealm
())
.
setParameter
(
"client_id"
,
config
.
getClientId
())
.
setParameter
(
"redirect_uri"
,
config
.
getRediretUrl
());
String
urlString
=
split
.
toUrlString
();
response
.
sendRedirect
(
urlString
);
}
catch
(
Exception
e
)
{
...
...
@@ -53,8 +58,8 @@ public interface OAuthApi {
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
if
(
token
==
null
)
{
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
if
(
token
==
null
)
{
OAuthConfig
config
=
this
.
getOAuthConfig
();
OAuthAuthzResponse
oauthAuthzResponse
=
OAuthAuthzResponse
.
oauthCodeAuthzResponse
(
request
);
String
code
=
oauthAuthzResponse
.
getCode
();
...
...
@@ -66,7 +71,8 @@ public interface OAuthApi {
builder
.
setCode
(
code
);
OAuthClientRequest
oauthClientRequest
=
builder
.
buildQueryMessage
();
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
String
accessToken
=
oAuthResponse
.
getAccessToken
();
String
refreshToken
=
oAuthResponse
.
getRefreshToken
();
Long
expiresIn
=
oAuthResponse
.
getExpiresIn
();
...
...
@@ -93,7 +99,7 @@ public interface OAuthApi {
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthConfig
config
=
this
.
getOAuthConfig
();
TokenRequestBuilder
builder
=
OAuthClientRequest
.
tokenLocation
(
config
.
getAccessTokenUrl
());
builder
.
setGrantType
(
GrantType
.
REFRESH_TOKEN
);
...
...
@@ -102,7 +108,8 @@ public interface OAuthApi {
builder
.
setClientSecret
(
config
.
getClientSecret
());
OAuthClientRequest
oauthClientRequest
=
builder
.
buildQueryMessage
();
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
OAuthJSONAccessTokenResponse
oAuthResponse
=
oAuthClient
.
accessToken
(
oauthClientRequest
,
OAuth
.
HttpMethod
.
POST
);
String
accessToken
=
oAuthResponse
.
getAccessToken
();
String
refreshToken
=
oAuthResponse
.
getRefreshToken
();
Long
expiresIn
=
oAuthResponse
.
getExpiresIn
();
...
...
@@ -129,13 +136,15 @@ public interface OAuthApi {
headers
.
put
(
"X-SE-IFW-ApplicationName"
,
applicationName
);
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthClient
oAuthClient
=
new
OAuthClient
(
new
URLConnectionClient
());
String
accessToken
=
token
.
getAccessToken
();
OAuthClientRequest
clientRequest
=
new
OAuthBearerClientRequest
(
url
).
setAccessToken
(
accessToken
).
buildQueryMessage
();
OAuthClientRequest
clientRequest
=
new
OAuthBearerClientRequest
(
url
).
setAccessToken
(
accessToken
)
.
buildQueryMessage
();
clientRequest
.
setBody
(
data
.
toString
());
clientRequest
.
setHeaders
(
headers
);
OAuthResourceResponse
resourceResponse
=
oAuthClient
.
resource
(
clientRequest
,
"POST"
,
OAuthResourceResponse
.
class
);
OAuthResourceResponse
resourceResponse
=
oAuthClient
.
resource
(
clientRequest
,
"POST"
,
OAuthResourceResponse
.
class
);
String
resBody
=
resourceResponse
.
getBody
();
return
resBody
;
}
catch
(
OAuthProblemException
e
)
{
...
...
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