działa
This commit is contained in:
parent
2f164e7922
commit
5503210aeb
@ -2,7 +2,9 @@ package com.wmi.lti.controllers;
|
||||
|
||||
import com.wmi.lti.model.course.Course;
|
||||
import com.wmi.lti.model.course.CourseRepository;
|
||||
import com.wmi.lti.model.user.User;
|
||||
import com.wmi.lti.model.user.UserPrincipal;
|
||||
import com.wmi.lti.model.user.UserRepository;
|
||||
import org.imsglobal.lti.launch.LtiOauthSigner;
|
||||
import org.imsglobal.lti.launch.LtiSigner;
|
||||
import org.imsglobal.lti.launch.LtiSigningException;
|
||||
@ -25,6 +27,9 @@ public class StartController {
|
||||
@Autowired
|
||||
private CourseRepository courseRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@GetMapping("")
|
||||
public String start(Model model){
|
||||
List<Course> courses = courseRepository.findAll();
|
||||
@ -32,17 +37,21 @@ public class StartController {
|
||||
for (Course course : courses) {
|
||||
LtiSigner signer = new LtiOauthSigner();
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
User user = userRepository.findByUsername(((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||
parameters.put("lti_message_type", "basic-lti-launch-request");
|
||||
parameters.put("lti_version", "LTI-1p0");
|
||||
parameters.put("resource_link_id", ((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||
parameters.put("resource_link_id", user.getUsername() + "_" + course.getCourse_key());
|
||||
parameters.put("user_id", user.getId().toString());
|
||||
parameters.put("lis_person_name_given", user.getUsername());
|
||||
parameters.put("tool_consumer_instance_name", "wmi.lti");
|
||||
try {
|
||||
Map<String, String> signedParameters = signer.signParameters(parameters, course.getCourse_key(), course.getSecret(), course.getUrl(), "POST");
|
||||
String link = course.getUrl() + "?" + "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") + "<i_message_type=" + signedParameters.get("lti_message_type") + "<i_version=" + signedParameters.get("lti_version") + "&resource_link_id=" + signedParameters.get("resource_link_id");
|
||||
String link = course.getUrl() + "?" + "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") + "<i_message_type=" + signedParameters.get("lti_message_type") + "<i_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");
|
||||
course.setSecret(null);
|
||||
course.setCourse_key(null);
|
||||
course.setUrl(link);
|
||||
coursesToReturn.add(course);
|
||||
} catch (LtiSigningException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user