aboutsummaryrefslogtreecommitdiff
path: root/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java')
-rw-r--r--id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java111
1 files changed, 86 insertions, 25 deletions
diff --git a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java
index a25a7f421..900adaff7 100644
--- a/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java
+++ b/id/server/modules/moa-id-module-ehvd_integration/src/main/java/at/gv/egovernment/moa/id/auth/modules/ehvd/service/EhvdCommunicationService.java
@@ -2,10 +2,12 @@ package at.gv.egovernment.moa.id.auth.modules.ehvd.service;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
@@ -29,6 +31,7 @@ import at.gv.egiz.eaaf.core.exceptions.EAAFBuilderException;
import at.gv.egiz.eaaf.core.exceptions.EAAFConfigurationException;
import at.gv.egiz.eaaf.core.impl.data.Pair;
import at.gv.egiz.eaaf.core.impl.idp.auth.builder.BPKBuilder;
+import at.gv.egiz.eaaf.core.impl.utils.KeyValueUtils;
import at.gv.egovernment.moa.id.auth.exception.AuthenticationException;
import at.gv.egovernment.moa.id.auth.modules.ehvd.ConfigurationProperties;
import at.gv.egovernment.moa.id.auth.modules.ehvd.client.wsdl.EHVD;
@@ -55,16 +58,20 @@ public class EhvdCommunicationService implements IEhvdCommunication {
private static final String ERROR_EHVD_01 = "ehvd.01";
private static final String ERROR_EHVD_02 = "ehvd.02";
private static final String ERROR_EHVD_03 = "ehvd.03";
+ private static final String ERROR_EHVD_04 = "ehvd.04";
private static final String ERROR_CONFIG_05 = "config.05";
-
+
private static final Set<String> SERVICE_ERRORS_LOG_INFO = Sets.newHashSet("6002");
-
+
@Autowired
IConfiguration config;
private String ehvdBpkTarget;
private EHVD ehvdClient;
+ private Pattern ehvdRolePattern;
+
+ private List<String> ehvhPvpRoleList;
/**
* Get user's GDA roles from EHVD Service.
@@ -102,9 +109,9 @@ public class EhvdCommunicationService implements IEhvdCommunication {
Logger.debug("Receive GDA status. Starting response validation ... ");
return gdaResp;
- } catch (final SOAPFaultException e) {
+ } catch (final SOAPFaultException e) {
throw handleSoapFaultError(e);
-
+
} catch (final Exception e) {
Logger.error("EHVD communication failed with generic error: " + e.getMessage(), e);
throw new EhvdException(ERROR_EHVD_01, new Object[] {}, e);
@@ -114,24 +121,25 @@ public class EhvdCommunicationService implements IEhvdCommunication {
}
private EhvdException handleSoapFaultError(SOAPFaultException e) {
- // extract reason for this error
- String errorMsg = e.getFault() != null
- ? StringUtils.isNotEmpty(e.getFault().getFaultString()) ? e.getFault().getFaultString() : e.getMessage()
+ // extract reason for this error
+ final String errorMsg = e.getFault() != null
+ ? StringUtils.isNotEmpty(e.getFault().getFaultString()) ? e.getFault().getFaultString()
+ : e.getMessage()
: e.getMessage();
-
+
if (SERVICE_ERRORS_LOG_INFO.stream()
- .filter(el -> errorMsg.contains(el))
- .findFirst()
- .isPresent()) {
- Logger.info("EHVD communication failed with SOAP response: " + errorMsg);
-
+ .filter(el -> errorMsg.contains(el))
+ .findFirst()
+ .isPresent()) {
+ Logger.info("EHVD communication failed with SOAP response: " + errorMsg);
+
} else {
Logger.warn("EHVD communication failed with SOAP response: " + errorMsg, e);
-
- }
-
- return new EhvdException(ERROR_EHVD_02, new Object[] {errorMsg});
-
+
+ }
+
+ return new EhvdException(ERROR_EHVD_02, new Object[] { errorMsg });
+
}
private List<String> parseGdaResponse(GdaIndexResponse ehvdResp) throws EhvdException {
@@ -139,7 +147,24 @@ public class EhvdCommunicationService implements IEhvdCommunication {
final GdaDescriptor gdaInfo = ehvdResp.getGda();
if (GDA_RESP_STATUS_ACTIVE.equals(gdaInfo.getStatus().getEhvdstatus())) {
Logger.debug("Find #" + gdaInfo.getRoles().getRole().size() + " roles");
- return gdaInfo.getRoles().getRole();
+
+ // match roles with regex from configuration
+ final Optional<String> validGdaRole = gdaInfo.getRoles().getRole().stream()
+ .filter(el -> matchGdaRole(el))
+ .findFirst();
+
+ if (validGdaRole.isPresent()) {
+ Logger.info("Find valid GDA role: " + validGdaRole.get() + " Set PVP Role: "
+ + StringUtils.join(ehvhPvpRoleList, ",") + " into Session");
+
+ // set role into response
+ return ehvhPvpRoleList;
+
+ } else {
+ Logger.info("No valid GDA role in EHVD response");
+ throw new EhvdException(ERROR_EHVD_04, null);
+
+ }
} else {
Logger.info("GDA is marked as 'inactive'. Stopping process with an error ... ");
@@ -150,11 +175,19 @@ public class EhvdCommunicationService implements IEhvdCommunication {
} else {
Logger.info("Receive empty GDA response");
throw new EhvdException(ERROR_EHVD_03, new Object[] {});
-
}
}
+ private boolean matchGdaRole(String role) {
+ final Matcher matcher = ehvdRolePattern.matcher(role);
+ final boolean matches = matcher.matches();
+ Logger.trace(matches ? "EHVD role: " + role + " matches"
+ : "EHVD role: " + role + " does not matche to pattern: " + matcher.toString());
+ return matches;
+
+ }
+
private GetGdaDescriptors buildGdaRequest(String bPK) {
final GetGdaDescriptors req = new GetGdaDescriptors();
final InstanceIdentifier gdaIdentifier = new InstanceIdentifier();
@@ -170,17 +203,45 @@ public class EhvdCommunicationService implements IEhvdCommunication {
if (config.getBasicConfigurationBoolean(ConfigurationProperties.PROP_MODULE_ENABLED, false)) {
initializeEhvdClient();
+ // load EHVD bPK target
ehvdBpkTarget = config.getBasicConfiguration(
ConfigurationProperties.PROP_MODULE_SERVICE_TARGET,
ConfigurationProperties.DEFAULT_EHVD_SERVICE_TARGET);
Logger.info("Set-up EHVD Client with bPK target: " + ehvdBpkTarget);
+ // load Regex to match EHVD Roles to PVP Roles
+ final String ehvdRoleRegex = config.getBasicConfiguration(
+ ConfigurationProperties.PROP_MODULE_EHVD_ROLE_REGEX);
+ checkConfigPropertyNotNull(ehvdRoleRegex, ConfigurationProperties.PROP_MODULE_EHVD_ROLE_REGEX);
+ ehvdRolePattern = Pattern.compile(ehvdRoleRegex);
+
+ Logger.info("Set-up EHVD Client with Role regex: " + ehvdRolePattern.toString());
+
+ // load PVP Roles for EHVD integration
+ final String ehvdPvpRole = config.getBasicConfiguration(
+ ConfigurationProperties.PROP_MODULE_PVP_ROLE);
+ checkConfigPropertyNotNull(ehvdPvpRole, ConfigurationProperties.PROP_MODULE_PVP_ROLE);
+ ehvhPvpRoleList = KeyValueUtils.getListOfCSVValues(ehvdPvpRole);
+ Logger.info("Set-up EHVD module with PVP Role: " + StringUtils.join(ehvhPvpRoleList, ","));
+
} else {
Logger.info("Skipping EHVD client because it's not active");
}
}
+ private void checkConfigPropertyNotNull(String valueToCheck, String configPropName)
+ throws EAAFConfigurationException {
+ if (StringUtils.isEmpty(valueToCheck)) {
+ Logger.error("Missing configuration for EHVD module. "
+ + "(Property: " + configPropName + ")");
+ throw new EAAFConfigurationException(ERROR_CONFIG_05,
+ new Object[] { configPropName });
+
+ }
+
+ }
+
private void initializeEhvdClient() throws EAAFConfigurationException {
Logger.debug("Initializing EHVD client ... ");
final URL url = EhvdCommunicationService.class.getResource("/wsdl/eHVD.wsdl");
@@ -214,9 +275,9 @@ public class EhvdCommunicationService implements IEhvdCommunication {
Logger.info("Initialize EHVD Client with service end-point: " + ehvdEndpointUrl);
-
// these code is only for local testing
- String socksPort = config.getBasicConfiguration(ConfigurationProperties.PROP_MODULE_PROXY_SOCKS_PORT);
+ final String socksPort = config.getBasicConfiguration(
+ ConfigurationProperties.PROP_MODULE_PROXY_SOCKS_PORT);
if (StringUtils.isNotEmpty(socksPort)) {
Logger.warn("Injecting SOCKS5 Proxy for service communication!");
final Client client = ClientProxy.getClient(ehvdClient);
@@ -224,9 +285,9 @@ public class EhvdCommunicationService implements IEhvdCommunication {
http.getClient().setProxyServerType(ProxyServerType.SOCKS);
http.getClient().setProxyServer("127.0.0.1");
http.getClient().setProxyServerPort(Integer.valueOf(socksPort));
-
+
}
-
+
}
}