Map<String, Object> merged = generateEffectiveAttributes(converted);
String newName = (String) merged.get(NAME);
if(!getName().equals(newName))
{
throw new IllegalConfigurationException("Changing the port name is not allowed");
}
Integer newPort = (Integer) merged.get(PORT);
if(getPort() != newPort)
{
for(Port p : _broker.getPorts())
{
if(p.getPort() == newPort)
{
throw new IllegalConfigurationException("Port number " + newPort + " is already in use by port " + p.getName());
}
}
}
@SuppressWarnings("unchecked")
Collection<Transport> transports = (Collection<Transport>)merged.get(TRANSPORTS);
@SuppressWarnings("unchecked")
Collection<Protocol> protocols = (Collection<Protocol>)merged.get(PROTOCOLS);
Boolean needClientCertificate = (Boolean)merged.get(NEED_CLIENT_AUTH);
Boolean wantClientCertificate = (Boolean)merged.get(WANT_CLIENT_AUTH);
boolean requiresCertificate = (needClientCertificate != null && needClientCertificate.booleanValue())
|| (wantClientCertificate != null && wantClientCertificate.booleanValue());
String keyStoreName = (String) merged.get(KEY_STORE);
if(keyStoreName != null)
{
if (_broker.findKeyStoreByName(keyStoreName) == null)
{
throw new IllegalConfigurationException("Can't find key store with name '" + keyStoreName + "' for port " + getName());
}
}
Set<String> trustStoreNames = (Set<String>) merged.get(TRUST_STORES);
boolean hasTrustStore = trustStoreNames != null && !trustStoreNames.isEmpty();
if(hasTrustStore)
{
for (String trustStoreName : trustStoreNames)
{
if (_broker.findTrustStoreByName(trustStoreName) == null)
{
throw new IllegalConfigurationException("Cannot find trust store with name '" + trustStoreName + "'");
}
}
}
boolean usesSsl = transports != null && transports.contains(Transport.SSL);
if (usesSsl)
{
if (keyStoreName == null)
{
throw new IllegalConfigurationException("Can't create port which requires SSL but has no key store configured.");
}
if (!hasTrustStore && 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.");
}
}
if (protocols != null && protocols.contains(Protocol.RMI) && usesSsl)
{
throw new IllegalConfigurationException("Can't create RMI Registry port which requires SSL.");
}
String authenticationProviderName = (String)merged.get(AUTHENTICATION_PROVIDER);
if (authenticationProviderName != null)
{
Collection<AuthenticationProvider> providers = _broker.getAuthenticationProviders();
AuthenticationProvider provider = null;
for (AuthenticationProvider p : providers)
{
if (p.getName().equals(authenticationProviderName))
{
provider = p;
break;
}
}
if (provider == null)
{
throw new IllegalConfigurationException("Cannot find authentication provider with name '"
+ authenticationProviderName + "'");
}
}
else
{
if (protocols != null && !protocols.contains(Protocol.RMI))
{
throw new IllegalConfigurationException("An authentication provider must be specified");
}
}
super.changeAttributes(converted);
}