Skip to content

Commit 67895fd

Browse files
committed
add SkipAuthorizationFilter
1 parent b1eb58c commit 67895fd

15 files changed

Lines changed: 220 additions & 118 deletions

File tree

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.codingapi.springboot.authorization;
22

33
import com.codingapi.springboot.authorization.filter.DataAuthorizationFilter;
4+
import com.codingapi.springboot.authorization.filter.DefaultSkipAuthorizationFilter;
45
import com.codingapi.springboot.authorization.handler.Condition;
5-
import com.codingapi.springboot.authorization.interceptor.SQLInterceptState;
6+
import com.codingapi.springboot.authorization.filter.SkipAuthorizationFilter;
7+
import com.codingapi.springboot.authorization.interceptor.SQLExecuteState;
68
import lombok.Getter;
9+
import lombok.Setter;
710
import org.springframework.util.StringUtils;
811

912
import java.util.ArrayList;
@@ -19,8 +22,19 @@ public class DataAuthorizationContext {
1922

2023
private final List<DataAuthorizationFilter> filters;
2124

25+
@Setter
26+
private SkipAuthorizationFilter skipAuthorizationFilter;
27+
2228
private DataAuthorizationContext() {
2329
this.filters = new ArrayList<>();
30+
this.skipAuthorizationFilter = new DefaultSkipAuthorizationFilter();
31+
}
32+
33+
/**
34+
* 跳过拦截的处理机制
35+
*/
36+
public String skipSQLFilter(String sql){
37+
return this.skipAuthorizationFilter.filter(sql);
2438
}
2539

2640
/**
@@ -47,7 +61,7 @@ public void clearDataAuthorizationFilters() {
4761
* @return T
4862
* @param <T> 泛型
4963
*/
50-
public <T> T columnAuthorization(SQLInterceptState interceptState, String tableName, String columnName, T value) {
64+
public <T> T columnAuthorization(SQLExecuteState interceptState, String tableName, String columnName, T value) {
5165
if (interceptState != null && interceptState.hasIntercept()) {
5266
String realTableName = interceptState.getTableName(tableName);
5367
String realColumnName = interceptState.getColumnName(tableName,columnName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codingapi.springboot.authorization.filter;
2+
3+
public class DefaultSkipAuthorizationFilter implements SkipAuthorizationFilter{
4+
5+
@Override
6+
public String filter(String sql) {
7+
return sql;
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.codingapi.springboot.authorization.filter;
2+
3+
/**
4+
* 跳过数据权限拦截处理机制
5+
*/
6+
public interface SkipAuthorizationFilter {
7+
8+
String filter(String sql);
9+
10+
}
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.codingapi.springboot.authorization.handler;
22

3-
import com.codingapi.springboot.authorization.interceptor.SQLInterceptState;
3+
import com.codingapi.springboot.authorization.interceptor.SQLExecuteState;
44

55
import java.io.InputStream;
66
import java.io.Reader;
@@ -13,62 +13,62 @@
1313
*/
1414
public interface ColumnHandler {
1515

16-
String getString(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, String value);
16+
String getString(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, String value);
1717

18-
boolean getBoolean(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, boolean value);
18+
boolean getBoolean(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, boolean value);
1919

20-
byte getByte(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, byte value);
20+
byte getByte(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, byte value);
2121

22-
short getShort(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, short value);
22+
short getShort(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, short value);
2323

24-
int getInt(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, int value);
24+
int getInt(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, int value);
2525

26-
long getLong(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, long value);
26+
long getLong(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, long value);
2727

28-
float getFloat(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, float value);
28+
float getFloat(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, float value);
2929

30-
double getDouble(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, double value);
30+
double getDouble(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, double value);
3131

32-
BigDecimal getBigDecimal(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, BigDecimal value);
32+
BigDecimal getBigDecimal(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, BigDecimal value);
3333

34-
byte[] getBytes(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, byte[] value);
34+
byte[] getBytes(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, byte[] value);
3535

36-
Date getDate(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Date value);
36+
Date getDate(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Date value);
3737

38-
Time getTime(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Time value);
38+
Time getTime(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Time value);
3939

40-
Timestamp getTimestamp(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Timestamp value);
40+
Timestamp getTimestamp(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Timestamp value);
4141

42-
InputStream getAsciiStream(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, InputStream value);
42+
InputStream getAsciiStream(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, InputStream value);
4343

44-
InputStream getUnicodeStream(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, InputStream value);
44+
InputStream getUnicodeStream(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, InputStream value);
4545

46-
InputStream getBinaryStream(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, InputStream value);
46+
InputStream getBinaryStream(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, InputStream value);
4747

48-
Object getObject(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Object value);
48+
Object getObject(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Object value);
4949

50-
Reader getCharacterStream(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Reader value);
50+
Reader getCharacterStream(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Reader value);
5151

52-
Ref getRef(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Ref value);
52+
Ref getRef(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Ref value);
5353

54-
Blob getBlob(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Blob value);
54+
Blob getBlob(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Blob value);
5555

56-
Clob getClob(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Clob value);
56+
Clob getClob(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Clob value);
5757

58-
Array getArray(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Array value);
58+
Array getArray(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Array value);
5959

60-
URL getURL(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, URL value);
60+
URL getURL(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, URL value);
6161

62-
NClob getNClob(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, NClob value);
62+
NClob getNClob(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, NClob value);
6363

64-
SQLXML getSQLXML(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, SQLXML value);
64+
SQLXML getSQLXML(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, SQLXML value);
6565

66-
String getNString(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, String value);
66+
String getNString(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, String value);
6767

68-
Reader getNCharacterStream(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, Reader value);
68+
Reader getNCharacterStream(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, Reader value);
6969

70-
RowId getRowId(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, RowId value);
70+
RowId getRowId(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, RowId value);
7171

72-
<T> T getObject(SQLInterceptState interceptState, int columnIndex, String tableName, String columnName, T value, Class<T> type);
72+
<T> T getObject(SQLExecuteState interceptState, int columnIndex, String tableName, String columnName, T value, Class<T> type);
7373

7474
}

0 commit comments

Comments
 (0)