This commit is contained in:
unknown 2020-05-03 16:12:43 +02:00
parent 9671929787
commit 3a861f03c3
4 changed files with 21 additions and 22 deletions

View File

@ -46,7 +46,7 @@ public class CourseController {
String url, @RequestParam(name = "name", required = false, defaultValue = "")
String name, Model model) {
courseRepository.save(new Course(null, name, url, key, secret));
courseRepository.save(new Course(null, name, url, key, secret, null));
return "start"; //view
}

View File

@ -38,12 +38,6 @@ public class StartController {
for (Course course : courses) {
LtiSigner signer = new LtiOauthSigner();
Map<String, String> parameters = new HashMap<>();
if (course.getUrl().contains("?")) {
for (String element : course.getUrl().split("\\?")[1].split("\\&")) {
String[] splitted = element.split("=");
parameters.put(splitted[0], splitted[1]);
}
}
parameters.put("lti_message_type", "basic-lti-launch-request");
parameters.put("lti_version", "LTI-1p0");
parameters.put("resource_link_id", user.getUsername() + "_" + course.getCourse_key());
@ -53,14 +47,11 @@ public class StartController {
parameters.put("target", "frame");
try {
Map<String, String> signedParameters = signer.signParameters(parameters, course.getCourse_key(), course.getSecret(), course.getUrl(), "POST");
String link = course.getUrl();
if (link.contains("?"))
link += "&" + "oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "&lti_message_type=" + signedParameters.get("lti_message_type") + "&lti_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id") + "&user_id=" + signedParameters.get("user_id") + "&lis_person_name_given=" + signedParameters.get("lis_person_name_given") + "&tool_consumer_instance_name=" + signedParameters.get("tool_consumer_instance_name") + "&target=" + signedParameters.get("target");
else
link += "?" + "oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "&lti_message_type=" + signedParameters.get("lti_message_type") + "&lti_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id") + "&user_id=" + signedParameters.get("user_id") + "&lis_person_name_given=" + signedParameters.get("lis_person_name_given") + "&tool_consumer_instance_name=" + signedParameters.get("tool_consumer_instance_name") + "&target=" + signedParameters.get("target");
/* String link = course.getUrl();
link += "?oauth_nonce=" + signedParameters.get("oauth_nonce") + "&oauth_signature=" + signedParameters.get("oauth_signature") + "&oauth_consumer_key=" + signedParameters.get("oauth_consumer_key") + "&oauth_signature_method=" + signedParameters.get("oauth_signature_method") + "&oauth_timestamp=" + signedParameters.get("oauth_timestamp") + "&oauth_version=" + signedParameters.get("oauth_version") + "&lti_message_type=" + signedParameters.get("lti_message_type") + "&lti_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id") + "&user_id=" + signedParameters.get("user_id") + "&lis_person_name_given=" + signedParameters.get("lis_person_name_given") + "&tool_consumer_instance_name=" + signedParameters.get("tool_consumer_instance_name") + "&target=" + signedParameters.get("target");
*/
course.setSecret(null);
course.setCourse_key(null);
course.setUrl(link);
course.setSignedParameters(signedParameters);
coursesToReturn.add(course);
} catch (Exception e) {
e.printStackTrace();

View File

@ -5,10 +5,8 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;
import java.util.Map;
@Entity
@AllArgsConstructor
@ -37,4 +35,9 @@ public class Course {
@Setter
private String secret;
@Getter
@Setter
@Transient
private Map<String, String> signedParameters;
}

View File

@ -9,12 +9,17 @@
<link rel="stylesheet" th:href="@{/css/main.css}"/>
</head>
<body>
<tr th:each="course: ${courses}">
<form th:action="${course.url}" method="POST">
<th:block th:each="parameter : ${course.signedParameters}">
<input type="hidden" th:name="${parameter.key}" th:value="${parameter.value}" />
</th:block>
<input type="submit">Launch Tool</input>
</form>
</tr>
<br><br><br>
<form th:action="@{/courses/addCourse}" method="GET">
<div><input type="submit" value="Add new content"/></div>