Remove bundle extension (de)serializers
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / SslKeyStore.java
index 3868e734afccd7333dd8da87e61f5863de235a31..e4efea9f765dcfdcfc58cc46537148cba747b863 100644 (file)
@@ -8,8 +8,15 @@
 
 package org.opendaylight.openflowjava.protocol.impl.core;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Class for storing keys
  *
@@ -17,32 +24,43 @@ import java.io.InputStream;
  */
 public final class SslKeyStore {
 
-    private static final String filename = "/key.bin";
+    private static final Logger LOG = LoggerFactory.getLogger(SslKeyStore.class);
+
+    private SslKeyStore() {
+        throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
+    }
 
     /**
-     * InputStream instance of key
+     * InputStream instance of key - key location is on classpath
+     * @param filename keystore location
+     * @param pathType keystore location type - "classpath" or "path"
      *
      * @return key as InputStream
      */
-    public static InputStream asInputStream() {
-        InputStream in = SslKeyStore.class.getResourceAsStream(filename);
-        if (in == null) {
-            throw new IllegalStateException("KeyStore file not found: " + filename);
+    public static InputStream asInputStream(String filename, PathType pathType) {
+        InputStream in;
+        switch (pathType) {
+        case CLASSPATH:
+            in = SslKeyStore.class.getResourceAsStream(filename);
+            if (in == null) {
+                throw new IllegalStateException("KeyStore file not found: "
+                        + filename);
+            }
+            break;
+        case PATH:
+            LOG.debug("Current dir using System:"
+                    + System.getProperty("user.dir"));
+            File keystorefile = new File(filename);
+            try {
+                in = new FileInputStream(keystorefile);
+            } catch (FileNotFoundException e) {
+                throw new IllegalStateException("KeyStore file not found: "
+                        + filename,e);
+            }
+            break;
+        default:
+            throw new IllegalArgumentException("Unknown path type: " + pathType);
         }
         return in;
     }
-
-    /**
-     * @return certificate password as char[]
-     */
-    public static char[] getCertificatePassword() {
-        return "secret".toCharArray();
-    }
-
-    /**
-     * @return KeyStore password as char[]
-     */
-    public static char[] getKeyStorePassword() {
-        return "secret".toCharArray();
-    }
-}
\ No newline at end of file
+}