Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/user/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ vadmin:
| `vadmin.local-iam.table-prefix` | `vadmin` | Prefix for the six local IAM tables. The default produces `vadmin_users` and its siblings. A blank value is rejected and does not fall back to unprefixed names. |
| `vadmin.jdbc.enabled` | `false` | Opt into complete JDBC IAM persistence and initial admin bootstrap on an existing schema. Replaces host identity/audit storage beans. |
| `vadmin.jdbc.table-prefix` | `vadmin` | Prefix for all six JDBC IAM tables; validated as a SQL identifier. |
| `vadmin.jdbc.uuid-storage` | `string` | `string` for MySQL CHAR(36); `native` for PostgreSQL UUID and JSONB metadata. |
| `vadmin.jdbc.uuid-storage` | `string` | `string` for MySQL VARCHAR(36); `native` for PostgreSQL UUID and JSONB metadata. |
| `vadmin.bootstrap.password` | Unset | First admin password for JDBC IAM; falls back to APP_BOOTSTRAP_PASSWORD, or `change-me` only in dev. Existing passwords are never reset. |
| `vadmin.oidc.registration-id` | `oidc` | The Spring Security client registration used by the optional OIDC login. The registration itself is standard `spring.security.oauth2.client.*` configuration. |

Expand Down
2 changes: 1 addition & 1 deletion docs/en/user/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Keep `vadmin.system-admin.enabled=true` to use the shared pages and
enable the VAdmin Spring Security integration in the host.

All six tables share `vadmin.jdbc.table-prefix` (default `vadmin`).
`vadmin.jdbc.uuid-storage=string` uses MySQL `CHAR(36)` identifiers;
`vadmin.jdbc.uuid-storage=string` uses MySQL `VARCHAR(36)` identifiers;
`native` uses PostgreSQL UUIDs and JSONB audit metadata. Existing contract beans
take precedence over the JDBC defaults. Exclude the starter's `vadmin-spring-jpa`
and PostgreSQL driver when replacing the default persistence setup.
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/user/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ vadmin:
| `vadmin.local-iam.table-prefix` | `vadmin` | 本地 IAM 六张表的前缀。默认写成 `vadmin_users` 这一组;空字符串会被拒绝,不会退回没有前缀的表名。 |
| `vadmin.jdbc.enabled` | `false` | 在已有表结构上启用完整 JDBC IAM 存储和初始管理员引导,宿主不再提供身份或审计存储 Bean。 |
| `vadmin.jdbc.table-prefix` | `vadmin` | JDBC IAM 六张表统一前缀,按 SQL 标识符校验。 |
| `vadmin.jdbc.uuid-storage` | `string` | MySQL CHAR(36) 使用 `string`;PostgreSQL UUID 和 JSONB 使用 `native`。 |
| `vadmin.jdbc.uuid-storage` | `string` | MySQL VARCHAR(36) 使用 `string`;PostgreSQL UUID 和 JSONB 使用 `native`。 |
| `vadmin.bootstrap.password` | 未配置 | JDBC IAM 首个管理员密码,回退到 APP_BOOTSTRAP_PASSWORD;仅 dev 使用默认 change-me,已有密码不会重置。 |
| `vadmin.oidc.registration-id` | `oidc` | 可选 OIDC 登录使用的 Spring Security 客户端注册 ID。注册本身是标准的 `spring.security.oauth2.client.*` 配置。 |

Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/user/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ VAdmin 在两层检查权限:
保留 `vadmin.system-admin.enabled=true` 以启用共享页面,并接入 VAdmin Spring Security。

六张表统一使用 `vadmin.jdbc.table-prefix`(默认 `vadmin`)。
`vadmin.jdbc.uuid-storage=string` 对应 MySQL `CHAR(36)`;`native` 对应 PostgreSQL UUID
`vadmin.jdbc.uuid-storage=string` 对应 MySQL `VARCHAR(36)`;`native` 对应 PostgreSQL UUID
和 JSONB 审计字段。已有契约 Bean 优先于 JDBC 默认实现。替换默认持久化时,排除 starter
的 `vadmin-spring-jpa` 和 PostgreSQL 驱动。管理写操作、审计和初始化必须共享 DataSource
及事务管理器;宿主仍负责 Flyway 表结构迁移,本模块不会创建表。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.UUID;

/** Bind UUIDs as native PostgreSQL UUIDs or MySQL CHAR(36) strings. */
/** Bind UUIDs as native PostgreSQL UUIDs or MySQL VARCHAR(36) strings. */
public enum UuidStorage {
NATIVE, STRING;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{"name": "vadmin.jdbc.table-prefix", "type": "java.lang.String", "defaultValue": "vadmin",
"description": "SQL identifier prefix shared by all six JDBC IAM tables."},
{"name": "vadmin.jdbc.uuid-storage", "type": "io.github.huahill.vadmin.springjdbc.UuidStorage", "defaultValue": "STRING",
"description": "STRING binds MySQL CHAR(36) identifiers; NATIVE binds PostgreSQL UUIDs and JSONB audit metadata."},
"description": "STRING binds MySQL VARCHAR(36) identifiers; NATIVE binds PostgreSQL UUIDs and JSONB audit metadata."},
{"name": "vadmin.bootstrap.password", "type": "java.lang.String",
"description": "Initial admin password on an empty JDBC IAM schema. Falls back to APP_BOOTSTRAP_PASSWORD; never resets an existing account."}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static JdbcTemplate database(UuidStorage format) {
dataSource.setURL("jdbc:h2:mem:" + UUID.randomUUID() + ";MODE="
+ (format == UuidStorage.STRING ? "MySQL" : "PostgreSQL") + ";DB_CLOSE_DELAY=-1");
var jdbc = new JdbcTemplate(dataSource);
String id = format == UuidStorage.STRING ? "CHAR(36)" : "UUID";
String id = format == UuidStorage.STRING ? "VARCHAR(36)" : "UUID";
jdbc.execute("CREATE TABLE ci_users (id " + id + " PRIMARY KEY, username VARCHAR(120) UNIQUE, "
+ "password_hash VARCHAR(255), enabled BOOLEAN, auth_version BIGINT)");
jdbc.execute("CREATE TABLE ci_roles (id " + id + " PRIMARY KEY, code VARCHAR(120) UNIQUE)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static JdbcTemplate create(UuidStorage format, String prefix) {
+ (format == UuidStorage.STRING ? "MySQL" : "PostgreSQL") + ";DB_CLOSE_DELAY=-1");
var jdbc = new JdbcTemplate(dataSource);
var tables = new JdbcIamTables(prefix);
String id = format == UuidStorage.STRING ? "CHAR(36)" : "UUID";
String id = format == UuidStorage.STRING ? "VARCHAR(36)" : "UUID";
jdbc.execute("CREATE TABLE " + tables.users() + " (id " + id + " PRIMARY KEY, username VARCHAR(120) UNIQUE, "
+ "password_hash VARCHAR(255), enabled BOOLEAN, auth_version BIGINT)");
jdbc.execute("CREATE TABLE " + tables.roles() + " (id " + id + " PRIMARY KEY, code VARCHAR(120) UNIQUE)");
Expand Down
1 change: 1 addition & 0 deletions vadmin-spring/vadmin-spring-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
<dependency><groupId>org.assertj</groupId><artifactId>assertj-core</artifactId><scope>test</scope></dependency>
<dependency><groupId>org.testcontainers</groupId><artifactId>testcontainers-junit-jupiter</artifactId><scope>test</scope></dependency>
<dependency><groupId>org.testcontainers</groupId><artifactId>testcontainers-postgresql</artifactId><scope>test</scope></dependency>
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>test</scope></dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.huahill.vadmin.springjpa;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.hibernate.annotations.JavaType;

/// Marks a VAdmin identity UUID. The JDBC type depends on the dialect.
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@JavaType(IdentityUuidJavaType.class)
public @interface IdentityUuid {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.huahill.vadmin.springjpa;

import org.hibernate.dialect.MySQLDialect;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.java.UUIDJavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;

/// Identity UUID storage for VAdmin tables.
///
/// MySQL and MariaDB have no native UUID column in the host schema, so those
/// dialects bind the same Java UUID as VARCHAR(36). PostgreSQL keeps the native
/// uuid column created by the Flyway migration.
public final class IdentityUuidJavaType extends UUIDJavaType {
@Override
public JdbcType getRecommendedJdbcType(JdbcTypeIndicators indicators) {
if (indicators.getDialect() instanceof MySQLDialect) {
return indicators.getJdbcType(SqlTypes.VARCHAR);
}
return super.getRecommendedJdbcType(indicators);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import io.github.huahill.vadmin.contracts.auth.LocalUserSessionLookup;
import io.github.huahill.vadmin.platform.access.AccessControlRepository;
import io.github.huahill.vadmin.platform.administration.AdministrationStore;
import io.github.huahill.vadmin.springjdbc.JdbcAdministrationStore;
import io.github.huahill.vadmin.springjdbc.UuidStorage;
import io.github.huahill.vadmin.springjpa.access.JpaAccessControlRepository;
import io.github.huahill.vadmin.springjpa.access.JpaLocalUserAccountLookup;
import io.github.huahill.vadmin.springjpa.access.JpaLocalUserSessionLookup;
import io.github.huahill.vadmin.springjpa.access.PermissionCatalogSynchronizer;
import io.github.huahill.vadmin.springjpa.administration.JpaAdministrationStore;
import io.github.huahill.vadmin.springjpa.audit.JpaAuditSink;
import jakarta.persistence.EntityManager;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@AutoConfiguration
@AutoConfigureBefore({
Expand All @@ -28,8 +29,9 @@
@EnableConfigurationProperties(LocalIamProperties.class)
public class JpaAccessControlConfiguration {
@Bean
AdministrationStore administrationStore(JdbcTemplate jdbcTemplate, LocalIamProperties properties) {
return new JdbcAdministrationStore(jdbcTemplate, properties.getTablePrefix(), UuidStorage.NATIVE);
@ConditionalOnBean(DataSource.class)
AdministrationStore administrationStore(EntityManager entityManager, LocalIamProperties properties) {
return new JpaAdministrationStore(entityManager, properties.tables());
}

@Bean
Expand All @@ -48,16 +50,19 @@ AccessControlNamingCustomizer accessControlNamingCustomizer(LocalIamProperties p
}

@Bean
@ConditionalOnBean(DataSource.class)
AccessControlRepository accessControlRepository(EntityManager entityManager, AccessControlTables tables) {
return new JpaAccessControlRepository(entityManager, tables);
}

@Bean
@ConditionalOnBean(DataSource.class)
LocalUserAccountLookup localUserAccountLookup(EntityManager entityManager, AccessControlTables tables) {
return new JpaLocalUserAccountLookup(entityManager, tables);
}

@Bean
@ConditionalOnBean(DataSource.class)
LocalUserSessionLookup localUserSessionLookup(EntityManager entityManager) {
return new JpaLocalUserSessionLookup(entityManager);
}
Expand All @@ -68,11 +73,13 @@ AuditMetadataRedactor auditMetadataRedactor() {
}

@Bean
@ConditionalOnBean(DataSource.class)
AuditSink auditSink(EntityManager entityManager, AuditMetadataRedactor redactor) {
return new JpaAuditSink(entityManager, redactor);
}

@Bean
@ConditionalOnBean(DataSource.class)
PermissionCatalogSynchronizer permissionCatalogSynchronizer(EntityManager entityManager) {
return new PermissionCatalogSynchronizer(entityManager);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.huahill.vadmin.springjpa.access;

import io.github.huahill.vadmin.springjpa.IdentityUuid;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
Expand All @@ -10,6 +11,8 @@
@Table(name = "vadmin_permissions")
public class JpaPermissionEntity {
@Id
@IdentityUuid
@Column(length = 36)
private UUID id;

@Column(nullable = false, unique = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.huahill.vadmin.springjpa.access;

import io.github.huahill.vadmin.springjpa.IdentityUuid;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
Expand All @@ -10,6 +11,8 @@
@Table(name = "vadmin_roles")
public class JpaRoleEntity {
@Id
@IdentityUuid
@Column(length = 36)
private UUID id;

@Column(nullable = false, unique = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.huahill.vadmin.springjpa.access;

import io.github.huahill.vadmin.springjpa.IdentityUuid;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
Expand All @@ -10,6 +11,8 @@
@Table(name = "vadmin_users")
public class JpaUserAccountEntity {
@Id
@IdentityUuid
@Column(length = 36)
private UUID id;

@Column(nullable = false, unique = true)
Expand Down
Loading
Loading