Hi everyone,
Please give me some idea about a random exception that occurs when using IvyAsyncRunner, and ISession together.
In an Ivy process, we have a refresh method:
When the method is called, it will call some Restful API asynchronously, in the java code we IvyAsyncRunner like this:
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import ch.ivyteam.util.threadcontext.IvyAsyncRunner;
public class AsyncRefresher {
public void refresh() {
ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_4);
IvyAsyncRunner asyncRunner = new IvyAsyncRunner();
try {
Future<Boolean> async1 = submitBooleanFunction(executor, asyncRunner, createAsyncCallable1());
Future<Boolean> async2 = submitBooleanFunction(executor, asyncRunner, createAsyncCallable2());
Future<Boolean> async3 = submitBooleanFunction(executor, asyncRunner, createAsyncCallable3());
Future<Boolean> async4 = submitBooleanFunction(executor, asyncRunner, createAsyncCallable4());
// wait until all async.isDone() == true
AsyncFunctionUtil.waitAsyncFunctions(REFRESH_PROCESSING_INTERVAL_TIME,
async1, async2, async3, async4);
this.hasUnstoredLetter = asyncRefreshHasUnstoredLetter.get();
this.hasStoredLetter = asyncRefreshHasStoredLetter.get();
return;
} catch (InterruptedException | ExecutionException ex) {
throw new LetterboxWebException(ex);
} finally {
executor.shutdown();
}
}
private Future<Boolean> submitBooleanFunction(ExecutorService executor, IvyAsyncRunner asyncRunner, Callable<Boolean> callable) {
return executor.submit(() -> asyncRunner.run(callable));
}
}
In the callable, we read some environment variables like in the following class:
import ch.ivyteam.api.API;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.security.ISession;
public class RestAuthenticationToken {
private ISession session;
public RestAuthenticationToken(ISession session) {
this.session = session;
}
public static AuthenticationToken ofSessionUser() {
return new RestAuthenticationToken(Ivy.session());
}
public String getCurrentTenantId() {
if(isAttributeSet(SESSION_ATTRIBUTE_NAME_TENANT_ID)) {
return String.valueOf(session.getAttribute(SESSION_ATTRIBUTE_NAME_TENANT_ID));
}
return null;
}
public void set(String token) {
if (session.getAttribute(SESSION_ATTRIBUTE_NAME_TOKEN_TEMP) != null) {
session.removeAttribute(SESSION_ATTRIBUTE_NAME_TOKEN_TEMP);
}
session.setAttribute(SESSION_ATTRIBUTE_NAME_TOKEN, token);
}
}
But there is a random exception that occurs when multiple users use that method, the exception log is as follows:
ch.ivyteam.ivy.security.PermissionDeniedException: Session SYSTEM is not allowed to call method public ch.ivyteam.ivy.workflow.internal.cases.Case ch.ivyteam.ivy.workflow.internal.Task.getCase().
The session does not fulfill the permission rule SESSION OWNS CaseReadOwnCaseOfTask PERMISSION OR OWNS CaseRead PERMISSION OR OWNS CaseRead@SYSTEM PERMISSION
at ch.ivyteam.ivy.security.internal.permission.PermissionChecker.checkPermission(PermissionChecker.java:65)
at ch.ivyteam.ivy.security.internal.SecurityManager.lambda$6(SecurityManager.java:826)
at ch.ivyteam.ivy.persistence.ITransactionExecutableWithoutResult.execute(ITransactionExecutableWithoutResult.java:9)
at ch.ivyteam.ivy.persistence.ITransactionExecutableWithoutResult.execute(ITransactionExecutableWithoutResult.java:1)
at ch.ivyteam.ivy.persistence.base.AbstractPersistencyService.execute(AbstractPersistencyService.java:135)
at ch.ivyteam.ivy.persistence.base.AbstractPersistencyService.executeWithoutResult(AbstractPersistencyService.java:154)
at ch.ivyteam.ivy.persistence.base.ClassPersistencyService.executeWithoutResult(ClassPersistencyService.java:560)
at ch.ivyteam.ivy.persistence.client.PersistentClientObjectChildren.executeWithoutResult(PersistentClientObjectChildren.java:492)
at ch.ivyteam.ivy.security.internal.SecurityManager.checkPermission(SecurityManager.java:825)
at ch.ivyteam.ivy.security.restricted.fw.Secure.exec(Secure.java:40)
at ch.ivyteam.ivy.workflow.internal.Task.getCase(Task.java:186)
at ch.ivyteam.ivy.workflow.internal.Task.getCase(Task.java:1)
at ch.ivyteam.ivy.workflow.ICase.current(ICase.java:1173)
at ch.ivyteam.ivy.workflow.internal.WorkflowManager.getCurrentCase(WorkflowManager.java:1588)
at ch.ivyteam.ivy.workflow.internal.ApplicationConfigurationDelegator.getActiveCaseEnvironment(ApplicationConfigurationDelegator.java:46)
at ch.ivyteam.ivy.application.internal.ApplicationConfigurationManager.getActiveCaseEnvironment(ApplicationConfigurationManager.java:976)
at ch.ivyteam.ivy.application.internal.Application.getCaseEnvironment(Application.java:1155)
at ch.ivyteam.ivy.application.internal.Application.lambda$56(Application.java:1131)
at ch.ivyteam.ivy.security.exec.Sudo.exec(Sudo.java:17)
at ch.ivyteam.ivy.application.internal.Application.getActualEnvironment(Application.java:1130)
at ch.ivyteam.ivy.application.internal.Application.lambda$47(Application.java:1075)
at ch.ivyteam.ivy.security.exec.Sudo.exec(Sudo.java:17)
at ch.ivyteam.ivy.application.internal.Application.findGlobalVariable(Application.java:1075)
at ch.ivyteam.ivy.globalvars.restricted.GlobalVariableContext.get(GlobalVariableContext.java:37)
at ch.xpertline.luz.components.rest.auth.IvyGlobalVariable.get(IvyGlobalVariable.java:13)
I don't know how to overcome this error, do you have any idea?
Thanks and best regards