Skip to content

Commit 365880d

Browse files
authored
feat(699): redirect to OIDC issuer when local login is disabled (#741)
1 parent 3c3c730 commit 365880d

File tree

5 files changed

+83
-9
lines changed

5 files changed

+83
-9
lines changed

src/main/java/com/dedicatedcode/reitti/controller/WebViewController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ public String index(Authentication authentication, Model model) {
3333

3434
return "index";
3535
}
36-
36+
3737
@GetMapping("/login")
3838
public String login(Model model) {
39-
model.addAttribute("oidcEnabled", oidcEnabled);
39+
if (!localLoginEnabled && oidcEnabled) {
40+
return "redirect:/oauth2/authorization/oauth";
41+
}
4042
model.addAttribute("localLoginEnabled", localLoginEnabled);
43+
model.addAttribute("oidcEnabled", oidcEnabled);
4144
return "login";
4245
}
4346

src/main/resources/static/css/main.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ header {
271271
transform: translateY(20px);
272272
opacity: 0;
273273
transition: all 0.3s ease;
274+
pointer-events: none;
274275
}
275276

276277
.settings-menu.visible {
277278
transform: translateY(0);
278279
opacity: 1;
280+
pointer-events: all;
279281
}
280282

281283
.settings-menu-header {

src/main/resources/static/js/map-renderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ class MapRenderer {
6767
shadowOpacity: 155,
6868
pathWidth: 2,
6969
pathOpacity: 35,
70-
staticPathWidth: 2,
71-
staticPathOpacity: 150,
72-
70+
staticPathWidth: 4,
71+
staticPathOpacity: 200,
7372
},
7473
visits: {
7574
minZoom: 12,
@@ -177,7 +176,8 @@ class MapRenderer {
177176
right: 100,
178177
left: 450
179178
},
180-
duration: 2000,
179+
maxZoom: 15,
180+
duration: 1000,
181181
essential: true
182182
});
183183
}

src/main/resources/templates/login.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ <h1>Reitti</h1>
148148
Invalid username or password
149149
</div>
150150

151-
<form th:action="@{/login}" method="post" th:if="${localLoginEnabled}">
151+
<form th:action="@{/login}" method="post" th:if="${localLoginEnabled != null && localLoginEnabled}">
152152
<div class="form-group">
153153
<label for="username" th:text="#{login.username}">Username</label>
154154
<input type="text" id="username" name="username" required autofocus>
@@ -166,8 +166,8 @@ <h1>Reitti</h1>
166166

167167
<button type="submit" th:text="#{login.button}">Login</button>
168168
</form>
169-
<div th:if="${oidcEnabled}">
170-
<hr th:if="${localLoginEnabled}" style="margin: 30px 0; border: none; border-top: 1px solid var(--color-highlight);">
169+
<div th:if="${oidcEnabled != null && oidcEnabled}">
170+
<hr th:if="${localLoginEnabled != null && localLoginEnabled}" style="margin: 30px 0; border: none; border-top: 1px solid var(--color-highlight);">
171171
<a th:href="@{/oauth2/authorization/oauth}" style="text-decoration: none;">
172172
<button type="button" th:text="#{login.oauth.button}">Log in with OAuth</button>
173173
</a>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.dedicatedcode.reitti.controller;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.ui.ExtendedModelMap;
5+
import org.springframework.ui.Model;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class WebViewControllerTest {
10+
11+
@Test
12+
void login_WithLocalLoginEnabled_ShouldShowLoginPage() {
13+
// Given
14+
WebViewController controller = new WebViewController(false, true, false);
15+
Model model = new ExtendedModelMap();
16+
17+
// When
18+
String result = controller.login(model);
19+
20+
// Then
21+
assertEquals("login", result);
22+
assertEquals(true, model.getAttribute("localLoginEnabled"));
23+
assertEquals(true, model.getAttribute("oidcEnabled"));
24+
}
25+
26+
@Test
27+
void login_WithLocalLoginDisabledAndOidcEnabled_ShouldRedirectToOAuth() {
28+
// Given
29+
WebViewController controller = new WebViewController(true, true, true);
30+
Model model = new ExtendedModelMap();
31+
32+
// When
33+
String result = controller.login( model);
34+
35+
// Then
36+
assertEquals("redirect:/oauth2/authorization/oauth", result);
37+
}
38+
39+
@Test
40+
void login_WithOnlyLocalLoginEnabled_ShouldShowLoginPage() {
41+
// Given
42+
WebViewController controller = new WebViewController(false, false, false);
43+
Model model = new ExtendedModelMap();
44+
45+
// When
46+
String result = controller.login(model);
47+
48+
// Then
49+
assertEquals("login", result);
50+
assertEquals(true, model.getAttribute("localLoginEnabled"));
51+
assertEquals(false, model.getAttribute("oidcEnabled"));
52+
}
53+
54+
@Test
55+
void login_WithBothLoginMethodsDisabled_ShouldShowLoginPageWithoutOptions() {
56+
// Given
57+
WebViewController controller = new WebViewController(true, false, false);
58+
Model model = new ExtendedModelMap();
59+
60+
// When
61+
String result = controller.login(model);
62+
63+
// Then
64+
assertEquals("login", result);
65+
assertEquals(true, model.getAttribute("localLoginEnabled"));
66+
assertEquals(false, model.getAttribute("oidcEnabled"));
67+
}
68+
69+
}

0 commit comments

Comments
 (0)