not working

This commit is contained in:
unknown 2020-05-03 12:10:10 +02:00
parent 5503210aeb
commit 9671929787

View File

@ -34,19 +34,30 @@ public class StartController {
public String start(Model model){
List<Course> courses = courseRepository.findAll();
List<Course> coursesToReturn = new ArrayList<>();
User user = userRepository.findByUsername(((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
for (Course course : courses) {
LtiSigner signer = new LtiOauthSigner();
Map<String, String> parameters = new HashMap<>();
User user = userRepository.findByUsername(((UserPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
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());
parameters.put("user_id", user.getId().toString());
parameters.put("lis_person_name_given", user.getUsername());
parameters.put("tool_consumer_instance_name", "wmi.lti");
parameters.put("target", "frame");
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") + "&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");
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");
course.setSecret(null);
course.setCourse_key(null);
course.setUrl(link);