From f6c9606ac76004662783542158ea43d6d02cbea8 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 31 Mar 2020 14:10:14 +0200 Subject: [PATCH] fix client config access test (background) --- .../gbl/async/AsyncServiceSpringConfig.java | 4 ++-- .../servicelayer/sebconfig/ClientConfigService.java | 5 +++++ .../sebconfig/impl/ClientConfigServiceImpl.java | 12 +++++++++++- .../weblayer/api/ExamAPI_V1_Controller.java | 2 +- .../weblayer/api/SebClientConfigController.java | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java b/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java index fc1ac201..23b8de59 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/async/AsyncServiceSpringConfig.java @@ -37,9 +37,9 @@ public class AsyncServiceSpringConfig implements AsyncConfigurer { return executor; } - public static final String EXAM_AIP_EXECUTOR_BEAN_NAME = "ExamAPIAsyncServiceExecutorBean"; + public static final String EXAM_API_EXECUTOR_BEAN_NAME = "ExamAPIAsyncServiceExecutorBean"; - @Bean(name = EXAM_AIP_EXECUTOR_BEAN_NAME) + @Bean(name = EXAM_API_EXECUTOR_BEAN_NAME) public Executor examAPIThreadPoolTaskExecutor() { final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(200); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ClientConfigService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ClientConfigService.java index 40f483b9..f7a24184 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ClientConfigService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/ClientConfigService.java @@ -13,8 +13,10 @@ import java.io.OutputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.annotation.Cacheable; +import org.springframework.scheduling.annotation.Async; import org.springframework.security.oauth2.provider.ClientDetails; +import ch.ethz.seb.sebserver.gbl.async.AsyncServiceSpringConfig; import ch.ethz.seb.sebserver.gbl.model.sebconfig.SebClientConfig; import ch.ethz.seb.sebserver.gbl.util.Result; @@ -62,4 +64,7 @@ public interface ClientConfigService { * @param config the SebClientConfig to check access * @return true if the system was able to gain an access token for the client. False otherwise */ boolean checkAccess(SebClientConfig config); + + @Async(AsyncServiceSpringConfig.EXECUTOR_BEAN_NAME) + void initalCheckAccess(SebClientConfig config); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ClientConfigServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ClientConfigServiceImpl.java index c31df124..68850e91 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ClientConfigServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ClientConfigServiceImpl.java @@ -325,9 +325,14 @@ public class ClientConfigServiceImpl implements ClientConfigService { try { final RestTemplate restTemplate = new RestTemplate(); - final String externalServerURL = this.webserviceInfo.getExternalServerURL() + + String externalServerURL = this.webserviceInfo.getExternalServerURL() + API.OAUTH_TOKEN_ENDPOINT; + final String lmsExternalAddressAlias = this.webserviceInfo.getLmsExternalAddressAlias(externalServerURL); + if (StringUtils.isNotBlank(lmsExternalAddressAlias)) { + externalServerURL = lmsExternalAddressAlias; + } + final MultiValueMap headers = new LinkedMultiValueMap<>(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); final ClientCredentials credentials = this.sebClientConfigDAO @@ -363,6 +368,11 @@ public class ClientConfigServiceImpl implements ClientConfigService { } } + @Override + public void initalCheckAccess(final SebClientConfig config) { + checkAccess(config); + } + private void passwordEncryption( final OutputStream output, final CharSequence encryptionPassword, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java index 05fd0912..06d9ad13 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java @@ -72,7 +72,7 @@ public class ExamAPI_V1_Controller { final SebClientConnectionService sebClientConnectionService, final SebClientConfigDAO sebClientConfigDAO, final JSONMapper jsonMapper, - @Qualifier(AsyncServiceSpringConfig.EXAM_AIP_EXECUTOR_BEAN_NAME) final Executor executor) { + @Qualifier(AsyncServiceSpringConfig.EXAM_API_EXECUTOR_BEAN_NAME) final Executor executor) { this.lmsSetupDAO = lmsSetupDAO; this.examSessionService = examSessionService; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/SebClientConfigController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/SebClientConfigController.java index f90ef1cb..5e1881a2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/SebClientConfigController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/SebClientConfigController.java @@ -150,7 +150,7 @@ public class SebClientConfigController extends ActivatableEntityController notifySaved(final SebClientConfig entity) { if (entity.isActive()) { // try to get access token for SEB client - this.sebClientConfigService.checkAccess(entity); + this.sebClientConfigService.initalCheckAccess(entity); } return super.notifySaved(entity); }