diff --git a/README.md b/README.md index be0a7de3..9876dd2c 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ application.yml文件依次修改以下配置 ## 加入社群 - + ## 参与贡献 @@ -228,4 +228,13 @@ application.yml文件依次修改以下配置 - console-public-base-url (后台前端服务域名,可配置IP+端口) - portal-public-base-url (门户前台服务域名,可配置IP+端口) - openapi-public-base-url (后台服务域名,可配置IP+端口) -- synchronizer-public-base-url (同步认证源服务域名,可配置IP+端口) \ No newline at end of file +- synchronizer-public-base-url (同步认证源服务域名,可配置IP+端口) + +2、提示 cn.topiam.employee.common.entity.* 相关包缺失 + +因项目用到了 `QueryDSL` 查询框架,需要进行编译。 + +解决方案: +- 使用命令 `mvn compile`之后,自动生成代码,对应的代码目标在target/generated-sources目录下。 +- 通过 IDEA 选中其目录,Mark Directory as -> generated sources root 。 +- 通过 IDEA 工具类中File -> Invalidate Caches 清理缓存(可选操作) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..4e4a0674 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,62 @@ +version: '3' +services: + eiam-console: + build: + context: ./eiam-console/ + dockerfile: Dockerfile + environment: + MYSQL_HOST: 192.168.56.107 + MYSQL_USER: root + MYSQL_PASSWORD: admin + ES_HOST: 192.168.56.107 + REDIS_HOST: 192.168.56.107 + REDIS_PASSWORD: 12345678 + ports: + - 1898:1898 + image: eiam-console + restart: always + eiam-openapi: + build: + context: ./eiam-openapi/ + dockerfile: Dockerfile + environment: + MYSQL_HOST: 192.168.56.107 + MYSQL_USER: root + MYSQL_PASSWORD: admin + ES_HOST: 192.168.56.107 + REDIS_HOST: 192.168.56.107 + REDIS_PASSWORD: 12345678 + image: eiam-openapi + restart: always + ports: + - 1988:1988 + eiam-portal: + build: + context: ./eiam-portal/ + dockerfile: Dockerfile + environment: + MYSQL_HOST: 192.168.56.107 + MYSQL_USER: root + MYSQL_PASSWORD: admin + ES_HOST: 192.168.56.107 + REDIS_HOST: 192.168.56.107 + REDIS_PASSWORD: 12345678 + image: eiam-portal + restart: always + ports: + - 1989:1989 + eiam-synchronizer: + build: + context: ./eiam-synchronizer/ + dockerfile: Dockerfile + environment: + MYSQL_HOST: 192.168.56.107 + MYSQL_USER: root + MYSQL_PASSWORD: admin + ES_HOST: 192.168.56.107 + REDIS_HOST: 192.168.56.107 + REDIS_PASSWORD: 12345678 + image: eiam-synchronizer + restart: always + ports: + - 1986:1986 diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/AbstractCasApplicationService.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/AbstractCasApplicationService.java index c1b3ac19..fd9570e5 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/AbstractCasApplicationService.java +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/AbstractCasApplicationService.java @@ -22,10 +22,9 @@ import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.application.AbstractApplicationService; -import cn.topiam.employee.application.CasApplicationService; +import cn.topiam.employee.application.cas.model.CasSsoModel; import cn.topiam.employee.common.entity.app.po.AppCasConfigPO; import cn.topiam.employee.common.repository.app.*; -import cn.topiam.employee.core.protocol.CasSsoModel; /** * CAS 应用配置 @@ -58,8 +57,8 @@ public abstract class AbstractCasApplicationService extends AbstractApplicationS @Override public CasSsoModel getSsoModel(Long appId) { - AppCasConfigPO appCasConfigPO = appCasConfigRepository.getByAppId(appId); - return CasSsoModel.builder().ssoCallbackUrl(appCasConfigPO.getSpCallbackUrl()).build(); + AppCasConfigPO appCasConfigPo = appCasConfigRepository.getByAppId(appId); + return CasSsoModel.builder().clientServiceUrl(appCasConfigPo.getClientServiceUrl()).build(); } /** diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/CasApplicationService.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasApplicationService.java similarity index 81% rename from eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/CasApplicationService.java rename to eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasApplicationService.java index 7752258f..6397a9ab 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/CasApplicationService.java +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasApplicationService.java @@ -1,5 +1,5 @@ /* - * eiam-application-core - Employee Identity and Access Management Program + * eiam-application-cas - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,9 +15,10 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application; +package cn.topiam.employee.application.cas; -import cn.topiam.employee.core.protocol.CasSsoModel; +import cn.topiam.employee.application.ApplicationService; +import cn.topiam.employee.application.cas.model.CasSsoModel; /** * @author TopIAM diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasStandardApplicationServiceImpl.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasStandardApplicationServiceImpl.java index 39851e2e..f0b45ffd 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasStandardApplicationServiceImpl.java +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/CasStandardApplicationServiceImpl.java @@ -28,26 +28,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import cn.topiam.employee.application.cas.model.AppCasStandardConfigGetResult; -import cn.topiam.employee.application.cas.model.AppCasStandardSaveConfigParam; +import cn.topiam.employee.application.cas.converter.AppCasStandardConfigConverter; +import cn.topiam.employee.application.cas.pojo.AppCasStandardSaveConfigParam; import cn.topiam.employee.application.exception.AppNotExistException; import cn.topiam.employee.audit.context.AuditContext; -import cn.topiam.employee.common.constants.ProtocolConstants; import cn.topiam.employee.common.entity.app.AppCasConfigEntity; import cn.topiam.employee.common.entity.app.AppEntity; import cn.topiam.employee.common.entity.app.po.AppCasConfigPO; -import cn.topiam.employee.common.enums.app.AppProtocol; -import cn.topiam.employee.common.enums.app.AppType; -import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; +import cn.topiam.employee.common.enums.app.*; import cn.topiam.employee.common.repository.app.*; -import cn.topiam.employee.core.context.ServerContextHelp; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.validation.ValidationHelp; import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; -import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE_VARIABLE; - /** * Cas 用户应用 * @@ -56,23 +49,7 @@ import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE_VAR */ @Component public class CasStandardApplicationServiceImpl extends AbstractCasApplicationService { - private final Logger logger = LoggerFactory - .getLogger(CasStandardApplicationServiceImpl.class); - - /** - * AppCasConfigRepository - */ - protected final AppCasConfigRepository appCasConfigRepository; - - public CasStandardApplicationServiceImpl(AppCertRepository appCertRepository, - AppAccountRepository appAccountRepository, - AppAccessPolicyRepository appAccessPolicyRepository, - AppRepository appRepository, - AppCasConfigRepository appCasConfigRepository) { - super(appCertRepository, appAccountRepository, appAccessPolicyRepository, appRepository, - appCasConfigRepository); - this.appCasConfigRepository = appCasConfigRepository; - } + private final Logger logger = LoggerFactory.getLogger(CasStandardApplicationServiceImpl.class); /** * 更新应用配置 @@ -119,7 +96,9 @@ public class CasStandardApplicationServiceImpl extends AbstractCasApplicationSer throw new AppNotExistException(); } AppCasConfigEntity entity = cas.get(); - entity.setSpCallbackUrl(model.getSpCallbackUrl()); + entity.setClientServiceUrl(model.getClientServiceUrl()); + entity.setUserIdentityType(model.getUserIdentityType()); + entity.setServiceTicketExpireTime(model.getServiceTicketExpireTime()); appCasConfigRepository.save(entity); } @@ -133,18 +112,7 @@ public class CasStandardApplicationServiceImpl extends AbstractCasApplicationSer @Override public Object getConfig(String appId) { AppCasConfigPO po = appCasConfigRepository.getByAppId(Long.valueOf(appId)); - AppCasStandardConfigGetResult result = new AppCasStandardConfigGetResult(); - result.setAuthorizationType(po.getAuthorizationType()); - result.setInitLoginType(po.getInitLoginType()); - result.setInitLoginUrl(po.getInitLoginUrl()); - result.setSpCallbackUrl(po.getSpCallbackUrl()); - - String baseUrl = ServerContextHelp.getPortalPublicBaseUrl(); - // 服务端URL配置前缀 - result.setServerUrlPrefix( - baseUrl + ProtocolConstants.CasEndpointConstants.CAS_AUTHORIZE_BASE_PATH - .replace(APP_CODE_VARIABLE, po.getAppCode())); - return result; + return casStandardConfigConverter.entityConverterToCasConfigResult(po); } /** @@ -236,16 +204,36 @@ public class CasStandardApplicationServiceImpl extends AbstractCasApplicationSer appEntity.setProtocol(getProtocol()); appEntity.setClientId(idGenerator.generateId().toString().replace("-", "")); appEntity.setClientSecret(idGenerator.generateId().toString().replace("-", "")); - appEntity.setInitLoginType(InitLoginType.PORTAL_OR_APP); + appEntity.setInitLoginType(InitLoginType.APP); appEntity.setAuthorizationType(AuthorizationType.AUTHORIZATION); appEntity.setRemark(remark); appRepository.save(appEntity); AppCasConfigEntity casEntity = new AppCasConfigEntity(); casEntity.setAppId(appEntity.getId()); - casEntity.setSpCallbackUrl(""); + casEntity.setUserIdentityType(CasUserIdentityType.USER_USERNAME); + casEntity.setServiceTicketExpireTime(30); appCasConfigRepository.save(casEntity); return appEntity.getId().toString(); } + private final AppCasStandardConfigConverter casStandardConfigConverter; + + /** + * AppCasConfigRepository + */ + protected final AppCasConfigRepository appCasConfigRepository; + + public CasStandardApplicationServiceImpl(AppCertRepository appCertRepository, + AppAccountRepository appAccountRepository, + AppAccessPolicyRepository appAccessPolicyRepository, + AppRepository appRepository, + AppCasConfigRepository appCasConfigRepository, + AppCasStandardConfigConverter casStandardConfigConverter) { + super(appCertRepository, appAccountRepository, appAccessPolicyRepository, appRepository, + appCasConfigRepository); + this.appCasConfigRepository = appCasConfigRepository; + this.casStandardConfigConverter = casStandardConfigConverter; + } + } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/converter/AppCasStandardConfigConverter.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/converter/AppCasStandardConfigConverter.java index 82e67f8c..391c7184 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/converter/AppCasStandardConfigConverter.java +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/converter/AppCasStandardConfigConverter.java @@ -19,6 +19,13 @@ package cn.topiam.employee.application.cas.converter; import org.mapstruct.Mapper; +import cn.topiam.employee.application.cas.pojo.AppCasProtocolEndpoint; +import cn.topiam.employee.application.cas.pojo.AppCasStandardConfigGetResult; +import cn.topiam.employee.common.constants.ProtocolConstants; +import cn.topiam.employee.common.entity.app.po.AppCasConfigPO; +import cn.topiam.employee.core.context.ServerContextHelp; +import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE_VARIABLE; + /** * 配置转换 * @@ -27,4 +34,35 @@ import org.mapstruct.Mapper; */ @Mapper(componentModel = "spring") public interface AppCasStandardConfigConverter { + + /** + * 实体转CAS配置 + * + * @param po {@link AppCasConfigPO} + * @return {@link AppCasStandardConfigGetResult} + */ + default AppCasStandardConfigGetResult entityConverterToCasConfigResult(AppCasConfigPO po) { + AppCasStandardConfigGetResult result = new AppCasStandardConfigGetResult(); + result.setAuthorizationType(po.getAuthorizationType()); + result.setAppId(String.valueOf(po.getAppId())); + result.setInitLoginType(po.getInitLoginType()); + result.setInitLoginUrl(po.getInitLoginUrl()); + result.setClientServiceUrl(po.getClientServiceUrl()); + result.setUserIdentityType(po.getUserIdentityType()); + result.setServiceTicketExpireTime(po.getServiceTicketExpireTime()); + + //封装端点信息 + //@formatter:off + AppCasProtocolEndpoint protocolEndpoint = new AppCasProtocolEndpoint(); + String baseUrl = ServerContextHelp.getPortalPublicBaseUrl(); + protocolEndpoint.setCasServerUrlPrefix(baseUrl+ProtocolConstants.CasEndpointConstants.CAS_AUTHORIZE_BASE_PATH.replace(APP_CODE_VARIABLE, po.getAppCode())); + protocolEndpoint.setCasSsoEndpoint(baseUrl + ProtocolConstants.CasEndpointConstants.CAS_LOGIN_PATH.replace(APP_CODE_VARIABLE, po.getAppCode())); + protocolEndpoint.setCasSloEndpoint(baseUrl + ProtocolConstants.CasEndpointConstants.CAS_LOGOUT_PATH.replace(APP_CODE_VARIABLE, po.getAppCode())); + protocolEndpoint.setCasValidateEndpoint(baseUrl + ProtocolConstants.CasEndpointConstants.CAS_VALIDATE_V1_PATH.replace(APP_CODE_VARIABLE, po.getAppCode())); + protocolEndpoint.setCasValidateV2Endpoint(baseUrl + ProtocolConstants.CasEndpointConstants.CAS_VALIDATE_V2_PATH.replace(APP_CODE_VARIABLE, po.getAppCode())); + protocolEndpoint.setCasValidateV3Endpoint(baseUrl + ProtocolConstants.CasEndpointConstants.CAS_VALIDATE_V3_PATH.replace(APP_CODE_VARIABLE, po.getAppCode())); + result.setProtocolEndpoint(protocolEndpoint); + //@formatter:on + return result; + } } diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/protocol/CasSsoModel.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/CasSsoModel.java similarity index 82% rename from eiam-core/src/main/java/cn/topiam/employee/core/protocol/CasSsoModel.java rename to eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/CasSsoModel.java index 14719eed..2c00928e 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/protocol/CasSsoModel.java +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/CasSsoModel.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-application-cas - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.protocol; +package cn.topiam.employee.application.cas.model; import java.io.Serializable; @@ -30,6 +30,9 @@ import lombok.Data; @Builder public class CasSsoModel implements Serializable { - private String ssoCallbackUrl; + /** + * 客户端服务URL + */ + private String clientServiceUrl; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasProtocolEndpoint.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasProtocolEndpoint.java new file mode 100644 index 00000000..7f6e4653 --- /dev/null +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasProtocolEndpoint.java @@ -0,0 +1,73 @@ +/* + * eiam-application-cas - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.cas.pojo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** +* 协议端点域 +* +* @author TopIAM +* Created by support@topiam.cn on 2022/6/4 23:37 +*/ +@Data +@Schema(description = "协议端点") +public class AppCasProtocolEndpoint implements Serializable { + + @Serial + private static final long serialVersionUID = -2261602995152894964L; + /** + * CAS URL前缀 + */ + @Schema(description = "CAS URL前缀") + private String casServerUrlPrefix; + + /** + * CAS SSO 端点 + */ + @Schema(description = "CAS SSO 端点") + private String casSsoEndpoint; + + /** + * CAS SLO 端点 + */ + @Schema(description = "CAS SLO 端点") + private String casSloEndpoint; + + /** + * CAS 校验端点 + */ + @Schema(description = "CAS 校验端点") + private String casValidateEndpoint; + + /** + * CAS v2 校验端点 + */ + @Schema(description = "CAS V2 校验端点") + private String casValidateV2Endpoint; + + /** + * CAS v3 校验端点 + */ + @Schema(description = "CAS V3 校验端点") + private String casValidateV3Endpoint; +} diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasStandardConfigGetResult.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasStandardConfigGetResult.java new file mode 100644 index 00000000..807ce0e8 --- /dev/null +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasStandardConfigGetResult.java @@ -0,0 +1,81 @@ +/* + * eiam-application-cas - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.cas.pojo; + +import cn.topiam.employee.common.enums.app.AuthorizationType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; +import cn.topiam.employee.common.enums.app.InitLoginType; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2023/1/2 22:23 + */ +@Data +@Schema(description = "CAS 配置返回结果") +public class AppCasStandardConfigGetResult { + + /** + * 应用id + */ + @Schema(description = "应用id") + private String appId; + + /** + * SSO 发起方 + */ + @Parameter(description = "SSO 发起方") + private InitLoginType initLoginType; + + /** + * SSO 登录链接 + */ + @Parameter(description = "SSO 登录链接") + private String initLoginUrl; + + /** + * 授权范围 + */ + @Parameter(description = "SSO 授权范围") + private AuthorizationType authorizationType; + + /** + * 客户端服务URL + */ + @Schema(name = "客户端服务URL") + private String clientServiceUrl; + + /** + * 用户身份类型标识 + */ + @Schema(name = "用户身份类型标识") + private CasUserIdentityType userIdentityType; + + /** + * serviceTicket 过期时间(秒) + */ + @Schema(name = "serviceTicket 过期时间(秒)") + private Integer serviceTicketExpireTime; + /** + * CAS 协议端点 + */ + @Schema(name = "CAS 协议端点") + private AppCasProtocolEndpoint protocolEndpoint; +} diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardSaveConfigParam.java b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasStandardSaveConfigParam.java similarity index 66% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardSaveConfigParam.java rename to eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasStandardSaveConfigParam.java index 0ea31a7a..89581305 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardSaveConfigParam.java +++ b/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/pojo/AppCasStandardSaveConfigParam.java @@ -15,19 +15,17 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.application.cas.pojo; + +import cn.topiam.employee.common.enums.app.AuthorizationType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; +import cn.topiam.employee.common.enums.app.InitLoginType; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; import java.io.Serial; import java.io.Serializable; -import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; - -import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; - /** * @author TopIAM * Created by support@topiam.cn on 2023/1/2 22:27 @@ -35,29 +33,41 @@ import io.swagger.v3.oas.annotations.media.Schema; @Data public class AppCasStandardSaveConfigParam implements Serializable { @Serial - private static final long serialVersionUID = 1881187724713984421L; + private static final long serialVersionUID = 1881187724713984421L; /** * 应用ID */ @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private AuthorizationType authorizationType; /** * SSO 发起登录类型 */ @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private InitLoginType initLoginType; /** * SSO 发起登录URL */ @Schema(description = "SSO 发起登录URL") - private String initLoginUrl; + private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 客户端服务URL */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + @Schema(name = "客户端服务URL") + private String clientServiceUrl; + + /** + * 用户身份类型标识 + */ + @Schema(name = "用户身份类型标识") + private CasUserIdentityType userIdentityType; + + /** + * serviceTicket 过期时间(秒) + */ + @Schema(name = "serviceTicket 过期时间(秒)") + private Integer serviceTicketExpireTime; } diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java index f1b32495..e7e81d20 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/AbstractApplicationService.java @@ -57,7 +57,7 @@ public abstract class AbstractApplicationService implements ApplicationService { * 创建证书 * * @param appId {@link Long} - * @param appCode {@link Long} + * @param appCode {@link Long} * @param usingType {@link AppCertUsingType} */ public void createCertificate(Long appId, String appCode, AppCertUsingType usingType) { @@ -120,7 +120,7 @@ public abstract class AbstractApplicationService implements ApplicationService { protected final AppAccountRepository appAccountRepository; /** - * AppAccessPolicyRepository + *AppAccessPolicyRepository */ protected final AppAccessPolicyRepository appAccessPolicyRepository; diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationServiceLoader.java b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationServiceLoader.java index ea299531..62445b34 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationServiceLoader.java +++ b/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/ApplicationServiceLoader.java @@ -44,6 +44,7 @@ public class ApplicationServiceLoader implements ApplicationContextAware { * 用于保存接口实现类名及对应的类 */ private Map loadMap = new HashMap<>(16); + private ApplicationContext applicationContext; /** * key: code,value:templateImpl */ @@ -64,9 +65,9 @@ public class ApplicationServiceLoader implements ApplicationContextAware { * @see BeanInitializationException */ @Override - public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; loadMap = applicationContext.getBeansOfType(ApplicationService.class); - getApplicationServiceList(); } /** @@ -101,4 +102,12 @@ public class ApplicationServiceLoader implements ApplicationContextAware { return impl; } + public void addApplicationService(List beanNameList) { + Map applicationServiceMap = new HashMap<>(16); + for (String beanName : beanNameList) { + applicationServiceMap.put(beanName, + applicationContext.getBean(beanName, ApplicationService.class)); + } + loadMap.putAll(applicationServiceMap); + } } diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java index 9fe8f53a..3867036c 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/AbstractFormApplicationService.java @@ -17,8 +17,11 @@ */ package cn.topiam.employee.application.form; -import cn.topiam.employee.application.ApplicationService; -import cn.topiam.employee.common.repository.app.AppCertRepository; +import org.springframework.util.AlternativeJdkIdGenerator; +import org.springframework.util.IdGenerator; + +import cn.topiam.employee.common.repository.app.AppAccountRepository; +import cn.topiam.employee.common.repository.app.AppFormConfigRepository; import cn.topiam.employee.common.repository.app.AppRepository; /** @@ -27,20 +30,40 @@ import cn.topiam.employee.common.repository.app.AppRepository; * @author TopIAM * Created by support@topiam.cn on 2022/8/23 20:58 */ -public abstract class AbstractFormApplicationService implements ApplicationService { +public abstract class AbstractFormApplicationService implements FormApplicationService { + + @Override + public void delete(String appId) { + //删除应用 + appRepository.deleteById(Long.valueOf(appId)); + //删除应用账户 + appAccountRepository.deleteAllByAppId(Long.valueOf(appId)); + // 删除应用配置 + appFormConfigRepository.deleteByAppId(Long.valueOf(appId)); + } - /** - * AppCertRepository - */ - protected final AppCertRepository appCertRepository; /** * ApplicationRepository */ - protected final AppRepository appRepository; + protected final AppRepository appRepository; - protected AbstractFormApplicationService(AppCertRepository appCertRepository, - AppRepository appRepository) { - this.appCertRepository = appCertRepository; + /** + * AppAccountRepository + */ + protected final AppAccountRepository appAccountRepository; + + protected final AppFormConfigRepository appFormConfigRepository; + + /** + * IdGenerator + */ + protected final IdGenerator idGenerator = new AlternativeJdkIdGenerator(); + + protected AbstractFormApplicationService(AppRepository appRepository, + AppAccountRepository appAccountRepository, + AppFormConfigRepository appFormConfigRepository) { this.appRepository = appRepository; + this.appAccountRepository = appAccountRepository; + this.appFormConfigRepository = appFormConfigRepository; } } diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormApplicationService.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormApplicationService.java new file mode 100644 index 00000000..8d105ce6 --- /dev/null +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormApplicationService.java @@ -0,0 +1,48 @@ +/* + * eiam-application-form - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.form; + +import cn.topiam.employee.application.ApplicationService; +import cn.topiam.employee.application.form.model.FormProtocolConfig; +import cn.topiam.employee.common.entity.app.AppAccountEntity; + +/** + * 应用接口 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/8/20 23:20 + */ +public interface FormApplicationService extends ApplicationService { + + /** + * 获取协议配置 + * + * @param appCode {@link String} + * @return {@link FormProtocolConfig} + */ + FormProtocolConfig getProtocolConfig(String appCode); + + /** + * 获取应用用户信息 + * + * @param appId {@link Long} + * @param userId {@link Long} + * @return {@link FormProtocolConfig} + */ + AppAccountEntity getAppAccount(Long appId, Long userId); +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java index 75e5dd82..ed24688d 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/FormStandardApplicationServiceImpl.java @@ -17,15 +17,45 @@ */ package cn.topiam.employee.application.form; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; +import javax.validation.ConstraintViolationException; + +import org.apache.commons.text.StringSubstitutor; import org.springframework.stereotype.Component; -import cn.topiam.employee.common.enums.app.AppProtocol; -import cn.topiam.employee.common.enums.app.AppType; -import cn.topiam.employee.common.repository.app.AppCertRepository; +import com.fasterxml.jackson.databind.ObjectMapper; + +import cn.topiam.employee.application.exception.AppNotExistException; +import cn.topiam.employee.application.form.converter.AppFormConfigConverter; +import cn.topiam.employee.application.form.model.FormProtocolConfig; +import cn.topiam.employee.application.form.pojo.AppFormSaveConfigParam; +import cn.topiam.employee.audit.context.AuditContext; +import cn.topiam.employee.common.entity.app.AppAccountEntity; +import cn.topiam.employee.common.entity.app.AppEntity; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; +import cn.topiam.employee.common.entity.app.po.AppFormConfigPO; +import cn.topiam.employee.common.enums.app.*; +import cn.topiam.employee.common.exception.app.AppAccountNotExistException; +import cn.topiam.employee.common.repository.app.AppAccountRepository; +import cn.topiam.employee.common.repository.app.AppFormConfigRepository; import cn.topiam.employee.common.repository.app.AppRepository; +import cn.topiam.employee.core.context.ServerContextHelp; +import cn.topiam.employee.support.exception.TopIamException; +import cn.topiam.employee.support.util.BeanUtils; +import cn.topiam.employee.support.util.HttpUrlUtils; +import cn.topiam.employee.support.validation.ValidationHelp; + +import lombok.extern.slf4j.Slf4j; +import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; + +import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE; +import static cn.topiam.employee.common.constants.ProtocolConstants.FormEndpointConstants.IDP_FORM_SSO_INITIATOR; +import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_BY; +import static cn.topiam.employee.support.repository.domain.BaseEntity.LAST_MODIFIED_TIME; /** * Form 用户应用 @@ -33,6 +63,7 @@ import cn.topiam.employee.common.repository.app.AppRepository; * @author TopIAM * Created by support@topiam.cn on 2022/8/20 23:20 */ +@Slf4j @Component public class FormStandardApplicationServiceImpl extends AbstractFormApplicationService { @@ -44,6 +75,51 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS */ @Override public void saveConfig(String appId, Map config) { + AppFormSaveConfigParam model; + try { + ObjectMapper mapper = new ObjectMapper(); + String value = mapper.writeValueAsString(config); + // 指定序列化输入的类型 + mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); + model = mapper.readValue(value, AppFormSaveConfigParam.class); + } catch (Exception e) { + throw new TopIamException(e.getMessage()); + } + //@formatter:off + ValidationHelp.ValidationResult validationResult = ValidationHelp.validateEntity(model); + if (validationResult.isHasErrors()) { + throw new ConstraintViolationException(validationResult.getConstraintViolations()); + } + //@formatter:on + //1、修改基本信息 + Optional optional = appRepository.findById(Long.valueOf(appId)); + if (optional.isEmpty()) { + AuditContext.setContent("保存配置失败,应用 [" + appId + "] 不存在!"); + log.error(AuditContext.getContent()); + throw new AppNotExistException(); + } + AppEntity appEntity = optional.get(); + appEntity.setAuthorizationType(model.getAuthorizationType()); + Map variables = new HashMap<>(16); + variables.put(APP_CODE, appEntity.getCode()); + StringSubstitutor sub = new StringSubstitutor(variables, "{", "}"); + appEntity.setInitLoginUrl(sub.replace(HttpUrlUtils + .format(ServerContextHelp.getPortalPublicBaseUrl() + IDP_FORM_SSO_INITIATOR))); + appEntity.setInitLoginType(model.getInitLoginType()); + appRepository.save(appEntity); + //2、修改 表单代填 配置 + Optional form = appFormConfigRepository + .findByAppId(Long.valueOf(appId)); + if (form.isEmpty()) { + AuditContext.setContent("保存配置失败,应用 [" + appId + "] 不存在!"); + log.error(AuditContext.getContent()); + throw new AppNotExistException(); + } + AppFormConfigEntity entity = form.get(); + AppFormConfigEntity formConfig = appFormConfigConverter + .appFormSaveConfigParamToEntity(model); + BeanUtils.merge(formConfig, entity, LAST_MODIFIED_BY, LAST_MODIFIED_TIME); + appFormConfigRepository.save(entity); } /** @@ -54,7 +130,8 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS */ @Override public Object getConfig(String appId) { - return null; + AppFormConfigPO po = appFormConfigRepository.getByAppId(Long.valueOf(appId)); + return appFormConfigConverter.entityConverterToFormConfigResult(po); } /** @@ -64,7 +141,7 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS */ @Override public String getCode() { - return "form"; + return AppProtocol.FORM.getCode(); } /** @@ -74,7 +151,7 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS */ @Override public String getName() { - return "表单代填"; + return AppProtocol.FORM.getDesc(); } /** @@ -124,7 +201,7 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS */ @Override public String getBase64Icon() { - return "data:image/svg+xml;base64,PHN2ZyB0PSIxNjYwOTc4MDk3OTkyIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjMxNDMiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMjk0LjkxMiA0MTQuMjA4aDg2LjUyOHYzNDIuMDE2SDI5NC45MTJ6TTQyNC45NiA0MTQuMjA4aDMwMy4xMDR2MzQyLjAxNkg0MjQuOTZ6TTI5NC45MTIgMjY3LjI2NGg0MzMuMTUydjk3Ljc5MkgyOTQuOTEyeiIgZmlsbD0iIzI3QTNGRiIgcC1pZD0iMzE0NCI+PC9wYXRoPjxwYXRoIGQ9Ik05MjEuNiAwSDEwMi40YTEwMi40IDEwMi40IDAgMCAwLTEwMi40IDEwMi40djgxOS4yYTEwMi40IDEwMi40IDAgMCAwIDEwMi40IDEwMi40aDgxOS4yYTEwMi40IDEwMi40IDAgMCAwIDEwMi40LTEwMi40VjEwMi40YTEwMi40IDEwMi40IDAgMCAwLTEwMi40LTEwMi40eiBtLTE1MC4wMTYgNzgwLjhhMjMuMDQgMjMuMDQgMCAwIDEtMjEuNTA0IDI0LjA2NEgyNzMuNDA4YTIzLjA0IDIzLjA0IDAgMCAxLTIxLjUwNC0yNC4wNjRWMjQyLjY4OGEyMy4wNCAyMy4wNCAwIDAgMSAyMS41MDQtMjQuMDY0aDQ3Ni42NzJhMjMuMDQgMjMuMDQgMCAwIDEgMjEuNTA0IDI0LjA2NHoiIGZpbGw9IiMyN0EzRkYiIHAtaWQ9IjMxNDUiPjwvcGF0aD48L3N2Zz4="; + return "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNjcyNDA3MTc3NTExIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjQ5MjkiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTQ2Ny4yNyA4NzAuMzNIMTgzLjczYy0yMC41OCAwLTM3LjMyLTE1LjE2LTM3LjMyLTMzLjhWMTg1Ljg2YzAtMTguNjMgMTYuNzQtMzMuNzkgMzcuMzItMzMuNzlINzE4YzIwLjU3IDAgMzcuMzEgMTUuMTYgMzcuMzEgMzMuNzl2MjYyLjU5YTI0IDI0IDAgMSAwIDQ4IDBWMTg1Ljg2YzAtNDUuMS0zOC4yNy04MS43OS04NS4zMS04MS43OUgxODMuNzNjLTQ3IDAtODUuMzIgMzYuNjktODUuMzIgODEuNzl2NjUwLjY3YzAgNDUuMSAzOC4yNyA4MS44IDg1LjMyIDgxLjhoMjgzLjU0YTI0IDI0IDAgMCAwIDAtNDh6IiBmaWxsPSIjNjc3Nzg3IiBwLWlkPSI0OTMwIj48L3BhdGg+PHBhdGggZD0iTTkyMi4zOSA2NzQuNThsLTAuMzQtMi4xOGE0Ni4zOCA0Ni4zOCAwIDAgMC0zOS41OC0zOC42bC0yLjE5LTAuMjlhMzcuMzcgMzcuMzcgMCAwIDEtMzIuNDEtMzdBMzYuNDQgMzYuNDQgMCAwIDEgODUwIDU4NS42bDAuNzYtMi4zMmE0Ni4xOSA0Ni4xOSAwIDAgMC0yMS40Ni01NC42N2wtNDEuNDMtMjNhNDYuMDggNDYuMDggMCAwIDAtNTMuNDQgNi4yNWwtMS41OCAxLjQzYTExMi4zNSAxMTIuMzUgMCAwIDEtMTAuNiA4LjcxYy04LjgxIDYuMTYtMTUuNDIgOC4zNC0xOC40IDguMzRzLTkuNzItMi4yMi0xOC40OC04LjQ1YTEwMS42MSAxMDEuNjEgMCAwIDEtMTAuMjYtOC40NGwtMS41Ni0xLjQ4YTQ2IDQ2IDAgMCAwLTU0LTdsLTQzLjE4IDIzLjY3YTQ2LjEgNDYuMSAwIDAgMC0yMS41OSA1NWwwLjc4IDIuMzRhMzUuNyAzNS43IDAgMCAxLTMwLjMzIDQ3LjYxbC0yLjE4IDAuMjlhNDYuMzggNDYuMzggMCAwIDAtMzkuNTcgMzguNTRsLTAuMzQgMi4xOGMtMS40OCA5LjM0LTMuMjMgMjMuMDUtMy4yMyAzNS4zMyAwIDEyLjA5IDEuNzUgMjUuODEgMy4yMiAzNS4ybDAuMzQgMi4xOGE0Ni4zOCA0Ni4zOCAwIDAgMCAzOS42MiAzOC41OWwyLjE5IDAuMjlhMzUuNzUgMzUuNzUgMCAwIDEgMzAuMjcgNDcuNjhsLTAuNzcgMi4zMUE0Ni4xNiA0Ni4xNiAwIDAgMCA1NzYuMDYgODkxbDQwLjI2IDIyLjUxYTQ1Ljg3IDQ1Ljg3IDAgMCAwIDU0LjQ1LTdsMS41OS0xLjUyYTEwMS4zNiAxMDEuMzYgMCAwIDEgMTAuNTEtOC44M2M5LTYuNiAxNS43NS04Ljk0IDE4LjgxLTguOTQgMS41NyAwIDcuNTYgMC42NiAxOS4wNyA5LjE4YTk3LjU3IDk3LjU3IDAgMCAxIDEwLjMzIDguODFsMS41NyAxLjU0YTQ2LjM4IDQ2LjM4IDAgMCAwIDU0LjU5IDcuNDlsNDItMjMuMTNhNDYuMTYgNDYuMTYgMCAwIDAgMjEuNTctNTQuNzNMODUwIDgzNGEzNi43OSAzNi43OSAwIDAgMS0yLjE0LTEwLjkzIDM3LjMyIDM3LjMyIDAgMCAxIDMyLjM2LTM3bDIuMi0wLjI5QTQ2LjM3IDQ2LjM3IDAgMCAwIDkyMiA3NDcuMjRsMC4zNS0yLjE3YzEuMTktNy42MiAzLjItMjIuMzMgMy4yLTM1LjIyIDAuMDQtMTIuMjUtMS43LTI1Ljk0LTMuMTYtMzUuMjd6IG0tNDcuNDIgNjNsLTAuMTMgMC43OS0wLjc5IDAuMWE4NS40NSA4NS40NSAwIDAgMC03NC4xOCA4NC41OCA4My43OSA4My43OSAwIDAgMCA0LjUyIDI1Ljg1bDAuMjggMC44NS0zOS4zOCAyMS43LTAuNTctMC41NmExNDcuNiAxNDcuNiAwIDAgMC0xNS40NC0xMy4xOGMtMTYuNjUtMTIuMzItMzIuNjctMTguNTctNDcuNi0xOC41N3MtMzAuNzEgNi4xMy00Ny4xNyAxOC4yMWExNTMuNiAxNTMuNiAwIDAgMC0xNS40MSAxMi45NGwtMC41NyAwLjU2LTM3LjY5LTIxLjA3IDAuMjgtMC44NGE4NC4xNSA4NC4xNSAwIDAgMCA0LjU1LTI1LjkgODUuNDIgODUuNDIgMCAwIDAtNzQuMTYtODQuNTdsLTAuOC0wLjExLTAuMTItMC43OWExOTMuMzMgMTkzLjMzIDAgMCAxLTIuNTktMjcuNzIgMTkxLjkgMTkxLjkgMCAwIDEgMi41OS0yNy44NWwwLjEzLTAuNzkgMC43OS0wLjExYTg1LjUgODUuNSAwIDAgMCA3NC4xNi04NC41NyA4My40NSA4My40NSAwIDAgMC00LjUyLTI1Ljc3bC0wLjI5LTAuODYgNDAuNi0yMi4yNSAwLjU3IDAuNTRhMTQ2LjE5IDE0Ni4xOSAwIDAgMCAxNS40NSAxMi43MmMxNi4yMiAxMS41NCAzMS44MiAxNy4zOSA0Ni4zNyAxNy4zOSAxNC4zNCAwIDI5LjgyLTUuNzQgNDYtMTcuMDdsMC4xMy0wLjA5YTE1Ny40MSAxNTcuNDEgMCAwIDAgMTUuMjMtMTIuMzZsMC41OC0wLjUyIDM4Ljg5IDIxLjU3LTAuMjggMC44NGE4My45IDgzLjkgMCAwIDAtNC41MiAyNS44NiA4NS41MSA4NS41MSAwIDAgMCA3NC4xOCA4NC41OGwwLjc5IDAuMSAwLjEzIDAuNzlhMTk2LjUyIDE5Ni41MiAwIDAgMSAyLjYyIDI3Ljg2IDE5My43MSAxOTMuNzEgMCAwIDEtMi42IDI3Ljc2eiIgZmlsbD0iIzY3Nzc4NyIgcC1pZD0iNDkzMSI+PC9wYXRoPjxwYXRoIGQ9Ik03MDIuNzcgNjMzLjQ1YTc2LjEzIDc2LjEzIDAgMSAwIDc2LjEzIDc2LjEzIDc2LjIxIDc2LjIxIDAgMCAwLTc2LjEzLTc2LjEzeiBtMCAxMDQuMjZhMjguMTMgMjguMTMgMCAxIDEgMjguMTMtMjguMTMgMjguMTYgMjguMTYgMCAwIDEtMjguMTMgMjguMTN6TTU1OS4yMyA0ODguNDVhMjQgMjQgMCAwIDAtMjQtMjRIMjM3Ljc0YTI0IDI0IDAgMSAwIDAgNDhoMjk3LjQ5YTI0IDI0IDAgMCAwIDI0LTI0ek02ODIuMzMgMzA3LjIxYTI0IDI0IDAgMCAwLTI0LTI0SDIzNy43NGEyNCAyNCAwIDAgMCAwIDQ4aDQyMC41OWEyNCAyNCAwIDAgMCAyNC0yNHpNMjQzLjIxIDYzOC45NGEyNCAyNCAwIDAgMCAwIDQ4aDE4My45NGEyNCAyNCAwIDEgMCAwLTQ4eiIgZmlsbD0iIzY3Nzc4NyIgcC1pZD0iNDkzMiI+PC9wYXRoPjwvc3ZnPg=="; } /** @@ -135,22 +212,50 @@ public class FormStandardApplicationServiceImpl extends AbstractFormApplicationS */ @Override public String create(String name, String remark) { - return ""; + //1、创建应用 + AppEntity appEntity = new AppEntity(); + appEntity.setName(name); + appEntity.setCode( + org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric(32).toLowerCase()); + appEntity.setTemplate(getCode()); + appEntity.setType(getType()); + appEntity.setEnabled(true); + appEntity.setProtocol(getProtocol()); + appEntity.setClientId(idGenerator.generateId().toString().replace("-", "")); + appEntity.setClientSecret(idGenerator.generateId().toString().replace("-", "")); + appEntity.setInitLoginType(InitLoginType.PORTAL_OR_APP); + appEntity.setAuthorizationType(AuthorizationType.AUTHORIZATION); + appEntity.setRemark(remark); + appRepository.save(appEntity); + + AppFormConfigEntity appFormConfig = new AppFormConfigEntity(); + appFormConfig.setAppId(appEntity.getId()); + //提交类型 + appFormConfig.setSubmitType(FormSubmitType.POST); + appFormConfigRepository.save(appFormConfig); + return String.valueOf(appEntity.getId()); } - /** - * 删除应用 - * - * @param appId {@link String} 应用ID - */ @Override - public void delete(String appId) { - + public FormProtocolConfig getProtocolConfig(String appCode) { + AppFormConfigPO configPo = appFormConfigRepository.findByAppCode(appCode); + return appFormConfigConverter.appFormEntityToConfig(configPo); } - protected FormStandardApplicationServiceImpl(AppCertRepository appCertRepository, - AppRepository appRepository) { - super(appCertRepository, appRepository); + @Override + public AppAccountEntity getAppAccount(Long appId, Long userId) { + return appAccountRepository.findByAppIdAndUserId(appId, userId) + .orElseThrow(AppAccountNotExistException::new); + } + + private final AppFormConfigConverter appFormConfigConverter; + + protected FormStandardApplicationServiceImpl(AppAccountRepository appAccountRepository, + AppFormConfigRepository appFormConfigRepository, + AppRepository appRepository, + AppFormConfigConverter appFormConfigConverter) { + super(appRepository, appAccountRepository, appFormConfigRepository); + this.appFormConfigConverter = appFormConfigConverter; } } diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/converter/AppFormConfigConverter.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/converter/AppFormConfigConverter.java new file mode 100644 index 00000000..c0df3a14 --- /dev/null +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/converter/AppFormConfigConverter.java @@ -0,0 +1,117 @@ +/* + * eiam-application-form - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.form.converter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.text.StringSubstitutor; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +import cn.topiam.employee.application.form.model.FormProtocolConfig; +import cn.topiam.employee.application.form.pojo.AppFormConfigGetResult; +import cn.topiam.employee.application.form.pojo.AppFormProtocolEndpoint; +import cn.topiam.employee.application.form.pojo.AppFormSaveConfigParam; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; +import cn.topiam.employee.common.entity.app.po.AppFormConfigPO; +import cn.topiam.employee.core.context.ServerContextHelp; +import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE; +import static cn.topiam.employee.common.constants.ProtocolConstants.FormEndpointConstants.FORM_SSO_PATH; + +/** + * 应用映射 + * + * @author TopIAM + * Created by support@topiam.cn on 2020/8/14 22:45 + */ +@Mapper(componentModel = "spring") +public interface AppFormConfigConverter { + + /** + * save 转 entity + * + * @param config {@link AppFormSaveConfigParam} + * @return {@link AppFormConfigEntity} + */ + @Mapping(target = "updateTime", ignore = true) + @Mapping(target = "updateBy", ignore = true) + @Mapping(target = "remark", ignore = true) + @Mapping(target = "id", ignore = true) + @Mapping(target = "createTime", ignore = true) + @Mapping(target = "createBy", ignore = true) + @Mapping(target = "appId", ignore = true) + AppFormConfigEntity appFormSaveConfigParamToEntity(AppFormSaveConfigParam config); + + /** + * entity转config + * + * @param po {@link AppFormConfigPO} + * @return {@link FormProtocolConfig} + */ + FormProtocolConfig appFormEntityToConfig(AppFormConfigPO po); + + /** + * po 转 result + * + * @param po {@link AppFormConfigPO} + * @return {@link AppFormConfigGetResult} + */ + default AppFormConfigGetResult entityConverterToFormConfigResult(AppFormConfigPO po) { + if (po == null) { + return null; + } + AppFormConfigGetResult result = new AppFormConfigGetResult(); + if (po.getAppId() != null) { + result.setAppId(String.valueOf(po.getAppId())); + } + result.setInitLoginType(po.getInitLoginType()); + result.setInitLoginUrl(po.getInitLoginUrl()); + result.setAuthorizationType(po.getAuthorizationType()); + result.setLoginUrl(po.getLoginUrl()); + result.setUsernameField(po.getUsernameField()); + result.setPasswordField(po.getPasswordField()); + result.setSubmitType(po.getSubmitType()); + List list = po.getOtherField(); + if (list != null) { + result.setOtherField(new ArrayList<>(list)); + } + result.setProtocolEndpoint(getProtocolEndpointDomain(po.getAppCode())); + return result; + } + + /** + * 获取协议端点 + * + * @param appCode {@link String} + * @return {@link AppFormProtocolEndpoint} + */ + private AppFormProtocolEndpoint getProtocolEndpointDomain(String appCode) { + //@formatter:off + AppFormProtocolEndpoint domain = new AppFormProtocolEndpoint(); + Map variables = new HashMap<>(16); + variables.put(APP_CODE,appCode); + StringSubstitutor sub = new StringSubstitutor(variables, "{", "}"); + //IDP SSO 端点 + domain.setIdpSsoEndpoint(sub.replace(ServerContextHelp.getPortalPublicBaseUrl()+FORM_SSO_PATH)); + return domain; + //@formatter:on + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/FormProtocolConfig.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/FormProtocolConfig.java new file mode 100644 index 00000000..cab38d69 --- /dev/null +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/FormProtocolConfig.java @@ -0,0 +1,77 @@ +/* + * eiam-application-form - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.form.model; + +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; +import cn.topiam.employee.common.enums.app.FormSubmitType; + +import lombok.Builder; +import lombok.Data; + +/** + * Form 协议配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/8/28 21:43 + */ +@Data +@Builder +public class FormProtocolConfig implements Serializable { + + @Serial + private static final long serialVersionUID = -3671812647788723766L; + + /** + * APP ID + */ + private String appId; + + /** + * APP Code + */ + private String appCode; + + /** + * 登录URL + */ + private String loginUrl; + + /** + * 登录名属性名称 + */ + private String usernameField; + + /** + * 登录密码属性名称 + */ + private String passwordField; + + /** + * 登录提交方式 + */ + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + private List otherField; +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormConfigGetResult.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormConfigGetResult.java new file mode 100644 index 00000000..4e72f037 --- /dev/null +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormConfigGetResult.java @@ -0,0 +1,101 @@ +/* + * eiam-application-form - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.form.pojo; + +import java.io.Serializable; +import java.util.List; + +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; +import cn.topiam.employee.common.enums.app.AuthorizationType; +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.common.enums.app.InitLoginType; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; + +/** + * Form 配置返回 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/31 22:46 + */ +@Data +@Schema(description = "Form 配置返回结果") +public class AppFormConfigGetResult implements Serializable { + /** + * 应用id + */ + @Schema(description = "应用id") + private String appId; + + /** + * SSO 发起方 + */ + @Parameter(description = "SSO 发起方") + private InitLoginType initLoginType; + + /** + * SSO 登录链接 + */ + @Parameter(description = "SSO 登录链接") + private String initLoginUrl; + + /** + * 授权范围 + */ + @Parameter(description = "SSO 授权范围") + private AuthorizationType authorizationType; + + /** + * 登录URL + */ + @Schema(description = "登录URL") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Schema(description = "登录名属性名称") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Schema(description = "登录密码属性名称") + private String passwordField; + + /** + * 登录提交方式 + */ + @Schema(description = "登录提交方式") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Schema(description = "登录其他信息") + private List otherField; + + /** + * 协议端点 + */ + @Schema(description = "协议端点") + private AppFormProtocolEndpoint protocolEndpoint; +} diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/pojo/result/LoginMfaFactorResult.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormProtocolEndpoint.java similarity index 58% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/pojo/result/LoginMfaFactorResult.java rename to eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormProtocolEndpoint.java index 87308dcc..eef01b69 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/pojo/result/LoginMfaFactorResult.java +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormProtocolEndpoint.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-application-form - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,38 +15,32 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.pojo.result; +package cn.topiam.employee.application.form.pojo; import java.io.Serial; import java.io.Serializable; -import cn.topiam.employee.common.enums.MfaFactor; - -import lombok.Builder; import lombok.Data; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; + /** - * Mfa 登录方式 - * - * @author TopIAM - * Created by support@topiam.cn on 2022/8/13 21:29 - */ -@Builder +* 协议端点域 +* +* @author TopIAM +* Created by support@topiam.cn on 2022/6/4 23:37 +*/ @Data -public class LoginMfaFactorResult implements Serializable { +@Schema(description = "协议端点") +public class AppFormProtocolEndpoint implements Serializable { @Serial - private static final long serialVersionUID = 7255002979319970337L; + private static final long serialVersionUID = -2261602995152894964L; + /** - * provider + * IDP SSO 端点 */ - private MfaFactor factor; - /** - * 可用 - */ - private Boolean usable; - /** - * 目标 - */ - private String target; + @Parameter(description = "IDP SSO 端点") + private String idpSsoEndpoint; } diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormSaveConfigParam.java b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormSaveConfigParam.java new file mode 100644 index 00000000..3ebad2c3 --- /dev/null +++ b/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/pojo/AppFormSaveConfigParam.java @@ -0,0 +1,93 @@ +/* + * eiam-application-form - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.form.pojo; + +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +import javax.validation.constraints.NotNull; + +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; +import cn.topiam.employee.common.enums.app.AuthorizationType; +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.common.enums.app.InitLoginType; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.media.Schema; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:45 + */ +@Data +@Schema(description = "保存 表单代填 应用配置参数") +public class AppFormSaveConfigParam implements Serializable { + + @Serial + private static final long serialVersionUID = 7257798528680745281L; + + /** + * SSO范围 + */ + @NotNull(message = "SSO范围不能为空") + @Schema(description = "SSO范围") + private AuthorizationType authorizationType; + + /** + * SSO发起方 + */ + @NotNull(message = "SSO发起方不能为空") + @Schema(description = "SSO发起方") + private InitLoginType initLoginType; + + /** + * 登录URL + */ + @NotNull(message = "登录URL不能为空") + @Schema(description = "登录URL") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @NotNull(message = "登录名属性名称不能为空") + @Schema(description = "登录名属性名称") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @NotNull(message = "登录密码属性名称不能为空") + @Schema(description = "登录密码属性名称") + private String passwordField; + + /** + * 登录提交方式 + */ + @NotNull(message = "登录提交方式不能为空") + @Schema(description = "登录提交方式") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Schema(description = "登录其他信息") + private List otherField; +} diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcApplicationService.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcApplicationService.java index a01c4e72..7c320944 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcApplicationService.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/AbstractOidcApplicationService.java @@ -40,7 +40,7 @@ public abstract class AbstractOidcApplicationService extends AbstractApplication appAccountRepository.deleteAllByAppId(Long.valueOf(appId)); //删除应用权限策略 appAccessPolicyRepository.deleteAllByAppId(Long.valueOf(appId)); - //删除SAML2配置 + //删除OIDC配置 appOidcConfigRepository.deleteByAppId(Long.valueOf(appId)); } diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardApplicationServiceImpl.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardApplicationServiceImpl.java index 075a59c5..17993f0b 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardApplicationServiceImpl.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/OidcStandardApplicationServiceImpl.java @@ -39,7 +39,7 @@ import com.google.common.collect.Sets; import cn.topiam.employee.application.exception.AppNotExistException; import cn.topiam.employee.application.oidc.converter.AppOidcStandardConfigConverter; -import cn.topiam.employee.application.oidc.model.AppOidcStandardSaveConfigParam; +import cn.topiam.employee.application.oidc.pojo.AppOidcStandardSaveConfigParam; import cn.topiam.employee.audit.context.AuditContext; import cn.topiam.employee.common.entity.app.AppEntity; import cn.topiam.employee.common.entity.app.AppOidcConfigEntity; diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/converter/AppOidcStandardConfigConverter.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/converter/AppOidcStandardConfigConverter.java index 91452748..d648f1e8 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/converter/AppOidcStandardConfigConverter.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/converter/AppOidcStandardConfigConverter.java @@ -25,8 +25,9 @@ import org.apache.commons.text.StringSubstitutor; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import cn.topiam.employee.application.oidc.model.AppOidcStandardConfigGetResult; -import cn.topiam.employee.application.oidc.model.AppOidcStandardSaveConfigParam; +import cn.topiam.employee.application.oidc.pojo.AppOidcProtocolEndpoint; +import cn.topiam.employee.application.oidc.pojo.AppOidcStandardConfigGetResult; +import cn.topiam.employee.application.oidc.pojo.AppOidcStandardSaveConfigParam; import cn.topiam.employee.common.constants.ProtocolConstants; import cn.topiam.employee.common.entity.app.AppOidcConfigEntity; import cn.topiam.employee.common.entity.app.po.AppOidcConfigPO; @@ -88,6 +89,7 @@ public interface AppOidcStandardConfigConverter { * @param config {@link AppOidcConfigEntity} * @return {@link AppOidcConfigEntity} */ + @Mapping(target = "responseTypes", ignore = true) @Mapping(target = "updateTime", ignore = true) @Mapping(target = "updateBy", ignore = true) @Mapping(target = "remark", ignore = true) @@ -101,11 +103,11 @@ public interface AppOidcStandardConfigConverter { * 获取协议端点 * * @param appCode {@link String} - * @return {@link AppOidcStandardConfigGetResult.ProtocolEndpoint} + * @return {@link AppOidcProtocolEndpoint} */ - private AppOidcStandardConfigGetResult.ProtocolEndpoint getProtocolEndpointDomain(String appCode) { + private AppOidcProtocolEndpoint getProtocolEndpointDomain(String appCode) { //@formatter:off - AppOidcStandardConfigGetResult.ProtocolEndpoint domain = new AppOidcStandardConfigGetResult.ProtocolEndpoint(); + AppOidcProtocolEndpoint domain = new AppOidcProtocolEndpoint(); //issues Map variables = new HashMap<>(16); variables.put(APP_CODE,appCode); diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcProtocolEndpoint.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcProtocolEndpoint.java new file mode 100644 index 00000000..f5d5a6f6 --- /dev/null +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcProtocolEndpoint.java @@ -0,0 +1,81 @@ +/* + * eiam-application-oidc - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.application.oidc.pojo; + +import java.io.Serial; +import java.io.Serializable; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Schema; + +/** + * 协议端点域 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/6/4 23:37 + */ +@Data +@Schema(description = "协议端点") +public class AppOidcProtocolEndpoint implements Serializable { + + @Serial + private static final long serialVersionUID = -2261602995152894964L; + /** + * oidcIssuer + */ + @Parameter(description = "Issuer") + private String issuer; + + /** + * discoveryEndpoint + */ + @Parameter(description = "Discovery Endpoint") + private String discoveryEndpoint; + + /** + * UserinfoEndpoint + */ + @Parameter(description = "UserInfo Endpoint") + private String userinfoEndpoint; + + /** + * jwksEndpoint + */ + @Parameter(description = "Jwks Endpoint") + private String jwksEndpoint; + + /** + * revokeEndpoint + */ + @Parameter(description = "Revoke Endpoint") + private String revokeEndpoint; + + /** + * tokenEndpoint + */ + @Parameter(description = "Token Endpoint") + private String tokenEndpoint; + + /** + * authorizationEndpoint + */ + @Parameter(description = "Authorization Endpoint") + private String authorizationEndpoint; +} diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/model/AppOidcStandardConfigGetResult.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcStandardConfigGetResult.java similarity index 55% rename from eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/model/AppOidcStandardConfigGetResult.java rename to eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcStandardConfigGetResult.java index ccea1df6..0ca3fd5a 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/model/AppOidcStandardConfigGetResult.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcStandardConfigGetResult.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.oidc.model; +package cn.topiam.employee.application.oidc.pojo; import java.io.Serial; import java.io.Serializable; @@ -40,163 +40,109 @@ import io.swagger.v3.oas.annotations.media.Schema; public class AppOidcStandardConfigGetResult implements Serializable { @Serial - private static final long serialVersionUID = 4177874005424703372L; + private static final long serialVersionUID = 4177874005424703372L; /** * APP ID */ @Parameter(description = "appId") - private Long appId; + private Long appId; /** * SSO 发起方 */ @Parameter(description = "SSO 发起方") - private InitLoginType initLoginType; + private InitLoginType initLoginType; /** * SSO 登录链接 */ @Parameter(description = "SSO 登录链接") - private String initLoginUrl; + private String initLoginUrl; /** * 授权范围 */ @Parameter(description = "SSO 授权范围") - private AuthorizationType authorizationType; + private AuthorizationType authorizationType; /** * authorizationGrantTypes */ @Parameter(description = "认证授权类型") - private Set authGrantTypes; + private Set authGrantTypes; /** * 客户端认证方式 */ @Parameter(description = "客户端认证方式") - private Set clientAuthMethods; + private Set clientAuthMethods; /** * 重定向URI */ @Parameter(description = "重定向URI") - private Set redirectUris; + private Set redirectUris; /** * scopes */ @Parameter(description = "授权范围") - private Set grantScopes; + private Set grantScopes; /** * 启用PKCE */ @Parameter(description = "启用PKCE") - private Boolean requireProofKey; + private Boolean requireProofKey; /** * 令牌 Endpoint 身份验证签名算法 */ @Parameter(description = "令牌 Endpoint 身份验证签名算法") - private String tokenEndpointAuthSigningAlgorithm; + private String tokenEndpointAuthSigningAlgorithm; /** * 是否需要授权同意 */ @Parameter(description = "是否需要授权同意") - private Boolean requireAuthConsent; + private Boolean requireAuthConsent; /** * 访问令牌有效时间 */ @Parameter(description = "访问令牌有效时间") - private String accessTokenTimeToLive; + private String accessTokenTimeToLive; /** * 刷新令牌有效时间 */ @Parameter(description = "刷新令牌有效时间") - private String refreshTokenTimeToLive; + private String refreshTokenTimeToLive; /** * ID token 有效时间 */ @Parameter(description = "ID 令牌有效时间") - private String idTokenTimeToLive; + private String idTokenTimeToLive; /** * id 令牌签名算法 */ @Parameter(description = "Id令牌签名算法") - private String idTokenSignatureAlgorithm; + private String idTokenSignatureAlgorithm; /** * 协议端点域 */ @Parameter(description = "协议端点域") - private ProtocolEndpoint protocolEndpoint; + private AppOidcProtocolEndpoint protocolEndpoint; /** * Access Token 格式 */ @Parameter(description = "Access Token 格式") - private String accessTokenFormat; + private String accessTokenFormat; /** * 是否重用刷新令牌 */ @Parameter(description = "是否重用刷新令牌") - private Boolean reuseRefreshToken; + private Boolean reuseRefreshToken; - /** - * 协议端点域 - * - * @author TopIAM - * Created by support@topiam.cn on 2022/6/4 23:37 - */ - @Data - @Schema(description = "协议端点") - public static class ProtocolEndpoint implements Serializable { - - @Serial - private static final long serialVersionUID = -2261602995152894964L; - /** - * oidcIssuer - */ - @Parameter(description = "Issuer") - private String issuer; - - /** - * discoveryEndpoint - */ - @Parameter(description = "Discovery Endpoint") - private String discoveryEndpoint; - - /** - * UserinfoEndpoint - */ - @Parameter(description = "UserInfo Endpoint") - private String userinfoEndpoint; - - /** - * jwksEndpoint - */ - @Parameter(description = "Jwks Endpoint") - private String jwksEndpoint; - - /** - * revokeEndpoint - */ - @Parameter(description = "Revoke Endpoint") - private String revokeEndpoint; - - /** - * tokenEndpoint - */ - @Parameter(description = "Token Endpoint") - private String tokenEndpoint; - - /** - * authorizationEndpoint - */ - @Parameter(description = "Authorization Endpoint") - private String authorizationEndpoint; - } } diff --git a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/model/AppOidcStandardSaveConfigParam.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcStandardSaveConfigParam.java similarity index 98% rename from eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/model/AppOidcStandardSaveConfigParam.java rename to eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcStandardSaveConfigParam.java index f66a60b4..4140309f 100644 --- a/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/model/AppOidcStandardSaveConfigParam.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/AppOidcStandardSaveConfigParam.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.oidc.model; +package cn.topiam.employee.application.oidc.pojo; import java.io.Serial; import java.io.Serializable; diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/package-info.java b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/package-info.java similarity index 85% rename from eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/package-info.java rename to eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/package-info.java index 24c3c14d..14b28282 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/package-info.java +++ b/eiam-application/eiam-application-oidc/src/main/java/cn/topiam/employee/application/oidc/pojo/package-info.java @@ -1,5 +1,5 @@ /* - * eiam-application-saml2 - Employee Identity and Access Management Program + * eiam-application-oidc - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application; \ No newline at end of file +package cn.topiam.employee.application.oidc.pojo; \ No newline at end of file diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/AbstractSamlAppService.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/AbstractSamlAppService.java index 9a369e5a..a05cc437 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/AbstractSamlAppService.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/AbstractSamlAppService.java @@ -26,11 +26,14 @@ import org.mapstruct.Mapping; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.AlternativeJdkIdGenerator; import org.springframework.util.CollectionUtils; +import org.springframework.util.IdGenerator; import cn.topiam.employee.application.AbstractApplicationService; -import cn.topiam.employee.application.Saml2ApplicationService; import cn.topiam.employee.application.exception.AppCertNotExistException; +import cn.topiam.employee.application.saml2.model.Saml2ProtocolConfig; +import cn.topiam.employee.application.saml2.model.Saml2SsoModel; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.entity.app.AppAccountEntity; import cn.topiam.employee.common.entity.app.AppCertEntity; @@ -43,8 +46,6 @@ import cn.topiam.employee.common.exception.app.AppAccountNotExistException; import cn.topiam.employee.common.repository.account.UserRepository; import cn.topiam.employee.common.repository.app.*; import cn.topiam.employee.common.util.SamlKeyStoreProvider; -import cn.topiam.employee.core.protocol.Saml2ProtocolConfig; -import cn.topiam.employee.core.protocol.Saml2SsoModel; import cn.topiam.employee.core.security.util.SecurityUtils; import cn.topiam.employee.support.context.ApplicationContextHelp; import static cn.topiam.employee.common.enums.app.SamlNameIdValueType.*; @@ -134,6 +135,11 @@ public abstract class AbstractSamlAppService extends AbstractApplicationService */ protected final AppSaml2ConfigRepository appSaml2ConfigRepository; + /** + * IdGenerator + */ + protected final IdGenerator idGenerator; + protected AbstractSamlAppService(AppCertRepository appCertRepository, AppAccountRepository appAccountRepository, AppAccessPolicyRepository appAccessPolicyRepository, @@ -141,6 +147,7 @@ public abstract class AbstractSamlAppService extends AbstractApplicationService AppSaml2ConfigRepository appSaml2ConfigRepository) { super(appCertRepository, appAccountRepository, appAccessPolicyRepository, appRepository); this.appSaml2ConfigRepository = appSaml2ConfigRepository; + this.idGenerator = new AlternativeJdkIdGenerator(); } @Mapper(componentModel = "spring") diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/Saml2ApplicationService.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2ApplicationService.java similarity index 79% rename from eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/Saml2ApplicationService.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2ApplicationService.java index 4f25df24..98e8b50d 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/Saml2ApplicationService.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2ApplicationService.java @@ -1,5 +1,5 @@ /* - * eiam-application-core - Employee Identity and Access Management Program + * eiam-application-saml2 - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,10 +15,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application; +package cn.topiam.employee.application.saml2; -import cn.topiam.employee.core.protocol.Saml2ProtocolConfig; -import cn.topiam.employee.core.protocol.Saml2SsoModel; +import cn.topiam.employee.application.ApplicationService; +import cn.topiam.employee.application.saml2.model.Saml2ProtocolConfig; +import cn.topiam.employee.application.saml2.model.Saml2SsoModel; /** * 应用接口 diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2StandardApplicationServiceImpl.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2StandardApplicationServiceImpl.java index eb3e424c..6db7a640 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2StandardApplicationServiceImpl.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/Saml2StandardApplicationServiceImpl.java @@ -28,9 +28,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.ObjectMapper; + import cn.topiam.employee.application.exception.AppNotExistException; import cn.topiam.employee.application.saml2.converter.AppSaml2StandardConfigConverter; -import cn.topiam.employee.application.saml2.model.AppSaml2StandardSaveConfigParam; +import cn.topiam.employee.application.saml2.pojo.AppSaml2StandardSaveConfigParam; import cn.topiam.employee.audit.context.AuditContext; import cn.topiam.employee.common.entity.app.AppEntity; import cn.topiam.employee.common.entity.app.AppSaml2ConfigEntity; @@ -69,6 +71,7 @@ public class Saml2StandardApplicationServiceImpl extends AbstractSamlAppService public void saveConfig(String appId, Map config) { AppSaml2StandardSaveConfigParam model; try { + ObjectMapper mapper = new ObjectMapper(); String value = mapper.writeValueAsString(config); // 指定序列化输入的类型 mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); diff --git a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/SamlRamRoleNameValueType.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/SamlRamRoleNameValueType.java similarity index 91% rename from eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/SamlRamRoleNameValueType.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/SamlRamRoleNameValueType.java index 0f18b798..e357d9c5 100644 --- a/eiam-application/eiam-application-core/src/main/java/cn/topiam/employee/application/SamlRamRoleNameValueType.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/SamlRamRoleNameValueType.java @@ -1,5 +1,5 @@ /* - * eiam-application-core - Employee Identity and Access Management Program + * eiam-application-saml2 - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application; +package cn.topiam.employee.application.saml2; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/converter/AppSaml2StandardConfigConverter.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/converter/AppSaml2StandardConfigConverter.java index 053b1ccb..48eefa9b 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/converter/AppSaml2StandardConfigConverter.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/converter/AppSaml2StandardConfigConverter.java @@ -22,9 +22,9 @@ import java.util.List; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import cn.topiam.employee.application.saml2.model.AppSaml2StandardConfigGetResult; -import cn.topiam.employee.application.saml2.model.AppSaml2StandardSaveConfigParam; -import cn.topiam.employee.application.saml2.model.Saml2ConverterUtils; +import cn.topiam.employee.application.saml2.pojo.AppSaml2StandardConfigGetResult; +import cn.topiam.employee.application.saml2.pojo.AppSaml2StandardSaveConfigParam; +import cn.topiam.employee.application.saml2.pojo.Saml2ConverterUtils; import cn.topiam.employee.common.entity.app.AppSaml2ConfigEntity; import cn.topiam.employee.common.entity.app.po.AppSaml2ConfigPO; diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/protocol/Saml2ProtocolConfig.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ProtocolConfig.java similarity index 97% rename from eiam-core/src/main/java/cn/topiam/employee/core/protocol/Saml2ProtocolConfig.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ProtocolConfig.java index 6e5f646a..7b945fda 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/protocol/Saml2ProtocolConfig.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ProtocolConfig.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-application-saml2 - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.protocol; +package cn.topiam.employee.application.saml2.model; import java.io.Serial; import java.io.Serializable; diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/protocol/Saml2SsoModel.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2SsoModel.java similarity index 97% rename from eiam-core/src/main/java/cn/topiam/employee/core/protocol/Saml2SsoModel.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2SsoModel.java index 82d145a3..5b4b8041 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/protocol/Saml2SsoModel.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2SsoModel.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-application-saml2 - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.protocol; +package cn.topiam.employee.application.saml2.model; import java.io.Serial; import java.io.Serializable; diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ProtocolEndpoint.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2ProtocolEndpoint.java similarity index 93% rename from eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ProtocolEndpoint.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2ProtocolEndpoint.java index 2e16338e..1adf4dad 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ProtocolEndpoint.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2ProtocolEndpoint.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.saml2.model; +package cn.topiam.employee.application.saml2.pojo; import java.io.Serial; import java.io.Serializable; @@ -33,7 +33,7 @@ import io.swagger.v3.oas.annotations.media.Schema; */ @Data @Schema(description = "协议端点") -public class Saml2ProtocolEndpoint implements Serializable { +public class AppSaml2ProtocolEndpoint implements Serializable { @Serial private static final long serialVersionUID = -2261602995152894964L; diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/AppSaml2StandardConfigGetResult.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2StandardConfigGetResult.java similarity index 97% rename from eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/AppSaml2StandardConfigGetResult.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2StandardConfigGetResult.java index 02605901..24e90c86 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/AppSaml2StandardConfigGetResult.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2StandardConfigGetResult.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.saml2.model; +package cn.topiam.employee.application.saml2.pojo; import java.util.List; import java.util.Map; @@ -160,7 +160,7 @@ public class AppSaml2StandardConfigGetResult { * 协议端点域 */ @Parameter(description = "协议端点域") - private Saml2ProtocolEndpoint protocolEndpoint; + private AppSaml2ProtocolEndpoint protocolEndpoint; /** * 模版配置 diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/AppSaml2StandardSaveConfigParam.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2StandardSaveConfigParam.java similarity index 98% rename from eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/AppSaml2StandardSaveConfigParam.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2StandardSaveConfigParam.java index 8923844e..d36de479 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/AppSaml2StandardSaveConfigParam.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/AppSaml2StandardSaveConfigParam.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.saml2.model; +package cn.topiam.employee.application.saml2.pojo; import java.io.Serial; import java.io.Serializable; diff --git a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ConverterUtils.java b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/Saml2ConverterUtils.java similarity index 83% rename from eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ConverterUtils.java rename to eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/Saml2ConverterUtils.java index ac618f1e..5e528d7c 100644 --- a/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/model/Saml2ConverterUtils.java +++ b/eiam-application/eiam-application-saml2/src/main/java/cn/topiam/employee/application/saml2/pojo/Saml2ConverterUtils.java @@ -15,10 +15,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.saml2.model; +package cn.topiam.employee.application.saml2.pojo; import cn.topiam.employee.core.context.ServerContextHelp; -import static cn.topiam.employee.common.constants.ProtocolConstants.*; +import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE_VARIABLE; +import static cn.topiam.employee.common.constants.ProtocolConstants.Saml2EndpointConstants; /** * Saml2ConverterUtils @@ -31,10 +32,10 @@ public class Saml2ConverterUtils { * 应用ID * * @param appCode {@link String} - * @return {@link Saml2ProtocolEndpoint} + * @return {@link AppSaml2ProtocolEndpoint} */ - public static Saml2ProtocolEndpoint getProtocolEndpointDomain(String appCode) { - Saml2ProtocolEndpoint domain = new Saml2ProtocolEndpoint(); + public static AppSaml2ProtocolEndpoint getProtocolEndpointDomain(String appCode) { + AppSaml2ProtocolEndpoint domain = new AppSaml2ProtocolEndpoint(); //IDP String baseUrl = ServerContextHelp.getPortalPublicBaseUrl(); //元数据端点 diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/context/AuditContext.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/context/AuditContext.java index 667113b4..aee7f92b 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/context/AuditContext.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/context/AuditContext.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import org.springframework.security.core.Authentication; import org.springframework.util.CollectionUtils; import com.alibaba.ttl.TransmittableThreadLocal; @@ -41,6 +42,11 @@ public class AuditContext { */ private static final TransmittableThreadLocal CONTENT = new TransmittableThreadLocal<>(); + /** + * Authentication + */ + private static final TransmittableThreadLocal AUTHENTICATION = new TransmittableThreadLocal<>(); + /** * 目标对象 */ @@ -122,6 +128,19 @@ public class AuditContext { ADDITIONAL_DATA.set(value); } + /** + * Get Authentication + * + * @return {@link Authentication} + */ + public static Authentication getAuthorization() { + return AUTHENTICATION.get(); + } + + public static void setAuthorization(Authentication authorization) { + AUTHENTICATION.set(authorization); + } + /** * Get Target * @@ -156,6 +175,13 @@ public class AuditContext { TARGET_LIST.remove(); } + /** + * Remove Authentication + */ + public static void removeAuthentication() { + AUTHENTICATION.remove(); + } + /** * remove */ @@ -182,5 +208,7 @@ public class AuditContext { removeAdditionalData(); removeContent(); removeTarget(); + removeAuthentication(); } + } diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Actor.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Actor.java index bbf4dd48..0935d4b4 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Actor.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Actor.java @@ -40,6 +40,8 @@ public class Actor implements Serializable { public static final String ACTOR_ID = "actor.id"; public static final String ACTOR_TYPE = "actor.type"; + public static final String ACTOR_AUTH_TYPE = "actor.auth_type.keyword"; + @Serial private static final long serialVersionUID = -1144169992714000310L; /** @@ -54,4 +56,10 @@ public class Actor implements Serializable { @Field(type = FieldType.Keyword, name = "type") private UserType type; + /** + * 身份验证类型 + */ + @Field(type = FieldType.Keyword, name = "auth_type") + private String authType; + } diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/AuditEntity.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/AuditEntity.java index 1c2adfde..7da1b835 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/AuditEntity.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/AuditEntity.java @@ -25,18 +25,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.audit.enums.EventStatus; import cn.topiam.employee.audit.enums.EventType; import cn.topiam.employee.common.enums.UserType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 审计 @@ -51,7 +56,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @Entity @Table(name = "audit") -public class AuditEntity extends BaseEntity { +@SQLDelete(sql = "update audit set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update audit set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AuditEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3119319193111206582L; @@ -136,4 +144,10 @@ public class AuditEntity extends BaseEntity { */ @Column(name = "actor_type") private UserType actorType; + + /** + * 身份验证类型 + */ + @Column(name = "actor_auth_type") + private String actorAuthType; } diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Event.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Event.java index 6b7b7787..f145df1a 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Event.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Event.java @@ -64,7 +64,7 @@ public class Event implements Serializable { /** * 事件内容 */ - @Field(type = FieldType.Text, name = "content") + @Field(type = FieldType.Object, name = "content") private String content; /** diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/GeoLocation.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/GeoLocation.java index 6d36b0fd..2d9ac4e4 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/GeoLocation.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/GeoLocation.java @@ -41,7 +41,9 @@ import lombok.Data; public class GeoLocation implements Serializable { @Serial - private static final long serialVersionUID = -1144169992714000310L; + private static final long serialVersionUID = -1144169992714000310L; + + public static final String GEO_LOCATION_PROVINCE_CODE = "geo_location.province_code.keyword"; /** * IP diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Target.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Target.java index 054b1e64..9b143bec 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Target.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/entity/Target.java @@ -48,6 +48,12 @@ public class Target implements Serializable { */ @Field(type = FieldType.Keyword, name = "id") private String id; + + /** + * 目标名称 + */ + @Field(type = FieldType.Keyword, name = "name") + private String name; /** * * 目标类型 @@ -55,4 +61,9 @@ public class Target implements Serializable { @Field(type = FieldType.Keyword, name = "type") private TargetType type; + /** + * 目标类型名称 + */ + @Field(type = FieldType.Keyword, name = "type_name") + private String typeName; } diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEvent.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEvent.java index 93cce30b..138b1136 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEvent.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEvent.java @@ -18,7 +18,7 @@ package cn.topiam.employee.audit.event; import java.io.Serial; -import java.util.*; +import java.util.List; import org.springframework.context.ApplicationEvent; diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventListener.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventListener.java index 5410e82f..af91a912 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventListener.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventListener.java @@ -30,7 +30,7 @@ import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import cn.topiam.employee.audit.entity.*; -import cn.topiam.employee.audit.repository.*; +import cn.topiam.employee.audit.repository.AuditRepository; import cn.topiam.employee.core.configuration.EiamSupportProperties; import static cn.topiam.employee.common.constants.AuditConstants.getAuditIndexPrefix; import static cn.topiam.employee.support.constant.EiamConstants.DEFAULT_DATE_FORMATTER_PATTERN; diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventPublish.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventPublish.java index f1ab28d9..20d2d3f6 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventPublish.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/event/AuditEventPublish.java @@ -35,6 +35,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Maps; import cn.topiam.employee.audit.entity.*; import cn.topiam.employee.audit.enums.EventStatus; @@ -86,6 +87,35 @@ public class AuditEventPublish { //@formatter:on } + /** + * 发布 审计事件 + * + * @param eventType {@link EventType} + */ + public void publish(EventType eventType, Authentication authentication, EventStatus eventStatus, + List targets, String result) { + //@formatter:off + //封装操作事件 + Event event = Event.builder() + .type(eventType) + .time(Instant.now()) + .result(result) + .status(eventStatus).build(); + if (authentication.getPrincipal() instanceof UserDetails){ + String username = ((UserDetails) authentication.getPrincipal()).getUsername(); + event.setContent(username+":"+event.getType().getDesc()); + } + //封装地理位置 + GeoLocation geoLocationModal = getGeoLocation(); + //封装用户代理 + UserAgent userAgent = getUserAgent(); + //封装操作人 + Actor actor = getActor(authentication); + //Publish AuditEvent + applicationEventPublisher.publishEvent(new AuditEvent(TraceUtils.get(), ServletContextHelp.getSession().getId(), actor, event, userAgent, geoLocationModal, targets)); + //@formatter:on + } + /** * 发布 审计事件 * @@ -99,9 +129,12 @@ public class AuditEventPublish { .type(eventType) .time(Instant.now()) .status(eventStatus).build(); - if (authentication.getPrincipal() instanceof UserDetails){ - String username = ((UserDetails) authentication.getPrincipal()).getUsername(); - event.setContent(username+":"+event.getType().getDesc()); + if (authentication.getPrincipal() instanceof UserDetails principal){ + String username = principal.getUsername(); + Map content= Maps.newConcurrentMap(); + content.put("auth_type",principal.getAuthType()); + content.put("desc",username+":"+event.getType().getDesc()); + event.setContent(JSONObject.toJSONString(content)); } //封装地理位置 GeoLocation geoLocationModal = getGeoLocation(); @@ -209,10 +242,16 @@ public class AuditEventPublish { //@formatter:off SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); - return Actor.builder() + Object principal = authentication.getPrincipal(); + + Actor actor = Actor.builder() .id(getActorId(authentication)) .type(getActorType(authentication)) .build(); + if (principal instanceof UserDetails){ + actor.setAuthType(((UserDetails) principal).getAuthType()); + } + return actor; //@formatter:on } @@ -223,10 +262,15 @@ public class AuditEventPublish { */ private Actor getActor(Authentication authentication) { //@formatter:off - return Actor.builder() + Actor actor = Actor.builder() .id(getActorId(authentication)) .type(getActorType(authentication)) .build(); + Object principal = authentication.getPrincipal(); + if (principal instanceof UserDetails){ + actor.setAuthType(((UserDetails) principal).getAuthType()); + } + return actor; //@formatter:on } diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/repository/AuditRepository.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/repository/AuditRepository.java index 3b05e6cf..21615f80 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/repository/AuditRepository.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/repository/AuditRepository.java @@ -21,11 +21,11 @@ import java.time.LocalDateTime; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import cn.topiam.employee.audit.entity.AuditEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 行为审计repository @@ -34,7 +34,7 @@ import cn.topiam.employee.audit.entity.AuditEntity; * Created by support@topiam.cn on 2021/9/11 22:32 */ @Repository -public interface AuditRepository extends CrudRepository, +public interface AuditRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { /** diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/service/converter/AuditDataConverter.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/service/converter/AuditDataConverter.java index e23eebe9..ffef737d 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/service/converter/AuditDataConverter.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/service/converter/AuditDataConverter.java @@ -40,13 +40,33 @@ import com.google.common.collect.Lists; import cn.topiam.employee.audit.controller.pojo.AuditListQuery; import cn.topiam.employee.audit.controller.pojo.AuditListResult; -import cn.topiam.employee.audit.entity.*; +import cn.topiam.employee.audit.entity.Actor; +import cn.topiam.employee.audit.entity.AuditElasticSearchEntity; +import cn.topiam.employee.audit.entity.Event; +import cn.topiam.employee.audit.entity.Target; import cn.topiam.employee.audit.enums.EventType; +import cn.topiam.employee.audit.enums.TargetType; +import cn.topiam.employee.common.entity.account.OrganizationEntity; import cn.topiam.employee.common.entity.account.UserEntity; +import cn.topiam.employee.common.entity.account.UserGroupEntity; +import cn.topiam.employee.common.entity.app.AppEntity; +import cn.topiam.employee.common.entity.app.AppPermissionResourceEntity; +import cn.topiam.employee.common.entity.app.AppPermissionRoleEntity; +import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; +import cn.topiam.employee.common.entity.identitysource.IdentitySourceEntity; import cn.topiam.employee.common.entity.setting.AdministratorEntity; +import cn.topiam.employee.common.entity.setting.MailTemplateEntity; import cn.topiam.employee.common.enums.UserType; +import cn.topiam.employee.common.repository.account.OrganizationRepository; +import cn.topiam.employee.common.repository.account.UserGroupRepository; import cn.topiam.employee.common.repository.account.UserRepository; +import cn.topiam.employee.common.repository.app.AppPermissionResourceRepository; +import cn.topiam.employee.common.repository.app.AppPermissionRoleRepository; +import cn.topiam.employee.common.repository.app.AppRepository; +import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; +import cn.topiam.employee.common.repository.identitysource.IdentitySourceRepository; import cn.topiam.employee.common.repository.setting.AdministratorRepository; +import cn.topiam.employee.common.repository.setting.MailTemplateRepository; import cn.topiam.employee.support.context.ApplicationContextHelp; import cn.topiam.employee.support.repository.page.domain.Page; import cn.topiam.employee.support.repository.page.domain.PageModel; @@ -69,7 +89,7 @@ public interface AuditDataConverter { * searchHits 转审计列表 * * @param search {@link SearchHits} - * @param page {@link PageModel} + * @param page {@link PageModel} * @return {@link Page} */ default Page searchHitsConvertToAuditListResult(SearchHits search, @@ -94,6 +114,14 @@ public interface AuditDataConverter { //用户类型 result.setUserType(actor.getType().getCode()); //操作对象 + if (Objects.nonNull(content.getTargets())) { + for (Target target : content.getTargets()) { + if (Objects.nonNull(target.getId())) { + target.setName(getTargetName(target.getType(), target.getId())); + } + target.setTypeName(target.getType().getDesc()); + } + } result.setTargets(content.getTargets()); list.add(result); }); @@ -102,7 +130,7 @@ public interface AuditDataConverter { result.setPagination(Page.Pagination.builder() .total(search.getTotalHits()) .totalPages(Math.toIntExact(search.getTotalHits() / page.getPageSize())) - .current(page.getCurrent()+1) + .current(page.getCurrent() + 1) .build()); result.setList(list); //@formatter:on @@ -110,10 +138,9 @@ public interface AuditDataConverter { } /** - * * 获取用户名 * - * @param actorId {@link String} + * @param actorId {@link String} * @param actorType {@link UserType} * @return {@link String} */ @@ -140,7 +167,7 @@ public interface AuditDataConverter { * 审计列表请求到本机搜索查询 * * @param query {@link AuditListQuery} - * @param page {@link PageModel} + * @param page {@link PageModel} * @return {@link NativeSearchQuery} */ default NativeSearchQuery auditListRequestConvertToNativeSearchQuery(AuditListQuery query, @@ -201,4 +228,118 @@ public interface AuditDataConverter { //排序 .withSorts(fieldSortBuilders).build(); } + + /** + * 获取目标名称 + * + * @param targetType {@link TargetType} + * @param id {@link String} + * @return + */ + @SuppressWarnings("AlibabaMethodTooLong") + default String getTargetName(TargetType targetType, String id) { + String name = ""; + if (TargetType.USER.equals(targetType) || TargetType.USER_DETAIL.equals(targetType)) { + UserRepository userRepository = ApplicationContextHelp.getBean(UserRepository.class); + Optional user = userRepository.findByIdContainsDeleted(Long.valueOf(id)); + if (user.isPresent()) { + name = user.get().getUsername(); + } + } + + if (TargetType.USER_GROUP.equals(targetType)) { + UserGroupRepository userGroupRepository = ApplicationContextHelp + .getBean(UserGroupRepository.class); + Optional userGroup = userGroupRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (userGroup.isPresent()) { + name = userGroup.get().getName(); + } + } + + if (TargetType.IDENTITY_SOURCE.equals(targetType)) { + IdentitySourceRepository identitySourceRepository = ApplicationContextHelp + .getBean(IdentitySourceRepository.class); + Optional identitySource = identitySourceRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (identitySource.isPresent()) { + name = identitySource.get().getName(); + } + } + + if (TargetType.ORGANIZATION.equals(targetType)) { + OrganizationRepository organizationRepository = ApplicationContextHelp + .getBean(OrganizationRepository.class); + Optional organizationEntity = organizationRepository + .findByIdContainsDeleted(id); + if (organizationEntity.isPresent()) { + name = organizationEntity.get().getName(); + } + } + + if (TargetType.APPLICATION.equals(targetType)) { + AppRepository appRepository = ApplicationContextHelp.getBean(AppRepository.class); + Optional appEntity = appRepository.findByIdContainsDeleted(Long.valueOf(id)); + if (appEntity.isPresent()) { + name = appEntity.get().getName(); + } + } + + if (TargetType.APP_PERMISSION_RESOURCE.equals(targetType)) { + AppPermissionResourceRepository appPermissionResourceRepository = ApplicationContextHelp + .getBean(AppPermissionResourceRepository.class); + Optional appPermissionResourceEntity = appPermissionResourceRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (appPermissionResourceEntity.isPresent()) { + name = appPermissionResourceEntity.get().getName(); + } + } + + if (TargetType.APPLICATION_ACCOUNT.equals(targetType)) { + if (org.apache.commons.lang3.StringUtils.isNotBlank(id)) { + name = id; + } + } + + if (TargetType.APP_PERMISSION_ROLE.equals(targetType)) { + AppPermissionRoleRepository appPermissionResourceRepository = ApplicationContextHelp + .getBean(AppPermissionRoleRepository.class); + Optional appPermissionRoleEntity = appPermissionResourceRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (appPermissionRoleEntity.isPresent()) { + name = appPermissionRoleEntity.get().getName(); + } + } + + if (TargetType.ADMINISTRATOR.equals(targetType)) { + AdministratorRepository administratorRepository = ApplicationContextHelp + .getBean(AdministratorRepository.class); + Optional administratorEntity = administratorRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (administratorEntity.isPresent()) { + name = administratorEntity.get().getUsername(); + } + } + + if (TargetType.MAIL_TEMPLATE.equals(targetType)) { + MailTemplateRepository mailTemplateRepository = ApplicationContextHelp + .getBean(MailTemplateRepository.class); + Optional mailTemplateEntity = mailTemplateRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (mailTemplateEntity.isPresent()) { + name = mailTemplateEntity.get().getSender(); + } + } + + if (TargetType.IDENTITY_PROVIDER.equals(targetType)) { + IdentityProviderRepository identityProviderRepository = ApplicationContextHelp + .getBean(IdentityProviderRepository.class); + Optional identityProviderEntity = identityProviderRepository + .findByIdContainsDeleted(Long.valueOf(id)); + if (identityProviderEntity.isPresent()) { + name = identityProviderEntity.get().getName(); + } + } + return name; + } } diff --git a/eiam-audit/src/main/java/cn/topiam/employee/audit/service/impl/AuditServiceImpl.java b/eiam-audit/src/main/java/cn/topiam/employee/audit/service/impl/AuditServiceImpl.java index 18ae85c9..61563148 100644 --- a/eiam-audit/src/main/java/cn/topiam/employee/audit/service/impl/AuditServiceImpl.java +++ b/eiam-audit/src/main/java/cn/topiam/employee/audit/service/impl/AuditServiceImpl.java @@ -17,7 +17,10 @@ */ package cn.topiam.employee.audit.service.impl; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; diff --git a/eiam-authentication/eiam-authentication-all/pom.xml b/eiam-authentication/eiam-authentication-all/pom.xml index b861659c..940d36d0 100644 --- a/eiam-authentication/eiam-authentication-all/pom.xml +++ b/eiam-authentication/eiam-authentication-all/pom.xml @@ -63,6 +63,12 @@ eiam-authentication-wechatwork ${project.version} + + + cn.topiam + eiam-authentication-captcha + ${project.version} + cn.topiam diff --git a/eiam-authentication/eiam-authentication-captcha/pom.xml b/eiam-authentication/eiam-authentication-captcha/pom.xml new file mode 100644 index 00000000..a0cf577e --- /dev/null +++ b/eiam-authentication/eiam-authentication-captcha/pom.xml @@ -0,0 +1,42 @@ + + + + + eiam-authentication + cn.topiam + 1.0.0-beta1 + ../pom.xml + + 4.0.0 + + eiam-authentication-captcha + jar + + + + cn.topiam + eiam-authentication-core + ${project.version} + + + \ No newline at end of file diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/CaptchaValidator.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/CaptchaValidator.java similarity index 90% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/CaptchaValidator.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/CaptchaValidator.java index 00a6da91..ddfb5f04 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/CaptchaValidator.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/CaptchaValidator.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha; +package cn.topiam.employee.authentication.captcha; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/NoneCaptchaProvider.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/NoneCaptchaProvider.java similarity index 90% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/NoneCaptchaProvider.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/NoneCaptchaProvider.java index c27812f1..e12e6ac9 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/NoneCaptchaProvider.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/NoneCaptchaProvider.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha; +package cn.topiam.employee.authentication.captcha; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/configurer/package-info.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/configurer/package-info.java new file mode 100644 index 00000000..d30603cf --- /dev/null +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/configurer/package-info.java @@ -0,0 +1,18 @@ +/* + * eiam-authentication-captcha - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.captcha.configurer; \ No newline at end of file diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/CaptchaValidatorFilter.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/filter/CaptchaValidatorFilter.java similarity index 95% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/CaptchaValidatorFilter.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/filter/CaptchaValidatorFilter.java index a3c548ff..3027927a 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/CaptchaValidatorFilter.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/filter/CaptchaValidatorFilter.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha; +package cn.topiam.employee.authentication.captcha.filter; import java.io.IOException; import java.util.Objects; @@ -38,6 +38,7 @@ import org.springframework.web.filter.OncePerRequestFilter; import com.alibaba.fastjson2.JSONObject; +import cn.topiam.employee.authentication.captcha.CaptchaValidator; import cn.topiam.employee.common.constants.AuthorizeConstants; import cn.topiam.employee.support.result.ApiRestResult; import cn.topiam.employee.support.trace.TraceUtils; diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/package-info.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/filter/package-info.java similarity index 84% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/package-info.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/filter/package-info.java index 7f596dcf..0800dc3b 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/package-info.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/filter/package-info.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha.geetest; \ No newline at end of file +package cn.topiam.employee.authentication.captcha.filter; \ No newline at end of file diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/GeeTestCaptchaProviderConfig.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/GeeTestCaptchaProviderConfig.java similarity index 91% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/GeeTestCaptchaProviderConfig.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/GeeTestCaptchaProviderConfig.java index 498f065f..276bede4 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/GeeTestCaptchaProviderConfig.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/GeeTestCaptchaProviderConfig.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha.geetest; +package cn.topiam.employee.authentication.captcha.geetest; import java.io.Serial; diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/GeeTestCaptchaValidator.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/GeeTestCaptchaValidator.java similarity index 90% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/GeeTestCaptchaValidator.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/GeeTestCaptchaValidator.java index 0664a3f2..93fec7d9 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/geetest/GeeTestCaptchaValidator.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/GeeTestCaptchaValidator.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha.geetest; +package cn.topiam.employee.authentication.captcha.geetest; import java.util.Map; @@ -33,8 +33,8 @@ import org.springframework.web.client.RestTemplate; import com.alibaba.fastjson2.JSONObject; +import cn.topiam.employee.authentication.captcha.CaptchaValidator; import cn.topiam.employee.common.util.RequestUtils; -import cn.topiam.employee.core.security.captcha.CaptchaValidator; /** * 极速验证 @@ -57,17 +57,17 @@ public class GeeTestCaptchaValidator implements CaptchaValidator { */ @Override public boolean validate(HttpServletRequest request, HttpServletResponse response) { - Map getParams = RequestUtils.getParams(request); + Map getParams = RequestUtils.getParams(request); // 1.初始化极验参数信息 String captchaId = config.getCaptchaId(); String captchaKey = config.getCaptchaKey(); String domain = "https://gcaptcha4.geetest.com"; // 2.获取用户验证后前端传过来的验证流水号等参数 - String lotNumber = getParams.get("lot_number"); - String captchaOutput = getParams.get("captcha_output"); - String passToken = getParams.get("pass_token"); - String genTime = getParams.get("gen_time"); + String lotNumber = (String) getParams.get("lot_number"); + String captchaOutput = (String) getParams.get("captcha_output"); + String passToken = (String) getParams.get("pass_token"); + String genTime = (String) getParams.get("gen_time"); // 3.生成签名 // 生成签名使用标准的hmac算法,使用用户当前完成验证的流水号lot_number作为原始消息message,使用客户验证私钥作为key diff --git a/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/package-info.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/package-info.java new file mode 100644 index 00000000..31ea649e --- /dev/null +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/geetest/package-info.java @@ -0,0 +1,18 @@ +/* + * eiam-authentication-captcha - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.captcha.geetest; \ No newline at end of file diff --git a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/package-info.java b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/package-info.java similarity index 85% rename from eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/package-info.java rename to eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/package-info.java index 1b66a0ad..5824acb8 100644 --- a/eiam-core/src/main/java/cn/topiam/employee/core/security/captcha/package-info.java +++ b/eiam-authentication/eiam-authentication-captcha/src/main/java/cn/topiam/employee/authentication/captcha/package-info.java @@ -1,5 +1,5 @@ /* - * eiam-core - Employee Identity and Access Management Program + * eiam-authentication-captcha - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.core.security.captcha; \ No newline at end of file +package cn.topiam.employee.authentication.sms; \ No newline at end of file diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderCategory.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderCategory.java similarity index 83% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderCategory.java rename to eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderCategory.java index 915487ab..e97a2ba9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderCategory.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderCategory.java @@ -1,5 +1,5 @@ /* - * eiam-common - Employee Identity and Access Management Program + * eiam-authentication-core - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,12 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums; +package cn.topiam.employee.authentication.common; import java.util.List; import com.google.common.collect.Lists; +import cn.topiam.employee.common.enums.AuthenticationType; +import cn.topiam.employee.common.enums.BaseEnum; import cn.topiam.employee.support.web.converter.EnumConvert; /** @@ -35,20 +37,17 @@ public enum IdentityProviderCategory implements BaseEnum { */ social("social", "社交", Lists.newArrayList( IdentityProviderType.QQ, - IdentityProviderType.WECHAT_SCAN_CODE, - IdentityProviderType.WEIBO, - IdentityProviderType.GITHUB, - IdentityProviderType.GOOGLE, - IdentityProviderType.ALIPAY)), + IdentityProviderType.WECHAT_QR)), /** * 企业 */ enterprise("enterprise", "企业", Lists .newArrayList( - IdentityProviderType.WECHATWORK_SCAN_CODE, - IdentityProviderType.DINGTALK_SCAN_CODE, + IdentityProviderType.WECHAT_WORK_QR, + IdentityProviderType.DINGTALK_QR, IdentityProviderType.DINGTALK_OAUTH, - IdentityProviderType.LDAP)); + IdentityProviderType.LDAP, + IdentityProviderType.FEISHU_OAUTH)); private final String code; @@ -62,10 +61,12 @@ public enum IdentityProviderCategory implements BaseEnum { this.providers = providers; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderCategoryConverter.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderCategoryConverter.java similarity index 92% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderCategoryConverter.java rename to eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderCategoryConverter.java index 813b1acc..dcfee952 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderCategoryConverter.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderCategoryConverter.java @@ -1,5 +1,5 @@ /* - * eiam-common - Employee Identity and Access Management Program + * eiam-authentication-core - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,15 +15,13 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.authentication.common; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderCategory; - /** * @author TopIAM * Created by support@topiam.cn on 2020/12/11 19:42 diff --git a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderService.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderService.java index 7c5ecda1..0efd2843 100644 --- a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderService.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderService.java @@ -23,7 +23,6 @@ import java.util.Map; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.authentication.common.config.IdentityProviderConfig; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * IdentityProviderService diff --git a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderType.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderType.java new file mode 100644 index 00000000..ba7f6c60 --- /dev/null +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/IdentityProviderType.java @@ -0,0 +1,109 @@ +/* + * eiam-authentication-core - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.common; + +import org.springframework.util.Assert; +import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; +import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; + +/** + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/31 15:18 + */ +public record IdentityProviderType(String value,String name,String desc){ +/** + * 飞书 + */ +public static final IdentityProviderType FEISHU_OAUTH=new IdentityProviderType("feishu_oauth","飞书认证","通过飞书进行身份验证"); +/** + * 钉钉 + */ +public static final IdentityProviderType DINGTALK_OAUTH=new IdentityProviderType("dingtalk_oauth","钉钉Oauth认证","通过钉钉进行身份认证"); +/** + * 钉钉扫码 + */ +public static final IdentityProviderType DINGTALK_QR=new IdentityProviderType("dingtalk_qr","钉钉扫码认证","通过钉钉扫码进行身份认证"); +/** + * 微信开放平台 + */ +public static final IdentityProviderType WECHAT_QR=new IdentityProviderType("wechat_qr","微信扫码登录","通过微信扫码进行身份认证"); +/** + * 企业微信 + */ +public static final IdentityProviderType WECHAT_WORK_QR=new IdentityProviderType("wechatwork_qr","企业微信扫码认证","通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"); + +/** + * QQ认证 + */ +public static final IdentityProviderType QQ=new IdentityProviderType("qq_oauth","QQ认证","通过QQ进行身份认证"); + +/** + * IDAP + */ +public static final IdentityProviderType LDAP=new IdentityProviderType("ldap","LDAP认证","通过 LDAP 进行身份验证"); + +/** + * 用户名密码 + */ +public static final IdentityProviderType USERNAME_PASSWORD=new IdentityProviderType("username_password","用户名密码认证","通过用户名密码进行身份认证"); + +/** + * 短信验证码 + */ +public static final IdentityProviderType SMS=new IdentityProviderType("sms","短信验证码认证","通过短信验证码进行身份认证"); + +/** + * Constructs an {@code IdentityProviderType} using the provided value. + * + * @param value the value of the authorization grant type + */ +public IdentityProviderType{Assert.hasText(value,"value cannot be empty");} + +/** + * Returns the value of the authorization grant type. + * + * @return the value of the authorization grant type + */ +@Override public String value(){return this.value;} + +@Override public boolean equals(Object obj){if(this==obj){return true;}if(obj==null||this.getClass()!=obj.getClass()){return false;}IdentityProviderType that=(IdentityProviderType)obj;return this.value().equals(that.value());} + +@Override public int hashCode(){return this.value().hashCode();} + + @Override + public String name() { + return name; + } + + @Override + public String desc() { + return desc; + } + + public String getLoginPathPrefix() { + return LOGIN_PATH + "/" + value(); + } + + public String getAuthorizationPathPrefix() { + return AUTHORIZATION_REQUEST_URI + "/" + value(); + } + + public static int size() { + return 9; + } +} diff --git a/eiam-protocol/eiam-protocol-oidc/src/main/java/cn/topiam/employee/protocol/oidc/handler/package-info.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/constant/AuthenticationConstants.java similarity index 68% rename from eiam-protocol/eiam-protocol-oidc/src/main/java/cn/topiam/employee/protocol/oidc/handler/package-info.java rename to eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/constant/AuthenticationConstants.java index cc7f6a92..091e42f7 100644 --- a/eiam-protocol/eiam-protocol-oidc/src/main/java/cn/topiam/employee/protocol/oidc/handler/package-info.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/constant/AuthenticationConstants.java @@ -1,5 +1,5 @@ /* - * eiam-protocol-oidc - Employee Identity and Access Management Program + * eiam-authentication-core - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,10 +15,18 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +package cn.topiam.employee.authentication.common.constant; + /** - * 处理器 + * 认证常量 * * @author TopIAM - * Created by support@topiam.cn on 2020/10/29 23:12 + * Created by support@topiam.cn on 2021/12/20 23:19 */ -package cn.topiam.employee.protocol.oidc.handler; +public final class AuthenticationConstants { + + /** + * 提供商ID + */ + public static final String PROVIDER_CODE = "providerId"; +} \ No newline at end of file diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/sms/SmsOtpProviderValidator.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/exception/IdentityProviderNotExistException.java similarity index 58% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/sms/SmsOtpProviderValidator.java rename to eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/exception/IdentityProviderNotExistException.java index 5f5ff2c9..7bc3565a 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/sms/SmsOtpProviderValidator.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/exception/IdentityProviderNotExistException.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-core - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,24 +15,20 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa.sms; +package cn.topiam.employee.authentication.common.exception; -import cn.topiam.employee.core.security.mfa.MfaProviderValidator; +import cn.topiam.employee.support.exception.TopIamException; +import static org.springframework.http.HttpStatus.BAD_REQUEST; /** - * OTP 提供商验证 + * 身份提供商不存在 * * @author TopIAM - * Created by support@topiam.cn on 2022/7/31 20:50 + * Created by support@topiam.cn on 2022/12/20 22:50 */ -public class SmsOtpProviderValidator implements MfaProviderValidator { - /** - * 验证 - * - * @param code {@link String} - */ - @Override - public boolean validate(String code) { - return true; +public class IdentityProviderNotExistException extends TopIamException { + + public IdentityProviderNotExistException() { + super("idp_not_exist", "身份提供商不存在", BAD_REQUEST); } } diff --git a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/filter/AbstractIdpAuthenticationProcessingFilter.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/filter/AbstractIdpAuthenticationProcessingFilter.java index 9dae4cf8..8d687075 100644 --- a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/filter/AbstractIdpAuthenticationProcessingFilter.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/filter/AbstractIdpAuthenticationProcessingFilter.java @@ -35,10 +35,11 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import com.alibaba.fastjson2.JSONObject; +import cn.topiam.employee.authentication.common.IdentityProviderType; +import cn.topiam.employee.authentication.common.exception.IdentityProviderNotExistException; import cn.topiam.employee.authentication.common.modal.IdpUser; import cn.topiam.employee.authentication.common.service.UserIdpService; import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; -import cn.topiam.employee.common.enums.IdentityProviderType; import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; import cn.topiam.employee.core.security.authentication.IdpAuthentication; import cn.topiam.employee.core.security.userdetails.UserDetails; @@ -65,14 +66,18 @@ public abstract class AbstractIdpAuthenticationProcessingFilter extends * @param request {@link HttpServletRequest} * @param response {@link HttpServletResponse} * @param provider {@link IdentityProviderType} - * @param providerId {@link String} + * @param providerCode {@link String} * @param info {@link JSONObject} * @return {@link Authentication} */ public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response, - IdentityProviderType provider, String providerId, + IdentityProviderType provider, String providerCode, IdpUser info) throws IOException { + IdentityProviderEntity identityProvider = identityProviderRepository + .findByCodeAndEnabledIsTrue(providerCode) + .orElseThrow(IdentityProviderNotExistException::new); + String providerId = String.valueOf(identityProvider.getId()); info.setProviderId(providerId); info.setProviderType(provider); //调用接口查询是否已绑定 @@ -81,7 +86,7 @@ public abstract class AbstractIdpAuthenticationProcessingFilter extends //是否自动绑定 if (!userIdpService.isAutoBindUserIdp(providerId)) { setUserBindSessionContent(request, info); - return new IdpAuthentication(provider.getCode(), providerId); + return new IdpAuthentication(provider.value(), providerId); } //调用接口进行绑定操作 info.setProviderId(providerId); @@ -136,16 +141,16 @@ public abstract class AbstractIdpAuthenticationProcessingFilter extends String providerId, HttpServletRequest request) { //认证 UserDetails userDetails = userIdpService.getUserDetails(openId, providerId); - IdpAuthentication token = new IdpAuthentication(userDetails, provider.getCode(), providerId, + IdpAuthentication token = new IdpAuthentication(userDetails, provider.value(), providerId, true, userDetails.getAuthorities()); // Allow subclasses to set the "details" property token.setDetails(this.authenticationDetailsSource.buildDetails(request)); return token; } - public IdentityProviderEntity getIdentityProviderEntity(String providerId) { + public IdentityProviderEntity getIdentityProviderEntity(String code) { Optional optional = getIdentityProviderRepository() - .findByIdAndEnabledIsTrue(Long.valueOf(providerId)); + .findByCodeAndEnabledIsTrue(code); if (optional.isEmpty()) { //无效身份提供商 OAuth2Error oauth2Error = new OAuth2Error(INVALID_IDP); diff --git a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/modal/IdpUser.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/modal/IdpUser.java index 99f0a993..ec26d132 100644 --- a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/modal/IdpUser.java +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/modal/IdpUser.java @@ -19,7 +19,7 @@ package cn.topiam.employee.authentication.common.modal; import java.util.Map; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.authentication.common.IdentityProviderType; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/util/AuthenticationUtils.java b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/util/AuthenticationUtils.java new file mode 100644 index 00000000..709f6ebc --- /dev/null +++ b/eiam-authentication/eiam-authentication-core/src/main/java/cn/topiam/employee/authentication/common/util/AuthenticationUtils.java @@ -0,0 +1,60 @@ +/* + * eiam-authentication-core - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.common.util; + +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; + +import cn.topiam.employee.core.security.authentication.IdpAuthentication; +import cn.topiam.employee.core.security.authentication.SmsAuthentication; +import cn.topiam.employee.core.security.mfa.MfaAuthentication; +import static cn.topiam.employee.authentication.common.IdentityProviderType.SMS; +import static cn.topiam.employee.authentication.common.IdentityProviderType.USERNAME_PASSWORD; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/31 14:29 + */ +public class AuthenticationUtils { + /** + * 获取认证类型 + * + * @param authentication {@link Authentication} + * @return {@link String} + */ + public static String geAuthType(Authentication authentication) { + //用户名密码 + if (authentication instanceof UsernamePasswordAuthenticationToken) { + return USERNAME_PASSWORD.value(); + } + //身份提供商 + if (authentication instanceof IdpAuthentication) { + return ((IdpAuthentication) authentication).getProviderType(); + } + //短信登录 + if (authentication instanceof SmsAuthentication) { + return SMS.value(); + } + //MFA + if (authentication instanceof MfaAuthentication) { + return geAuthType(((MfaAuthentication) authentication).getFirst()); + } + throw new IllegalArgumentException("未知认证对象"); + } +} diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java index 055f527f..a8a3ccf4 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOAuth2AuthorizationRequestRedirectFilter.java @@ -51,9 +51,10 @@ import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; import static org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames.RESPONSE_TYPE; +import static cn.topiam.employee.authentication.common.IdentityProviderType.DINGTALK_OAUTH; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthenticationConstants.URL_AUTHORIZE; import static cn.topiam.employee.authentication.dingtalk.filter.DingtalkOauthAuthenticationFilter.getLoginUrl; -import static cn.topiam.employee.common.enums.IdentityProviderType.DINGTALK_OAUTH; /** * 微信扫码登录请求重定向过滤器 @@ -67,16 +68,11 @@ public class DingtalkOAuth2AuthorizationRequestRedirectFilter extends OncePerReq private final Logger logger = LoggerFactory .getLogger(DingtalkOAuth2AuthorizationRequestRedirectFilter.class); - /** - * 提供商ID - */ - public static final String PROVIDER_ID = "providerId"; - /** * AntPathRequestMatcher */ public static final AntPathRequestMatcher DINGTALK_OAUTH2_REQUEST_MATCHER = new AntPathRequestMatcher( - DINGTALK_OAUTH.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_ID + "}", + DINGTALK_OAUTH.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** @@ -108,9 +104,9 @@ public class DingtalkOAuth2AuthorizationRequestRedirectFilter extends OncePerReq return; } Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerCode = variables.get(PROVIDER_CODE); Optional optional = identityProviderRepository - .findByIdAndEnabledIsTrue(Long.valueOf(providerId)); + .findByCodeAndEnabledIsTrue(providerCode); if (optional.isEmpty()) { throw new NullPointerException("未查询到身份提供商信息"); } @@ -121,7 +117,8 @@ public class DingtalkOAuth2AuthorizationRequestRedirectFilter extends OncePerReq //构建授权请求 OAuth2AuthorizationRequest.Builder builder = OAuth2AuthorizationRequest.authorizationCode() .clientId(config.getAppKey()).authorizationUri(URL_AUTHORIZE) - .redirectUri(getLoginUrl(providerId)).state(DEFAULT_STATE_GENERATOR.generateKey()); + .redirectUri(getLoginUrl(optional.get().getCode())) + .state(DEFAULT_STATE_GENERATOR.generateKey()); builder.parameters(parameters -> { parameters.put(RESPONSE_TYPE, OAuth2ParameterNames.CODE); parameters.put("prompt", "consent"); diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java index ca09ed18..2ccb014e 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkOauthAuthenticationFilter.java @@ -59,8 +59,9 @@ import cn.topiam.employee.core.context.ServerContextHelp; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.trace.TraceUtils; import cn.topiam.employee.support.util.HttpUrlUtils; -import static cn.topiam.employee.authentication.dingtalk.filter.DingtalkScanCodeAuthorizationRequestGetFilter.PROVIDER_ID; -import static cn.topiam.employee.common.enums.IdentityProviderType.DINGTALK_OAUTH; +import static cn.topiam.employee.authentication.common.IdentityProviderType.DINGTALK_OAUTH; +import static cn.topiam.employee.authentication.common.IdentityProviderType.DINGTALK_QR; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; /** * 钉钉认证过滤器 @@ -72,13 +73,14 @@ import static cn.topiam.employee.common.enums.IdentityProviderType.DINGTALK_OAUT */ @SuppressWarnings("DuplicatedCode") public class DingtalkOauthAuthenticationFilter extends AbstractIdpAuthenticationProcessingFilter { - public final static String DEFAULT_FILTER_PROCESSES_URI = DINGTALK_OAUTH + public final static String DEFAULT_FILTER_PROCESSES_URI = DINGTALK_QR .getLoginPathPrefix() + "/*"; /** * AntPathRequestMatcher */ public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( - DINGTALK_OAUTH.getLoginPathPrefix() + "/" + "{" + PROVIDER_ID + "}", HttpMethod.GET.name()); + DINGTALK_OAUTH.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", + HttpMethod.GET.name()); /** * Creates a new instance @@ -108,7 +110,7 @@ public class DingtalkOauthAuthenticationFilter extends AbstractIdpAuthentication TraceUtils.put(UUID.randomUUID().toString()); RequestMatcher.MatchResult matcher = REQUEST_MATCHER.matcher(request); Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerId = variables.get(PROVIDER_CODE); //code 钉钉新版登录为 authCode String code = request.getParameter(AUTH_CODE); if (StringUtils.isEmpty(code)) { @@ -154,7 +156,7 @@ public class DingtalkOauthAuthenticationFilter extends AbstractIdpAuthentication } //执行逻辑 IdpUser idpUser = IdpUser.builder().openId(user.getBody().getOpenId()).build(); - return attemptAuthentication(request, response, DINGTALK_OAUTH, providerId, idpUser); + return attemptAuthentication(request, response, DINGTALK_QR, providerId, idpUser); } /** @@ -199,8 +201,8 @@ public class DingtalkOauthAuthenticationFilter extends AbstractIdpAuthentication private Cache cache; public static String getLoginUrl(String providerId) { - String url = ServerContextHelp.getPortalPublicBaseUrl() - + DINGTALK_OAUTH.getLoginPathPrefix() + "/" + providerId; + String url = ServerContextHelp.getPortalPublicBaseUrl() + DINGTALK_QR.getLoginPathPrefix() + + "/" + providerId; return HttpUrlUtils.format(url); } diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthenticationFilter.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthenticationFilter.java index 13d39e1b..a949aaa0 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthenticationFilter.java @@ -59,15 +59,14 @@ import cn.topiam.employee.authentication.common.modal.IdpUser; import cn.topiam.employee.authentication.common.service.UserIdpService; import cn.topiam.employee.authentication.dingtalk.DingTalkIdpScanCodeConfig; import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; -import cn.topiam.employee.common.enums.IdentityProviderType; import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; import cn.topiam.employee.core.context.ServerContextHelp; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.trace.TraceUtils; import cn.topiam.employee.support.util.HttpUrlUtils; +import static cn.topiam.employee.authentication.common.IdentityProviderType.DINGTALK_QR; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthenticationConstants.*; -import static cn.topiam.employee.authentication.dingtalk.filter.DingtalkScanCodeAuthorizationRequestGetFilter.PROVIDER_ID; -import static cn.topiam.employee.common.enums.IdentityProviderType.DINGTALK_SCAN_CODE; /** * 钉钉认证过滤器 @@ -80,14 +79,13 @@ import static cn.topiam.employee.common.enums.IdentityProviderType.DINGTALK_SCAN @SuppressWarnings("DuplicatedCode") public class DingtalkScanCodeAuthenticationFilter extends AbstractIdpAuthenticationProcessingFilter { - public final static String DEFAULT_FILTER_PROCESSES_URI = DINGTALK_SCAN_CODE + public final static String DEFAULT_FILTER_PROCESSES_URI = DINGTALK_QR .getLoginPathPrefix() + "/*"; /** * AntPathRequestMatcher */ public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( - DINGTALK_SCAN_CODE.getLoginPathPrefix() + "/" + "{" + PROVIDER_ID + "}", - HttpMethod.GET.name()); + DINGTALK_QR.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** * Creates a new instance @@ -117,7 +115,7 @@ public class DingtalkScanCodeAuthenticationFilter extends TraceUtils.put(UUID.randomUUID().toString()); RequestMatcher.MatchResult matcher = REQUEST_MATCHER.matcher(request); Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerId = variables.get(PROVIDER_CODE); //code String code = request.getParameter(OAuth2ParameterNames.CODE); if (StringUtils.isEmpty(code)) { @@ -195,8 +193,7 @@ public class DingtalkScanCodeAuthenticationFilter extends //4、执行逻辑 OapiV2UserGetResponse.UserGetResponse result = rspGetResponse.getResult(); IdpUser idpUser = IdpUser.builder().openId(result.getUserid()).build(); - return attemptAuthentication(request, response, IdentityProviderType.DINGTALK_SCAN_CODE, - providerId, idpUser); + return attemptAuthentication(request, response, DINGTALK_QR, providerId, idpUser); } /** @@ -234,8 +231,8 @@ public class DingtalkScanCodeAuthenticationFilter extends private Cache cache; public static String getLoginUrl(String providerId) { - String url = ServerContextHelp.getPortalPublicBaseUrl() - + DINGTALK_SCAN_CODE.getLoginPathPrefix() + "/" + providerId; + String url = ServerContextHelp.getPortalPublicBaseUrl() + DINGTALK_QR.getLoginPathPrefix() + + "/" + providerId; return HttpUrlUtils.format(url); } diff --git a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthorizationRequestGetFilter.java b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthorizationRequestGetFilter.java index 799b6638..581440d3 100644 --- a/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthorizationRequestGetFilter.java +++ b/eiam-authentication/eiam-authentication-dingtalk/src/main/java/cn/topiam/employee/authentication/dingtalk/filter/DingtalkScanCodeAuthorizationRequestGetFilter.java @@ -55,10 +55,11 @@ import cn.topiam.employee.support.util.HttpResponseUtils; import static org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames.CODE; import static org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames.RESPONSE_TYPE; +import static cn.topiam.employee.authentication.common.IdentityProviderType.DINGTALK_QR; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthenticationConstants.APP_ID; import static cn.topiam.employee.authentication.dingtalk.constant.DingTalkAuthenticationConstants.SCAN_CODE_URL_AUTHORIZE; import static cn.topiam.employee.authentication.dingtalk.filter.DingtalkScanCodeAuthenticationFilter.getLoginUrl; -import static cn.topiam.employee.common.enums.IdentityProviderType.DINGTALK_SCAN_CODE; /** * 微信扫码登录请求重定向过滤器 @@ -72,16 +73,11 @@ public class DingtalkScanCodeAuthorizationRequestGetFilter extends OncePerReques private final Logger logger = LoggerFactory .getLogger(DingtalkScanCodeAuthorizationRequestGetFilter.class); - /** - * 提供商ID - */ - public static final String PROVIDER_ID = "providerId"; - /** * AntPathRequestMatcher */ public static final AntPathRequestMatcher DINGTALK_SCAN_CODE_REQUEST_MATCHER = new AntPathRequestMatcher( - DINGTALK_SCAN_CODE.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_ID + "}", + DINGTALK_QR.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** @@ -109,9 +105,9 @@ public class DingtalkScanCodeAuthorizationRequestGetFilter extends OncePerReques } Map variables = matcher.getVariables(); //校验身份提供商 - String providerId = variables.get(PROVIDER_ID); + String providerCode = variables.get(PROVIDER_CODE); Optional optional = identityProviderRepository - .findByIdAndEnabledIsTrue(Long.valueOf(providerId)); + .findByCodeAndEnabledIsTrue(providerCode); if (optional.isEmpty()) { logger.error("身份提供商不存在"); throw new NullPointerException("身份提供商不存在"); @@ -131,7 +127,7 @@ public class DingtalkScanCodeAuthorizationRequestGetFilter extends OncePerReques .clientId(config.getAppKey()) .scopes(Sets.newHashSet("snsapi_login")) .authorizationUri(SCAN_CODE_URL_AUTHORIZE) - .redirectUri(getLoginUrl(providerId)) + .redirectUri(getLoginUrl(optional.get().getCode())) .state(DEFAULT_STATE_GENERATOR.generateKey()) .attributes(attributes); builder.parameters(parameters -> { diff --git a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/FeiShuIdpScanCodeConfig.java b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/FeiShuIdpScanCodeConfig.java new file mode 100644 index 00000000..d7a3ff51 --- /dev/null +++ b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/FeiShuIdpScanCodeConfig.java @@ -0,0 +1,52 @@ +/* + * eiam-authentication-feishu - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.feishu; + +import java.io.Serial; + +import javax.validation.constraints.NotBlank; + +import cn.topiam.employee.authentication.common.config.IdentityProviderConfig; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 飞书扫码 认证配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/19 22:58 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class FeiShuIdpScanCodeConfig extends IdentityProviderConfig { + @Serial + private static final long serialVersionUID = -6850223527422243076L; + + /** + * APP ID + */ + @NotBlank(message = "APP ID 不能为空") + private String appId; + + /** + * APP Secret + */ + @NotBlank(message = "APP Secret 不能为空") + private String appSecret; +} diff --git a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/configurer/FeiShuScanCodeAuthenticationConfigurer.java b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/configurer/FeiShuScanCodeAuthenticationConfigurer.java new file mode 100644 index 00000000..fd9ecf4c --- /dev/null +++ b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/configurer/FeiShuScanCodeAuthenticationConfigurer.java @@ -0,0 +1,91 @@ +/* + * eiam-authentication-feishu - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.feishu.configurer; + +import org.springframework.security.config.annotation.web.HttpSecurityBuilder; +import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer; +import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter; +import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.OrRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.util.Assert; + +import cn.topiam.employee.authentication.common.service.UserIdpService; +import cn.topiam.employee.authentication.feishu.filter.FeiShuAuthorizationRequestGetFilter; +import cn.topiam.employee.authentication.feishu.filter.FeiShuLoginAuthenticationFilter; +import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; + +/** + * 认证配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2021/12/19 23:58 + */ +public final class FeiShuScanCodeAuthenticationConfigurer> extends + AbstractAuthenticationFilterConfigurer, FeiShuLoginAuthenticationFilter> { + + private final IdentityProviderRepository identityProviderRepository; + private final UserIdpService userIdpService; + + public FeiShuScanCodeAuthenticationConfigurer(IdentityProviderRepository identityProviderRepository, + UserIdpService userIdpService) { + Assert.notNull(identityProviderRepository, "identityProviderRepository must not be null"); + Assert.notNull(userIdpService, "userIdpService must not be null"); + this.identityProviderRepository = identityProviderRepository; + this.userIdpService = userIdpService; + } + + /** + * Create the {@link RequestMatcher} given a loginProcessingUrl + * + * @param loginProcessingUrl creates the {@link RequestMatcher} based upon the + * loginProcessingUrl + * @return the {@link RequestMatcher} to use based upon the loginProcessingUrl + */ + @Override + protected RequestMatcher createLoginProcessingUrlMatcher(String loginProcessingUrl) { + return new AntPathRequestMatcher(loginProcessingUrl); + } + + @Override + public void init(H http) throws Exception { + //微信扫码登录认证 + FeiShuLoginAuthenticationFilter loginAuthenticationFilter = new FeiShuLoginAuthenticationFilter( + identityProviderRepository, userIdpService); + this.setAuthenticationFilter(loginAuthenticationFilter); + //处理URL + super.loginProcessingUrl(FeiShuLoginAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI); + super.init(http); + } + + @Override + public void configure(H http) throws Exception { + //微信扫码请求重定向 + FeiShuAuthorizationRequestGetFilter requestRedirectFilter = new FeiShuAuthorizationRequestGetFilter( + identityProviderRepository); + http.addFilterBefore(requestRedirectFilter, OAuth2AuthorizationRequestRedirectFilter.class); + http.addFilterBefore(this.getAuthenticationFilter(), OAuth2LoginAuthenticationFilter.class); + super.configure(http); + } + + public RequestMatcher getRequestMatcher() { + return new OrRequestMatcher(FeiShuAuthorizationRequestGetFilter.getRequestMatcher(), + FeiShuLoginAuthenticationFilter.getRequestMatcher()); + } +} diff --git a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/constant/FeiShuAuthenticationConstants.java b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/constant/FeiShuAuthenticationConstants.java new file mode 100644 index 00000000..532424a3 --- /dev/null +++ b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/constant/FeiShuAuthenticationConstants.java @@ -0,0 +1,39 @@ +/* + * eiam-authentication-feishu - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.feishu.constant; + +/** + * 飞书认证常量 + * + * @author TopIAM + * Created by support@topiam.cn on 2021/12/19 23:19 + */ +public final class FeiShuAuthenticationConstants { + + public static final String AUTHORIZATION_REQUEST = "https://passport.feishu.cn/suite/passport/oauth/authorize"; + public static final String ACCESS_TOKEN = "https://passport.feishu.cn/suite/passport/oauth/token"; + public static final String USER_INFO = "https://passport.feishu.cn/suite/passport/oauth/userinfo"; + + public static final String CLIENT_ID = "client_id"; + public static final String CLIENT_SECRET = "client_secret"; + public static final String OPEN_ID = "open_id"; + + public static final String CODE = "code"; + public static final String HREF = "href"; + +} \ No newline at end of file diff --git a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuAuthenticationFilter.java b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuAuthenticationFilter.java deleted file mode 100644 index 5fe2fcf3..00000000 --- a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuAuthenticationFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * eiam-authentication-feishu - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.authentication.feishu.filter; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.core.Authentication; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; -import org.springframework.security.web.util.matcher.RequestMatcher; - -/** - * 飞书认证过滤器 - * https://open.feishu.cn/document/common-capabilities/sso/web-application-sso/qr-sdk-documentation - * - * @author TopIAM - * Created by support@topiam.cn on 2021/12/8 21:11 - */ -public class FeiShuAuthenticationFilter extends AbstractAuthenticationProcessingFilter { - - /** - * Creates a new instance - * - * @param requiresAuthenticationRequestMatcher the {@link RequestMatcher} used to - * determine if authentication is required. Cannot be null. - */ - protected FeiShuAuthenticationFilter(RequestMatcher requiresAuthenticationRequestMatcher) { - super(requiresAuthenticationRequestMatcher); - } - - /** - * qq认证 - * - * @param request {@link HttpServletRequest} - * @param response {@link HttpServletRequest} - * @return {@link HttpServletRequest} - * @throws AuthenticationException AuthenticationException - * @throws IOException IOException - * @throws ServletException ServletException - */ - @Override - public Authentication attemptAuthentication(HttpServletRequest request, - HttpServletResponse response) throws AuthenticationException, - IOException, - ServletException { - //@formatter:off - - //@formatter:on - return null; - } -} diff --git a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuAuthorizationRequestGetFilter.java b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuAuthorizationRequestGetFilter.java new file mode 100644 index 00000000..52869b93 --- /dev/null +++ b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuAuthorizationRequestGetFilter.java @@ -0,0 +1,163 @@ +/* + * eiam-authentication-feishu - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.feishu.filter; + +import java.io.IOException; +import java.util.*; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.checkerframework.checker.nullness.qual.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpMethod; +import org.springframework.lang.NonNull; +import org.springframework.security.crypto.keygen.Base64StringKeyGenerator; +import org.springframework.security.crypto.keygen.StringKeyGenerator; +import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository; +import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository; +import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; +import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; +import org.springframework.security.web.DefaultRedirectStrategy; +import org.springframework.security.web.RedirectStrategy; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.util.Assert; +import org.springframework.web.filter.OncePerRequestFilter; + +import com.alibaba.fastjson2.JSONObject; +import com.google.common.collect.Maps; + +import cn.topiam.employee.authentication.feishu.FeiShuIdpScanCodeConfig; +import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; +import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; +import static org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames.RESPONSE_TYPE; + +import static cn.topiam.employee.authentication.common.IdentityProviderType.FEISHU_OAUTH; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; +import static cn.topiam.employee.authentication.feishu.constant.FeiShuAuthenticationConstants.*; +import static cn.topiam.employee.authentication.feishu.filter.FeiShuLoginAuthenticationFilter.getLoginUrl; + +/** + * 飞书认证过滤器 + * + * https://open.feishu.cn/document/common-capabilities/sso/web-application-sso/qr-sdk-documentation + * + * @author TopIAM + * Created by support@topiam.cn on 2021/12/8 21:11 + */ +public class FeiShuAuthorizationRequestGetFilter extends OncePerRequestFilter { + + private final Logger logger = LoggerFactory + .getLogger(FeiShuAuthorizationRequestGetFilter.class); + + /** + * AntPathRequestMatcher + */ + public static final AntPathRequestMatcher FEI_SHU_SCAN_CODE_REQUEST_MATCHER = new AntPathRequestMatcher( + FEISHU_OAUTH.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", + HttpMethod.GET.name()); + + /** + * 认证请求存储库 + */ + private final AuthorizationRequestRepository authorizationRequestRepository = new HttpSessionOAuth2AuthorizationRequestRepository(); + + private static final StringKeyGenerator DEFAULT_STATE_GENERATOR = new Base64StringKeyGenerator( + Base64.getUrlEncoder()); + private final IdentityProviderRepository identityProviderRepository; + + public FeiShuAuthorizationRequestGetFilter(IdentityProviderRepository identityProviderRepository) { + this.identityProviderRepository = identityProviderRepository; + } + + @Override + protected void doFilterInternal(@NonNull HttpServletRequest request, + @NonNull HttpServletResponse response, + @NonNull FilterChain filterChain) throws IOException, + ServletException { + RequestMatcher.MatchResult matcher = FEI_SHU_SCAN_CODE_REQUEST_MATCHER.matcher(request); + if (!matcher.isMatch()) { + filterChain.doFilter(request, response); + return; + } + Map variables = matcher.getVariables(); + String providerCode = variables.get(PROVIDER_CODE); + Optional optional = identityProviderRepository + .findByCodeAndEnabledIsTrue(providerCode); + if (optional.isEmpty()) { + throw new NullPointerException("未查询到身份提供商信息"); + } + IdentityProviderEntity entity = optional.get(); + FeiShuIdpScanCodeConfig config = JSONObject.parseObject(entity.getConfig(), + FeiShuIdpScanCodeConfig.class); + Assert.notNull(config, "飞书扫码登录配置不能为空"); + //构建授权请求 + //@formatter:off + HashMap<@Nullable String, @Nullable Object> attributes = Maps.newHashMap(); + attributes.put(RESPONSE_TYPE, CODE); + OAuth2AuthorizationRequest.Builder builder = OAuth2AuthorizationRequest.authorizationCode() + .clientId(config.getAppId()) + .authorizationUri(AUTHORIZATION_REQUEST) + .redirectUri(getLoginUrl(optional.get().getCode())) + .state(DEFAULT_STATE_GENERATOR.generateKey()) + .attributes(attributes); + //@formatter:on + builder.parameters(parameters -> { + HashMap linkedParameters = new LinkedHashMap<>(); + parameters.forEach((key, value) -> { + if (OAuth2ParameterNames.CLIENT_ID.equals(key)) { + linkedParameters.put(CLIENT_ID, value); + } + if (OAuth2ParameterNames.STATE.equals(key)) { + linkedParameters.put(OAuth2ParameterNames.STATE, value); + } + if (OAuth2ParameterNames.REDIRECT_URI.equals(key)) { + linkedParameters.put(OAuth2ParameterNames.REDIRECT_URI, value); + } + if (RESPONSE_TYPE.equals(key)) { + linkedParameters.put(RESPONSE_TYPE, value); + } + }); + parameters.clear(); + parameters.putAll(linkedParameters); + }); + this.sendRedirectForAuthorization(request, response, builder.build()); + } + + private void sendRedirectForAuthorization(HttpServletRequest request, + HttpServletResponse response, + OAuth2AuthorizationRequest authorizationRequest) throws IOException { + this.authorizationRequestRepository.saveAuthorizationRequest(authorizationRequest, request, + response); + this.authorizationRedirectStrategy.sendRedirect(request, response, + authorizationRequest.getAuthorizationRequestUri()); + } + + /** + * 重定向策略 + */ + private final RedirectStrategy authorizationRedirectStrategy = new DefaultRedirectStrategy(); + + public static RequestMatcher getRequestMatcher() { + return FEI_SHU_SCAN_CODE_REQUEST_MATCHER; + } +} diff --git a/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuLoginAuthenticationFilter.java b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuLoginAuthenticationFilter.java new file mode 100644 index 00000000..de02dcfe --- /dev/null +++ b/eiam-authentication/eiam-authentication-feishu/src/main/java/cn/topiam/employee/authentication/feishu/filter/FeiShuLoginAuthenticationFilter.java @@ -0,0 +1,152 @@ +/* + * eiam-authentication-feishu - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.feishu.filter; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.apache.http.message.BasicHeader; +import org.springframework.http.HttpMethod; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.security.oauth2.core.OAuth2AuthenticationException; +import org.springframework.security.oauth2.core.OAuth2Error; +import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; +import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.nimbusds.oauth2.sdk.GrantType; + +import cn.topiam.employee.authentication.common.filter.AbstractIdpAuthenticationProcessingFilter; +import cn.topiam.employee.authentication.common.modal.IdpUser; +import cn.topiam.employee.authentication.common.service.UserIdpService; +import cn.topiam.employee.authentication.feishu.FeiShuIdpScanCodeConfig; +import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; +import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; +import cn.topiam.employee.core.context.ServerContextHelp; +import cn.topiam.employee.support.util.HttpClientUtils; +import static cn.topiam.employee.authentication.common.IdentityProviderType.FEISHU_OAUTH; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; +import static cn.topiam.employee.authentication.feishu.constant.FeiShuAuthenticationConstants.*; + +/** + * 飞书扫码登录过滤器 + * + * @author TopIAM + * Created by support@topiam.cn on 2021/12/8 21:11 + */ +public class FeiShuLoginAuthenticationFilter extends AbstractIdpAuthenticationProcessingFilter { + + public final static String DEFAULT_FILTER_PROCESSES_URI = FEISHU_OAUTH + .getLoginPathPrefix() + "/*"; + public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( + FEISHU_OAUTH.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); + + /** + * Creates a new instance + * + * @param identityProviderRepository the {@link IdentityProviderRepository} + * @param authenticationUserDetails {@link UserIdpService} + */ + public FeiShuLoginAuthenticationFilter(IdentityProviderRepository identityProviderRepository, + UserIdpService authenticationUserDetails) { + super(DEFAULT_FILTER_PROCESSES_URI, authenticationUserDetails, identityProviderRepository); + } + + /** + * 飞书认证 + * + * @param request {@link HttpServletRequest} + * @param response {@link HttpServletRequest} + * @return {@link HttpServletRequest} + * @throws AuthenticationException {@link AuthenticationException} AuthenticationException + */ + @Override + public Authentication attemptAuthentication(HttpServletRequest request, + HttpServletResponse response) throws AuthenticationException, + IOException { + OAuth2AuthorizationRequest authorizationRequest = getOAuth2AuthorizationRequest(request, + response); + RequestMatcher.MatchResult matcher = REQUEST_MATCHER.matcher(request); + Map variables = matcher.getVariables(); + String providerCode = variables.get(PROVIDER_CODE); + //code + String code = request.getParameter(OAuth2ParameterNames.CODE); + if (StringUtils.isEmpty(code)) { + OAuth2Error oauth2Error = new OAuth2Error(INVALID_CODE_PARAMETER_ERROR_CODE); + throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString()); + } + // state + String state = request.getParameter(OAuth2ParameterNames.STATE); + if (StringUtils.isEmpty(state)) { + OAuth2Error oauth2Error = new OAuth2Error(INVALID_STATE_PARAMETER_ERROR_CODE); + throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString()); + } + if (!authorizationRequest.getState().equals(state)) { + OAuth2Error oauth2Error = new OAuth2Error(INVALID_STATE_PARAMETER_ERROR_CODE); + throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString()); + } + //获取身份提供商 + IdentityProviderEntity provider = getIdentityProviderEntity(providerCode); + FeiShuIdpScanCodeConfig config = JSONObject.parseObject(provider.getConfig(), + FeiShuIdpScanCodeConfig.class); + if (Objects.isNull(config)) { + logger.error("未查询到飞书扫码登录配置"); + //无效身份提供商 + OAuth2Error oauth2Error = new OAuth2Error( + AbstractIdpAuthenticationProcessingFilter.INVALID_IDP_CONFIG); + throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString()); + } + //获取access token + HashMap param = new HashMap<>(16); + param.put(CLIENT_ID, config.getAppId()); + param.put(CLIENT_SECRET, config.getAppSecret()); + param.put(OAuth2ParameterNames.CODE, code); + param.put(OAuth2ParameterNames.REDIRECT_URI, getLoginUrl(provider.getCode())); + param.put(OAuth2ParameterNames.GRANT_TYPE, GrantType.AUTHORIZATION_CODE.getValue()); + JSONObject result = JSON.parseObject(HttpClientUtils.post(ACCESS_TOKEN, param)); + // 获取user信息 + param = new HashMap<>(16); + BasicHeader authorization = new BasicHeader( + "Authorization", result.getString(OAuth2ParameterNames.TOKEN_TYPE) + " " + + result.getString(OAuth2ParameterNames.ACCESS_TOKEN)); + result = JSON.parseObject(HttpClientUtils.get(USER_INFO, param, authorization)); + // 返回 + IdpUser idpUser = IdpUser.builder().openId(result.getString(OPEN_ID)).build(); + return attemptAuthentication(request, response, FEISHU_OAUTH, providerCode, idpUser); + } + + public static String getLoginUrl(String providerId) { + String url = ServerContextHelp.getPortalPublicBaseUrl() + FEISHU_OAUTH.getLoginPathPrefix() + + "/" + providerId; + return url.replaceAll("(?. */ -package cn.topiam.employee.portal.mfa; +package cn.topiam.employee.authentication.mfa; import org.springframework.security.config.annotation.web.HttpSecurityBuilder; import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.util.Assert; -import cn.topiam.employee.portal.handler.PortalAuthenticationHandler; +import cn.topiam.employee.core.security.otp.OtpContextHelp; /** * Mfa Authentication Configurer @@ -34,7 +37,19 @@ import cn.topiam.employee.portal.handler.PortalAuthenticationHandler; public final class MfaAuthenticationConfigurer> extends AbstractAuthenticationFilterConfigurer, MfaAuthenticationFilter> { - public MfaAuthenticationConfigurer() { + private final OtpContextHelp otpContextHelp; + private final MfaAuthenticationHandler mfaAuthenticationHandler; + + public MfaAuthenticationConfigurer(OtpContextHelp otpContextHelp, + AuthenticationSuccessHandler successHandler, + AuthenticationFailureHandler authenticationFailureHandler) { + Assert.notNull(otpContextHelp, "otpContextHelp must not be null"); + Assert.notNull(successHandler, "successHandler must not be null"); + Assert.notNull(authenticationFailureHandler, + "authenticationFailureHandler must not be null"); + this.otpContextHelp = otpContextHelp; + mfaAuthenticationHandler = new MfaAuthenticationHandler(successHandler, + authenticationFailureHandler); } /** @@ -52,8 +67,8 @@ public final class MfaAuthenticationConfigurer> @Override public void init(H http) throws Exception { //设置登录成功失败处理器 - super.successHandler(new PortalAuthenticationHandler()); - super.failureHandler(new PortalAuthenticationHandler()); + super.successHandler(mfaAuthenticationHandler); + super.failureHandler(mfaAuthenticationHandler); //MFA认证 MfaAuthenticationFilter loginAuthenticationFilter = new MfaAuthenticationFilter(); this.setAuthenticationFilter(loginAuthenticationFilter); @@ -64,12 +79,20 @@ public final class MfaAuthenticationConfigurer> @Override public void configure(H http) throws Exception { - http.addFilterAfter(this.getAuthenticationFilter(), + //Mfa认证方式 + http.addFilterBefore(new MfaAuthenticationMfaFactorsFilter(), UsernamePasswordAuthenticationFilter.class); + //Mfa认证方式 + http.addFilterAfter(new MfaAuthenticationSendOtpFilter(otpContextHelp), + MfaAuthenticationMfaFactorsFilter.class); + //Mfa认证 + http.addFilterAfter(this.getAuthenticationFilter(), + MfaAuthenticationMfaFactorsFilter.class); super.configure(http); } - public RequestMatcher getRequestMatcher() { + public static RequestMatcher getRequestMatcher() { return MfaAuthenticationFilter.getRequestMatcher(); } + } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/MfaAuthenticationFilter.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationFilter.java similarity index 82% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/MfaAuthenticationFilter.java rename to eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationFilter.java index 8ef9adcd..9d1a4d67 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/MfaAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationFilter.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-mfa - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,12 +15,10 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa; +package cn.topiam.employee.authentication.mfa; -import java.io.IOException; import java.util.Objects; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -35,16 +33,15 @@ import org.springframework.security.web.authentication.AbstractAuthenticationPro import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; +import cn.topiam.employee.authentication.mfa.email.EmailOtpProviderValidator; +import cn.topiam.employee.authentication.mfa.sms.SmsOtpProviderValidator; +import cn.topiam.employee.authentication.mfa.totp.TotpProviderValidator; import cn.topiam.employee.common.entity.account.UserEntity; -import cn.topiam.employee.common.enums.MessageNoticeChannel; import cn.topiam.employee.common.enums.MfaFactor; import cn.topiam.employee.core.security.mfa.MfaAuthentication; import cn.topiam.employee.core.security.mfa.exception.MfaRequiredException; -import cn.topiam.employee.core.security.otp.OtpContextHelp; import cn.topiam.employee.core.security.util.UserUtils; -import cn.topiam.employee.portal.mfa.totp.TotpProviderValidator; -import cn.topiam.employee.support.context.ApplicationContextHelp; -import static cn.topiam.employee.common.constants.AuthorizeConstants.MFA_VALIDATE; +import static cn.topiam.employee.authentication.mfa.constant.MfaAuthenticationConstants.MFA_VALIDATE; import static cn.topiam.employee.common.enums.MfaFactor.SMS_OTP; /** @@ -69,7 +66,7 @@ public class MfaAuthenticationFilter extends AbstractAuthenticationProcessingFil super(MFA_LOGIN_MATCHER); } - public static RequestMatcher getRequestMatcher() { + protected static RequestMatcher getRequestMatcher() { return MFA_LOGIN_MATCHER; } @@ -95,14 +92,11 @@ public class MfaAuthenticationFilter extends AbstractAuthenticationProcessingFil */ @Override public Authentication attemptAuthentication(HttpServletRequest request, - HttpServletResponse response) throws AuthenticationException, - IOException, - ServletException { + HttpServletResponse response) throws AuthenticationException { UserEntity user = UserUtils.getUser(); - OtpContextHelp bean = ApplicationContextHelp.getBean(OtpContextHelp.class); MfaAuthentication authentication = (MfaAuthentication) SecurityContextHolder.getContext() .getAuthentication(); - Boolean result = false; + boolean result = false; //获取类型 MfaFactor type = MfaFactor.getType(request.getParameter(SPRING_SECURITY_FORM_TYPE_KEY)); if (Objects.isNull(type)) { @@ -114,7 +108,7 @@ public class MfaAuthenticationFilter extends AbstractAuthenticationProcessingFil if (StringUtils.isBlank(otp)) { throw new MfaRequiredException("OTP 参数不存在"); } - result = bean.checkOtp(type.getCode(), MessageNoticeChannel.SMS, "", otp); + result = smsOtpProviderValidator.validate(otp); } //Mail OPT if (MfaFactor.EMAIL_OTP.equals(type)) { @@ -122,12 +116,12 @@ public class MfaAuthenticationFilter extends AbstractAuthenticationProcessingFil if (StringUtils.isBlank(otp)) { throw new MfaRequiredException("OTP 参数不存在"); } - result = bean.checkOtp(type.getCode(), MessageNoticeChannel.MAIL, "", otp); + result = emailOtpProviderValidator.validate(otp); } //TOTP if (MfaFactor.APP_TOTP.equals(type)) { long totp = Long.parseLong(request.getParameter(SPRING_SECURITY_FORM_TOTP_KEY)); - result = new TotpProviderValidator().validate(String.valueOf(totp)); + result = totpProviderValidator.validate(String.valueOf(totp)); } if (!result) { logger.error("用户ID: [{}] 用户名: [{}] {} 认证失败", type.getDesc(), user.getId(), @@ -140,4 +134,8 @@ public class MfaAuthenticationFilter extends AbstractAuthenticationProcessingFil authentication.setValidated(true); return authentication; } + + protected final EmailOtpProviderValidator emailOtpProviderValidator = new EmailOtpProviderValidator(); + protected final SmsOtpProviderValidator smsOtpProviderValidator = new SmsOtpProviderValidator(); + protected final TotpProviderValidator totpProviderValidator = new TotpProviderValidator(); } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/handler/PortalAuthenticationHandler.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationHandler.java similarity index 74% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/handler/PortalAuthenticationHandler.java rename to eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationHandler.java index 89814fd7..33d3c4aa 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/handler/PortalAuthenticationHandler.java +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationHandler.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-mfa - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.handler; +package cn.topiam.employee.authentication.mfa; import java.io.IOException; @@ -31,11 +31,10 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.WebAttributes; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +import org.springframework.util.Assert; import cn.topiam.employee.common.constants.AuthorizeConstants; import cn.topiam.employee.core.context.ServerContextHelp; -import cn.topiam.employee.core.security.authentication.IdpAuthentication; -import cn.topiam.employee.core.security.authentication.SmsAuthentication; import cn.topiam.employee.core.security.mfa.MfaAuthentication; import cn.topiam.employee.support.result.ApiRestResult; import cn.topiam.employee.support.util.HttpResponseUtils; @@ -53,14 +52,20 @@ import static cn.topiam.employee.support.exception.enums.ExceptionStatus.EX00010 * Created by support@topiam.cn on 2022/7/28 23:36 */ @SuppressWarnings("DuplicatedCode") -public class PortalAuthenticationHandler implements AuthenticationSuccessHandler, - AuthenticationFailureHandler { +public class MfaAuthenticationHandler implements AuthenticationSuccessHandler, + AuthenticationFailureHandler { + private static final String REQUIRE_MFA = "require_mfa"; - private final AuthenticationSuccessHandler successHandler = new PortalAuthenticationSuccessHandler(); - private final AuthenticationFailureHandler failureHandler = new PortalAuthenticationFailureHandler(); + private final AuthenticationSuccessHandler successHandler; + private final AuthenticationFailureHandler failureHandler; - private static final String REQUIRE_MFA = "require_mfa"; - private static final String REQUIRE_USER_BIND = "require_user_bind"; + public MfaAuthenticationHandler(AuthenticationSuccessHandler successHandler, + AuthenticationFailureHandler failureHandler) { + Assert.notNull(successHandler, "userIdpService must not be null"); + Assert.notNull(failureHandler, "userIdpService must not be null"); + this.successHandler = successHandler; + this.failureHandler = failureHandler; + } /** * Called when an authentication attempt fails. @@ -90,35 +95,6 @@ public class PortalAuthenticationHandler implements AuthenticationSuccessHandler Authentication authentication) throws IOException, ServletException { boolean isTextHtml = acceptIncludeTextHtml(request); - //TODO SMS 不需要双因素 - if (authentication instanceof SmsAuthentication) { - successHandler.onAuthenticationSuccess(request, response, authentication); - return; - } - //TODO IDP 未关联 - if (authentication instanceof IdpAuthentication - && !((IdpAuthentication) authentication).getAssociated()) { - //Clear Authentication Attributes - clearAuthenticationAttributes(request); - if (response.isCommitted()) { - return; - } - if (!isTextHtml) { - HttpResponseUtils.flushResponseJson(response, HttpStatus.BAD_REQUEST.value(), - ApiRestResult.builder().status(REQUIRE_USER_BIND).message(REQUIRE_USER_BIND) - .build()); - return; - } - //跳转登录,前端会有接口获取状态,并进行展示绑定页面 - response.sendRedirect(HttpUrlUtils - .format(ServerContextHelp.getPortalPublicBaseUrl() + AuthorizeConstants.FE_LOGIN)); - return; - } - //TODO IDP 不需要双因素 - if (authentication instanceof IdpAuthentication) { - successHandler.onAuthenticationSuccess(request, response, authentication); - return; - } //TODO MFA启用、但是对象非MFA,说明需要MFA认证 if (isMfaEnabled() && !(authentication instanceof MfaAuthentication)) { SecurityContextHolder.getContext() diff --git a/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationMfaFactorsFilter.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationMfaFactorsFilter.java new file mode 100644 index 00000000..eb479f4f --- /dev/null +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationMfaFactorsFilter.java @@ -0,0 +1,132 @@ +/* + * eiam-authentication-mfa - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.mfa; + +import java.io.IOException; +import java.io.Serial; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.web.filter.OncePerRequestFilter; + +import cn.topiam.employee.common.entity.account.UserEntity; +import cn.topiam.employee.common.enums.MfaFactor; +import cn.topiam.employee.core.security.util.UserUtils; +import cn.topiam.employee.support.result.ApiRestResult; +import cn.topiam.employee.support.util.DesensitizationUtil; +import cn.topiam.employee.support.util.HttpResponseUtils; + +import lombok.Builder; +import lombok.Data; +import static cn.topiam.employee.authentication.mfa.constant.MfaAuthenticationConstants.LOGIN_MFA_FACTORS; +import static cn.topiam.employee.core.context.SettingContextHelp.getMfaFactors; + +/** + * MfaAuthenticationMfaFactorsFilter + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2023/1/2 13:28 + */ +public class MfaAuthenticationMfaFactorsFilter extends OncePerRequestFilter { + + public final static String DEFAULT_FILTER_PROCESSES_URI = LOGIN_MFA_FACTORS; + + public static final RequestMatcher LOGIN_MFA_FACTORS_MATCHER = new AntPathRequestMatcher( + DEFAULT_FILTER_PROCESSES_URI, HttpMethod.GET.name()); + + @Override + @SuppressWarnings("AlibabaAvoidComplexCondition") + protected void doFilterInternal(@NotNull HttpServletRequest request, + @NotNull HttpServletResponse response, + @NotNull FilterChain filterChain) throws ServletException, + IOException { + if (!getRequestMatcher().matches(request)) { + filterChain.doFilter(request, response); + return; + } + UserEntity user = UserUtils.getUser(); + List list = new ArrayList<>(); + List factors = getMfaFactors(); + for (MfaFactor provider : factors) { + MfaFactorResult result = MfaFactorResult.builder().build(); + result.setFactor(provider); + result.setUsable(false); + //sms + if (provider.equals(MfaFactor.SMS_OTP) && StringUtils.isNotBlank(user.getPhone())) { + result.setTarget(DesensitizationUtil.phoneEncrypt(user.getPhone())); + result.setUsable(true); + } + //otp + if (provider.equals(MfaFactor.EMAIL_OTP) && StringUtils.isNotBlank(user.getEmail())) { + result.setTarget(DesensitizationUtil.emailEncrypt(user.getEmail())); + result.setUsable(true); + } + //totp + if (provider.equals(MfaFactor.APP_TOTP) + && (!Objects.isNull(user.getTotpBind()) && user.getTotpBind())) { + result.setUsable(true); + } + list.add(result); + } + HttpResponseUtils.flushResponseJson(response, HttpStatus.OK.value(), + ApiRestResult.ok(list)); + } + + public static RequestMatcher getRequestMatcher() { + return LOGIN_MFA_FACTORS_MATCHER; + } + + /** + * Mfa 登录方式 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/8/13 21:29 + */ + @Builder + @Data + public static class MfaFactorResult implements Serializable { + + @Serial + private static final long serialVersionUID = 7255002979319970337L; + /** + * provider + */ + private MfaFactor factor; + /** + * 可用 + */ + private Boolean usable; + /** + * 目标 + */ + private String target; + } +} diff --git a/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationSendOtpFilter.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationSendOtpFilter.java new file mode 100644 index 00000000..536bed47 --- /dev/null +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/MfaAuthenticationSendOtpFilter.java @@ -0,0 +1,159 @@ +/* + * eiam-authentication-mfa - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.mfa; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Map; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.validation.ConstraintViolationException; + +import org.jetbrains.annotations.NotNull; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.web.filter.OncePerRequestFilter; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import cn.topiam.employee.common.entity.account.UserEntity; +import cn.topiam.employee.common.enums.MailType; +import cn.topiam.employee.common.enums.MessageNoticeChannel; +import cn.topiam.employee.common.enums.SmsType; +import cn.topiam.employee.common.exception.LoginOtpActionNotSupportException; +import cn.topiam.employee.common.util.RequestUtils; +import cn.topiam.employee.core.security.mfa.MfaAuthentication; +import cn.topiam.employee.core.security.otp.OtpContextHelp; +import cn.topiam.employee.core.security.userdetails.UserDetails; +import cn.topiam.employee.core.security.util.SecurityUtils; +import cn.topiam.employee.core.security.util.UserUtils; +import cn.topiam.employee.support.result.ApiRestResult; +import cn.topiam.employee.support.util.HttpResponseUtils; +import cn.topiam.employee.support.validation.ValidationHelp; + +import lombok.Data; + +import io.swagger.v3.oas.annotations.Parameter; +import static cn.topiam.employee.authentication.mfa.constant.MfaAuthenticationConstants.OTP_SEND_OTP; + +/** + * 发送短信OPT + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2023/1/1 22:01 + */ +public class MfaAuthenticationSendOtpFilter extends OncePerRequestFilter { + public final static String DEFAULT_FILTER_PROCESSES_URI = OTP_SEND_OTP; + + public static final RequestMatcher SMS_SEND_OPT_MATCHER = new AntPathRequestMatcher( + DEFAULT_FILTER_PROCESSES_URI, HttpMethod.POST.name()); + + @Override + protected void doFilterInternal(@NotNull HttpServletRequest request, + @NotNull HttpServletResponse response, + @NotNull FilterChain filterChain) throws ServletException, + IOException { + if (!getRequestMatcher().matches(request)) { + filterChain.doFilter(request, response); + return; + } + SecurityContext securityContext = SecurityUtils.getSecurityContext(); + Authentication authentication = securityContext.getAuthentication(); + //非MFA对象 + if (!(authentication instanceof MfaAuthentication)) { + HttpResponseUtils.flushResponseJson(response, HttpStatus.UNAUTHORIZED.value(), + ApiRestResult.ok()); + return; + } + Map params = RequestUtils.getParams(request); + String value = OBJECT_MAPPER.writeValueAsString(params); + SendOtpRequest sendOtpRequest = OBJECT_MAPPER.readValue(value, SendOtpRequest.class); + ValidationHelp.ValidationResult validationResult = ValidationHelp + .validateEntity(sendOtpRequest); + if (validationResult.isHasErrors()) { + throw new ConstraintViolationException(validationResult.getConstraintViolations()); + } + //MFA,从会话上下文中获取手机号及邮箱信息 + UserDetails principal = (UserDetails) ((MfaAuthentication) authentication).getFirst() + .getPrincipal(); + UserEntity user = UserUtils.getUser(principal.getId()); + String email = user.getEmail(); + if (MessageNoticeChannel.MAIL.equals(sendOtpRequest.getChannel())) { + send(email, MessageNoticeChannel.MAIL); + HttpResponseUtils.flushResponseJson(response, HttpStatus.OK.value(), + ApiRestResult.ok()); + return; + } + String phone = user.getPhone(); + if (MessageNoticeChannel.SMS.equals(sendOtpRequest.getChannel())) { + send(phone, MessageNoticeChannel.SMS); + HttpResponseUtils.flushResponseJson(response, HttpStatus.OK.value(), + ApiRestResult.ok()); + return; + } + throw new LoginOtpActionNotSupportException(); + } + + /** + * 发送 + * + * @param target {@link String} + * @param channel {@link MessageNoticeChannel} + */ + private void send(String target, MessageNoticeChannel channel) { + String type; + if (channel == MessageNoticeChannel.MAIL) { + type = MailType.AGAIN_VERIFY.getCode(); + } else { + type = SmsType.AGAIN_VERIFY.getCode(); + } + otpContextHelp.sendOtp(target, type, channel); + } + + /** + * 发送 OTP 请求 + */ + @Data + public static class SendOtpRequest implements Serializable { + /** + * 渠道 + */ + @Parameter(description = "channel") + @javax.validation.constraints.NotNull(message = "消息渠道不能为空") + private MessageNoticeChannel channel; + } + + public static RequestMatcher getRequestMatcher() { + return SMS_SEND_OPT_MATCHER; + } + + private final OtpContextHelp otpContextHelp; + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + public MfaAuthenticationSendOtpFilter(OtpContextHelp otpContextHelp) { + this.otpContextHelp = otpContextHelp; + } +} diff --git a/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/constant/MfaAuthenticationConstants.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/constant/MfaAuthenticationConstants.java new file mode 100644 index 00000000..8c79d61a --- /dev/null +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/constant/MfaAuthenticationConstants.java @@ -0,0 +1,48 @@ +/* + * eiam-authentication-mfa - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.mfa.constant; + +import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; + +/** + * Mfa 认证常量 + * + * @author TopIAM + * Created by support@topiam.cn on 2021/12/19 23:19 + */ +public final class MfaAuthenticationConstants { + /** + * mfa + */ + public static final String LOGIN_MFA = LOGIN_PATH + "/mfa"; + /** + * mfa 登录提供者 + */ + public static final String LOGIN_MFA_FACTORS = LOGIN_MFA + "/factors"; + + /** + * maf 验证 + */ + public static final String MFA_VALIDATE = LOGIN_MFA + "/validate"; + + /** + * 发送 OTP + */ + public static final String OTP_SEND_OTP = LOGIN_MFA + "/send"; + +} \ No newline at end of file diff --git a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/configurer/package-info.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/constant/package-info.java similarity index 85% rename from eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/configurer/package-info.java rename to eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/constant/package-info.java index 3c293f6c..d98f7da2 100644 --- a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/configurer/package-info.java +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/constant/package-info.java @@ -1,5 +1,5 @@ /* - * eiam-authentication-sms - Employee Identity and Access Management Program + * eiam-authentication-mfa - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.authentication.sms.configurer; \ No newline at end of file +package cn.topiam.employee.authentication.mfa.constant; \ No newline at end of file diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/email/EmailOtpProviderValidator.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/email/EmailOtpProviderValidator.java similarity index 60% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/email/EmailOtpProviderValidator.java rename to eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/email/EmailOtpProviderValidator.java index 9f0779f0..6308f87a 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/email/EmailOtpProviderValidator.java +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/email/EmailOtpProviderValidator.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-mfa - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,9 +15,15 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa.email; +package cn.topiam.employee.authentication.mfa.email; +import cn.topiam.employee.common.entity.account.UserEntity; +import cn.topiam.employee.common.enums.MailType; +import cn.topiam.employee.common.enums.MessageNoticeChannel; import cn.topiam.employee.core.security.mfa.MfaProviderValidator; +import cn.topiam.employee.core.security.otp.OtpContextHelp; +import cn.topiam.employee.core.security.util.UserUtils; +import cn.topiam.employee.support.context.ApplicationContextHelp; /** * OTP 提供商验证 @@ -33,6 +39,9 @@ public class EmailOtpProviderValidator implements MfaProviderValidator { */ @Override public boolean validate(String code) { - return true; + UserEntity user = UserUtils.getUser(); + OtpContextHelp bean = ApplicationContextHelp.getBean(OtpContextHelp.class); + return bean.checkOtp(MailType.AGAIN_VERIFY.getCode(), MessageNoticeChannel.MAIL, + user.getEmail(), code); } } diff --git a/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/sms/SmsOtpProviderValidator.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/sms/SmsOtpProviderValidator.java new file mode 100644 index 00000000..bdba5dfc --- /dev/null +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/sms/SmsOtpProviderValidator.java @@ -0,0 +1,47 @@ +/* + * eiam-authentication-mfa - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.mfa.sms; + +import cn.topiam.employee.common.entity.account.UserEntity; +import cn.topiam.employee.common.enums.MessageNoticeChannel; +import cn.topiam.employee.common.enums.SmsType; +import cn.topiam.employee.core.security.mfa.MfaProviderValidator; +import cn.topiam.employee.core.security.otp.OtpContextHelp; +import cn.topiam.employee.core.security.util.UserUtils; +import cn.topiam.employee.support.context.ApplicationContextHelp; + +/** + * 短信 OTP 提供商验证 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/7/31 20:50 + */ +public class SmsOtpProviderValidator implements MfaProviderValidator { + /** + * 验证 + * + * @param code {@link String} + */ + @Override + public boolean validate(String code) { + UserEntity user = UserUtils.getUser(); + OtpContextHelp bean = ApplicationContextHelp.getBean(OtpContextHelp.class); + return bean.checkOtp(SmsType.AGAIN_VERIFY.getCode(), MessageNoticeChannel.SMS, + user.getPhone(), code); + } +} diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/totp/TotpProviderValidator.java b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/totp/TotpProviderValidator.java similarity index 82% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/totp/TotpProviderValidator.java rename to eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/totp/TotpProviderValidator.java index f96799ff..e7f92bef 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/totp/TotpProviderValidator.java +++ b/eiam-authentication/eiam-authentication-mfa/src/main/java/cn/topiam/employee/authentication/mfa/totp/TotpProviderValidator.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-mfa - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa.totp; +package cn.topiam.employee.authentication.mfa.totp; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.core.security.mfa.MfaProviderValidator; @@ -37,7 +37,9 @@ public class TotpProviderValidator implements MfaProviderValidator { @Override public boolean validate(String code) { UserEntity user = UserUtils.getUser(); - return new TotpAuthenticator().checkCode(user.getSharedSecret(), Long.parseLong(code), + return totpAuthenticator.checkCode(user.getSharedSecret(), Long.parseLong(code), System.currentTimeMillis()); } + + private final TotpAuthenticator totpAuthenticator = new TotpAuthenticator(); } diff --git a/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2AuthorizationRequestRedirectFilter.java b/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2AuthorizationRequestRedirectFilter.java index 6a6a130b..41b6749e 100644 --- a/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2AuthorizationRequestRedirectFilter.java +++ b/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2AuthorizationRequestRedirectFilter.java @@ -49,8 +49,9 @@ import com.alibaba.fastjson2.JSONObject; import cn.topiam.employee.authentication.qq.QqIdpOauthConfig; import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; +import static cn.topiam.employee.authentication.common.IdentityProviderType.QQ; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.qq.filter.QqOAuth2LoginAuthenticationFilter.getLoginUrl; -import static cn.topiam.employee.common.enums.IdentityProviderType.QQ; import static cn.topiam.employee.portal.idp.qq.constant.QqAuthenticationConstants.URL_AUTHORIZE; /** @@ -64,16 +65,12 @@ public class QqOAuth2AuthorizationRequestRedirectFilter extends OncePerRequestFi private final Logger logger = LoggerFactory .getLogger(QqOAuth2AuthorizationRequestRedirectFilter.class); - /** - * 提供商ID - */ - public static final String PROVIDER_ID = "providerId"; /** * AntPathRequestMatcher */ public static final AntPathRequestMatcher QQ_REQUEST_MATCHER = new AntPathRequestMatcher( - QQ.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_ID + "}", HttpMethod.GET.name()); + QQ.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** * 重定向策略 @@ -104,9 +101,9 @@ public class QqOAuth2AuthorizationRequestRedirectFilter extends OncePerRequestFi return; } Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerCode = variables.get(PROVIDER_CODE); Optional optional = identityProviderRepository - .findByIdAndEnabledIsTrue(Long.valueOf(providerId)); + .findByCodeAndEnabledIsTrue(providerCode); if (optional.isEmpty()) { throw new NullPointerException("未查询到身份提供商信息"); } @@ -117,7 +114,8 @@ public class QqOAuth2AuthorizationRequestRedirectFilter extends OncePerRequestFi //构建授权请求 OAuth2AuthorizationRequest.Builder builder = OAuth2AuthorizationRequest.authorizationCode() .clientId(config.getAppId()).authorizationUri(URL_AUTHORIZE) - .redirectUri(getLoginUrl(providerId)).state(DEFAULT_STATE_GENERATOR.generateKey()); + .redirectUri(getLoginUrl(optional.get().getCode())) + .state(DEFAULT_STATE_GENERATOR.generateKey()); builder.parameters(parameters -> { parameters.put(OAuth2ParameterNames.RESPONSE_TYPE, OAuth2ParameterNames.CODE); }); diff --git a/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2LoginAuthenticationFilter.java b/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2LoginAuthenticationFilter.java index 0b55c440..c197ed4d 100644 --- a/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2LoginAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-qq/src/main/java/cn/topiam/employee/authentication/qq/filter/QqOAuth2LoginAuthenticationFilter.java @@ -53,8 +53,8 @@ import cn.topiam.employee.support.trace.TraceUtils; import cn.topiam.employee.support.util.HttpClientUtils; import static com.nimbusds.oauth2.sdk.GrantType.AUTHORIZATION_CODE; -import static cn.topiam.employee.authentication.qq.filter.QqOAuth2AuthorizationRequestRedirectFilter.PROVIDER_ID; -import static cn.topiam.employee.common.enums.IdentityProviderType.QQ; +import static cn.topiam.employee.authentication.common.IdentityProviderType.QQ; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.portal.idp.qq.constant.QqAuthenticationConstants.URL_GET_ACCESS_TOKEN; import static cn.topiam.employee.portal.idp.qq.constant.QqAuthenticationConstants.URL_GET_OPEN_ID; @@ -70,7 +70,7 @@ public class QqOAuth2LoginAuthenticationFilter extends AbstractIdpAuthentication public final static String DEFAULT_FILTER_PROCESSES_URI = QQ.getLoginPathPrefix() + "/*"; public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( - QQ.getLoginPathPrefix() + "/" + "{" + PROVIDER_ID + "}", HttpMethod.GET.name()); + QQ.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** * Creates a new instance @@ -100,7 +100,7 @@ public class QqOAuth2LoginAuthenticationFilter extends AbstractIdpAuthentication TraceUtils.put(UUID.randomUUID().toString()); RequestMatcher.MatchResult matcher = REQUEST_MATCHER.matcher(request); Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerId = variables.get(PROVIDER_CODE); //code String code = request.getParameter(OAuth2ParameterNames.CODE); if (StringUtils.isEmpty(code)) { @@ -133,7 +133,7 @@ public class QqOAuth2LoginAuthenticationFilter extends AbstractIdpAuthentication param.put(OAuth2ParameterNames.CLIENT_ID, config.getAppId().trim()); param.put(OAuth2ParameterNames.CLIENT_SECRET, config.getAppKey().trim()); param.put(OAuth2ParameterNames.CODE, code.trim()); - param.put(OAuth2ParameterNames.REDIRECT_URI, getLoginUrl(providerId)); + param.put(OAuth2ParameterNames.REDIRECT_URI, getLoginUrl(provider.getCode())); param.put("fmt", "json"); //注意:QQ不能使用编码后的get请求,否则会报 {"error_description":"redirect uri is illegal","error":100010} JSONObject result = JSON.parseObject(HttpClientUtils.doGet(URL_GET_ACCESS_TOKEN, param)); diff --git a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SendSmsCaptchaFilter.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SendSmsCaptchaFilter.java new file mode 100644 index 00000000..a708c3be --- /dev/null +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SendSmsCaptchaFilter.java @@ -0,0 +1,94 @@ +/* + * eiam-authentication-sms - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.authentication.sms; + +import java.io.IOException; +import java.util.Objects; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.security.web.util.matcher.RequestMatcher; +import org.springframework.web.filter.OncePerRequestFilter; + +import cn.topiam.employee.authentication.sms.exception.PhoneNotExistException; +import cn.topiam.employee.common.entity.account.UserEntity; +import cn.topiam.employee.common.repository.account.UserRepository; +import cn.topiam.employee.core.security.otp.OtpContextHelp; +import cn.topiam.employee.support.result.ApiRestResult; +import cn.topiam.employee.support.util.HttpResponseUtils; +import static cn.topiam.employee.authentication.sms.constant.SmsAuthenticationConstants.PHONE_KEY; +import static cn.topiam.employee.authentication.sms.constant.SmsAuthenticationConstants.SMS_SEND_OTP; +import static cn.topiam.employee.common.enums.MessageNoticeChannel.SMS; +import static cn.topiam.employee.common.enums.SmsType.LOGIN; + +/** + * 发送短信OPT + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2023/1/1 22:01 + */ +public class SendSmsCaptchaFilter extends OncePerRequestFilter { + public final static String DEFAULT_FILTER_PROCESSES_URI = SMS_SEND_OTP; + + public static final RequestMatcher SMS_SEND_OPT_MATCHER = new AntPathRequestMatcher( + DEFAULT_FILTER_PROCESSES_URI, HttpMethod.POST.name()); + + @Override + protected void doFilterInternal(@NotNull HttpServletRequest request, + @NotNull HttpServletResponse response, + @NotNull FilterChain filterChain) throws ServletException, + IOException { + if (!getRequestMatcher().matches(request)) { + filterChain.doFilter(request, response); + return; + } + String phone = request.getParameter(PHONE_KEY); + if (StringUtils.isBlank(phone)) { + throw new PhoneNotExistException(); + } + //判断是否存在用户 + UserEntity user = userRepository.findByPhone(phone); + if (Objects.isNull(user)) { + HttpResponseUtils.flushResponseJson(response, HttpStatus.OK.value(), + ApiRestResult.ok()); + return; + } + //发送OPT + otpContextHelp.sendOtp(phone, LOGIN.getCode(), SMS); + } + + public static RequestMatcher getRequestMatcher() { + return SMS_SEND_OPT_MATCHER; + } + + private final UserRepository userRepository; + private final OtpContextHelp otpContextHelp; + + public SendSmsCaptchaFilter(UserRepository userRepository, OtpContextHelp otpContextHelp) { + this.userRepository = userRepository; + this.otpContextHelp = otpContextHelp; + } +} diff --git a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/configurer/SmsAuthenticationConfigurer.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SmsAuthenticationConfigurer.java similarity index 72% rename from eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/configurer/SmsAuthenticationConfigurer.java rename to eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SmsAuthenticationConfigurer.java index efeecc89..2d87d306 100644 --- a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/configurer/SmsAuthenticationConfigurer.java +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SmsAuthenticationConfigurer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.authentication.sms.configurer; +package cn.topiam.employee.authentication.sms; import org.springframework.security.config.annotation.web.HttpSecurityBuilder; import org.springframework.security.config.annotation.web.configurers.AbstractAuthenticationFilterConfigurer; @@ -25,7 +25,8 @@ import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.util.Assert; -import cn.topiam.employee.authentication.sms.filter.SmsAuthenticationFilter; +import cn.topiam.employee.common.repository.account.UserRepository; +import cn.topiam.employee.core.security.otp.OtpContextHelp; /** * 认证配置 @@ -35,11 +36,20 @@ import cn.topiam.employee.authentication.sms.filter.SmsAuthenticationFilter; */ public final class SmsAuthenticationConfigurer> extends AbstractAuthenticationFilterConfigurer, SmsAuthenticationFilter> { + private final UserRepository userRepository; private final UserDetailsService userDetailsService; - public SmsAuthenticationConfigurer(UserDetailsService userDetailsService) { + private final OtpContextHelp otpContextHelp; + + public SmsAuthenticationConfigurer(UserRepository userRepository, + UserDetailsService userDetailsService, + OtpContextHelp otpContextHelp) { + Assert.notNull(userDetailsService, "userRepository must not be null"); Assert.notNull(userDetailsService, "userDetailsService must not be null"); + Assert.notNull(otpContextHelp, "otpContextHelp must not be null"); this.userDetailsService = userDetailsService; + this.userRepository = userRepository; + this.otpContextHelp = otpContextHelp; } /** @@ -58,7 +68,7 @@ public final class SmsAuthenticationConfigurer> public void init(H http) throws Exception { //SMS SmsAuthenticationFilter loginAuthenticationFilter = new SmsAuthenticationFilter( - userDetailsService); + userDetailsService, otpContextHelp); this.setAuthenticationFilter(loginAuthenticationFilter); //处理URL super.loginProcessingUrl(SmsAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI); @@ -67,12 +77,10 @@ public final class SmsAuthenticationConfigurer> @Override public void configure(H http) throws Exception { - http.addFilterAfter(this.getAuthenticationFilter(), - UsernamePasswordAuthenticationFilter.class); + SendSmsCaptchaFilter sendSmsCaptchaFilter = new SendSmsCaptchaFilter(userRepository, + otpContextHelp); + http.addFilterAfter(sendSmsCaptchaFilter, UsernamePasswordAuthenticationFilter.class); + http.addFilterAfter(this.getAuthenticationFilter(), SendSmsCaptchaFilter.class); super.configure(http); } - - public RequestMatcher getRequestMatcher() { - return SmsAuthenticationFilter.getRequestMatcher(); - } } diff --git a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/filter/SmsAuthenticationFilter.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SmsAuthenticationFilter.java similarity index 72% rename from eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/filter/SmsAuthenticationFilter.java rename to eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SmsAuthenticationFilter.java index 6bf48b78..074508c4 100644 --- a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/filter/SmsAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/SmsAuthenticationFilter.java @@ -15,12 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.authentication.sms.filter; +package cn.topiam.employee.authentication.sms; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.security.authentication.AuthenticationServiceException; @@ -28,15 +30,23 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; import org.springframework.util.Assert; +import cn.topiam.employee.authentication.sms.exception.CaptchaNotExistException; +import cn.topiam.employee.authentication.sms.exception.PhoneNotExistException; +import cn.topiam.employee.common.enums.MessageNoticeChannel; import cn.topiam.employee.core.security.authentication.SmsAuthentication; +import cn.topiam.employee.core.security.otp.OtpContextHelp; import cn.topiam.employee.support.result.ApiRestResult; import cn.topiam.employee.support.util.HttpResponseUtils; +import static cn.topiam.employee.authentication.sms.constant.SmsAuthenticationConstants.CODE_KEY; +import static cn.topiam.employee.authentication.sms.constant.SmsAuthenticationConstants.PHONE_KEY; import static cn.topiam.employee.common.constants.AuthorizeConstants.SMS_LOGIN; +import static cn.topiam.employee.common.enums.SmsType.LOGIN; import static cn.topiam.employee.support.exception.enums.ExceptionStatus.EX000102; /** @@ -47,13 +57,15 @@ import static cn.topiam.employee.support.exception.enums.ExceptionStatus.EX00010 */ public class SmsAuthenticationFilter extends AbstractAuthenticationProcessingFilter { - public static final String PHONE_KEY = "phone"; + private final Logger logger = LoggerFactory + .getLogger(SmsAuthenticationFilter.class); /** * 请求方法 */ public static final String METHOD = "POST"; private String phoneParameter = PHONE_KEY; + private String codeParameter = CODE_KEY; /** * 是否值处理POST请求 */ @@ -64,11 +76,6 @@ public class SmsAuthenticationFilter extends AbstractAuthenticationProcessingFil public static final RequestMatcher SMS_LOGIN_MATCHER = new AntPathRequestMatcher( DEFAULT_FILTER_PROCESSES_URI, HttpMethod.POST.name()); - public SmsAuthenticationFilter(UserDetailsService userDetailsService) { - super(SMS_LOGIN_MATCHER); - this.userDetailsService = userDetailsService; - } - @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { @@ -79,7 +86,21 @@ public class SmsAuthenticationFilter extends AbstractAuthenticationProcessingFil } // 获取手机号 String phone = StringUtils.defaultString(obtainUsername(request), "").trim(); + if (StringUtils.isBlank(phone)) { + throw new PhoneNotExistException(); + } + String code = StringUtils.defaultString(obtainCode(request), "").trim(); + if (StringUtils.isBlank(code)) { + throw new CaptchaNotExistException(); + } UserDetails userDetails = userDetailsService.loadUserByUsername(phone); + //判断短信验证码 + Boolean checkOtp = otpContextHelp.checkOtp(LOGIN.getCode(), MessageNoticeChannel.SMS, + phone, code); + if (!checkOtp) { + logger.error("用户手机号: [{}], 验证码: [{}] 认证失败", phone, code); + throw new UsernameNotFoundException("用户名或密码错误"); + } SmsAuthentication authentication = new SmsAuthentication(userDetails, phone, userDetails.getAuthorities()); // Allow subclasses to set the "details" property @@ -106,6 +127,10 @@ public class SmsAuthenticationFilter extends AbstractAuthenticationProcessingFil return request.getParameter(phoneParameter); } + protected String obtainCode(HttpServletRequest request) { + return request.getParameter(codeParameter); + } + /** * Provided so that subclasses may configure what is put into the * authentication request's details property. @@ -135,9 +160,18 @@ public class SmsAuthenticationFilter extends AbstractAuthenticationProcessingFil return phoneParameter; } - public void setPhoneParameter(String phoneParameter) { + public final String getCodeParameter() { + return codeParameter; + } + + public void setPhoneParameter(String codeParameter) { Assert.hasText(phoneParameter, "Mobile parameter must not be empty or null"); - this.phoneParameter = phoneParameter; + this.codeParameter = codeParameter; + } + + public void setCodeParameter(String codeParameter) { + Assert.hasText(codeParameter, "Code parameter must not be empty or null"); + this.codeParameter = codeParameter; } public static RequestMatcher getRequestMatcher() { @@ -145,4 +179,13 @@ public class SmsAuthenticationFilter extends AbstractAuthenticationProcessingFil } private final UserDetailsService userDetailsService; + + private final OtpContextHelp otpContextHelp; + + public SmsAuthenticationFilter(UserDetailsService userDetailsService, + OtpContextHelp otpContextHelp) { + super(SMS_LOGIN_MATCHER); + this.userDetailsService = userDetailsService; + this.otpContextHelp = otpContextHelp; + } } diff --git a/eiam-protocol/eiam-protocol-form/src/main/java/cn/topiam/employee/protocol/form/constant/ProtocolConstants.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/constant/SmsAuthenticationConstants.java similarity index 59% rename from eiam-protocol/eiam-protocol-form/src/main/java/cn/topiam/employee/protocol/form/constant/ProtocolConstants.java rename to eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/constant/SmsAuthenticationConstants.java index 2122276f..5606889b 100644 --- a/eiam-protocol/eiam-protocol-form/src/main/java/cn/topiam/employee/protocol/form/constant/ProtocolConstants.java +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/constant/SmsAuthenticationConstants.java @@ -1,5 +1,5 @@ /* - * eiam-protocol-form - Employee Identity and Access Management Program + * eiam-authentication-sms - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,23 +15,29 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.protocol.form.constant; +package cn.topiam.employee.authentication.sms.constant; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZE_PATH; -import static cn.topiam.employee.common.constants.ProtocolConstants.APP_CODE_VARIABLE; +import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; /** - * 协议常量 + * Sms认证常量 * * @author TopIAM - * Created by support@topiam.cn on 2021/12/8 21:29 + * Created by support@topiam.cn on 2021/12/19 23:19 */ -public class ProtocolConstants { +public final class SmsAuthenticationConstants { /** - * FORM IDP SSO 发起 + * sms login 路径 */ - public static final String IDP_FORM_SSO_INITIATOR = AUTHORIZE_PATH + "/form/" - + APP_CODE_VARIABLE + "/initiator"; + public static final String SMS_LOGIN = LOGIN_PATH + "/sms"; -} + /** + * 发送短信OTP + */ + public static final String SMS_SEND_OTP = SMS_LOGIN + "/send"; + + public static final String PHONE_KEY = "phone"; + public static final String CODE_KEY = "code"; + +} \ No newline at end of file diff --git a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/filter/package-info.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/constant/package-info.java similarity index 93% rename from eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/filter/package-info.java rename to eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/constant/package-info.java index 09f5ba56..c250c94b 100644 --- a/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/filter/package-info.java +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/constant/package-info.java @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.authentication.sms.filter; \ No newline at end of file +package cn.topiam.employee.authentication.sms.constant; \ No newline at end of file diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/SmsProviderValidator.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/exception/CaptchaNotExistException.java similarity index 61% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/SmsProviderValidator.java rename to eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/exception/CaptchaNotExistException.java index 3e9843c0..58a63c68 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/SmsProviderValidator.java +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/exception/CaptchaNotExistException.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-sms - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,24 +15,17 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa; +package cn.topiam.employee.authentication.sms.exception; -import cn.topiam.employee.core.security.mfa.MfaProviderValidator; +import cn.topiam.employee.support.exception.TopIamException; /** - * Sms提供商验证 * - * @author TopIAM - * Created by support@topiam.cn on 2022/7/31 20:50 + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2023/1/2 13:00 */ -public class SmsProviderValidator implements MfaProviderValidator { - /** - * 验证 - * - * @param code {@link String} - */ - @Override - public boolean validate(String code) { - return true; +public class CaptchaNotExistException extends TopIamException { + public CaptchaNotExistException() { + super("captcha_not_exist", "验证码不存在", DEFAULT_STATUS); } } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/EmailProviderValidator.java b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/exception/PhoneNotExistException.java similarity index 60% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/EmailProviderValidator.java rename to eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/exception/PhoneNotExistException.java index 181daba1..e80bb762 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/EmailProviderValidator.java +++ b/eiam-authentication/eiam-authentication-sms/src/main/java/cn/topiam/employee/authentication/sms/exception/PhoneNotExistException.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-authentication-sms - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,24 +15,19 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa; +package cn.topiam.employee.authentication.sms.exception; -import cn.topiam.employee.core.security.mfa.MfaProviderValidator; +import cn.topiam.employee.support.exception.TopIamException; /** - * Email提供商验证 + * 手机号不存在异常 * - * @author TopIAM - * Created by support@topiam.cn on 2022/7/31 20:50 + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2023/1/2 12:59 */ -public class EmailProviderValidator implements MfaProviderValidator { - /** - * 验证 - * - * @param code {@link String} - */ - @Override - public boolean validate(String code) { - return true; +public class PhoneNotExistException extends TopIamException { + public PhoneNotExistException() { + super("phone_not_exist", "手机号不存在", DEFAULT_STATUS); } + } diff --git a/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeAuthorizationRequestRedirectFilter.java b/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeAuthorizationRequestRedirectFilter.java index b7643b3e..c63ea3bd 100644 --- a/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeAuthorizationRequestRedirectFilter.java +++ b/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeAuthorizationRequestRedirectFilter.java @@ -51,8 +51,9 @@ import com.google.common.collect.Sets; import cn.topiam.employee.authentication.wechat.WeChatIdpScanCodeConfig; import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; +import static cn.topiam.employee.authentication.common.IdentityProviderType.WECHAT_QR; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.wechat.constant.WeChatAuthenticationConstants.*; -import static cn.topiam.employee.common.enums.IdentityProviderType.WECHAT_SCAN_CODE; /** * 微信扫码登录请求重定向过滤器 @@ -66,16 +67,11 @@ public class WeChatScanCodeAuthorizationRequestRedirectFilter extends OncePerReq private final Logger logger = LoggerFactory .getLogger(WeChatScanCodeAuthorizationRequestRedirectFilter.class); - /** - * 提供商ID - */ - public static final String PROVIDER_ID = "providerId"; - /** * AntPathRequestMatcher */ public static final AntPathRequestMatcher WE_CHAT_SCAN_CODE_REQUEST_MATCHER = new AntPathRequestMatcher( - WECHAT_SCAN_CODE.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_ID + "}", + WECHAT_QR.getAuthorizationPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** @@ -107,9 +103,9 @@ public class WeChatScanCodeAuthorizationRequestRedirectFilter extends OncePerReq return; } Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerCode = variables.get(PROVIDER_CODE); Optional optional = identityProviderRepository - .findByIdAndEnabledIsTrue(Long.valueOf(providerId)); + .findByCodeAndEnabledIsTrue(providerCode); if (optional.isEmpty()) { throw new NullPointerException("未查询到身份提供商信息"); } @@ -124,7 +120,7 @@ public class WeChatScanCodeAuthorizationRequestRedirectFilter extends OncePerReq .clientId(config.getAppId()) .scopes(Sets.newHashSet(SNSAPI_LOGIN)) .authorizationUri(AUTHORIZATION_REQUEST) - .redirectUri(WeChatScanCodeLoginAuthenticationFilter.getLoginUrl(providerId)) + .redirectUri(WeChatScanCodeLoginAuthenticationFilter.getLoginUrl(optional.get().getCode())) .state(DEFAULT_STATE_GENERATOR.generateKey()) .attributes(attributes); //@formatter:on @@ -160,13 +156,13 @@ public class WeChatScanCodeAuthorizationRequestRedirectFilter extends OncePerReq authorizationRequest.getAuthorizationRequestUri()); } - private final static String STYLE = "" + private static final String STYLE = "" + ".impowerBox .qrcode {width: 280px;border: none;margin-top:10px;}\n" + ".impowerBox .title {display: none;}\n" + ".impowerBox .info {display: none;}\n" + ".status_icon {display: none}\n" + ".impowerBox .status {text-align: center;} "; - private final static String STYLE_BASE64 = "data:text/css;base64," + Base64.getEncoder() + private static final String STYLE_BASE64 = "data:text/css;base64," + Base64.getEncoder() .encodeToString(STYLE.getBytes(StandardCharsets.UTF_8)); public static RequestMatcher getRequestMatcher() { diff --git a/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeLoginAuthenticationFilter.java b/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeLoginAuthenticationFilter.java index 9118375e..fb1f6ea5 100644 --- a/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeLoginAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-wechat/src/main/java/cn/topiam/employee/authentication/wechat/filter/WeChatScanCodeLoginAuthenticationFilter.java @@ -46,16 +46,15 @@ import cn.topiam.employee.authentication.common.service.UserIdpService; import cn.topiam.employee.authentication.wechat.WeChatIdpScanCodeConfig; import cn.topiam.employee.authentication.wechat.constant.WeChatAuthenticationConstants; import cn.topiam.employee.common.entity.authentication.IdentityProviderEntity; -import cn.topiam.employee.common.enums.IdentityProviderType; import cn.topiam.employee.common.repository.authentication.IdentityProviderRepository; import cn.topiam.employee.core.context.ServerContextHelp; import cn.topiam.employee.support.exception.TopIamException; import cn.topiam.employee.support.util.HttpClientUtils; import static org.springframework.security.oauth2.core.AuthorizationGrantType.AUTHORIZATION_CODE; +import static cn.topiam.employee.authentication.common.IdentityProviderType.WECHAT_QR; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; import static cn.topiam.employee.authentication.wechat.constant.WeChatAuthenticationConstants.*; -import static cn.topiam.employee.authentication.wechat.filter.WeChatScanCodeAuthorizationRequestRedirectFilter.PROVIDER_ID; -import static cn.topiam.employee.common.enums.IdentityProviderType.WECHAT_SCAN_CODE; /** * 微信扫码登录过滤器 @@ -66,11 +65,10 @@ import static cn.topiam.employee.common.enums.IdentityProviderType.WECHAT_SCAN_C public class WeChatScanCodeLoginAuthenticationFilter extends AbstractIdpAuthenticationProcessingFilter { - public final static String DEFAULT_FILTER_PROCESSES_URI = WECHAT_SCAN_CODE + public final static String DEFAULT_FILTER_PROCESSES_URI = WECHAT_QR .getLoginPathPrefix() + "/*"; public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( - WECHAT_SCAN_CODE.getLoginPathPrefix() + "/" + "{" + PROVIDER_ID + "}", - HttpMethod.GET.name()); + WECHAT_QR.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** * Creates a new instance @@ -99,7 +97,7 @@ public class WeChatScanCodeLoginAuthenticationFilter extends response); RequestMatcher.MatchResult matcher = REQUEST_MATCHER.matcher(request); Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerId = variables.get(PROVIDER_CODE); //code String code = request.getParameter(OAuth2ParameterNames.CODE); if (StringUtils.isEmpty(code)) { @@ -152,13 +150,12 @@ public class WeChatScanCodeLoginAuthenticationFilter extends } // 返回 IdpUser idpUser = IdpUser.builder().openId(param.get(OidcScopes.OPENID)).build(); - return attemptAuthentication(request, response, IdentityProviderType.WECHAT_SCAN_CODE, - providerId, idpUser); + return attemptAuthentication(request, response, WECHAT_QR, providerId, idpUser); } public static String getLoginUrl(String providerId) { - String url = ServerContextHelp.getPortalPublicBaseUrl() - + WECHAT_SCAN_CODE.getLoginPathPrefix() + "/" + providerId; + String url = ServerContextHelp.getPortalPublicBaseUrl() + WECHAT_QR.getLoginPathPrefix() + + "/" + providerId; return url.replaceAll("(? variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerCode = variables.get(PROVIDER_CODE); Optional optional = identityProviderRepository - .findByIdAndEnabledIsTrue(Long.valueOf(providerId)); + .findByCodeAndEnabledIsTrue(providerCode); if (optional.isEmpty()) { throw new NullPointerException("未查询到身份提供商信息"); } @@ -115,7 +111,8 @@ public class WeChatWorkScanCodeAuthorizationRequestRedirectFilter extends OncePe OAuth2AuthorizationRequest.Builder builder = OAuth2AuthorizationRequest.authorizationCode() .clientId(config.getCorpId()) .authorizationUri(WeChatWorkAuthenticationConstants.URL_AUTHORIZE) - .redirectUri(WeChatWorkScanCodeLoginAuthenticationFilter.getLoginUrl(providerId)) + .redirectUri( + WeChatWorkScanCodeLoginAuthenticationFilter.getLoginUrl(optional.get().getCode())) .state(DEFAULT_STATE_GENERATOR.generateKey()); builder.parameters(parameters -> { HashMap linkedParameters = new LinkedHashMap<>(); @@ -149,13 +146,13 @@ public class WeChatWorkScanCodeAuthorizationRequestRedirectFilter extends OncePe authorizationRequest.getAuthorizationRequestUri()); } - private final static String STYLE = "" + private static final String STYLE = "" + ".impowerBox .qrcode {width: 280px;border: none;margin-top:10px;}\n" + ".impowerBox .title {display: none;}\n" + ".impowerBox .info {display: none;}\n" + ".status_icon {display: none}\n" + ".impowerBox .status {text-align: center;} "; - private final static String STYLE_BASE64 = "data:text/css;base64," + Base64.getEncoder() + private static final String STYLE_BASE64 = "data:text/css;base64," + Base64.getEncoder() .encodeToString(STYLE.getBytes(StandardCharsets.UTF_8)); public static RequestMatcher getRequestMatcher() { diff --git a/eiam-authentication/eiam-authentication-wechatwork/src/main/java/cn/topiam/employee/authentication/wechatwork/filter/WeChatWorkScanCodeLoginAuthenticationFilter.java b/eiam-authentication/eiam-authentication-wechatwork/src/main/java/cn/topiam/employee/authentication/wechatwork/filter/WeChatWorkScanCodeLoginAuthenticationFilter.java index 8c732d63..0898cd5f 100644 --- a/eiam-authentication/eiam-authentication-wechatwork/src/main/java/cn/topiam/employee/authentication/wechatwork/filter/WeChatWorkScanCodeLoginAuthenticationFilter.java +++ b/eiam-authentication/eiam-authentication-wechatwork/src/main/java/cn/topiam/employee/authentication/wechatwork/filter/WeChatWorkScanCodeLoginAuthenticationFilter.java @@ -53,8 +53,8 @@ import cn.topiam.employee.common.repository.authentication.IdentityProviderRepos import cn.topiam.employee.core.context.ServerContextHelp; import cn.topiam.employee.support.trace.TraceUtils; import cn.topiam.employee.support.util.HttpClientUtils; -import static cn.topiam.employee.authentication.wechatwork.filter.WeChatWorkScanCodeAuthorizationRequestRedirectFilter.PROVIDER_ID; -import static cn.topiam.employee.common.enums.IdentityProviderType.WECHATWORK_SCAN_CODE; +import static cn.topiam.employee.authentication.common.IdentityProviderType.WECHAT_WORK_QR; +import static cn.topiam.employee.authentication.common.constant.AuthenticationConstants.PROVIDER_CODE; /** * 企业微信扫码登录 @@ -67,10 +67,10 @@ public class WeChatWorkScanCodeLoginAuthenticationFilter extends AbstractIdpAuthenticationProcessingFilter { final String ERROR_CODE = "errcode"; final String SUCCESS = "0"; - public final static String DEFAULT_FILTER_PROCESSES_URI = WECHATWORK_SCAN_CODE + public final static String DEFAULT_FILTER_PROCESSES_URI = WECHAT_WORK_QR .getLoginPathPrefix() + "/*"; public static final AntPathRequestMatcher REQUEST_MATCHER = new AntPathRequestMatcher( - WECHATWORK_SCAN_CODE.getLoginPathPrefix() + "/" + "{" + PROVIDER_ID + "}", + WECHAT_WORK_QR.getLoginPathPrefix() + "/" + "{" + PROVIDER_CODE + "}", HttpMethod.GET.name()); /** @@ -101,7 +101,7 @@ public class WeChatWorkScanCodeLoginAuthenticationFilter extends TraceUtils.put(UUID.randomUUID().toString()); RequestMatcher.MatchResult matcher = REQUEST_MATCHER.matcher(request); Map variables = matcher.getVariables(); - String providerId = variables.get(PROVIDER_ID); + String providerId = variables.get(PROVIDER_CODE); //code String code = request.getParameter(OAuth2ParameterNames.CODE); if (StringUtils.isEmpty(code)) { @@ -145,7 +145,7 @@ public class WeChatWorkScanCodeLoginAuthenticationFilter extends String userId = StringUtils.defaultString(result.getString("UserId"), result.getString("OpenId")); IdpUser idpUser = IdpUser.builder().openId(userId).build(); - return attemptAuthentication(request, response, WECHATWORK_SCAN_CODE, providerId, idpUser); + return attemptAuthentication(request, response, WECHAT_WORK_QR, providerId, idpUser); } /** @@ -186,7 +186,7 @@ public class WeChatWorkScanCodeLoginAuthenticationFilter extends public static String getLoginUrl(String providerId) { String url = ServerContextHelp.getPortalPublicBaseUrl() - + WECHATWORK_SCAN_CODE.getLoginPathPrefix() + "/" + providerId; + + WECHAT_WORK_QR.getLoginPathPrefix() + "/" + providerId; return url.replaceAll("(?eiam-authentication-wechatwork eiam-authentication-sms eiam-authentication-mfa + eiam-authentication-captcha eiam-authentication-all diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/constants/AuthorizeConstants.java b/eiam-common/src/main/java/cn/topiam/employee/common/constants/AuthorizeConstants.java index b297cbc3..b0f3e887 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/constants/AuthorizeConstants.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/constants/AuthorizeConstants.java @@ -37,21 +37,12 @@ public final class AuthorizeConstants { * form 表单登录 */ public static final String FORM_LOGIN = LOGIN_PATH; + /** * sms login 路径 */ public static final String SMS_LOGIN = LOGIN_PATH + "/sms"; - /** - * maf 验证 - */ - public static final String MFA_VALIDATE = LOGIN_PATH + "/mfa/validate"; - - /** - * mfa 登录提供者 - */ - public static final String LOGIN_MFA_FACTORS = LOGIN_PATH + "/mfa/factors"; - /** * 登录配置 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/constants/ConfigBeanNameConstants.java b/eiam-common/src/main/java/cn/topiam/employee/common/constants/ConfigBeanNameConstants.java index 3163b649..bb8af34f 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/constants/ConfigBeanNameConstants.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/constants/ConfigBeanNameConstants.java @@ -32,10 +32,12 @@ public final class ConfigBeanNameConstants { * 安全过滤器链 */ public static final String DEFAULT_SECURITY_FILTER_CHAIN = "defaultSecurityFilterChain"; - public static final String SOCIAL_SECURITY_FILTER_CHAIN = "socialSecurityFilterChain"; + public static final String IDP_SECURITY_FILTER_CHAIN = "idpSecurityFilterChain"; public static final String SAML2_PROTOCOL_SECURITY_FILTER_CHAIN = "saml2ProtocolSecurityFilterChain"; public static final String OIDC_PROTOCOL_SECURITY_FILTER_CHAIN = "oidcProtocolSecurityFilterChain"; + public static final String FORM_PROTOCOL_SECURITY_FILTER_CHAIN = "formProtocolSecurityFilterChain"; public static final String CAS_PROTOCOL_SECURITY_FILTER_CHAIN = "casProtocolSecurityFilterChain"; + public static final String TSA_PROTOCOL_SECURITY_FILTER_CHAIN = "tsaProtocolSecurityFilterChain"; /** * 默认密码策略管理器 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/constants/ProtocolConstants.java b/eiam-common/src/main/java/cn/topiam/employee/common/constants/ProtocolConstants.java index 0c263bc4..18f05639 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/constants/ProtocolConstants.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/constants/ProtocolConstants.java @@ -64,6 +64,16 @@ public final class ProtocolConstants { */ public static final String APP_CERT_CACHE_NAME = APP_CACHE_NAME_PREFIX + "cert"; + /** + * FORM 配置缓存名称 + */ + public static final String FORM_CONFIG_CACHE_NAME = APP_CACHE_NAME_PREFIX + "form"; + + /** + * TSA 配置缓存名称 + */ + public static final String TSA_CONFIG_CACHE_NAME = APP_CACHE_NAME_PREFIX + "tsa"; + /** * OIDC Endpoint config */ @@ -75,19 +85,19 @@ public final class ProtocolConstants { */ public final static String OIDC_AUTHORIZE_BASE_PATH = AUTHORIZE_PATH + "/" + APP_CODE_VARIABLE; - public final static String OIDC_AUTHORIZE_PATH = OIDC_AUTHORIZE_BASE_PATH + "/oidc"; + public final static String OIDC_AUTHORIZE_PATH = OIDC_AUTHORIZE_BASE_PATH +"/oidc"; - public final static String OAUTH2_AUTHORIZE_PATH = OIDC_AUTHORIZE_BASE_PATH + "/oauth2"; + public final static String OAUTH2_AUTHORIZE_PATH = OIDC_AUTHORIZE_BASE_PATH +"/oauth2"; /** * OpenID Provider metadata. */ - public static final String WELL_KNOWN_OPENID_CONFIGURATION = OIDC_AUTHORIZE_PATH + OPENID_PROVIDER_WELL_KNOWN_PATH; + public static final String WELL_KNOWN_OPENID_CONFIGURATION = OIDC_AUTHORIZE_PATH +OPENID_PROVIDER_WELL_KNOWN_PATH; /** * Jwk Set Endpoint */ - public static final String JWK_SET_ENDPOINT = OIDC_AUTHORIZE_PATH + "/jwks"; + public static final String JWK_SET_ENDPOINT = OIDC_AUTHORIZE_PATH + "/jwks"; /** * OIDC Client Registration Endpoint @@ -97,27 +107,32 @@ public final class ProtocolConstants { /** * Authorization Endpoint */ - public static final String AUTHORIZATION_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/auth"; + public static final String AUTHORIZATION_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/auth"; + + /** + * Authorization Consent Endpoint + */ + public static final String AUTHORIZATION_CONSENT_ENDPOINT = AUTHORIZATION_ENDPOINT+"/consent"; /** * Token Endpoint */ - public static final String TOKEN_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/token"; + public static final String TOKEN_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/token"; /** * Jwk Revocation Endpoint */ - public static final String TOKEN_REVOCATION_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/revoke"; + public static final String TOKEN_REVOCATION_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/revoke"; /** * Token Introspection Endpoint */ - public static final String TOKEN_INTROSPECTION_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/introspect"; + public static final String TOKEN_INTROSPECTION_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/introspect"; /** * OIDC User Info Endpoint */ - public static final String OIDC_USER_INFO_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/userinfo"; + public static final String OIDC_USER_INFO_ENDPOINT = OAUTH2_AUTHORIZE_PATH + "/userinfo"; //@formatter:on } @@ -149,6 +164,30 @@ public final class ProtocolConstants { public static final String SAML_SSO_PATH = SAML2_AUTHORIZE_BASE_PATH + "/sso"; } + /** + * Form Endpoint config + */ + @Data + public static class FormEndpointConstants { + + /** + * FORM 认证路径 + */ + public final static String FORM_AUTHORIZE_BASE_PATH = AUTHORIZE_PATH + "/form/" + + APP_CODE_VARIABLE; + + /** + * FORM_SSO + */ + public static final String FORM_SSO_PATH = FORM_AUTHORIZE_BASE_PATH + "/sso"; + + /** + * FORM IDP SSO 发起 + */ + public static final String IDP_FORM_SSO_INITIATOR = FORM_AUTHORIZE_BASE_PATH + + "/initiator"; + } + @Data public static class CasEndpointConstants { /** @@ -160,6 +199,12 @@ public final class ProtocolConstants { * cas 登陆地址 */ public final static String CAS_LOGIN_PATH = CAS_AUTHORIZE_BASE_PATH + "/login"; + + /** + * cas 登出地址 + */ + public final static String CAS_LOGOUT_PATH = CAS_AUTHORIZE_BASE_PATH + "/logout"; + /** * cas ticket校验地址 */ @@ -172,4 +217,21 @@ public final class ProtocolConstants { + "/p3/serviceValidate"; } + /** + * TSA Endpoint config + */ + @Data + public static class TsaEndpointConstants { + + /** + * TSA 认证路径 + */ + public final static String TSA_AUTHORIZE_BASE_PATH = AUTHORIZE_PATH + "/tsa/" + + APP_CODE_VARIABLE; + + /** + * TSA_SSO + */ + public static final String TSA_SSO_PATH = TSA_AUTHORIZE_BASE_PATH + "/sso"; + } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/constants/SettingConstants.java b/eiam-common/src/main/java/cn/topiam/employee/common/constants/SettingConstants.java index a37d26e6..eb9f75be 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/constants/SettingConstants.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/constants/SettingConstants.java @@ -48,4 +48,8 @@ public final class SettingConstants { */ public static final String ADMIN_CACHE_NAME = "admin"; + /** + * 应用AES秘钥 + */ + public static final String AES_SECRET = "security.aes_secret"; } diff --git a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/package-info.java b/eiam-common/src/main/java/cn/topiam/employee/common/context/package-info.java similarity index 87% rename from eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/package-info.java rename to eiam-common/src/main/java/cn/topiam/employee/common/context/package-info.java index 0522db3c..936d37cd 100644 --- a/eiam-portal/src/main/java/cn/topiam/employee/portal/mfa/package-info.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/context/package-info.java @@ -1,5 +1,5 @@ /* - * eiam-portal - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,4 +15,4 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.portal.mfa; \ No newline at end of file +package cn.topiam.employee.common.context; \ No newline at end of file diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/Encrypt.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/Encrypt.java new file mode 100644 index 00000000..a7445dca --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/Encrypt.java @@ -0,0 +1,40 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.fasterxml.jackson.annotation.JacksonAnnotation; + +/** + * Encrypt + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +@JacksonAnnotation +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER }) +public @interface Encrypt { + Type serializer() default Type.ENCRYPT; + + Type deserializer() default Type.DECRYPT; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptContextHelp.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptContextHelp.java new file mode 100644 index 00000000..2238c360 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptContextHelp.java @@ -0,0 +1,68 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import java.util.Objects; + +import org.springframework.util.Assert; + +import cn.topiam.employee.common.entity.setting.SettingEntity; +import cn.topiam.employee.common.repository.setting.SettingRepository; +import cn.topiam.employee.support.context.ApplicationContextHelp; +import cn.topiam.employee.support.util.AesUtils; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import static cn.topiam.employee.common.constants.SettingConstants.AES_SECRET; + +/** + * EncryptContextHelp + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EncryptContextHelp { + private static final AesUtils AES_UTILS = new AesUtils(getAesSecret()); + + public static String encrypt(String content) { + return AES_UTILS.encrypt(content); + } + + public static String decrypt(String content) { + if (Objects.isNull(content)) { + return null; + } + return AES_UTILS.decrypt(content); + } + + /** + * 获取AES秘钥 + * + * @return {@link String} + */ + public static String getAesSecret() { + SettingEntity setting = getSettingRepository().findByName(AES_SECRET); + Assert.notNull(setting, "aes secret must not be null"); + return setting.getValue(); + } + + private static SettingRepository getSettingRepository() { + return ApplicationContextHelp.getBean(SettingRepository.class); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedDeserializerModifier.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedDeserializerModifier.java new file mode 100644 index 00000000..8120795f --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedDeserializerModifier.java @@ -0,0 +1,61 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.DeserializationConfig; +import com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder; +import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +public class EncryptedDeserializerModifier extends BeanDeserializerModifier { + + private final Type type; + + public EncryptedDeserializerModifier() { + this.type = null; + } + + public EncryptedDeserializerModifier(Type type) { + this.type = type; + } + + @Override + public BeanDeserializerBuilder updateBuilder(DeserializationConfig config, + BeanDescription beanDesc, + BeanDeserializerBuilder builder) { + var properties = builder.getProperties(); + while (properties.hasNext()) { + var property = properties.next(); + Encrypt annotation = property.getAnnotation(Encrypt.class); + if (annotation != null) { + Type deserializer = type; + if (type == null) { + deserializer = annotation.deserializer(); + } + builder.addOrReplaceProperty( + property.withValueDeserializer(new EncryptedJsonDeserializer(deserializer)), + true); + } + } + return builder; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedJsonDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedJsonDeserializer.java new file mode 100644 index 00000000..085213f8 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedJsonDeserializer.java @@ -0,0 +1,54 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import java.io.IOException; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +public class EncryptedJsonDeserializer extends JsonDeserializer { + + private final Type deserializerType; + + public EncryptedJsonDeserializer(Type deserializer) { + this.deserializerType = deserializer; + } + + @Override + public Object deserialize(final JsonParser parser, + final DeserializationContext context) throws IOException { + String value = parser.getValueAsString(); + if (StringUtils.isBlank(value)) { + return null; + } + if (Type.ENCRYPT == deserializerType) { + return EncryptContextHelp.encrypt(value); + } else if (Type.DECRYPT == deserializerType) { + return EncryptContextHelp.decrypt(value); + } + return value; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedJsonSerializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedJsonSerializer.java new file mode 100644 index 00000000..87789b38 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedJsonSerializer.java @@ -0,0 +1,108 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import java.io.IOException; +import java.io.StringWriter; + +import org.apache.commons.lang3.StringUtils; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +public class EncryptedJsonSerializer extends JsonSerializer { + + /** + * 默认序列化工具对象 + */ + private final JsonSerializer serializer; + private final Type serializerType; + + public EncryptedJsonSerializer() { + this.serializer = null; + this.serializerType = null; + } + + public EncryptedJsonSerializer(JsonSerializer serializer, Type type) { + this.serializer = serializer; + this.serializerType = type; + } + + @Override + public void serialize(Object obj, JsonGenerator jsonGenerator, + SerializerProvider serializerProvider) throws IOException { + StringWriter stringWriter = new StringWriter(); + ObjectCodec objectCodec = jsonGenerator.getCodec(); + JsonGenerator nestedGenerator = null; + + //空对象或空字符串不处理。 + if (obj == null || StringUtils.isEmpty(String.valueOf(obj))) { + if (serializer == null) { + serializerProvider.defaultSerializeValue(obj, jsonGenerator); + } else { + serializer.serialize(obj, jsonGenerator, serializerProvider); + } + return; + } + /* + 生成一个新的JsonGenerator,用于将obj写入。 + */ + if (objectCodec instanceof ObjectMapper) { + nestedGenerator = objectCodec.getFactory().createGenerator(stringWriter); + } + + if (nestedGenerator == null) { + throw new NullPointerException("nestedGenerator == null"); + } + + /* + 将数据写入到新生成的JsonGenerator中 + */ + if (serializer == null) { + serializerProvider.defaultSerializeValue(obj, nestedGenerator); + } else { + serializer.serialize(obj, nestedGenerator, serializerProvider); + } + + nestedGenerator.close(); + /* + JsonGenerator会生成一个带双引号的字符串, 将数据加密后写入。 + */ + String value = stringWriter.getBuffer().toString(); + try { + String newValue = value.substring(1, value.length() - 1); + if (StringUtils.isNotEmpty(newValue)) { + if (Type.ENCRYPT == serializerType) { + newValue = EncryptContextHelp.encrypt(newValue); + } else if (Type.DECRYPT == serializerType) { + newValue = EncryptContextHelp.decrypt(value); + } + } + jsonGenerator.writeString(newValue); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedSerializerModifier.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedSerializerModifier.java new file mode 100644 index 00000000..f3ae0104 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptedSerializerModifier.java @@ -0,0 +1,71 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; +import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +public class EncryptedSerializerModifier extends BeanSerializerModifier { + + private final Type type; + + public EncryptedSerializerModifier() { + this.type = null; + } + + public EncryptedSerializerModifier(Type type) { + this.type = type; + } + + @Override + public List changeProperties(SerializationConfig config, + BeanDescription beanDesc, + List beanProperties) { + /* + 遍历beanProperties处理Encrypt.class注解 + */ + List newWriter = new ArrayList<>(); + for (BeanPropertyWriter writer : beanProperties) { + Encrypt annotation = writer.getAnnotation(Encrypt.class); + if (null == annotation) { + newWriter.add(writer); + } else { + Type deserializer = type; + if (type == null) { + deserializer = annotation.deserializer(); + } + JsonSerializer serializer = new EncryptedJsonSerializer( + writer.getSerializer(), deserializer); + writer.assignSerializer(serializer); + newWriter.add(writer); + } + } + + return newWriter; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptionModule.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptionModule.java new file mode 100644 index 00000000..ec66395a --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/EncryptionModule.java @@ -0,0 +1,75 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.crypto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.module.SimpleModule; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/12/22 21:53 + */ +public class EncryptionModule extends SimpleModule { + + private final Type serializer; + private final Type deserializer; + + public EncryptionModule() { + this.serializer = null; + this.deserializer = null; + } + + public EncryptionModule(Type serializer, Type deserializer) { + this.serializer = serializer; + this.deserializer = deserializer; + } + + @Override + public void setupModule(SetupContext setupContext) { + setupContext.addBeanSerializerModifier(new EncryptedSerializerModifier(serializer)); + setupContext.addBeanDeserializerModifier(new EncryptedDeserializerModifier(deserializer)); + } + + public static ObjectMapper serializerEncrypt() { + return createMapper(Type.ENCRYPT, Type.NONE); + } + + public static ObjectMapper deserializerEncrypt() { + return createMapper(Type.NONE, Type.ENCRYPT); + } + + public static ObjectMapper serializerDecrypt() { + return createMapper(Type.DECRYPT, Type.NONE); + } + + public static ObjectMapper deserializerDecrypt() { + return createMapper(Type.NONE, Type.DECRYPT); + } + + public static ObjectMapper createMapper(Type serializer, Type deserializer) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + objectMapper.registerModule(new EncryptionModule(serializer, deserializer)); + return objectMapper; + } +} \ No newline at end of file diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/util/CasUtils.java b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/Type.java similarity index 66% rename from eiam-common/src/main/java/cn/topiam/employee/common/util/CasUtils.java rename to eiam-common/src/main/java/cn/topiam/employee/common/crypto/Type.java index 58fa4fab..ae8de653 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/util/CasUtils.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/crypto/Type.java @@ -15,16 +15,24 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.util; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package cn.topiam.employee.common.crypto; /** * @author TopIAM - * Created by support@topiam.cn on 2022/12/30 01:06 + * Created by support@topiam.cn on 2022/12/22 21:53 */ -public class CasUtils { - private final static Logger logger = LoggerFactory.getLogger(CasUtils.class); +public enum Type { + /** + * Encrypt + */ + ENCRYPT, + /** + * Decrypt + */ + DECRYPT, + /** + * None + */ + NONE } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationEntity.java index 59e4c521..d6b13219 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationEntity.java @@ -25,14 +25,19 @@ import javax.persistence.Entity; import javax.persistence.Table; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.OrganizationType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,8 +51,11 @@ import lombok.ToString; @Setter @ToString @Entity -@Table(name = "`organization`") -public class OrganizationEntity extends BaseEntity { +@Table(name = "organization") +@SQLDelete(sql = "update organization set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update organization set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class OrganizationEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 8143944323232082295L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java index c6dd357f..d3ee275a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Entity; import javax.persistence.Table; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 组织机构成员 @@ -43,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`organization_member`") -public class OrganizationMemberEntity extends BaseEntity { +@Table(name = "organization_member") +@SQLDelete(sql = "update organization_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update organization_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class OrganizationMemberEntity extends LogicDeleteEntity { /** * 组织机构ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java index f872d729..f1c37995 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java @@ -25,14 +25,19 @@ import javax.persistence.Entity; import javax.persistence.Table; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.enums.UserIdType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -48,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @Entity @Table(name = "user_detail") -public class UserDetailEntity extends BaseEntity { +@SQLDelete(sql = "update user_detail set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_detail set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserDetailEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3599183663669763315L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java index e09da282..5a546393 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java @@ -28,17 +28,22 @@ import javax.persistence.Table; import javax.persistence.Transient; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; import com.fasterxml.jackson.annotation.JsonIgnore; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -53,8 +58,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user`") -public class UserEntity extends BaseEntity { +@Table(name = "user") +@SQLDelete(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java index b22055f6..86033a8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group`") -public class UserGroupEntity extends BaseEntity { +@Table(name = "user_group") +@SQLDelete(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java index e64282cd..4233275e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户组成员 @@ -39,8 +45,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group_member`") -public class UserGroupMemberEntity extends BaseEntity { +@Table(name = "user_group_member") +@SQLDelete(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupMemberEntity extends LogicDeleteEntity { /** * 组ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java index 9ba74092..9381fa73 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java @@ -24,14 +24,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import com.fasterxml.jackson.annotation.JsonIgnore; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,8 +52,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_history_password`") -public class UserHistoryPasswordEntity extends BaseEntity { +@Table(name = "user_history_password") +@SQLDelete(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserHistoryPasswordEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java index 1171373c..d06bf831 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户认证方式绑定表 @@ -40,47 +45,50 @@ import lombok.experimental.Accessors; */ @Entity @Table(name = "user_idp_bind") +@SQLDelete(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) @Accessors(chain = true) @Getter @Setter @ToString -public class UserIdpBindEntity extends BaseEntity { +public class UserIdpBindEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -14364708756807242L; + private static final long serialVersionUID = -14364708756807242L; /** * 用户ID */ @Column(name = "user_id") - private Long userId; + private Long userId; /** * OpenId */ @Column(name = "open_id") - private String openId; + private String openId; /** * 身份提供商 ID */ @Column(name = "idp_id") - private String idpId; + private String idpId; /** * 身份提供商 类型 */ @Column(name = "idp_type") - private IdentityProviderType idpType; + private String idpType; /** * 绑定时间 */ @Column(name = "bind_time") - private LocalDateTime bindTime; + private LocalDateTime bindTime; /** * 附加信息 */ @Column(name = "addition_info") - private String additionInfo; + private String additionInfo; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java index 823e2494..4def668b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java @@ -21,13 +21,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用授权策略 @@ -41,7 +47,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_access_policy") -public class AppAccessPolicyEntity extends BaseEntity { +@SQLDelete(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccessPolicyEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java index 41252ea6..84ca85f5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用账户 @@ -40,7 +46,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_account") -public class AppAccountEntity extends BaseEntity { +@SQLDelete(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccountEntity extends LogicDeleteEntity { /** * 应用ID */ @@ -58,4 +67,10 @@ public class AppAccountEntity extends BaseEntity { */ @Column(name = "account_") private String account; + + /** + * 账户密码 + */ + @Column(name = "password_") + private String password; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java index 0f2d67f0..d41788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java @@ -25,6 +25,7 @@ import org.hibernate.annotations.TypeDef; import com.vladmihalcea.hibernate.type.json.JsonStringType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; import cn.topiam.employee.support.repository.domain.BaseEntity; import lombok.Getter; @@ -50,12 +51,24 @@ public class AppCasConfigEntity extends BaseEntity { * APP ID */ @Column(name = "app_id") - private Long appId; + private Long appId; /** - * SP 接受回调地址 + * 用户身份类型 */ - @Column(name = "sp_callback_url") - private String spCallbackUrl; + @Column(name = "user_identity_type") + private CasUserIdentityType userIdentityType; + + /** + * 客户端服务URL + */ + @Column(name = "client_service_url") + private String clientServiceUrl; + + /** + * serviceTicket 过期时间(秒) + */ + @Column(name = "service_ticket_expire_time") + private Integer serviceTicketExpireTime; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java index b4b69aae..81111318 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @author TopIAM @@ -42,7 +48,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_cert") -public class AppCertEntity extends BaseEntity { +@SQLDelete(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppCertEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java index 1367c07b..c784481e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app") -public class AppEntity extends BaseEntity { +@SQLDelete(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppEntity extends LogicDeleteEntity { /** * 应用名称 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java new file mode 100644 index 00000000..2fa6c528 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java @@ -0,0 +1,107 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_form_config") +@SQLDelete(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppFormConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录URL + */ + @Column(name = "login_url") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Column(name = "username_field") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Column(name = "password_field") + private String passwordField; + + /** + * 登录提交方式 + */ + @Column(name = "submit_type") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Column(name = "other_field") + @Type(type = "json") + private List otherField; + + @Data + @Schema(description = "表单其他信息") + public static class OtherField implements Serializable { + + private String fieldName; + + private String fieldValue; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java index efedbf1b..b1d60aab 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java @@ -23,17 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.vladmihalcea.hibernate.type.json.JsonStringType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP OIDC 配置 @@ -47,8 +48,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_oidc_config") +@SQLDelete(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppOidcConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppOidcConfigEntity extends LogicDeleteEntity { /** * APP ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java index 097bfeb1..7c6cf858 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java @@ -21,13 +21,19 @@ import java.io.Serial; import javax.persistence.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PermissionActionType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用权限 @@ -40,8 +46,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_action`") -public class AppPermissionActionEntity extends BaseEntity { +@Table(name = "app_permission_action") +@SQLDelete(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionActionEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3954680915360748087L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java index f8b51c68..50aa2c82 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java @@ -21,15 +21,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicyEffect; import cn.topiam.employee.common.enums.PolicyObjectType; import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用策略 @@ -42,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_policy`") -public class AppPermissionPolicyEntity extends BaseEntity { +@Table(name = "app_permission_policy") +@SQLDelete(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionPolicyEntity extends LogicDeleteEntity { /** * 应用id diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java index 4ebea00b..f9f4e994 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java @@ -22,7 +22,11 @@ import java.util.List; import javax.persistence.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; @@ -30,6 +34,9 @@ import lombok.ToString; import lombok.experimental.Accessors; import static javax.persistence.FetchType.LAZY; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + /** * * 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -46,8 +51,11 @@ import lombok.ToString; @Setter @ToString @Entity -@Table(name = "`organization`") -public class OrganizationEntity extends BaseEntity { +@Table(name = "organization") +@SQLDelete(sql = "update organization set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update organization set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class OrganizationEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 8143944323232082295L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java index c6dd357f..d3ee275a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/OrganizationMemberEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Entity; import javax.persistence.Table; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 组织机构成员 @@ -43,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`organization_member`") -public class OrganizationMemberEntity extends BaseEntity { +@Table(name = "organization_member") +@SQLDelete(sql = "update organization_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update organization_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class OrganizationMemberEntity extends LogicDeleteEntity { /** * 组织机构ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java index f872d729..f1c37995 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserDetailEntity.java @@ -25,14 +25,19 @@ import javax.persistence.Entity; import javax.persistence.Table; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.enums.UserIdType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -48,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @Entity @Table(name = "user_detail") -public class UserDetailEntity extends BaseEntity { +@SQLDelete(sql = "update user_detail set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_detail set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserDetailEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3599183663669763315L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java index e09da282..5a546393 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java @@ -28,17 +28,22 @@ import javax.persistence.Table; import javax.persistence.Transient; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; import com.fasterxml.jackson.annotation.JsonIgnore; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -53,8 +58,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user`") -public class UserEntity extends BaseEntity { +@Table(name = "user") +@SQLDelete(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java index b22055f6..86033a8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group`") -public class UserGroupEntity extends BaseEntity { +@Table(name = "user_group") +@SQLDelete(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java index e64282cd..4233275e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户组成员 @@ -39,8 +45,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group_member`") -public class UserGroupMemberEntity extends BaseEntity { +@Table(name = "user_group_member") +@SQLDelete(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupMemberEntity extends LogicDeleteEntity { /** * 组ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java index 9ba74092..9381fa73 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java @@ -24,14 +24,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import com.fasterxml.jackson.annotation.JsonIgnore; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,8 +52,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_history_password`") -public class UserHistoryPasswordEntity extends BaseEntity { +@Table(name = "user_history_password") +@SQLDelete(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserHistoryPasswordEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java index 1171373c..d06bf831 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户认证方式绑定表 @@ -40,47 +45,50 @@ import lombok.experimental.Accessors; */ @Entity @Table(name = "user_idp_bind") +@SQLDelete(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) @Accessors(chain = true) @Getter @Setter @ToString -public class UserIdpBindEntity extends BaseEntity { +public class UserIdpBindEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -14364708756807242L; + private static final long serialVersionUID = -14364708756807242L; /** * 用户ID */ @Column(name = "user_id") - private Long userId; + private Long userId; /** * OpenId */ @Column(name = "open_id") - private String openId; + private String openId; /** * 身份提供商 ID */ @Column(name = "idp_id") - private String idpId; + private String idpId; /** * 身份提供商 类型 */ @Column(name = "idp_type") - private IdentityProviderType idpType; + private String idpType; /** * 绑定时间 */ @Column(name = "bind_time") - private LocalDateTime bindTime; + private LocalDateTime bindTime; /** * 附加信息 */ @Column(name = "addition_info") - private String additionInfo; + private String additionInfo; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java index 823e2494..4def668b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java @@ -21,13 +21,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用授权策略 @@ -41,7 +47,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_access_policy") -public class AppAccessPolicyEntity extends BaseEntity { +@SQLDelete(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccessPolicyEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java index 41252ea6..84ca85f5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用账户 @@ -40,7 +46,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_account") -public class AppAccountEntity extends BaseEntity { +@SQLDelete(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccountEntity extends LogicDeleteEntity { /** * 应用ID */ @@ -58,4 +67,10 @@ public class AppAccountEntity extends BaseEntity { */ @Column(name = "account_") private String account; + + /** + * 账户密码 + */ + @Column(name = "password_") + private String password; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java index 0f2d67f0..d41788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java @@ -25,6 +25,7 @@ import org.hibernate.annotations.TypeDef; import com.vladmihalcea.hibernate.type.json.JsonStringType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; import cn.topiam.employee.support.repository.domain.BaseEntity; import lombok.Getter; @@ -50,12 +51,24 @@ public class AppCasConfigEntity extends BaseEntity { * APP ID */ @Column(name = "app_id") - private Long appId; + private Long appId; /** - * SP 接受回调地址 + * 用户身份类型 */ - @Column(name = "sp_callback_url") - private String spCallbackUrl; + @Column(name = "user_identity_type") + private CasUserIdentityType userIdentityType; + + /** + * 客户端服务URL + */ + @Column(name = "client_service_url") + private String clientServiceUrl; + + /** + * serviceTicket 过期时间(秒) + */ + @Column(name = "service_ticket_expire_time") + private Integer serviceTicketExpireTime; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java index b4b69aae..81111318 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @author TopIAM @@ -42,7 +48,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_cert") -public class AppCertEntity extends BaseEntity { +@SQLDelete(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppCertEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java index 1367c07b..c784481e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app") -public class AppEntity extends BaseEntity { +@SQLDelete(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppEntity extends LogicDeleteEntity { /** * 应用名称 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java new file mode 100644 index 00000000..2fa6c528 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java @@ -0,0 +1,107 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_form_config") +@SQLDelete(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppFormConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录URL + */ + @Column(name = "login_url") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Column(name = "username_field") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Column(name = "password_field") + private String passwordField; + + /** + * 登录提交方式 + */ + @Column(name = "submit_type") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Column(name = "other_field") + @Type(type = "json") + private List otherField; + + @Data + @Schema(description = "表单其他信息") + public static class OtherField implements Serializable { + + private String fieldName; + + private String fieldValue; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java index efedbf1b..b1d60aab 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java @@ -23,17 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.vladmihalcea.hibernate.type.json.JsonStringType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP OIDC 配置 @@ -47,8 +48,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_oidc_config") +@SQLDelete(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppOidcConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppOidcConfigEntity extends LogicDeleteEntity { /** * APP ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java index 097bfeb1..7c6cf858 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java @@ -21,13 +21,19 @@ import java.io.Serial; import javax.persistence.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PermissionActionType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用权限 @@ -40,8 +46,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_action`") -public class AppPermissionActionEntity extends BaseEntity { +@Table(name = "app_permission_action") +@SQLDelete(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionActionEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3954680915360748087L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java index f8b51c68..50aa2c82 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java @@ -21,15 +21,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicyEffect; import cn.topiam.employee.common.enums.PolicyObjectType; import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用策略 @@ -42,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_policy`") -public class AppPermissionPolicyEntity extends BaseEntity { +@Table(name = "app_permission_policy") +@SQLDelete(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionPolicyEntity extends LogicDeleteEntity { /** * 应用id diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java index 4ebea00b..f9f4e994 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java @@ -22,7 +22,11 @@ import java.util.List; import javax.persistence.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; @@ -30,6 +34,9 @@ import lombok.ToString; import lombok.experimental.Accessors; import static javax.persistence.FetchType.LAZY; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + /** * * 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -48,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @Entity @Table(name = "user_detail") -public class UserDetailEntity extends BaseEntity { +@SQLDelete(sql = "update user_detail set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_detail set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserDetailEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3599183663669763315L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java index e09da282..5a546393 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserEntity.java @@ -28,17 +28,22 @@ import javax.persistence.Table; import javax.persistence.Transient; import org.hibernate.Hibernate; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; import com.fasterxml.jackson.annotation.JsonIgnore; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -53,8 +58,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user`") -public class UserEntity extends BaseEntity { +@Table(name = "user") +@SQLDelete(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java index b22055f6..86033a8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group`") -public class UserGroupEntity extends BaseEntity { +@Table(name = "user_group") +@SQLDelete(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java index e64282cd..4233275e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户组成员 @@ -39,8 +45,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group_member`") -public class UserGroupMemberEntity extends BaseEntity { +@Table(name = "user_group_member") +@SQLDelete(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupMemberEntity extends LogicDeleteEntity { /** * 组ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java index 9ba74092..9381fa73 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java @@ -24,14 +24,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import com.fasterxml.jackson.annotation.JsonIgnore; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,8 +52,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_history_password`") -public class UserHistoryPasswordEntity extends BaseEntity { +@Table(name = "user_history_password") +@SQLDelete(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserHistoryPasswordEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java index 1171373c..d06bf831 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户认证方式绑定表 @@ -40,47 +45,50 @@ import lombok.experimental.Accessors; */ @Entity @Table(name = "user_idp_bind") +@SQLDelete(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) @Accessors(chain = true) @Getter @Setter @ToString -public class UserIdpBindEntity extends BaseEntity { +public class UserIdpBindEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -14364708756807242L; + private static final long serialVersionUID = -14364708756807242L; /** * 用户ID */ @Column(name = "user_id") - private Long userId; + private Long userId; /** * OpenId */ @Column(name = "open_id") - private String openId; + private String openId; /** * 身份提供商 ID */ @Column(name = "idp_id") - private String idpId; + private String idpId; /** * 身份提供商 类型 */ @Column(name = "idp_type") - private IdentityProviderType idpType; + private String idpType; /** * 绑定时间 */ @Column(name = "bind_time") - private LocalDateTime bindTime; + private LocalDateTime bindTime; /** * 附加信息 */ @Column(name = "addition_info") - private String additionInfo; + private String additionInfo; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java index 823e2494..4def668b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java @@ -21,13 +21,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用授权策略 @@ -41,7 +47,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_access_policy") -public class AppAccessPolicyEntity extends BaseEntity { +@SQLDelete(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccessPolicyEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java index 41252ea6..84ca85f5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用账户 @@ -40,7 +46,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_account") -public class AppAccountEntity extends BaseEntity { +@SQLDelete(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccountEntity extends LogicDeleteEntity { /** * 应用ID */ @@ -58,4 +67,10 @@ public class AppAccountEntity extends BaseEntity { */ @Column(name = "account_") private String account; + + /** + * 账户密码 + */ + @Column(name = "password_") + private String password; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java index 0f2d67f0..d41788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java @@ -25,6 +25,7 @@ import org.hibernate.annotations.TypeDef; import com.vladmihalcea.hibernate.type.json.JsonStringType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; import cn.topiam.employee.support.repository.domain.BaseEntity; import lombok.Getter; @@ -50,12 +51,24 @@ public class AppCasConfigEntity extends BaseEntity { * APP ID */ @Column(name = "app_id") - private Long appId; + private Long appId; /** - * SP 接受回调地址 + * 用户身份类型 */ - @Column(name = "sp_callback_url") - private String spCallbackUrl; + @Column(name = "user_identity_type") + private CasUserIdentityType userIdentityType; + + /** + * 客户端服务URL + */ + @Column(name = "client_service_url") + private String clientServiceUrl; + + /** + * serviceTicket 过期时间(秒) + */ + @Column(name = "service_ticket_expire_time") + private Integer serviceTicketExpireTime; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java index b4b69aae..81111318 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @author TopIAM @@ -42,7 +48,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_cert") -public class AppCertEntity extends BaseEntity { +@SQLDelete(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppCertEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java index 1367c07b..c784481e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app") -public class AppEntity extends BaseEntity { +@SQLDelete(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppEntity extends LogicDeleteEntity { /** * 应用名称 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java new file mode 100644 index 00000000..2fa6c528 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java @@ -0,0 +1,107 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_form_config") +@SQLDelete(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppFormConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录URL + */ + @Column(name = "login_url") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Column(name = "username_field") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Column(name = "password_field") + private String passwordField; + + /** + * 登录提交方式 + */ + @Column(name = "submit_type") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Column(name = "other_field") + @Type(type = "json") + private List otherField; + + @Data + @Schema(description = "表单其他信息") + public static class OtherField implements Serializable { + + private String fieldName; + + private String fieldValue; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java index efedbf1b..b1d60aab 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java @@ -23,17 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.vladmihalcea.hibernate.type.json.JsonStringType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP OIDC 配置 @@ -47,8 +48,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_oidc_config") +@SQLDelete(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppOidcConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppOidcConfigEntity extends LogicDeleteEntity { /** * APP ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java index 097bfeb1..7c6cf858 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java @@ -21,13 +21,19 @@ import java.io.Serial; import javax.persistence.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PermissionActionType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用权限 @@ -40,8 +46,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_action`") -public class AppPermissionActionEntity extends BaseEntity { +@Table(name = "app_permission_action") +@SQLDelete(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionActionEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3954680915360748087L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java index f8b51c68..50aa2c82 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java @@ -21,15 +21,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicyEffect; import cn.topiam.employee.common.enums.PolicyObjectType; import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用策略 @@ -42,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_policy`") -public class AppPermissionPolicyEntity extends BaseEntity { +@Table(name = "app_permission_policy") +@SQLDelete(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionPolicyEntity extends LogicDeleteEntity { /** * 应用id diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java index 4ebea00b..f9f4e994 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java @@ -22,7 +22,11 @@ import java.util.List; import javax.persistence.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; @@ -30,6 +34,9 @@ import lombok.ToString; import lombok.experimental.Accessors; import static javax.persistence.FetchType.LAZY; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + /** * * 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -53,8 +58,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user`") -public class UserEntity extends BaseEntity { +@Table(name = "user") +@SQLDelete(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java index b22055f6..86033a8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group`") -public class UserGroupEntity extends BaseEntity { +@Table(name = "user_group") +@SQLDelete(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java index e64282cd..4233275e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户组成员 @@ -39,8 +45,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group_member`") -public class UserGroupMemberEntity extends BaseEntity { +@Table(name = "user_group_member") +@SQLDelete(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupMemberEntity extends LogicDeleteEntity { /** * 组ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java index 9ba74092..9381fa73 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java @@ -24,14 +24,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import com.fasterxml.jackson.annotation.JsonIgnore; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,8 +52,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_history_password`") -public class UserHistoryPasswordEntity extends BaseEntity { +@Table(name = "user_history_password") +@SQLDelete(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserHistoryPasswordEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java index 1171373c..d06bf831 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户认证方式绑定表 @@ -40,47 +45,50 @@ import lombok.experimental.Accessors; */ @Entity @Table(name = "user_idp_bind") +@SQLDelete(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) @Accessors(chain = true) @Getter @Setter @ToString -public class UserIdpBindEntity extends BaseEntity { +public class UserIdpBindEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -14364708756807242L; + private static final long serialVersionUID = -14364708756807242L; /** * 用户ID */ @Column(name = "user_id") - private Long userId; + private Long userId; /** * OpenId */ @Column(name = "open_id") - private String openId; + private String openId; /** * 身份提供商 ID */ @Column(name = "idp_id") - private String idpId; + private String idpId; /** * 身份提供商 类型 */ @Column(name = "idp_type") - private IdentityProviderType idpType; + private String idpType; /** * 绑定时间 */ @Column(name = "bind_time") - private LocalDateTime bindTime; + private LocalDateTime bindTime; /** * 附加信息 */ @Column(name = "addition_info") - private String additionInfo; + private String additionInfo; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java index 823e2494..4def668b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java @@ -21,13 +21,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用授权策略 @@ -41,7 +47,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_access_policy") -public class AppAccessPolicyEntity extends BaseEntity { +@SQLDelete(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccessPolicyEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java index 41252ea6..84ca85f5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用账户 @@ -40,7 +46,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_account") -public class AppAccountEntity extends BaseEntity { +@SQLDelete(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccountEntity extends LogicDeleteEntity { /** * 应用ID */ @@ -58,4 +67,10 @@ public class AppAccountEntity extends BaseEntity { */ @Column(name = "account_") private String account; + + /** + * 账户密码 + */ + @Column(name = "password_") + private String password; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java index 0f2d67f0..d41788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java @@ -25,6 +25,7 @@ import org.hibernate.annotations.TypeDef; import com.vladmihalcea.hibernate.type.json.JsonStringType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; import cn.topiam.employee.support.repository.domain.BaseEntity; import lombok.Getter; @@ -50,12 +51,24 @@ public class AppCasConfigEntity extends BaseEntity { * APP ID */ @Column(name = "app_id") - private Long appId; + private Long appId; /** - * SP 接受回调地址 + * 用户身份类型 */ - @Column(name = "sp_callback_url") - private String spCallbackUrl; + @Column(name = "user_identity_type") + private CasUserIdentityType userIdentityType; + + /** + * 客户端服务URL + */ + @Column(name = "client_service_url") + private String clientServiceUrl; + + /** + * serviceTicket 过期时间(秒) + */ + @Column(name = "service_ticket_expire_time") + private Integer serviceTicketExpireTime; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java index b4b69aae..81111318 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @author TopIAM @@ -42,7 +48,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_cert") -public class AppCertEntity extends BaseEntity { +@SQLDelete(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppCertEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java index 1367c07b..c784481e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app") -public class AppEntity extends BaseEntity { +@SQLDelete(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppEntity extends LogicDeleteEntity { /** * 应用名称 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java new file mode 100644 index 00000000..2fa6c528 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java @@ -0,0 +1,107 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_form_config") +@SQLDelete(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppFormConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录URL + */ + @Column(name = "login_url") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Column(name = "username_field") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Column(name = "password_field") + private String passwordField; + + /** + * 登录提交方式 + */ + @Column(name = "submit_type") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Column(name = "other_field") + @Type(type = "json") + private List otherField; + + @Data + @Schema(description = "表单其他信息") + public static class OtherField implements Serializable { + + private String fieldName; + + private String fieldValue; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java index efedbf1b..b1d60aab 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java @@ -23,17 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.vladmihalcea.hibernate.type.json.JsonStringType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP OIDC 配置 @@ -47,8 +48,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_oidc_config") +@SQLDelete(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppOidcConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppOidcConfigEntity extends LogicDeleteEntity { /** * APP ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java index 097bfeb1..7c6cf858 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java @@ -21,13 +21,19 @@ import java.io.Serial; import javax.persistence.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PermissionActionType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用权限 @@ -40,8 +46,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_action`") -public class AppPermissionActionEntity extends BaseEntity { +@Table(name = "app_permission_action") +@SQLDelete(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionActionEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3954680915360748087L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java index f8b51c68..50aa2c82 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java @@ -21,15 +21,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicyEffect; import cn.topiam.employee.common.enums.PolicyObjectType; import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用策略 @@ -42,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_policy`") -public class AppPermissionPolicyEntity extends BaseEntity { +@Table(name = "app_permission_policy") +@SQLDelete(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionPolicyEntity extends LogicDeleteEntity { /** * 应用id diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java index 4ebea00b..f9f4e994 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java @@ -22,7 +22,11 @@ import java.util.List; import javax.persistence.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; @@ -30,6 +34,9 @@ import lombok.ToString; import lombok.experimental.Accessors; import static javax.persistence.FetchType.LAZY; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + /** * * 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group`") -public class UserGroupEntity extends BaseEntity { +@Table(name = "user_group") +@SQLDelete(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java index e64282cd..4233275e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserGroupMemberEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户组成员 @@ -39,8 +45,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_group_member`") -public class UserGroupMemberEntity extends BaseEntity { +@Table(name = "user_group_member") +@SQLDelete(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_group_member set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserGroupMemberEntity extends LogicDeleteEntity { /** * 组ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java index 9ba74092..9381fa73 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserHistoryPasswordEntity.java @@ -24,14 +24,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import com.fasterxml.jackson.annotation.JsonIgnore; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,8 +52,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_history_password`") -public class UserHistoryPasswordEntity extends BaseEntity { +@Table(name = "user_history_password") +@SQLDelete(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserHistoryPasswordEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java index 1171373c..d06bf831 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户认证方式绑定表 @@ -40,47 +45,50 @@ import lombok.experimental.Accessors; */ @Entity @Table(name = "user_idp_bind") +@SQLDelete(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) @Accessors(chain = true) @Getter @Setter @ToString -public class UserIdpBindEntity extends BaseEntity { +public class UserIdpBindEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -14364708756807242L; + private static final long serialVersionUID = -14364708756807242L; /** * 用户ID */ @Column(name = "user_id") - private Long userId; + private Long userId; /** * OpenId */ @Column(name = "open_id") - private String openId; + private String openId; /** * 身份提供商 ID */ @Column(name = "idp_id") - private String idpId; + private String idpId; /** * 身份提供商 类型 */ @Column(name = "idp_type") - private IdentityProviderType idpType; + private String idpType; /** * 绑定时间 */ @Column(name = "bind_time") - private LocalDateTime bindTime; + private LocalDateTime bindTime; /** * 附加信息 */ @Column(name = "addition_info") - private String additionInfo; + private String additionInfo; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java index 823e2494..4def668b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java @@ -21,13 +21,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用授权策略 @@ -41,7 +47,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_access_policy") -public class AppAccessPolicyEntity extends BaseEntity { +@SQLDelete(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccessPolicyEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java index 41252ea6..84ca85f5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用账户 @@ -40,7 +46,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_account") -public class AppAccountEntity extends BaseEntity { +@SQLDelete(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccountEntity extends LogicDeleteEntity { /** * 应用ID */ @@ -58,4 +67,10 @@ public class AppAccountEntity extends BaseEntity { */ @Column(name = "account_") private String account; + + /** + * 账户密码 + */ + @Column(name = "password_") + private String password; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java index 0f2d67f0..d41788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java @@ -25,6 +25,7 @@ import org.hibernate.annotations.TypeDef; import com.vladmihalcea.hibernate.type.json.JsonStringType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; import cn.topiam.employee.support.repository.domain.BaseEntity; import lombok.Getter; @@ -50,12 +51,24 @@ public class AppCasConfigEntity extends BaseEntity { * APP ID */ @Column(name = "app_id") - private Long appId; + private Long appId; /** - * SP 接受回调地址 + * 用户身份类型 */ - @Column(name = "sp_callback_url") - private String spCallbackUrl; + @Column(name = "user_identity_type") + private CasUserIdentityType userIdentityType; + + /** + * 客户端服务URL + */ + @Column(name = "client_service_url") + private String clientServiceUrl; + + /** + * serviceTicket 过期时间(秒) + */ + @Column(name = "service_ticket_expire_time") + private Integer serviceTicketExpireTime; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java index b4b69aae..81111318 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @author TopIAM @@ -42,7 +48,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_cert") -public class AppCertEntity extends BaseEntity { +@SQLDelete(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppCertEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java index 1367c07b..c784481e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app") -public class AppEntity extends BaseEntity { +@SQLDelete(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppEntity extends LogicDeleteEntity { /** * 应用名称 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java new file mode 100644 index 00000000..2fa6c528 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java @@ -0,0 +1,107 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_form_config") +@SQLDelete(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppFormConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录URL + */ + @Column(name = "login_url") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Column(name = "username_field") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Column(name = "password_field") + private String passwordField; + + /** + * 登录提交方式 + */ + @Column(name = "submit_type") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Column(name = "other_field") + @Type(type = "json") + private List otherField; + + @Data + @Schema(description = "表单其他信息") + public static class OtherField implements Serializable { + + private String fieldName; + + private String fieldValue; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java index efedbf1b..b1d60aab 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java @@ -23,17 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.vladmihalcea.hibernate.type.json.JsonStringType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP OIDC 配置 @@ -47,8 +48,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_oidc_config") +@SQLDelete(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppOidcConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppOidcConfigEntity extends LogicDeleteEntity { /** * APP ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java index 097bfeb1..7c6cf858 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java @@ -21,13 +21,19 @@ import java.io.Serial; import javax.persistence.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PermissionActionType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用权限 @@ -40,8 +46,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_action`") -public class AppPermissionActionEntity extends BaseEntity { +@Table(name = "app_permission_action") +@SQLDelete(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionActionEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3954680915360748087L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java index f8b51c68..50aa2c82 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java @@ -21,15 +21,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicyEffect; import cn.topiam.employee.common.enums.PolicyObjectType; import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用策略 @@ -42,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_policy`") -public class AppPermissionPolicyEntity extends BaseEntity { +@Table(name = "app_permission_policy") +@SQLDelete(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionPolicyEntity extends LogicDeleteEntity { /** * 应用id diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java index 4ebea00b..f9f4e994 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java @@ -22,7 +22,11 @@ import java.util.List; import javax.persistence.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; @@ -30,6 +34,9 @@ import lombok.ToString; import lombok.experimental.Accessors; import static javax.persistence.FetchType.LAZY; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + /** * * 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -46,8 +52,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`user_history_password`") -public class UserHistoryPasswordEntity extends BaseEntity { +@Table(name = "user_history_password") +@SQLDelete(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_history_password set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class UserHistoryPasswordEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java index 1171373c..d06bf831 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/account/UserIdpBindEntity.java @@ -24,13 +24,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 用户认证方式绑定表 @@ -40,47 +45,50 @@ import lombok.experimental.Accessors; */ @Entity @Table(name = "user_idp_bind") +@SQLDelete(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update user_idp_bind set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) @Accessors(chain = true) @Getter @Setter @ToString -public class UserIdpBindEntity extends BaseEntity { +public class UserIdpBindEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -14364708756807242L; + private static final long serialVersionUID = -14364708756807242L; /** * 用户ID */ @Column(name = "user_id") - private Long userId; + private Long userId; /** * OpenId */ @Column(name = "open_id") - private String openId; + private String openId; /** * 身份提供商 ID */ @Column(name = "idp_id") - private String idpId; + private String idpId; /** * 身份提供商 类型 */ @Column(name = "idp_type") - private IdentityProviderType idpType; + private String idpType; /** * 绑定时间 */ @Column(name = "bind_time") - private LocalDateTime bindTime; + private LocalDateTime bindTime; /** * 附加信息 */ @Column(name = "addition_info") - private String additionInfo; + private String additionInfo; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java index 823e2494..4def668b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccessPolicyEntity.java @@ -21,13 +21,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用授权策略 @@ -41,7 +47,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_access_policy") -public class AppAccessPolicyEntity extends BaseEntity { +@SQLDelete(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_access_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccessPolicyEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java index 41252ea6..84ca85f5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppAccountEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用账户 @@ -40,7 +46,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_account") -public class AppAccountEntity extends BaseEntity { +@SQLDelete(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_account set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppAccountEntity extends LogicDeleteEntity { /** * 应用ID */ @@ -58,4 +67,10 @@ public class AppAccountEntity extends BaseEntity { */ @Column(name = "account_") private String account; + + /** + * 账户密码 + */ + @Column(name = "password_") + private String password; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java index 0f2d67f0..d41788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCasConfigEntity.java @@ -25,6 +25,7 @@ import org.hibernate.annotations.TypeDef; import com.vladmihalcea.hibernate.type.json.JsonStringType; +import cn.topiam.employee.common.enums.app.CasUserIdentityType; import cn.topiam.employee.support.repository.domain.BaseEntity; import lombok.Getter; @@ -50,12 +51,24 @@ public class AppCasConfigEntity extends BaseEntity { * APP ID */ @Column(name = "app_id") - private Long appId; + private Long appId; /** - * SP 接受回调地址 + * 用户身份类型 */ - @Column(name = "sp_callback_url") - private String spCallbackUrl; + @Column(name = "user_identity_type") + private CasUserIdentityType userIdentityType; + + /** + * 客户端服务URL + */ + @Column(name = "client_service_url") + private String clientServiceUrl; + + /** + * serviceTicket 过期时间(秒) + */ + @Column(name = "service_ticket_expire_time") + private Integer serviceTicketExpireTime; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java index b4b69aae..81111318 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppCertEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppCertUsingType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @author TopIAM @@ -42,7 +48,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_cert") -public class AppCertEntity extends BaseEntity { +@SQLDelete(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_cert set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppCertEntity extends LogicDeleteEntity { /** * 应用ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java index 1367c07b..c784481e 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.app.AppProtocol; import cn.topiam.employee.common.enums.app.AppType; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app") -public class AppEntity extends BaseEntity { +@SQLDelete(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppEntity extends LogicDeleteEntity { /** * 应用名称 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java new file mode 100644 index 00000000..2fa6c528 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppFormConfigEntity.java @@ -0,0 +1,107 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.common.enums.app.FormSubmitType; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_form_config") +@SQLDelete(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_form_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppFormConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录URL + */ + @Column(name = "login_url") + private String loginUrl; + + /** + * 登录名属性名称 + */ + @Column(name = "username_field") + private String usernameField; + + /** + * 登录密码属性名称 + */ + @Column(name = "password_field") + private String passwordField; + + /** + * 登录提交方式 + */ + @Column(name = "submit_type") + private FormSubmitType submitType; + + /** + * 登录其他信息 + */ + @Column(name = "other_field") + @Type(type = "json") + private List otherField; + + @Data + @Schema(description = "表单其他信息") + public static class OtherField implements Serializable { + + private String fieldName; + + private String fieldValue; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java index efedbf1b..b1d60aab 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppOidcConfigEntity.java @@ -23,17 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.vladmihalcea.hibernate.type.json.JsonStringType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP OIDC 配置 @@ -47,8 +48,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_oidc_config") +@SQLDelete(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_oidc_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppOidcConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppOidcConfigEntity extends LogicDeleteEntity { /** * APP ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java index 097bfeb1..7c6cf858 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionActionEntity.java @@ -21,13 +21,19 @@ import java.io.Serial; import javax.persistence.*; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PermissionActionType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用权限 @@ -40,8 +46,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_action`") -public class AppPermissionActionEntity extends BaseEntity { +@Table(name = "app_permission_action") +@SQLDelete(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_action set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionActionEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -3954680915360748087L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java index f8b51c68..50aa2c82 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionPolicyEntity.java @@ -21,15 +21,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.PolicyEffect; import cn.topiam.employee.common.enums.PolicyObjectType; import cn.topiam.employee.common.enums.PolicySubjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 应用策略 @@ -42,8 +48,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_policy`") -public class AppPermissionPolicyEntity extends BaseEntity { +@Table(name = "app_permission_policy") +@SQLDelete(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_policy set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionPolicyEntity extends LogicDeleteEntity { /** * 应用id diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java index 4ebea00b..f9f4e994 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionResourceEntity.java @@ -22,7 +22,11 @@ import java.util.List; import javax.persistence.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; @@ -30,6 +34,9 @@ import lombok.ToString; import lombok.experimental.Accessors; import static javax.persistence.FetchType.LAZY; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + /** * * 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
* 应用资源关联 @@ -43,8 +50,11 @@ import static javax.persistence.FetchType.LAZY; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_resource`") -public class AppPermissionResourceEntity extends BaseEntity { +@Table(name = "app_permission_resource") +@SQLDelete(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_resource set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionResourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 7342074686605139968L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java index cf01d0d3..3b36e343 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppPermissionRoleEntity.java @@ -23,12 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -43,8 +49,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`app_permission_role`") -public class AppPermissionRoleEntity extends BaseEntity { +@Table(name = "app_permission_role") +@SQLDelete(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_permission_role set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AppPermissionRoleEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7761332532995424593L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java index 935ede51..c22920e9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppSaml2ConfigEntity.java @@ -26,20 +26,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.*; import com.fasterxml.jackson.annotation.JsonAlias; import com.vladmihalcea.hibernate.type.json.JsonStringType; import cn.topiam.employee.common.enums.app.*; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * APP SAML 配置 @@ -53,8 +54,11 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "app_saml2_config") +@SQLDelete(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_saml2_config set " + SOFT_DELETE_SET + " where id_ = ?") @TypeDef(name = "json", typeClass = JsonStringType.class) -public class AppSaml2ConfigEntity extends BaseEntity { +@Where(clause = SOFT_DELETE_WHERE) +public class AppSaml2ConfigEntity extends LogicDeleteEntity { /** * APP ID */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java new file mode 100644 index 00000000..06993dc4 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/AppTsaConfigEntity.java @@ -0,0 +1,128 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.entity.app; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +import org.hibernate.annotations.*; + +import com.vladmihalcea.hibernate.type.json.JsonStringType; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +import io.swagger.v3.oas.annotations.media.Schema; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; + +/** + * APP Form 配置 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/12/13 22:31 + */ +@Getter +@Setter +@ToString +@Entity +@Accessors(chain = true) +@Table(name = "app_tsa_config") +@SQLDelete(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update app_tsa_config set " + SOFT_DELETE_SET + " where id_ = ?") +@TypeDef(name = "json", typeClass = JsonStringType.class) +@Where(clause = SOFT_DELETE_WHERE) +public class AppTsaConfigEntity extends LogicDeleteEntity { + + /** + * APP ID + */ + @Column(name = "app_id") + private Long appId; + + /** + * 登录页面 + */ + @Column(name = "login_page") + private String loginPage; + + /** + * 自动登录步骤 + */ + @Column(name = "auto_login_steps") + @Type(type = "json") + private List autoLoginSteps; + + /** + * 创建账号步骤 + */ + @Column(name = "create_account_steps") + @Type(type = "json") + private List createAccountSteps; + + @Data + @Schema(description = "自动登录步骤") + public static class AutoLoginStep implements Serializable { + + private String action; + + private String target; + + private String value; + } + + @Data + @Schema(description = "创建账号步骤") + public static class CreateAccountStep implements Serializable { + + private String title; + + private String titleI18n; + + private FormItemProp formItemProps; + } + + @Data + @Schema(description = "表单内容") + public static class FormItemProp implements Serializable { + + private List name; + + private List rules; + } + + @Data + @Schema(description = "表单验证规则") + public static class Rule implements Serializable { + + private Boolean required; + + private String message; + + private String messageI18n; + } +} diff --git a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java similarity index 60% rename from eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java index 89635696..c15d5cbd 100644 --- a/eiam-application/eiam-application-form/src/main/java/cn/topiam/employee/application/form/model/AppFormConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppFormConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-form - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,42 +15,61 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.form.model; - -import java.io.Serializable; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppFormConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** - * Form 配置返回 * * @author TopIAM - * Created by support@topiam.cn on 2022/5/31 22:46 + * Created by support@topiam.cn on 2022/12/13 23:45 */ @Data -@Schema(description = "Form 配置返回结果") -public class AppFormConfigGetResult implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class AppFormConfigPO extends AppFormConfigEntity { + + /** + * 应用编码 + */ + private String appCode; + + /** + * 模版 + */ + private String appTemplate; + + /** + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + /** * SSO 发起方 */ - @Parameter(description = "SSO 发起方") private InitLoginType initLoginType; /** * SSO 登录链接 */ - @Parameter(description = "SSO 登录链接") private String initLoginUrl; /** * 授权范围 */ - @Parameter(description = "SSO 授权范围") private AuthorizationType authorizationType; + + /** + * 应用是否启用 + */ + private Boolean enabled; } diff --git a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java similarity index 53% rename from eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java index f4815280..65edad5e 100644 --- a/eiam-application/eiam-application-cas/src/main/java/cn/topiam/employee/application/cas/model/AppCasStandardConfigGetResult.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/app/po/AppTsaConfigPO.java @@ -1,5 +1,5 @@ /* - * eiam-application-cas - Employee Identity and Access Management Program + * eiam-common - Employee Identity and Access Management Program * Copyright © 2020-2023 TopIAM (support@topiam.cn) * * This program is free software: you can redistribute it and/or modify @@ -15,50 +15,60 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.application.cas.model; +package cn.topiam.employee.common.entity.app.po; +import cn.topiam.employee.common.entity.app.AppTsaConfigEntity; import cn.topiam.employee.common.enums.app.AuthorizationType; -import cn.topiam.employee.common.enums.app.InitLoginType; import lombok.Data; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; +import lombok.EqualsAndHashCode; /** + * * @author TopIAM - * Created by support@topiam.cn on 2023/1/2 22:23 + * Created by support@topiam.cn on 2022/01/14 10:45 */ @Data -@Schema(description = "CAS 配置返回结果") -public class AppCasStandardConfigGetResult { +@EqualsAndHashCode(callSuper = true) +public class AppTsaConfigPO extends AppTsaConfigEntity { /** - * 应用ID + * 应用编码 */ - @Schema(description = "授权类型") - private AuthorizationType authorizationType; + private String appCode; /** - * SSO 发起登录类型 + * 模版 */ - @Schema(description = "SSO 发起登录类型") - private InitLoginType initLoginType; + private String appTemplate; /** - * SSO 发起登录URL + * 客户端ID + */ + private String clientId; + + /** + * 客户端秘钥 + */ + private String clientSecret; + + // /** + // * SSO 发起方 + // */ + // private InitLoginType initLoginType; + + /** + * SSO 登录链接 */ - @Schema(description = "SSO 发起登录URL") private String initLoginUrl; /** - * 单点登录 SP 回调地址 + * 授权范围 */ - @Parameter(name = "单点登录 sp Callback Url") - private String spCallbackUrl; + private AuthorizationType authorizationType; /** - * Server端配置前缀 + * 应用是否启用 */ - private String serverUrlPrefix; + private Boolean enabled; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java index 4bb9876e..4e77e331 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/authentication/IdentityProviderEntity.java @@ -23,14 +23,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.common.enums.IdentityProviderCategory; -import cn.topiam.employee.common.enums.IdentityProviderType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -46,51 +50,54 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "identity_provider") -public class IdentityProviderEntity extends BaseEntity { +@SQLDelete(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_provider set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentityProviderEntity extends LogicDeleteEntity { @Serial - private static final long serialVersionUID = -7936931011805155568L; + private static final long serialVersionUID = -7936931011805155568L; /** * 名称 */ @Column(name = "name_") - private String name; + private String name; /** * 唯一CODE 不可修改 */ @Column(name = "code_") - private String code; + private String code; /** * 平台 */ @Column(name = "type_") - private IdentityProviderType type; + private String type; /** * 分类 */ @Column(name = "category_") - private IdentityProviderCategory category; + private String category; /** * 配置JSON串 */ @Column(name = "config_") - private String config; + private String config; /** * 是否启用 */ @Column(name = "is_enabled") - private Boolean enabled; + private Boolean enabled; /** * 是否展示 */ @Column(name = "is_displayed") - private Boolean displayed; + private Boolean displayed; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java index 18056331..d6b4f15d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEntity.java @@ -23,18 +23,23 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.Type; +import org.hibernate.annotations.Where; import cn.topiam.employee.common.entity.identitysource.config.JobConfig; import cn.topiam.employee.common.entity.identitysource.config.StrategyConfig; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -51,7 +56,10 @@ import lombok.extern.slf4j.Slf4j; @Accessors(chain = true) @Slf4j @Table(name = "identity_source") -public class IdentitySourceEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -7936931011805155568L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java index 31559b40..a08fa618 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceEventRecordEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源事件记录 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_event_record") -public class IdentitySourceEventRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_event_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceEventRecordEntity extends LogicDeleteEntity { /** * 身份源ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java index 0b458833..9c22cc9d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncHistoryEntity.java @@ -23,16 +23,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.TriggerType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步记录表 @@ -47,7 +53,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_history") -public class IdentitySourceSyncHistoryEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_history set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncHistoryEntity extends LogicDeleteEntity { /** * 批号 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java index 89f94eb6..b47e3614 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/IdentitySourceSyncRecordEntity.java @@ -21,16 +21,22 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.SyncStatus; import cn.topiam.employee.common.enums.identitysource.IdentitySourceActionType; import cn.topiam.employee.common.enums.identitysource.IdentitySourceObjectType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 身份源同步详情 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Accessors(chain = true) @NoArgsConstructor @Table(name = "identity_source_sync_record") -public class IdentitySourceSyncRecordEntity extends BaseEntity { +@SQLDelete(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update identity_source_sync_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class IdentitySourceSyncRecordEntity extends LogicDeleteEntity { /** * 同步历史ID diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java index d5256f71..0e546e29 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/identitysource/config/JobConfig.java @@ -170,14 +170,14 @@ public class JobConfig { } } //模式为定时 解析时分秒 - if (mode.equals(JobConfig.Mode.timed)) { + if (mode.equals(Mode.timed)) { LocalTime time = LocalTime.parse(value, DateTimeFormatter.ofPattern("H[H]:mm:ss")); hour = on(time.getHour()); minute = on(time.getMinute()); second = on(time.getSecond()); } //模式为周期(0- 某个小时)执行 - if (mode.equals(JobConfig.Mode.period)) { + if (mode.equals(Mode.period)) { hour = new Every(on(0), new IntegerFieldValue(Integer.parseInt(value))); minute = on(0); second = on(0); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java similarity index 74% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java index c5eec298..cfa788fe 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/MailSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/MailSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,14 +23,20 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.message.enums.MailProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 邮件发送记录 @@ -44,7 +50,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "mail_send_record") -public class MailSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailSendRecordEntity extends LogicDeleteEntity { /** * subject */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java rename to eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java index 915df827..a6c741b8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/SmsSendRecordEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/message/SmsSendRecordEntity.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.entity; +package cn.topiam.employee.common.entity.message; import java.time.LocalDateTime; @@ -23,15 +23,21 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MessageCategory; import cn.topiam.employee.common.enums.SmsType; import cn.topiam.employee.common.message.enums.SmsProvider; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * 短信记录发送表 @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Setter @ToString @Table(name = "sms_send_record") -public class SmsSendRecordEntity extends BaseEntity { +@SQLDelete(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update sms_send_record set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SmsSendRecordEntity extends LogicDeleteEntity { /** * phone_ */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java index a3c436ce..f41c5849 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/AdministratorEntity.java @@ -24,13 +24,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.UserStatus; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -45,8 +51,11 @@ import lombok.experimental.Accessors; @ToString @Accessors(chain = true) @Entity -@Table(name = "`administrator`") -public class AdministratorEntity extends BaseEntity { +@Table(name = "administrator") +@SQLDelete(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update administrator set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class AdministratorEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = -2619231849746900857L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java index e664e9ce..f9f60324 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/MailTemplateEntity.java @@ -23,13 +23,19 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + import cn.topiam.employee.common.enums.MailType; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -45,7 +51,10 @@ import lombok.experimental.Accessors; @Entity @Accessors(chain = true) @Table(name = "mail_template") -public class MailTemplateEntity extends BaseEntity { +@SQLDelete(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update mail_template set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class MailTemplateEntity extends LogicDeleteEntity { @Serial private static final long serialVersionUID = 5983857137670090984L; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java index 3ceb0101..9a1b2cf9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/entity/setting/SettingEntity.java @@ -21,12 +21,18 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import cn.topiam.employee.support.repository.domain.BaseEntity; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLDeleteAll; +import org.hibernate.annotations.Where; + +import cn.topiam.employee.support.repository.domain.LogicDeleteEntity; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -41,8 +47,11 @@ import lombok.experimental.Accessors; @ToString @Entity @Accessors(chain = true) -@Table(name = "`setting`") -public class SettingEntity extends BaseEntity { +@Table(name = "setting") +@SQLDelete(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@SQLDeleteAll(sql = "update setting set " + SOFT_DELETE_SET + " where id_ = ?") +@Where(clause = SOFT_DELETE_WHERE) +public class SettingEntity extends LogicDeleteEntity { /** * name diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java deleted file mode 100644 index ef43433c..00000000 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/IdentityProviderType.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * eiam-common - Employee Identity and Access Management Program - * Copyright © 2020-2023 TopIAM (support@topiam.cn) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package cn.topiam.employee.common.enums; - -import com.fasterxml.jackson.annotation.JsonValue; - -import cn.topiam.employee.support.web.converter.EnumConvert; -import static cn.topiam.employee.common.constants.AuthorizeConstants.AUTHORIZATION_REQUEST_URI; -import static cn.topiam.employee.common.constants.AuthorizeConstants.LOGIN_PATH; - -/** - * 认证提供商 - * - * @author TopIAM - * Created by support@topiam.cn on 2020/8/13 22:18 - */ -public enum IdentityProviderType implements BaseEnum { - /** - * 微信扫码登录 - */ - WECHAT_SCAN_CODE("wechat_scan_code", "微信扫码登录", - "通过微信扫码进行身份认证"), - /** - * 钉钉扫码登录 - */ - DINGTALK_SCAN_CODE("dingtalk_scan_code", - "钉钉扫码认证", - - "通过钉钉扫码进行身份认证"), - /** - * 钉钉Oauth2 - */ - DINGTALK_OAUTH("dingtalk_oauth", "钉钉Oauth认证", - "通过钉钉进行身份认证"), - /** - * 企业微信 - */ - WECHATWORK_SCAN_CODE("wechatwork_scan_code", - "企业微信扫码认证", - - "通过企业微信同步的用户可使用企业微信扫码登录进行身份认证"), - /** - * QQ - */ - QQ("qq_oauth", "QQ认证", "通过QQ进行身份认证"), - /** - * 微博 - */ - WEIBO("weibo_oauth", "微博认证", "通过微博进行身份认证"), - /** - * Github - */ - GITHUB("github_oauth", "Github", - "通过 GitHub 进行身份认证"), - /** - * Google - */ - GOOGLE("google_oauth", "Google", - "通过 Google 进行身份认证"), - /** - * 支付宝扫码认证 - */ - ALIPAY("alipay_oauth", "支付宝认证", - "通过支付宝进行身份认证"), - - /** - * LDAP - */ - LDAP("ldap", "LDAP 认证源", "通过 LDAP 认证源进行身份验证"); - - @JsonValue - private final String code; - private final String name; - private final String desc; - - IdentityProviderType(String code, String name, String desc) { - this.code = code; - this.name = name; - this.desc = desc; - } - - public String getCode() { - return code; - } - - public String getName() { - return name; - } - - public String getDesc() { - return desc; - } - - public String getAuthorizationPathPrefix() { - return AUTHORIZATION_REQUEST_URI + "/" + getCode(); - } - - public String getLoginPathPrefix() { - return LOGIN_PATH + "/" + getCode(); - } - - /** - * 获取认证平台 - * - * @param code {@link String} - * @return {@link IdentityProviderType} - */ - @EnumConvert - public static IdentityProviderType getType(String code) { - IdentityProviderType[] values = values(); - for (IdentityProviderType status : values) { - if (String.valueOf(status.getCode()).equals(code)) { - return status; - } - } - return null; - } -} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java index 13703bcf..b989c177 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/ListEnumDeserializer.java @@ -22,7 +22,10 @@ import java.lang.reflect.Field; import java.util.*; import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; import com.fasterxml.jackson.databind.node.ArrayNode; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java index ce3e2b8a..0ffdfac5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/SmsType.java @@ -63,7 +63,7 @@ public enum SmsType implements BaseEnum { RESET_PASSWORD_SUCCESS("reset_password_success", "重置密码成功", MessageCategory.NOTICE), /** - * 登录验证 未使用 + * 登录验证 */ LOGIN("login", "登录验证", MessageCategory.CODE), diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java index ff0f8a0e..6af6e6fb 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppProtocol.java @@ -52,7 +52,12 @@ public enum AppProtocol implements BaseEnum { /** * FORM表单 */ - FORM("form", "表单代填"); + FORM("form", "表单代填"), + + /** + * TSA + */ + TSA("tsa", "TSA"); @JsonValue private final String code; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java index a7d53320..59ea6fe9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/AppType.java @@ -42,7 +42,11 @@ public enum AppType implements BaseEnum { /** * 自研 */ - SELF_DEVELOPED("self_developed", "自研应用"); + SELF_DEVELOPED("self_developed", "自研应用"), + /** + * TSA + */ + TSA("tsa", "TSA"),; /** * code diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java new file mode 100644 index 00000000..06d94c9e --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/CasUserIdentityType.java @@ -0,0 +1,78 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * Cas 用户标识类型 + * + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:49 + */ +public enum CasUserIdentityType { + /** + * 用户名 + */ + USER_USERNAME("user.username"), + /** + * 姓名 + */ + USER_FULL_NAME("user.fullName"), + /** + * 昵称 + */ + USER_NICK_NAME("user.nickName"), + /** + * 邮箱 + */ + USER_EMAIL("user.email"), + /** + * 应用账户 + */ + APP_USERNAME("app_user.username"); + + @JsonValue + private final String code; + + CasUserIdentityType(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + + @EnumConvert + public static CasUserIdentityType getType(String code) { + CasUserIdentityType[] values = values(); + for (CasUserIdentityType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java new file mode 100644 index 00000000..00964ace --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/FormSubmitType.java @@ -0,0 +1,84 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app; + +import com.fasterxml.jackson.annotation.JsonValue; + +import cn.topiam.employee.common.enums.BaseEnum; +import cn.topiam.employee.support.web.converter.EnumConvert; + +/** + * + * @author SanLi + * Created by qinggang.zuo@gmail.com / 2689170096@qq.com on 2022/12/21 17:20 + */ +public enum FormSubmitType implements BaseEnum { + /** + * POST + */ + POST("post", "POST"), + /** + * GET + */ + GET("get", "GET"); + + /** + * code + */ + @JsonValue + private final String code; + /** + * desc + */ + private final String desc; + + FormSubmitType(String code, String desc) { + this.code = code; + this.desc = desc; + } + + public String getCode() { + return code; + } + + public String getDesc() { + return desc; + } + + /** + * 获取类型 + * + * @param code {@link String} + * @return {@link InitLoginType} + */ + @EnumConvert + public static FormSubmitType getType(String code) { + FormSubmitType[] values = values(); + for (FormSubmitType status : values) { + if (String.valueOf(status.getCode()).equals(code)) { + return status; + } + } + return null; + } + + @Override + public String toString() { + return this.code; + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java index 7a437e0d..2093768d 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/InitLoginType.java @@ -53,10 +53,12 @@ public enum InitLoginType implements BaseEnum { this.desc = desc; } + @Override public String getCode() { return code; } + @Override public String getDesc() { return desc; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java new file mode 100644 index 00000000..c46fdfff --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/CasUserIdentityTypeConverter.java @@ -0,0 +1,46 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.enums.app.converter; + +import java.util.Objects; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import cn.topiam.employee.common.enums.app.CasUserIdentityType; + +/** + * @author TopIAM + * Created by support@topiam.cn on 2022/5/22 23:25 + */ +@Converter(autoApply = true) +public class CasUserIdentityTypeConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(CasUserIdentityType attribute) { + if (Objects.isNull(attribute)) { + return null; + } + return attribute.getCode(); + } + + @Override + public CasUserIdentityType convertToEntityAttribute(String dbData) { + return CasUserIdentityType.getType(dbData); + } +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java similarity index 75% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java index cae8b060..b983e49a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/converter/IdentityProviderTypeConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/app/converter/FormSubmitTypeConverter.java @@ -15,22 +15,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.converter; +package cn.topiam.employee.common.enums.app.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.IdentityProviderType; +import cn.topiam.employee.common.enums.app.FormSubmitType; /** * @author TopIAM - * Created by support@topiam.cn on 2020/12/11 19:42 + * Created by support@topiam.cn on 2020/12/11 23:48 */ @Converter(autoApply = true) -public class IdentityProviderTypeConverter implements - AttributeConverter { +public class FormSubmitTypeConverter implements AttributeConverter { /** * Converts the value stored in the entity attribute into the @@ -41,11 +40,11 @@ public class IdentityProviderTypeConverter implements * column */ @Override - public String convertToDatabaseColumn(IdentityProviderType attribute) { - if (!Objects.isNull(attribute)) { - return attribute.getCode(); + public String convertToDatabaseColumn(FormSubmitType attribute) { + if (Objects.isNull(attribute)) { + return null; } - return null; + return attribute.getCode(); } /** @@ -62,7 +61,7 @@ public class IdentityProviderTypeConverter implements * attribute */ @Override - public IdentityProviderType convertToEntityAttribute(String dbData) { - return IdentityProviderType.getType(dbData); + public FormSubmitType convertToEntityAttribute(String dbData) { + return FormSubmitType.getType(dbData); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java similarity index 98% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java index e38c3372..67e09ef4 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/IdentitySourceProvider.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/IdentitySourceProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider; +package cn.topiam.employee.common.enums.identitysource; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java similarity index 94% rename from eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java rename to eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java index 73225c17..186dbdbd 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/enums/identityprovider/converter/IdentitySourceProviderConverter.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/enums/identitysource/converter/IdentitySourceProviderConverter.java @@ -15,14 +15,14 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package cn.topiam.employee.common.enums.identityprovider.converter; +package cn.topiam.employee.common.enums.identitysource.converter; import java.util.Objects; import javax.persistence.AttributeConverter; import javax.persistence.Converter; -import cn.topiam.employee.common.enums.identityprovider.IdentitySourceProvider; +import cn.topiam.employee.common.enums.identitysource.IdentitySourceProvider; /** * 身份源提供商 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java new file mode 100644 index 00000000..aa4c0546 --- /dev/null +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/District.java @@ -0,0 +1,739 @@ +/* + * eiam-common - Employee Identity and Access Management Program + * Copyright © 2020-2023 TopIAM (support@topiam.cn) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package cn.topiam.employee.common.geo; + +import java.util.HashMap; +import java.util.Map; + +/** + * GeoLocationResponse + * + * @author TopIAM + * Created by support@topiam.cn on 2023/02/04 14:19 + */ +public final class District { + public static final Map PROVINCE_DISTRICT = new HashMap<>() { + { + put("北京市", "110000"); + put("天津市", "120000"); + put("河北省", "130000"); + put(" 石家庄市", "130100"); + put(" 唐山市", "130200"); + put(" 秦皇岛市", "130300"); + put(" 邯郸市", "130400"); + put(" 邢台市", "130500"); + put(" 保定市", "130600"); + put(" 张家口市", "130700"); + put(" 承德市", "130800"); + put(" 沧州市", "130900"); + put(" 廊坊市", "131000"); + put(" 衡水市", "131100"); + put("山西省", "140000"); + put(" 太原市", "140100"); + put(" 大同市", "140200"); + put(" 阳泉市", "140300"); + put(" 长治市", "140400"); + put(" 晋城市", "140500"); + put(" 朔州市", "140600"); + put(" 晋中市", "140700"); + put(" 运城市", "140800"); + put(" 忻州市", "140900"); + put(" 临汾市", "141000"); + put(" 吕梁市", "141100"); + put("内蒙古自治区", "150000"); + put(" 呼和浩特市", "150100"); + put(" 包头市", "150200"); + put(" 乌海市", "150300"); + put(" 赤峰市", "150400"); + put(" 通辽市", "150500"); + put(" 鄂尔多斯市", "150600"); + put(" 呼伦贝尔市", "150700"); + put(" 巴彦淖尔市", "150800"); + put(" 乌兰察布市", "150900"); + put(" 兴安盟", "152200"); + put(" 锡林郭勒盟", "152500"); + put(" 阿拉善盟", "152900"); + put("辽宁省", "210000"); + put(" 沈阳市", "210100"); + put(" 大连市", "210200"); + put(" 鞍山市", "210300"); + put(" 抚顺市", "210400"); + put(" 本溪市", "210500"); + put(" 丹东市", "210600"); + put(" 锦州市", "210700"); + put(" 营口市", "210800"); + put(" 阜新市", "210900"); + put(" 辽阳市", "211000"); + put(" 盘锦市", "211100"); + put(" 铁岭市", "211200"); + put(" 朝阳市", "211300"); + put(" 葫芦岛市", "211400"); + put("吉林省", "220000"); + put(" 长春市", "220100"); + put(" 吉林市", "220200"); + put(" 四平市", "220300"); + put(" 辽源市", "220400"); + put(" 通化市", "220500"); + put(" 白山市", "220600"); + put(" 松原市", "220700"); + put(" 白城市", "220800"); + put(" 延边朝鲜族自治州", "222400"); + put("黑龙江省", "230000"); + put(" 哈尔滨市", "230100"); + put(" 齐齐哈尔市", "230200"); + put(" 鸡西市", "230300"); + put(" 鹤岗市", "230400"); + put(" 双鸭山市", "230500"); + put(" 大庆市", "230600"); + put(" 伊春市", "230700"); + put(" 佳木斯市", "230800"); + put(" 七台河市", "230900"); + put(" 牡丹江市", "231000"); + put(" 黑河市", "231100"); + put(" 绥化市", "231200"); + put(" 大兴安岭地区", "232700"); + put("上海市", "310000"); + put("江苏省", "320000"); + put(" 南京市", "320100"); + put(" 无锡市", "320200"); + put(" 徐州市", "320300"); + put(" 常州市", "320400"); + put(" 苏州市", "320500"); + put(" 南通市", "320600"); + put(" 连云港市", "320700"); + put(" 淮安市", "320800"); + put(" 盐城市", "320900"); + put(" 扬州市", "321000"); + put(" 镇江市", "321100"); + put(" 泰州市", "321200"); + put(" 宿迁市", "321300"); + put("浙江省", "330000"); + put(" 杭州市", "330100"); + put(" 宁波市", "330200"); + put(" 温州市", "330300"); + put(" 嘉兴市", "330400"); + put(" 湖州市", "330500"); + put(" 绍兴市", "330600"); + put(" 金华市", "330700"); + put(" 衢州市", "330800"); + put(" 舟山市", "330900"); + put(" 台州市", "331000"); + put(" 丽水市", "331100"); + put("安徽省", "340000"); + put(" 合肥市", "340100"); + put(" 芜湖市", "340200"); + put(" 蚌埠市", "340300"); + put(" 淮南市", "340400"); + put(" 马鞍山市", "340500"); + put(" 淮北市", "340600"); + put(" 铜陵市", "340700"); + put(" 安庆市", "340800"); + put(" 黄山市", "341000"); + put(" 滁州市", "341100"); + put(" 阜阳市", "341200"); + put(" 宿州市", "341300"); + put(" 六安市", "341500"); + put(" 亳州市", "341600"); + put(" 池州市", "341700"); + put(" 宣城市", "341800"); + put("福建省", "350000"); + put(" 福州市", "350100"); + put(" 厦门市", "350200"); + put(" 莆田市", "350300"); + put(" 三明市", "350400"); + put(" 泉州市", "350500"); + put(" 漳州市", "350600"); + put(" 南平市", "350700"); + put(" 龙岩市", "350800"); + put(" 宁德市", "350900"); + put("江西省", "360000"); + put(" 南昌市", "360100"); + put(" 景德镇市", "360200"); + put(" 萍乡市", "360300"); + put(" 九江市", "360400"); + put(" 新余市", "360500"); + put(" 鹰潭市", "360600"); + put(" 赣州市", "360700"); + put(" 吉安市", "360800"); + put(" 宜春市", "360900"); + put(" 抚州市", "361000"); + put(" 上饶市", "361100"); + put("山东省", "370000"); + put(" 济南市", "370100"); + put(" 青岛市", "370200"); + put(" 淄博市", "370300"); + put(" 枣庄市", "370400"); + put(" 东营市", "370500"); + put(" 烟台市", "370600"); + put(" 潍坊市", "370700"); + put(" 济宁市", "370800"); + put(" 泰安市", "370900"); + put(" 威海市", "371000"); + put(" 日照市", "371100"); + put(" 临沂市", "371300"); + put(" 德州市", "371400"); + put(" 聊城市", "371500"); + put(" 滨州市", "371600"); + put(" 菏泽市", "371700"); + put("河南省", "410000"); + put(" 郑州市", "410100"); + put(" 开封市", "410200"); + put(" 洛阳市", "410300"); + put(" 平顶山市", "410400"); + put(" 安阳市", "410500"); + put(" 鹤壁市", "410600"); + put(" 新乡市", "410700"); + put(" 焦作市", "410800"); + put(" 濮阳市", "410900"); + put(" 许昌市", "411000"); + put(" 漯河市", "411100"); + put(" 三门峡市", "411200"); + put(" 南阳市", "411300"); + put(" 商丘市", "411400"); + put(" 信阳市", "411500"); + put(" 周口市", "411600"); + put(" 驻马店市", "411700"); + put("湖北省", "420000"); + put(" 武汉市", "420100"); + put(" 黄石市", "420200"); + put(" 十堰市", "420300"); + put(" 宜昌市", "420500"); + put(" 襄阳市", "420600"); + put(" 鄂州市", "420700"); + put(" 荆门市", "420800"); + put(" 孝感市", "420900"); + put(" 荆州市", "421000"); + put(" 黄冈市", "421100"); + put(" 咸宁市", "421200"); + put(" 随州市", "421300"); + put(" 恩施土家族苗族自治州", "422800"); + put("湖南省", "430000"); + put(" 长沙市", "430100"); + put(" 株洲市", "430200"); + put(" 湘潭市", "430300"); + put(" 衡阳市", "430400"); + put(" 邵阳市", "430500"); + put(" 岳阳市", "430600"); + put(" 常德市", "430700"); + put(" 张家界市", "430800"); + put(" 益阳市", "430900"); + put(" 郴州市", "431000"); + put(" 永州市", "431100"); + put(" 怀化市", "431200"); + put(" 娄底市", "431300"); + put(" 湘西土家族苗族自治州", "433100"); + put("广东省", "440000"); + put(" 广州市", "440100"); + put(" 韶关市", "440200"); + put(" 深圳市", "440300"); + put(" 珠海市", "440400"); + put(" 汕头市", "440500"); + put(" 佛山市", "440600"); + put(" 江门市", "440700"); + put(" 湛江市", "440800"); + put(" 茂名市", "440900"); + put(" 肇庆市", "441200"); + put(" 惠州市", "441300"); + put(" 梅州市", "441400"); + put(" 汕尾市", "441500"); + put(" 河源市", "441600"); + put(" 阳江市", "441700"); + put(" 清远市", "441800"); + put(" 东莞市", "441900"); + put(" 中山市", "442000"); + put(" 潮州市", "445100"); + put(" 揭阳市", "445200"); + put(" 云浮市", "445300"); + put("广西壮族自治区", "450000"); + put(" 南宁市", "450100"); + put(" 柳州市", "450200"); + put(" 桂林市", "450300"); + put(" 梧州市", "450400"); + put(" 北海市", "450500"); + put(" 防城港市", "450600"); + put(" 钦州市", "450700"); + put(" 贵港市", "450800"); + put(" 玉林市", "450900"); + put(" 百色市", "451000"); + put(" 贺州市", "451100"); + put(" 河池市", "451200"); + put(" 来宾市", "451300"); + put(" 崇左市", "451400"); + put("海南省", "460000"); + put(" 海口市", "460100"); + put(" 三亚市", "460200"); + put(" 三沙市", "460300"); + put(" 儋州市", "460400"); + put("重庆市", "500000"); + put("四川省", "510000"); + put(" 成都市", "510100"); + put(" 自贡市", "510300"); + put(" 攀枝花市", "510400"); + put(" 泸州市", "510500"); + put(" 德阳市", "510600"); + put(" 绵阳市", "510700"); + put(" 广元市", "510800"); + put(" 遂宁市", "510900"); + put(" 内江市", "511000"); + put(" 乐山市", "511100"); + put(" 南充市", "511300"); + put(" 眉山市", "511400"); + put(" 宜宾市", "511500"); + put(" 广安市", "511600"); + put(" 达州市", "511700"); + put(" 雅安市", "511800"); + put(" 巴中市", "511900"); + put(" 资阳市", "512000"); + put(" 阿坝藏族羌族自治州", "513200"); + put(" 甘孜藏族自治州", "513300"); + put(" 凉山彝族自治州", "513400"); + put("贵州省", "520000"); + put(" 贵阳市", "520100"); + put(" 六盘水市", "520200"); + put(" 遵义市", "520300"); + put(" 安顺市", "520400"); + put(" 毕节市", "520500"); + put(" 铜仁市", "520600"); + put(" 黔西南布依族苗族自治州", "522300"); + put(" 黔东南苗族侗族自治州", "522600"); + put(" 黔南布依族苗族自治州", "522700"); + put("云南省", "530000"); + put(" 昆明市", "530100"); + put(" 曲靖市", "530300"); + put(" 玉溪市", "530400"); + put(" 保山市", "530500"); + put(" 昭通市", "530600"); + put(" 丽江市", "530700"); + put(" 普洱市", "530800"); + put(" 临沧市", "530900"); + put(" 楚雄彝族自治州", "532300"); + put(" 红河哈尼族彝族自治州", "532500"); + put(" 文山壮族苗族自治州", "532600"); + put(" 西双版纳傣族自治州", "532800"); + put(" 大理白族自治州", "532900"); + put(" 德宏傣族景颇族自治州", "533100"); + put(" 怒江傈僳族自治州", "533300"); + put(" 迪庆藏族自治州", "533400"); + put("西藏自治区", "540000"); + put(" 拉萨市", "540100"); + put(" 日喀则市", "540200"); + put(" 昌都市", "540300"); + put(" 林芝市", "540400"); + put(" 山南市", "540500"); + put(" 那曲市", "540600"); + put(" 阿里地区", "542500"); + put("陕西省", "610000"); + put(" 西安市", "610100"); + put(" 铜川市", "610200"); + put(" 宝鸡市", "610300"); + put(" 咸阳市", "610400"); + put(" 渭南市", "610500"); + put(" 延安市", "610600"); + put(" 汉中市", "610700"); + put(" 榆林市", "610800"); + put(" 安康市", "610900"); + put(" 商洛市", "611000"); + put("甘肃省", "620000"); + put(" 兰州市", "620100"); + put(" 嘉峪关市", "620200"); + put(" 金昌市", "620300"); + put(" 白银市", "620400"); + put(" 天水市", "620500"); + put(" 武威市", "620600"); + put(" 张掖市", "620700"); + put(" 平凉市", "620800"); + put(" 酒泉市", "620900"); + put(" 庆阳市", "621000"); + put(" 定西市", "621100"); + put(" 陇南市", "621200"); + put(" 临夏回族自治州", "622900"); + put(" 甘南藏族自治州", "623000"); + put("青海省", "630000"); + put(" 西宁市", "630100"); + put(" 海东市", "630200"); + put(" 海北藏族自治州", "632200"); + put(" 黄南藏族自治州", "632300"); + put(" 海南藏族自治州", "632500"); + put(" 果洛藏族自治州", "632600"); + put(" 玉树藏族自治州", "632700"); + put(" 海西蒙古族藏族自治州", "632800"); + put("宁夏回族自治区", "640000"); + put(" 银川市", "640100"); + put(" 石嘴山市", "640200"); + put(" 吴忠市", "640300"); + put(" 固原市", "640400"); + put(" 中卫市", "640500"); + put("新疆维吾尔自治区", "650000"); + put(" 乌鲁木齐市", "650100"); + put(" 克拉玛依市", "650200"); + put(" 吐鲁番市", "650400"); + put(" 哈密市", "650500"); + put(" 昌吉回族自治州", "652300"); + put(" 博尔塔拉蒙古自治州", "652700"); + put(" 巴音郭楞蒙古自治州", "652800"); + put(" 阿克苏地区", "652900"); + put(" 克孜勒苏柯尔克孜自治州", "653000"); + put(" 喀什地区", "653100"); + put(" 和田地区", "653200"); + put(" 伊犁哈萨克自治州", "654000"); + put(" 塔城地区", "654200"); + put(" 阿勒泰地区", "654300"); + put("台湾省", "710000"); + put("香港特别行政区", "810000"); + put("澳门特别行政区", "820000"); + } + }; + + public static final Map CITY_DISTRICT = new HashMap<>() { + { + put("石家庄市", "130100"); + put("唐山市", "130200"); + put("秦皇岛市", "130300"); + put("邯郸市", "130400"); + put("邢台市", "130500"); + put("保定市", "130600"); + put("张家口市", "130700"); + put("承德市", "130800"); + put("沧州市", "130900"); + put("廊坊市", "131000"); + put("衡水市", "131100"); + put("太原市", "140100"); + put("大同市", "140200"); + put("阳泉市", "140300"); + put("长治市", "140400"); + put("晋城市", "140500"); + put("朔州市", "140600"); + put("晋中市", "140700"); + put("运城市", "140800"); + put("忻州市", "140900"); + put("临汾市", "141000"); + put("吕梁市", "141100"); + put("呼和浩特市", "150100"); + put("包头市", "150200"); + put("乌海市", "150300"); + put("赤峰市", "150400"); + put("通辽市", "150500"); + put("鄂尔多斯市", "150600"); + put("呼伦贝尔市", "150700"); + put("巴彦淖尔市", "150800"); + put("乌兰察布市", "150900"); + put("兴安盟", "152200"); + put("锡林郭勒盟", "152500"); + put("阿拉善盟", "152900"); + put("沈阳市", "210100"); + put("大连市", "210200"); + put("鞍山市", "210300"); + put("抚顺市", "210400"); + put("本溪市", "210500"); + put("丹东市", "210600"); + put("锦州市", "210700"); + put("营口市", "210800"); + put("阜新市", "210900"); + put("辽阳市", "211000"); + put("盘锦市", "211100"); + put("铁岭市", "211200"); + put("朝阳市", "211300"); + put("葫芦岛市", "211400"); + put("长春市", "220100"); + put("吉林市", "220200"); + put("四平市", "220300"); + put("辽源市", "220400"); + put("通化市", "220500"); + put("白山市", "220600"); + put("松原市", "220700"); + put("白城市", "220800"); + put("延边朝鲜族自治州", "222400"); + put("哈尔滨市", "230100"); + put("齐齐哈尔市", "230200"); + put("鸡西市", "230300"); + put("鹤岗市", "230400"); + put("双鸭山市", "230500"); + put("大庆市", "230600"); + put("伊春市", "230700"); + put("佳木斯市", "230800"); + put("七台河市", "230900"); + put("牡丹江市", "231000"); + put("黑河市", "231100"); + put("绥化市", "231200"); + put("大兴安岭地区", "232700"); + put("南京市", "320100"); + put("无锡市", "320200"); + put("徐州市", "320300"); + put("常州市", "320400"); + put("苏州市", "320500"); + put("南通市", "320600"); + put("连云港市", "320700"); + put("淮安市", "320800"); + put("盐城市", "320900"); + put("扬州市", "321000"); + put("镇江市", "321100"); + put("泰州市", "321200"); + put("宿迁市", "321300"); + put("杭州市", "330100"); + put("宁波市", "330200"); + put("温州市", "330300"); + put("嘉兴市", "330400"); + put("湖州市", "330500"); + put("绍兴市", "330600"); + put("金华市", "330700"); + put("衢州市", "330800"); + put("舟山市", "330900"); + put("台州市", "331000"); + put("丽水市", "331100"); + put("合肥市", "340100"); + put("芜湖市", "340200"); + put("蚌埠市", "340300"); + put("淮南市", "340400"); + put("马鞍山市", "340500"); + put("淮北市", "340600"); + put("铜陵市", "340700"); + put("安庆市", "340800"); + put("黄山市", "341000"); + put("滁州市", "341100"); + put("阜阳市", "341200"); + put("宿州市", "341300"); + put("六安市", "341500"); + put("亳州市", "341600"); + put("池州市", "341700"); + put("宣城市", "341800"); + put("福州市", "350100"); + put("厦门市", "350200"); + put("莆田市", "350300"); + put("三明市", "350400"); + put("泉州市", "350500"); + put("漳州市", "350600"); + put("南平市", "350700"); + put("龙岩市", "350800"); + put("宁德市", "350900"); + put("南昌市", "360100"); + put("景德镇市", "360200"); + put("萍乡市", "360300"); + put("九江市", "360400"); + put("新余市", "360500"); + put("鹰潭市", "360600"); + put("赣州市", "360700"); + put("吉安市", "360800"); + put("宜春市", "360900"); + put("抚州市", "361000"); + put("上饶市", "361100"); + put("济南市", "370100"); + put("青岛市", "370200"); + put("淄博市", "370300"); + put("枣庄市", "370400"); + put("东营市", "370500"); + put("烟台市", "370600"); + put("潍坊市", "370700"); + put("济宁市", "370800"); + put("泰安市", "370900"); + put("威海市", "371000"); + put("日照市", "371100"); + put("临沂市", "371300"); + put("德州市", "371400"); + put("聊城市", "371500"); + put("滨州市", "371600"); + put("菏泽市", "371700"); + put("郑州市", "410100"); + put("开封市", "410200"); + put("洛阳市", "410300"); + put("平顶山市", "410400"); + put("安阳市", "410500"); + put("鹤壁市", "410600"); + put("新乡市", "410700"); + put("焦作市", "410800"); + put("濮阳市", "410900"); + put("许昌市", "411000"); + put("漯河市", "411100"); + put("三门峡市", "411200"); + put("南阳市", "411300"); + put("商丘市", "411400"); + put("信阳市", "411500"); + put("周口市", "411600"); + put("驻马店市", "411700"); + put("武汉市", "420100"); + put("黄石市", "420200"); + put("十堰市", "420300"); + put("宜昌市", "420500"); + put("襄阳市", "420600"); + put("鄂州市", "420700"); + put("荆门市", "420800"); + put("孝感市", "420900"); + put("荆州市", "421000"); + put("黄冈市", "421100"); + put("咸宁市", "421200"); + put("随州市", "421300"); + put("恩施土家族苗族自治州", "422800"); + put("长沙市", "430100"); + put("株洲市", "430200"); + put("湘潭市", "430300"); + put("衡阳市", "430400"); + put("邵阳市", "430500"); + put("岳阳市", "430600"); + put("常德市", "430700"); + put("张家界市", "430800"); + put("益阳市", "430900"); + put("郴州市", "431000"); + put("永州市", "431100"); + put("怀化市", "431200"); + put("娄底市", "431300"); + put("湘西土家族苗族自治州", "433100"); + put("广州市", "440100"); + put("韶关市", "440200"); + put("深圳市", "440300"); + put("珠海市", "440400"); + put("汕头市", "440500"); + put("佛山市", "440600"); + put("江门市", "440700"); + put("湛江市", "440800"); + put("茂名市", "440900"); + put("肇庆市", "441200"); + put("惠州市", "441300"); + put("梅州市", "441400"); + put("汕尾市", "441500"); + put("河源市", "441600"); + put("阳江市", "441700"); + put("清远市", "441800"); + put("东莞市", "441900"); + put("中山市", "442000"); + put("潮州市", "445100"); + put("揭阳市", "445200"); + put("云浮市", "445300"); + put("南宁市", "450100"); + put("柳州市", "450200"); + put("桂林市", "450300"); + put("梧州市", "450400"); + put("北海市", "450500"); + put("防城港市", "450600"); + put("钦州市", "450700"); + put("贵港市", "450800"); + put("玉林市", "450900"); + put("百色市", "451000"); + put("贺州市", "451100"); + put("河池市", "451200"); + put("来宾市", "451300"); + put("崇左市", "451400"); + put("海口市", "460100"); + put("三亚市", "460200"); + put("三沙市", "460300"); + put("儋州市", "460400"); + put("成都市", "510100"); + put("自贡市", "510300"); + put("攀枝花市", "510400"); + put("泸州市", "510500"); + put("德阳市", "510600"); + put("绵阳市", "510700"); + put("广元市", "510800"); + put("遂宁市", "510900"); + put("内江市", "511000"); + put("乐山市", "511100"); + put("南充市", "511300"); + put("眉山市", "511400"); + put("宜宾市", "511500"); + put("广安市", "511600"); + put("达州市", "511700"); + put("雅安市", "511800"); + put("巴中市", "511900"); + put("资阳市", "512000"); + put("阿坝藏族羌族自治州", "513200"); + put("甘孜藏族自治州", "513300"); + put("凉山彝族自治州", "513400"); + put("贵阳市", "520100"); + put("六盘水市", "520200"); + put("遵义市", "520300"); + put("安顺市", "520400"); + put("毕节市", "520500"); + put("铜仁市", "520600"); + put("黔西南布依族苗族自治州", "522300"); + put("黔东南苗族侗族自治州", "522600"); + put("黔南布依族苗族自治州", "522700"); + put("昆明市", "530100"); + put("曲靖市", "530300"); + put("玉溪市", "530400"); + put("保山市", "530500"); + put("昭通市", "530600"); + put("丽江市", "530700"); + put("普洱市", "530800"); + put("临沧市", "530900"); + put("楚雄彝族自治州", "532300"); + put("红河哈尼族彝族自治州", "532500"); + put("文山壮族苗族自治州", "532600"); + put("西双版纳傣族自治州", "532800"); + put("大理白族自治州", "532900"); + put("德宏傣族景颇族自治州", "533100"); + put("怒江傈僳族自治州", "533300"); + put("迪庆藏族自治州", "533400"); + put("拉萨市", "540100"); + put("日喀则市", "540200"); + put("昌都市", "540300"); + put("林芝市", "540400"); + put("山南市", "540500"); + put("那曲市", "540600"); + put("阿里地区", "542500"); + put("西安市", "610100"); + put("铜川市", "610200"); + put("宝鸡市", "610300"); + put("咸阳市", "610400"); + put("渭南市", "610500"); + put("延安市", "610600"); + put("汉中市", "610700"); + put("榆林市", "610800"); + put("安康市", "610900"); + put("商洛市", "611000"); + put("兰州市", "620100"); + put("嘉峪关市", "620200"); + put("金昌市", "620300"); + put("白银市", "620400"); + put("天水市", "620500"); + put("武威市", "620600"); + put("张掖市", "620700"); + put("平凉市", "620800"); + put("酒泉市", "620900"); + put("庆阳市", "621000"); + put("定西市", "621100"); + put("陇南市", "621200"); + put("临夏回族自治州", "622900"); + put("甘南藏族自治州", "623000"); + put("西宁市", "630100"); + put("海东市", "630200"); + put("海北藏族自治州", "632200"); + put("黄南藏族自治州", "632300"); + put("海南藏族自治州", "632500"); + put("果洛藏族自治州", "632600"); + put("玉树藏族自治州", "632700"); + put("海西蒙古族藏族自治州", "632800"); + put("银川市", "640100"); + put("石嘴山市", "640200"); + put("吴忠市", "640300"); + put("固原市", "640400"); + put("中卫市", "640500"); + put("乌鲁木齐市", "650100"); + put("克拉玛依市", "650200"); + put("吐鲁番市", "650400"); + put("哈密市", "650500"); + put("昌吉回族自治州", "652300"); + put("博尔塔拉蒙古自治州", "652700"); + put("巴音郭楞蒙古自治州", "652800"); + put("阿克苏地区", "652900"); + put("克孜勒苏柯尔克孜自治州", "653000"); + put("喀什地区", "653100"); + put("和田地区", "653200"); + put("伊犁哈萨克自治州", "654000"); + put("塔城地区", "654200"); + put("阿勒泰地区", "654300"); + } + }; +} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java index 9102638d..53978e1a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindGeoLocationServiceImpl.java @@ -34,6 +34,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -54,6 +55,8 @@ import lombok.extern.slf4j.Slf4j; import dev.failsafe.Failsafe; import dev.failsafe.RetryPolicy; +import static cn.topiam.employee.common.geo.District.CITY_DISTRICT; +import static cn.topiam.employee.common.geo.District.PROVINCE_DISTRICT; import static cn.topiam.employee.common.geo.maxmind.enums.GeoLocationProvider.MAXMIND; /** @@ -116,9 +119,9 @@ public class MaxmindGeoLocationServiceImpl implements GeoLocationService { .setCountryName(country.getName()) .setCountryCode(country.getGeoNameId().toString()) .setCityName(city.getName()) - .setCityCode(String.valueOf(city.getGeoNameId())) + .setCityCode(StringUtils.defaultString(CITY_DISTRICT.get(city.getName()), String.valueOf(city.getGeoNameId()))) .setProvinceName(subdivision.getName()) - .setProvinceCode(subdivision.getIsoCode()) + .setProvinceCode(StringUtils.defaultString(PROVINCE_DISTRICT.get(subdivision.getName()), subdivision.getIsoCode())) .setLongitude(location.getLongitude()) .setLatitude(location.getLatitude()) .setProvider(MAXMIND); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java index 94e2eb0b..59f95d2c 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/geo/maxmind/MaxmindProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.geo.maxmind; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.geo.GeoLocationProviderConfig; import lombok.Data; @@ -35,6 +36,7 @@ public class MaxmindProviderConfig extends GeoLocationProviderConfig.GeoLocation /** * 密码 */ + @Encrypt @NotEmpty(message = "密码不能为空") private String sessionKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java index 6a5aacd5..20c2abf5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/mail/MailProviderConfig.java @@ -20,9 +20,9 @@ package cn.topiam.employee.common.message.mail; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import cn.topiam.employee.common.crypto.EncryptContextHelp; import cn.topiam.employee.common.message.enums.MailProvider; import cn.topiam.employee.common.message.enums.MailSafetyType; -import cn.topiam.employee.support.util.AesUtils; import lombok.Builder; import lombok.Data; @@ -86,6 +86,6 @@ public class MailProviderConfig { private String secret; public String getDecryptSecret() { - return AesUtils.decrypt(this.secret); + return EncryptContextHelp.decrypt(this.secret); } } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java index 23bfcf3e..9ccb84f9 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/aliyun/AliyunSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.aliyun; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class AliyunSmsProviderConfig extends SmsProviderConfig { /** * accessKeySecret */ + @Encrypt @NotEmpty(message = "accessKeySecret不能为空") private String accessKeySecret; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java index 1f21e672..05e52295 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/qiniu/QiNiuSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.qiniu; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -44,6 +45,7 @@ public class QiNiuSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "secretKey不能为空") private String secretKey; } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java index e67e8f66..208372e3 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderConfig.java @@ -19,6 +19,7 @@ package cn.topiam.employee.common.message.sms.tencent; import javax.validation.constraints.NotEmpty; +import cn.topiam.employee.common.crypto.Encrypt; import cn.topiam.employee.common.message.sms.SmsProviderConfig; import lombok.Data; @@ -45,6 +46,7 @@ public class TencentSmsProviderConfig extends SmsProviderConfig { /** * secretKey */ + @Encrypt @NotEmpty(message = "SecretKey不能为空") private String secretKey; diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java index 85036b92..105822d5 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/message/sms/tencent/TencentSmsProviderSend.java @@ -89,9 +89,7 @@ public class TencentSmsProviderSend implements SmsProviderSend { /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */ Map parameters = sendSmsParam.getParameters(); List templateParamList = new ArrayList<>(); - parameters.forEach((key, value) -> { - templateParamList.add(value); - }); + parameters.forEach((key, value) -> templateParamList.add(value)); req.setTemplateParamSet(templateParamList.toArray(new String[0])); /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号] * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */ diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java index 4e6e2f43..5bcfa77b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/OrganizationMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 组织机构成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.OrganizationMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:06 */ @Repository -public interface OrganizationMemberRepository extends JpaRepository, +public interface OrganizationMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, OrganizationMemberCustomizedRepository { @@ -46,7 +48,10 @@ public interface OrganizationMemberRepository extends JpaRepository userIds); /** @@ -72,6 +79,8 @@ public interface OrganizationMemberRepository extends JpaRepository @@ -44,8 +44,7 @@ import cn.topiam.employee.common.enums.DataOrigin; * Created by support@topiam.cn on 2020-08-09 */ @Repository -public interface OrganizationRepository extends CrudRepository, - PagingAndSortingRepository, +public interface OrganizationRepository extends LogicDeleteRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor, OrganizationRepositoryCustomized { @@ -197,4 +196,13 @@ public interface OrganizationRepository extends CrudRepository findByIdInOrderByOrderAsc(Collection parentIds); + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link OrganizationEntity} + */ + @NotNull + @Query(value = "SELECT * FROM organization WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") String id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java index d1883241..a2528190 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserDetailRepository.java @@ -23,12 +23,13 @@ import java.util.Optional; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserDetailEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_HQL_SET; /** * @@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -39,8 +40,7 @@ import cn.topiam.employee.common.entity.account.UserDetailEntity; * Created by support@topiam.cn on 2020-08-07 */ @Repository -public interface UserDetailRepository extends PagingAndSortingRepository, - CrudRepository, +public interface UserDetailRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserDetailRepositoryCustomized { /** @@ -56,16 +56,21 @@ public interface UserDetailRepository extends PagingAndSortingRepository userIds); + @Transactional(rollbackFor = Exception.class) + @Query(value = "UPDATE UserDetailEntity SET " + SOFT_DELETE_HQL_SET + + " WHERE userId IN (:userIds)") + void deleteAllByUserIds(@Param("userIds") Iterable userIds); /** * 根据用户ID查询用户详情 @@ -73,7 +78,5 @@ public interface UserDetailRepository extends PagingAndSortingRepository findAllByUserIds(@Param("userIds") Iterable userIds); + List findAllByUserIdIn(List userIds); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java index 3391b807..56b94296 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserGroupMemberRepository.java @@ -19,7 +19,6 @@ package cn.topiam.employee.common.repository.account; import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -28,6 +27,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 用户组成员 @@ -36,7 +37,8 @@ import cn.topiam.employee.common.entity.account.UserGroupMemberEntity; * Created by support@topiam.cn on 2021/11/30 03:04 */ @Repository -public interface UserGroupMemberRepository extends JpaRepository, +public interface UserGroupMemberRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, UserGroupMemberRepositoryCustomized { @@ -46,7 +48,10 @@ public interface UserGroupMemberRepository extends JpaRepository userIds); /** @@ -73,6 +80,8 @@ public interface UserGroupMemberRepository extends JpaRepository @@ -33,8 +37,16 @@ import cn.topiam.employee.common.entity.account.UserGroupEntity; * Created by support@topiam.cn on 2020-07-31 */ @Repository -public interface UserGroupRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserGroupRepository extends LogicDeleteRepository, QuerydslPredicateExecutor { + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserGroupEntity} + */ + @NotNull + @Query(value = "SELECT * FROM user_group WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java index def209b6..27e656c7 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserHistoryPasswordRepository.java @@ -20,11 +20,10 @@ package cn.topiam.employee.common.repository.account; import java.util.List; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * @@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -36,8 +35,7 @@ import cn.topiam.employee.common.entity.account.UserHistoryPasswordEntity; */ @Repository public interface UserHistoryPasswordRepository extends - CrudRepository, - PagingAndSortingRepository, + LogicDeleteRepository, QuerydslPredicateExecutor { /** * 根据用户ID查询历史密码 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java index 645ddba9..a966587a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserIdpRepository.java @@ -18,10 +18,10 @@ package cn.topiam.employee.common.repository.account; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; import cn.topiam.employee.common.entity.account.UserIdpBindEntity; +import cn.topiam.employee.support.repository.LogicDeleteRepository; /** * 用户身份绑定表 @@ -30,7 +30,7 @@ import cn.topiam.employee.common.entity.account.UserIdpBindEntity; * Created by support@topiam.cn on 2022/4/3 22:18 */ @Repository -public interface UserIdpRepository extends CrudRepository, +public interface UserIdpRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserIdpRepositoryCustomized { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java index 1b5f9e82..f18c424b 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepository.java @@ -29,8 +29,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -38,7 +36,9 @@ import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.enums.DataOrigin; import cn.topiam.employee.common.enums.UserStatus; +import cn.topiam.employee.support.repository.LogicDeleteRepository; import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NAME; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_WHERE; /** * @@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository
@@ -50,8 +50,7 @@ import static cn.topiam.employee.common.constants.AccountConstants.USER_CACHE_NA */ @Repository @CacheConfig(cacheNames = { USER_CACHE_NAME }) -public interface UserRepository extends CrudRepository, - PagingAndSortingRepository, +public interface UserRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, UserRepositoryCustomized { /** * findById @@ -62,7 +61,18 @@ public interface UserRepository extends CrudRepository, @NotNull @Override @Cacheable(key = "#p0", unless = "#result==null") - Optional findById(@NotNull Long id); + Optional findById(@NotNull @Param(value = "id") Long id); + + /** + * findByIdContainsDeleted + * + * @param id must not be {@literal null}. + * @return {@link UserEntity} + */ + @NotNull + @Cacheable(key = "#p0", unless = "#result==null") + @Query(value = "SELECT * FROM user WHERE id_ = :id", nativeQuery = true) + Optional findByIdContainsDeleted(@NotNull @Param(value = "id") Long id); /** * findById @@ -195,7 +205,8 @@ public interface UserRepository extends CrudRepository, * @param expireWarnDays {@link Integer} 即将到期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireWarnDays DAY ) <= CURDATE() and user.status_ != 'locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireWarnUser(@Param(value = "expireWarnDays") Integer expireWarnDays); /** @@ -204,7 +215,8 @@ public interface UserRepository extends CrudRepository, * @param expireDays {@link Integer} 密码过期日期 * @return {@link UserEntity} */ - @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') and user.status_ != 'password_expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE DATE_ADD(DATE_FORMAT(last_update_password_time,'%Y-%m-%d'), INTERVAL :expireDays DAY ) BETWEEN DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 HOUR),'%Y-%m-%d %h') AND user.status_ != 'password_expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findPasswordExpireUser(@Param(value = "expireDays") Integer expireDays); /** @@ -212,7 +224,8 @@ public interface UserRepository extends CrudRepository, * * @return {@link UserEntity} */ - @Query(value = "SELECT * from `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked'", nativeQuery = true) + @Query(value = "SELECT * FROM `user` WHERE expire_date <= CURDATE() and status_ != 'expired_locked' AND " + + SOFT_DELETE_WHERE, nativeQuery = true) List findExpireUser(); /** @@ -230,13 +243,6 @@ public interface UserRepository extends CrudRepository, @Param(value = "sharedSecret") String sharedSecret, @Param(value = "totpBind") Boolean totpBind); - /** - * 根据第三方扩展ID 删除用户 - * - * @param externalIds {@link List} - */ - void deleteAllByExternalIdIn(Collection externalIds); - /** * 根据用户名查询全部 * @@ -268,4 +274,17 @@ public interface UserRepository extends CrudRepository, * @return {@link List} */ List findAllByIdNotInAndDataOrigin(Collection ids, DataOrigin dataOrigin); + + /** + * 更新认证成功信息 + * + * @param id {@link String} + * @param ip {@link String} + * @param loginTime {@link LocalDateTime} + */ + @CacheEvict(allEntries = true) + @Transactional(rollbackFor = Exception.class) + @Modifying + @Query(value = "UPDATE user SET auth_total = (IFNULL(auth_total,0) +1),last_auth_ip = ?2,last_auth_time = ?3 WHERE id_ = ?1", nativeQuery = true) + void updateAuthSucceedInfo(String id, String ip, LocalDateTime loginTime); } diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java index 67769df8..c3385255 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/UserRepositoryCustomized.java @@ -44,7 +44,7 @@ public interface UserRepositoryCustomized { Page getUserList(UserListQuery query, Pageable pageable); /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java index 7227a360..c7dd7d38 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserGroupMemberRepositoryCustomizedImpl.java @@ -83,12 +83,13 @@ public class UserGroupMemberRepositoryCustomizedImpl implements group_concat( organization_.display_path ) AS org_display_path FROM user_group_member ugm - INNER JOIN user u ON ugm.user_id = u.id_ - INNER JOIN user_group ug ON ug.id_ = ugm.group_id - LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id ) - LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id ) + INNER JOIN user u ON ugm.user_id = u.id_ AND u.is_deleted = '0' + INNER JOIN user_group ug ON ug.id_ = ugm.group_id AND ug.is_deleted = '0' + LEFT JOIN organization_member ON ( u.id_ = organization_member.user_id AND organization_member.is_deleted = '0') + LEFT JOIN organization organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0') WHERE - ugm.group_id = '%s' + ugm.is_deleted = '0' + AND ugm.group_id = '%s' AND ug.id_ = '%s' """.formatted(query.getId(), query.getId())); //用户名 diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java index 12f6d539..36f979e8 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserIdpRepositoryCustomizedImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -54,7 +55,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndOpenId(String idpId, String openId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -65,8 +66,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -79,7 +85,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Optional findByIdpIdAndUserId(String idpId, Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //身份提供商ID if (StringUtils.isNoneBlank(idpId)) { builder.append(" AND uidp.idp_id = '").append(idpId).append("'"); @@ -90,8 +96,13 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi } //@formatter:on String sql = builder.toString(); - UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, new UserIdpBindPoMapper()); - return Optional.ofNullable(userIdpBindPo); + try { + UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, + new UserIdpBindPoMapper()); + return Optional.ofNullable(userIdpBindPo); + } catch (EmptyResultDataAccessException e) { + return Optional.empty(); + } } /** @@ -103,7 +114,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi @Override public Iterable getUserIdpBindList(Long userId) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); //用户ID if (Objects.nonNull(userId)) { builder.append(" AND uidp.user_id = '").append(userId).append("'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java index 6d0e385b..763bbe77 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/UserRepositoryCustomizedImpl.java @@ -68,7 +68,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserList(UserListQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE 1=1"); + StringBuilder builder = new StringBuilder("SELECT `user`.id_, `user`.username_,`user`.password_, `user`.email_, `user`.phone_,`user`.phone_area_code, `user`.full_name ,`user`.nick_name, `user`.avatar_ , `user`.status_, `user`.data_origin, `user`.email_verified, `user`.phone_verified, `user`.shared_secret, `user`.totp_bind , `user`.auth_total, `user`.last_auth_ip, `user`.last_auth_time, `user`.expand_, `user`.external_id , `user`.expire_date,`user`.create_by, `user`.create_time, `user`.update_by , `user`.update_time, `user`.remark_, group_concat(organization_.display_path) AS org_display_path FROM `user` INNER JOIN `organization_member` ON (`user`.id_ = organization_member.user_id) INNER JOIN `organization` organization_ ON (organization_.id_ = organization_member.org_id) WHERE `user`.is_deleted = 0"); //组织条件 if (StringUtils.isNoneBlank(query.getOrganizationId())) { //包含子节点 @@ -118,7 +118,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { } /** - * 获取用户组成员列表 + * 获取用户组不存在成员列表 * * @param query {@link UserListNotInGroupQuery} * @param pageable {@link Pageable} @@ -127,48 +127,52 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized { @Override public Page getUserListNotInGroupId(UserListNotInGroupQuery query, Pageable pageable) { //@formatter:off - StringBuilder builder = new StringBuilder("SELECT\n" + - " \t`user`.id_,\n" + - " \t`user`.username_,\n" + - " \t`user`.password_,\n" + - " \t`user`.email_,\n" + - " \t`user`.phone_,\n" + - " \t`user`.phone_area_code,\n" + - " \t`user`.full_name,\n" + - " \t`user`.nick_name,\n" + - " \t`user`.avatar_,\n" + - " \t`user`.status_,\n" + - " \t`user`.data_origin,\n" + - " \t`user`.email_verified,\n" + - " \t`user`.phone_verified,\n" + - " \t`user`.shared_secret,\n" + - " \t`user`.totp_bind,\n" + - " \t`user`.auth_total,\n" + - " \t`user`.last_auth_ip,\n" + - " \t`user`.last_auth_time,\n" + - " \t`user`.expand_,\n" + - " \t`user`.external_id,\n" + - " \t`user`.expire_date,\n" + - " \t`user`.create_by,\n" + - " \t`user`.create_time,\n" + - " \t`user`.update_by,\n" + - " \t`user`.update_time,\n" + - " \t`user`.remark_,\n" + - " \tgroup_concat( organization_.display_path ) AS org_display_path \n" + - " FROM\n" + - " `user` \n" + - " LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id )\n" + - " LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id ) \n" + - " WHERE\n" + - " \tuser.id_ NOT IN (\n" + - " \tSELECT\n" + - " \t\tu.id_ \n" + - " \tFROM\n" + - " \t\tuser u\n" + - " \t\tINNER JOIN user_group_member ugm ON ugm.user_id = u.id_\n" + - " \t\tINNER JOIN user_group ug ON ug.id_ = ugm.group_id \n" + - " \tWHERE\n" + - " \tug.id_ = '%s' AND ugm.group_id = '%s')".formatted(query.getId(), query.getId())); + StringBuilder builder = new StringBuilder( + """ + SELECT + `user`.id_, + `user`.username_, + `user`.password_, + `user`.email_, + `user`.phone_, + `user`.phone_area_code, + `user`.full_name, + `user`.nick_name, + `user`.avatar_, + `user`.status_, + `user`.data_origin, + `user`.email_verified, + `user`.phone_verified, + `user`.shared_secret, + `user`.totp_bind, + `user`.auth_total, + `user`.last_auth_ip, + `user`.last_auth_time, + `user`.expand_, + `user`.external_id, + `user`.expire_date, + `user`.create_by, + `user`.create_time, + `user`.update_by, + `user`.update_time, + `user`.remark_, + group_concat( organization_.display_path ) AS org_display_path + FROM `user` + LEFT JOIN `organization_member` ON ( `user`.id_ = organization_member.user_id AND organization_member.is_deleted = '0' ) + LEFT JOIN `organization` organization_ ON ( organization_.id_ = organization_member.org_id AND organization_.is_deleted = '0' ) + WHERE + user.is_deleted = 0 AND + user.id_ NOT IN ( + SELECT + u.id_ + FROM + user u + INNER JOIN user_group_member ugm ON ugm.user_id = u.id_ + INNER JOIN user_group ug ON ug.id_ = ugm.group_id + WHERE + u.is_deleted = '0' + AND ug.id_ = '%s' AND ugm.group_id = '%s') + """.formatted(query.getId(), query.getId())); if (StringUtils.isNoneBlank(query.getKeyword())) { builder.append(" AND user.username_ LIKE '%").append(query.getKeyword()).append("%'"); builder.append(" OR user.full_name LIKE '%").append(query.getKeyword()).append("%'"); diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java index d370c7ad..6e844753 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/account/impl/mapper/UserIdpBindPoMapper.java @@ -25,7 +25,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.lang.NonNull; import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; -import cn.topiam.employee.common.enums.IdentityProviderType; /** * @author TopIAM @@ -52,7 +51,7 @@ public class UserIdpBindPoMapper implements RowMapper { userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setIdpId(rs.getString("idp_id")); - userIdpBindPo.setIdpType(IdentityProviderType.getType(rs.getString("idp_type"))); + userIdpBindPo.setIdpType(rs.getString("idp_type")); userIdpBindPo.setBindTime(rs.getTimestamp("bind_time").toLocalDateTime()); userIdpBindPo.setAdditionInfo(rs.getString("addition_info")); if (isExistColumn(rs, "username_")) { diff --git a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java index 6232c5cf..21a0fe8a 100644 --- a/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java +++ b/eiam-common/src/main/java/cn/topiam/employee/common/repository/app/AppAccessPolicyRepository.java @@ -19,12 +19,17 @@ package cn.topiam.employee.common.repository.app; import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import cn.topiam.employee.common.entity.app.AppAccessPolicyEntity; import cn.topiam.employee.common.enums.PolicySubjectType; +import cn.topiam.employee.support.repository.LogicDeleteRepository; +import static cn.topiam.employee.support.repository.domain.LogicDeleteEntity.SOFT_DELETE_SET; /** * 应用授权策略 Repository @@ -33,7 +38,8 @@ import cn.topiam.employee.common.enums.PolicySubjectType; * Created by support@topiam.cn on 2022/6/4 19:54 */ @Repository -public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccessPolicyRepository extends + LogicDeleteRepository, QuerydslPredicateExecutor, AppAccessPolicyRepositoryCustomized { /** @@ -41,7 +47,11 @@ public interface AppAccessPolicyRepository extends JpaRepository, +public interface AppAccountRepository extends LogicDeleteRepository, QuerydslPredicateExecutor, AppAccountRepositoryCustomized { /** @@ -78,7 +83,11 @@ public interface AppAccountRepository extends JpaRepository, +public interface AppCertRepository extends LogicDeleteRepository