fix client config access test (background)

This commit is contained in:
anhefti 2020-03-31 14:10:14 +02:00
parent b5dfa097a4
commit f6c9606ac7
5 changed files with 20 additions and 5 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -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<String, String> 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,

View file

@ -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;

View file

@ -150,7 +150,7 @@ public class SebClientConfigController extends ActivatableEntityController<SebCl
protected Result<SebClientConfig> 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);
}