You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2017/10/29 05:23:12 UTC
[2/5] incubator-guacamole-client git commit: GUACAMOLE-362: Move
close to finally block.
GUACAMOLE-362: Move close to finally block.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/91e57027
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/91e57027
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/91e57027
Branch: refs/heads/master
Commit: 91e570276889bd3b83e8420be7604ee7817a3965
Parents: 5c0c823
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Oct 28 14:04:13 2017 -0400
Committer: Nick Couchman <vn...@apache.org>
Committed: Sat Oct 28 14:04:13 2017 -0400
----------------------------------------------------------------------
.../cas/conf/PrivateKeyGuacamoleProperty.java | 51 +++++++++++---------
1 file changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/91e57027/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
----------------------------------------------------------------------
diff --git a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
index 78da89e..d71ae1a 100644
--- a/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
+++ b/extensions/guacamole-auth-cas/src/main/java/org/apache/guacamole/auth/cas/conf/PrivateKeyGuacamoleProperty.java
@@ -49,39 +49,44 @@ public abstract class PrivateKeyGuacamoleProperty implements GuacamoleProperty<P
if (value == null || value.isEmpty())
return null;
+ FileInputStream keyStreamIn = null;
+
try {
+ try {
- // Open and read the file specified in the configuration.
- File keyFile = new File(value);
- FileInputStream keyStreamIn = new FileInputStream(keyFile);
- ByteArrayOutputStream keyStreamOut = new ByteArrayOutputStream();
- byte[] keyBuffer = new byte[1024];
+ // Open and read the file specified in the configuration.
+ File keyFile = new File(value);
+ keyStreamIn = new FileInputStream(keyFile);
+ ByteArrayOutputStream keyStreamOut = new ByteArrayOutputStream();
+ byte[] keyBuffer = new byte[1024];
- for (int readBytes; (readBytes = keyStreamIn.read(keyBuffer)) != -1;)
- keyStreamOut.write(keyBuffer, 0, readBytes);
+ for (int readBytes; (readBytes = keyStreamIn.read(keyBuffer)) != -1;)
+ keyStreamOut.write(keyBuffer, 0, readBytes);
- keyStreamIn.close();
- final byte[] keyBytes = keyStreamOut.toByteArray();
+ final byte[] keyBytes = keyStreamOut.toByteArray();
- // Set up decryption infrastructure
- KeyFactory keyFactory = KeyFactory.getInstance("RSA");
- KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
- return keyFactory.generatePrivate(keySpec);
+ // Set up decryption infrastructure
+ KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+ KeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
+ return keyFactory.generatePrivate(keySpec);
- }
- catch (FileNotFoundException e) {
- throw new GuacamoleServerException("Could not find the specified key file.", e);
+ }
+ catch (FileNotFoundException e) {
+ throw new GuacamoleServerException("Could not find the specified key file.", e);
+ }
+ catch (NoSuchAlgorithmException e) {
+ throw new GuacamoleServerException("RSA algorithm is not available.", e);
+ }
+ catch (InvalidKeySpecException e) {
+ throw new GuacamoleServerException("Key is not in expected PKCS8 encoding.", e);
+ }
+ finally {
+ keyStreamIn.close();
+ }
}
catch (IOException e) {
throw new GuacamoleServerException("Could not read in the specified key file.", e);
}
- catch (NoSuchAlgorithmException e) {
- throw new GuacamoleServerException("RSA algorithm is not available.", e);
- }
- catch (InvalidKeySpecException e) {
- throw new GuacamoleServerException("Key is not in expected PKCS8 encoding.", e);
- }
-
}
}