From: Roland Haeder Date: Mon, 21 Sep 2015 10:04:08 +0000 (+0200) Subject: added missing Apache Commons library for BASE64-encoding + removed jcore-ee-logger... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b4c34f3a9fa28333fc69ff381e26978c3a6944bd;p=jshop-core.git added missing Apache Commons library for BASE64-encoding + removed jcore-ee-logger.jar as this jar was no longer needed (is an EJB module anyway) Signed-off-by:Roland Häder --- diff --git a/lib/commons-codec-1.10.jar b/lib/commons-codec-1.10.jar new file mode 100644 index 0000000..1d7417c Binary files /dev/null and b/lib/commons-codec-1.10.jar differ diff --git a/lib/jcore-ee-logger.jar b/lib/jcore-ee-logger.jar deleted file mode 100644 index 903d016..0000000 Binary files a/lib/jcore-ee-logger.jar and /dev/null differ diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index 42674a2..6061f28 100644 Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index b9b8134..e841dc3 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -921,14 +921,6 @@ is divided into following sections: - - - - - - - - @@ -1414,14 +1406,6 @@ is divided into following sections: - - - - - - - - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index e80406e..6cfed58 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=1c4c32e3 +build.xml.data.CRC32=9ef4aaf1 build.xml.script.CRC32=fa35cacf build.xml.stylesheet.CRC32=8064a381@1.75.2.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=1c4c32e3 -nbproject/build-impl.xml.script.CRC32=33c1ce19 +nbproject/build-impl.xml.data.CRC32=9ef4aaf1 +nbproject/build-impl.xml.script.CRC32=40bf9247 nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/nbproject/project.properties b/nbproject/project.properties index feebabc..4776cf1 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -30,6 +30,7 @@ dist.jar=${dist.dir}/jshop-core.jar dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= +file.reference.commons-codec-1.10.jar=lib\\commons-codec-1.10.jar file.reference.jcore.jar=lib/jcore.jar file.reference.jcoreee.jar=lib/jcoreee.jar includes=** @@ -38,9 +39,9 @@ jar.compress=false jar.index=${jnlp.enabled} javac.classpath=\ ${file.reference.jcore.jar}:\ - ${reference.jcore-ee-logger.dist}:\ ${file.reference.jcoreee.jar}:\ - ${libs.javaee-api-7.0.classpath} + ${libs.javaee-api-7.0.classpath}:\ + ${file.reference.commons-codec-1.10.jar} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation javac.deprecation=true @@ -80,9 +81,7 @@ manifest.custom.permissions= meta.inf.dir=${src.dir}/META-INF mkdist.disabled=true platform.active=default_platform -project.jcore-ee-logger=../jcore-ee-logger project.license=gpl30 -reference.jcore-ee-logger.dist=${project.jcore-ee-logger}/dist/jcore-ee-logger.jar run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/nbproject/project.xml b/nbproject/project.xml index c4336b2..feaeefa 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -14,15 +14,6 @@ ./lib/nblibraries.properties - - - jcore-ee-logger - jar - - dist - clean - dist - - + diff --git a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java index 72e024e..0a58bd4 100644 --- a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java +++ b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java @@ -20,6 +20,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.digest.Sha2Crypt; import org.mxchange.jcore.BaseFrameworkSystem; /** @@ -91,4 +93,59 @@ public class CustomerUtils extends BaseFrameworkSystem { // Found one return customerNumber; } + + /** + * Generates an unique access key. + * + * @param connection Connection instance + * @param customer Customer instance + * @return An unique access key + * @throws java.sql.SQLException If any SQL error occured + */ + public static String generateAccessKey (final Connection connection, final Customer customer) throws SQLException { + // Trace message + // TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: connection={0} - CALLED!", connection)); + // connection cannot be null + if (null == connection) { + // Abort here + throw new NullPointerException("connection is null"); //NOI18N + } + + // Prepare statement + PreparedStatement statement = connection.prepareStatement("SELECT `id` FROM `orders` WHERE `access_key` = ? LIMIT 1"); //NOI18N + + // Generate access keyy + String accessKey = null; + + // Default is found + boolean isFound = true; + + // Is the number used? + while (isFound) { + // Both number parts + String randString = String.format("%s:%s:%s", Long.toHexString(Math.round(Math.random() * 1000000)), connection, customer.getCustomerNumber()); + + // Generate new number + accessKey = Base64.encodeBase64String(Sha2Crypt.sha512Crypt(randString.getBytes()).getBytes()).substring(0, 100); + + // Debug message + // TODO: utils.getLogger().logDebug(MessageFormat.format("generateAccessKey: accessKey={0}", accessKey)); + // Insert customer number + statement.setString(1, accessKey); + + // Find it + statement.execute(); + + // Get result + ResultSet result = statement.getResultSet(); + + // Try to get next result + isFound = result.next(); + } + + // Trace message + // TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: accessKey={0} - EXIT!", accessKey)); + // Found one + return accessKey; + } }