does any body know how to fix authentication issue Token token = SpringSecurityContext.getToken(); when called in async method
2024-05-08T16:27:17.92+0530 [APP/PROC/WEB/1] OUT {"msg":"Unexpected exception occurred invoking async method: public void com.sap.dvh.messaging.EnterpriseMessagingHelper.createVehicleEvent(com.sap.dvh.dto.CreateDVHVehicleRequestDTO,com.sap.dvh.pojo.VehicleInfo) throws com.sap.dvh.exceptions.ServiceInstanceNotFoundException,com.fasterxml.jackson.core.JsonProcessingException,com.sap.dvh.exceptions.JMSProcessingException","level":"ERROR","written_ts":"1715165837925103120","logger":"org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler","exception_type":"org.springframework.security.access.AccessDeniedException","written_at":"2024-05-08T10:57:17.924Z","thread":"","type":"log","exception_message":"Access forbidden: not authenticated","stacktrace":["org.springframework.security.access.AccessDeniedException: Access forbidden: not authenticated","tat com.sap.cloud.security.xsuaa.token.SpringSecurityContext.getToken(SpringSecurityContext.java:36)","tat com.sap.dvh.messaging.EnterpriseMessagingConfiguration.initializeEMSConfiguration(EnterpriseMessagingConfigur...:27)","tat com.sap.dvh.messaging.EnterpriseMessagingHelper.createVehicleEvent(EnterpriseMessagingHelper.java:74)","tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unkno
The issue comes after adding this code to enable virtual thread
@Bean public AsyncTaskExecutor applicationTaskExecutor() { return new TaskExecutorAdapter(Executors.newVirtualThreadPerTaskExecutor()); }
@Bean public TomcatProtocolHandlerCustomizer protocolHandlerVirtualThreadExecutorCustomizer() { return protocolHandler -> protocolHandler.setExecutor( Executors.newVirtualThreadPerTaskExecutor()); }
after trying this as well , its not working
@Bean(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME) public AsyncTaskExecutor applicationTaskExecutor() { return new TaskExecutorAdapter(Executors.newVirtualThreadPerTaskExecutor()); }
@Bean public TomcatProtocolHandlerCustomizer<?> protocolHandlerVirtualThreadExecutorCustomizer() { return protocolHandler -> protocolHandler.setExecutor( Executors.newVirtualThreadPerTaskExecutor()); }