summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas <>2023-10-02 13:07:50 +0200
committerThomas <>2023-10-02 13:07:50 +0200
commit44240b20f863fbd437e06947b539f76e73e91668 (patch)
treecbd401da1998dc6a44ff3cb424f0dcfdb7792f28
parent433042fbb344387aabd7bb09ed498797b538aae3 (diff)
downloadEAAF-Components-44240b20f863fbd437e06947b539f76e73e91668.tar.gz
EAAF-Components-44240b20f863fbd437e06947b539f76e73e91668.tar.bz2
EAAF-Components-44240b20f863fbd437e06947b539f76e73e91668.zip
chore(core): code clean-up and optimization
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java2
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java13
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java28
3 files changed, 29 insertions, 14 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java
index 8dd208a9..0e454c7a 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java
@@ -494,7 +494,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
try {
final IGuiBuilderConfiguration config = guiConfigFactory
- .getDefaultErrorGui(HttpUtils.extractAuthUrlFromRequest(httpReq));
+ .getDefaultErrorGui(HttpUtils.extractAuthUrlStringFromRequest(httpReq));
String[] errorCodeParams = null;
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java
index 3b3e7cd8..f5703cab 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/protocols/RequestImpl.java
@@ -21,7 +21,6 @@ package at.gv.egiz.eaaf.core.impl.idp.controller.protocols;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
import java.net.URL;
import java.time.Instant;
import java.util.HashMap;
@@ -182,21 +181,13 @@ public abstract class RequestImpl implements IRequest, Serializable {
// Random.nextLongRandom());
// check if End-Point is valid
- final String authUrlString = HttpUtils.extractAuthUrlFromRequest(req);
- URL authReqUrl;
- try {
- authReqUrl = new URL(authUrlString);
-
- } catch (final MalformedURLException e) {
- log.error("IDP AuthenticationServiceURL Prefix is not a valid URL." + authUrlString, e);
- throw new EaafAuthenticationException(ERROR_CODE_INTERNAL_00, new Object[] { authUrlString }, e);
+ URL authReqUrl = HttpUtils.extractAuthUrlFromRequest(req);
- }
this.idpAuthUrl = authConfig.validateIdpUrl(authReqUrl);
if (this.idpAuthUrl == null) {
log.warn(
"Extract AuthenticationServiceURL: " + authReqUrl + " is NOT found in configuration.");
- throw new EaafAuthenticationException(ERROR_CODE_INTERNAL_00, new Object[] { authUrlString });
+ throw new EaafAuthenticationException(ERROR_CODE_INTERNAL_00, new Object[] { authReqUrl });
}
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());
}