diff options
author | Robert Godfrey <rgodfrey@apache.org> | 2014-09-08 12:36:23 +0000 |
---|---|---|
committer | Robert Godfrey <rgodfrey@apache.org> | 2014-09-08 12:36:23 +0000 |
commit | ec7ff2d475f27bd884c29634c0bad34e2838a1f9 (patch) | |
tree | d933fc133a09b70f1d99f87f82e0de391d5b1f78 | |
parent | e1fea178b285b0ce8c302443f3a8cc69950eca36 (diff) | |
download | qpid-python-ec7ff2d475f27bd884c29634c0bad34e2838a1f9.tar.gz |
QPID-6068 : Merged revisions 1622677, 1622747, 1622768 from trunk to 0.30
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.30@1623378 13f79535-47bb-0310-9956-ffa450edef68
13 files changed, 297 insertions, 154 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractClientAuthCapablePortWithAuthProvider.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractClientAuthCapablePortWithAuthProvider.java new file mode 100644 index 0000000000..0871fbb0d9 --- /dev/null +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractClientAuthCapablePortWithAuthProvider.java @@ -0,0 +1,102 @@ +/* + * 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. + */ +package org.apache.qpid.server.model.port; + +import java.util.Map; +import java.util.Set; + +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ManagedAttributeField; + +abstract public class AbstractClientAuthCapablePortWithAuthProvider<X extends AbstractClientAuthCapablePortWithAuthProvider<X>> extends AbstractPortWithAuthProvider<X> + implements ClientAuthCapablePort<X> +{ + public static final String DEFAULT_AMQP_NEED_CLIENT_AUTH = "false"; + public static final String DEFAULT_AMQP_WANT_CLIENT_AUTH = "false"; + + @ManagedAttributeField + private boolean _needClientAuth; + + @ManagedAttributeField + private boolean _wantClientAuth; + + public AbstractClientAuthCapablePortWithAuthProvider(final Map<String, Object> attributes, + final Broker<?> broker) + { + super(attributes, broker); + } + + @Override + public boolean getNeedClientAuth() + { + return _needClientAuth; + } + + @Override + public boolean getWantClientAuth() + { + return _wantClientAuth; + } + + @Override + public void onValidate() + { + super.onValidate(); + boolean useClientAuth = getNeedClientAuth() || getWantClientAuth(); + + if(useClientAuth && (getTrustStores() == null || getTrustStores().isEmpty())) + { + throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust stores configured."); + } + + boolean useTLSTransport = isUsingTLSTransport(); + if(useClientAuth && !useTLSTransport) + { + throw new IllegalConfigurationException( + "Can't create port which requests SSL client certificates but doesn't use SSL transport."); + } + } + + @Override + protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) + { + super.validateChange(proxyForValidation, changedAttributes); + ClientAuthCapablePort<?> updated = (ClientAuthCapablePort<?>)proxyForValidation; + + boolean requiresCertificate = updated.getNeedClientAuth() || updated.getWantClientAuth(); + + boolean usesSsl = isUsingTLSTransport(updated.getTransports()); + if (usesSsl) + { + if ((updated.getTrustStores() == null || updated.getTrustStores().isEmpty() ) && requiresCertificate) + { + throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust store configured."); + } + } + else + { + if (requiresCertificate) + { + throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but doesn't use SSL transport."); + } + } + } +} diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java index c90215f141..30b97e9e01 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPort.java @@ -149,7 +149,7 @@ abstract public class AbstractPort<X extends AbstractPort<X>> extends AbstractCo { super.onValidate(); - boolean useTLSTransport = getTransports().contains(Transport.SSL) || getTransports().contains(Transport.WSS); + boolean useTLSTransport = isUsingTLSTransport(); if(useTLSTransport && getKeyStore() == null) { @@ -175,6 +175,28 @@ abstract public class AbstractPort<X extends AbstractPort<X>> extends AbstractCo } } + protected final boolean isUsingTLSTransport() + { + return isUsingTLSTransport(getTransports()); + } + + protected final boolean isUsingTLSTransport(final Collection<Transport> transports) + { + boolean usesTLS = false; + if(transports != null) + { + for (Transport transport : transports) + { + if (transport.isSecure()) + { + usesTLS = true; + break; + } + } + } + return usesTLS; + } + @Override protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) { @@ -215,7 +237,7 @@ abstract public class AbstractPort<X extends AbstractPort<X>> extends AbstractCo Collection<Protocol> protocols = updated.getProtocols(); - boolean usesSsl = transports != null && transports.contains(Transport.SSL); + boolean usesSsl = isUsingTLSTransport(transports); if (usesSsl) { if (updated.getKeyStore() == null) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPortWithAuthProvider.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPortWithAuthProvider.java index a959709657..87d5889727 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPortWithAuthProvider.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AbstractPortWithAuthProvider.java @@ -21,46 +21,22 @@ package org.apache.qpid.server.model.port; import java.util.Map; -import java.util.Set; -import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.ManagedAttributeField; -import org.apache.qpid.server.model.Port; -import org.apache.qpid.server.model.Transport; abstract public class AbstractPortWithAuthProvider<X extends AbstractPortWithAuthProvider<X>> extends AbstractPort<X> { - public static final String DEFAULT_AMQP_NEED_CLIENT_AUTH = "false"; - public static final String DEFAULT_AMQP_WANT_CLIENT_AUTH = "false"; - @ManagedAttributeField private AuthenticationProvider _authenticationProvider; - @ManagedAttributeField - private boolean _needClientAuth; - - @ManagedAttributeField - private boolean _wantClientAuth; - public AbstractPortWithAuthProvider(final Map<String, Object> attributes, final Broker<?> broker) { super(attributes, broker); } - public boolean getNeedClientAuth() - { - return _needClientAuth; - } - - public boolean getWantClientAuth() - { - return _wantClientAuth; - } - public AuthenticationProvider getAuthenticationProvider() { Broker<?> broker = getParent(Broker.class); @@ -70,55 +46,4 @@ abstract public class AbstractPortWithAuthProvider<X extends AbstractPortWithAut } return _authenticationProvider; } - - @Override - public void onValidate() - { - super.onValidate(); - boolean useClientAuth = getNeedClientAuth() || getWantClientAuth(); - - if(useClientAuth && (getTrustStores() == null || getTrustStores().isEmpty())) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust stores configured."); - } - - boolean useTLSTransport = getTransports().contains(Transport.SSL) || getTransports().contains(Transport.WSS); - if(useClientAuth && !useTLSTransport) - { - throw new IllegalConfigurationException( - "Can't create port which requests SSL client certificates but doesn't use SSL transport."); - } - - } - - - @Override - protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) - { - super.validateChange(proxyForValidation, changedAttributes); - Port<?> updated = (Port<?>)proxyForValidation; - - boolean needClientCertificate = (Boolean) updated.getAttribute(NEED_CLIENT_AUTH); - boolean wantClientCertificate = (Boolean) updated.getAttribute(WANT_CLIENT_AUTH); - boolean requiresCertificate = needClientCertificate || wantClientCertificate; - - boolean usesSsl = updated.getTransports().contains(Transport.SSL); - if (usesSsl) - { - if ((updated.getTrustStores() == null || updated.getTrustStores().isEmpty() ) && requiresCertificate) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust store configured."); - } - } - else - { - if (requiresCertificate) - { - throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but doesn't use SSL transport."); - } - } - - - - } } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java index 5c74beb5b7..f7eeca354a 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPort.java @@ -32,7 +32,7 @@ import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.virtualhost.VirtualHostImpl; @ManagedObject( category = false, type = "AMQP") -public interface AmqpPort<X extends AmqpPort<X>> extends Port<X> +public interface AmqpPort<X extends AmqpPort<X>> extends ClientAuthCapablePort<X> { String DEFAULT_AMQP_SEND_BUFFER_SIZE = "262144"; String DEFAULT_AMQP_RECEIVE_BUFFER_SIZE = "262144"; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java index 9a0ea3548e..fe7d419c78 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/AmqpPortImpl.java @@ -57,7 +57,7 @@ import org.apache.qpid.server.util.ServerScopedRuntimeException; import org.apache.qpid.server.virtualhost.VirtualHostImpl; import org.apache.qpid.transport.network.security.ssl.QpidMultipleTrustManager; -public class AmqpPortImpl extends AbstractPortWithAuthProvider<AmqpPortImpl> implements AmqpPort<AmqpPortImpl> +public class AmqpPortImpl extends AbstractClientAuthCapablePortWithAuthProvider<AmqpPortImpl> implements AmqpPort<AmqpPortImpl> { public static final String DEFAULT_BINDING_ADDRESS = "*"; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/ClientAuthCapablePort.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/ClientAuthCapablePort.java new file mode 100644 index 0000000000..4500b1510e --- /dev/null +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/ClientAuthCapablePort.java @@ -0,0 +1,30 @@ +/* + * 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. + */ + +package org.apache.qpid.server.model.port; + +import org.apache.qpid.server.model.Port; + + +public interface ClientAuthCapablePort<X extends Port<X>> extends Port<X> +{ + boolean getNeedClientAuth(); + + boolean getWantClientAuth(); +} diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPort.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPort.java index d8c87fb123..7c77389a83 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPort.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPort.java @@ -30,9 +30,8 @@ import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Transport; @ManagedObject( category = false, type = "HTTP") -public interface HttpPort<X extends HttpPort<X>> extends Port<X> +public interface HttpPort<X extends HttpPort<X>> extends ClientAuthCapablePort<X> { - String DEFAULT_AMQP_NEED_CLIENT_AUTH = "false"; String DEFAULT_AMQP_WANT_CLIENT_AUTH = "false"; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPortImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPortImpl.java index 80e79a68ca..1774f16ab6 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPortImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/HttpPortImpl.java @@ -20,17 +20,14 @@ */ package org.apache.qpid.server.model.port; -import java.util.Collections; import java.util.Map; -import java.util.Set; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.ManagedAttributeField; import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.State; -public class HttpPortImpl extends AbstractPortWithAuthProvider<HttpPortImpl> implements HttpPort<HttpPortImpl> +public class HttpPortImpl extends AbstractClientAuthCapablePortWithAuthProvider<HttpPortImpl> implements HttpPort<HttpPortImpl> { private PortManager _portManager; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/JmxPortImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/JmxPortImpl.java index a235613c29..3e21db23c6 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/JmxPortImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/port/JmxPortImpl.java @@ -20,13 +20,10 @@ */ package org.apache.qpid.server.model.port; -import java.util.Collections; import java.util.Map; -import java.util.Set; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.State; public class JmxPortImpl extends AbstractPortWithAuthProvider<JmxPortImpl> implements JmxPort<JmxPortImpl> diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/addPort.html b/qpid/java/broker-plugins/management-http/src/main/java/resources/addPort.html index 348b18f355..c76a230382 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/addPort.html +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/addPort.html @@ -78,7 +78,7 @@ <div id="formAddPort:fieldsProtocols"> <div class="clear"> <div class="formLabel-labelCell"> - <label for="formAddPort.protocols">Protocols*:</label> + <label for="formAddPort.protocols">Protocols:</label> </div> <div class="formLabel-controlCell"> <select id="formAddPort.protocols" @@ -86,11 +86,15 @@ data-dojo-props=" name: 'protocols', value: '', - label: 'protocol*:', - promptMessage: 'Protocol to be associated with this port', - title: 'Enter protocol to be associated with this port'"> + title: 'Select protocol(s) to be associated with this port'"> </select> </div> + <div id="formAddPort.protocols.tooltip" + data-dojo-type="dijit.Tooltip" + data-dojo-props="connectId: 'formAddPort.protocols', + label: 'Protocol(s) to be associated with the port'"> + </div> + </div> </div> @@ -144,9 +148,13 @@ placeHolder: 'TCP', value: '', multiple: true, - promptMessage: 'Transport(s)', - title: 'Select transports'"> + title: 'Select transport(s) to be associated with the port'"> </select> + <div id="formAddPort.transports.tooltip" + data-dojo-type="dijit.Tooltip" + data-dojo-props="connectId: 'formAddPort.transports', + label: 'Transport(s) to be associated with the port'"> + </div> </div> </div> </div> diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/widgetconfigurer.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/widgetconfigurer.js index 0b08dde615..2eb0a9b808 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/widgetconfigurer.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/widgetconfigurer.js @@ -23,12 +23,13 @@ define(["dojo/_base/xhr", "dojo/dom", "dojo/dom-construct", "dojo/dom-attr", + "dijit/registry", "qpid/common/properties", "qpid/common/metadata", "dojo/text!strings.html", "dojo/domReady!" ], - function (xhr, string, query, dom, domConstruct, domAttr, properties, metadata, template) + function (xhr, string, query, dom, domConstruct, domAttr, registry, properties, metadata, template) { var widgetconfigurer = { @@ -67,6 +68,32 @@ define(["dojo/_base/xhr", } } } + else if (widget instanceof dijit.Tooltip) + { + // If it is a tooltop, find the connected widget and use its name to lookup the default from the metadata. + if (typeof widget.get("qpid.originalLabel") == "undefined") + { + widget.set("qpid.originalLabel", widget.get("label")); + } + + var message = widget.get("qpid.originalLabel"); + var connectId = widget.get("connectId")[0]; + var connectWidget = registry.byId(connectId); + if (connectWidget) + { + var connectWidgetName = connectWidget.get("name"); + var defaultValue = metadata.getDefaultValueForAttribute(category, type, connectWidgetName); + if (defaultValue) + { + var newMessage = string.substitute(this.promptTemplateWithDefault, { 'default': defaultValue, 'prompt': message }); + + if (message != newMessage) + { + widget.set("label", newMessage); + } + } + } + } }, _processWidgetValue: function (widget, category, type) { diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js index 54391c78f6..1bf41ec730 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Port.js @@ -137,6 +137,7 @@ define(["dojo/dom", "needClientAuthValue", "wantClientAuthValue", "trustStoresValue", + "authenticationProvider", "bindingAddress", "keyStore", "needClientAuth", @@ -183,6 +184,7 @@ define(["dojo/dom", var typeMetaData = metadata.getMetaData("Port", this.portData["type"]); + this.authenticationProvider.style.display = "authenticationProvider" in typeMetaData.attributes ? "block" : "none"; this.bindingAddress.style.display = "bindingAddress" in typeMetaData.attributes ? "block" : "none"; this.keyStore.style.display = "keyStore" in typeMetaData.attributes ? "block" : "none"; this.needClientAuth.style.display = "needClientAuth" in typeMetaData.attributes ? "block" : "none"; diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addPort.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addPort.js index 8a862693cf..43ccdfff70 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addPort.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/addPort.js @@ -23,7 +23,6 @@ define(["dojo/_base/xhr", "dojo/dom-construct", "dojo/_base/window", "dijit/registry", - "dojo/parser", "dojo/_base/array", "dojo/_base/event", 'dojo/_base/json', @@ -56,7 +55,7 @@ define(["dojo/_base/xhr", "dojox/grid/EnhancedGrid", "dojox/grid/enhanced/plugins/IndirectSelection", "dojo/domReady!"], - function (xhr, dom, construct, win, registry, parser, array, event, json, Memory, ObjectStore, FilteringSelect, domStyle, lang, util, metadata) { + function (xhr, dom, construct, win, registry, array, event, json, Memory, ObjectStore, FilteringSelect, domStyle, lang, util, metadata) { var addPort = {}; @@ -86,10 +85,18 @@ define(["dojo/_base/xhr", var transportsValues = metadata.extractUniqueListOfValues(transportsValidValues); util.setMultiSelectOptions(transportsMultiSelect, transportsValues.sort()); - toggleSslWidgets(newValue, transportsMultiSelect.value); + addPort._toggleSslWidgets(newValue, transportsMultiSelect.value); + util.applyMetadataToWidgets(registry.byId("addPort").domNode, "Port", newValue); + }; - var convertToPort = function convertToPort(formValues) + addPort._isSecure = function(currentTransport) + { + return currentTransport == "SSL" || (lang.isArray(currentTransport) && array.indexOf(currentTransport, "SSL")>=0) + || currentTransport == "WSS" || (lang.isArray(currentTransport) && array.indexOf(currentTransport, "WSS")>=0); + } + + addPort._convertToPort = function(formValues) { var newPort = {}; newPort.name = dijit.byId("formAddPort.name").value; @@ -154,7 +161,7 @@ define(["dojo/_base/xhr", var initialTransport = transportWidget.initialValue; var currentTransport = transportWidget.value; - if (currentTransport == "SSL" || (lang.isArray(currentTransport) && array.indexOf(currentTransport, "SSL")>=0)) + if (addPort._isSecure(currentTransport)) { newPort.needClientAuth = needClientAuth.checked; newPort.wantClientAuth = wantClientAuth.checked @@ -185,12 +192,12 @@ define(["dojo/_base/xhr", return newPort; }; - var toggleSslWidgets = function toggleSslWidgets(portType, transportType) + addPort._toggleSslWidgets = function(portType, transportType) { var clientAuthPanel = dojo.byId("formAddPort:fieldsClientAuth"); var transportSSLPanelNode = dom.byId("formAddPort:fieldsTransportSSL"); - if (transportType == "SSL" || (lang.isArray(transportType) && array.indexOf(transportType, "SSL")>=0)) + if (addPort._isSecure(transportType)) { var typeMetaData = metadata.getMetaData("Port", portType); var clientAuth = "needClientAuth" in typeMetaData.attributes || "wantClientAuth" in typeMetaData.attributes; @@ -217,67 +224,90 @@ define(["dojo/_base/xhr", }; - xhr.get({url: "addPort.html", sync: true, load: function(data) { - var theForm; - node.innerHTML = data; - addPort.dialogNode = dom.byId("addPort"); - parser.instantiate([addPort.dialogNode]); - - //add the port types to formAddPort.type - var portTypeSelect = registry.byId("formAddPort.type"); - var supportedPortTypes = metadata.getTypesForCategory("Port"); - var portTypeSelectStore = util.makeTypeStore(supportedPortTypes); - portTypeSelect.set("store", portTypeSelectStore); - - //add handler for transports change - registry.byId("formAddPort.transports").on("change", function(newValue){ - var portType = portTypeSelect.get("value"); - toggleSslWidgets(portType, newValue); - }); - - - theForm = registry.byId("formAddPort"); - theForm.on("submit", function(e) { - - event.stop(e); - if(theForm.validate()){ + addPort._init = function() + { + xhr.get({url: "addPort.html", sync: true, load: function (data) + { + var theForm; + node.innerHTML = data; + addPort.dialogNode = dom.byId("addPort"); + }}); + } + + addPort._prepareForm = function() + { + //add the port types to formAddPort.type + var portTypeSelect = registry.byId("formAddPort.type"); + var supportedPortTypes = metadata.getTypesForCategory("Port"); + var portTypeSelectStore = util.makeTypeStore(supportedPortTypes); + portTypeSelect.set("store", portTypeSelectStore); + + //add handler for transports change + registry.byId("formAddPort.transports").on("change", function (newValue) + { + var portType = portTypeSelect.get("value"); + addPort._toggleSslWidgets(portType, newValue); + }); + + theForm = registry.byId("formAddPort"); + theForm.on("submit", function (e) + { + + event.stop(e); + if (theForm.validate()) + { - var newPort = convertToPort(theForm.getValues()); - if ((newPort.needClientAuth || newPort.wantClientAuth) && (!newPort.hasOwnProperty("trustStores") || newPort.trustStores.length==0)) - { - alert("A trust store must be selected when requesting client certificates."); - return false; - } - var that = this; + var newPort = addPort._convertToPort(theForm.getValues()); + if ((newPort.needClientAuth || newPort.wantClientAuth) && (!newPort.hasOwnProperty("trustStores") || newPort.trustStores.length == 0)) + { + alert("A trust store must be selected when requesting client certificates."); + return false; + } + var that = this; + + xhr.put({url: "api/latest/port/" + encodeURIComponent(newPort.name), sync: true, handleAs: "json", + headers: { "Content-Type": "application/json"}, + putData: json.toJson(newPort), + load: function (x) + { + that.success = true; + }, + error: function (error) + { + that.success = false; + that.failureReason = error; + }}); - xhr.put({url: "api/latest/port/"+encodeURIComponent(newPort.name), sync: true, handleAs: "json", - headers: { "Content-Type": "application/json"}, - putData: json.toJson(newPort), - load: function(x) {that.success = true; }, - error: function(error) {that.success = false; that.failureReason = error;}}); + if (this.success === true) + { + registry.byId("addPort").hide(); + } + else + { + util.xhrErrorHandler(this.failureReason); + } - if(this.success === true) - { - registry.byId("addPort").hide(); - } - else - { - util.xhrErrorHandler(this.failureReason); - } + return false; - return false; + } else + { + alert('Form contains invalid data. Please correct first'); + return false; + } - }else{ - alert('Form contains invalid data. Please correct first'); - return false; - } + }); + } - }); - }}); + addPort.show = function(portName, portType, providers, keystores, truststores) + { + if (!this.formPrepared) + { + this._prepareForm(); + this.formPrepared = true; + } - addPort.show = function(portName, portType, providers, keystores, truststores) { registry.byId("formAddPort").reset(); dojo.byId("formAddPort.id").value = ""; @@ -371,6 +401,8 @@ define(["dojo/_base/xhr", //authenticationProvider providerWidget.set("value", port.authenticationProvider ? port.authenticationProvider : ""); + providerWidget.set("disabled", ! ("authenticationProvider" in typeMetaData.attributes)); + dom.byId("formAddPort:fieldsAuthenticationProvider").style.display = "authenticationProvider" in typeMetaData.attributes ? "block" : "none"; //transports var transportsMultiSelect = dom.byId("formAddPort.transports"); @@ -444,5 +476,7 @@ define(["dojo/_base/xhr", }; + addPort._init(); + return addPort; }); |