summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 12:13:29 +0200
committerThomas Lenz <thomas.lenz@egiz.gv.at>2020-06-10 12:13:29 +0200
commit95608438dd3efa448f5fcd0cb2b7960b317d1af0 (patch)
treecfe88f78bae51412df1d9981ef3428c89177c2e0
parent4e4002c7e982218649f10349e634c17770d603d4 (diff)
downloadEAAF-Components-95608438dd3efa448f5fcd0cb2b7960b317d1af0.tar.gz
EAAF-Components-95608438dd3efa448f5fcd0cb2b7960b317d1af0.tar.bz2
EAAF-Components-95608438dd3efa448f5fcd0cb2b7960b317d1af0.zip
add i18n parameter into SL2.0 request
-rw-r--r--eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/tasks/AbstractCreateQualEidRequestTask.java118
-rw-r--r--eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20Constants.java13
2 files changed, 77 insertions, 54 deletions
diff --git a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/tasks/AbstractCreateQualEidRequestTask.java b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/tasks/AbstractCreateQualEidRequestTask.java
index 6c11fa63..032ac8ee 100644
--- a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/tasks/AbstractCreateQualEidRequestTask.java
+++ b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/tasks/AbstractCreateQualEidRequestTask.java
@@ -4,26 +4,12 @@ import java.io.Serializable;
import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.NameValuePair;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.message.BasicNameValuePair;
-import org.jose4j.base64url.Base64Url;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
import at.gv.egiz.eaaf.core.api.idp.IConfigurationWithSP;
import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration;
import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext;
@@ -45,6 +31,23 @@ import at.gv.egiz.eaaf.modules.auth.sl20.utils.SL20HttpBindingUtils;
import at.gv.egiz.eaaf.modules.auth.sl20.utils.SL20JsonBuilderUtils;
import at.gv.egiz.eaaf.modules.auth.sl20.utils.SL20JsonExtractorUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.message.BasicNameValuePair;
+import org.jose4j.base64url.Base64Url;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.i18n.LocaleContextHolder;
+import org.springframework.web.servlet.support.RequestContextUtils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
public abstract class AbstractCreateQualEidRequestTask extends AbstractAuthServletTask {
private static final Logger log = LoggerFactory.getLogger(AbstractCreateQualEidRequestTask.class);
@@ -97,27 +100,10 @@ public abstract class AbstractCreateQualEidRequestTask extends AbstractAuthServl
final List<NameValuePair> parameters = new ArrayList<>();
parameters.add(new BasicNameValuePair(SL20Constants.PARAM_SL20_REQ_COMMAND_PARAM,
Base64Url.encode(sl20Req.toString().getBytes("UTF-8"))));
-
- //set specific authentication method if it was selection by process step before
- VdaAuthMethod authMethod = getVdaAuthMethodFromContext(executionContext);
- if (authMethod != null) {
- log.debug("Request VDA with authType: {}", authMethod);
- parameters.add(new BasicNameValuePair(SL20Constants.PARAM_SL20_REQ_AUTH_METHOD_PARAM,
- authMethod.getAuthMethod()));
- }
- //set VDA sessionId if it was available on context
- String vdaSessionId = getVdaSessionIdFromContext(executionContext);
- if (vdaSessionId != null) {
- log.trace("Request VDA with sessionId: {}", vdaSessionId);
- parameters.add(new BasicNameValuePair(
- SL20Constants.PARAM_SL20_REQ_AUTH_VDA_SESSIONID,
- vdaSessionId));
-
- }
-
-
-
+ //inject additional request parameters
+ injectAdditionalSL20RequestParams(parameters, executionContext, request);
+
httpReq.setEntity(new UrlEncodedFormEntity(parameters));
// build http GET request
@@ -213,9 +199,45 @@ public abstract class AbstractCreateQualEidRequestTask extends AbstractAuthServl
}
+ protected void injectAdditionalSL20RequestParams(List<NameValuePair> parameters,
+ ExecutionContext executionContext, HttpServletRequest request) {
+ //set specific authentication method if it was selection by process step before
+ final VdaAuthMethod authMethod = getVdaAuthMethodFromContext(executionContext);
+ if (authMethod != null) {
+ log.debug("Request VDA with authType: {}", authMethod);
+ parameters.add(new BasicNameValuePair(SL20Constants.PARAM_SL20_REQ_AUTH_METHOD_PARAM,
+ authMethod.getAuthMethod()));
+ }
+
+ //set VDA sessionId if it was available on context
+ final String vdaSessionId = getVdaSessionIdFromContext(executionContext);
+ if (vdaSessionId != null) {
+ log.trace("Request VDA with sessionId: {}", vdaSessionId);
+ parameters.add(new BasicNameValuePair(
+ SL20Constants.PARAM_SL20_REQ_AUTH_VDA_SESSIONID,
+ vdaSessionId));
+
+ }
+
+ //set i18n language into VDA request
+ final Locale locale = LocaleContextHolder.getLocale();
+ RequestContextUtils.getLocaleResolver(request);
+ final String language = locale.getLanguage();
+ if (StringUtils.isNotEmpty(language)) {
+ log.trace("Find i18n context. Inject locale: {} into VDA request", locale.getLanguage());
+ parameters.add(new BasicNameValuePair(
+ SL20Constants.PARAM_SL20_REQ_AUTH_VDA_LOCALE,
+ language.toUpperCase(locale)));
+
+ } else {
+ log.info("Find i18n context, but Language is UNKNOWN. It will be ignored");
+
+ }
+ }
+
/**
- * Get ExecutionContext parameter-key for VDA AuthMethod information.
- *
+ * Get ExecutionContext parameter-key for VDA AuthMethod information.
+ *
* @return Key to get AuthMethod from {@link ExecutionContext}
*/
protected abstract String getAuthMethodContextParamKey();
@@ -231,34 +253,34 @@ public abstract class AbstractCreateQualEidRequestTask extends AbstractAuthServl
*/
protected abstract String buildSignedQualifiedEidCommand() throws CertificateEncodingException, SL20Exception;
-
+
private VdaAuthMethod getVdaAuthMethodFromContext(ExecutionContext executionContext) {
- Serializable authMethodRaw = executionContext.get(getAuthMethodContextParamKey());
+ final Serializable authMethodRaw = executionContext.get(getAuthMethodContextParamKey());
if (authMethodRaw instanceof String) {
log.trace("Find authMethod parameter: {} on context", authMethodRaw);
return VdaAuthMethod.fromString((String) authMethodRaw);
-
+
}
-
+
return null;
}
-
+
private String getVdaSessionIdFromContext(ExecutionContext executionContext) {
- Serializable vdaSessionId = executionContext.get(
+ final Serializable vdaSessionId = executionContext.get(
SL20Constants.SL20_COMMAND_PARAM_GENERAL_RESPONSE_ERROR_VDASESSIONID);
- if (vdaSessionId instanceof String
+ if (vdaSessionId instanceof String
&& StringUtils.isNotEmpty((CharSequence) vdaSessionId)) {
executionContext.remove(
SL20Constants.SL20_COMMAND_PARAM_GENERAL_RESPONSE_ERROR_VDASESSIONID);
-
+
log.trace("Find vdaSessionId parameter: {} on context", vdaSessionId);
return (String) vdaSessionId;
-
+
}
-
+
return null;
}
-
+
private String extractVdaUrlForSpecificOa(final ISpConfiguration oaConfig, final ExecutionContext executionContext) {
// load SP specific config for development and testing purposes
diff --git a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20Constants.java b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20Constants.java
index edf70cc8..f0557619 100644
--- a/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20Constants.java
+++ b/eaaf_modules/eaaf_module_auth_sl20/src/main/java/at/gv/egiz/eaaf/modules/auth/sl20/utils/SL20Constants.java
@@ -13,14 +13,15 @@ import org.jose4j.jws.AlgorithmIdentifiers;
public class SL20Constants {
public static final int CURRENT_SL20_VERSION = 10;
-
+
// http binding parameters
public static final String PARAM_SL20_REQ_COMMAND_PARAM = "slcommand";
public static final String PARAM_SL20_REQ_COMMAND_PARAM_OLD = "sl2command";
public static final String PARAM_SL20_REQ_AUTH_METHOD_PARAM = "authtype";
public static final String PARAM_SL20_REQ_AUTH_VDA_SESSIONID = "session";
-
+ public static final String PARAM_SL20_REQ_AUTH_VDA_LOCALE = "locale";
+
public enum VdaAuthMethod {
ANY("any"), MOBILEPHONE("handy"), CARD("card"), SMARTPHONE("smartphone");
@@ -51,7 +52,7 @@ public class SL20Constants {
} catch (IllegalArgumentException | NullPointerException e) {
return VdaAuthMethod.ANY;
-
+
}
}
@@ -59,9 +60,9 @@ public class SL20Constants {
public String toString() {
return getAuthMethod();
- }
+ }
}
-
+
public static final String PARAM_SL20_REQ_ICP_RETURN_URL_PARAM = "slIPCReturnUrl";
public static final String PARAM_SL20_REQ_TRANSACTIONID = "slTransactionID";
@@ -177,7 +178,7 @@ public class SL20Constants {
// error command
public static final String SL20_COMMAND_PARAM_GENERAL_RESPONSE_ERRORCODE = "errorCode";
public static final String SL20_COMMAND_PARAM_GENERAL_RESPONSE_ERRORMESSAGE = "errorMessage";
- public static final String SL20_COMMAND_PARAM_GENERAL_RESPONSE_ERROR_VDASESSIONID
+ public static final String SL20_COMMAND_PARAM_GENERAL_RESPONSE_ERROR_VDASESSIONID
= "handySignaturSession";
// qualified eID command