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
45ec31fe
Commit
45ec31fe
authored
Aug 07, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
0d6622ec
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
11 deletions
+43
-11
OAuthApi.java
src/main/java/com/egolm/sso/oauth/OAuthApi.java
+43
-11
No files found.
src/main/java/com/egolm/sso/oauth/OAuthApi.java
View file @
45ec31fe
...
@@ -40,10 +40,28 @@ public interface OAuthApi {
...
@@ -40,10 +40,28 @@ public interface OAuthApi {
}
}
default
OAuthToken
getOAuthToken
()
{
default
OAuthToken
getOAuthToken
()
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
HttpSession
session
=
request
.
getSession
();
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
OAuthToken
token
=
(
OAuthToken
)
session
.
getAttribute
(
OAUTH_TOKEN_SESSION
);
return
token
;
return
token
;
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
default
void
doOAuthLogin
()
{
try
{
String
redirectUrl
=
this
.
getOAuthPath
();
HttpServletResponse
response
=
this
.
getHttpServletResponse
();
response
.
sendRedirect
(
redirectUrl
);
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
}
default
String
getOAuthPath
()
{
default
String
getOAuthPath
()
{
...
@@ -60,6 +78,8 @@ public interface OAuthApi {
...
@@ -60,6 +78,8 @@ public interface OAuthApi {
redirectUrl
=
redirectUrl
.
replaceAll
(
"\\+"
,
"%20"
);
redirectUrl
=
redirectUrl
.
replaceAll
(
"\\+"
,
"%20"
);
logger
.
debug
(
"redirect:"
+
redirectUrl
);
logger
.
debug
(
"redirect:"
+
redirectUrl
);
return
redirectUrl
;
return
redirectUrl
;
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
...
@@ -93,16 +113,24 @@ public interface OAuthApi {
...
@@ -93,16 +113,24 @@ public interface OAuthApi {
}
else
{
}
else
{
throw
new
OAuthApiException
(
"OAuthToken already exists"
);
throw
new
OAuthApiException
(
"OAuthToken already exists"
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
}
}
default
void
doLogout
()
{
default
void
doLogout
()
{
try
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
HttpSession
session
=
request
.
getSession
();
session
.
removeAttribute
(
OAUTH_TOKEN_SESSION
);
session
.
removeAttribute
(
OAUTH_TOKEN_SESSION
);
session
.
invalidate
();
session
.
invalidate
();
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
}
default
void
refresh
()
{
default
void
refresh
()
{
...
@@ -126,7 +154,9 @@ public interface OAuthApi {
...
@@ -126,7 +154,9 @@ public interface OAuthApi {
String
tokenType
=
oAuthResponse
.
getTokenType
();
String
tokenType
=
oAuthResponse
.
getTokenType
();
OAuthToken
newToken
=
new
OAuthToken
(
accessToken
,
refreshToken
,
idToken
,
tokenType
,
expiresIn
);
OAuthToken
newToken
=
new
OAuthToken
(
accessToken
,
refreshToken
,
idToken
,
tokenType
,
expiresIn
);
session
.
setAttribute
(
OAUTH_TOKEN_SESSION
,
newToken
);
session
.
setAttribute
(
OAUTH_TOKEN_SESSION
,
newToken
);
}
catch
(
Exception
e
)
{
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
}
}
...
@@ -154,10 +184,12 @@ public interface OAuthApi {
...
@@ -154,10 +184,12 @@ public interface OAuthApi {
OAuthResourceResponse
resourceResponse
=
oAuthClient
.
resource
(
clientRequest
,
"POST"
,
OAuthResourceResponse
.
class
);
OAuthResourceResponse
resourceResponse
=
oAuthClient
.
resource
(
clientRequest
,
"POST"
,
OAuthResourceResponse
.
class
);
String
resBody
=
resourceResponse
.
getBody
();
String
resBody
=
resourceResponse
.
getBody
();
return
resBody
;
return
resBody
;
}
catch
(
OAuthApiException
e
)
{
throw
e
;
}
catch
(
OAuthProblemException
e
)
{
}
catch
(
OAuthProblemException
e
)
{
this
.
refresh
();
this
.
refresh
();
return
doPost
(
url
,
headers
,
data
);
return
doPost
(
url
,
headers
,
data
);
}
catch
(
Exception
e
)
{
}
catch
(
Throwable
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
throw
new
OAuthApiException
(
e
.
getMessage
(),
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