WICKET-6154 move provider registration to factory, so the check for the cipher's availability is done once only
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c6f53a64 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c6f53a64 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c6f53a64 Branch: refs/heads/WICKET-6183 Commit: c6f53a649575ff0944e32f6a45896fbaa80bbf80 Parents: da37b30 Author: Sven Meier <[email protected]> Authored: Mon May 2 23:12:05 2016 +0200 Committer: Andrea Del Bene <[email protected]> Committed: Fri May 27 13:12:16 2016 +0200 ---------------------------------------------------------------------- .../crypt/KeyInSessionSunJceCryptFactory.java | 27 +++++++++++++++++--- .../apache/wicket/util/crypt/SunJceCrypt.java | 18 ------------- 2 files changed, 23 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/c6f53a64/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 5b3bae6..ceedcfc 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 @@ -16,6 +16,8 @@ */ package org.apache.wicket.core.util.crypt; +import java.security.Provider; +import java.security.Security; import java.util.UUID; import org.apache.wicket.MetaDataKey; @@ -26,11 +28,11 @@ import org.apache.wicket.util.crypt.SunJceCrypt; import org.apache.wicket.util.lang.Args; /** - * Crypt factory that produces {@link SunJceCrypt} instances based on http session-specific - * encryption key. This allows each user to have their own encryption key, hardening against CSRF + * Crypt factory that produces {@link SunJceCrypt} instances based on session-specific + * encryption key. This allows each user to have his own encryption key, hardening against CSRF * attacks. - * - * Note that the use of this crypt factory will result in an immediate creation of a http session + * <br> + * Note that the use of this crypt factory will result in an immediate creation of a session. * * @author igor.vaynberg */ @@ -61,6 +63,23 @@ public class KeyInSessionSunJceCryptFactory implements ICryptFactory public KeyInSessionSunJceCryptFactory(String cryptMethod) { this.cryptMethod = Args.notNull(cryptMethod, "Crypt method"); + + + if (Security.getProviders("Cipher." + cryptMethod).length > 0) + { + return; // we are good to go! + } + 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); + } } @Override http://git-wip-us.apache.org/repos/asf/wicket/blob/c6f53a64/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java b/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java index 934f586..778cfb0 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/crypt/SunJceCrypt.java @@ -18,8 +18,6 @@ package org.apache.wicket.util.crypt; import java.security.GeneralSecurityException; import java.security.NoSuchAlgorithmException; -import java.security.Provider; -import java.security.Security; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.InvalidKeySpecException; import java.security.spec.KeySpec; @@ -77,22 +75,6 @@ public class SunJceCrypt extends AbstractCrypt public SunJceCrypt(String cryptMethod) { this.cryptMethod = Args.notNull(cryptMethod, "Crypt method"); - - if (Security.getProviders("Cipher." + cryptMethod).length > 0) - { - return; // we are good to go! - } - 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); - } } /**
