-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from oxctl/spring-boot-3
Update for Spring Boot 3.x
- Loading branch information
Showing
12 changed files
with
101 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copy this file to `application.properties` and customise | ||
|
||
# Set this to the client ID of the key | ||
spring.security.oauth2.client.registration.canvas.client-id= | ||
# This isn't used for the implicit OAuth grant so it's value doesn't matter | ||
spring.security.oauth2.client.registration.canvas.client-secret=secret | ||
# This must be implicit | ||
spring.security.oauth2.client.registration.canvas.authorization-grant-type=implicit | ||
# This must be openid | ||
spring.security.oauth2.client.registration.canvas.scope=openid | ||
# Unless you remap the login path this should be the same | ||
spring.security.oauth2.client.registration.canvas.redirect-uri={baseUrl}/lti/login | ||
|
||
# These are example values for a production Canvas instance. | ||
spring.security.oauth2.client.provider.canvas.authorization-uri=https://canvas.instructure.com/api/lti/authorize_redirect | ||
spring.security.oauth2.client.provider.canvas.token-uri=https://canvas.instructure.com/login/oauth2/token | ||
spring.security.oauth2.client.provider.canvas.jwk-set-uri=https://canvas.instructure.com/api/lti/security/jwks | ||
spring.security.oauth2.client.provider.canvas.user-name-attribute=sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
src/main/java/uk/ac/ox/ctl/lti13/demo/WebSecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
package uk.ac.ox.ctl.lti13.demo; | ||
|
||
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.web.SecurityFilterChain; | ||
import org.springframework.security.web.context.HttpSessionSecurityContextRepository; | ||
import uk.ac.ox.ctl.lti13.Lti13Configurer; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||
public class WebSecurityConfig { | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.authorizeRequests() | ||
.antMatchers("/", "/resources/**", "/favicon.ico", "/config.json", "/.well-known/jwks.json") | ||
.permitAll() | ||
; | ||
@Bean | ||
protected SecurityFilterChain configure(HttpSecurity http) throws Exception { | ||
http.authorizeHttpRequests(authorizeHttpRequestsCustomizer -> { | ||
authorizeHttpRequestsCustomizer.requestMatchers( | ||
"/", "/index.html", "/resources/**", "/favicon.ico", | ||
"/config.json", "/.well-known/jwks.json", "/error").permitAll(); | ||
authorizeHttpRequestsCustomizer.anyRequest().authenticated(); | ||
}); | ||
Lti13Configurer lti13Configurer = new Lti13Configurer(); | ||
lti13Configurer.setSecurityContextRepository(new HttpSessionSecurityContextRepository()); | ||
http.apply(lti13Configurer); | ||
return http.build(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/uk/ac/ox/ctl/lti13/demo/controller/Config13Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/uk/ac/ox/ctl/lti13/demo/controller/DemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package uk.ac.ox.ctl.lti13.demo.controller; | ||
|
||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* This is a simple controller to demonstrate how you can use data from the LTI launch. | ||
*/ | ||
@Controller | ||
public class DemoController { | ||
|
||
@GetMapping("/demo") | ||
public ModelAndView index( | ||
@AuthenticationPrincipal(expression = "claims['sub']") String sub, | ||
@AuthenticationPrincipal(expression = "claims['name']") String name | ||
) { | ||
Map<String, Object> model = new HashMap<>(); | ||
model.put("sub", sub); | ||
model.put("name", name); | ||
return new ModelAndView("demo", model); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/main/java/uk/ac/ox/ctl/lti13/demo/controller/lti13/Lti13ConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/uk/ac/ox/ctl/lti13/demo/utils/SameSiteCookeValve.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Demo Application</title> | ||
</head> | ||
<body> | ||
<h1>Demo</h1> | ||
<p> | ||
Hello {{name}} (sub:{{sub}}) | ||
</p> | ||
<p> | ||
This reloads the current document to check that HTTP sessions are correctly setup and the user remains | ||
authenticated.<br> | ||
<button onclick="location.reload()"> | ||
Check HTTP Session | ||
</button> | ||
</p> | ||
</body> | ||
</html> |