From 5a55f9521aaf9ad6776e1d646b4cecba1b862498 Mon Sep 17 00:00:00 2001 From: "shengzhaoli.shengz" Date: Mon, 16 Oct 2023 18:53:34 +0800 Subject: [PATCH] client, jsp -> html , test flow --- .../OauthClientDetailsDtoValidator.java | 47 +++++++++++++++++-- .../clientdetails/register_client.html | 2 +- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/monkeyk/sos/web/controller/OauthClientDetailsDtoValidator.java b/src/main/java/com/monkeyk/sos/web/controller/OauthClientDetailsDtoValidator.java index 86c771f..255a24b 100644 --- a/src/main/java/com/monkeyk/sos/web/controller/OauthClientDetailsDtoValidator.java +++ b/src/main/java/com/monkeyk/sos/web/controller/OauthClientDetailsDtoValidator.java @@ -5,6 +5,7 @@ import com.monkeyk.sos.service.OauthService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.oauth2.core.oidc.OidcScopes; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.Validator; @@ -32,6 +33,44 @@ public class OauthClientDetailsDtoValidator implements Validator { validateClientSecret(clientDetailsDto, errors); validateGrantTypes(clientDetailsDto, errors); + //v3.0.0 added + validateClientName(clientDetailsDto, errors); + validateScopes(clientDetailsDto, errors); + validateMethods(clientDetailsDto, errors); + } + + + /** + * @since 3.0.0 + */ + private void validateMethods(OauthClientDetailsDto clientDetailsDto, Errors errors) { + String methods = clientDetailsDto.getClientAuthenticationMethods(); + if (StringUtils.isBlank(methods)) { + errors.reject(null, "authentication_methods is required"); + } + } + + + /** + * @since 3.0.0 + */ + private void validateScopes(OauthClientDetailsDto clientDetailsDto, Errors errors) { + String scopes = clientDetailsDto.getScopes(); + if (StringUtils.isBlank(scopes)) { + errors.reject(null, "scopes is required"); + } else if (!scopes.contains(OidcScopes.OPENID)) { + errors.reject(null, "scopes [openid] must be selected"); + } + } + + /** + * @since 3.0.0 + */ + private void validateClientName(OauthClientDetailsDto clientDetailsDto, Errors errors) { + String clientName = clientDetailsDto.getClientName(); + if (StringUtils.isBlank(clientName)) { + errors.reject(null, "client_name is required"); + } } private void validateGrantTypes(OauthClientDetailsDto clientDetailsDto, Errors errors) { @@ -53,8 +92,8 @@ public class OauthClientDetailsDtoValidator implements Validator { return; } - if (clientSecret.length() < 8) { - errors.rejectValue("clientSecret", null, "client_secret 长度至少8位"); + if (clientSecret.length() < 10) { + errors.rejectValue("clientSecret", null, "client_secret 长度至少10位"); } } @@ -65,8 +104,8 @@ public class OauthClientDetailsDtoValidator implements Validator { return; } - if (clientId.length() < 5) { - errors.rejectValue("clientId", null, "client_id 长度至少5位"); + if (clientId.length() < 10) { + errors.rejectValue("clientId", null, "client_id 长度至少10位"); return; } diff --git a/src/main/resources/templates/clientdetails/register_client.html b/src/main/resources/templates/clientdetails/register_client.html index 7a72bc7..2348300 100644 --- a/src/main/resources/templates/clientdetails/register_client.html +++ b/src/main/resources/templates/clientdetails/register_client.html @@ -33,7 +33,7 @@ -

client_id必须输入,且必须唯一,长度至少5位; 在实际应用中的另一个名称叫appKey,与client_id是同一个概念.

+

client_id必须输入,且必须唯一,长度至少10位; 在实际应用中的另一个名称叫appKey,与client_id是同一个概念.