Repository: wicket Updated Branches: refs/heads/WICKET-6154-jce-crypt-performance 051e294ab -> 21bd7a421
WICKET-6154 Performance bottleneck when using KeyInSessionSunJceCryptFactory Reduce the complexity of the method by removing a conditional branch that is not really needed. Note: Security#getProviders() javadoc states that it may return null but the implementation (and the years in usage) show that it actually returns empty array Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/a338eb9d Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/a338eb9d Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/a338eb9d Branch: refs/heads/WICKET-6154-jce-crypt-performance Commit: a338eb9df15f3609d3fab78fc2d51cf1afacbb10 Parents: 051e294 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Sun May 22 10:44:49 2016 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Sun May 22 10:44:49 2016 +0200 ---------------------------------------------------------------------- .../crypt/KeyInSessionSunJceCryptFactory.java | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/a338eb9d/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java b/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java index ceedcfc..ce3037e 100644 --- a/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java +++ b/wicket-core/src/main/java/org/apache/wicket/core/util/crypt/KeyInSessionSunJceCryptFactory.java @@ -64,21 +64,20 @@ public class KeyInSessionSunJceCryptFactory implements ICryptFactory { this.cryptMethod = Args.notNull(cryptMethod, "Crypt method"); - - if (Security.getProviders("Cipher." + cryptMethod).length > 0) - { - return; // we are good to go! - } - try + if (Security.getProviders("Cipher." + cryptMethod).length == 0) { - // Initialize and add a security provider required for encryption - final Class<?> clazz = Class.forName("com.sun.crypto.provider.SunJCE"); + try + { + // Initialize and add a security provider required for encryption + final Class<?> clazz = Class.forName("com.sun.crypto.provider.SunJCE"); - Security.addProvider((Provider)clazz.newInstance()); - } - catch (Exception ex) - { - throw new RuntimeException("Unable to load SunJCE service provider", ex); + final Provider provider = (Provider) clazz.newInstance(); + Security.addProvider(provider); + } + catch (Exception ex) + { + throw new RuntimeException("Unable to load SunJCE service provider", ex); + } } }
