use of com.sun.messaging.jmq.jmsserver.cluster.api.ClusteredBroker in project openmq by eclipse-ee4j.
the class MQWebSocketServiceApp method checkOrigin.
private boolean checkOrigin(HttpRequestPacket request) throws Exception {
String origin = request.getHeader(Constants.ORIGIN_HEADER);
List<URL> origins = service.getAllowedOrigins();
URL myurl = service.getMyURL();
if (MQWebSocket.getDEBUG()) {
logger.log(Logger.INFO, getClass().getSimpleName() + ".checkOrigin(" + request + "): origin=" + origin + ", myurl=" + myurl + ", allowedOrigins=" + origins);
}
if (origin == null || origins == null) {
return true;
}
URL ou = null;
try {
ou = new URL(origin);
} catch (Exception e) {
logger.log(logger.ERROR, br.getKString(br.X_WEBSOCKET_INVALID_CLIENT_ORIGIN, origin));
return false;
}
if (!ou.getProtocol().equals(myurl.getProtocol())) {
return false;
}
if (ou.getHost().equals(myurl.getHost())) {
return true;
}
InetAddress oia = InetAddress.getByName(ou.getHost());
if (oia.equals(InetAddress.getByName(myurl.getHost()))) {
return true;
}
ClusterManager cm = Globals.getClusterManager();
Iterator itr = cm.getConfigBrokers();
ClusteredBroker cb = null;
BrokerMQAddress addr = null;
String h;
while (itr.hasNext()) {
cb = (ClusteredBroker) itr.next();
addr = (BrokerMQAddress) cb.getBrokerURL();
h = addr.getHost().getCanonicalHostName();
if (MQWebSocket.getDEBUG()) {
logger.log(logger.INFO, getClass().getSimpleName() + ".checkOrigin(" + request + "), origin=" + ou + ", check configured cluster broker " + addr + "[" + h + "]");
}
if (ou.getHost().equals(h)) {
return true;
}
if (oia.equals(addr.getHost())) {
return true;
}
}
URL url;
Iterator<URL> itr1 = origins.iterator();
while (itr1.hasNext()) {
url = itr1.next();
if (!ou.getProtocol().equals(url.getProtocol())) {
continue;
}
if (ou.getHost().equals(url.getHost())) {
return true;
}
if (oia.equals(InetAddress.getByName(url.getHost()))) {
return true;
}
}
logger.log(logger.ERROR, br.getKString(br.X_WEBSOCKET_ORIGIN_NOT_ALLOWED, origin, origins));
return false;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ClusteredBroker in project openmq by eclipse-ee4j.
the class PortMapper method allowConnection.
/**
*****************************************************
* Implement PUServiceCallback interface
*******************************************************************
*/
@Override
public boolean allowConnection(InetSocketAddress sa, boolean ssl) {
if (DEBUG) {
logger.log(logger.INFO, "PortMapper.alllowConnection(" + sa + ", " + ssl + "), sslEnabled=" + sslEnabled + ", allowedHosts=" + allowedHosts + ", broker=" + Globals.getBrokerInetAddress());
}
if (!sslEnabled) {
return true;
}
if (ssl) {
return true;
}
if (sa.getAddress().equals(Globals.getBrokerInetAddress())) {
return true;
}
if (sa.getAddress().isLoopbackAddress()) {
return true;
}
if (allowedHosts.contains(sa.getAddress())) {
return true;
}
ClusterManager cm = Globals.getClusterManager();
Iterator itr = cm.getConfigBrokers();
ClusteredBroker cb = null;
BrokerMQAddress addr = null;
while (itr.hasNext()) {
cb = (ClusteredBroker) itr.next();
addr = (BrokerMQAddress) cb.getBrokerURL();
if (DEBUG) {
logger.log(logger.INFO, "PortMapper.allowConnection(" + sa + "), check configured cluster broker " + addr);
}
if (addr.getHost().equals(sa.getAddress())) {
return true;
}
}
return false;
}
Aggregations