diff --git a/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseAssignIDEntity.java b/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseAssignIDEntity.java
index b882f51..5c71f25 100644
--- a/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseAssignIDEntity.java
+++ b/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseAssignIDEntity.java
@@ -5,6 +5,7 @@
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
+import java.io.Serializable;
import java.time.LocalDateTime;
/**
@@ -18,12 +19,11 @@
*/
@Getter
@Setter
-public class BaseAssignIDEntity {
+public class BaseAssignIDEntity implements Serializable {
/**
* id, incr
*/
- @TableField("c_id")
- @TableId(type = IdType.ASSIGN_ID)
+ @TableId(type = IdType.ASSIGN_ID, value = "c_id")
private Long id;
/**
diff --git a/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseIncrIDEntity.java b/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseIncrIDEntity.java
index d43f1da..e2e6885 100644
--- a/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseIncrIDEntity.java
+++ b/achobeta-infra-common/src/main/java/com/achobeta/www/common/entity/BaseIncrIDEntity.java
@@ -5,6 +5,7 @@
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
+import java.io.Serializable;
import java.time.LocalDateTime;
/**
@@ -17,12 +18,11 @@
*/
@Getter
@Setter
-public class BaseIncrIDEntity {
+public class BaseIncrIDEntity implements Serializable {
/**
* id, incr
*/
- @TableField("c_id")
- @TableId(type = IdType.AUTO)
+ @TableId(type = IdType.AUTO, value = "c_id")
private Long id;
/**
diff --git a/achobeta-infra-oauth/pom.xml b/achobeta-infra-oauth/pom.xml
index 40bf37d..8f29be4 100644
--- a/achobeta-infra-oauth/pom.xml
+++ b/achobeta-infra-oauth/pom.xml
@@ -16,9 +16,9 @@
- com.mysql
- mysql-connector-j
- runtime
+ com.achobeta.www
+ achobeta-infra-common
+ 0.0.1-SNAPSHOT
org.springframework.boot
@@ -39,6 +39,52 @@
logstash-logback-encoder
7.1.1
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.5.3.1
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+ cn.hutool
+ hutool-all
+ 5.7.21
+
+
+
+ com.alibaba.fastjson2
+ fastjson2-extension-spring6
+ ${fastjson.version}
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+ org.apache.commons
+ commons-pool2
+
+
+ org.springframework.session
+ spring-session-data-redis
+ 3.1.3
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+ 6.0.0
+ provided
+
@@ -47,6 +93,15 @@
org.springframework.boot
spring-boot-maven-plugin
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 21
+ --enable-preview
+
+
diff --git a/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/AchoBetaWebSecurityConfig.java b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/AchoBetaWebSecurityConfig.java
new file mode 100644
index 0000000..6276b50
--- /dev/null
+++ b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/AchoBetaWebSecurityConfig.java
@@ -0,0 +1,72 @@
+package com.achobeta.www.oauth.config;
+
+import com.achobeta.www.oauth.config.handler.AuthenticationFailureHandler;
+import com.achobeta.www.oauth.config.handler.logout.AuthenticationLogoutHandler;
+import com.achobeta.www.oauth.config.handler.logout.AuthenticationLogoutSuccessHandler;
+import com.achobeta.www.oauth.config.handler.AuthenticationSuccessHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
+import org.springframework.security.config.web.server.ServerHttpSecurity;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.server.SecurityWebFilterChain;
+
+import static org.springframework.security.authorization.AuthorityReactiveAuthorizationManager.hasRole;
+
+/**
+ *
+ * security config
+ *
+ *
+ * @author jettcc in 2023/10/18
+ * @version 1.0
+ */
+@Configuration
+@EnableWebFluxSecurity
+public class AchoBetaWebSecurityConfig {
+ @Autowired
+ private AuthenticationWhitelistConfig whitelistConfig;
+ @Bean
+ public SecurityWebFilterChain defaultSecurityFilterChain(ServerHttpSecurity http) {
+ String[] urls = whitelistConfig.getUrls().toArray(new String[0]);
+ http
+ .authorizeExchange((authorize) -> authorize
+ // 白名单路径
+ .pathMatchers(urls)
+ .permitAll()
+ .pathMatchers("/admin/**")
+ .hasRole("ADMIN")
+ .pathMatchers("/db/**")
+ .access((authentication, context) ->
+ hasRole("ADMIN").check(authentication, context)
+ .filter(decision -> !decision.isGranted())
+ .switchIfEmpty(hasRole("DBA").check(authentication, context))
+ )
+ .anyExchange().denyAll()
+ ).formLogin(fl ->
+ fl.authenticationSuccessHandler(new AuthenticationSuccessHandler())
+ .authenticationFailureHandler(new AuthenticationFailureHandler()))
+ .logout(logoutSpec -> logoutSpec.logoutHandler(new AuthenticationLogoutHandler())
+ .logoutSuccessHandler(new AuthenticationLogoutSuccessHandler())
+ )
+// .httpBasic(basicSpec -> {
+// basicSpec.
+// })
+ ;
+
+
+ http.csrf(ServerHttpSecurity.CsrfSpec::disable);
+ return http.build();
+ }
+
+ /**
+ * this bean is encryptor
+ */
+ @Bean
+ public PasswordEncoder passwordEncoder() {
+ return new BCryptPasswordEncoder();
+ }
+}
+
diff --git a/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/AuthenticationWhitelistConfig.java b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/AuthenticationWhitelistConfig.java
new file mode 100644
index 0000000..c335936
--- /dev/null
+++ b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/AuthenticationWhitelistConfig.java
@@ -0,0 +1,24 @@
+package com.achobeta.www.oauth.config;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ *
+ * Whitelist request URL list
+ *
+ *
+ * @author jettcc in 2023/10/31
+ * @version 1.0
+ */
+@Getter
+@Setter
+@Component
+@ConfigurationProperties(prefix = "achobeta.auth.whitelist")
+public class AuthenticationWhitelistConfig {
+ private List urls;
+}
diff --git a/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/MybatisFillConfig.java b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/MybatisFillConfig.java
new file mode 100644
index 0000000..f5b0908
--- /dev/null
+++ b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/MybatisFillConfig.java
@@ -0,0 +1,34 @@
+package com.achobeta.www.oauth.config;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+/**
+ *
+ * Mybatis fill config
+ *
+ *
+ * @author jettcc in 2023/10/18
+ * @version 1.0
+ */
+@Component
+@EnableTransactionManagement
+public class MybatisFillConfig implements MetaObjectHandler {
+ @Override
+ public void insertFill(MetaObject metaObject) {
+ this.strictInsertFill(metaObject, "uuid", String.class, UUID.randomUUID().toString());
+ this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
+ this.strictInsertFill(metaObject, "version", Integer.class, 1);
+ this.strictInsertFill(metaObject, "deleted", Integer.class, 0);
+ }
+
+ @Override
+ public void updateFill(MetaObject metaObject) {
+ this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
+ }
+}
\ No newline at end of file
diff --git a/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/RedisConfig.java b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/RedisConfig.java
new file mode 100644
index 0000000..a8e9ecd
--- /dev/null
+++ b/achobeta-infra-oauth/src/main/java/com/achobeta/www/oauth/config/RedisConfig.java
@@ -0,0 +1,37 @@
+package com.achobeta.www.oauth.config;
+
+import com.alibaba.fastjson2.support.spring6.data.redis.GenericFastJsonRedisSerializer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.RedisSerializer;
+
+/**
+ *
+ * redis config
+ *
+ *
+ * @author jettcc in 2023/10/31
+ * @version 1.0
+ */
+@Configuration
+public class RedisConfig {
+ @Bean
+ public RedisSerializer