Merge remote-tracking branch 'origin/dev-1.1.0' into development

This commit is contained in:
anhefti 2021-03-17 10:39:21 +01:00
commit 89c2406b4e
2 changed files with 51 additions and 18 deletions

View file

@ -118,6 +118,11 @@ public final class InstitutionalAuthenticationEntryPoint implements Authenticati
if (StringUtils.isNoneBlank(institutionalEndpoint) && log.isDebugEnabled()) {
log.debug("No default gui entrypoint requested: {}", institutionalEndpoint);
} else {
request.getSession().setAttribute(INST_SUFFIX_ATTRIBUTE, null);
request.getSession().removeAttribute(API.PARAM_LOGO_IMAGE);
forwardToEntryPoint(request, response, this.guiEntryPoint, false);
return;
}
try {
@ -198,6 +203,9 @@ public final class InstitutionalAuthenticationEntryPoint implements Authenticati
public static String extractInstitutionalEndpoint(final HttpServletRequest request) {
final String requestURI = request.getRequestURI();
if (StringUtils.isBlank(requestURI) || requestURI.equals(Constants.SLASH.toString())) {
return null;
}
if (log.isDebugEnabled()) {
log.debug("Trying to verify institution from requested entrypoint url: {}", requestURI);

View file

@ -130,7 +130,8 @@ class MoodleRestTemplateFactory {
if (result.hasError()) {
log.warn("Failed to get access token for LMS: {}({})",
this.lmsSetup.name,
this.lmsSetup.id);
this.lmsSetup.id,
result.getError());
}
return result;
})
@ -336,27 +337,51 @@ class MoodleRestTemplateFactory {
private void requestAccessToken() {
final ResponseEntity<String> response = super.exchange(
this.serverURL + this.tokenPath,
HttpMethod.GET,
this.tokenReqEntity,
String.class,
this.tokenReqURIVars);
if (response.getStatusCode() != HttpStatus.OK) {
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody());
}
try {
final MoodleToken moodleToken = MoodleRestTemplateFactory.this.jsonMapper.readValue(
response.getBody(),
MoodleToken.class);
final ResponseEntity<String> response = super.exchange(
this.serverURL + this.tokenPath,
HttpMethod.GET,
this.tokenReqEntity,
String.class,
this.tokenReqURIVars);
if (response.getStatusCode() != HttpStatus.OK) {
log.error("Failed to gain access token for LMS (Moodle): lmsSetup: {} response: {} : {}",
MoodleRestTemplateFactory.this.lmsSetup,
response.getStatusCode(),
response.getBody());
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody());
}
try {
final MoodleToken moodleToken = MoodleRestTemplateFactory.this.jsonMapper.readValue(
response.getBody(),
MoodleToken.class);
if (moodleToken == null || moodleToken.token == null) {
throw new RuntimeException("Access Token request with 200 but no or invalid token body");
} else {
log.info("Successfully get access token from Moodle: {}",
MoodleRestTemplateFactory.this.lmsSetup);
}
this.accessToken = moodleToken.token;
} catch (final Exception e) {
log.error("Failed to gain access token for LMS (Moodle): lmsSetup: {} response: {} : {}",
MoodleRestTemplateFactory.this.lmsSetup,
response.getStatusCode(),
response.getBody());
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody(), e);
}
this.accessToken = moodleToken.token;
} catch (final Exception e) {
log.error("Failed to gain access token for LMS (Moodle): lmsSetup: {} :",
MoodleRestTemplateFactory.this.lmsSetup,
e);
throw new RuntimeException("Failed to gain access token for LMS (Moodle): lmsSetup: " +
MoodleRestTemplateFactory.this.lmsSetup + " response: " + response.getBody(), e);
MoodleRestTemplateFactory.this.lmsSetup + " cause: " + e.getMessage());
}
}