Skip to content

Commit

Permalink
!96 允许在ServiceContext中设置并使用自定义权限处理器
Browse files Browse the repository at this point in the history
Merge pull request !96 from dialYun/N/A
  • Loading branch information
entropy-cloud authored and gitee-org committed Oct 27, 2024
2 parents 84ed39b + 911edc9 commit 4cc6ec1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ public static CompletionStage<Object> invokeActionAsync(String bizObjName, Strin
* @return 结果对象
*/
public static CompletionStage<ApiResponse<?>> invokeGraphQLAsync(String bizObjName, String bizAction,
ApiRequest<?> request) {
ApiRequest<?> request, IServiceContext context) {
IGraphQLEngine graphQLEngine = BeanContainer.getBeanByType(IGraphQLEngine.class);
String realBizName = bizObjName + "__" + bizAction;
IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request);
IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request, context);
return graphQLEngine.executeRpcAsync(gqlCtx);
}

public static ApiResponse<?> invokeGraphQLSync(String bizObjName, String bizAction,
ApiRequest<?> request) {
ApiRequest<?> request, IServiceContext context) {
IGraphQLEngine graphQLEngine = BeanContainer.getBeanByType(IGraphQLEngine.class);
String realBizName = bizObjName + "__" + bizAction;
IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request);
IGraphQLExecutionContext gqlCtx = graphQLEngine.newRpcContext(null, realBizName, request, context);
return graphQLEngine.executeRpc(gqlCtx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ default IActionAuthChecker getActionAuthChecker(){
return getServiceContext().getActionAuthChecker();
}

default IDataAuthChecker getDataAuthChecker(){
return getServiceContext().getDataAuthChecker();
}

default IUserContext getUserContext(){
return getServiceContext().getUserContext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,17 @@ public GraphQLFieldDefinition getOperationDefinition(GraphQLOperationType opType
public IGraphQLExecutionContext newGraphQLContextFromContext(IServiceContext ctx) {
GraphQLExecutionContext context = new GraphQLExecutionContext(ctx);

if (enableActionAuth)
context.setActionAuthChecker(actionAuthChecker);
if (enableDataAuth)
context.setDataAuthChecker(dataAuthChecker);
if (enableActionAuth){
if (context.getActionAuthChecker() == null){
context.setActionAuthChecker(actionAuthChecker);
}
}

if (enableDataAuth){
if (context.getDataAuthChecker() == null){
context.setDataAuthChecker(dataAuthChecker);
}
}
return context;
}

Expand Down

0 comments on commit 4cc6ec1

Please sign in to comment.