Skip to content
Snippets Groups Projects
Commit 59edf46b authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'master' of git.ozg-sh.de:mgm/goofy

parents 949a0d9e 6f931edc
No related branches found
No related tags found
No related merge requests found
package de.itvsh.goofy;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
class DelegatingContextAwareRunnable implements Runnable {
private final Runnable delegate;
private final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
@Override
public void run() {
try {
if (requestAttributes != null) {
RequestContextHolder.setRequestAttributes(requestAttributes);
}
delegate.run();
} finally {
RequestContextHolder.resetRequestAttributes();
}
}
}
......@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.concurrent.DelegatingSecurityContextRunnable;
import org.springframework.web.filter.ForwardedHeaderFilter;
@SpringBootApplication
......@@ -28,4 +30,13 @@ public class GoofyServerApplication {
bean.setFilter(new ForwardedHeaderFilter());
return bean;
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("async-");
executor.setTaskDecorator(runnable -> new DelegatingContextAwareRunnable(new DelegatingSecurityContextRunnable(runnable)));
return executor;
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
......@@ -30,7 +29,6 @@ public class SecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
......
......@@ -18,7 +18,7 @@ class PostfachMailService {
@Autowired
private PostfachMailRemoteService remoteService;
// FIXME - reenable async sending
// TODO reenable async
// @Async
public void sendPostfachMail(String commandId, PostfachMail postfachMail) {
try {
......@@ -39,7 +39,7 @@ class PostfachMailService {
}
// FIXME - reenable async sending
// TODO reenable async
// @Async
public void resendPostfachMail(String commandId, String postfachMailId) {
try {
......
......@@ -6,10 +6,13 @@ import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.util.ReflectionTestUtils;
import de.itvsh.goofy.common.command.CommandTestFactory;
import de.itvsh.goofy.vorgang.EingangTestFactory;
......@@ -24,13 +27,18 @@ public class PostfachMailITCase {
@Autowired
private PostfachMailController controller;
@MockBean
@SpyBean
private PostfachMailRemoteService postfachRemoteService;
@MockBean
@Mock
private PostfachServiceBlockingStub serviceStub;
@MockBean
private VorgangController vorgangController;
@BeforeEach
void initTest() {
ReflectionTestUtils.setField(postfachRemoteService, "serviceStub", serviceStub);
}
@Nested
@WithMockUser
class TestSendeMail {
......@@ -39,8 +47,7 @@ public class PostfachMailITCase {
void shouldCallPostfachGrpc() throws InterruptedException {
controller.sendPostfachMail(CommandTestFactory.ID, PostfachMailTestFactory.createLikeFromClient());
Thread.sleep(2000);
verify(postfachRemoteService).sendPostfachMail(anyString(), any());
verify(serviceStub, after(2000)).sendPostfachMail(any());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment