[utilities COMMIT] in /java-support/trunk/src: main/java/net/shibboleth/utilities/java/support/security/DataSealer.ja...
noreply at shibboleth.net
noreply at shibboleth.net
Sun Jun 22 02:13:23 EDT 2014
Author: tzeller
Date: Sun Jun 22 02:13:23 2014
New Revision: 605
URL: http://svn.shibboleth.net/view/utilities?rev=605&view=rev
Log:
Make the DataSealer consume a keystore Resource rather than a String path.
Modified:
java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java
java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java
Modified: java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java?rev=605&r1=604&r2=605&view=diff
==============================================================================
--- java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java (original)
+++ java-support/trunk/src/main/java/net/shibboleth/utilities/java/support/security/DataSealer.java Sun Jun 22 02:13:23 2014
@@ -21,7 +21,6 @@
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
@@ -44,6 +43,7 @@
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resource.Resource;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESEngine;
@@ -72,8 +72,8 @@
/** Type of keystore to use for access to keys. */
@NonnullAfterInit private String keystoreType;
- /** Path to keystore. */
- @NonnullAfterInit private String keystorePath;
+ /** Keystore resource. */
+ @NonnullAfterInit private Resource keystoreResource;
/** Password for keystore. */
@NonnullAfterInit private String keystorePassword;
@@ -94,7 +94,7 @@
try {
try {
Constraint.isNotNull(keystoreType, "Keystore type cannot be null");
- Constraint.isNotNull(keystorePath, "Keystore path cannot be null");
+ Constraint.isNotNull(keystoreResource, "Keystore resource cannot be null");
Constraint.isNotNull(keystorePassword, "Keystore password cannot be null");
Constraint.isNotNull(cipherKeyAlias, "Cipher key alias cannot be null");
Constraint.isNotNull(cipherKeyPassword, "Cipher key password cannot be null");
@@ -148,12 +148,12 @@
}
/**
- * Returns the keystore path.
- *
- * @return the keystore path
- */
- @NonnullAfterInit public String getKeystorePath() {
- return keystorePath;
+ * Returns the keystore resource.
+ *
+ * @return the keystore keystoreResource
+ */
+ @NonnullAfterInit public Resource getKeystoreResource() {
+ return keystoreResource;
}
/**
@@ -206,14 +206,14 @@
}
/**
- * Sets the keystore path.
- *
- * @param path the keystore path to set
- */
- public void setKeystorePath(@Nonnull @NotEmpty final String path) {
- ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
-
- keystorePath = Constraint.isNotNull(StringSupport.trimOrNull(path), "Keystore path cannot be null or empty");
+ * Sets the keystore resource.
+ *
+ * @param resource the keystore resource to set
+ */
+ public void setKeystoreResource(@Nonnull @NotEmpty final Resource resource) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+ keystoreResource = Constraint.isNotNull(resource, "Keystore resource cannot be null");
}
/**
@@ -459,15 +459,8 @@
throws GeneralSecurityException, IOException {
final KeyStore ks = KeyStore.getInstance(keystoreType);
- FileInputStream fis = null;
- try {
- fis = new java.io.FileInputStream(keystorePath);
- ks.load(fis, keystorePassword.toCharArray());
- } finally {
- if (fis != null) {
- fis.close();
- }
- }
+
+ ks.load(keystoreResource.getInputStream(), keystorePassword.toCharArray());
Key loadedKey = ks.getKey(alias, cipherKeyPassword.toCharArray());
if (loadedKey == null) {
Modified: java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java
URL: http://svn.shibboleth.net/view/utilities/java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java?rev=605&r1=604&r2=605&view=diff
==============================================================================
--- java-support/trunk/src/test/java/net/shibboleth/utilities/java/support/security/DataSealerTest.java (original)
[... 113 lines stripped ...]
More information about the commits
mailing list