Shuffle things around to make things available unauthenticated

This commit is contained in:
Andreas Svanberg 2024-05-08 20:27:59 +02:00
parent c1a6f6f515
commit 1aa00dacb5
6 changed files with 33 additions and 30 deletions
src/main

@ -2,9 +2,9 @@ package se.su.dsv.studentportalenpoc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.PathRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults;
@ -24,9 +24,10 @@ public class StudentportalenPocApplication {
http
.csrf(crsf -> crsf.disable())
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("manifest.json").anonymous()
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.requestMatchers("public/**").permitAll()
// service worker must live in the root to "own" the entire web app
.requestMatchers("sw.js").permitAll()
.requestMatchers("images/**").permitAll()
.anyRequest().authenticated())
.oauth2Login(withDefaults());
return http.build();

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Studentportalen [proof-of-concept progressive web app]</title>
<link rel="manifest" href="manifest.json">
<link rel="manifest" href="public/manifest.json">
<link rel="icon" href="images/icons/student-hat-32.png" type="image/png" sizes="32x32">
<link rel="icon" href="images/icons/student-hat-64.png" type="image/png" sizes="64x64">
<link rel="icon" href="images/icons/student-hat-128.png" type="image/png" sizes="128x128">

@ -1,18 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Studentportalen [proof-of-concept progressive web app]</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" href="images/icons/student-hat-32.png" type="image/png" sizes="32x32">
<link rel="icon" href="images/icons/student-hat-64.png" type="image/png" sizes="64x64">
<link rel="icon" href="images/icons/student-hat-128.png" type="image/png" sizes="128x128">
<link rel="icon" href="images/icons/student-hat-256.png" type="image/png" sizes="256x256">
<link rel="icon" href="images/icons/student-hat-512.png" type="image/png" sizes="512x512">
</head>
<body>
<h1>Offline</h1>
<p>Oh no, you are offline. Please check your internet connection.</p>
</body>
</html>

@ -2,31 +2,31 @@
"name": "Studentportalen Proof-of-Concept",
"icons": [
{
"src": "images/icons/student-hat-32.png",
"src": "../images/icons/student-hat-32.png",
"sizes": "32x32",
"type": "image/png"
},
{
"src": "images/icons/student-hat-64.png",
"src": "../images/icons/student-hat-64.png",
"sizes": "64x64",
"type": "image/png"
},
{
"src": "images/icons/student-hat-128.png",
"src": "../images/icons/student-hat-128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "images/icons/student-hat-256.png",
"src": "../images/icons/student-hat-256.png",
"sizes": "256x256",
"type": "image/png"
},
{
"src": "images/icons/student-hat-512.png",
"src": "../images/icons/student-hat-512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "index.html",
"start_url": "../index.html",
"display": "fullscreen"
}

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Studentportalen [proof-of-concept progressive web app]</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" href="../images/icons/student-hat-32.png" type="image/png" sizes="32x32">
<link rel="icon" href="../images/icons/student-hat-64.png" type="image/png" sizes="64x64">
<link rel="icon" href="../images/icons/student-hat-128.png" type="image/png" sizes="128x128">
<link rel="icon" href="../images/icons/student-hat-256.png" type="image/png" sizes="256x256">
<link rel="icon" href="../images/icons/student-hat-512.png" type="image/png" sizes="512x512">
</head>
<body>
<h1>Offline</h1>
<p>Oh no, you are offline. Please check your internet connection.</p>
</body>
</html>

@ -1,9 +1,11 @@
const offlinePage = 'public/offline.html';
self.addEventListener('install', function (event) {
console.log('Service Worker installing.', event);
event.waitUntil(
caches.open('v1').then(function (cache) {
return cache.addAll([
'offline.html',
offlinePage,
]);
}))
});
@ -36,7 +38,7 @@ self.addEventListener('fetch', /** @param {FetchEvent} event */ async function (
return networkResponse;
})
.catch(async function () {
const offline = await cache.match('offline.html');
const offline = await cache.match(offlinePage);
return offline || Response.error();
});