Skip to content

Commit

Permalink
springboot2.5.4対応とリバースプロキシでの動作に対応(X-Forwarded-Protocol)
Browse files Browse the repository at this point in the history
  • Loading branch information
takawitter committed Sep 21, 2021
1 parent 9c2f445 commit d489361
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 25 deletions.
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@
<modelVersion>4.0.0</modelVersion>

<groupId>jp.ac.hosei.media.lti_sample</groupId>
<artifactId>demo</artifactId>
<artifactId>ltitest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>lti_sample</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand All @@ -47,11 +46,12 @@
<dependency>
<groupId>org.imsglobal</groupId>
<artifactId>basiclti-util</artifactId>
<version>1.1.2</version>
<version>1.2.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies>

Expand Down
23 changes: 21 additions & 2 deletions src/main/java/jp/ac/hosei/media/lti_sample/AOPConfig.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package jp.ac.hosei.media.lti_sample;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.imsglobal.aspect.LtiKeySecretService;
import org.imsglobal.aspect.LtiLaunchVerifier;
import org.imsglobal.lti.launch.LtiOauthVerifier;
import org.imsglobal.lti.launch.LtiVerificationException;
import org.imsglobal.lti.launch.LtiVerificationResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -16,7 +21,21 @@ public class AOPConfig {

@Bean
public LtiLaunchVerifier ltiLaunchVerifier() {
return new LtiLaunchVerifier(keyService, new LtiOauthVerifier());
return new LtiLaunchVerifier(keyService, new LtiOauthVerifier(){
@Override
public LtiVerificationResult verify(HttpServletRequest request, String secret)
throws LtiVerificationException {
if(request.getHeader("X-Forwarded-Proto").equals("https") &&
request.getRequestURL().subSequence(0, 5).equals("http:")){
request = new HttpServletRequestWrapper(request){
@Override
public StringBuffer getRequestURL() {
return super.getRequestURL().replace(0, 4, "https");
}
};
}
return super.verify(request, secret);
}
});
}

}
Empty file.
4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
server:
port: 8080
servlet:
context-path: /basiclti-java-sample
2 changes: 1 addition & 1 deletion src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Error</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="/css/bootstrap.css" />
<script type="text/javascript" href="/js/bootstrap.js" />
<script type="text/javascript" href="/js/bootstrap.js"></script>
</head>
<body>
<h1 th:text="${status} + ' ' + ${error}">500 Internal Server Error</h1>
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<link rel="stylesheet" href="/css/bootstrap.css" />
<script type="text/javascript" href="/js/bootstrap.js" />
<script type="text/javascript" href="/js/bootstrap.js"></script>
</head>
<body>
<div>
Expand All @@ -19,9 +19,9 @@ <h1>LTI Launch Parameters</h1>
</tr>
</thead>
<tbody>
<tr th:each="param : ${ltiParams}">
<td th:text="${param.key}" />
<td th:text="${param.value}" />
<tr th:each="p : ${ltiParams}">
<td th:text="${p.key}" />
<td th:text="${p.value}" />
</tr>
</tbody>
</table>
Expand All @@ -38,11 +38,11 @@ <h1>POST Request Parameters</h1>
</tr>
</thead>
<tbody>
<tr th:each="param : ${reqParams}">
<td th:text="${param.key}" />
<tr th:each="p : ${reqParams}">
<td th:text="${p.key}" />
<td>
<ul class="list-unstyled">
<li th:each="element : ${param.value}" th:text="${element}"/>
<li th:each="element : ${p.value}" th:text="${element}"/>
</ul>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package jp.ac.hosei.media.lti_sample;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class LtiSampleApplicationTests {

Expand Down

0 comments on commit d489361

Please sign in to comment.