|
@@ -1,31 +1,38 @@
|
|
-package riomhaire.lti.business.actions;
|
|
|
|
|
|
+package riomhaire.lti.core.business.actions;
|
|
|
|
|
|
import com.auth0.jwt.JWT;
|
|
import com.auth0.jwt.JWT;
|
|
-import lombok.Builder;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
-import riomhaire.lti.adapters.token.JWKBasedJwtToMapAdapter;
|
|
|
|
-import riomhaire.lti.infrastructure.Registry;
|
|
|
|
-import riomhaire.lti.model.interfaces.Action;
|
|
|
|
-import riomhaire.lti.model.interfaces.DecodeException;
|
|
|
|
|
|
+import riomhaire.lti.Registry;
|
|
|
|
+import riomhaire.lti.core.adapters.token.JWKBasedJwtToMapAdapterBuilder;
|
|
|
|
+import riomhaire.lti.core.model.interfaces.Action;
|
|
|
|
+import riomhaire.lti.core.model.interfaces.DecodeException;
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+import static riomhaire.lti.core.business.builder.Builder.LaunchContentBuilder;
|
|
|
|
+import static riomhaire.lti.core.business.builder.Builder.SelectDeepLinkContentBuilder;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* This is the router for lti type messages - lti launch and create deep link .. this action will delegate to the
|
|
* This is the router for lti type messages - lti launch and create deep link .. this action will delegate to the
|
|
* appropriate sub handler
|
|
* appropriate sub handler
|
|
*/
|
|
*/
|
|
@Slf4j
|
|
@Slf4j
|
|
-@Builder
|
|
|
|
public class ProcessLtiMessage implements Action<ModelAndView> {
|
|
public class ProcessLtiMessage implements Action<ModelAndView> {
|
|
public static final String CLAIM_MESSAGE_TYPE = "https://purl.imsglobal.org/spec/lti/claim/message_type";
|
|
public static final String CLAIM_MESSAGE_TYPE = "https://purl.imsglobal.org/spec/lti/claim/message_type";
|
|
public static final String LTI_RESOURCE_LINK_REQUEST = "LtiResourceLinkRequest";
|
|
public static final String LTI_RESOURCE_LINK_REQUEST = "LtiResourceLinkRequest";
|
|
public static final String LTI_DEEP_LINKING_REQUEST = "LtiDeepLinkingRequest";
|
|
public static final String LTI_DEEP_LINKING_REQUEST = "LtiDeepLinkingRequest";
|
|
- Registry registry;
|
|
|
|
- Map<String, String> queryParams;
|
|
|
|
- Map<String, Object> metadata;
|
|
|
|
|
|
|
|
|
|
+ protected Registry registry;
|
|
|
|
+ protected Map<String, String> queryParams;
|
|
|
|
+ protected Map<String, Object> metadata;
|
|
|
|
+
|
|
|
|
+ public ProcessLtiMessage(Registry registry, Map<String, String> queryParams, Map<String, Object> metadata) {
|
|
|
|
+ this.registry = registry;
|
|
|
|
+ this.queryParams = queryParams;
|
|
|
|
+ this.metadata = metadata;
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ModelAndView execute() {
|
|
public ModelAndView execute() {
|
|
@@ -46,7 +53,7 @@ public class ProcessLtiMessage implements Action<ModelAndView> {
|
|
return switch (messageType) {
|
|
return switch (messageType) {
|
|
case LTI_RESOURCE_LINK_REQUEST:
|
|
case LTI_RESOURCE_LINK_REQUEST:
|
|
//noinspection unchecked
|
|
//noinspection unchecked
|
|
- yield LaunchContent.builder()
|
|
|
|
|
|
+ yield registry.actionBuilderFactory().getBuilder(LaunchContentBuilder)
|
|
.registry(registry)
|
|
.registry(registry)
|
|
.metadata(metadata)
|
|
.metadata(metadata)
|
|
.queryParams(queryParams)
|
|
.queryParams(queryParams)
|
|
@@ -55,7 +62,7 @@ public class ProcessLtiMessage implements Action<ModelAndView> {
|
|
.execute();
|
|
.execute();
|
|
case LTI_DEEP_LINKING_REQUEST:
|
|
case LTI_DEEP_LINKING_REQUEST:
|
|
//noinspection unchecked
|
|
//noinspection unchecked
|
|
- yield SelectDeepLinkContent.builder()
|
|
|
|
|
|
+ yield registry.actionBuilderFactory().getBuilder(SelectDeepLinkContentBuilder)
|
|
.registry(registry)
|
|
.registry(registry)
|
|
.metadata(metadata)
|
|
.metadata(metadata)
|
|
.queryParams(queryParams)
|
|
.queryParams(queryParams)
|
|
@@ -73,16 +80,16 @@ public class ProcessLtiMessage implements Action<ModelAndView> {
|
|
* @param token token to decode
|
|
* @param token token to decode
|
|
* @param issuer who the issuer was
|
|
* @param issuer who the issuer was
|
|
* @param clientId the client id
|
|
* @param clientId the client id
|
|
- * @param toolRegistration the tool configguration
|
|
|
|
- * @return
|
|
|
|
|
|
+ * @param toolRegistration the tool configuration
|
|
|
|
+ * @return Model and View to Return the code
|
|
*/
|
|
*/
|
|
- private HashMap<Object, Object> decodeToken(String token, String issuer, String clientId, java.util.Optional<riomhaire.lti.model.ClientConfiguration> toolRegistration) {
|
|
|
|
|
|
+ private HashMap<Object, Object> decodeToken(String token, String issuer, String clientId, java.util.Optional<riomhaire.lti.core.model.ClientConfiguration> toolRegistration) {
|
|
var claims = new HashMap<>();
|
|
var claims = new HashMap<>();
|
|
|
|
|
|
if (toolRegistration.isPresent()) {
|
|
if (toolRegistration.isPresent()) {
|
|
// Validate JWT to verify its by who they say they are
|
|
// Validate JWT to verify its by who they say they are
|
|
var clientConfiguration = toolRegistration.get();
|
|
var clientConfiguration = toolRegistration.get();
|
|
- var adapter = JWKBasedJwtToMapAdapter.builder()
|
|
|
|
|
|
+ var adapter = JWKBasedJwtToMapAdapterBuilder.context()
|
|
.jwksUrl(clientConfiguration.getJwksUrl())
|
|
.jwksUrl(clientConfiguration.getJwksUrl())
|
|
.skipVerification(clientConfiguration.isSkipVerification())
|
|
.skipVerification(clientConfiguration.isSkipVerification())
|
|
.build();
|
|
.build();
|