|
@@ -13,15 +13,15 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.security.authentication.util;
|
|
|
|
|
|
-import org.apache.hadoop.thirdparty.com.google.common.base.Charsets;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
|
|
|
-import org.apache.hadoop.security.authentication.util.SignerSecretProvider;
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
import java.io.*;
|
|
|
-import java.nio.charset.Charset;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.Properties;
|
|
|
|
|
|
/**
|
|
@@ -43,29 +43,24 @@ public class FileSignerSecretProvider extends SignerSecretProvider {
|
|
|
String signatureSecretFile = config.getProperty(
|
|
|
AuthenticationFilter.SIGNATURE_SECRET_FILE, null);
|
|
|
|
|
|
- Reader reader = null;
|
|
|
if (signatureSecretFile != null) {
|
|
|
- try {
|
|
|
+ try (Reader reader = new InputStreamReader(Files.newInputStream(
|
|
|
+ Paths.get(signatureSecretFile)), StandardCharsets.UTF_8)) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- reader = new InputStreamReader(
|
|
|
- new FileInputStream(signatureSecretFile), Charsets.UTF_8);
|
|
|
int c = reader.read();
|
|
|
while (c > -1) {
|
|
|
sb.append((char) c);
|
|
|
c = reader.read();
|
|
|
}
|
|
|
- secret = sb.toString().getBytes(Charset.forName("UTF-8"));
|
|
|
+
|
|
|
+ secret = sb.toString().getBytes(StandardCharsets.UTF_8);
|
|
|
+ if (secret.length == 0) {
|
|
|
+ throw new RuntimeException("No secret in signature secret file: "
|
|
|
+ + signatureSecretFile);
|
|
|
+ }
|
|
|
} catch (IOException ex) {
|
|
|
throw new RuntimeException("Could not read signature secret file: " +
|
|
|
signatureSecretFile);
|
|
|
- } finally {
|
|
|
- if (reader != null) {
|
|
|
- try {
|
|
|
- reader.close();
|
|
|
- } catch (IOException e) {
|
|
|
- // nothing to do
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|