diff --git a/src/main/java/org/olat/core/helpers/Settings.java b/src/main/java/org/olat/core/helpers/Settings.java index 57f74daa6c781a2fec7b452537eb6f0bb77aeed5..28aed8f578b783c3c0d0e9090423d4d6edb08c5f 100644 --- a/src/main/java/org/olat/core/helpers/Settings.java +++ b/src/main/java/org/olat/core/helpers/Settings.java @@ -388,8 +388,8 @@ public class Settings implements Initializable, Destroyable, GenericEventListene return (isSecurePortAvailable() ? "https:" : "http:"); } - private static boolean isSecurePortAvailable() { - return ! Settings.getServerconfig("server_securePort").equals("0"); + public static boolean isSecurePortAvailable() { + return !Settings.getServerconfig("server_securePort").equals("0"); } diff --git a/src/main/java/org/olat/core/servlets/FakeHttpsFilter.java b/src/main/java/org/olat/core/servlets/FakeHttpsFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..f9fd02e618fd5872535dd456c978639d986c5cda --- /dev/null +++ b/src/main/java/org/olat/core/servlets/FakeHttpsFilter.java @@ -0,0 +1,54 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * Universität Innsbruck + * <p> + */ +package org.olat.core.servlets; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; + +/** + * A Filter that uses a special RequestWrapper to fake an HTTPS connection + * + */ + +public class FakeHttpsFilter implements Filter { + + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) + throws IOException, ServletException { + + HttpServletRequest request = (HttpServletRequest) req; + FakeHttpsRequestWrapper fakereq = new FakeHttpsRequestWrapper(request); + chain.doFilter(fakereq, res); + } + + public void init(FilterConfig config) throws ServletException { + // nothing to do + } + + public void destroy() { + // no resources to release + } +} diff --git a/src/main/java/org/olat/core/servlets/FakeHttpsRequestWrapper.java b/src/main/java/org/olat/core/servlets/FakeHttpsRequestWrapper.java new file mode 100644 index 0000000000000000000000000000000000000000..59847afa712c98cfe52153f3f21d6607edebb8ef --- /dev/null +++ b/src/main/java/org/olat/core/servlets/FakeHttpsRequestWrapper.java @@ -0,0 +1,58 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * Universität Innsbruck + * <p> + */ +package org.olat.core.servlets; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; + +import org.olat.core.helpers.Settings; + +/** + * A RequestWrapper that "fakes" a https-connection: + * I.e. regardless of the real connection type it answers + * "true" for isSecure, "https" for the scheme and "443" for the server port. But + * it only deliver these settings if OpenOLAT is set to use https. + * + * Necessary for automatic WSDL generation (ONYX) behind an apache that is + * behind a haproxy + * + */ +public class FakeHttpsRequestWrapper extends HttpServletRequestWrapper { + + public FakeHttpsRequestWrapper(HttpServletRequest request) { + super(request); + } + + @Override + public boolean isSecure() { + return Settings.isSecurePortAvailable(); + } + + @Override + public String getScheme() { + return Settings.getURIScheme(); + } + + @Override + public int getServerPort() { + String port = Settings.getServerconfig("server_securePort"); + return Integer.parseInt(port); + } +} diff --git a/src/main/webapp-gae/WEB-INF/web.xml b/src/main/webapp-gae/WEB-INF/web.xml index 1ab31c49e3e4481ee585e578cd5728fe2208fc9f..85572dde5ceb6a6f5d080edeca1b5b85b6d12036 100644 --- a/src/main/webapp-gae/WEB-INF/web.xml +++ b/src/main/webapp-gae/WEB-INF/web.xml @@ -78,6 +78,11 @@ <!-- 2. Filters --> + <filter> + <filter-name>OnyxHttpsFilter</filter-name> + <filter-class>org.olat.core.servlets.FakeHttpsFilter</filter-class> + </filter> + <filter> <filter-name>PaypalIPNFilter</filter-name> <filter-class>org.olat.resource.accesscontrol.provider.paypal.PaypalIPNFilter</filter-class> @@ -98,6 +103,16 @@ <param-value>org.olat.restapi.support.OlatRestApplication</param-value> </init-param> </filter> + + <!-- Use FakeHTTPSFilter for requests to WSService and TraineeStatusService (dynamic WSDL for ONYX) --> + <filter-mapping> + <filter-name>OnyxHttpsFilter</filter-name> + <url-pattern>/services/ReturnWSService</url-pattern> + </filter-mapping> + <filter-mapping> + <filter-name>OnyxHttpsFilter</filter-name> + <url-pattern>/services/TraineeStatusService</url-pattern> + </filter-mapping> <!-- The mapping to the Login filter REST API --> <filter-mapping> diff --git a/src/main/webapp-jbossas7/WEB-INF/web.xml b/src/main/webapp-jbossas7/WEB-INF/web.xml index e646b192ba6d560cfee45bef0f6bc1edb1c5a023..34bb5a07fb49e0067ded6c22f42d948d6c99adfb 100644 --- a/src/main/webapp-jbossas7/WEB-INF/web.xml +++ b/src/main/webapp-jbossas7/WEB-INF/web.xml @@ -78,6 +78,11 @@ <!-- 2. Filters --> + <filter> + <filter-name>OnyxHttpsFilter</filter-name> + <filter-class>org.olat.core.servlets.FakeHttpsFilter</filter-class> + </filter> + <filter> <filter-name>PaypalIPNFilter</filter-name> <filter-class>org.olat.resource.accesscontrol.provider.paypal.PaypalIPNFilter</filter-class> @@ -98,6 +103,16 @@ <param-value>org.olat.restapi.support.OlatRestApplication</param-value> </init-param> </filter> + + <!-- Use FakeHTTPSFilter for requests to WSService and TraineeStatusService (dynamic WSDL for ONYX) --> + <filter-mapping> + <filter-name>OnyxHttpsFilter</filter-name> + <url-pattern>/services/ReturnWSService</url-pattern> + </filter-mapping> + <filter-mapping> + <filter-name>OnyxHttpsFilter</filter-name> + <url-pattern>/services/TraineeStatusService</url-pattern> + </filter-mapping> <!-- The mapping to the Login filter REST API --> <filter-mapping> diff --git a/src/main/webapp-tomcat/WEB-INF/web.xml b/src/main/webapp-tomcat/WEB-INF/web.xml index 8f2d444c4bfd7a1b5755747d0ab8a303f131ed06..0e40b6ebf1342796baee81e8b0fdda3142f3ebc6 100644 --- a/src/main/webapp-tomcat/WEB-INF/web.xml +++ b/src/main/webapp-tomcat/WEB-INF/web.xml @@ -73,6 +73,11 @@ <!-- 2. Filters --> + <filter> + <filter-name>OnyxHttpsFilter</filter-name> + <filter-class>org.olat.core.servlets.FakeHttpsFilter</filter-class> + </filter> + <filter> <filter-name>PaypalIPNFilter</filter-name> <filter-class>org.olat.resource.accesscontrol.provider.paypal.PaypalIPNFilter</filter-class> @@ -83,6 +88,16 @@ <filter-class>org.olat.restapi.security.RestApiLoginFilter</filter-class> </filter> + <!-- Use FakeHTTPSFilter for requests to WSService and TraineeStatusService (dynamic WSDL for ONYX) --> + <filter-mapping> + <filter-name>OnyxHttpsFilter</filter-name> + <url-pattern>/services/ReturnWSService</url-pattern> + </filter-mapping> + <filter-mapping> + <filter-name>OnyxHttpsFilter</filter-name> + <url-pattern>/services/TraineeStatusService</url-pattern> + </filter-mapping> + <!-- The mapping to the Login filter REST API --> <filter-mapping> <filter-name>PaypalIPNFilter</filter-name>