Merge remote-tracking branch 'origin/dev-1.1.0' into development
This commit is contained in:
commit
89c2406b4e
2 changed files with 51 additions and 18 deletions
|
@ -118,6 +118,11 @@ public final class InstitutionalAuthenticationEntryPoint implements Authenticati
|
||||||
|
|
||||||
if (StringUtils.isNoneBlank(institutionalEndpoint) && log.isDebugEnabled()) {
|
if (StringUtils.isNoneBlank(institutionalEndpoint) && log.isDebugEnabled()) {
|
||||||
log.debug("No default gui entrypoint requested: {}", institutionalEndpoint);
|
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 {
|
try {
|
||||||
|
@ -198,6 +203,9 @@ public final class InstitutionalAuthenticationEntryPoint implements Authenticati
|
||||||
|
|
||||||
public static String extractInstitutionalEndpoint(final HttpServletRequest request) {
|
public static String extractInstitutionalEndpoint(final HttpServletRequest request) {
|
||||||
final String requestURI = request.getRequestURI();
|
final String requestURI = request.getRequestURI();
|
||||||
|
if (StringUtils.isBlank(requestURI) || requestURI.equals(Constants.SLASH.toString())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Trying to verify institution from requested entrypoint url: {}", requestURI);
|
log.debug("Trying to verify institution from requested entrypoint url: {}", requestURI);
|
||||||
|
|
|
@ -130,7 +130,8 @@ class MoodleRestTemplateFactory {
|
||||||
if (result.hasError()) {
|
if (result.hasError()) {
|
||||||
log.warn("Failed to get access token for LMS: {}({})",
|
log.warn("Failed to get access token for LMS: {}({})",
|
||||||
this.lmsSetup.name,
|
this.lmsSetup.name,
|
||||||
this.lmsSetup.id);
|
this.lmsSetup.id,
|
||||||
|
result.getError());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
|
@ -336,27 +337,51 @@ class MoodleRestTemplateFactory {
|
||||||
|
|
||||||
private void requestAccessToken() {
|
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 {
|
try {
|
||||||
final MoodleToken moodleToken = MoodleRestTemplateFactory.this.jsonMapper.readValue(
|
final ResponseEntity<String> response = super.exchange(
|
||||||
response.getBody(),
|
this.serverURL + this.tokenPath,
|
||||||
MoodleToken.class);
|
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) {
|
} 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: " +
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue