Commit f288e28a authored by jiatao's avatar jiatao

完善sso.json文件

parent 13e594d6
...@@ -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;
}
} }
...@@ -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()) {
......
...@@ -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",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment