From 119b5b63a4d508e4acf8ee5f67bd91df214a268f Mon Sep 17 00:00:00 2001 From: Alex Rudyy Date: Thu, 29 Jan 2015 09:30:58 +0000 Subject: QPID-6346: [Java Broker] Add UI for uploading of pem/der keys and certificates for non-java keystores/truststores into web management console git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1655560 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/resources/js/qpid/management/addStore.js | 1 + .../qpid/management/store/nonjavakeystore/add.js | 162 +++++++++++++++++++++ .../qpid/management/store/nonjavakeystore/show.js | 42 ++++++ .../qpid/management/store/nonjavatruststore/add.js | 162 +++++++++++++++++++++ .../management/store/nonjavatruststore/show.js | 66 +++++++++ .../java/resources/store/nonjavakeystore/add.html | 153 +++++++++++++++++++ .../java/resources/store/nonjavakeystore/show.html | 35 +++++ .../resources/store/nonjavatruststore/add.html | 67 +++++++++ .../resources/store/nonjavatruststore/show.html | 31 ++++ 9 files changed, 719 insertions(+) create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/add.js create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/show.js create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/add.js create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/show.js create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/add.html create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/show.html create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/add.html create mode 100644 qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/show.html (limited to 'qpid/java') diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addStore.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addStore.js index 98068f2376..c6ce218530 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addStore.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addStore.js @@ -90,6 +90,7 @@ define(["dojo/_base/lang", } this.storeName.set("disabled", effectiveData == null ? false : true); this.storeType.set("disabled", effectiveData == null ? false : true); + this.dialog.set("title", effectiveData == null ? "Add Key Store" : "Edit Key Store - " + effectiveData.name) this.dialog.show(); }, _initFields:function(data) diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/add.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/add.js new file mode 100644 index 0000000000..7488ad93d6 --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/add.js @@ -0,0 +1,162 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +define(["dojo/dom","dojo/query", "dojo/_base/array", "dijit/registry","qpid/common/util", "qpid/common/metadata"], + function (dom, query, array, registry, util, metadata) + { + var addKeyStore = + { + init: function() + { + }, + show: function(data) + { + var that=this; + util.parseHtmlIntoDiv(data.containerNode, "store/nonjavakeystore/add.html"); + + this.keyStoreOldBrowserWarning = dom.byId("addStore.oldBrowserWarning"); + this.addButton = data.parent.addButton; + this.containerNode = data.containerNode; + + if (!window.FileReader) + { + this.keyStoreOldBrowserWarning.innerHTML = "File upload requires a more recent browser with HTML5 support"; + this.keyStoreOldBrowserWarning.className = this.keyStoreOldBrowserWarning.className.replace("hidden", ""); + } + + this._initUploadFields("privateKey", "private key"); + this._initUploadFields("certificate", "certificate"); + this._initUploadFields("intermediateCertificate", "intermediate certificate"); + }, + _initUploadFields: function(fieldName, description) + { + var that=this; + this[fieldName] = registry.byId("addStore." + fieldName); + this[fieldName + "UploadFields"] = dom.byId("addStore." + fieldName +"UploadFields"); + this[fieldName + "UploadContainer"] = dom.byId("addStore." + fieldName + "UploadContainer"); + this[fieldName + "UploadStatusContainer"] = dom.byId("addStore." + fieldName + "UploadStatusContainer"); + this[fieldName + "File"] = registry.byId("addStore." + fieldName + "File"); + this[fieldName + "FileClearButton"] = registry.byId("addStore." + fieldName + "FileClearButton"); + + // field to submit + this[fieldName + "Url"] = registry.byId("addStore." + fieldName + "Url"); + + if (window.FileReader) + { + this[fieldName + "Reader"] = new FileReader(); + this[fieldName + "Reader"].onload = function(evt) {that._uploadFileComplete(evt, fieldName);}; + this[fieldName + "Reader"].onerror = function(ex) {console.error("Failed to load " + description + " file", ex);}; + this[fieldName + "File"].on("change", function(selected){that._fileChanged(selected, fieldName)}); + this[fieldName + "FileClearButton"].on("click", function(event){that._fileClearButtonClicked(event, fieldName)}); + } + else + { + // Fall back for IE8/9 which do not support FileReader + this[fieldName + "UploadFields"].style.display = "none"; + } + + this[fieldName].on("blur", function(){that._pathChanged(fieldName)}); + }, + _fileChanged: function (evt, fieldName) + { + var file = this[fieldName + "File"].domNode.children[0].files[0]; + + this[fieldName + "UploadContainer"].innerHTML = file.name; + this[fieldName + "UploadStatusContainer"].className = "loadingIcon"; + + console.log("Beginning to read file " + file.name + " for " + fieldName ); + this[fieldName + "Reader"].readAsDataURL(file); + }, + _uploadFileComplete: function(evt, fieldName) + { + var reader = evt.target; + var result = reader.result; + console.log(fieldName + " file read complete, contents " + result); + + this[fieldName + "UploadStatusContainer"].className = "loadedIcon"; + + this[fieldName].set("value", ""); + this[fieldName].setDisabled(true); + this[fieldName].set("required", false); + + this[fieldName + "FileClearButton"].setDisabled(false); + + this[fieldName + "Url"].set("value", result); + }, + _fileClearButtonClicked: function(event, fieldName) + { + this[fieldName + "File"].reset(); + this[fieldName + "UploadStatusContainer"].className = ""; + this[fieldName + "UploadContainer"].innerHTML = ""; + this[fieldName].set("required", true); + this[fieldName].setDisabled(false); + this[fieldName + "FileClearButton"].setDisabled(true); + + this[fieldName + "Url"].set("value", ""); + }, + _pathChanged: function(fieldName) + { + var serverPathValue = this[fieldName].get("value"); + this[fieldName + "Url"].set("value", serverPathValue); + }, + update: function(effectiveData) + { + var attributes = metadata.getMetaData("KeyStore", "NonJavaKeyStore").attributes; + var widgets = registry.findWidgets(this.containerNode); + var that=this; + array.forEach(widgets, function(item) + { + var name = item.id.replace("addStore.",""); + var val = effectiveData[name]; + item.set("value", val); + + if (name.indexOf("Url") != -1) + { + var isDataUrl = val && val.indexOf("data:") == 0; + var fieldName = name.substring(0, name.length - 3); + if (isDataUrl) + { + that[fieldName + "UploadStatusContainer"].className = "loadedIcon"; + that[fieldName + "UploadContainer"].innerHTML = "uploaded.jks"; + that[fieldName].setDisabled(true); + that[fieldName].set("required", false); + that[fieldName + "FileClearButton"].setDisabled(false); + } + else + { + that[fieldName].set("value", val); + } + } + }); + + } + }; + + try + { + addKeyStore.init(); + } + catch(e) + { + console.warn(e); + } + return addKeyStore; + } +); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/show.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/show.js new file mode 100644 index 0000000000..1985410e57 --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavakeystore/show.js @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +define(["qpid/common/util", "qpid/common/metadata", "dojo/domReady!"], + function (util, metadata) + { + + function NonJavaKeyStore(data) + { + this.fields = []; + var attributes = metadata.getMetaData("KeyStore", "NonJavaKeyStore").attributes; + for(var name in attributes) + { + this.fields.push(name); + } + util.buildUI(data.containerNode, data.parent, "store/nonjavakeystore/show.html", this.fields, this); + } + + NonJavaKeyStore.prototype.update = function(data) + { + util.updateUI(data, this.fields, this); + } + + return NonJavaKeyStore; + } +); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/add.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/add.js new file mode 100644 index 0000000000..2cff365f60 --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/add.js @@ -0,0 +1,162 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +define(["dojo/dom","dojo/query", "dojo/_base/array", "dijit/registry","qpid/common/util", "qpid/common/metadata"], + function (dom, query, array, registry, util, metadata) + { + var addKeyStore = + { + init: function() + { + }, + show: function(data) + { + var that=this; + util.parseHtmlIntoDiv(data.containerNode, "store/nonjavatruststore/add.html"); + + this.keyStoreOldBrowserWarning = dom.byId("addStore.oldBrowserWarning"); + this.addButton = data.parent.addButton; + this.containerNode = data.containerNode; + + if (!window.FileReader) + { + this.keyStoreOldBrowserWarning.innerHTML = "File upload requires a more recent browser with HTML5 support"; + this.keyStoreOldBrowserWarning.className = this.keyStoreOldBrowserWarning.className.replace("hidden", ""); + } + + this._initUploadFields("certificates", "certificates"); + }, + _initUploadFields: function(fieldName, description) + { + var that=this; + this[fieldName] = registry.byId("addStore." + fieldName); + this[fieldName + "UploadFields"] = dom.byId("addStore." + fieldName +"UploadFields"); + this[fieldName + "UploadContainer"] = dom.byId("addStore." + fieldName + "UploadContainer"); + this[fieldName + "UploadStatusContainer"] = dom.byId("addStore." + fieldName + "UploadStatusContainer"); + this[fieldName + "File"] = registry.byId("addStore." + fieldName + "File"); + this[fieldName + "FileClearButton"] = registry.byId("addStore." + fieldName + "FileClearButton"); + + // field to submit + this[fieldName + "Url"] = registry.byId("addStore." + fieldName + "Url"); + + if (window.FileReader) + { + this[fieldName + "Reader"] = new FileReader(); + this[fieldName + "Reader"].onload = function(evt) {that._uploadFileComplete(evt, fieldName);}; + this[fieldName + "Reader"].onerror = function(ex) {console.error("Failed to load " + description + " file", ex);}; + this[fieldName + "File"].on("change", function(selected){that._fileChanged(selected, fieldName)}); + this[fieldName + "FileClearButton"].on("click", function(event){that._fileClearButtonClicked(event, fieldName)}); + } + else + { + // Fall back for IE8/9 which do not support FileReader + this[fieldName + "UploadFields"].style.display = "none"; + } + + this[fieldName].on("blur", function(){that._pathChanged(fieldName)}); + }, + _fileChanged: function (evt, fieldName) + { + var file = this[fieldName + "File"].domNode.children[0].files[0]; + + this[fieldName + "UploadContainer"].innerHTML = file.name; + this[fieldName + "UploadStatusContainer"].className = "loadingIcon"; + + console.log("Beginning to read file " + file.name + " for " + fieldName ); + this[fieldName + "Reader"].readAsDataURL(file); + }, + _uploadFileComplete: function(evt, fieldName) + { + var reader = evt.target; + var result = reader.result; + console.log(fieldName + " file read complete, contents " + result); + + // it is not clear the purpose of this operation + //this.addButton.setDisabled(false); + this[fieldName + "UploadStatusContainer"].className = "loadedIcon"; + + this[fieldName].set("value", ""); + this[fieldName].setDisabled(true); + this[fieldName].set("required", false); + + this[fieldName + "FileClearButton"].setDisabled(false); + + this[fieldName + "Url"].set("value", result); + }, + _fileClearButtonClicked: function(event, fieldName) + { + this[fieldName + "File"].reset(); + this[fieldName + "UploadStatusContainer"].className = ""; + this[fieldName + "UploadContainer"].innerHTML = ""; + this[fieldName].set("required", true); + this[fieldName].setDisabled(false); + this[fieldName + "FileClearButton"].setDisabled(true); + + this[fieldName + "Url"].set("value", ""); + }, + _pathChanged: function(fieldName) + { + var serverPathValue = this[fieldName].get("value"); + this[fieldName + "Url"].set("value", serverPathValue); + }, + update: function(effectiveData) + { + var attributes = metadata.getMetaData("TrustStore", "NonJavaTrustStore").attributes; + var widgets = registry.findWidgets(this.containerNode); + var that=this; + array.forEach(widgets, function(item) + { + var name = item.id.replace("addStore.",""); + var val = effectiveData[name]; + item.set("value", val); + + if (name.indexOf("Url") != -1) + { + var isDataUrl = val && val.indexOf("data:") == 0; + var fieldName = name.substring(0, name.length - 3); + if (isDataUrl) + { + that[fieldName + "UploadStatusContainer"].className = "loadedIcon"; + that[fieldName + "UploadContainer"].innerHTML = "uploaded.jks"; + that[fieldName].setDisabled(true); + that[fieldName].set("required", false); + that[fieldName + "FileClearButton"].setDisabled(false); + } + else + { + that[fieldName].set("value", val); + } + } + }); + + } + }; + + try + { + addKeyStore.init(); + } + catch(e) + { + console.warn(e); + } + return addKeyStore; + } +); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/show.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/show.js new file mode 100644 index 0000000000..ac210ea4be --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/store/nonjavatruststore/show.js @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +define(["dojo/query", + "qpid/common/util", + "qpid/common/metadata", + "dojox/grid/DataGrid", + "qpid/common/UpdatableStore", + "qpid/management/UserPreferences", + "dojo/domReady!"], + function (query, util, metadata, DataGrid, UpdatableStore, UserPreferences) + { + + + function NonJavaTrustStore(data) + { + this.fields = []; + var attributes = metadata.getMetaData("TrustStore", "NonJavaTrustStore").attributes; + for(var name in attributes) + { + this.fields.push(name); + } + util.buildUI(data.containerNode, data.parent, "store/nonjavatruststore/show.html", this.fields, this); + var gridNode = query(".details", data.containerNode)[0] + this.detailsGrid = new UpdatableStore([], + gridNode, + [ + { name: 'Subject', field: 'SUBJECT_NAME', width: '25%' }, + { name: 'Issuer', field: 'ISSUER_NAME', width: '25%' }, + { name: 'Valid from', field: 'VALID_START', width: '25%', formatter: function(value){ return value ? UserPreferences.formatDateTime(value) : "";}}, + { name: 'Valid to', field: 'VALID_END', width: '25%', formatter: function(value){ return value ? UserPreferences.formatDateTime(value) : "";}} + ]); + } + + NonJavaTrustStore.prototype.update = function(data) + { + util.updateUI(data, this.fields, this); + var details = data.certificateDetails; + for(var i=0; i < details.length; i++) + { + details[i].id = details[i].SUBJECT_NAME + "_" + details[i].ISSUER_NAME + "_" + details[i].VALID_START + "_" + details[i].VALID_END; + } + this.detailsGrid.grid.beginUpdate(); + this.detailsGrid.update(details); + this.detailsGrid.grid.endUpdate(); + } + + return NonJavaTrustStore; + } +); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/add.html b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/add.html new file mode 100644 index 0000000000..5272537bdf --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/add.html @@ -0,0 +1,153 @@ + + + +
+ + +
+
Private Key URL or Path*:
+
+ + + + + + +
+ +
+ + +
+ +
+ + +
+
+
+
+
+ +
+
Certificate URL or Path*:
+
+ + + + + + +
+
+ + +
+ +
+ + +
+
+
+
+
+ +
+
Intermediate Certificate URL or Path:
+
+ + + + +
+ +
+
+ + +
+ +
+ + +
+
+
+
+ +
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/show.html b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/show.html new file mode 100644 index 0000000000..e0dd896d7b --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavakeystore/show.html @@ -0,0 +1,35 @@ + + +
+
+
Private Key:
+
+
+
+
Certificate:
+
+
+
+
Intermediate Certificate:
+
+
+
+
+ diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/add.html b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/add.html new file mode 100644 index 0000000000..9de25877cb --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/add.html @@ -0,0 +1,67 @@ + + + +
+ + +
+
Certificate URL or Path*:
+
+ + + + + + +
+
+ + +
+ +
+ + +
+
+
+
+
+ +
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/show.html b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/show.html new file mode 100644 index 0000000000..b45f457e41 --- /dev/null +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/store/nonjavatruststore/show.html @@ -0,0 +1,31 @@ + + +
+
+
Certificate:
+
+
+
+
+
+
+
+
+ -- cgit v1.2.1