Skip to content

Commit

Permalink
fix: Move static data update in permission
Browse files Browse the repository at this point in the history
  • Loading branch information
abhvsn committed Jun 19, 2024
1 parent 505162b commit 4b29951
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class PermissionAspect {
@Around("execution(* com.appsmith.server.repositories..*(..))")
public Object handlePermission(ProceedingJoinPoint joinPoint) throws Throwable {

Class<?> returnType =
((MethodSignature) joinPoint.getSignature()).getMethod().getReturnType();
if (!Mono.class.isAssignableFrom(returnType) && !Flux.class.isAssignableFrom(returnType)) {
return joinPoint.proceed(joinPoint.getArgs());
}

AclPermission permissionWithoutUserContext = Arrays.stream(joinPoint.getArgs())
.filter(arg -> arg instanceof AclPermission
|| (arg instanceof Optional && ((Optional<?>) arg).orElse(null) instanceof AclPermission)
Expand All @@ -42,13 +48,8 @@ public Object handlePermission(ProceedingJoinPoint joinPoint) throws Throwable {
if (permissionWithoutUserContext == null) {
return joinPoint.proceed(joinPoint.getArgs());
}
// Make sure the user context is not available in the permission object to avoid any static data leaks from the
// earlier call.
permissionWithoutUserContext.setUser(null);

Mono<AclPermission> permissionMono = updateAclWithUserContext(permissionWithoutUserContext);
Class<?> returnType =
((MethodSignature) joinPoint.getSignature()).getMethod().getReturnType();
if (Mono.class.isAssignableFrom(returnType)) {
return permissionMono.then(Mono.defer(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public static Mono<AclPermission> updateAclWithUserContext(AclPermission permiss
if (permission == null) {
return Mono.empty();
}
// Make sure the user context is not available in the permission object to avoid any static data leaks from the
// earlier call.
permission.setUser(null);
return getCurrentUser()
.map(user -> {
permission.setUser(user);
Expand Down

0 comments on commit 4b29951

Please sign in to comment.