|
1 | | -/* |
2 | | - * ContainerProxy |
3 | | - * |
4 | | - * Copyright (C) 2016-2025 Open Analytics |
5 | | - * |
6 | | - * =========================================================================== |
7 | | - * |
8 | | - * This program is free software: you can redistribute it and/or modify |
9 | | - * it under the terms of the Apache License as published by |
10 | | - * The Apache Software Foundation, either version 2 of the License, or |
11 | | - * (at your option) any later version. |
12 | | - * |
13 | | - * This program is distributed in the hope that it will be useful, |
14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | - * Apache License for more details. |
17 | | - * |
18 | | - * You should have received a copy of the Apache License |
19 | | - * along with this program. If not, see <http://www.apache.org/licenses/> |
20 | | - */ |
21 | | -package eu.openanalytics.containerproxy.api; |
22 | | - |
23 | | -import eu.openanalytics.containerproxy.service.IdentifierService; |
24 | | -import eu.openanalytics.containerproxy.service.UserService; |
25 | | -import eu.openanalytics.containerproxy.spec.expression.SpecExpressionContext; |
26 | | -import eu.openanalytics.containerproxy.spec.expression.SpecExpressionResolver; |
27 | | -import jakarta.servlet.http.HttpServletRequest; |
28 | | -import jakarta.servlet.http.HttpServletResponse; |
29 | | -import org.springframework.core.env.Environment; |
30 | | -import org.springframework.security.core.Authentication; |
31 | | -import org.springframework.ui.ModelMap; |
32 | | -import org.springframework.web.context.request.RequestContextHolder; |
33 | | -import org.springframework.web.context.request.ServletRequestAttributes; |
34 | | - |
35 | | -import javax.annotation.PostConstruct; |
36 | | -import javax.inject.Inject; |
37 | | - |
38 | | -public class BaseController { |
39 | | - |
40 | | - @Inject |
41 | | - private Environment environment; |
42 | | - |
43 | | - @Inject |
44 | | - private IdentifierService identifierService; |
45 | | - |
46 | | - @Inject |
47 | | - protected SpecExpressionResolver expressionResolver; |
48 | | - |
49 | | - @Inject |
50 | | - private UserService userService; |
51 | | - |
52 | | - private String title; |
53 | | - private boolean titleContainsExpression; |
54 | | - |
55 | | - @PostConstruct |
56 | | - public void baseInit() { |
57 | | - title = environment.getProperty("proxy.title", "ShinyProxy"); |
58 | | - titleContainsExpression = title.contains("#{"); |
59 | | - } |
60 | | - |
61 | | - protected void prepareMap(ModelMap map) { |
62 | | - ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); |
63 | | - HttpServletRequest httpServletRequest = servletRequestAttributes.getRequest(); |
64 | | - HttpServletResponse httpServletResponse = servletRequestAttributes.getResponse(); |
65 | | - map.put("title", getTitle(userService.getCurrentAuth(), httpServletRequest.getServerName())); |
66 | | - // no versioning (using instanceId) needed since paths already contain a version |
67 | | - map.put("bootstrapCss", "/css/bootstrap.css"); |
68 | | - map.put("bootstrapJs", "/js/bootstrap.js"); |
69 | | - map.put("jqueryJs", "/webjars/jquery/3.7.1/jquery.min.js"); |
70 | | - map.put("fontAwesomeCss", "/webjars/fontawesome/4.7.0/css/font-awesome.min.css"); |
71 | | - map.put("resourcePrefix", "/" + identifierService.instanceId); |
72 | | - |
73 | | - map.put("request", httpServletRequest); |
74 | | - map.put("response", httpServletResponse); |
75 | | - } |
76 | | - |
77 | | - private String getTitle(Authentication user, String serverName) { |
78 | | - if (!titleContainsExpression) { |
79 | | - return title; |
80 | | - } |
81 | | - SpecExpressionContext context = SpecExpressionContext.create( |
82 | | - user, |
83 | | - user.getPrincipal(), |
84 | | - user.getCredentials() |
85 | | - ) |
86 | | - .serverName(serverName) |
87 | | - .build(); |
88 | | - return expressionResolver.evaluateToString(title, context); |
89 | | - } |
90 | | - |
91 | | -} |
| 1 | +/* |
| 2 | + * ContainerProxy |
| 3 | + * |
| 4 | + * Copyright (C) 2016-2025 Open Analytics |
| 5 | + * |
| 6 | + * =========================================================================== |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the Apache License as published by |
| 10 | + * The Apache Software Foundation, either version 2 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * Apache License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the Apache License |
| 19 | + * along with this program. If not, see <http://www.apache.org/licenses/> |
| 20 | + */ |
| 21 | +package eu.openanalytics.containerproxy.api; |
| 22 | + |
| 23 | +import eu.openanalytics.containerproxy.service.IdentifierService; |
| 24 | +import eu.openanalytics.containerproxy.service.UserService; |
| 25 | +import eu.openanalytics.containerproxy.spec.expression.SpecExpressionContext; |
| 26 | +import eu.openanalytics.containerproxy.spec.expression.SpecExpressionResolver; |
| 27 | +import jakarta.servlet.http.HttpServletRequest; |
| 28 | +import jakarta.servlet.http.HttpServletResponse; |
| 29 | +import org.springframework.core.env.Environment; |
| 30 | +import org.springframework.security.core.Authentication; |
| 31 | +import org.springframework.ui.ModelMap; |
| 32 | +import org.springframework.web.context.request.RequestContextHolder; |
| 33 | +import org.springframework.web.context.request.ServletRequestAttributes; |
| 34 | + |
| 35 | +import javax.annotation.PostConstruct; |
| 36 | +import javax.inject.Inject; |
| 37 | + |
| 38 | +public class BaseController { |
| 39 | + |
| 40 | + @Inject |
| 41 | + private Environment environment; |
| 42 | + |
| 43 | + @Inject |
| 44 | + private IdentifierService identifierService; |
| 45 | + |
| 46 | + @Inject |
| 47 | + protected SpecExpressionResolver expressionResolver; |
| 48 | + |
| 49 | + @Inject |
| 50 | + private UserService userService; |
| 51 | + |
| 52 | + private String title; |
| 53 | + private boolean titleContainsExpression; |
| 54 | + |
| 55 | + @PostConstruct |
| 56 | + public void baseInit() { |
| 57 | + title = environment.getProperty("proxy.title", "ShinyProxy"); |
| 58 | + titleContainsExpression = title.contains("#{"); |
| 59 | + } |
| 60 | + |
| 61 | + protected void prepareMap(ModelMap map) { |
| 62 | + ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); |
| 63 | + HttpServletRequest httpServletRequest = servletRequestAttributes.getRequest(); |
| 64 | + HttpServletResponse httpServletResponse = servletRequestAttributes.getResponse(); |
| 65 | + map.put("title", getTitle(userService.getCurrentAuth(), httpServletRequest.getServerName())); |
| 66 | + // no versioning (using instanceId) needed since paths already contain a version |
| 67 | + map.put("bootstrapCss", "/css/bootstrap.css"); |
| 68 | + map.put("bootstrapJs", "/js/bootstrap.js"); |
| 69 | + map.put("jqueryJs", "/webjars/jquery/3.7.1/jquery.min.js"); |
| 70 | + map.put("fontAwesomeCss", "/webjars/fontawesome/4.7.0/css/font-awesome.min.css"); |
| 71 | + map.put("resourcePrefix", "/" + identifierService.instanceId); |
| 72 | + |
| 73 | + map.put("request", httpServletRequest); |
| 74 | + map.put("response", httpServletResponse); |
| 75 | + } |
| 76 | + |
| 77 | + private String getTitle(Authentication user, String serverName) { |
| 78 | + if (!titleContainsExpression) { |
| 79 | + return title; |
| 80 | + } |
| 81 | + SpecExpressionContext context = SpecExpressionContext.create( |
| 82 | + user, |
| 83 | + user.getPrincipal(), |
| 84 | + user.getCredentials() |
| 85 | + ) |
| 86 | + .serverName(serverName) |
| 87 | + .build(); |
| 88 | + return expressionResolver.evaluateToString(title, context); |
| 89 | + } |
| 90 | + |
| 91 | +} |
0 commit comments