not working
This commit is contained in:
parent
1e68cf776e
commit
98178c1066
33
pom.xml
33
pom.xml
@ -28,6 +28,12 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.imsglobal</groupId>
|
||||
<artifactId>basiclti-util</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
@ -38,6 +44,28 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@ -57,6 +85,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
16
src/main/java/com/wmi/lti/config/MvcConfig.java
Normal file
16
src/main/java/com/wmi/lti/config/MvcConfig.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.wmi.lti.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class MvcConfig implements WebMvcConfigurer {
|
||||
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/home").setViewName("home");
|
||||
registry.addViewController("/").setViewName("home");
|
||||
registry.addViewController("/login").setViewName("login");
|
||||
}
|
||||
|
||||
}
|
43
src/main/java/com/wmi/lti/config/WebSecurityConfig.java
Normal file
43
src/main/java/com/wmi/lti/config/WebSecurityConfig.java
Normal file
@ -0,0 +1,43 @@
|
||||
package com.wmi.lti.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", "/home").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/login")
|
||||
.permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
public UserDetailsService userDetailsService() {
|
||||
UserDetails user =
|
||||
User.withDefaultPasswordEncoder()
|
||||
.username("adrianw")
|
||||
.password("eduserwis1245")
|
||||
.roles("USER")
|
||||
.build();
|
||||
|
||||
return new InMemoryUserDetailsManager(user);
|
||||
}
|
||||
}
|
20
src/main/java/com/wmi/lti/controllers/HomeController.java
Normal file
20
src/main/java/com/wmi/lti/controllers/HomeController.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.wmi.lti.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class HomeController {
|
||||
|
||||
@GetMapping("/home")
|
||||
public String home(
|
||||
@RequestParam(name = "name", required = false, defaultValue = "")
|
||||
String name, Model model) {
|
||||
|
||||
//model.addAttribute("message", name);
|
||||
|
||||
return "home"; //view
|
||||
}
|
||||
}
|
47
src/main/java/com/wmi/lti/controllers/StartController.java
Normal file
47
src/main/java/com/wmi/lti/controllers/StartController.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.wmi.lti.controllers;
|
||||
|
||||
import org.imsglobal.lti.launch.LtiOauthSigner;
|
||||
import org.imsglobal.lti.launch.LtiSigner;
|
||||
import org.imsglobal.lti.launch.LtiSigningException;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class StartController {
|
||||
|
||||
@GetMapping("/start")
|
||||
public String start(
|
||||
@RequestParam(name = "key", required = false, defaultValue = "")
|
||||
String key, @RequestParam(name = "secret", required = false, defaultValue = "")
|
||||
String secret, @RequestParam(name = "url", required = false, defaultValue = "")
|
||||
String url, Model model) {
|
||||
|
||||
LtiSigner signer = new LtiOauthSigner();
|
||||
Map<String, String> parameters = new HashMap<>();
|
||||
parameters.put("lti_message_type","basic-lti-launch-request");
|
||||
parameters.put("lti_version", "LTI-1p0");
|
||||
parameters.put("resource_link_id", "gsdgsdgsdgsdsgddsg3g3");
|
||||
//parameters.put("resource_link_id", ((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||
try {
|
||||
Map<String, String> signedParameters = signer.signParameters(parameters, key, secret, url, "POST");
|
||||
String link = url + "?" + "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");
|
||||
model.addAttribute("parameters", signedParameters);
|
||||
model.addAttribute("launchUrl", link);
|
||||
} catch (LtiSigningException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//model.addAttribute("message", name);
|
||||
return "start"; //view
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1 +1,6 @@
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/lti
|
||||
spring.datasource.username=lti
|
||||
spring.datasource.password=YnBDC0hqqhKaxt94
|
||||
|
||||
spring.thymeleaf.cache=false
|
||||
|
15
src/main/resources/static/css/main.css
Normal file
15
src/main/resources/static/css/main.css
Normal file
@ -0,0 +1,15 @@
|
||||
body {
|
||||
padding-top: 0rem;
|
||||
}
|
||||
.starter-template {
|
||||
padding: 3rem 1.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1{
|
||||
color:#0000FF;
|
||||
}
|
||||
|
||||
h2{
|
||||
color:#FF0000;
|
||||
}
|
15
src/main/resources/templates/home.html
Normal file
15
src/main/resources/templates/home.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<title>LTI</title>
|
||||
|
||||
<link rel="stylesheet" th:href="@{/css/main.css}"/>
|
||||
</head>
|
||||
<body>
|
||||
This is tool consumer for LTI<br>
|
||||
<button type="button" th:onclick="|window.location.href='/start?url=https://cloud.scorm.com/sc/blti&key=7ec922aa-7095-497d-a1b8-5a507008fb90&secret=Fr5hG91UdCPQ2mKodG82u3UNqf0SLJ7NB1wSxAJ8'|">Launch</button>
|
||||
</body>
|
||||
</html>
|
20
src/main/resources/templates/login.html
Normal file
20
src/main/resources/templates/login.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
|
||||
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
|
||||
<head>
|
||||
<title>Login </title>
|
||||
</head>
|
||||
<body>
|
||||
<div th:if="${param.error}">
|
||||
Invalid username and password.
|
||||
</div>
|
||||
<div th:if="${param.logout}">
|
||||
You have been logged out.
|
||||
</div>
|
||||
<form th:action="@{/login}" method="post">
|
||||
<div><label> User Name : <input type="text" name="username"/> </label></div>
|
||||
<div><label> Password: <input type="password" name="password"/> </label></div>
|
||||
<div><input type="submit" value="Sign In"/></div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
16
src/main/resources/templates/start.html
Normal file
16
src/main/resources/templates/start.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<title>LTI start</title>
|
||||
|
||||
<link rel="stylesheet" th:href="@{/css/main.css}"/>
|
||||
</head>
|
||||
<body>
|
||||
<form th:action="${launchUrl}" target="_blank" method="POST">
|
||||
<input type="submit">Launch Tool</input>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user