SEBSERV-467 fix plus added authentication to LMSSetup test
This commit is contained in:
parent
d6782075bc
commit
1d2c88c971
5 changed files with 28 additions and 3 deletions
|
@ -163,6 +163,23 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
|
||||||
"lmsSetup:lmsClientsecret:notNull"));
|
"lmsSetup:lmsClientsecret:notNull"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Result<OlatLmsRestTemplate> restTemplateResult = getRestTemplate();
|
||||||
|
if (restTemplateResult.hasError()) {
|
||||||
|
missingAttrs.add(APIMessage.fieldValidationError(
|
||||||
|
LMS_SETUP.ATTR_LMS_URL,
|
||||||
|
"lmsSetup:lmsUrl:url.noservice"));
|
||||||
|
} else {
|
||||||
|
final OlatLmsRestTemplate olatLmsRestTemplate = restTemplateResult.get();
|
||||||
|
try {
|
||||||
|
olatLmsRestTemplate.testAuthentication();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.error("Failed to test Authentication: {}", e.getMessage());
|
||||||
|
missingAttrs.add(APIMessage.fieldValidationError(
|
||||||
|
LMS_SETUP.ATTR_LMS_URL,
|
||||||
|
"lmsSetup:lmsUrl:url.noaccess"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!missingAttrs.isEmpty()) {
|
if (!missingAttrs.isEmpty()) {
|
||||||
return LmsSetupTestResult.ofMissingAttributes(LmsType.OPEN_OLAT, missingAttrs);
|
return LmsSetupTestResult.ofMissingAttributes(LmsType.OPEN_OLAT, missingAttrs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,10 @@ public class OlatLmsRestTemplate extends RestTemplate {
|
||||||
private String token;
|
private String token;
|
||||||
private ClientCredentialsResourceDetails details;
|
private ClientCredentialsResourceDetails details;
|
||||||
|
|
||||||
|
public void testAuthentication() {
|
||||||
|
authenticate();
|
||||||
|
}
|
||||||
|
|
||||||
public OlatLmsRestTemplate(final ClientCredentialsResourceDetails details) {
|
public OlatLmsRestTemplate(final ClientCredentialsResourceDetails details) {
|
||||||
super();
|
super();
|
||||||
this.details = details;
|
this.details = details;
|
||||||
|
@ -45,7 +49,6 @@ public class OlatLmsRestTemplate extends RestTemplate {
|
||||||
final ClientHttpRequestExecution execution) throws IOException {
|
final ClientHttpRequestExecution execution) throws IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// if there's no token, authenticate first
|
// if there's no token, authenticate first
|
||||||
if (OlatLmsRestTemplate.this.token == null) {
|
if (OlatLmsRestTemplate.this.token == null) {
|
||||||
authenticate();
|
authenticate();
|
||||||
|
@ -59,6 +62,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
|
||||||
|
|
||||||
return execution.execute(request, body);
|
return execution.execute(request, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, add the X-OLAT-TOKEN
|
// otherwise, add the X-OLAT-TOKEN
|
||||||
request.getHeaders().set("accept", "application/json");
|
request.getHeaders().set("accept", "application/json");
|
||||||
request.getHeaders().set("X-OLAT-TOKEN", OlatLmsRestTemplate.this.token);
|
request.getHeaders().set("X-OLAT-TOKEN", OlatLmsRestTemplate.this.token);
|
||||||
|
@ -85,6 +89,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
|
||||||
log.debug("OLAT [retry API call]: URL {}", request.getURI());
|
log.debug("OLAT [retry API call]: URL {}", request.getURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.close();
|
||||||
response = execution.execute(request, body);
|
response = execution.execute(request, body);
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
|
@ -97,7 +102,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO find a way to better deal with Olat temporary unavailability
|
// TODO find a way to better deal with Olat temporary unavailability
|
||||||
log.error("Unexpected error: ", e);
|
log.error("Unexpected error: {}", e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ sebserver.webservice.clean-db-on-startup=false
|
||||||
|
|
||||||
# webservice configuration
|
# webservice configuration
|
||||||
sebserver.init.adminaccount.gen-on-init=false
|
sebserver.init.adminaccount.gen-on-init=false
|
||||||
sebserver.webservice.distributed=true
|
sebserver.webservice.distributed=false
|
||||||
#sebserver.webservice.master.delay.threshold=10000
|
#sebserver.webservice.master.delay.threshold=10000
|
||||||
sebserver.webservice.http.external.scheme=http
|
sebserver.webservice.http.external.scheme=http
|
||||||
sebserver.webservice.http.external.servername=localhost
|
sebserver.webservice.http.external.servername=localhost
|
||||||
|
|
|
@ -111,6 +111,7 @@ sebserver.form.validation.fieldError.serverNotAvailable=No service seems to be a
|
||||||
sebserver.form.validation.fieldError.url.invalid=Invalid URL. The given URL cannot be reached.
|
sebserver.form.validation.fieldError.url.invalid=Invalid URL. The given URL cannot be reached.
|
||||||
sebserver.form.validation.fieldError.typeInvalid=This type is not implemented yet and cannot be used.
|
sebserver.form.validation.fieldError.typeInvalid=This type is not implemented yet and cannot be used.
|
||||||
sebserver.form.validation.fieldError.url.noservice=The expected service is not available within the given URL and API access.
|
sebserver.form.validation.fieldError.url.noservice=The expected service is not available within the given URL and API access.
|
||||||
|
sebserver.form.validation.fieldError.url.noaccess=There has no access been granted by the service. Please check the given access credentials.
|
||||||
sebserver.form.validation.fieldError.thresholdDuplicate=There are duplicate threshold values.
|
sebserver.form.validation.fieldError.thresholdDuplicate=There are duplicate threshold values.
|
||||||
sebserver.form.validation.fieldError.thresholdEmpty=There are missing values or colors for the threshold declaration
|
sebserver.form.validation.fieldError.thresholdEmpty=There are missing values or colors for the threshold declaration
|
||||||
sebserver.form.validation.fieldError.invalidIP=Invalid IP v4. Please enter a valid IP-address (v4)
|
sebserver.form.validation.fieldError.invalidIP=Invalid IP v4. Please enter a valid IP-address (v4)
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class OlatLmsAPITemplateTest extends AdministrationAPIIntegrationTester {
|
||||||
private ExamConfigurationValueService examConfigurationValueService;
|
private ExamConfigurationValueService examConfigurationValueService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CacheManager cacheManager;
|
private CacheManager cacheManager;
|
||||||
|
@Autowired
|
||||||
|
private OlatLmsRestTemplate olatLmsRestTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRestriction() throws Exception {
|
public void testSetRestriction() throws Exception {
|
||||||
|
|
Loading…
Reference in a new issue