Skip to content

Commit 3a7fe83

Browse files
committed
fix: plugin endpoint invocation
1 parent c504c7a commit 3a7fe83

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/constant/NewUrl.java

+2
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ private NewUrl() {
3434
public static final String MATERIAL_URL = PREFIX + "/materials";
3535
public static final String CONTACT_SYNC = PREFIX + "/sync";
3636
public static final String NPM_REGISTRY = PREFIX + "/npm";
37+
38+
public static final String PLUGINS_URL = PREFIX + "/plugins";
3739
}

server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/exception/BizError.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum BizError {
1111

1212
// 5000 - 5100 general errorCode
1313
INTERNAL_SERVER_ERROR(500, 5000, VERBOSE),
14-
NOT_AUTHORIZED(500, 5001),
14+
NOT_AUTHORIZED(401, 5001),
1515
INVALID_PARAMETER(500, 5002),
1616
UNSUPPORTED_OPERATION(400, 5003),
1717
DUPLICATE_KEY(409, 5004, VERBOSE),
@@ -113,6 +113,7 @@ public enum BizError {
113113
PLUGIN_EXECUTION_TIMEOUT(504, 5800),
114114
INVALID_DATASOURCE_TYPE(500, 5801),
115115
PLUGIN_EXECUTION_TIMEOUT_WITHOUT_TIME(504, 5802, VERBOSE),
116+
PLUGIN_ENDPOINT_ERROR(500, 5850),
116117

117118
// business related, code range 5900 - 5999
118119
NOT_RELEASE(423, 5901),

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/exception/GlobalExceptionHandler.java

+20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import java.util.Map;
99
import java.util.concurrent.TimeoutException;
1010

11+
import org.apache.commons.lang3.StringUtils;
1112
import org.lowcoder.api.framework.view.ResponseView;
13+
import org.lowcoder.infra.constant.NewUrl;
1214
import org.lowcoder.infra.util.LogUtils;
1315
import org.lowcoder.sdk.exception.BaseException;
1416
import org.lowcoder.sdk.exception.BizError;
@@ -26,6 +28,7 @@
2628
import org.springframework.web.bind.annotation.ExceptionHandler;
2729
import org.springframework.web.bind.annotation.ResponseBody;
2830
import org.springframework.web.bind.support.WebExchangeBindException;
31+
import org.springframework.web.server.ResponseStatusException;
2932
import org.springframework.web.server.ServerWebExchange;
3033
import org.springframework.web.server.ServerWebInputException;
3134

@@ -133,6 +136,23 @@ public Mono<ResponseView<?>> catchServerException(ServerException e, ServerWebEx
133136
});
134137
}
135138

139+
@ExceptionHandler
140+
@ResponseBody
141+
public Mono<ResponseView<?>> catchResponseStatusException(ResponseStatusException e, ServerWebExchange exchange) {
142+
if (StringUtils.startsWith(exchange.getRequest().getPath().toString(), NewUrl.PLUGINS_URL + "/")) {
143+
BizError bizError = BizError.PLUGIN_ENDPOINT_ERROR;
144+
exchange.getResponse().setStatusCode(e.getStatusCode());
145+
return Mono.deferContextual(ctx -> {
146+
apiPerfHelper.perf(bizError, exchange.getRequest().getPath());
147+
doLog(e, ctx, bizError.logVerbose());
148+
return Mono.just(error(bizError.getBizErrorCode(), e.getMessage() + " - path: " + exchange.getRequest().getPath()));
149+
});
150+
151+
} else {
152+
return catchException(e, exchange);
153+
}
154+
}
155+
136156
@ExceptionHandler
137157
@ResponseBody
138158
public Mono<ResponseView<?>> catchException(java.lang.Exception e, ServerWebExchange exchange) {

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/plugin/security/PluginAuthorizationManager.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ public PluginAuthorizationManager()
3131
public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, MethodInvocation invocation)
3232
{
3333
log.info("Checking plugin reactive endpoint invocation security for {}", invocation.getMethod().getName());
34-
34+
3535
EndpointExtension endpointExtension = (EndpointExtension)invocation.getArguments()[1];
3636
if (endpointExtension == null || StringUtils.isBlank(endpointExtension.authorize()))
3737
{
38-
return Mono.empty();
38+
log.debug("Authorization expression is empty, proceeding without authorization - authorization granted.");
39+
return Mono.just(new AuthorizationDecision(true));
3940
}
4041

4142
Expression authorizeExpression = this.expressionHandler.getExpressionParser()

0 commit comments

Comments
 (0)