}
public void methodReceived(AMQStateManager stateManager, AMQMethodEvent<ConnectionOpenBody> evt) throws AMQException
{
AMQProtocolSession session = stateManager.getProtocolSession();
ConnectionOpenBody body = evt.getMethod();
//ignore leading '/'
String virtualHostName;
if ((body.virtualHost != null) && body.virtualHost.charAt(0) == '/')
{
virtualHostName = new StringBuilder(body.virtualHost.subSequence(1, body.virtualHost.length())).toString();
}
else
{
virtualHostName = body.virtualHost == null ? null : String.valueOf(body.virtualHost);
}
VirtualHost virtualHost = stateManager.getVirtualHostRegistry().getVirtualHost(virtualHostName);
if (virtualHost == null)
{
throw body.getConnectionException(AMQConstant.NOT_FOUND, "Unknown virtual host: '" + virtualHostName + "'");
}
else
{
session.setVirtualHost(virtualHost);
AccessResult result = virtualHost.getAccessManager().isAuthorized(virtualHost, session.getAuthorizedID(), AccessRights.Rights.ANY);
switch (result.getStatus())
{
default:
case REFUSED:
String error = "Any access denied to vHost '" + virtualHostName + "' by "
+ result.getAuthorizer();
_logger.warn(error);
throw body.getConnectionException(AMQConstant.ACCESS_REFUSED, error);
case GRANTED:
_logger.info("Granted any access to vHost '" + virtualHostName + "' for " + session.getAuthorizedID()
+ " by '" + result.getAuthorizer() + "'");
}