📄 extensionstore.java
字号:
URL storeURL = null;
try {
String sslxVersion = System.getProperty("sslexplorer.forceVersion", ContextHolder.getContext().getVersion()
.toString());
String location = System.getProperty("sslexplorer.downloadableApplicationStore.location",
"http://3sp.com/getApplicationStoreXML.do?version=" + sslxVersion);
storeURL = new URL(location);
} catch (MalformedURLException murle) {
try {
storeURL = new File(System.getProperty("sslexplorer.downloadableApplicationStore.location")).toURL();
} catch (MalformedURLException e) {
log
.error("Invalid downloadable extension store location specified in system property sslexplorer.downloadableApplicationStore.location, '"
+ System.getProperty("sslexplorer.downloadableApplicationStore.location")
+ "'. Must be either a URL or the file path of the store descriptor file.");
}
}
if (storeURL != null) {
if (log.isInfoEnabled())
log.info("Loading extension store descriptor from " + storeURL.toExternalForm());
downloadableExtensions = new ExtensionStoreDescriptor(storeURL);
downloadableExtensionsLastUpdated = new GregorianCalendar();
// Check for updates on any currently installed extensions
for (Iterator i = downloadableExtensions.getExtensionBundles().iterator(); i.hasNext();) {
ExtensionBundle app = (ExtensionBundle) i.next();
try {
ExtensionBundle installedApp = getExtensionBundle(app.getId());
if (installedApp.getVersion().compareTo(app.getVersion()) < 0) {
if (log.isInfoEnabled())
log.info("Update found for extenions " + app.getId());
installedApp.setType(ExtensionBundle.TYPE_UPDATEABLE);
}
} catch (Exception e) {
// / Not installed
}
}
if (log.isInfoEnabled())
log.info("Extension store descriptor loaded from " + storeURL.toExternalForm());
}
}
return downloadableExtensions;
}
public void deregisterApplicationPermissions() {
Util.toDo("Deregister application permissions");
}
private synchronized List reloadAll() throws Exception {
CoreMessageResources resources = CoreServlet.getServlet().getExtensionStoreResources();
for (Iterator i = extensionBundles.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
for (Iterator j = ((ExtensionBundle) entry.getValue()).iterator(); j.hasNext();) {
ExtensionDescriptor app = (ExtensionDescriptor) j.next();
List toRemove = new ArrayList();
for (Iterator ki = resources.keys(); ki.hasNext();) {
String key = (String) ki.next();
if (key.startsWith("application." + app.getId() + ".")) {
toRemove.add(key);
}
}
for (Iterator ki = toRemove.iterator(); ki.hasNext();) {
resources.removeKey((String) ki.next());
}
}
}
extensionBundles.clear();
extensionBundlesList.clear();
CoreServlet.getServlet().getPluginManager().removeAllPluginDefinitions();
if (!agentLocation.exists()) {
log.warn("SSL-Explorer Agent is not available so applications will not be loaded");
if (log.isDebugEnabled())
log.debug(agentLocation.getAbsolutePath());
return null;
}
return loadAll();
}
private List loadAll() throws Exception {
List errors = new ArrayList();
try {
File f = new File(agentLocation, "extension.xml");
if (!f.exists()) {
f = new File(agentLocation, "application.xml");
if (f.exists()) {
log.warn("DEPRECATED. Application descriptor file " + f
+ " is no longer used, please use extension.xml instead.");
}
}
ExtensionBundle vpnClientBundle = new ExtensionBundle(f);
vpnClientBundle.load();
if (vpnClientBundle.size() > 0) {
agentDescriptor = (ExtensionDescriptor) vpnClientBundle.get(0);
} else {
throw new Exception("Extension descriptor not found at " + f.getAbsolutePath() + ".");
}
} catch (Exception ex) {
log.error("Failed to load SSL-Explorer Agent.", ex);
// Just ignore this so that dev environment does not fail
}
if (log.isInfoEnabled())
log.info("Loading applications");
if (!basedir.exists()) {
basedir.mkdirs();
}
File[] files = basedir.listFiles();
for (int i = 0; i < files.length; i++) {
try {
loadDir(files[i]);
} catch (UnknownExtensionTypeException ex) {
unknownExtensions.add(ex.getBundle());
} catch (Exception ex) {
log.error("Failed to load " + files[i].getName(), ex);
errors.add(ex);
}
}
// Load any additional descriptors
StringTokenizer t = new StringTokenizer(System.getProperty("sslexplorer.additionalDescriptors", ""), ",");
while (t.hasMoreTokens()) {
File f = new File(t.nextToken());
if (f.exists()) {
loadBundle(f);
}
}
Collections.sort(extensionBundlesList);
return errors;
}
public void loadUnknownExtensions() {
/**
* TODO: This seems like a bit of a hack. Is there a better way to do
* this BPS?
*
* Now retry any bundles that failed as further extension types may have
* been added.
*/
log.info("Trying to load unknown extensions");
ArrayList loaded = new ArrayList();
for (Iterator it = unknownExtensions.iterator(); it.hasNext();) {
ExtensionBundle bundle = (ExtensionBundle) it.next();
try {
loadBundle(bundle);
loaded.add(bundle);
} catch (Exception ex) {
log.error("Failed to load extension bundle " + bundle.getName(), ex);
}
}
unknownExtensions.removeAll(loaded);
}
private void loadDir(File dir) throws JDOMException, IOException, UnknownExtensionTypeException {
if (dir.isDirectory()) {
File[] descriptors = dir.listFiles(new FilenameFilter() {
public boolean accept(File f, String filename) {
return filename.equals("application.xml") || filename.equals("extension.xml");
}
});
if (descriptors.length == 0) {
log.warn("Extension folder " + dir.getName() + " found with no extension.xml (or the deprecated application.xml)");
return;
} else if (descriptors.length > 1) {
// Should never happen if its case sensitive
log
.warn("Extension folder "
+ dir.getName()
+ " found with too many extension.xml (or deprecated application.xml) files. Please remove one. This extensions will be ignored.");
return;
}
if (log.isInfoEnabled())
log.info("Found application bundle " + dir.getName());
if (descriptors[0].getName().equals("application.xml")) {
log.warn("DEPRECATED. Application descriptor file " + descriptors[0]
+ " is no longer used, please use extension.xml instead.");
}
loadBundle(descriptors[0]);
}
}
private void loadBundle(File descriptor) throws JDOMException, IOException, UnknownExtensionTypeException {
ExtensionBundle bundle = new ExtensionBundle(descriptor);
loadBundle(bundle);
}
private void loadBundle(ExtensionBundle bundle) throws JDOMException, IOException, UnknownExtensionTypeException {
bundle.load();
// TODO JB would be nice to have it intrenationalised.
bundle.setCategory(ExtensionStore.INSTALLED_CATEGORY);
for (Iterator it = bundle.iterator(); it.hasNext();) {
ExtensionDescriptor app = (ExtensionDescriptor) it.next();
if (log.isInfoEnabled())
log.info(app.getName() + " has been loaded");
}
ExtensionBundle oldBundle = (ExtensionBundle) extensionBundles.get(bundle.getId());
extensionBundlesList.remove(oldBundle);
extensionBundles.put(bundle.getId(), bundle);
extensionBundlesList.add(bundle);
}
public List getExtensionBundles() {
return extensionBundlesList;
}
public boolean isExtensionBundleLoaded(String name) {
return extensionBundles.containsKey(name);
}
public ExtensionDescriptor getAgentApplication() {
return agentDescriptor;
}
public void addAgentExtension(AgentExtensionDefinition agent) {
agentExtensions.put(agent.getName(), agent);
}
public Element getAgentDescriptor(User user, Properties properties) throws IOException {
Element el = getAgentApplication().getDescriptorElement();
Element agents = new Element("agents");
AgentExtensionDefinition def;
String extensionClasses = "";
for (Iterator it = agentExtensions.values().iterator(); it.hasNext();) {
def = (AgentExtensionDefinition) it.next();
Element a = new Element("agent");
Plugin plugin = CoreServlet.getServlet().getPluginManager().getPlugin(def.getPlugin());
if (plugin != null && plugin instanceof AgentVerifier) {
if (!((AgentVerifier) plugin).verifyAccess(def.getName(), user, properties))
continue;
}
a.setAttribute("class", def.getClassName());
a.setAttribute("name", def.getName());
extensionClasses += (extensionClasses.equals("") ? def.getClassName() : "," + def.getClassName());
for (Iterator i = def.getJVMArguments().iterator(); i.hasNext();) {
a.addContent(new Element("jvm").setText((String) i.next()));
}
if (def.getDescriptor().getFiles().size() > 0) {
Element b = new Element("files");
for (Iterator it2 = def.getDescriptor().getFiles().iterator(); it2.hasNext();) {
Element c = new Element("file");
c.setText((String) it2.next());
File entry = new File(def.getDescriptor().getApplicationBundle().getBaseDir(), c.getText());
if (!entry.exists()) {
if ("true".equals(System.getProperty("sslexplorer.useDevConfig", "false"))) {
log.warn("File specified in extension descriptor "
+ def.getDescriptor().getApplicationBundle().getFile().getAbsolutePath()
+ " does not exist. As SSL-Explorer is running in Dev. mode, this will be ignored.");
} else {
throw new IOException("File '" + c.getText()
+ "' specified in Agent extension definition does not exist! "
+ entry.getAbsolutePath());
}
} else {
c.setAttribute("checksum", String.valueOf(CoreUtil.generateChecksum(entry)));
}
c.setAttribute("size", String.valueOf(entry.length()));
b.addContent(c);
}
a.addContent(b);
}
if (def.getClassPath().size() > 0) {
Element b = new Element("classpath");
for (Iterator it2 = def.getClassPath().iterator(); it2.hasNext();) {
Element c = new Element("jar");
c.setText((String) it2.next());
File entry = new File(def.getDescriptor().getApplicationBundle().getBaseDir(), c.getText());
if (!entry.exists()) {
if ("true".equals(System.getProperty("sslexplorer.useDevConfig", "false"))) {
log.warn("File specified in extension descriptor "
+ def.getDescriptor().getApplicationBundle().getFile().getAbsolutePath()
+ " does not exist. As SSL-Explorer is running in Dev. mode, this will be ignored.");
} else {
throw new IOException("Jar '" + c.getText()
+ "' specified in Agent extension definition does not exist! "
+ entry.getAbsolutePath());
}
} else {
c.setAttribute("checksum", String.valueOf(CoreUtil.generateChecksum(entry)));
}
c.setAttribute("size", String.valueOf(entry.length()));
b.addContent(c);
}
a.addContent(b);
}
agents.addContent(a);
}
// Add the agents element to the root descriptor
if (agents.getChildren().size() > 0) {
agents.setAttribute("extensionClasses", extensionClasses);
el.addContent(0, agents);
}
return el;
}
public ExtensionDescriptor getExtensionDescriptor(String id) throws Exception {
for (Iterator i = extensionBundlesList.iterator(); i.hasNext();) {
ExtensionBundle bundle = (ExtensionBundle) i.next();
ExtensionDescriptor app = bundle.getApplicationDescriptor(id);
if (app != null && app instanceof ExtensionDescriptor) {
return (ExtensionDescriptor) app;
}
}
return null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -