-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[header]: add AccountVO.source #4018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: zsv_5.1.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,32 @@ | ||
| CREATE TABLE IF NOT EXISTS `zstack`.`TpmKeyBackupVO` ( | ||
| `uuid` char(32) NOT NULL UNIQUE, | ||
| `lastOpDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
| `createDate` timestamp NOT NULL DEFAULT '1999-12-31 23:59:59', | ||
| PRIMARY KEY (`uuid`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
|
||
| DELETE FROM `EncryptedResourceKeyRefVO` | ||
| WHERE `resourceUuid` NOT IN (SELECT `uuid` FROM `ResourceVO`); | ||
| ALTER TABLE `EncryptedResourceKeyRefVO` | ||
| ADD CONSTRAINT `fkEncryptedResourceKeyRefResourceVO` FOREIGN KEY (`resourceUuid`) REFERENCES `ResourceVO`(`uuid`) | ||
| ON DELETE CASCADE; | ||
| CREATE TABLE IF NOT EXISTS `zstack`.`TpmKeyBackupVO` ( | ||
| `uuid` char(32) NOT NULL UNIQUE, | ||
| `lastOpDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
| `createDate` timestamp NOT NULL DEFAULT '1999-12-31 23:59:59', | ||
| PRIMARY KEY (`uuid`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
|
||
| DELETE FROM `EncryptedResourceKeyRefVO` | ||
| WHERE `resourceUuid` NOT IN (SELECT `uuid` FROM `ResourceVO`); | ||
| ALTER TABLE `EncryptedResourceKeyRefVO` | ||
| ADD CONSTRAINT `fkEncryptedResourceKeyRefResourceVO` FOREIGN KEY (`resourceUuid`) REFERENCES `ResourceVO`(`uuid`) | ||
| ON DELETE CASCADE; | ||
|
|
||
| -- Feature: ZCenter Account | ZSV-12257 | ||
|
|
||
| ALTER TABLE `zstack`.`AccountVO` | ||
| ADD COLUMN `source` varchar(32) NOT NULL DEFAULT 'Local' AFTER `type`; | ||
|
|
||
| UPDATE `zstack`.`AccountVO` a | ||
| INNER JOIN `zstack`.`AccountThirdPartyAccountSourceRefVO` ref ON ref.accountUuid = a.uuid | ||
| INNER JOIN `zstack`.`LdapServerVO` ldap ON ldap.uuid = ref.accountSourceUuid | ||
| SET a.`source` = IF(ldap.serverType IN ('OpenLdap', 'WindowsAD'), ldap.serverType, 'WindowsAD'); | ||
|
|
||
| UPDATE `zstack`.`AccountVO` a | ||
| INNER JOIN `zstack`.`AccountThirdPartyAccountSourceRefVO` ref ON ref.accountUuid = a.uuid | ||
| INNER JOIN `zstack`.`ThirdPartyAccountSourceVO` src ON src.uuid = ref.accountSourceUuid | ||
| SET a.`source` = src.type | ||
| WHERE src.type IN ('CAS', 'OAuth2'); | ||
|
|
||
| UPDATE `zstack`.`AccountVO` | ||
| SET `type` = 'Normal' | ||
| WHERE `type` = 'ThirdParty'; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||||
| package org.zstack.header.identity; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import org.zstack.header.configuration.PythonClass; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import javax.annotation.Nullable; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||
| * Where an account was originally created. Immutable after creation (ZSV-12257). | ||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||
| @PythonClass | ||||||||||||||||||||||||||||||||
| public enum AccountSource { | ||||||||||||||||||||||||||||||||
| Local, | ||||||||||||||||||||||||||||||||
| OpenLdap, | ||||||||||||||||||||||||||||||||
| WindowsAD, | ||||||||||||||||||||||||||||||||
| CAS, | ||||||||||||||||||||||||||||||||
| OAuth2, | ||||||||||||||||||||||||||||||||
| ZCenter; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| public static AccountSource fromLdapServerTypeName(@Nullable String serverType) { | ||||||||||||||||||||||||||||||||
| if (OpenLdap.name().equals(serverType)) { | ||||||||||||||||||||||||||||||||
| return OpenLdap; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| return WindowsAD; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 避免将未知/空 LDAP 类型静默映射为 当前逻辑会把 建议修改 public static AccountSource fromLdapServerTypeName(`@Nullable` String serverType) {
- if (OpenLdap.name().equals(serverType)) {
- return OpenLdap;
- }
- return WindowsAD;
+ if (OpenLdap.name().equals(serverType)) {
+ return OpenLdap;
+ }
+ if (WindowsAD.name().equals(serverType)) {
+ return WindowsAD;
+ }
+ throw new IllegalArgumentException(String.format("Unsupported LDAP server type: %s", serverType));
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from wenhao.zhang: 在 LDAP 部分传入的值,不是 null 也是 "Unknown",这里没办法只能塞进 WindowsAD 中,和现有的默认值保持一致 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
为了让后续维护者更容易理解这一回退语义,建议在 // null or "Unknown" serverType defaults to WindowsAD to align with legacy behavior
return WindowsAD;这不影响任何逻辑,只是让意图更自解释。采纳与否由团队决定。 (´• ω •`) 🐇 ✏️ Learnings added
🧠 Learnings used |
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -177,7 +177,7 @@ public void prepareDbInitialValue() { | |||||||||||||||||||||
| if (AccountConstant.OTHER_ROLE_UUID.equals(role.getUuid()) | ||||||||||||||||||||||
| || AccountConstant.LEGACY_ROLE_UUID.equals(role.getUuid())) { | ||||||||||||||||||||||
| List<String> accountUuidList = Q.New(AccountVO.class) | ||||||||||||||||||||||
| .in(AccountVO_.type, list(AccountType.Normal, AccountType.ThirdParty)) | ||||||||||||||||||||||
| .eq(AccountVO_.type, AccountType.Normal) | ||||||||||||||||||||||
| .select(AccountVO_.uuid) | ||||||||||||||||||||||
| .listValues(); | ||||||||||||||||||||||
|
Comment on lines
179
to
182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 180 现在只按 建议修复(示意) List<String> accountUuidList = Q.New(AccountVO.class)
- .in(AccountVO_.type, AccountType.Normal)
+ .eq(AccountVO_.type, AccountType.Normal)
+ .eq(AccountVO_.source, AccountSource.Local)
.select(AccountVO_.uuid)
.listValues();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| for (String accountUuid : accountUuidList) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createDate使用固定历史时间会导致数据时间语义失真。这里把
createDate默认值写死为1999-12-31 23:59:59,会让新插入记录的创建时间不准确,影响审计、排序和排障。建议改为DEFAULT CURRENT_TIMESTAMP。💡建议修改
As per coding guidelines
**/*.sql: “Do not useDEFAULT 0000-00-00 00:00:00, useDEFAULT CURRENT_TIMESTAMPinstead”.📝 Committable suggestion
🤖 Prompt for AI Agents