Skip to content

Commit 1996694

Browse files
committed
add SQLRunningContext#skipDataAuthorization 3.3.40
1 parent 80a32e0 commit 1996694

File tree

14 files changed

+31
-15
lines changed

14 files changed

+31
-15
lines changed

example/example-application/pom.xml

+1-1
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.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/pom.xml

+1-1
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.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

+1-1
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.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/pom.xml

+1-1
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.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

+1-1
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.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.39</version>
20+
<version>3.3.40</version>
2121

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

pom.xml

+1-1
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.39</version>
18+
<version>3.3.40</version>
1919

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

springboot-starter-data-authorization/pom.xml

+1-1
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.39</version>
9+
<version>3.3.40</version>
1010
</parent>
1111

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

springboot-starter-data-authorization/src/main/java/com/codingapi/springboot/authorization/interceptor/SQLRunningContext.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public class SQLRunningContext {
1414

1515
private final ThreadLocal<Boolean> skipInterceptor = ThreadLocal.withInitial(() -> false);
1616

17-
private SQLRunningContext() {}
17+
private SQLRunningContext() {
18+
}
1819

1920
/**
2021
* 拦截SQL
@@ -40,7 +41,7 @@ public SQLInterceptState intercept(String sql) throws SQLException {
4041
} catch (SQLException exception) {
4142
sqlInterceptor.afterHandler(sql, null, exception);
4243
throw exception;
43-
}finally {
44+
} finally {
4445
// 重置拦截器状态
4546
skipInterceptor.set(false);
4647
}
@@ -49,6 +50,19 @@ public SQLInterceptState intercept(String sql) throws SQLException {
4950
}
5051

5152

52-
53+
/**
54+
* 跳过数据权限拦截
55+
* @param supplier 业务逻辑
56+
* @return T
57+
* @param <T> T
58+
*/
59+
public <T> T skipDataAuthorization(java.util.function.Supplier<T> supplier) {
60+
try {
61+
skipInterceptor.set(true);
62+
return (T) supplier.get();
63+
} finally {
64+
skipInterceptor.set(false);
65+
}
66+
}
5367

5468
}

springboot-starter-data-authorization/src/test/java/com/codingapi/springboot/authorization/DataAuthorizationContextTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.codingapi.springboot.authorization.entity.User;
77
import com.codingapi.springboot.authorization.filter.DefaultDataAuthorizationFilter;
88
import com.codingapi.springboot.authorization.handler.Condition;
9+
import com.codingapi.springboot.authorization.interceptor.SQLRunningContext;
910
import com.codingapi.springboot.authorization.mask.ColumnMaskContext;
1011
import com.codingapi.springboot.authorization.mask.impl.BankCardMask;
1112
import com.codingapi.springboot.authorization.mask.impl.IDCardMask;
@@ -182,6 +183,7 @@ public boolean supportColumnAuthorization(String tableName, String columnName, O
182183
userRepository.save(bob);
183184
userRepository.save(tom);
184185

186+
assertEquals(3, SQLRunningContext.getInstance().skipDataAuthorization(()->userRepository.findAll()).size());
185187

186188
CurrentUser.getInstance().setUser(bob);
187189

springboot-starter-data-fast/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.39</version>
9+
<version>3.3.40</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

springboot-starter-security/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>3.3.39</version>
9+
<version>3.3.40</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>3.3.39</version>
8+
<version>3.3.40</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

0 commit comments

Comments
 (0)