Skip to content

Commit a4a9b49

Browse files
committed
Fix #24429: remove JS/CSS versions from templates
+ refactor auth related controllers into one class
1 parent 4300076 commit a4a9b49

File tree

10 files changed

+66
-124
lines changed

10 files changed

+66
-124
lines changed

src/main/java/eu/openanalytics/containerproxy/api/BaseController.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,32 @@
2020
*/
2121
package eu.openanalytics.containerproxy.api;
2222

23+
import org.springframework.core.env.Environment;
2324
import org.springframework.http.HttpStatus;
25+
import org.springframework.security.authentication.AnonymousAuthenticationToken;
26+
import org.springframework.security.core.Authentication;
27+
import org.springframework.security.core.context.SecurityContextHolder;
28+
import org.springframework.ui.ModelMap;
2429
import org.springframework.web.bind.annotation.ControllerAdvice;
2530
import org.springframework.web.bind.annotation.ExceptionHandler;
2631
import org.springframework.web.bind.annotation.ResponseBody;
2732
import org.springframework.web.bind.annotation.ResponseStatus;
2833

34+
import javax.inject.Inject;
35+
import javax.servlet.http.HttpServletRequest;
36+
2937
public class BaseController {
3038

39+
@Inject
40+
private Environment environment;
41+
42+
protected void prepareMap(ModelMap map) {
43+
map.put("title", environment.getProperty("proxy.title", "ShinyProxy"));
44+
map.put("bootstrapCss", "/webjars/bootstrap/3.4.1/css/bootstrap.min.css");
45+
map.put("bootstrapJs", "/webjars/bootstrap/3.4.1/js/bootstrap.min.js");
46+
map.put("jqueryJs", "/webjars/jquery/3.5.0/jquery.min.js");
47+
}
48+
3149
public static class NotFoundException extends RuntimeException {
3250

3351
private static final long serialVersionUID = 2042632906716154791L;

src/main/java/eu/openanalytics/containerproxy/ui/AuthController.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,58 @@
2323
import javax.inject.Inject;
2424
import javax.servlet.http.HttpServletRequest;
2525

26+
import eu.openanalytics.containerproxy.auth.IAuthenticationBackend;
27+
import eu.openanalytics.containerproxy.auth.impl.OpenIDAuthenticationBackend;
2628
import org.springframework.core.env.Environment;
2729
import org.springframework.stereotype.Controller;
2830
import org.springframework.ui.ModelMap;
2931
import org.springframework.web.bind.annotation.RequestMapping;
3032
import org.springframework.web.bind.annotation.RequestMethod;
3133

3234
import eu.openanalytics.containerproxy.api.BaseController;
35+
import org.springframework.web.bind.annotation.RequestParam;
36+
import org.springframework.web.servlet.view.RedirectView;
37+
38+
import java.util.Optional;
3339

3440
@Controller
3541
public class AuthController extends BaseController {
3642

3743
@Inject
3844
private Environment environment;
3945

46+
@Inject
47+
private IAuthenticationBackend auth;
48+
49+
@RequestMapping(value = "/login", method = RequestMethod.GET)
50+
public Object getLoginPage(@RequestParam Optional<String> error, ModelMap map) {
51+
prepareMap(map);
52+
if (error.isPresent()) map.put("error", "Invalid user name or password");
53+
54+
if (auth instanceof OpenIDAuthenticationBackend) {
55+
return new RedirectView(((OpenIDAuthenticationBackend) auth).getLoginRedirectURI());
56+
} else {
57+
return "login";
58+
}
59+
}
60+
4061
@RequestMapping(value = "/auth-error", method = RequestMethod.GET)
41-
public String getAuthErrorPage(ModelMap map, HttpServletRequest request) {
62+
public String getAuthErrorPage(ModelMap map) {
63+
prepareMap(map);
4264
map.put("application_name", environment.getProperty("spring.application.name"));
4365
return "auth-error";
4466
}
4567

4668
@RequestMapping(value = "/app-access-denied", method = RequestMethod.GET)
47-
public String getAppAccessDeniedPage(ModelMap map, HttpServletRequest request) {
69+
public String getAppAccessDeniedPage(ModelMap map) {
70+
prepareMap(map);
4871
return "app-access-denied";
4972
}
5073

74+
@RequestMapping(value = "/logout-success", method = RequestMethod.GET)
75+
public String getLogoutSuccessPage(ModelMap map) {
76+
prepareMap(map);
77+
return "logout-success";
78+
}
79+
5180
}

src/main/java/eu/openanalytics/containerproxy/ui/ErrorController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public String handleError(ModelMap map, HttpServletRequest request, HttpServletR
7878
if (response.getStatus() == 200 && (exception != null) && isAccountStatusException(exception)) {
7979
return "redirect:/";
8080
}
81-
81+
82+
prepareMap(map);
8283
map.put("message", msg[0]);
8384
map.put("stackTrace", msg[1]);
8485
map.put("status", response.getStatus());

src/main/java/eu/openanalytics/containerproxy/ui/LoginController.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/main/java/eu/openanalytics/containerproxy/ui/LogoutSuccessController.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/resources/templates/app-access-denied.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
<head lang="en">
2929
<title th:text="${title}"></title>
3030
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31-
<link rel="stylesheet" media="screen" th:href="@{/webjars/bootstrap/3.4.1/css/bootstrap.min.css}"/>
31+
<link rel="stylesheet" media="screen" th:href="@{${bootstrapCss}}" />
3232
<link rel="stylesheet" media="screen" th:href="@{/css/login.css}"/>
33-
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/bootstrap-social/5.1.1/bootstrap-social.css"/>
34-
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/fontawesome/4.7.0/css/font-awesome.min.css"/>
35-
<script th:src="@{/webjars/jquery/3.5.0/jquery.min.js}"></script>
36-
<script th:src="@{/webjars/bootstrap/3.4.1/js/bootstrap.min.js}"></script>
33+
<script th:src="@{${jqueryJs}}"></script>
34+
<script th:src="@{${bootstrapJs}}"></script>
3735
</head>
3836

3937
<body>

src/main/resources/templates/auth-error.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
<head lang="en">
2929
<title th:text="${title}"></title>
3030
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31-
<link rel="stylesheet" media="screen" th:href="@{/webjars/bootstrap/3.4.1/css/bootstrap.min.css}"/>
31+
<link rel="stylesheet" media="screen" th:href="@{${bootstrapCss}}" />
3232
<link rel="stylesheet" media="screen" th:href="@{/css/login.css}"/>
33-
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/bootstrap-social/5.1.1/bootstrap-social.css"/>
34-
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/fontawesome/4.7.0/css/font-awesome.min.css"/>
35-
<script th:src="@{/webjars/jquery/3.5.0/jquery.min.js}"></script>
36-
<script th:src="@{/webjars/bootstrap/3.4.1/js/bootstrap.min.js}"></script>
33+
<script th:src="@{${jqueryJs}}"></script>
34+
<script th:src="@{${bootstrapJs}}"></script>
3735
</head>
3836

3937
<body>

src/main/resources/templates/error.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
<head lang="en">
2929
<title>Error</title>
3030
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31-
<link rel="stylesheet" media="screen" th:href="@{/webjars/bootstrap/3.4.1/css/bootstrap.min.css}"/>
31+
<link rel="stylesheet" media="screen" th:href="@{${bootstrapCss}}" />
3232
<link rel="stylesheet" media="screen" th:href="@{/css/error.css}"/>
33-
<script th:src="@{/webjars/jquery/3.5.0/jquery.min.js}"></script>
34-
<script th:src="@{/webjars/bootstrap/3.4.1/js/bootstrap.min.js}"></script>
33+
<script th:src="@{${jqueryJs}}"></script>
34+
<script th:src="@{${bootstrapJs}}"></script>
3535
</head>
3636

3737
<body>

src/main/resources/templates/login.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
<head lang="en">
2929
<title th:text="${title}"></title>
3030
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31-
<link rel="stylesheet" media="screen" th:href="@{/webjars/bootstrap/3.4.1/css/bootstrap.min.css}"/>
31+
<link rel="stylesheet" media="screen" th:href="@{${bootstrapCss}}" />
3232
<link rel="stylesheet" media="screen" th:href="@{/css/login.css}"/>
3333
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/bootstrap-social/5.1.1/bootstrap-social.css"/>
3434
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/fontawesome/4.7.0/css/font-awesome.min.css"/>
35-
<script th:src="@{/webjars/jquery/3.5.0/jquery.min.js}"></script>
36-
<script th:src="@{/webjars/bootstrap/3.4.1/js/bootstrap.min.js}"></script>
35+
<script th:src="@{${jqueryJs}}"></script>
36+
<script th:src="@{${bootstrapJs}}"></script>
3737
</head>
3838

3939
<body>

src/main/resources/templates/logout-success.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
<head lang="en">
2929
<title th:text="${title}"></title>
3030
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
31-
<link rel="stylesheet" media="screen" th:href="@{/webjars/bootstrap/3.4.1/css/bootstrap.min.css}"/>
31+
<link rel="stylesheet" media="screen" th:href="@{${bootstrapCss}}" />
3232
<link rel="stylesheet" media="screen" th:href="@{/css/login.css}"/>
33-
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/bootstrap-social/5.1.1/bootstrap-social.css"/>
34-
<link rel="stylesheet" media="screen" type="text/css" href="https://cdn.jsdelivr.net/fontawesome/4.7.0/css/font-awesome.min.css"/>
35-
<script th:src="@{/webjars/jquery/3.5.0/jquery.min.js}"></script>
36-
<script th:src="@{/webjars/bootstrap/3.4.1/js/bootstrap.min.js}"></script>
33+
<script th:src="@{${jqueryJs}}"></script>
34+
<script th:src="@{${bootstrapJs}}"></script>
3735
</head>
3836

3937
<body>

0 commit comments

Comments
 (0)