Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
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
lanmw
loginservice
Commits
bcb3b51f
Commit
bcb3b51f
authored
Feb 25, 2021
by
chenzx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改接口请求放回的数据
parent
a0282805
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
14 deletions
+10
-14
SecurityConfig.java
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
+10
-14
No files found.
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
View file @
bcb3b51f
...
...
@@ -61,6 +61,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.
csrf
().
disable
();
}
public
static
String
baseUrl
=
"http://cas.zua.edu.cn/oauth2.0/authorize?response_type=code&client_id=tVnAsJna9Y&redirect_uri=http://10.60.60.127:8091/api/auth/sso"
;
// 获取 code : http://cas.zua.edu.cn/oauth2.0/authorize?response_type=cod e&client_id=clientId&redirect_uri=ssoUrl 认证成功之后会跳转到 redirect_uri ,并且连接后面会带着code参数。
@Bean
public
AbstractAuthenticationProcessingFilter
authenticationFilter
()
throws
Exception
{
...
...
@@ -71,7 +72,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
//回调到这里获取用户的code
String
code
=
httpServletRequest
.
getParameter
(
"code"
);
if
(
null
==
code
){
httpServletResponse
.
sendRedirect
(
"/refuse?code=401"
);
httpServletResponse
.
sendRedirect
(
baseUrl
);
return
null
;
}
//获取 accessToken
...
...
@@ -83,30 +84,25 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
map
.
put
(
"redirect_uri"
,
ssoUrl
);
map
.
put
(
"code"
,
code
);
System
.
out
.
println
(
"param:--------->"
+
map
.
toString
());
JSONObject
jsonObject
=
null
;
String
accessToken
=
""
;
try
{
jsonObject
=
JSONObject
.
fromObject
(
HttpClientUtil
.
doPost
(
"http://cas.zua.edu.cn/oauth2.0/accessToken"
,
map
)
);
accessToken
=
HttpClientUtil
.
doPost
(
"http://cas.zua.edu.cn/oauth2.0/accessToken"
,
map
);
}
catch
(
Exception
e
){
System
.
out
.
println
(
e
.
getMessage
());
e
.
printStackTrace
();
}
String
accessToken
=
""
;
if
(
null
!=
jsonObject
){
if
(
null
!=
accessToken
){
//返回内容 access_token=AT-1-vDqPefqwHJl39iUtsAh19oI1vwAIQn6k&expires_in=28800
System
.
out
.
println
(
"request return:--------->"
+
jsonObject
.
toString
());
accessToken
=
jsonObject
.
get
(
"accessToken"
).
toString
();
System
.
out
.
println
(
"request return:--------->"
+
accessToken
);
}
else
{
System
.
out
.
println
(
"
jsonObject
is null"
);
System
.
out
.
println
(
"
accessToken
is null"
);
}
if
(!
StringUtils
.
isEmpty
(
accessToken
)){
httpServletResponse
.
sendRedirect
(
"/refuse?code=402"
);
if
(
StringUtils
.
isEmpty
(
accessToken
)){
httpServletResponse
.
sendRedirect
(
baseUrl
);
return
null
;
}
//根据token获取用户信息
Map
map2
=
new
HashMap
();
map2
.
put
(
"access_token="
,
"authorization_code"
);
JSONObject
object
=
JSONObject
.
fromObject
(
HttpClientUtil
.
doGet
(
"http://cas.zua.edu.cn/oauth2.0/profile"
,
map
));
JSONObject
object
=
JSONObject
.
fromObject
(
HttpClientUtil
.
doGet
(
"http://cas.zua.edu.cn/oauth2.0/profile?"
+
accessToken
));
//返回内容 { "attributes" : { "changeCodeStatus" : "1", "credentialType" : "UsernamePasswordCredential", "id" : "1676604", "nickName" : "张凤元", "organizationId" : "104001000", "realName" : "张凤元", <真实姓名> "sex" : "0", <性别> "userNumber" : "003213" <学号/工号> },"id" : "003213" }
String
loginName
=
object
.
get
(
"id"
).
toString
();
if
(!
checkToken
(
loginName
)){
...
...
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