summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java
diff options
context:
space:
mode:
authorThomas <thomas.lenz@egiz.gv.at>2019-12-05 09:52:48 +0100
committerThomas <thomas.lenz@egiz.gv.at>2019-12-05 09:52:48 +0100
commit3fada6cef21c9b16467177d866df778203b51b4d (patch)
tree8fe8ed37b6ee9fe35a1e035ceba6c68808328415 /eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java
parent95b21a826e5d81fdeabcf4673a9e87047edaec9d (diff)
downloadEAAF-Components-3fada6cef21c9b16467177d866df778203b51b4d.tar.gz
EAAF-Components-3fada6cef21c9b16467177d866df778203b51b4d.tar.bz2
EAAF-Components-3fada6cef21c9b16467177d866df778203b51b4d.zip
some code code-style modifications
active code-quality checks!
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java109
1 files changed, 57 insertions, 52 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java
index 60c08253..a613bd56 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/BpkBuilder.java
@@ -16,8 +16,6 @@
* works that you distribute must include a readable copy of the "NOTICE" text file.
*/
-
-
package at.gv.egiz.eaaf.core.impl.idp.auth.builder;
import java.security.InvalidKeyException;
@@ -27,22 +25,26 @@ import java.security.PrivateKey;
import java.security.PublicKey;
import java.text.SimpleDateFormat;
import java.util.Date;
+
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
-import at.gv.egiz.eaaf.core.api.data.EAAFConstants;
-import at.gv.egiz.eaaf.core.exceptions.EaafBuilderException;
-import at.gv.egiz.eaaf.core.impl.data.Pair;
+
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils;
+import at.gv.egiz.eaaf.core.api.data.EaafConstants;
+import at.gv.egiz.eaaf.core.exceptions.EaafBuilderException;
+import at.gv.egiz.eaaf.core.impl.data.Pair;
+
/**
* Builder for the bPK, as defined in
- * <code>&quot;Ableitung f&uml;r die bereichsspezifische Personenkennzeichnung&quot;</code> version
- * <code>1.0.1</code> from <code>&quot;reference.e-government.gv.at&quot;</code>.
+ * <code>&quot;Ableitung f&uml;r die bereichsspezifische Personenkennzeichnung&quot;</code>
+ * version <code>1.0.1</code> from
+ * <code>&quot;reference.e-government.gv.at&quot;</code>.
*
*/
public class BpkBuilder {
@@ -51,58 +53,60 @@ public class BpkBuilder {
/**
* Calculates an area specific unique person-identifier from a baseID.
*
- * @param baseID baseId from user but never null
- * @param targetIdentifier target identifier for area specific identifier calculation but never
- * null
- * @return Pair consists of (unique person identifier for this target, targetArea) but never null
+ * @param baseID baseId from user but never null
+ * @param targetIdentifier target identifier for area specific identifier
+ * calculation but never null
+ * @return Pair consists of (unique person identifier for this target,
+ * targetArea) but never null
* @throws EaafBuilderException if some input data are not valid
*/
public static Pair<String, String> generateAreaSpecificPersonIdentifier(final String baseID,
final String targetIdentifier) throws EaafBuilderException {
- return generateAreaSpecificPersonIdentifier(baseID, EAAFConstants.URN_PREFIX_BASEID,
+ return generateAreaSpecificPersonIdentifier(baseID, EaafConstants.URN_PREFIX_BASEID,
targetIdentifier);
}
/**
- * Calculates an area specific unique person-identifier from an unique identifier with a specific
- * type.
+ * Calculates an area specific unique person-identifier from an unique
+ * identifier with a specific type.
*
- * @param baseID baseId from user but never null
- * @param baseIdType Type of the baseID but never null
- * @param targetIdentifier target identifier for area specific identifier calculation but never
- * null
- * @return Pair consists of (unique person identifier for this target, targetArea) but never null
+ * @param baseID baseId from user but never null
+ * @param baseIdType Type of the baseID but never null
+ * @param targetIdentifier target identifier for area specific identifier
+ * calculation but never null
+ * @return Pair consists of (unique person identifier for this target,
+ * targetArea) but never null
* @throws EaafBuilderException if some input data are not valid
*/
public static Pair<String, String> generateAreaSpecificPersonIdentifier(final String baseID,
final String baseIdType, final String targetIdentifier) throws EaafBuilderException {
if (StringUtils.isEmpty(baseID)) {
- throw new EaafBuilderException("builder.00", new Object[] {"baseID is empty or null"},
+ throw new EaafBuilderException("builder.00", new Object[] { "baseID is empty or null" },
"BaseId is empty or null");
}
if (StringUtils.isEmpty(baseIdType)) {
throw new EaafBuilderException("builder.00",
- new Object[] {"the type of baseID is empty or null"}, "Type of baseId is empty or null");
+ new Object[] { "the type of baseID is empty or null" }, "Type of baseId is empty or null");
}
if (StringUtils.isEmpty(targetIdentifier)) {
throw new EaafBuilderException("builder.00",
- new Object[] {"SP specific target identifier is empty or null"},
+ new Object[] { "SP specific target identifier is empty or null" },
"SP specific target identifier is empty or null");
}
- if (baseIdType.equals(EAAFConstants.URN_PREFIX_BASEID)) {
+ if (baseIdType.equals(EaafConstants.URN_PREFIX_BASEID)) {
log.trace("Find baseID. Starting unique identifier caluclation for this target");
- if (targetIdentifier.startsWith(EAAFConstants.URN_PREFIX_CDID)
- || targetIdentifier.startsWith(EAAFConstants.URN_PREFIX_WBPK)) {
+ if (targetIdentifier.startsWith(EaafConstants.URN_PREFIX_CDID)
+ || targetIdentifier.startsWith(EaafConstants.URN_PREFIX_WBPK)) {
log.trace("Calculate bPK, wbPK, or STORK identifier for target: " + targetIdentifier);
return Pair.newInstance(calculatebPKwbPK(baseID + "+" + targetIdentifier),
targetIdentifier);
- } else if (targetIdentifier.startsWith(EAAFConstants.URN_PREFIX_EIDAS)) {
+ } else if (targetIdentifier.startsWith(EaafConstants.URN_PREFIX_EIDAS)) {
log.trace("Calculate eIDAS identifier for target: " + targetIdentifier);
final String[] splittedTarget = targetIdentifier.split("\\+");
final String cititzenCountryCode = splittedTarget[1];
@@ -114,15 +118,14 @@ public class BpkBuilder {
}
return buildEidasIdentifer(baseID, baseIdType, cititzenCountryCode, eidasOutboundCountry);
-
} else {
throw new EaafBuilderException("builder.00",
- new Object[] {"Target identifier: " + targetIdentifier + " is NOT allowed or unknown"},
+ new Object[] { "Target identifier: " + targetIdentifier + " is NOT allowed or unknown" },
"Target identifier: " + targetIdentifier + " is NOT allowed or unknown");
}
} else {
- log.trace("BaseID is not of type " + EAAFConstants.URN_PREFIX_BASEID
+ log.trace("BaseID is not of type " + EaafConstants.URN_PREFIX_BASEID
+ ". Check type against requested target ...");
if (baseIdType.equals(targetIdentifier)) {
log.debug("Unique identifier is already area specific. Is nothing todo");
@@ -132,8 +135,8 @@ public class BpkBuilder {
log.warn("Get unique identifier for target: " + baseIdType + " but target: "
+ targetIdentifier + " is required!");
throw new EaafBuilderException("builder.00",
- new Object[] {"Get unique identifier for target: " + baseIdType + " but target: "
- + targetIdentifier + " is required"},
+ new Object[] { "Get unique identifier for target: " + baseIdType + " but target: "
+ + targetIdentifier + " is required" },
"Get unique identifier for target: " + baseIdType + " but target: " + targetIdentifier
+ " is required");
@@ -141,14 +144,15 @@ public class BpkBuilder {
}
}
-
/**
* Builds the eIDAS from the given parameters.
*
- * @param baseId baseID of the citizen
- * @param baseIdType Type of the baseID
- * @param sourceCountry CountryCode of that country, which build the eIDAs ID
- * @param destinationCountry CountryCode of that country, which receives the eIDAs ID
+ * @param baseId baseID of the citizen
+ * @param baseIdType Type of the baseID
+ * @param sourceCountry CountryCode of that country, which build the eIDAs
+ * ID
+ * @param destinationCountry CountryCode of that country, which receives the
+ * eIDAs ID
*
* @return Pair eIDAs/bPKType in a BASE64 encoding
* @throws EaafBuilderException if some input data are not valid
@@ -160,8 +164,8 @@ public class BpkBuilder {
String bpkType = null;
// check if we have been called by public sector application
- if (baseIdType.startsWith(EAAFConstants.URN_PREFIX_BASEID)) {
- bpkType = EAAFConstants.URN_PREFIX_EIDAS + sourceCountry + "+" + destinationCountry;
+ if (baseIdType.startsWith(EaafConstants.URN_PREFIX_BASEID)) {
+ bpkType = EaafConstants.URN_PREFIX_EIDAS + sourceCountry + "+" + destinationCountry;
log.debug("Building eIDAS identification from: [identValue]+" + bpkType);
bpk = calculatebPKwbPK(baseId + "+" + bpkType);
@@ -173,9 +177,9 @@ public class BpkBuilder {
if (StringUtils.isEmpty(bpk) || StringUtils.isEmpty(sourceCountry)
|| StringUtils.isEmpty(destinationCountry)) {
throw new EaafBuilderException("builder.00",
- new Object[] {"eIDAS-ID",
+ new Object[] { "eIDAS-ID",
"Unvollständige Parameterangaben: identificationValue=" + bpk + ", Zielland="
- + destinationCountry + ", Ursprungsland=" + sourceCountry},
+ + destinationCountry + ", Ursprungsland=" + sourceCountry },
"eIDAS-ID: Unvollständige Parameterangaben: identificationValue=" + bpk + ", Zielland="
+ destinationCountry + ", Ursprungsland=" + sourceCountry);
}
@@ -189,8 +193,8 @@ public class BpkBuilder {
/**
* Create an encrypted bPK.
*
- * @param bpk unencrypted bPK
- * @param target bPK target
+ * @param bpk unencrypted bPK
+ * @param target bPK target
* @param publicKey Public-Key used for encryption
* @return encrypted bPK
* @throws EaafBuilderException In case of an error
@@ -198,8 +202,8 @@ public class BpkBuilder {
public static String encryptBpk(final String bpk, String target, final PublicKey publicKey)
throws EaafBuilderException {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
- if (target.startsWith(EAAFConstants.URN_PREFIX_CDID)) {
- target = target.substring(EAAFConstants.URN_PREFIX_CDID.length());
+ if (target.startsWith(EaafConstants.URN_PREFIX_CDID)) {
+ target = target.substring(EaafConstants.URN_PREFIX_CDID.length());
}
final String input =
@@ -210,8 +214,8 @@ public class BpkBuilder {
final byte[] inputBytes = input.getBytes("ISO-8859-1");
result = encrypt(inputBytes, publicKey);
return new String(Base64Utils.encode(result), "ISO-8859-1").replaceAll("\r\n", "");
- // return new String(Base64Utils.encode(result, "ISO-8859-1")).replaceAll("\r\n", "");
-
+ // return new String(Base64Utils.encode(result,
+ // "ISO-8859-1")).replaceAll("\r\n", "");
} catch (final Exception e) {
throw new EaafBuilderException("bPK encryption FAILED", null, e.getMessage(), e);
@@ -223,8 +227,8 @@ public class BpkBuilder {
* Decrypt an encrypted bPK.
*
* @param encryptedBpk encrypted bPK
- * @param target bPK target
- * @param privateKey private-key for decryption
+ * @param target bPK target
+ * @param privateKey private-key for decryption
* @return bPK
* @throws EaafBuilderException In case of an error
*/
@@ -232,7 +236,8 @@ public class BpkBuilder {
final PrivateKey privateKey) throws EaafBuilderException {
String decryptedString;
try {
- // byte[] encryptedBytes = Base64Utils.decode(encryptedBpk, false, "ISO-8859-1");
+ // byte[] encryptedBytes = Base64Utils.decode(encryptedBpk, false,
+ // "ISO-8859-1");
final byte[] encryptedBytes = Base64Utils.decode(encryptedBpk.getBytes("ISO-8859-1"));
final byte[] decryptedBytes = decrypt(encryptedBytes, privateKey);
decryptedString = new String(decryptedBytes, "ISO-8859-1");
@@ -247,8 +252,8 @@ public class BpkBuilder {
tmp = tmp.substring(tmp.indexOf("::") + 2);
final String bPK = tmp.substring(0, tmp.indexOf("::"));
- if (target.startsWith(EAAFConstants.URN_PREFIX_CDID + "+")) {
- target = target.substring((EAAFConstants.URN_PREFIX_CDID + "+").length());
+ if (target.startsWith(EaafConstants.URN_PREFIX_CDID + "+")) {
+ target = target.substring((EaafConstants.URN_PREFIX_CDID + "+").length());
}
if (target.equals(sector)) {
@@ -268,7 +273,7 @@ public class BpkBuilder {
return hashBase64;
} catch (final Exception ex) {
- throw new EaafBuilderException("builder.00", new Object[] {"bPK/wbPK", ex.toString()},
+ throw new EaafBuilderException("builder.00", new Object[] { "bPK/wbPK", ex.toString() },
ex.getMessage(), ex);
}