|
| 1 | +package org.eclipse.core.pki.util; |
| 2 | + |
| 3 | +import java.nio.channels.Channels; |
| 4 | +import java.nio.channels.FileChannel; |
| 5 | +import java.nio.channels.FileLock; |
| 6 | +import java.nio.file.Files; |
| 7 | +import java.nio.file.Path; |
| 8 | +import java.nio.file.StandardOpenOption; |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.Arrays; |
| 11 | +import java.util.LinkedList; |
| 12 | +import java.util.List; |
| 13 | +import java.util.Properties; |
| 14 | +import java.util.Set; |
| 15 | + |
| 16 | +public enum DotPkiPropertiesRequired { |
| 17 | + CHECKER; |
| 18 | + List<String> list = get(); |
| 19 | + public boolean testFile(Path path) { |
| 20 | + Properties properties=new Properties(); |
| 21 | + System.out.println("DotPkiPropertiesRequired testFile:"+path.toString()); |
| 22 | + try { |
| 23 | + if (Files.exists(path)) { |
| 24 | + final FileChannel channel = FileChannel.open(path, StandardOpenOption.READ); |
| 25 | + final FileLock lock = channel.lock(0L, Long.MAX_VALUE, true); |
| 26 | + properties.load(Channels.newInputStream(channel)); |
| 27 | + Set<Object> keys=properties.keySet(); |
| 28 | + lock.close(); |
| 29 | + for ( Object key: keys ) { |
| 30 | + isProperty((String)key); |
| 31 | + } |
| 32 | + if ( list.isEmpty()) { |
| 33 | + //System.out.println("DotPkiPropertiesRequired All proeprties exist:"+list.size()); |
| 34 | + return true; |
| 35 | + } else { |
| 36 | + //System.out.println("DotPkiPropertiesRequired missing preoperties"); |
| 37 | + LogUtil.logWarning("Missing properies;"+ list.toString()); |
| 38 | + } |
| 39 | + } else { |
| 40 | + LogUtil.logWarning("DotPkiPropertiesRequired- NO PKI file detected"); |
| 41 | + } |
| 42 | + |
| 43 | + } catch (Exception e) { |
| 44 | + // TODO Auto-generated catch block |
| 45 | + e.printStackTrace(); |
| 46 | + } |
| 47 | + |
| 48 | + return false; |
| 49 | + } |
| 50 | + private void isProperty(String s) { |
| 51 | + if ( list.contains(s)) { |
| 52 | + list.remove(s); |
| 53 | + } |
| 54 | + |
| 55 | + } |
| 56 | + private List<String> get() { |
| 57 | + List<String> l = new LinkedList<String>(); |
| 58 | + l = Arrays.asList("javax.net.ssl.trustStore","javax.net.ssl.trustStoreType", |
| 59 | + "javax.net.ssl.trustStorePassword","javax.net.ssl.keyStoreType", |
| 60 | + "javax.net.ssl.keyStoreProvider","javax.net.ssl.cfgFileLocation", |
| 61 | + "javax.net.ssl.keyStorePassword", "javax.net.ssl.keyStore"); |
| 62 | + List<String> list = new ArrayList(l); |
| 63 | + return list; |
| 64 | + } |
| 65 | +} |
0 commit comments