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; ...@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.concurrent.DelegatingSecurityContextRunnable;
import org.springframework.web.filter.ForwardedHeaderFilter; import org.springframework.web.filter.ForwardedHeaderFilter;
@SpringBootApplication @SpringBootApplication
...@@ -28,4 +30,13 @@ public class GoofyServerApplication { ...@@ -28,4 +30,13 @@ public class GoofyServerApplication {
bean.setFilter(new ForwardedHeaderFilter()); bean.setFilter(new ForwardedHeaderFilter());
return bean; 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 ...@@ -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.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper; 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.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy; import org.springframework.security.web.authentication.session.NullAuthenticatedSessionStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
...@@ -30,7 +29,6 @@ public class SecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter ...@@ -30,7 +29,6 @@ public class SecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
......
...@@ -18,7 +18,7 @@ class PostfachMailService { ...@@ -18,7 +18,7 @@ class PostfachMailService {
@Autowired @Autowired
private PostfachMailRemoteService remoteService; private PostfachMailRemoteService remoteService;
// FIXME - reenable async sending // TODO reenable async
// @Async // @Async
public void sendPostfachMail(String commandId, PostfachMail postfachMail) { public void sendPostfachMail(String commandId, PostfachMail postfachMail) {
try { try {
...@@ -39,7 +39,7 @@ class PostfachMailService { ...@@ -39,7 +39,7 @@ class PostfachMailService {
} }
// FIXME - reenable async sending // TODO reenable async
// @Async // @Async
public void resendPostfachMail(String commandId, String postfachMailId) { public void resendPostfachMail(String commandId, String postfachMailId) {
try { try {
......
...@@ -6,10 +6,13 @@ import static org.mockito.Mockito.*; ...@@ -6,10 +6,13 @@ import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; 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.security.test.context.support.WithMockUser;
import org.springframework.test.util.ReflectionTestUtils;
import de.itvsh.goofy.common.command.CommandTestFactory; import de.itvsh.goofy.common.command.CommandTestFactory;
import de.itvsh.goofy.vorgang.EingangTestFactory; import de.itvsh.goofy.vorgang.EingangTestFactory;
...@@ -24,13 +27,18 @@ public class PostfachMailITCase { ...@@ -24,13 +27,18 @@ public class PostfachMailITCase {
@Autowired @Autowired
private PostfachMailController controller; private PostfachMailController controller;
@MockBean @SpyBean
private PostfachMailRemoteService postfachRemoteService; private PostfachMailRemoteService postfachRemoteService;
@MockBean @Mock
private PostfachServiceBlockingStub serviceStub; private PostfachServiceBlockingStub serviceStub;
@MockBean @MockBean
private VorgangController vorgangController; private VorgangController vorgangController;
@BeforeEach
void initTest() {
ReflectionTestUtils.setField(postfachRemoteService, "serviceStub", serviceStub);
}
@Nested @Nested
@WithMockUser @WithMockUser
class TestSendeMail { class TestSendeMail {
...@@ -39,8 +47,7 @@ public class PostfachMailITCase { ...@@ -39,8 +47,7 @@ public class PostfachMailITCase {
void shouldCallPostfachGrpc() throws InterruptedException { void shouldCallPostfachGrpc() throws InterruptedException {
controller.sendPostfachMail(CommandTestFactory.ID, PostfachMailTestFactory.createLikeFromClient()); controller.sendPostfachMail(CommandTestFactory.ID, PostfachMailTestFactory.createLikeFromClient());
Thread.sleep(2000); verify(serviceStub, after(2000)).sendPostfachMail(any());
verify(postfachRemoteService).sendPostfachMail(anyString(), any());
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment