Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Adapt LTI advantage deep linking service for exercise selection from Moodle #7425

Merged
merged 141 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
b71ebec
make lti user login again if email exists
basak-akan Oct 3, 2023
b0b05e3
throw exception when cannot find user
basak-akan Oct 3, 2023
7b54a3b
adapt authenticate newuser server test
basak-akan Oct 3, 2023
3571ede
add new handling for not logged in users
basak-akan Oct 5, 2023
c657f5e
fix server test
basak-akan Oct 5, 2023
c6ba5ab
first structure implementation
basak-akan Oct 6, 2023
dbb9a44
fix client tests
basak-akan Oct 6, 2023
1787912
add custom exception
basak-akan Oct 6, 2023
db38dff
refactor for teamscale findings fix
basak-akan Oct 6, 2023
8fdb9c9
fix request param key
basak-akan Oct 8, 2023
1bf5ecd
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 9, 2023
344b13b
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Oct 9, 2023
9a4fb75
redirect to home page wait to login
basak-akan Oct 11, 2023
6cf5b89
refactor var name
basak-akan Oct 11, 2023
fb9a1f4
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 11, 2023
45beaaa
small fixes
basak-akan Oct 11, 2023
e21156e
fix redirection after login
basak-akan Oct 12, 2023
0ad1e58
add check for if user already logged in
basak-akan Oct 12, 2023
41ef03a
revert unnecessary request param username
basak-akan Oct 12, 2023
e2ec1bc
fix team-scale findings
basak-akan Oct 12, 2023
d6a45c6
fix server tests
basak-akan Oct 12, 2023
0fd08fc
fix for already existing users
basak-akan Oct 12, 2023
120782f
fix codacy issues
basak-akan Oct 13, 2023
0523df8
first implementation for server-side
basak-akan Oct 16, 2023
c157059
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Oct 16, 2023
3d626b9
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 17, 2023
17850c4
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 17, 2023
da4d81f
implement feedback from Maximilian
basak-akan Oct 17, 2023
d289b23
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 17, 2023
f6cc2a9
implement client with server adaptations
basak-akan Oct 17, 2023
ce6a83f
minor button adjustments
basak-akan Oct 17, 2023
712b7c5
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 18, 2023
4730bdf
ui improvments
basak-akan Oct 19, 2023
59d0053
fix server test
basak-akan Oct 19, 2023
cfd5862
add java docs and minor refactoring
basak-akan Oct 19, 2023
0f2f9ed
rename client components
basak-akan Oct 19, 2023
65449d6
cleanup client components
basak-akan Oct 19, 2023
de9301a
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Oct 19, 2023
b0c03aa
fix server test
basak-akan Oct 19, 2023
aad277f
fix server test
basak-akan Oct 19, 2023
692794e
add client tests
basak-akan Oct 21, 2023
734dc16
Merge branch 'chore/lti-authentication' of https://github.com/ls1intu…
basak-akan Oct 21, 2023
ca61cea
add one more client test
basak-akan Oct 21, 2023
295463c
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 21, 2023
8abf2a7
try fix autosubmit form method
basak-akan Oct 23, 2023
df3bfe7
Merge branch 'chore/lti-authentication' into feature/lti-deep-linking
basak-akan Oct 23, 2023
8afe8e2
extract Lti13DeepLinkingResponse class
basak-akan Oct 23, 2023
9da589c
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 25, 2023
a0f6fc0
add LtiDeepLinkingService server tests, adapt deeplinking target uri …
basak-akan Oct 26, 2023
a08a532
Merge branch 'develop' into chore/lti-authentication
basak-akan Oct 26, 2023
cadd033
Merge branch 'chore/lti-authentication' into feature/lti-deep-linking
basak-akan Oct 26, 2023
eb421b3
add integration tests
basak-akan Oct 26, 2023
48ac226
add server tests for Lti13Service, small path fix
basak-akan Oct 26, 2023
e1edb92
use safeResourceUrl pipe
basak-akan Nov 1, 2023
20433cb
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 1, 2023
cdf033c
fix test
basak-akan Nov 1, 2023
186d6b0
add client tests and small fixes
basak-akan Nov 3, 2023
c0287b0
add more client tests
basak-akan Nov 3, 2023
5c0a795
fix json implementations
basak-akan Nov 3, 2023
6c64b07
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 3, 2023
327d108
increase test coverage
basak-akan Nov 3, 2023
f7bfc68
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 3, 2023
a98df2c
small fixes
basak-akan Nov 5, 2023
bcc2553
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 5, 2023
f796cdd
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 5, 2023
e2f712d
fix client test
basak-akan Nov 5, 2023
90fc81b
add javadocs
basak-akan Nov 7, 2023
c0ef452
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 7, 2023
7a16314
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 8, 2023
d3d1cbb
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 11, 2023
f900bf0
refactor LtiDeepLinkingService
basak-akan Nov 16, 2023
43b0176
implement code review
basak-akan Nov 16, 2023
6074bcc
fix server tests
basak-akan Nov 16, 2023
7f42db4
fix client tests
basak-akan Nov 16, 2023
3d61613
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 16, 2023
3214cc7
add more server tests
basak-akan Nov 16, 2023
7518c10
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 16, 2023
da2f852
improve server test
basak-akan Nov 17, 2023
fdf68c3
improve deep-linking server test
basak-akan Nov 17, 2023
45a9187
fix codacy results
basak-akan Nov 17, 2023
df6e548
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 17, 2023
41d1bd4
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 17, 2023
b585f5c
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 18, 2023
5330fa9
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 19, 2023
f7ccbef
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 19, 2023
feac57f
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 19, 2023
c1c82d7
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 20, 2023
fff74a0
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 20, 2023
2b6f3e8
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 21, 2023
1e8a6ea
add login name to pop-up
basak-akan Nov 21, 2023
e1d005f
add prefilled username
basak-akan Nov 21, 2023
607a6bb
fix client test
basak-akan Nov 21, 2023
711f4bc
add username validation
basak-akan Nov 21, 2023
bb47e4a
revert unnecessary changes
basak-akan Nov 22, 2023
e9283cd
try server test fix
basak-akan Nov 22, 2023
5c85b75
try server test fix 2
basak-akan Nov 22, 2023
7ddfd6f
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 22, 2023
20e79e2
apply review feedback
basak-akan Nov 22, 2023
a4ae820
fix client tests
basak-akan Nov 22, 2023
0b036d2
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 23, 2023
603dbd3
try fix server tests
basak-akan Nov 23, 2023
b1c713d
try fix server tests lti quiz integration tests
basak-akan Nov 23, 2023
6f0d6ec
move spybean to abstract class
basak-akan Nov 23, 2023
d4bfe04
revert unnecessary test changes
basak-akan Nov 23, 2023
5917588
match the production package structure
basak-akan Nov 23, 2023
b167eff
add validate lti username
basak-akan Nov 23, 2023
fe898ba
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 23, 2023
faeb2ad
sanitize username
basak-akan Nov 23, 2023
aab0bfa
sanitize username replace \r\n
basak-akan Nov 23, 2023
7a14ead
revert some changes
basak-akan Nov 23, 2023
fce4299
fix copy user login name
basak-akan Nov 24, 2023
93eff6c
check if optionalUsername is present before
basak-akan Nov 24, 2023
252bb01
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 24, 2023
0b3fcd5
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 24, 2023
8125efa
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 25, 2023
4361d9c
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 25, 2023
a8cbc6e
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 26, 2023
81249ae
implement feedback for de translation
basak-akan Nov 26, 2023
0397117
reuse lti claims
basak-akan Nov 26, 2023
573b7cc
Merge branch 'feature/lti-deep-linking' of https://github.com/ls1intu…
basak-akan Nov 26, 2023
a854f49
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 26, 2023
ab2f1d0
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 26, 2023
c764e34
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 27, 2023
f993d4f
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 28, 2023
220c4c0
Merge branch 'develop' into feature/add-lti-login-name
krusche Nov 28, 2023
0d4099c
add javadoc
basak-akan Nov 28, 2023
24db55e
Merge branch 'develop' into feature/add-lti-login-name
basak-akan Nov 28, 2023
39ed807
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Nov 29, 2023
77b656a
address teamscale issues
basak-akan Nov 29, 2023
9c89022
refactor response
basak-akan Nov 29, 2023
285d507
address more teamscale issues and fix tests
basak-akan Nov 29, 2023
6d384b1
Merge branch 'feature/add-lti-login-name' into feature/lti-deep-linking
basak-akan Nov 29, 2023
08744ca
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Dec 2, 2023
7233d70
fix build
basak-akan Dec 2, 2023
efc7b72
add null check for ltiIdToken authToken and targetLink and fix warnings
basak-akan Dec 2, 2023
48065aa
fix more warnings
basak-akan Dec 2, 2023
45c0313
fix teamscale
basak-akan Dec 2, 2023
5af678c
implement julian suggestion
basak-akan Dec 2, 2023
abded7d
fix tests
basak-akan Dec 2, 2023
6b5e88b
fix small issue
basak-akan Dec 4, 2023
a45b844
Merge branch 'develop' into feature/lti-deep-linking
basak-akan Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,27 @@
@Profile("lti")
public class CustomLti13Configurer extends Lti13Configurer {

/** Path for login. **/
private static final String LOGIN_PATH = "/auth-login";

/** Path for initiating login process. */
private static final String LOGIN_INITIATION_PATH = "/initiate-login";

/** Base path for LTI 1.3 API endpoints. */
public static final String LTI13_BASE_PATH = "/api/public/lti13";

/** Full path for LTI 1.3 login. */
public static final String LTI13_LOGIN_PATH = LTI13_BASE_PATH + LOGIN_PATH;

/** Full path for LTI 1.3 login initiation. */
public static final String LTI13_LOGIN_INITIATION_PATH = LTI13_BASE_PATH + LOGIN_INITIATION_PATH;

/** Redirect proxy path for LTI 1.3 login. */
public static final String LTI13_LOGIN_REDIRECT_PROXY_PATH = LTI13_BASE_PATH + "/auth-callback";

/** Path for LTI 1.3 deep linking. */
public static final String LTI13_DEEPLINKING_PATH = "/lti/deep-linking/";

public CustomLti13Configurer() {
super.ltiPath(LTI13_BASE_PATH);
super.loginInitiationPath(LOGIN_INITIATION_PATH);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/de/tum/in/www1/artemis/domain/lti/Claims.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@

public class Claims extends uk.ac.ox.ctl.lti13.lti.Claims {

/**
* Constant for LTI Assignment and Grade Services (AGS) claim endpoint.
* Used to identify the AGS service endpoint in LTI messages.
*/
public static final String AGS_CLAIM = "https://purl.imsglobal.org/spec/lti-ags/claim/endpoint";

/**
* Constant for LTI Deep Linking message claim.
* Used to carry messages specific to LTI Deep Linking requests and responses.
*/
public static final String MSG = "https://purl.imsglobal.org/spec/lti-dl/claim/msg";
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Lti13ClientRegistration(String serverUrl, Course course, String clientReg
toolConfiguration.setDomain(domain);
toolConfiguration.setTargetLinkUri(serverUrl + "/courses/" + course.getId());
toolConfiguration.setClaims(Arrays.asList("iss", "email", "sub", "name", "given_name", "family_name"));
Message deepLinkingMessage = new Message("LtiDeepLinkingRequest", serverUrl + CustomLti13Configurer.LTI13_BASE_PATH + "/deep-linking/" + course.getId());
Message deepLinkingMessage = new Message("LtiDeepLinkingRequest", serverUrl + CustomLti13Configurer.LTI13_DEEPLINKING_PATH + course.getId());
toolConfiguration.setMessages(List.of(deepLinkingMessage));
this.setLti13ToolConfiguration(toolConfiguration);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
package de.tum.in.www1.artemis.domain.lti;

import java.util.HashMap;
import java.util.Map;

import org.springframework.security.oauth2.core.oidc.OidcIdToken;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
* Represents the LTI 1.3 Deep Linking Response.
* It encapsulates the necessary information to construct a valid deep linking response
* according to the LTI 1.3 specification.
*/
public class Lti13DeepLinkingResponse {
lennart-keller marked this conversation as resolved.
Show resolved Hide resolved

@JsonProperty("aud")
private String aud;

@JsonProperty("iss")
private String iss;

@JsonProperty("exp")
private String exp;

@JsonProperty("iat")
private String iat;

@JsonProperty("nonce")
private String nonce;

@JsonProperty(Claims.MSG)
private String message;

@JsonProperty(Claims.LTI_DEPLOYMENT_ID)
private String deploymentId;

@JsonProperty(Claims.MESSAGE_TYPE)
private String messageType;

@JsonProperty(Claims.LTI_VERSION)
private String ltiVersion;

@JsonProperty(Claims.CONTENT_ITEMS)
private String contentItems;

private JsonObject deepLinkingSettings;

private String clientRegistrationId;

private String returnUrl;

/**
* Constructs an Lti13DeepLinkingResponse from an OIDC ID token and client registration ID.
*
* @param ltiIdToken the OIDC ID token
* @param clientRegistrationId the client registration ID
*/
public Lti13DeepLinkingResponse(OidcIdToken ltiIdToken, String clientRegistrationId) {
validateClaims(ltiIdToken);

this.deepLinkingSettings = JsonParser.parseString(ltiIdToken.getClaim(Claims.DEEP_LINKING_SETTINGS).toString()).getAsJsonObject();
this.setReturnUrl(this.deepLinkingSettings.get("deep_link_return_url").getAsString());
this.clientRegistrationId = clientRegistrationId;

this.setAud(ltiIdToken.getClaim("iss").toString());
this.setIss(ltiIdToken.getClaim("aud").toString().replace("[", "").replace("]", ""));
this.setExp(ltiIdToken.getClaim("exp").toString());
this.setIat(ltiIdToken.getClaim("iat").toString());
this.setNonce(ltiIdToken.getClaim("nonce").toString());
this.setMessage("Content successfully linked");
this.setDeploymentId(ltiIdToken.getClaim(Claims.LTI_DEPLOYMENT_ID).toString());
this.setMessageType("LtiDeepLinkingResponse");
this.setLtiVersion("1.3.0");
}

/**
* Retrieves a map of claims to be included in the ID token.
*
* @return a map of claims
*/
public Map<String, Object> getClaims() {
Map<String, Object> claims = new HashMap<>();

claims.put("aud", aud);
claims.put("iss", iss);
claims.put("exp", exp);
claims.put("iat", iat);
claims.put("nonce", nonce);
claims.put(Claims.MSG, message);
claims.put(Claims.LTI_DEPLOYMENT_ID, deploymentId);
claims.put(Claims.MESSAGE_TYPE, messageType);
claims.put(Claims.LTI_VERSION, ltiVersion);
claims.put(Claims.CONTENT_ITEMS, contentItems);

return claims;
}

private void validateClaims(OidcIdToken ltiIdToken) {
if (ltiIdToken == null) {
throw new IllegalArgumentException("The OIDC ID token must not be null.");
}

Object deepLinkingSettingsElement = ltiIdToken.getClaim(Claims.DEEP_LINKING_SETTINGS);
if (deepLinkingSettingsElement == null) {
throw new IllegalArgumentException("Missing or invalid deep linking settings in ID token.");
}

ensureClaimPresent(ltiIdToken, "iss");
ensureClaimPresent(ltiIdToken, "aud");
ensureClaimPresent(ltiIdToken, "exp");
ensureClaimPresent(ltiIdToken, "iat");
ensureClaimPresent(ltiIdToken, "nonce");
ensureClaimPresent(ltiIdToken, Claims.LTI_DEPLOYMENT_ID);
}

private void ensureClaimPresent(OidcIdToken ltiIdToken, String claimName) {
Object claimValue = ltiIdToken.getClaim(claimName);
if (claimValue == null) {
throw new IllegalArgumentException("Missing claim: " + claimName);
}
}

public void setAud(String aud) {
this.aud = aud;
}

public String getIss() {
return iss;
}

public void setIss(String iss) {
this.iss = iss;
}

public String getExp() {
return exp;
}

public void setExp(String exp) {
this.exp = exp;
}

public String getIat() {
return iat;
}

public void setIat(String iat) {
this.iat = iat;
}

public String getNonce() {
return nonce;
}

public void setNonce(String nonce) {
this.nonce = nonce;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getDeploymentId() {
return deploymentId;
}

public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}

public String getMessageType() {
return messageType;
}

public void setMessageType(String messageType) {
this.messageType = messageType;
}

public String getLtiVersion() {
return ltiVersion;
}

public void setLtiVersion(String ltiVersion) {
this.ltiVersion = ltiVersion;
}

public String getContentItems() {
return contentItems;
}

public void setContentItems(String contentItems) {
this.contentItems = contentItems;
}

public JsonObject getDeepLinkingSettings() {
return deepLinkingSettings;
}

public void setDeepLinkingSettings(JsonObject deepLinkingSettings) {
this.deepLinkingSettings = deepLinkingSettings;
}

public String getClientRegistrationId() {
return clientRegistrationId;
}

public void setClientRegistrationId(String clientRegistrationId) {
this.clientRegistrationId = clientRegistrationId;
}

public String getAud() {
return aud;
}

public String getReturnUrl() {
return returnUrl;
}

public void setReturnUrl(String returnUrl) {
this.returnUrl = returnUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tum.in.www1.artemis.domain.lti;

/**
* Holds LTI authentication response details.
*
* @param targetLinkUri URI targeted in the LTI process.
* @param ltiIdToken LTI service provided ID token.
* @param clientRegistrationId Client's registration ID with LTI service.
*/
public record LtiAuthenticationResponseDTO(String targetLinkUri, String ltiIdToken, String clientRegistrationId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.UriComponentsBuilder;

import com.google.gson.JsonObject;
import com.google.gson.Gson;

import de.tum.in.www1.artemis.domain.lti.Claims;
import de.tum.in.www1.artemis.domain.lti.LtiAuthenticationResponseDTO;
import de.tum.in.www1.artemis.exception.LtiEmailAlreadyInUseException;
import de.tum.in.www1.artemis.security.SecurityUtils;
import de.tum.in.www1.artemis.service.connectors.lti.Lti13Service;
import uk.ac.ox.ctl.lti13.security.oauth2.client.lti.authentication.OidcAuthenticationToken;
import uk.ac.ox.ctl.lti13.security.oauth2.client.lti.web.OAuth2LoginAuthenticationFilter;
Expand Down Expand Up @@ -56,32 +58,37 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
return;
}

// Initialize targetLink as an empty string here to ensure it has a value even if an exception is caught later.
String targetLink = "";
OidcIdToken ltiIdToken = null;
try {
OidcAuthenticationToken authToken = finishOidcFlow(request, response);
OidcIdToken ltiIdToken = ((OidcUser) authToken.getPrincipal()).getIdToken();
String targetLink = ltiIdToken.getClaim(Claims.TARGET_LINK_URI).toString();

try {
// here we need to check if this is a deep-linking request or a launch request
if ("LtiDeepLinkingRequest".equals(ltiIdToken.getClaim(Claims.MESSAGE_TYPE))) {
lti13Service.startDeepLinking(ltiIdToken);
}
else {
lti13Service.performLaunch(ltiIdToken, authToken.getAuthorizedClientRegistrationId());
}
}
catch (LtiEmailAlreadyInUseException ex) {
// LtiEmailAlreadyInUseException is thrown in case of user who has email address in use is not authenticated after targetLink is set
// We need targetLink to redirect user on the client-side after successful authentication
handleLtiEmailAlreadyInUseException(response, ltiIdToken);
}

ltiIdToken = ((OidcUser) authToken.getPrincipal()).getIdToken();

targetLink = ltiIdToken.getClaim(Claims.TARGET_LINK_URI).toString();

lti13Service.performLaunch(ltiIdToken, authToken.getAuthorizedClientRegistrationId());

writeResponse(ltiIdToken.getClaim(Claims.TARGET_LINK_URI), response);
writeResponse(targetLink, ltiIdToken, authToken.getAuthorizedClientRegistrationId(), response);
}
catch (HttpClientErrorException | OAuth2AuthenticationException | IllegalStateException ex) {
log.error("Error during LTI 1.3 launch request: {}", ex.getMessage());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "LTI 1.3 Launch failed");
}
catch (LtiEmailAlreadyInUseException ex) {
// LtiEmailAlreadyInUseException is thrown in case of user who has email address in use is not authenticated after targetLink is set
// We need targetLink to redirect user on the client-side after successful authentication
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(targetLink);
lti13Service.buildLtiEmailInUseResponse(response, ltiIdToken);
response.setHeader("TargetLinkUri", uriBuilder.build().toUriString());
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "LTI 1.3 user authentication failed");
}
}

private void handleLtiEmailAlreadyInUseException(HttpServletResponse response, OidcIdToken ltiIdToken) {
this.lti13Service.buildLtiEmailInUseResponse(response, ltiIdToken);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}

private OidcAuthenticationToken finishOidcFlow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Expand All @@ -100,18 +107,18 @@ private OidcAuthenticationToken finishOidcFlow(HttpServletRequest request, HttpS
return ltiAuthToken;
}

private void writeResponse(String targetLinkUri, HttpServletResponse response) throws IOException {
private void writeResponse(String targetLinkUri, OidcIdToken ltiIdToken, String clientRegistrationId, HttpServletResponse response) throws IOException {
PrintWriter writer = response.getWriter();

UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(targetLinkUri);
lti13Service.buildLtiResponse(uriBuilder, response);

JsonObject json = new JsonObject();
json.addProperty("targetLinkUri", uriBuilder.build().toUriString());
if (SecurityUtils.isAuthenticated()) {
lti13Service.buildLtiResponse(uriBuilder, response);
}
LtiAuthenticationResponseDTO jsonResponse = new LtiAuthenticationResponseDTO(uriBuilder.build().toUriString(), ltiIdToken.getTokenValue(), clientRegistrationId);

response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
writer.print(json);
writer.print(new Gson().toJson(jsonResponse));
writer.flush();
}
}
Loading
Loading