Commit 13e594d6 authored by jiatao's avatar jiatao

完善sso.json文件

parent bf7142c4
CAS_RELAY_PORT=18080
CAS_SERVICE_URL=https://nercwbs-lms.xidian.edu.cn/orgsso
CAS_SERVER_URL_PREFIX=https://ids.xidian.edu.cn/authserver
CAS_SERVICE_VALIDATE_PATH=/serviceValidate
CAS_LOGIN_PATH=/login
CAS_LOGOUT_PATH=/logout
MINGDAO_ENABLED=true
MINGDAO_REFRESH_ENABLED=true
MINGDAO_REFRESH_INTERVAL_MS=600000
MINGDAO_API_URL=https://nercwbs-lms.xidian.edu.cn/api/v2/open/worksheet/getFilterRows
MINGDAO_APP_KEY=3ed6154939e6aa92
MINGDAO_SIGN= MDM0ZWU1YWM4NzM0ODljZTZiNDJlYmUwYzRmODU4OTNlN2ZkYzIwMjI1ZjBhNzIwZjA4OWU3YzQ1NTdiNGM0Mg==
OAUTH_CLIENT_ID=1506958348348624896
OAUTH_CLIENT_SECRET=19E483DC4D272E4JD5KD
OAUTH_REDIRECT_URI=https://nercwbs-lms.xidian.edu.cn/orgsso/oauth2
OAUTH_AUTHORIZATION_URI=https://ids.xidian.edu.cn/authserver/oauth2.0/authorize
OAUTH_TOKEN_URI=https://ids.xidian.edu.cn/authserver/oauth2.0/accessToken
OAUTH_USER_INFO_URI=https://ids.xidian.edu.cn/authserver/oauthApi/user/profile
OAUTH_USER_MOBILE_URI=https://ids.xidian.edu.cn/authserver/oauthApi/user/getMobile
WECOM_RELAY_ENABLED=true
WECOM_APP_ID=200260525100013951
WECOM_APP_SECRET=8ekpsdgmb9eh3m9w1gf3s1nm5ft2b3ne
WECOM_PLATFORM_DOMAIN=xxcapp.xidian.edu.cn
WECOM_CORP_ID=
WECOM_AGENT_ID=
WECOM_CORP_SECRET=
WECOM_REDIRECT_URI=https://nercwbs-lms.xidian.edu.cn/orgsso/oauth2
WECOM_AUTHORIZATION_URI=https://xxcapp.xidian.edu.cn/uc/api/oauth/index
WECOM_AUTHORIZATION_APP_ID_PARAM=appid
WECOM_AUTHORIZATION_REDIRECT_URI_PARAM=redirect
WECOM_AUTHORIZATION_RESPONSE_TYPE_PARAM=
WECOM_AUTHORIZATION_SCOPE_PARAM=
WECOM_AUTHORIZATION_STATE_PARAM=state
WECOM_AUTHORIZATION_QRCODE_PARAM=qrcode
WECOM_AUTHORIZATION_QRCODE_VALUE=1
WECOM_ACCESS_TOKEN_URI=https://qyapi.weixin.qq.com/cgi-bin/gettoken
WECOM_CODE_USER_INFO_URI=https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo
WECOM_USER_DETAIL_URI=https://qyapi.weixin.qq.com/cgi-bin/user/get
WECOM_SCOPE=snsapi_base
WECOM_MOCK_ENABLED=false
WECOM_MOCK_WORK_NO=20240001
WECOM_MOCK_NAME=Mock User
WECOM_MOCK_EMAIL=20240001@xidian.edu.cn
WECOM_MOCK_MOBILE=13800000000
......@@ -19,3 +19,37 @@ OAUTH_AUTHORIZATION_URI=https://ids.xidian.edu.cn/authserver/oauth2.0/authorize
OAUTH_TOKEN_URI=https://ids.xidian.edu.cn/authserver/oauth2.0/accessToken
OAUTH_USER_INFO_URI=https://ids.xidian.edu.cn/authserver/oauthApi/user/profile
OAUTH_USER_MOBILE_URI=https://ids.xidian.edu.cn/authserver/oauthApi/user/getMobile
WECOM_RELAY_ENABLED=false
WECOM_APP_ID=200260525100013951
WECOM_APP_SECRET=
WECOM_PLATFORM_DOMAIN=xxcapp.xidian.edu.cn
WECOM_CORP_ID=
WECOM_AGENT_ID=
WECOM_CORP_SECRET=
WECOM_REDIRECT_URI=https://nercwbs-lms.xidian.edu.cn/orgsso/oauth2
WECOM_ALLOWED_REDIRECT_HOST=nercwbs-lms.xidian.edu.cn
WECOM_AUTHORIZATION_URI=https://xxcapp.xidian.edu.cn/uc/api/oauth/index
WECOM_AUTHORIZATION_APP_ID_PARAM=appid
WECOM_AUTHORIZATION_REDIRECT_URI_PARAM=redirect
WECOM_AUTHORIZATION_RESPONSE_TYPE_PARAM=
WECOM_AUTHORIZATION_SCOPE_PARAM=
WECOM_AUTHORIZATION_STATE_PARAM=state
WECOM_AUTHORIZATION_QRCODE_PARAM=qrcode
WECOM_AUTHORIZATION_QRCODE_VALUE=1
WECOM_CODE_EXCHANGE_URI=https://xxcapp.xidian.edu.cn/api/third/get-token
WECOM_TOKEN_USER_INFO_URI=https://xxcapp.xidian.edu.cn/uc/api/oauth/user-by-code
WECOM_CODE_PARAM=code
WECOM_CODE_EXCHANGE_APP_ID_PARAM=appid
WECOM_CODE_EXCHANGE_APP_SECRET_PARAM=appsecret
WECOM_TOKEN_USER_INFO_TOKEN_PARAM=access_token
WECOM_PLATFORM_ACCESS_TOKEN_SKEW_SECONDS=300
WECOM_ACCESS_TOKEN_URI=
WECOM_CODE_USER_INFO_URI=
WECOM_USER_DETAIL_URI=
WECOM_SCOPE=snsapi_base
WECOM_MOCK_ENABLED=false
WECOM_MOCK_WORK_NO=20240001
WECOM_MOCK_NAME=MockUser
WECOM_MOCK_EMAIL=20240001@xidian.edu.cn
WECOM_MOCK_MOBILE=13800000000
FROM openjdk:8
FROM eclipse-temurin:8-jre
WORKDIR /app
......
......@@ -14,6 +14,17 @@ services:
MINGDAO_REFRESH_INTERVAL_MS: "${MINGDAO_REFRESH_INTERVAL_MS:-600000}"
MINGDAO_APP_KEY: "${MINGDAO_APP_KEY}"
MINGDAO_SIGN: "${MINGDAO_SIGN}"
WECOM_RELAY_ENABLED: "${WECOM_RELAY_ENABLED:-false}"
WECOM_APP_ID: "${WECOM_APP_ID:-200260525100013951}"
WECOM_APP_SECRET: "${WECOM_APP_SECRET:-}"
WECOM_PLATFORM_DOMAIN: "${WECOM_PLATFORM_DOMAIN:-xxcapp.xidian.edu.cn}"
WECOM_REDIRECT_URI: "${WECOM_REDIRECT_URI:-https://nercwbs-lms.xidian.edu.cn/orgsso/oauth2}"
WECOM_ALLOWED_REDIRECT_HOST: "${WECOM_ALLOWED_REDIRECT_HOST:-nercwbs-lms.xidian.edu.cn}"
WECOM_AUTHORIZATION_URI: "${WECOM_AUTHORIZATION_URI:-https://xxcapp.xidian.edu.cn/uc/api/oauth/index}"
WECOM_AUTHORIZATION_APP_ID_PARAM: "${WECOM_AUTHORIZATION_APP_ID_PARAM:-appid}"
WECOM_AUTHORIZATION_REDIRECT_URI_PARAM: "${WECOM_AUTHORIZATION_REDIRECT_URI_PARAM:-redirect}"
WECOM_AUTHORIZATION_QRCODE_PARAM: "${WECOM_AUTHORIZATION_QRCODE_PARAM:-qrcode}"
WECOM_AUTHORIZATION_QRCODE_VALUE: "${WECOM_AUTHORIZATION_QRCODE_VALUE:-1}"
JAVA_OPTS: >-
-Dcas.service=${CAS_SERVICE_URL}
-Dcas.server-url-prefix=${CAS_SERVER_URL_PREFIX:-https://ids.xidian.edu.cn/authserver}
......@@ -28,3 +39,15 @@ services:
-Doauth-relay.token-uri=${OAUTH_TOKEN_URI:-https://ids.xidian.edu.cn/authserver/oauth2.0/accessToken}
-Doauth-relay.user-info-uri=${OAUTH_USER_INFO_URI:-https://ids.xidian.edu.cn/authserver/oauthApi/user/profile}
-Doauth-relay.user-mobile-uri=${OAUTH_USER_MOBILE_URI:-https://ids.xidian.edu.cn/authserver/oauthApi/user/getMobile}
-Dwecom-relay.code-exchange-uri=${WECOM_CODE_EXCHANGE_URI:-https://xxcapp.xidian.edu.cn/api/third/get-token}
-Dwecom-relay.token-user-info-uri=${WECOM_TOKEN_USER_INFO_URI:-https://xxcapp.xidian.edu.cn/uc/api/oauth/user-by-code}
-Dwecom-relay.code-param=${WECOM_CODE_PARAM:-code}
-Dwecom-relay.code-exchange-app-id-param=${WECOM_CODE_EXCHANGE_APP_ID_PARAM:-appid}
-Dwecom-relay.code-exchange-app-secret-param=${WECOM_CODE_EXCHANGE_APP_SECRET_PARAM:-appsecret}
-Dwecom-relay.token-user-info-token-param=${WECOM_TOKEN_USER_INFO_TOKEN_PARAM:-access_token}
-Dwecom-relay.platform-access-token-skew-seconds=${WECOM_PLATFORM_ACCESS_TOKEN_SKEW_SECONDS:-300}
-Dwecom-relay.allowed-redirect-host=${WECOM_ALLOWED_REDIRECT_HOST:-nercwbs-lms.xidian.edu.cn}
-Dwecom-relay.access-token-uri=${WECOM_ACCESS_TOKEN_URI:-}
-Dwecom-relay.code-user-info-uri=${WECOM_CODE_USER_INFO_URI:-}
-Dwecom-relay.user-detail-uri=${WECOM_USER_DETAIL_URI:-}
-Dwecom-relay.scope=${WECOM_SCOPE:-snsapi_base}
......@@ -7,7 +7,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
@EnableConfigurationProperties({CasRelayProperties.class, MingdaoProperties.class, OAuthRelayProperties.class})
@EnableConfigurationProperties({CasRelayProperties.class, MingdaoProperties.class, OAuthRelayProperties.class,
WeComRelayProperties.class})
public class CasRelayApplication {
public static void main(String[] args) {
......
package com.jd.easywalk.casrelay;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertiesPropertySource;
public class DotenvPropertySourceInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final Logger log = LoggerFactory.getLogger(DotenvPropertySourceInitializer.class);
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
Properties properties = new Properties();
try (InputStream inputStream = new FileInputStream(".env")) {
properties.load(inputStream);
} catch (Exception ex) {
log.info("Local .env file not loaded: {}", ex.getMessage());
return;
}
ConfigurableEnvironment environment = applicationContext.getEnvironment();
environment.getPropertySources().addLast(new PropertiesPropertySource("localDotenv", properties));
log.info("Local .env file loaded");
}
}
......@@ -26,6 +26,7 @@ public class TeacherDirectoryService {
private final MingdaoProperties properties;
private final RestTemplate restTemplate;
private final Map<String, TeacherInfo> teachersByWorkNo = new ConcurrentHashMap<String, TeacherInfo>();
private final Map<String, TeacherInfo> teachersByMobile = new ConcurrentHashMap<String, TeacherInfo>();
public TeacherDirectoryService(MingdaoProperties properties, RestTemplateBuilder restTemplateBuilder) {
this.properties = properties;
......@@ -45,6 +46,7 @@ public class TeacherDirectoryService {
validateConfig();
Map<String, TeacherInfo> loaded = new HashMap<String, TeacherInfo>();
Map<String, TeacherInfo> loadedByMobile = new HashMap<String, TeacherInfo>();
int pageIndex = 1;
int pageSize = Math.max(properties.getPageSize(), 1);
while (true) {
......@@ -58,6 +60,9 @@ public class TeacherDirectoryService {
TeacherInfo teacher = toTeacherInfo(row);
if (teacher != null) {
loaded.put(teacher.getWorkNo(), teacher);
if (StringUtils.hasText(teacher.getMobile())) {
loadedByMobile.put(teacher.getMobile().trim(), teacher);
}
}
}
......@@ -69,6 +74,8 @@ public class TeacherDirectoryService {
teachersByWorkNo.clear();
teachersByWorkNo.putAll(loaded);
teachersByMobile.clear();
teachersByMobile.putAll(loadedByMobile);
log.info("Loaded {} teachers from Mingdao worksheet", teachersByWorkNo.size());
logTeacherDetails();
}
......@@ -80,6 +87,13 @@ public class TeacherDirectoryService {
return teachersByWorkNo.get(workNo.trim());
}
public TeacherInfo findByMobile(String mobile) {
if (!StringUtils.hasText(mobile)) {
return null;
}
return teachersByMobile.get(mobile.trim());
}
public int size() {
return teachersByWorkNo.size();
}
......
package com.jd.easywalk.casrelay;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.view.RedirectView;
@RestController
@RequestMapping("/wecom/oauth2")
public class WeComRelayController {
private static final Logger log = LoggerFactory.getLogger(WeComRelayController.class);
private final WeComRelayService weComRelayService;
public WeComRelayController(WeComRelayService weComRelayService) {
this.weComRelayService = weComRelayService;
}
@GetMapping({"/authorize", "/login"})
public RedirectView authorize(@RequestParam Map<String, String> params) {
String target = weComRelayService.buildAuthorizationRedirect(params);
log.info("WeCom OAuth relay authorize request: redirectUri={}, state={}, target={}",
params.get("redirect_uri"), params.get("state"), target);
RedirectView redirectView = new RedirectView(target);
redirectView.setExpandUriTemplateVariables(false);
return redirectView;
}
@GetMapping("/mock/authorize")
public RedirectView mockAuthorize(@RequestParam Map<String, String> params) {
String target = weComRelayService.buildMockAuthorizationRedirect(params);
log.info("WeCom OAuth relay mock authorize request: redirectUri={}, state={}, target={}",
params.get("redirect_uri"), params.get("state"), target);
RedirectView redirectView = new RedirectView(target);
redirectView.setExpandUriTemplateVariables(false);
return redirectView;
}
@PostMapping({"/access_token", "/token"})
public ResponseEntity<Map<String, Object>> accessToken(@RequestParam Map<String, String> params) {
log.info("WeCom OAuth relay token request received: grantType={}, hasCode={}, redirectUri={}",
params.get("grant_type"), StringUtils.hasText(params.get("code")), params.get("redirect_uri"));
Map<String, Object> body = weComRelayService.exchangeToken(params);
log.info("WeCom OAuth relay token response generated: keys={}, hasAccessToken={}, error={}",
body.keySet(), body.containsKey("access_token"), body.get("error_description"));
return ResponseEntity.ok(body);
}
@GetMapping({"/userinfo", "/user_info"})
public ResponseEntity<Map<String, Object>> userInfo(
@RequestParam(required = false) String token,
@RequestParam(required = false) String access_token) {
String realToken = StringUtils.hasText(token) ? token : access_token;
log.info("WeCom OAuth relay Mingdao userInfo request received: hasToken={}, hasAccessToken={}, token={}",
StringUtils.hasText(token), StringUtils.hasText(access_token), weComRelayService.maskForLog(realToken));
return ResponseEntity.ok(weComRelayService.userInfo(realToken));
}
}
This diff is collapsed.
package com.jd.easywalk.casrelay;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
public class WeComRelayStartupLogger {
private static final Logger log = LoggerFactory.getLogger(WeComRelayStartupLogger.class);
private final WeComRelayProperties properties;
public WeComRelayStartupLogger(WeComRelayProperties properties) {
this.properties = properties;
}
@PostConstruct
public void logConfig() {
log.info("WeCom relay config: enabled={}, appId={}, platformDomain={}, authorizationUri={}, "
+ "redirectUri={}, appIdParam={}, redirectParam={}, qrcodeParam={}, codeExchangeUri={}, mockEnabled={}",
properties.isEnabled(), properties.getAppId(), properties.getPlatformDomain(),
properties.getAuthorizationUri(), properties.getRedirectUri(),
properties.getAuthorizationAppIdParam(), properties.getAuthorizationRedirectUriParam(),
properties.getAuthorizationQrcodeParam(), properties.getCodeExchangeUri(), properties.isMockEnabled());
}
}
org.springframework.context.ApplicationContextInitializer=\
com.jd.easywalk.casrelay.DotenvPropertySourceInitializer
......@@ -42,3 +42,45 @@ oauth-relay:
expires-in: ${OAUTH_EXPIRES_IN:7200}
email-domain: ${OAUTH_EMAIL_DOMAIN:xidian.edu.cn}
synthesize-email: ${OAUTH_SYNTHESIZE_EMAIL:true}
wecom-relay:
enabled: ${WECOM_RELAY_ENABLED:false}
app-id: ${WECOM_APP_ID:200260525100013951}
app-secret: ${WECOM_APP_SECRET:}
platform-domain: ${WECOM_PLATFORM_DOMAIN:xxcapp.xidian.edu.cn}
corp-id: ${WECOM_CORP_ID:}
agent-id: ${WECOM_AGENT_ID:}
corp-secret: ${WECOM_CORP_SECRET:}
authorization-uri: ${WECOM_AUTHORIZATION_URI:https://xxcapp.xidian.edu.cn/uc/api/oauth/index}
authorization-app-id-param: ${WECOM_AUTHORIZATION_APP_ID_PARAM:appid}
authorization-redirect-uri-param: ${WECOM_AUTHORIZATION_REDIRECT_URI_PARAM:redirect}
authorization-response-type-param: ${WECOM_AUTHORIZATION_RESPONSE_TYPE_PARAM:}
authorization-scope-param: ${WECOM_AUTHORIZATION_SCOPE_PARAM:}
authorization-state-param: ${WECOM_AUTHORIZATION_STATE_PARAM:state}
authorization-qrcode-param: ${WECOM_AUTHORIZATION_QRCODE_PARAM:qrcode}
authorization-qrcode-value: ${WECOM_AUTHORIZATION_QRCODE_VALUE:1}
code-exchange-uri: ${WECOM_CODE_EXCHANGE_URI:https://xxcapp.xidian.edu.cn/api/third/get-token}
token-user-info-uri: ${WECOM_TOKEN_USER_INFO_URI:https://xxcapp.xidian.edu.cn/uc/api/oauth/user-by-code}
code-param: ${WECOM_CODE_PARAM:code}
code-exchange-app-id-param: ${WECOM_CODE_EXCHANGE_APP_ID_PARAM:appid}
code-exchange-app-secret-param: ${WECOM_CODE_EXCHANGE_APP_SECRET_PARAM:appsecret}
token-user-info-token-param: ${WECOM_TOKEN_USER_INFO_TOKEN_PARAM:access_token}
platform-access-token-skew-seconds: ${WECOM_PLATFORM_ACCESS_TOKEN_SKEW_SECONDS:300}
access-token-uri: ${WECOM_ACCESS_TOKEN_URI:}
code-user-info-uri: ${WECOM_CODE_USER_INFO_URI:}
user-detail-uri: ${WECOM_USER_DETAIL_URI:}
redirect-uri: ${WECOM_REDIRECT_URI:}
allowed-redirect-host: ${WECOM_ALLOWED_REDIRECT_HOST:nercwbs-lms.xidian.edu.cn}
scope: ${WECOM_SCOPE:snsapi_base}
token-expires-in: ${WECOM_TOKEN_EXPIRES_IN:7200}
corp-access-token-skew-seconds: ${WECOM_CORP_ACCESS_TOKEN_SKEW_SECONDS:300}
email-domain: ${WECOM_EMAIL_DOMAIN:xidian.edu.cn}
synthesize-email: ${WECOM_SYNTHESIZE_EMAIL:true}
append-wechat-redirect: ${WECOM_APPEND_WECHAT_REDIRECT:true}
connect-timeout-ms: ${WECOM_CONNECT_TIMEOUT_MS:5000}
read-timeout-ms: ${WECOM_READ_TIMEOUT_MS:10000}
mock-enabled: ${WECOM_MOCK_ENABLED:false}
mock-work-no: ${WECOM_MOCK_WORK_NO:20240001}
mock-name: ${WECOM_MOCK_NAME:MockUser}
mock-email: ${WECOM_MOCK_EMAIL:20240001@xidian.edu.cn}
mock-mobile: ${WECOM_MOCK_MOBILE:13800000000}
{
"mode": "common-oauth2",
"name": "xidian-wecom-oauth-relay",
"oauth2": {
"oauth2Url": "https://casrelay.xidian.edu.cn",
"clientId": "mingdao-wecom-relay",
"clientSecret": "mingdao-wecom-relay-secret",
"idParamName": "client_id",
"secretParamName": "client_secret",
"accessTokenParamName": "access_token",
"redirectUri": "https://nercwbs-lms.xidian.edu.cn/orgsso/oauth2",
"authorizePath": "/wecom/oauth2/authorize",
"tokenPath": "/wecom/oauth2/access_token",
"userInfoUrl": "https://casrelay.xidian.edu.cn/wecom/oauth2/userinfo",
"tokenKeyParamName": "token",
"authorizationMethod": "body",
"bodyFormat": "form",
"scope": "snsapi_base",
"params": {
"UserId": "uid",
"Name": "name",
"Email": "email",
"Mobile": "mobilePhone"
},
"autoRegister": true,
"projectId": "22070640-479c-493b-9045-9c39e303cf2a"
}
}
{
"mode": "common-oauth2",
"name": "xidian-wecom-oauth-relay-mock",
"oauth2": {
"oauth2Url": "https://casrelay.xidian.edu.cn",
"clientId": "mingdao-wecom-relay",
"clientSecret": "mingdao-wecom-relay-secret",
"idParamName": "client_id",
"secretParamName": "client_secret",
"accessTokenParamName": "access_token",
"redirectUri": "https://nercwbs-lms.xidian.edu.cn/orgsso/oauth2",
"authorizePath": "/wecom/oauth2/mock/authorize",
"tokenPath": "/wecom/oauth2/access_token",
"userInfoUrl": "https://casrelay.xidian.edu.cn/wecom/oauth2/userinfo",
"tokenKeyParamName": "token",
"authorizationMethod": "body",
"bodyFormat": "form",
"scope": "",
"params": {
"UserId": "uid",
"Name": "name",
"Email": "email",
"Mobile": "mobilePhone"
},
"autoRegister": true,
"projectId": "22070640-479c-493b-9045-9c39e303cf2a"
}
}
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