_defaultProtocols = Collections.unmodifiableCollection(defaultProtocols);
}
public Port createPort(UUID id, Broker broker, Map<String, Object> attributes)
{
final Port port;
Map<String, Object> defaults = new HashMap<String, Object>();
defaults.put(Port.TRANSPORTS, Collections.singleton(DEFAULT_TRANSPORT));
Object portValue = attributes.get(Port.PORT);
if (portValue == null)
{
throw new IllegalConfigurationException("Port attribute is not specified for port: " + attributes);
}
Set<Protocol> protocols = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class);
if (isAmqpProtocol(protocols, attributes))
{
Object binding = attributes.get(Port.BINDING_ADDRESS);
if (binding == null)
{
binding = DEFAULT_AMQP_BINDING;
defaults.put(Port.BINDING_ADDRESS, DEFAULT_AMQP_BINDING);
}
defaults.put(Port.NAME, binding + ":" + portValue);
defaults.put(Port.PROTOCOLS, _defaultProtocols);
defaults.put(Port.TCP_NO_DELAY, DEFAULT_AMQP_TCP_NO_DELAY);
defaults.put(Port.WANT_CLIENT_AUTH, DEFAULT_AMQP_WANT_CLIENT_AUTH);
defaults.put(Port.NEED_CLIENT_AUTH, DEFAULT_AMQP_NEED_CLIENT_AUTH);
defaults.put(Port.RECEIVE_BUFFER_SIZE, DEFAULT_AMQP_RECEIVE_BUFFER_SIZE);
defaults.put(Port.SEND_BUFFER_SIZE, DEFAULT_AMQP_SEND_BUFFER_SIZE);
port = new AmqpPortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor());
boolean useClientAuth = (Boolean) port.getAttribute(Port.NEED_CLIENT_AUTH) || (Boolean) port.getAttribute(Port.WANT_CLIENT_AUTH);
if(useClientAuth && port.getTrustStores().isEmpty())
{
throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but has no trust stores configured.");
}
if(useClientAuth && !(port.getTransports().contains(Transport.SSL) || port.getTransports().contains(Transport.WSS)))
{
throw new IllegalConfigurationException("Can't create port which requests SSL client certificates but doesn't use SSL transport.");
}
}
else
{
if (protocols.size() > 1)
{
throw new IllegalConfigurationException("Only one protocol can be used on non AMQP port");
}
Protocol protocol = protocols.iterator().next();
if(!broker.isManagementMode() && protocol.getProtocolType() != ProtocolType.HTTP)
{
//ManagementMode needs this relaxed to allow its overriding management ports to be inserted.
//Enforce only a single port of each management protocol, as the plugins will only use one.
Collection<Port> existingPorts = broker.getPorts();
for (Port existingPort : existingPorts)
{
Collection<Protocol> portProtocols = existingPort.getProtocols();
if (portProtocols != null && portProtocols.contains(protocol))
{
throw new IllegalConfigurationException("Port for protocol " + protocol + " already exists. Only one management port per protocol can be created.");
}
}
}
defaults.put(Port.NAME, portValue + "-" + protocol.name());
port = new NonAmqpPortAdapter(id, broker, attributes, defaults, broker.getTaskExecutor());
boolean rmiPort = port.getProtocols().contains(Protocol.RMI);
if (rmiPort && port.getTransports().contains(Transport.SSL))
{
throw new IllegalConfigurationException("Can't create RMI registry port which requires SSL");
}
}
if(port.getTransports().contains(Transport.SSL))
{
if(port.getKeyStore() == null)
{
throw new IllegalConfigurationException("Can't create port which requires SSL but has no key store configured.");
}
}