Skip to content

Commit 764ec4f

Browse files
committed
update 3.3.56
data authorization support union all sql
1 parent c10422b commit 764ec4f

File tree

16 files changed

+73
-22
lines changed

16 files changed

+73
-22
lines changed

example/example-application/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.55</version>
8+
<version>3.3.56</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.55</version>
8+
<version>3.3.56</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.55</version>
8+
<version>3.3.56</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.55</version>
8+
<version>3.3.56</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.55</version>
8+
<version>3.3.56</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.55</version>
20+
<version>3.3.56</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>3.3.55</version>
18+
<version>3.3.56</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-parent</artifactId>
9-
<version>3.3.55</version>
9+
<version>3.3.56</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-data-authorization</artifactId>

springboot-starter-data-authorization/src/main/java/com/codingapi/springboot/authorization/enhancer/DataPermissionSQLEnhancer.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
99
import net.sf.jsqlparser.schema.Table;
1010
import net.sf.jsqlparser.statement.Statement;
11-
import net.sf.jsqlparser.statement.select.FromItem;
12-
import net.sf.jsqlparser.statement.select.Join;
13-
import net.sf.jsqlparser.statement.select.PlainSelect;
14-
import net.sf.jsqlparser.statement.select.Select;
11+
import net.sf.jsqlparser.statement.select.*;
1512

1613
import java.sql.SQLException;
14+
import java.util.List;
1715

1816
/**
1917
* 数据权限 SQL 增强器
@@ -45,8 +43,7 @@ public String getNewSQL() throws SQLException {
4543
if (statement instanceof Select) {
4644
tableColumnAliasHolder.holderAlias();
4745
Select select = (Select) statement;
48-
PlainSelect plainSelect = select.getPlainSelect();
49-
this.enhanceDataPermissionInSelect(plainSelect);
46+
this.deepMatch(select);
5047
return statement.toString();
5148
}
5249
} catch (Exception e) {
@@ -55,6 +52,21 @@ public String getNewSQL() throws SQLException {
5552
return sql;
5653
}
5754

55+
56+
private void deepMatch(Select select) throws Exception {
57+
if (select instanceof PlainSelect) {
58+
PlainSelect plainSelect = select.getPlainSelect();
59+
this.enhanceDataPermissionInSelect(plainSelect);
60+
}
61+
if (select instanceof SetOperationList) {
62+
SetOperationList setOperationList = select.getSetOperationList();
63+
List<Select> selectList = setOperationList.getSelects();
64+
for (Select selectItem : selectList) {
65+
this.deepMatch(selectItem.getPlainSelect());
66+
}
67+
}
68+
}
69+
5870
public TableColumnAliasContext getTableAlias() {
5971
return tableColumnAliasHolder.getAliasContext();
6072
}

springboot-starter-data-authorization/src/main/java/com/codingapi/springboot/authorization/enhancer/TableColumnAliasHolder.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,22 @@ public TableColumnAliasHolder(Statement statement) {
2929
*/
3030
public void holderAlias() {
3131
Select select = (Select) statement;
32-
PlainSelect plainSelect = select.getPlainSelect();
33-
this.searchSubSelect(null, plainSelect);
34-
aliasContext.columnKeyToMap();
32+
this.deepSearch(select);
33+
}
34+
35+
36+
private void deepSearch(Select select) {
37+
if (select instanceof PlainSelect) {
38+
PlainSelect plainSelect = select.getPlainSelect();
39+
this.searchSubSelect(null, plainSelect);
40+
aliasContext.columnKeyToMap();
41+
} else if (select instanceof SetOperationList) {
42+
SetOperationList setOperationList = select.getSetOperationList();
43+
List<Select> selectList = setOperationList.getSelects();
44+
for (Select selectItem : selectList) {
45+
this.deepSearch(selectItem);
46+
}
47+
}
3548
}
3649

3750

0 commit comments

Comments
 (0)