Showing
1 changed file
with
20 additions
and
7 deletions
... | ... | @@ -78,7 +78,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { |
78 | 78 | |
79 | 79 | @Getter |
80 | 80 | @Value("${transport.lwm2m.security.key_store:}") |
81 | - private String keyStorePathFile; | |
81 | + private String keyStoreFilePath; | |
82 | 82 | |
83 | 83 | @Getter |
84 | 84 | @Setter |
... | ... | @@ -141,14 +141,27 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { |
141 | 141 | public void init() { |
142 | 142 | URI uri = null; |
143 | 143 | try { |
144 | - uri = Resources.getResource(keyStorePathFile).toURI(); | |
145 | - log.info("URI: {}", uri); | |
146 | - File keyStoreFile = new File(uri); | |
147 | - InputStream inKeyStore = new FileInputStream(keyStoreFile); | |
144 | + InputStream keyStoreInputStream; | |
145 | + File keyStoreFile = new File(keyStoreFilePath); | |
146 | + if (keyStoreFile.exists()) { | |
147 | + log.info("Reading key store from file {}", keyStoreFilePath); | |
148 | + keyStoreInputStream = new FileInputStream(keyStoreFile); | |
149 | + } else { | |
150 | + InputStream classPathStream = this.getClass().getClassLoader().getResourceAsStream(keyStoreFilePath); | |
151 | + if (classPathStream != null) { | |
152 | + log.info("Reading key store from class path {}", keyStoreFilePath); | |
153 | + keyStoreInputStream = classPathStream; | |
154 | + } else { | |
155 | + uri = Resources.getResource(keyStoreFilePath).toURI(); | |
156 | + log.info("Reading key store from URI {}", keyStoreFilePath); | |
157 | + keyStoreInputStream = new FileInputStream(new File(uri)); | |
158 | + } | |
159 | + } | |
148 | 160 | keyStoreValue = KeyStore.getInstance(keyStoreType); |
149 | - keyStoreValue.load(inKeyStore, keyStorePassword == null ? null : keyStorePassword.toCharArray()); | |
161 | + keyStoreValue.load(keyStoreInputStream, keyStorePassword == null ? null : keyStorePassword.toCharArray()); | |
150 | 162 | } catch (Exception e) { |
151 | - log.info("Unable to lookup LwM2M keystore. Reason: {}, {}" , uri, e.getMessage()); | |
163 | + log.info("Unable to lookup LwM2M keystore. Reason: {}, {}", uri, e.getMessage()); | |
152 | 164 | } |
153 | 165 | } |
166 | + | |
154 | 167 | } | ... | ... |