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
ba192c5a
Commit
ba192c5a
authored
Jul 29, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
4842e714
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
16 deletions
+57
-16
OAuthApi.java
src/main/java/com/egolm/sso/oauth/OAuthApi.java
+3
-16
UrlBuilder.java
src/main/java/com/egolm/sso/oauth/UrlBuilder.java
+54
-0
No files found.
src/main/java/com/egolm/sso/oauth/OAuthApi.java
View file @
ba192c5a
package
com
.
egolm
.
sso
.
oauth
;
package
com
.
egolm
.
sso
.
oauth
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -12,7 +10,6 @@ import org.apache.oltu.oauth2.client.OAuthClient;
...
@@ -12,7 +10,6 @@ import org.apache.oltu.oauth2.client.OAuthClient;
import
org.apache.oltu.oauth2.client.URLConnectionClient
;
import
org.apache.oltu.oauth2.client.URLConnectionClient
;
import
org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest
;
import
org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest
;
import
org.apache.oltu.oauth2.client.request.OAuthClientRequest
;
import
org.apache.oltu.oauth2.client.request.OAuthClientRequest
;
import
org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder
;
import
org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder
;
import
org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder
;
import
org.apache.oltu.oauth2.client.response.OAuthAuthzResponse
;
import
org.apache.oltu.oauth2.client.response.OAuthAuthzResponse
;
import
org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse
;
import
org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse
;
...
@@ -33,10 +30,6 @@ public interface OAuthApi {
...
@@ -33,10 +30,6 @@ public interface OAuthApi {
final
String
OAUTH_TOKEN_SESSION
=
"OAUTH2_TOKEN_SESSION_KEY"
;
final
String
OAUTH_TOKEN_SESSION
=
"OAUTH2_TOKEN_SESSION_KEY"
;
public
static
void
main
(
String
[]
args
)
throws
UnsupportedEncodingException
{
System
.
out
.
println
(
URLDecoder
.
decode
(
"https://identity-stg.schneider-electric.com/accessmanager/oauth2/authorize?scope=openid%2Bprofile&response_type=code&realm=%2Fse&redirect_uri=http%3A%2F%2F25d733423o.qicp.vip%2FdoLogin&client_id=clientId"
,
"utf-8"
));
}
default
boolean
isLogin
()
{
default
boolean
isLogin
()
{
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpServletRequest
request
=
this
.
getHttpServletRequest
();
HttpSession
session
=
request
.
getSession
();
HttpSession
session
=
request
.
getSession
();
...
@@ -48,15 +41,9 @@ public interface OAuthApi {
...
@@ -48,15 +41,9 @@ public interface OAuthApi {
try
{
try
{
HttpServletResponse
response
=
this
.
getHttpServletResponse
();
HttpServletResponse
response
=
this
.
getHttpServletResponse
();
OAuthConfig
config
=
this
.
getOAuthConfig
();
OAuthConfig
config
=
this
.
getOAuthConfig
();
AuthenticationRequestBuilder
builder
=
OAuthClientRequest
.
authorizationLocation
(
config
.
getAuthorizeUrl
());
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
());
builder
.
setResponseType
(
OAuth
.
OAUTH_CODE
);
String
urlString
=
split
.
toUrlString
();
builder
.
setClientId
(
config
.
getClientId
());
response
.
sendRedirect
(
urlString
);
builder
.
setRedirectURI
(
config
.
getRediretUrl
());
System
.
out
.
println
(
config
.
getScope
());
builder
.
setScope
(
config
.
getScope
());
builder
.
setParameter
(
"realm"
,
config
.
getRealm
());
OAuthClientRequest
oauthResponse
=
builder
.
buildQueryMessage
();
response
.
sendRedirect
(
oauthResponse
.
getLocationUri
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
throw
new
OAuthApiException
(
e
.
getMessage
(),
e
);
}
}
...
...
src/main/java/com/egolm/sso/oauth/UrlBuilder.java
0 → 100644
View file @
ba192c5a
package
com
.
egolm
.
sso
.
oauth
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Map
;
import
java.util.TreeMap
;
public
class
UrlBuilder
{
private
String
url
;
private
Map
<
String
,
String
>
parameters
=
new
TreeMap
<
String
,
String
>();
private
Map
<
String
,
String
>
headers
=
new
TreeMap
<
String
,
String
>();
public
UrlBuilder
(
String
url
)
{
this
.
url
=
url
;
}
public
UrlBuilder
setParameter
(
String
key
,
String
value
)
{
parameters
.
put
(
key
,
value
);
return
this
;
}
public
UrlBuilder
setHeader
(
String
key
,
String
value
)
{
headers
.
put
(
key
,
value
);
return
this
;
}
public
Map
<
String
,
String
>
getHeaders
()
{
return
headers
;
}
public
String
toUrlString
()
throws
UnsupportedEncodingException
{
StringBuffer
sb
=
new
StringBuffer
(
url
);
if
(!
url
.
contains
(
"?"
))
{
sb
.
append
(
"?"
);
}
else
{
sb
.
append
(
"&"
);
}
for
(
String
key
:
parameters
.
keySet
())
{
String
value
=
parameters
.
get
(
key
);
if
(
value
==
null
)
{
value
=
""
;
}
value
=
value
.
trim
();
sb
.
append
(
key
).
append
(
"="
).
append
(
URLEncoder
.
encode
(
value
,
"utf-8"
)).
append
(
"&"
);
}
String
urlString
=
sb
.
toString
();
if
(
urlString
.
endsWith
(
"&"
))
{
urlString
=
urlString
.
substring
(
0
,
urlString
.
length
()
-
1
);
}
return
urlString
;
}
}
\ No newline at end of file
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