From 7786f32f045f8a5324c3e4889235c634f78a3504 Mon Sep 17 00:00:00 2001 From: Thomasr Date: Tue, 29 Oct 2024 15:32:56 -0400 Subject: [PATCH] forbid email login that is disabled --- .../src/main/java/org/lowcoder/sdk/exception/BizError.java | 1 + .../lowcoder-sdk/src/main/resources/locale_en.properties | 1 + .../service/AuthenticationApiServiceImpl.java | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/exception/BizError.java b/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/exception/BizError.java index 7d12b8374..eab870605 100644 --- a/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/exception/BizError.java +++ b/server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/exception/BizError.java @@ -102,6 +102,7 @@ public enum BizError { JWT_NOT_FIND(400, 5619), ID_NOT_EXIST(500, 5620), DUPLICATE_AUTH_CONFIG_ADDITION(400, 5621), + EMAIL_PROVIDER_DISABLED(403, 5622), // asset related, code range 5700 - 5799 diff --git a/server/api-service/lowcoder-sdk/src/main/resources/locale_en.properties b/server/api-service/lowcoder-sdk/src/main/resources/locale_en.properties index 1e3a18c31..78601b9a7 100644 --- a/server/api-service/lowcoder-sdk/src/main/resources/locale_en.properties +++ b/server/api-service/lowcoder-sdk/src/main/resources/locale_en.properties @@ -281,3 +281,4 @@ ORG_DELETED_FOR_ENTERPRISE_MODE=Provided enterpriseOrgId workspace has been dele DISABLE_AUTH_CONFIG_FORBIDDEN=Can not disable current administrator''s last identity provider. USER_NOT_EXIST=User not exist. DUPLICATE_AUTH_CONFIG_ADDITION=Provider auth type already added to organization +EMAIL_PROVIDER_DISABLED=Email provider is disabled. \ No newline at end of file diff --git a/server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java b/server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java index 7ca9fe3f9..019d41639 100644 --- a/server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java +++ b/server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java @@ -88,15 +88,19 @@ protected Mono authenticate(String authId, @Deprecated String source, log.warn("source is deprecated and will be removed in the future, please use authId instead. {}", source); return authenticationService.findAuthConfigBySource(context.getOrgId(), source); }) - .doOnNext(findAuthConfig -> { + .flatMap(findAuthConfig -> { context.setAuthConfig(findAuthConfig.authConfig()); if (findAuthConfig.authConfig().getSource().equals("EMAIL")) { if(StringUtils.isBlank(context.getOrgId())) { context.setOrgId(Optional.ofNullable(findAuthConfig.organization()).map(Organization::getId).orElse(null)); } + if(!findAuthConfig.authConfig().getEnable()) { + return Mono.error(new BizException(EMAIL_PROVIDER_DISABLED, "EMAIL_PROVIDER_DISABLED")); + } } else { context.setOrgId(Optional.ofNullable(findAuthConfig.organization()).map(Organization::getId).orElse(null)); } + return Mono.just(findAuthConfig); }) .then(authRequestFactory.build(context)) .flatMap(authRequest -> authRequest.auth(context))