+ * Author: gelinghu + * Date: 2025年05月14 15:28 + * @author gelinghu + */ + +@Data +@Configuration +@ConfigurationProperties(prefix = "sso.client") +public class SsoProperies { + + private String switchState; + + private String clientId; + + private String clientSecret; + + private String authorizeUrl; + + private String baseUrl; + + private String redirectUri; + + private String authorizationUri; + + private String tokenUri; + + private String jwtPublicKey; + + private String syncUserUri; +} + + diff --git a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/oauth2/SsoService.java b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/oauth2/SsoService.java new file mode 100644 index 0000000..4fe0104 --- /dev/null +++ b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/oauth2/SsoService.java @@ -0,0 +1,50 @@ +package com.zteits.urbanops.module.system.service.oauth2; + +import com.smart.sdk.sso.client.Oauth2Client; +import com.smart.sdk.sso.client.SsoOauth2Client; +import com.smart.sdk.sso.domain.SsoUserSyncVo; +import com.zteits.urbanops.framework.common.enums.CommonStatusEnum; +import com.zteits.urbanops.module.system.dal.dataobject.user.AdminUserDO; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * Description:
+ *+ * Author: gelinghu + * Date: 2025年5月17 17:33 + */ +@Component +@EnableConfigurationProperties(SsoProperies.class) +public class SsoService { + + private SsoProperies ssoProperies; + + private Oauth2Client client; + + public SsoService(SsoProperies ssoProperies) { + this.ssoProperies = ssoProperies; + client = new SsoOauth2Client(ssoProperies.getClientId(), ssoProperies.getClientSecret(), ssoProperies.getBaseUrl(), ssoProperies.getRedirectUri()); + } + + public Oauth2Client getClient() { + return client; + } + + public SsoProperies getSsoProperies() { + return ssoProperies; + } + + public void syncUser(AdminUserDO user) { + SsoUserSyncVo ssoUserSyncVo = new SsoUserSyncVo(); + ssoUserSyncVo.setStaffNo(user.getMobile()) + .setAccount(user.getUsername()) + .setName(user.getNickname()) + .setEmail(user.getEmail()) + .setState(CommonStatusEnum.ENABLE.getStatus().equals(user.getStatus()) ? 1 : 0); + getClient().syncUser(ssoUserSyncVo); + } + +} + + diff --git a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java index a8395a8..399b2a0 100644 --- a/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java +++ b/urbanops-module-system/src/main/java/com/zteits/urbanops/module/system/service/user/AdminUserServiceImpl.java @@ -27,6 +27,7 @@ import com.zteits.urbanops.module.system.dal.mysql.user.AdminUserMapper; import com.zteits.urbanops.module.system.service.dept.DeptService; import com.zteits.urbanops.module.system.service.dept.PostService; import com.zteits.urbanops.module.system.service.dict.DictDataService; +import com.zteits.urbanops.module.system.service.oauth2.SsoService; import com.zteits.urbanops.module.system.service.permission.PermissionService; import com.zteits.urbanops.module.system.service.tenant.TenantService; import com.google.common.annotations.VisibleForTesting; @@ -87,6 +88,10 @@ public class AdminUserServiceImpl implements AdminUserService { @Resource private DictDataService dictDataService; + @Resource + private SsoService ssoService; + + @Override @Transactional(rollbackFor = Exception.class) @LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_CREATE_SUB_TYPE, bizNo = "{{#user.id}}", @@ -115,6 +120,8 @@ public class AdminUserServiceImpl implements AdminUserService { // 3. 记录操作日志上下文 LogRecordContext.putVariable("user", user); + + ssoService.syncUser(user); return user.getId(); } @@ -232,6 +239,8 @@ public class AdminUserServiceImpl implements AdminUserService { updateObj.setId(id); updateObj.setStatus(status); userMapper.updateById(updateObj); + + ssoService.syncUser(updateObj); } @Override @@ -251,6 +260,8 @@ public class AdminUserServiceImpl implements AdminUserService { // 3. 记录操作日志上下文 LogRecordContext.putVariable("user", user); + + ssoService.syncUser(user); } @Override diff --git a/urbanops-server/src/main/resources/application-dev.yaml b/urbanops-server/src/main/resources/application-dev.yaml index 0b4e707..4bcaf6b 100644 --- a/urbanops-server/src/main/resources/application-dev.yaml +++ b/urbanops-server/src/main/resources/application-dev.yaml @@ -191,30 +191,27 @@ urbanops: justauth: enabled: true type: - DINGTALK: # 钉钉 - client-id: dingvrnreaje3yqvzhxg - client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI - ignore-check-redirect-uri: true - WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 - ignore-check-redirect-uri: true - # noinspection SpringBootApplicationYaml - WECHAT_MINI_PROGRAM: # 微信小程序 - client-id: ${wx.miniapp.appid} - client-secret: ${wx.miniapp.secret} - ignore-check-redirect-uri: true - ignore-check-state: true # 微信小程序,不会使用到 state,所以不进行校验 - WECHAT_MP: # 微信公众号 - client-id: ${wx.mp.app-id} - client-secret: ${wx.mp.secret} + UAA: + client-id: schoms + client-secret: secret + redirect-uri: https://test.jichengshanshui.com.cn:28302/test/social-login?type=35 ignore-check-redirect-uri: true cache: type: REDIS prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 +sso: + client: + switchState: on + clientId: schoms + clientSecret: secret + # 前端授权地址(改为justauth,不再这儿配置) + authorizeUrl: + # sso 服务地址 + baseUrl: https://test.jichengshanshui.com.cn:28301 + # 登录成功后跳转地址 (改为justauth,不再这儿配置) + redirectUri: --- #################### iot相关配置 TODO 芋艿【IOT】:再瞅瞅 #################### pf4j: # pluginsDir: /tmp/ @@ -235,17 +232,7 @@ flow: - appid: wy secret: x3z7t6l2g2t2i4w3x5e2e0s5y9e6d1y3 url: https://pms.jichengshanshui.com.cn:9980/prod-api/task/third/report -sso: - client: - switchState: on - clientId: schoms - clientSecret: FVwUBd3ZCrt6mMrZ - # 前端授权地址 - authorizeUrl: https://giomp.jichengshanshui.com.cn:28205/authorize - # sso 服务地址 - baseUrl: https://uaa.jichengshanshui.com.cn:28201 - # 登录成功后跳转地址 - redirectUri: https://giomp.jichengshanshui.com.cn:28205/prod-api/admin-api/sso/callback + # 微信公众号配置 wechat: mp: diff --git a/urbanops-server/src/main/resources/application-prod.yaml b/urbanops-server/src/main/resources/application-prod.yaml index b1da883..5cd9670 100644 --- a/urbanops-server/src/main/resources/application-prod.yaml +++ b/urbanops-server/src/main/resources/application-prod.yaml @@ -228,30 +228,32 @@ global: justauth: enabled: true type: - DINGTALK: # 钉钉 - client-id: dingvrnreaje3yqvzhxg - client-secret: i8E6iZyDvZj51JIb0tYsYfVQYOks9Cq1lgryEjFRqC79P3iJcrxEwT6Qk2QvLrLI - ignore-check-redirect-uri: true - WECHAT_ENTERPRISE: # 企业微信 - client-id: wwd411c69a39ad2e54 - client-secret: 1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw - agent-id: 1000004 - ignore-check-redirect-uri: true - # noinspection SpringBootApplicationYaml - WECHAT_MINI_PROGRAM: # 微信小程序 - client-id: ${wx.miniapp.appid} - client-secret: ${wx.miniapp.secret} - ignore-check-redirect-uri: true - ignore-check-state: true # 微信小程序,不会使用到 state,所以不进行校验 - WECHAT_MP: # 微信公众号 - client-id: ${wx.mp.app-id} - client-secret: ${wx.mp.secret} + UAA: + client-id: schoms + client-secret: FVwUBd3ZCrt6mMrZ + redirect-uri: https://giomp.jichengshanshui.com.cn:4080/social-login?type=35 ignore-check-redirect-uri: true cache: type: REDIS prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 +sso: + client: + switchState: on + clientId: schoms + clientSecret: FVwUBd3ZCrt6mMrZ + # 前端授权地址(改为justauth,不再这儿配置) + authorizeUrl: + # sso 服务地址 + baseUrl: https://uaa.jichengshanshui.com.cn:28201 + # 登录成功后跳转地址 (改为justauth,不再这儿配置) + redirectUri: + cache: + type: REDIS + prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: + timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 + --- #################### iot相关配置 TODO 芋艿【IOT】:再瞅瞅 #################### pf4j: # pluginsDir: /tmp/ @@ -272,17 +274,7 @@ flow: - appid: wy secret: x3z7t6l2g2t2i4w3x5e2e0s5y9e6d1y3 url: https://pms.jichengshanshui.com.cn:9980/prod-api/task/third/report -sso: - client: - switchState: on - clientId: schoms - clientSecret: FVwUBd3ZCrt6mMrZ - # 前端授权地址 - authorizeUrl: https://giomp.jichengshanshui.com.cn:28205/authorize - # sso 服务地址 - baseUrl: https://uaa.jichengshanshui.com.cn:28201 - # 登录成功后跳转地址 - redirectUri: https://giomp.jichengshanshui.com.cn:28205/prod-api/admin-api/sso/callback + # 微信公众号配置 wechat: mp: diff --git a/urbanops-server/src/main/resources/application.yaml b/urbanops-server/src/main/resources/application.yaml index 2cfeef0..d67b2e4 100644 --- a/urbanops-server/src/main/resources/application.yaml +++ b/urbanops-server/src/main/resources/application.yaml @@ -3,7 +3,7 @@ spring: name: urbanops-server profiles: - active: prod + active: dev main: allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。 diff --git a/urbanops-server/src/main/resources/pub.cer b/urbanops-server/src/main/resources/pub.cer new file mode 100644 index 0000000..5045fa8 --- /dev/null +++ b/urbanops-server/src/main/resources/pub.cer