summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-03-11 12:46:45 +0100
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-03-11 12:46:45 +0100
commitf95a1fb3982395ccbc7e139cb5bd8a1c106bbb48 (patch)
treee2fd57efe89ded06cfe998d712b68bd2ed4b1de2 /eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java
parent19bc544de503af5992d045a699a1f2bcc1eaf505 (diff)
downloadEAAF-Components-f95a1fb3982395ccbc7e139cb5bd8a1c106bbb48.tar.gz
EAAF-Components-f95a1fb3982395ccbc7e139cb5bd8a1c106bbb48.tar.bz2
EAAF-Components-f95a1fb3982395ccbc7e139cb5bd8a1c106bbb48.zip
refactor HttpClientFactory.java to build HTTP clients with different authentication mechanisms
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java118
1 files changed, 0 insertions, 118 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java
deleted file mode 100644
index 66356ba0..00000000
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/HttpUtils.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2014 Federal Chancellery Austria MOA-ID has been developed in a cooperation between
- * BRZ, the Federal Chancellery Austria - ICT staff unit, and Graz University of Technology.
- *
- * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the European
- * Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work except in
- * compliance with the Licence. You may obtain a copy of the Licence at: http://www.osor.eu/eupl/
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the Licence
- * is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the Licence for the specific language governing permissions and limitations under
- * the Licence.
- *
- * This product combines work with different licenses. See the "NOTICE" text file for details on the
- * various modules and licenses. The "NOTICE" text file is part of the distribution. Any derivative
- * works that you distribute must include a readable copy of the "NOTICE" text file.
-*/
-
-package at.gv.egiz.eaaf.core.impl.utils;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.lang3.StringUtils;
-
-public class HttpUtils {
-
- /**
- * Helper method to retrieve server URL including context path.
- *
- * @param request HttpServletRequest
- * @return Server URL including context path (e.g.
- * http://localhost:8443/moa-id-auth
- */
- public static String getBaseUrl(final HttpServletRequest request) {
- final StringBuffer buffer = new StringBuffer(getServerUrl(request));
-
- // add context path if available
- final String contextPath = request.getContextPath();
- if (!StringUtils.isEmpty(contextPath)) {
- buffer.append(contextPath);
- }
-
- return buffer.toString();
- }
-
- /**
- * Helper method to retrieve server URL.
- *
- * @param request HttpServletRequest
- * @return Server URL (e.g. http://localhost:8443)
- */
- public static String getServerUrl(final HttpServletRequest request) {
- final StringBuffer buffer = new StringBuffer();
-
- // get protocol
- final String protocol = request.getScheme();
- buffer.append(protocol).append("://");
-
- // server name
- buffer.append(request.getServerName());
-
- // add port if necessary
- final int port = request.getServerPort();
- if (protocol.equals("http") && port != 80 || protocol.equals("https") && port != 443) {
- buffer.append(':');
- buffer.append(port);
- }
-
- return buffer.toString();
- }
-
- /**
- * Extract the IDP PublicURLPrefix from authrequest.
- *
- * @param req HttpServletRequest
- * @return PublicURLPrefix which ends always without /
- */
- public static String extractAuthUrlFromRequest(final HttpServletRequest req) {
- String authUrl = req.getScheme() + "://" + req.getServerName();
- if (req.getScheme().equalsIgnoreCase("https") && req.getServerPort() != 443
- || req.getScheme().equalsIgnoreCase("http") && req.getServerPort() != 80) {
- authUrl = authUrl.concat(":" + req.getServerPort());
- }
- authUrl = authUrl.concat(req.getContextPath());
- return authUrl;
-
- }
-
- /**
- * Extract the IDP requested URL from authrequest.
- *
- * @param req HttpServletRequest
- * @return RequestURL which ends always without /
- */
- public static String extractAuthServletPathFromRequest(final HttpServletRequest req) {
- return extractAuthUrlFromRequest(req).concat(req.getServletPath());
-
- }
-
- /**
- * Add a http GET parameter to URL.
- *
- * @param url URL
- * @param paramname Name of the parameter.
- * @param paramvalue Value of the parameter.
- * @return
- */
- public static String addUrlParameter(final String url, final String paramname,
- final String paramvalue) {
- final String param = paramname + "=" + paramvalue;
- if (url.indexOf("?") < 0) {
- return url + "?" + param;
- } else {
- return url + "&" + param;
- }
- }
-
-}