Hi Team ,
Currently we have Bean
inside that bean we are executing queries through and do some business logic with below exception
java.lang.SecurityException: No security context bound to the current thread
at com.haulmont.cuba.core.sys.AppContext.getSecurityContextNN(AppContext.java:153) ~[cuba-global-7.2.9.jar:7.2.9]
at com.haulmont.cuba.core.sys.UserSessionSourceImpl.getUserSession(UserSessionSourceImpl.java:48) ~[cuba-core-7.2.9.jar:7.2.9]
at com.haulmont.cuba.core.app.RdbmsStore.needToFilterByInMemoryReadConstraints(RdbmsStore.java:1037) ~[cuba-core-7.2.9.jar:7.2.9]
at com.haulmont.cuba.core.app.RdbmsStore.createRestrictedView(RdbmsStore.java:796) ~[cuba-core-7.2.9.jar:7.2.9]
at com.haulmont.cuba.core.app.RdbmsStore.load(RdbmsStore.java:150) ~[cuba-core-7.2.9.jar:7.2.9]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.sun.proxy.$Proxy440.load(Unknown Source) ~[na:na]
at com.haulmont.cuba.core.app.DataManagerBean.load(DataManagerBean.java:67) ~[cuba-core-7.2.9.jar:7.2.9]
at com.haulmont.cuba.core.global.FluentLoader$ByQuery.one(FluentLoader.java:519) ~[cuba-global-7.2.9.jar:7.2.9]
at com.vtss.vtower.core.repo.CommittedCostRepository.loadProjectCommittedCostItemByProjectIdAndCostItemIdAndBudgetRequestId(CommittedCostRepository.java:136) [vtower-core-0.1-SNAPSHOT.jar:na]
I followed many topic related to authenticating background Threads
below is sample
purchaseOrderItems.forEach(item ->
Executors.newSingleThreadScheduledExecutor().submit(new SecurityContextAwareRunnable(() -> {
ProjectCommittedCost committed =
loadProjectCommittedCostItemByProjectIdAndCostItemIdAndBudgetRequestId(projectId,
item.getCostItem().getId(), budgetRequestId);
ProjectForecastingCost currentForecasting = forecastingCosts.stream()
.filter(forecasting -> item.getCostItem().getId().equals(forecasting.getCostItem().getId()))
.findAny()
.orElse(null);
if (Objects.isNull(committed)) {
createNewCommittedCost(currentForecasting, orderRequest,item);
} else {
updateCurrentCommittedCost(currentForecasting, committed,item);
}
})));
but i’m still getting No security context boun to the current thread
@Note :
I’m also adding
@Authenticated on the inside called functions like createNewCommittedCost