summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
index caa73e04..1b6df3de 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
@@ -21,6 +21,8 @@ package at.gv.egiz.eaaf.core.impl.http;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -45,6 +47,7 @@ import org.apache.hc.core5.http.message.StatusLine;
import org.apache.hc.core5.ssl.TrustStrategy;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
+import at.gv.egiz.eaaf.core.exceptions.EaafAuthenticationException;
import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
import at.gv.egiz.eaaf.core.exceptions.EaafFactoryException;
import at.gv.egiz.eaaf.core.impl.data.Pair;
@@ -56,6 +59,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class HttpUtils {
+ private static final String ERROR_CODE_INTERNAL_00 = "eaaf.core.00";
private static final String ERROR_03 = "internal.httpclient.03";
/**
@@ -148,7 +152,7 @@ public class HttpUtils {
* @param req HttpServletRequest
* @return PublicURLPrefix which ends always without /
*/
- public static String extractAuthUrlFromRequest(final HttpServletRequest req) {
+ public static String extractAuthUrlStringFromRequest(final HttpServletRequest req) {
String authUrl = req.getScheme() + "://" + req.getServerName();
if (req.getScheme().equalsIgnoreCase("https") && req.getServerPort() != 443
|| req.getScheme().equalsIgnoreCase("http") && req.getServerPort() != 80) {
@@ -160,13 +164,33 @@ public class HttpUtils {
}
/**
+ * Extract the IDP PublicURLPrefix from authrequest.
+ *
+ * @param req HttpServletRequest
+ * @return PublicURLPrefix which ends always without /
+ */
+ public static URL extractAuthUrlFromRequest(final HttpServletRequest req)
+ throws EaafAuthenticationException {
+ String authUrlString = extractAuthUrlStringFromRequest(req);
+ try {
+ return new URL(authUrlString);
+
+ } catch (final MalformedURLException e) {
+ log.error("URL Prefix is not a valid URL." + authUrlString, e);
+ throw new EaafAuthenticationException(ERROR_CODE_INTERNAL_00, new Object[] { authUrlString }, e);
+
+ }
+
+ }
+
+ /**
* 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());
+ return extractAuthUrlStringFromRequest(req).concat(req.getServletPath());
}