diff --git a/pom.xml b/pom.xml
index 4440613..d528b4d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,8 +92,7 @@
2.11.0
1.1.0
5.8.8
- 3.3.3
- 3.5.0
+ 3.5.0
4.10.0
3.0.3
@@ -135,44 +134,32 @@
org.projectlombok
lombok
${lombok.version}
- pom
- import
com.fasterxml.jackson.core
jackson-core
${jackson.version}
- pom
- import
com.fasterxml.jackson.core
jackson-annotations
${jackson.version}
- pom
- import
com.fasterxml.jackson.datatype
jackson-datatype-jsr310
${jackson.version}
- pom
- import
com.fasterxml.jackson.core
jackson-databind
${jackson.version}
- pom
- import
mysql
mysql-connector-java
${mysql-jdbc.version}
- pom
- import
com.github.xiaoymin
@@ -199,29 +186,21 @@
org.bouncycastle
bcprov-jdk15on
${bcprov-jdk15on.version}
- pom
- import
com.aliyun
aliyun-java-sdk-core
${aliyun.version}
- pom
- import
io.github.openfeign
feign-hystrix
${feign-hystrix.version}
- pom
- import
com.alibaba.nacos
nacos-client
${nacos-client.version}
- pom
- import
com.baomidou
@@ -232,8 +211,6 @@
org.apache.commons
commons-pool2
2.7.0
- pom
- import
com.alibaba
@@ -259,8 +236,6 @@
org.apache.commons
commons-lang3
${commons-lang3.version}
- pom
- import
org.apache.commons
@@ -271,8 +246,6 @@
commons-io
commons-io
${commons-io.version}
- pom
- import
org.apache.commons
@@ -284,15 +257,11 @@
org.postgresql
postgresql
${postgresql.version}
- pom
- import
org.springframework.boot
spring-boot-maven-plugin
${compler.maven.plugin.version}
- pom
- import
@@ -311,21 +280,12 @@
cn.hutool
hutool-all
${hutool.version}
- pom
- import
com.google.zxing
core
${qrcode-zxing.version}
-
- com.google.zxing
- core
- ${zxing.version}
- pom
- import
-
io.minio
minio
@@ -335,15 +295,11 @@
com.squareup.okhttp3
okhttp
${okhttp3.version}
- pom
- import
com.aliyun
alibabacloud-dysmsapi20170525
${alibabacloud-dysmsapi20170525.version}
- pom
- import
com.tencentcloudapi
@@ -356,38 +312,28 @@
com.aliyun
dysmsapi20170525
${dysmsapi20170525.version}
- pom
- import
org.apache.maven.plugins
maven-assembly-plugin
${maven-assembly-plugin.version}
- pom
- import
org.apache.maven.plugins
maven-jar-plugin
${maven-jar-plugin.version}
- pom
- import
com.sun.xml.bind
jaxb-impl
${jaxb-impl.version}
- pom
- import
com.sun.xml.messaging.saaj
saaj-impl
${saaj-impl.version}
- pom
- import
com.alibaba.fastjson2
@@ -400,6 +346,7 @@
org.projectlombok
lombok
+ true
diff --git a/server/zyjblogs-gateway/pom.xml b/server/zyjblogs-gateway/pom.xml
index aae4189..72d906e 100644
--- a/server/zyjblogs-gateway/pom.xml
+++ b/server/zyjblogs-gateway/pom.xml
@@ -148,6 +148,14 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 15
+
+
\ No newline at end of file
diff --git a/server/zyjblogs-gateway/src/main/resources/banner.txt b/server/zyjblogs-gateway/src/main/resources/banner.txt
new file mode 100644
index 0000000..d686f19
--- /dev/null
+++ b/server/zyjblogs-gateway/src/main/resources/banner.txt
@@ -0,0 +1,9 @@
+ ________ ___ ___ ___ ________ ___ ________ ________ ________
+|\_____ \ |\ \ / /||\ \|\ __ \|\ \ |\ __ \|\ ____\|\ ____\
+ \|___/ /| \ \ \/ / /\ \ \ \ \|\ /\ \ \ \ \ \|\ \ \ \___|\ \ \___|_
+ / / / \ \ / /_ \ \ \ \ __ \ \ \ \ \ \\\ \ \ \ __\ \_____ \
+ / /_/__ \/ / /\ \\_\ \ \ \|\ \ \ \____\ \ \\\ \ \ \|\ \|____|\ \
+ |\________\__/ / / \ \________\ \_______\ \_______\ \_______\ \_______\____\_\ \
+ \|_______|\___/ / \|________|\|_______|\|_______|\|_______|\|_______|\_________\
+ \|___|/ \|_________|
+ Release 1.0.0. Powered by zyjblogs-framework 1.0.0.
\ No newline at end of file
diff --git a/server/zyjblogs-gateway/src/main/resources/logback-spring.xml b/server/zyjblogs-gateway/src/main/resources/logback-spring.xml
index 51f3170..b531430 100644
--- a/server/zyjblogs-gateway/src/main/resources/logback-spring.xml
+++ b/server/zyjblogs-gateway/src/main/resources/logback-spring.xml
@@ -6,20 +6,23 @@
-
+
-
-
-
+
+
+
-
+
- info
+ INFO
${CONSOLE_LOG_PATTERN}
@@ -33,7 +36,7 @@
${logger.path}/log_debug.log
- [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
UTF-8
@@ -61,7 +64,7 @@
${logger.path}/log_info.log
- [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
UTF-8
@@ -88,7 +91,7 @@
${logger.path}/log_warn.log
- [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
UTF-8
@@ -114,7 +117,7 @@
${logger.path}/log_error.log
- [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
+ [%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%X{traceId}] %-5level %logger{50} - %msg%n
UTF-8
@@ -143,55 +146,55 @@
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java
index a45f0a3..ff2851f 100644
--- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java
+++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/config/security/AuthorizationServerConfiguration.java
@@ -22,7 +22,6 @@ import org.springframework.security.oauth2.provider.CompositeTokenGranter;
import org.springframework.security.oauth2.provider.TokenGranter;
import org.springframework.security.oauth2.provider.TokenRequest;
import org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter;
-import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices;
import org.springframework.security.oauth2.provider.code.AuthorizationCodeTokenGranter;
import org.springframework.security.oauth2.provider.implicit.ImplicitTokenGranter;
@@ -57,6 +56,7 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
private final RedisTemplateHandler redisTemplateHandler;
private final UserDetailsService userDetailsService;
+ private final ClientDetailsService oauthClientDetailsService;
/**
* 令牌端点的安全约束
@@ -174,8 +174,8 @@ public class AuthorizationServerConfiguration extends AuthorizationServerConfigu
@Bean
public ClientDetailsService clientDetails(DataSource dataSource) {
- JdbcClientDetailsService jdbcClientDetailsService = new JdbcClientDetailsService(dataSource);
- return jdbcClientDetailsService;
+// JdbcClientDetailsService jdbcClientDetailsService = new JdbcClientDetailsService(dataSource);
+ return oauthClientDetailsService;
}
@Bean
diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java
index 35259f9..a9989cb 100644
--- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java
+++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/po/OauthClientDetail.java
@@ -1,258 +1,177 @@
package cn.zyjblogs.server.client.po;
-import cn.zyjblogs.starter.common.utils.bean.BeanUtils;
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.annotation.JSONField;
+import cn.zyjblogs.starter.mybatisplus.config.ListToStringHandler;
+import cn.zyjblogs.starter.mybatisplus.config.MapToStringHandler;
+import cn.zyjblogs.starter.mybatisplus.config.SetToStringHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.annotate.JsonProperty;
+import org.apache.ibatis.type.JdbcType;
import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.provider.ClientDetails;
+import org.springframework.security.oauth2.provider.client.BaseClientDetails;
+import org.springframework.security.oauth2.provider.client.Jackson2ArrayOrStringDeserializer;
+import org.springframework.security.oauth2.provider.client.JacksonArrayOrStringDeserializer;
import org.springframework.util.StringUtils;
import java.io.Serializable;
-import java.time.LocalDateTime;
import java.util.*;
/**
* @author zhuyijun
*/
-@org.codehaus.jackson.map.annotate.JsonSerialize(
- include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_DEFAULT
-)
-@JsonIgnoreProperties(
- ignoreUnknown = true
-)
-@JsonInclude(JsonInclude.Include.NON_DEFAULT)
-@com.fasterxml.jackson.annotation.JsonIgnoreProperties(
- ignoreUnknown = true
-)
-@TableName("oauth_client_details")
+@SuppressWarnings("serial")
+@org.codehaus.jackson.map.annotate.JsonSerialize(include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_DEFAULT)
+//@org.codehaus.jackson.annotate.JsonIgnoreProperties(ignoreUnknown = true)
+@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_DEFAULT)
+//@com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)
+@TableName(value = "oauth_client_details", autoResultMap = true)
public class OauthClientDetail implements ClientDetails, Serializable {
-
+ @org.codehaus.jackson.annotate.JsonProperty("clientId")
+ @com.fasterxml.jackson.annotation.JsonProperty("clientId")
@TableId("client_id")
private String clientId;
+ @org.codehaus.jackson.annotate.JsonProperty("clientSecret")
+ @com.fasterxml.jackson.annotation.JsonProperty("clientSecret")
@TableField("client_secret")
private String clientSecret;
- @TableField("resource_ids")
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- private String resourceIds;
+ @com.fasterxml.jackson.annotation.JsonProperty("scope")
+// @org.codehaus.jackson.map.annotate.JsonDeserialize(using = JacksonArrayOrStringDeserializer.class)
+ @org.codehaus.jackson.annotate.JsonProperty("scope")
+// @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class)
+ @TableField(value = "scope", jdbcType = JdbcType.VARCHAR, typeHandler = SetToStringHandler.class)
+ private Set scope = Collections.emptySet();
- @TableField("scope")
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- private String scope;
+ @org.codehaus.jackson.annotate.JsonProperty("resourceIds")
+// @org.codehaus.jackson.map.annotate.JsonDeserialize(using = JacksonArrayOrStringDeserializer.class)
+ @com.fasterxml.jackson.annotation.JsonProperty("resourceIds")
+// @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class)
+ @TableField(value = "resource_ids", jdbcType = JdbcType.VARCHAR, typeHandler = SetToStringHandler.class)
+ private Set resourceIds = Collections.emptySet();
- @TableField("authorized_grant_types")
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- private String authorizedGrantTypes;
+ @org.codehaus.jackson.annotate.JsonProperty("authorizedGrantTypes")
+// @org.codehaus.jackson.map.annotate.JsonDeserialize(using = JacksonArrayOrStringDeserializer.class)
+ @com.fasterxml.jackson.annotation.JsonProperty("authorizedGrantTypes")
+// @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class)
+ @TableField(value = "authorized_grant_types", jdbcType = JdbcType.VARCHAR, typeHandler = SetToStringHandler.class)
+ private Set authorizedGrantTypes = Collections.emptySet();
- @TableField("web_server_redirect_uri")
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- private String webServerRedirectUri;
+ @org.codehaus.jackson.annotate.JsonProperty("registeredRedirectUris")
+// @org.codehaus.jackson.map.annotate.JsonDeserialize(using = JacksonArrayOrStringDeserializer.class)
+ @com.fasterxml.jackson.annotation.JsonProperty("registeredRedirectUris")
+// @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class)
+ @TableField(value = "web_server_redirect_uri", jdbcType = JdbcType.VARCHAR, typeHandler = SetToStringHandler.class)
+ private Set registeredRedirectUris;
- @TableField("authorities")
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- private String authorities;
+ @org.codehaus.jackson.annotate.JsonProperty("autoApproveScopes")
+// @org.codehaus.jackson.map.annotate.JsonDeserialize(using = JacksonArrayOrStringDeserializer.class)
+ @com.fasterxml.jackson.annotation.JsonProperty("autoApproveScopes")
+// @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class)
+ @TableField(value = "autoapprove", jdbcType = JdbcType.VARCHAR, typeHandler = SetToStringHandler.class)
+ private Set autoApproveScopes;
+ @TableField(value = "authorities", jdbcType = JdbcType.VARCHAR, typeHandler = ListToStringHandler.class)
+ private List authorities = Collections.emptyList();
+ @org.codehaus.jackson.annotate.JsonProperty("accessTokenValiditySeconds")
+ @com.fasterxml.jackson.annotation.JsonProperty("accessTokenValiditySeconds")
@TableField("access_token_validity")
- private String accessTokenValidity;
-
- @TableField("refresh_token_validity")
- private String refreshTokenValidity;
-
- @TableField("additional_information")
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- private String additionalInformation;
-
- @TableField("create_time")
- @JsonSerialize(using = LocalDateTimeSerializer.class)
- @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
- @JSONField(format = "yyyy-MM-dd HH:mm:ss")
- private LocalDateTime createTime;
-
- @TableField("archived")
- @JsonProperty("archived")
- @com.fasterxml.jackson.annotation.JsonProperty("archived")
- private Integer archived;
-
- @TableField("trusted")
- @JsonProperty("trusted")
- @com.fasterxml.jackson.annotation.JsonProperty("trusted")
- private Integer trusted;
-
- @TableField("autoapprove")
- private String autoapprove;
-
- @TableField(exist = false)
- @JsonProperty("access_token_validity")
- @com.fasterxml.jackson.annotation.JsonProperty("access_token_validity")
private Integer accessTokenValiditySeconds;
- @TableField(exist = false)
- @JsonProperty("access_token_validity")
- @com.fasterxml.jackson.annotation.JsonProperty("refresh_token_validity")
+
+ @org.codehaus.jackson.annotate.JsonProperty("refreshTokenValiditySeconds")
+ @com.fasterxml.jackson.annotation.JsonProperty("refreshTokenValiditySeconds")
+ @TableField("refresh_token_validity")
private Integer refreshTokenValiditySeconds;
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ @TableField(value = "additional_information", jdbcType = JdbcType.VARCHAR, typeHandler = MapToStringHandler.class)
+ private Map additionalInformation = new LinkedHashMap();
+
public OauthClientDetail() {
}
public OauthClientDetail(ClientDetails prototype) {
this();
- this.setAccessTokenValiditySeconds(prototype.getAccessTokenValiditySeconds());
- this.setRefreshTokenValiditySeconds(prototype.getRefreshTokenValiditySeconds());
- Collection authorities = prototype.getAuthorities();
- this.setAuthorities(JSON.toJSONString(authorities));
- this.setAuthorizedGrantTypes(String.join(",", prototype.getAuthorizedGrantTypes()));
- this.setClientId(prototype.getClientId());
- this.setClientSecret(prototype.getClientSecret());
- this.setWebServerRedirectUri(String.join(",", prototype.getRegisteredRedirectUri()));
- this.setScope(String.join(",", prototype.getScope()));
- this.setResourceIds(String.join(",", prototype.getResourceIds()));
+ setAccessTokenValiditySeconds(prototype.getAccessTokenValiditySeconds());
+ setRefreshTokenValiditySeconds(prototype
+ .getRefreshTokenValiditySeconds());
+ setAuthorities(prototype.getAuthorities());
+ setAuthorizedGrantTypes(prototype.getAuthorizedGrantTypes());
+ setClientId(prototype.getClientId());
+ setClientSecret(prototype.getClientSecret());
+ setRegisteredRedirectUri(prototype.getRegisteredRedirectUri());
+ setScope(prototype.getScope());
+ setResourceIds(prototype.getResourceIds());
}
- @Override
+ public OauthClientDetail(String clientId, String resourceIds,
+ String scopes, String grantTypes, String authorities) {
+ this(clientId, resourceIds, scopes, grantTypes, authorities, null);
+ }
+
+ public OauthClientDetail(String clientId, String resourceIds,
+ String scopes, String grantTypes, String authorities,
+ String redirectUris) {
+
+ this.clientId = clientId;
+
+ if (StringUtils.hasText(resourceIds)) {
+ Set resources = StringUtils
+ .commaDelimitedListToSet(resourceIds);
+ if (!resources.isEmpty()) {
+ this.resourceIds = resources;
+ }
+ }
+
+ if (StringUtils.hasText(scopes)) {
+ Set scopeList = StringUtils.commaDelimitedListToSet(scopes);
+ if (!scopeList.isEmpty()) {
+ this.scope = scopeList;
+ }
+ }
+
+ if (StringUtils.hasText(grantTypes)) {
+ this.authorizedGrantTypes = StringUtils
+ .commaDelimitedListToSet(grantTypes);
+ } else {
+ this.authorizedGrantTypes = new HashSet(Arrays.asList(
+ "authorization_code", "refresh_token"));
+ }
+
+ if (StringUtils.hasText(authorities)) {
+ this.authorities = AuthorityUtils
+ .commaSeparatedStringToAuthorityList(authorities);
+ }
+
+ if (StringUtils.hasText(redirectUris)) {
+ this.registeredRedirectUris = StringUtils
+ .commaDelimitedListToSet(redirectUris);
+ }
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
public String getClientId() {
return clientId;
}
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Set getResourceIds() {
- return Set.of(resourceIds.split(","));
- }
-
public void setClientId(String clientId) {
this.clientId = clientId;
}
- public void setClientSecret(String clientSecret) {
- this.clientSecret = clientSecret;
- }
-
- public void setResourceIds(String resourceIds) {
- this.resourceIds = resourceIds;
- }
-
- public void setScope(String scope) {
- this.scope = scope;
- }
-
- public void setAuthorizedGrantTypes(String authorizedGrantTypes) {
- this.authorizedGrantTypes = authorizedGrantTypes;
- }
-
- public void setWebServerRedirectUri(String webServerRedirectUri) {
- this.webServerRedirectUri = webServerRedirectUri;
- }
-
- public void setAuthorities(String authorities) {
- this.authorities = authorities;
- }
-
- public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) {
- this.accessTokenValiditySeconds = accessTokenValiditySeconds;
- }
-
- public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) {
- this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
+ public void setAutoApproveScopes(Collection autoApproveScopes) {
+ this.autoApproveScopes = new HashSet(autoApproveScopes);
}
@Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public boolean isSecretRequired() {
- return this.clientSecret != null;
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public String getClientSecret() {
- return clientSecret;
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public boolean isScoped() {
- return this.scope != null && !this.scope.isEmpty();
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Set getScope() {
- return Set.of(scope.split(","));
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Set getAuthorizedGrantTypes() {
- if (authorizedGrantTypes == null) {
- return new HashSet<>(0);
- }
- return Set.of(authorizedGrantTypes.split(","));
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Set getRegisteredRedirectUri() {
- if (webServerRedirectUri == null) {
- return new HashSet<>(0);
- }
- return Set.of(webServerRedirectUri.split(","));
- }
-
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Collection getAuthorities() {
- if (StringUtils.isEmpty(authorities)) {
- return Collections.emptyList();
- }
- return JSON.parseArray(authorities, GrantedAuthority.class);
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Integer getAccessTokenValiditySeconds() {
- return accessTokenValiditySeconds;
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
- public Integer getRefreshTokenValiditySeconds() {
- return refreshTokenValiditySeconds;
- }
-
- @Override
- @JsonIgnore
- @com.fasterxml.jackson.annotation.JsonIgnore
public boolean isAutoApprove(String scope) {
- if (scope == null) {
+ if (autoApproveScopes == null) {
return false;
}
- for (String auto : getScope()) {
+ for (String auto : autoApproveScopes) {
if (auto.equals("true") || scope.matches(auto)) {
return true;
}
@@ -260,13 +179,249 @@ public class OauthClientDetail implements ClientDetails, Serializable {
return false;
}
- @Override
- @JsonIgnore
+ @org.codehaus.jackson.annotate.JsonIgnore
@com.fasterxml.jackson.annotation.JsonIgnore
- public Map getAdditionalInformation() {
- if (additionalInformation == null) {
- return new HashMap<>(0);
- }
- return BeanUtils.beanToMap(additionalInformation);
+ public Set getAutoApproveScopes() {
+ return autoApproveScopes;
}
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public boolean isSecretRequired() {
+ return this.clientSecret != null;
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public String getClientSecret() {
+ return clientSecret;
+ }
+
+ public void setClientSecret(String clientSecret) {
+ this.clientSecret = clientSecret;
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public boolean isScoped() {
+ return this.scope != null && !this.scope.isEmpty();
+ }
+
+ public Set getScope() {
+ return scope;
+ }
+
+ public void setScope(Collection scope) {
+ this.scope = scope == null ? Collections.emptySet()
+ : new LinkedHashSet(scope);
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public Set getResourceIds() {
+ return resourceIds;
+ }
+
+ public void setResourceIds(Collection resourceIds) {
+ this.resourceIds = resourceIds == null ? Collections
+ .emptySet() : new LinkedHashSet(resourceIds);
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public Set getAuthorizedGrantTypes() {
+ return authorizedGrantTypes;
+ }
+
+ public void setAuthorizedGrantTypes(Collection authorizedGrantTypes) {
+ this.authorizedGrantTypes = new LinkedHashSet(
+ authorizedGrantTypes);
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public Set getRegisteredRedirectUri() {
+ return registeredRedirectUris;
+ }
+
+ public void setRegisteredRedirectUri(Set registeredRedirectUris) {
+ this.registeredRedirectUris = registeredRedirectUris == null ? null
+ : new LinkedHashSet(registeredRedirectUris);
+ }
+
+ @org.codehaus.jackson.annotate.JsonProperty("authorities")
+ @com.fasterxml.jackson.annotation.JsonProperty("authorities")
+ private List getAuthoritiesAsStrings() {
+ return new ArrayList(
+ AuthorityUtils.authorityListToSet(authorities));
+ }
+
+ @org.codehaus.jackson.annotate.JsonProperty("authorities")
+ @org.codehaus.jackson.map.annotate.JsonDeserialize(using = JacksonArrayOrStringDeserializer.class)
+ @com.fasterxml.jackson.annotation.JsonProperty("authorities")
+ @com.fasterxml.jackson.databind.annotation.JsonDeserialize(using = Jackson2ArrayOrStringDeserializer.class)
+ private void setAuthoritiesAsStrings(Set values) {
+ setAuthorities(AuthorityUtils.createAuthorityList(values
+ .toArray(new String[values.size()])));
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public Collection getAuthorities() {
+ return authorities;
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public void setAuthorities(
+ Collection extends GrantedAuthority> authorities) {
+ this.authorities = new ArrayList(authorities);
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public Integer getAccessTokenValiditySeconds() {
+ return accessTokenValiditySeconds;
+ }
+
+ public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) {
+ this.accessTokenValiditySeconds = accessTokenValiditySeconds;
+ }
+
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
+ public Integer getRefreshTokenValiditySeconds() {
+ return refreshTokenValiditySeconds;
+ }
+
+ public void setRefreshTokenValiditySeconds(
+ Integer refreshTokenValiditySeconds) {
+ this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
+ }
+
+ public void setAdditionalInformation(Map additionalInformation) {
+ this.additionalInformation = new LinkedHashMap(
+ additionalInformation);
+ }
+
+ @org.codehaus.jackson.annotate.JsonAnyGetter
+ @com.fasterxml.jackson.annotation.JsonAnyGetter
+ public Map getAdditionalInformation() {
+ return Collections.unmodifiableMap(this.additionalInformation);
+ }
+
+ @org.codehaus.jackson.annotate.JsonAnySetter
+ @com.fasterxml.jackson.annotation.JsonAnySetter
+ public void addAdditionalInformation(String key, Object value) {
+ this.additionalInformation.put(key, value);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime
+ * result
+ + ((accessTokenValiditySeconds == null) ? 0
+ : accessTokenValiditySeconds);
+ result = prime
+ * result
+ + ((refreshTokenValiditySeconds == null) ? 0
+ : refreshTokenValiditySeconds);
+ result = prime * result
+ + ((authorities == null) ? 0 : authorities.hashCode());
+ result = prime
+ * result
+ + ((authorizedGrantTypes == null) ? 0 : authorizedGrantTypes
+ .hashCode());
+ result = prime * result
+ + ((clientId == null) ? 0 : clientId.hashCode());
+ result = prime * result
+ + ((clientSecret == null) ? 0 : clientSecret.hashCode());
+ result = prime
+ * result
+ + ((registeredRedirectUris == null) ? 0
+ : registeredRedirectUris.hashCode());
+ result = prime * result
+ + ((resourceIds == null) ? 0 : resourceIds.hashCode());
+ result = prime * result + ((scope == null) ? 0 : scope.hashCode());
+ result = prime * result + ((additionalInformation == null) ? 0 : additionalInformation.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ BaseClientDetails other = (BaseClientDetails) obj;
+ if (accessTokenValiditySeconds == null) {
+ if (other.getAccessTokenValiditySeconds() != null)
+ return false;
+ } else if (!accessTokenValiditySeconds.equals(other.getAccessTokenValiditySeconds()))
+ return false;
+ if (refreshTokenValiditySeconds == null) {
+ if (other.getRefreshTokenValiditySeconds() != null)
+ return false;
+ } else if (!refreshTokenValiditySeconds.equals(other.getRefreshTokenValiditySeconds()))
+ return false;
+ if (authorities == null) {
+ if (other.getAuthorities() != null)
+ return false;
+ } else if (!authorities.equals(other.getAuthorities()))
+ return false;
+ if (authorizedGrantTypes == null) {
+ if (other.getAuthorizedGrantTypes() != null)
+ return false;
+ } else if (!authorizedGrantTypes.equals(other.getAuthorizedGrantTypes()))
+ return false;
+ if (clientId == null) {
+ if (other.getClientId() != null)
+ return false;
+ } else if (!clientId.equals(other.getClientId()))
+ return false;
+ if (clientSecret == null) {
+ if (other.getClientSecret() != null)
+ return false;
+ } else if (!clientSecret.equals(other.getClientSecret()))
+ return false;
+ if (registeredRedirectUris == null) {
+ if (other.getRegisteredRedirectUri() != null)
+ return false;
+ } else if (!registeredRedirectUris.equals(other.getRegisteredRedirectUri()))
+ return false;
+ if (resourceIds == null) {
+ if (other.getResourceIds() != null)
+ return false;
+ } else if (!resourceIds.equals(other.getResourceIds()))
+ return false;
+ if (scope == null) {
+ if (other.getScope() != null)
+ return false;
+ } else if (!scope.equals(other.getScope()))
+ return false;
+ if (additionalInformation == null) {
+ if (other.getAdditionalInformation() != null)
+ return false;
+ } else if (!additionalInformation.equals(other.getAdditionalInformation()))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "BaseClientDetails [clientId=" + clientId + ", clientSecret="
+ + clientSecret + ", scope=" + scope + ", resourceIds="
+ + resourceIds + ", authorizedGrantTypes="
+ + authorizedGrantTypes + ", registeredRedirectUris="
+ + registeredRedirectUris + ", authorities=" + authorities
+ + ", accessTokenValiditySeconds=" + accessTokenValiditySeconds
+ + ", refreshTokenValiditySeconds="
+ + refreshTokenValiditySeconds + ", additionalInformation="
+ + additionalInformation + "]";
+ }
+
}
diff --git a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java
index d20f01d..3cedf16 100644
--- a/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java
+++ b/server/zyjblogs-oauth/src/main/java/cn/zyjblogs/server/client/service/impl/OauthClientDetailsServiceImpl.java
@@ -3,12 +3,14 @@ package cn.zyjblogs.server.client.service.impl;
import cn.zyjblogs.server.client.mapper.OauthClientDetailsMapper;
import cn.zyjblogs.server.client.po.OauthClientDetail;
import cn.zyjblogs.starter.common.utils.bean.BeanUtils;
+import cn.zyjblogs.starter.redis.utils.RedisTemplateHandler;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.provider.*;
+import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -23,12 +25,22 @@ import java.util.List;
public class OauthClientDetailsServiceImpl implements ClientDetailsService, ClientRegistrationService {
private final OauthClientDetailsMapper oauthClientDetailsMapper;
private final PasswordEncoder passwordEncoder;
+ private final RedisTemplateHandler redisTemplateHandler;
+ private static final String CLIENT = "OAUTH:CLIENT";
@Override
public OauthClientDetail loadClientByClientId(String clientId) throws ClientRegistrationException {
+ OauthClientDetail baseClientDetails1 = redisTemplateHandler.hGet(CLIENT, clientId);
+ if (baseClientDetails1 != null) {
+ return baseClientDetails1;
+ }
LambdaQueryWrapper wrapper = Wrappers.lambdaQuery();
wrapper.eq(OauthClientDetail::getClientId, clientId);
- return oauthClientDetailsMapper.selectOne(wrapper);
+ OauthClientDetail baseClientDetails = oauthClientDetailsMapper.selectOne(wrapper);
+ if (baseClientDetails != null) {
+ redisTemplateHandler.hPut(CLIENT, clientId, baseClientDetails);
+ }
+ return baseClientDetails;
}
@Override
@@ -37,7 +49,10 @@ public class OauthClientDetailsServiceImpl implements ClientDetailsService, Clie
if (oauthClientDetail.getClientSecret() != null) {
oauthClientDetail.setClientSecret(passwordEncoder.encode(oauthClientDetail.getClientSecret()));
}
- oauthClientDetailsMapper.insert(oauthClientDetail);
+ int insert = oauthClientDetailsMapper.insert(oauthClientDetail);
+ if (insert > 0) {
+ redisTemplateHandler.hPut(CLIENT, clientDetails.getClientId(), clientDetails);
+ }
}
@Override
@@ -46,6 +61,7 @@ public class OauthClientDetailsServiceImpl implements ClientDetailsService, Clie
updateWrapper.eq(OauthClientDetail::getClientId, clientDetails.getClientId());
OauthClientDetail oauthClientDetail = new OauthClientDetail(clientDetails);
oauthClientDetailsMapper.update(oauthClientDetail, updateWrapper);
+ redisTemplateHandler.hDelete(CLIENT, clientDetails.getClientId());
}
@Override
@@ -53,6 +69,7 @@ public class OauthClientDetailsServiceImpl implements ClientDetailsService, Clie
LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.eq(OauthClientDetail::getClientId, clientId).set(OauthClientDetail::getClientSecret, passwordEncoder.encode(clientSecret));
oauthClientDetailsMapper.update(null, updateWrapper);
+ redisTemplateHandler.hDelete(CLIENT, clientId);
}
@Override
@@ -60,6 +77,7 @@ public class OauthClientDetailsServiceImpl implements ClientDetailsService, Clie
LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.eq(OauthClientDetail::getClientId, clientId);
oauthClientDetailsMapper.delete(updateWrapper);
+ redisTemplateHandler.hDelete(CLIENT, clientId);
}
@Override
diff --git a/server/zyjblogs-oauth/src/main/resources/banner.txt b/server/zyjblogs-oauth/src/main/resources/banner.txt
index e52a19b..d686f19 100644
--- a/server/zyjblogs-oauth/src/main/resources/banner.txt
+++ b/server/zyjblogs-oauth/src/main/resources/banner.txt
@@ -1,15 +1,9 @@
-
- //
- \\ //
- \\ //
- ##DDDDDDDDDDDDDDDDDDDDDD##
- ## DDDDDDDDDDDDDDDDDDDD ## ________ ___ ___ ___ ________ ___ ___ ___
- ## hh hh ## |\ __ \ |\ \ |\ \ |\ \ |\ __ \ |\ \ |\ \ |\ \
- ## hh // \\ hh ## \ \ \|\ /_\ \ \\ \ \ \ \ \\ \ \|\ /_\ \ \\ \ \ \ \ \
- ## hh // \\ hh ## \ \ __ \\ \ \\ \ \ \ \ \\ \ __ \\ \ \\ \ \ \ \ \
- ## hh hh ## \ \ \|\ \\ \ \\ \ \____ \ \ \\ \ \|\ \\ \ \\ \ \____ \ \ \
- ## hh wwww hh ## \ \_______\\ \__\\ \_______\\ \__\\ \_______\\ \__\\ \_______\\ \__\
- ## hh hh ## \|_______| \|__| \|_______| \|__| \|_______| \|__| \|_______| \|__|
- ## MMMMMMMMMMMMMMMMMMMM ##
- ##MMMMMMMMMMMMMMMMMMMMMM## Release 1.6.11. Powered by jinkela-core 2.8.9.
- \/ \/
\ No newline at end of file
+ ________ ___ ___ ___ ________ ___ ________ ________ ________
+|\_____ \ |\ \ / /||\ \|\ __ \|\ \ |\ __ \|\ ____\|\ ____\
+ \|___/ /| \ \ \/ / /\ \ \ \ \|\ /\ \ \ \ \ \|\ \ \ \___|\ \ \___|_
+ / / / \ \ / /_ \ \ \ \ __ \ \ \ \ \ \\\ \ \ \ __\ \_____ \
+ / /_/__ \/ / /\ \\_\ \ \ \|\ \ \ \____\ \ \\\ \ \ \|\ \|____|\ \
+ |\________\__/ / / \ \________\ \_______\ \_______\ \_______\ \_______\____\_\ \
+ \|_______|\___/ / \|________|\|_______|\|_______|\|_______|\|_______|\_________\
+ \|___|/ \|_________|
+ Release 1.0.0. Powered by zyjblogs-framework 1.0.0.
\ No newline at end of file
diff --git a/server/zyjblogs-oauth/src/main/resources/bootstrap.yml b/server/zyjblogs-oauth/src/main/resources/bootstrap.yml
index cc4ca33..bdaf002 100644
--- a/server/zyjblogs-oauth/src/main/resources/bootstrap.yml
+++ b/server/zyjblogs-oauth/src/main/resources/bootstrap.yml
@@ -116,3 +116,5 @@ sms:
endpoint: dysmsapi.aliyuncs.com
region: cn-hangzhou
max-size: 200
+#mybatis-plus:
+# type-handlers-package: cn.zyjblogs.starter.mybatisplus.config
\ No newline at end of file
diff --git a/server/zyjblogs-rbac/src/main/resources/banner.txt b/server/zyjblogs-rbac/src/main/resources/banner.txt
new file mode 100644
index 0000000..d686f19
--- /dev/null
+++ b/server/zyjblogs-rbac/src/main/resources/banner.txt
@@ -0,0 +1,9 @@
+ ________ ___ ___ ___ ________ ___ ________ ________ ________
+|\_____ \ |\ \ / /||\ \|\ __ \|\ \ |\ __ \|\ ____\|\ ____\
+ \|___/ /| \ \ \/ / /\ \ \ \ \|\ /\ \ \ \ \ \|\ \ \ \___|\ \ \___|_
+ / / / \ \ / /_ \ \ \ \ __ \ \ \ \ \ \\\ \ \ \ __\ \_____ \
+ / /_/__ \/ / /\ \\_\ \ \ \|\ \ \ \____\ \ \\\ \ \ \|\ \|____|\ \
+ |\________\__/ / / \ \________\ \_______\ \_______\ \_______\ \_______\____\_\ \
+ \|_______|\___/ / \|________|\|_______|\|_______|\|_______|\|_______|\_________\
+ \|___|/ \|_________|
+ Release 1.0.0. Powered by zyjblogs-framework 1.0.0.
\ No newline at end of file
diff --git a/stater/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/starter/common/utils/bean/BeanUtils.java b/stater/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/starter/common/utils/bean/BeanUtils.java
index 4a43ace..7901828 100644
--- a/stater/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/starter/common/utils/bean/BeanUtils.java
+++ b/stater/zyjblogs-common-spring-boot-starter/src/main/java/cn/zyjblogs/starter/common/utils/bean/BeanUtils.java
@@ -4,30 +4,28 @@ import cn.zyjblogs.starter.common.utils.jackson.JacksonHolder;
import cn.zyjblogs.starter.common.utils.jackson.exception.JsonConvertException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
import ma.glasnost.orika.DefaultFieldMapper;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.metadata.ClassMapBuilder;
import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.*;
+import java.util.stream.Collectors;
public class BeanUtils {
- private static final Logger log = LoggerFactory.getLogger(BeanUtils.class);
private static final MapperFacade DEFAULT_MAPPER_FACADE = (new DefaultMapperFactory.Builder()).build().getMapperFacade();
- private static final Map MYSQL_ESCAPE_MAP = new LinkedHashMap<>();
+ private static final Map MYSQL_ESCAPE_MAP = new LinkedHashMap<>() {{
+ put("\\", "\\\\");
+ put("%", "\\%");
+ put("'", "\\'");
+ put("_", "\\_");
+ }};
+
private BeanUtils() {
}
@@ -68,7 +66,6 @@ public class BeanUtils {
T result = JacksonHolder.MAPPER.readValue(JacksonHolder.MAPPER.writeValueAsString(content), valueTypeRef);
return result;
} catch (JsonProcessingException var4) {
- log.error("json转换异常:", var4);
throw new JsonConvertException("json转换异常", var4);
}
} else {
@@ -161,10 +158,5 @@ public class BeanUtils {
return mapperFactory.getMapperFacade();
}
- static {
- MYSQL_ESCAPE_MAP.put("\\", "\\\\");
- MYSQL_ESCAPE_MAP.put("%", "\\%");
- MYSQL_ESCAPE_MAP.put("'", "\\'");
- MYSQL_ESCAPE_MAP.put("_", "\\_");
- }
+
}
\ No newline at end of file
diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml b/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml
index 3b43ad9..7a30f1d 100644
--- a/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml
+++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/pom.xml
@@ -44,6 +44,10 @@
com.fasterxml.jackson.datatype
jackson-datatype-jsr310
+
+ com.alibaba.fastjson2
+ fastjson2
+
org.postgresql
postgresql
diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java
index 9e6ac9a..afd99f1 100644
--- a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java
+++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/autoconfigure/MyBatisPlusConfig.java
@@ -1,5 +1,7 @@
package cn.zyjblogs.starter.mybatisplus.autoconfigure;
+import cn.zyjblogs.starter.mybatisplus.generator.GlobalIdGenerator;
+import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
@@ -7,6 +9,7 @@ import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.util.StringUtils;
import java.util.Properties;
@@ -29,6 +32,16 @@ public class MyBatisPlusConfig {
return interceptor;
}
+ @Bean
+ public MybatisPlusPropertiesCustomizer plusPropertiesCustomizer() {
+ return plusProperties -> {
+ if (StringUtils.isEmpty(plusProperties.getTypeHandlersPackage())) {
+ plusProperties.setTypeHandlersPackage("cn.zyjblogs.starter.mybatisplus.config");
+ }
+ plusProperties.getGlobalConfig().setIdentifierGenerator(new GlobalIdGenerator());
+ };
+ }
+
/**
* 数据库兼容,在mybatis里设置相应的databaseId即可
*/
diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/ListToStringHandler.java b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/ListToStringHandler.java
new file mode 100644
index 0000000..1a7f66f
--- /dev/null
+++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/ListToStringHandler.java
@@ -0,0 +1,49 @@
+package cn.zyjblogs.starter.mybatisplus.config;
+
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+/**
+ * List ==> string
+ *
+ * @Date 2022-10-08
+ */
+public class ListToStringHandler extends BaseTypeHandler {
+
+
+ @Override
+ public void setNonNullParameter(PreparedStatement preparedStatement, int i, List list, JdbcType jdbcType) throws SQLException {
+ if (!CollectionUtils.isEmpty(list)) {
+ preparedStatement.setString(i, String.join(",", list));
+ } else {
+ preparedStatement.setString(i, null);
+ }
+
+ }
+
+ @Override
+ public List getNullableResult(ResultSet resultSet, String s) throws SQLException {
+ String result = resultSet.getString(s);
+ return result == null ? null : List.of(StringUtils.commaDelimitedListToStringArray(result));
+ }
+
+ @Override
+ public List getNullableResult(ResultSet resultSet, int i) throws SQLException {
+ String result = resultSet.getString(i);
+ return result == null ? null : List.of(StringUtils.commaDelimitedListToStringArray(result));
+ }
+
+ @Override
+ public List getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
+ String result = callableStatement.getString(i);
+ return result == null ? null : List.of(StringUtils.commaDelimitedListToStringArray(result));
+ }
+}
\ No newline at end of file
diff --git a/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/MapToStringHandler.java b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/MapToStringHandler.java
new file mode 100644
index 0000000..edd6c6e
--- /dev/null
+++ b/stater/zyjblogs-mybatisplus-spring-boot-starter/src/main/java/cn/zyjblogs/starter/mybatisplus/config/MapToStringHandler.java
@@ -0,0 +1,43 @@
+package cn.zyjblogs.starter.mybatisplus.config;
+
+import com.alibaba.fastjson2.JSON;
+import org.apache.ibatis.type.BaseTypeHandler;
+import org.apache.ibatis.type.JdbcType;
+import org.springframework.util.CollectionUtils;
+
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+
+public class MapToStringHandler extends BaseTypeHandler