Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cas-relay
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
jiatao
cas-relay
Commits
f288e28a
Commit
f288e28a
authored
Jul 14, 2026
by
jiatao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善sso.json文件
parent
13e594d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
1 deletion
+48
-1
WeComRelayController.java
...n/java/com/jd/easywalk/casrelay/WeComRelayController.java
+39
-1
WeComRelayService.java
...main/java/com/jd/easywalk/casrelay/WeComRelayService.java
+8
-0
sso.wecom.mock.example.json
sso.wecom.mock.example.json
+1
-0
No files found.
src/main/java/com/jd/easywalk/casrelay/WeComRelayController.java
View file @
f288e28a
...
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.servlet.view.RedirectView
;
import
org.springframework.web.servlet.view.RedirectView
;
import
org.springframework.web.util.UriComponentsBuilder
;
@RestController
@RestController
@RequestMapping
(
"/wecom/oauth2"
)
@RequestMapping
(
"/wecom/oauth2"
)
...
@@ -20,9 +21,11 @@ public class WeComRelayController {
...
@@ -20,9 +21,11 @@ public class WeComRelayController {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
WeComRelayController
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
WeComRelayController
.
class
);
private
final
WeComRelayService
weComRelayService
;
private
final
WeComRelayService
weComRelayService
;
private
final
CasRelayProperties
casRelayProperties
;
public
WeComRelayController
(
WeComRelayService
weComRelayService
)
{
public
WeComRelayController
(
WeComRelayService
weComRelayService
,
CasRelayProperties
casRelayProperties
)
{
this
.
weComRelayService
=
weComRelayService
;
this
.
weComRelayService
=
weComRelayService
;
this
.
casRelayProperties
=
casRelayProperties
;
}
}
@GetMapping
({
"/authorize"
,
"/login"
})
@GetMapping
({
"/authorize"
,
"/login"
})
...
@@ -64,4 +67,39 @@ public class WeComRelayController {
...
@@ -64,4 +67,39 @@ public class WeComRelayController {
StringUtils
.
hasText
(
token
),
StringUtils
.
hasText
(
access_token
),
weComRelayService
.
maskForLog
(
realToken
));
StringUtils
.
hasText
(
token
),
StringUtils
.
hasText
(
access_token
),
weComRelayService
.
maskForLog
(
realToken
));
return
ResponseEntity
.
ok
(
weComRelayService
.
userInfo
(
realToken
));
return
ResponseEntity
.
ok
(
weComRelayService
.
userInfo
(
realToken
));
}
}
@GetMapping
(
"/logout"
)
public
RedirectView
logout
(
@RequestParam
(
required
=
false
)
String
token
,
@RequestParam
(
required
=
false
)
String
service
)
{
weComRelayService
.
revokeLocalToken
(
token
);
UriComponentsBuilder
builder
=
UriComponentsBuilder
.
fromHttpUrl
(
trimTrailingSlash
(
casRelayProperties
.
getServerUrlPrefix
())
+
normalizePath
(
casRelayProperties
.
getLogoutPath
()));
if
(
StringUtils
.
hasText
(
service
))
{
builder
.
queryParam
(
"service"
,
service
);
}
String
target
=
builder
.
build
().
toUriString
();
log
.
info
(
"WeCom OAuth relay logout redirect: hasToken={}, service={}, target={}"
,
StringUtils
.
hasText
(
token
),
service
,
target
);
RedirectView
redirectView
=
new
RedirectView
(
target
);
redirectView
.
setExpandUriTemplateVariables
(
false
);
return
redirectView
;
}
private
String
trimTrailingSlash
(
String
value
)
{
if
(!
StringUtils
.
hasText
(
value
))
{
return
""
;
}
return
value
.
endsWith
(
"/"
)
?
value
.
substring
(
0
,
value
.
length
()
-
1
)
:
value
;
}
private
String
normalizePath
(
String
value
)
{
if
(!
StringUtils
.
hasText
(
value
))
{
return
""
;
}
return
value
.
startsWith
(
"/"
)
?
value
:
"/"
+
value
;
}
}
}
src/main/java/com/jd/easywalk/casrelay/WeComRelayService.java
View file @
f288e28a
...
@@ -326,6 +326,14 @@ public class WeComRelayService {
...
@@ -326,6 +326,14 @@ public class WeComRelayService {
return
mask
(
value
);
return
mask
(
value
);
}
}
public
void
revokeLocalToken
(
String
token
)
{
if
(!
StringUtils
.
hasText
(
token
))
{
return
;
}
LocalToken
removed
=
localTokens
.
remove
(
token
);
log
.
info
(
"Campus OAuth relay local token revoked: token={}, existed={}"
,
mask
(
token
),
removed
!=
null
);
}
private
String
getCorpAccessToken
()
throws
Exception
{
private
String
getCorpAccessToken
()
throws
Exception
{
CorpAccessToken
current
=
corpAccessToken
;
CorpAccessToken
current
=
corpAccessToken
;
if
(
current
!=
null
&&
!
current
.
isExpired
())
{
if
(
current
!=
null
&&
!
current
.
isExpired
())
{
...
...
sso.wecom.mock.example.json
View file @
f288e28a
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
"authorizePath"
:
"/wecom/oauth2/mock/authorize"
,
"authorizePath"
:
"/wecom/oauth2/mock/authorize"
,
"tokenPath"
:
"/wecom/oauth2/access_token"
,
"tokenPath"
:
"/wecom/oauth2/access_token"
,
"userInfoUrl"
:
"https://casrelay.xidian.edu.cn/wecom/oauth2/userinfo"
,
"userInfoUrl"
:
"https://casrelay.xidian.edu.cn/wecom/oauth2/userinfo"
,
"logout"
:
"https://casrelay.xidian.edu.cn/wecom/oauth2/logout"
,
"tokenKeyParamName"
:
"token"
,
"tokenKeyParamName"
:
"token"
,
"authorizationMethod"
:
"body"
,
"authorizationMethod"
:
"body"
,
"bodyFormat"
:
"form"
,
"bodyFormat"
:
"form"
,
...
...
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