Skip to content
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

fix(data-security): create sensitive columns with case insensitive same column and table names #175

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ oracle:
"SALARY" INT DEFAULT NULL
);
COMMENT ON COLUMN "{3}"."DATABASE_2_TABLE_SALARY"."SALARY" IS ''RECORD SALARY OF EMPLOYEES'';
CREATE TABLE "{3}"."table_user"(
"ID" INT NOT NULL,
"NAME" VARCHAR(16) DEFAULT NULL,
"BIRTHDAY" VARCHAR(16) DEFAULT NULL,
"ADDRESS" VARCHAR(16) DEFAULT NULL,
"EMAIL" VARCHAR(16) DEFAULT NULL,
"PHONE_NUMBER" VARCHAR(16) DEFAULT NULL,
"COLUMN_1" VARCHAR(16) DEFAULT NULL
);
COMMENT ON COLUMN "{3}"."table_user"."COLUMN_1" IS ''RECORD SENSITIVE DATA'';
drop: |-
DROP USER {2} CASCADE;
DROP USER {3} CASCADE;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
Expand All @@ -35,7 +36,6 @@
import com.oceanbase.tools.dbbrowser.model.DBTableColumn;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;

/**
* @author gaoda.xy
Expand Down Expand Up @@ -74,8 +74,9 @@ public Void call() throws Exception {
for (String tableName : tables) {
List<SensitiveColumn> sensitiveColumns = new ArrayList<>();
for (DBTableColumn dbTableColumn : table2Columns.get(tableName)) {
if (recognizer.recognize(dbTableColumn) && !existsSensitiveColumns.contains(
new SimplifySensitiveColumn(database.getId(), tableName, dbTableColumn.getName()))) {
SimplifySensitiveColumn currentColumn =
new SimplifySensitiveColumn(database.getId(), tableName, dbTableColumn.getName());
if (recognizer.recognize(dbTableColumn) && !existsSensitiveColumns.contains(currentColumn)) {
SensitiveColumn column = new SensitiveColumn();
column.setDatabase(database);
column.setTableName(tableName);
Expand All @@ -84,6 +85,7 @@ public Void call() throws Exception {
column.setSensitiveRuleId(recognizer.sensitiveRuleId());
column.setLevel(recognizer.sensitiveLevel());
sensitiveColumns.add(column);
existsSensitiveColumns.add(currentColumn);
}
}
taskInfo.addSensitiveColumns(sensitiveColumns);
Expand All @@ -100,11 +102,26 @@ public Void call() throws Exception {
}

@AllArgsConstructor
@EqualsAndHashCode
private static class SimplifySensitiveColumn {
private Long databaseId;
private String tableName;
private String columnName;

@Override
public int hashCode() {
return Objects.hash(databaseId, tableName.toLowerCase(), columnName.toLowerCase());
}

@Override
public boolean equals(Object obj) {
if (obj instanceof SimplifySensitiveColumn) {
SimplifySensitiveColumn other = (SimplifySensitiveColumn) obj;
return Objects.equals(databaseId, other.databaseId)
&& Objects.equals(tableName.toLowerCase(), other.tableName.toLowerCase())
&& Objects.equals(columnName.toLowerCase(), other.columnName.toLowerCase());
}
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import com.oceanbase.odc.service.iam.auth.AuthenticationFacade;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

/**
Expand Down Expand Up @@ -430,7 +429,6 @@ private void checkoutSensitiveRules(@NotNull Long projectId, @NotEmpty Collectio
}

@Data
@EqualsAndHashCode
private static class SensitiveColumnMeta {
private Long databaseId;
private String tableName;
Expand All @@ -441,6 +439,23 @@ public SensitiveColumnMeta(SensitiveColumnEntity entity) {
this.tableName = entity.getTableName();
this.columnName = entity.getColumnName();
}

@Override
public int hashCode() {
return Objects.hash(databaseId, tableName.toLowerCase(), columnName.toLowerCase());
}

@Override
public boolean equals(Object obj) {
if (obj instanceof SensitiveColumnMeta) {
SensitiveColumnMeta other = (SensitiveColumnMeta) obj;
return Objects.equals(databaseId, other.databaseId)
&& Objects.equals(tableName.toLowerCase(), other.tableName.toLowerCase())
&& Objects.equals(columnName.toLowerCase(), other.columnName.toLowerCase());
}
return false;
}

}

}