added a helper method on the broker for its default administration connection context to avoid various parts of the code spoofing one and to provide a single place we can register any particular security details for startup or runtime MBean based administration

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@426132 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-07-27 16:39:09 +00:00
parent 4bd8a8bf85
commit 8abb655e82
8 changed files with 160 additions and 92 deletions

View File

@ -238,4 +238,14 @@ public interface Broker extends Region, Service {
* @return true if fault tolerant * @return true if fault tolerant
*/ */
public boolean isFaultTolerantConfiguration(); public boolean isFaultTolerantConfiguration();
/**
* @return the connection context used to make administration operations on startup or via JMX MBeans
*/
public abstract ConnectionContext getAdminConnectionContext();
/**
* Sets the default administration connection context used when configuring the broker on startup or via JMX
*/
public abstract void setAdminConnectionContext(ConnectionContext adminConnectionContext);
} }

View File

@ -213,9 +213,16 @@ public class BrokerFilter implements Broker {
} }
public boolean isFaultTolerantConfiguration(){ public boolean isFaultTolerantConfiguration(){
return next.isFaultTolerantConfiguration(); return next.isFaultTolerantConfiguration();
} }
public ConnectionContext getAdminConnectionContext() {
return next.getAdminConnectionContext();
}
public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
next.setAdminConnectionContext(adminConnectionContext);
}
} }

View File

@ -1202,16 +1202,41 @@ public class BrokerService implements Service, Serializable {
*/ */
protected void startDestinations() throws Exception { protected void startDestinations() throws Exception {
if (destinations != null) { if (destinations != null) {
ConnectionContext context = new ConnectionContext(); ConnectionContext adminConnectionContext = getAdminConnectionContext();
context.setBroker(getBroker());
for (int i = 0; i < destinations.length; i++) { for (int i = 0; i < destinations.length; i++) {
ActiveMQDestination destination = destinations[i]; ActiveMQDestination destination = destinations[i];
getBroker().addDestination(context, destination); getBroker().addDestination(adminConnectionContext, destination);
} }
} }
} }
/**
* Returns the broker's administration connection context used for configuring the broker
* at startup
*/
public ConnectionContext getAdminConnectionContext() throws Exception {
ConnectionContext adminConnectionContext = getBroker().getAdminConnectionContext();
if (adminConnectionContext == null) {
adminConnectionContext = createAdminConnectionContext();
getBroker().setAdminConnectionContext(adminConnectionContext);
}
return adminConnectionContext;
}
/**
* Factory method to create the new administration connection context object.
* Note this method is here rather than inside a default broker implementation to
* ensure that the broker reference inside it is the outer most interceptor
*/
protected ConnectionContext createAdminConnectionContext() throws Exception {
ConnectionContext context = new ConnectionContext();
context.setBroker(getBroker());
return context;
}
/** /**
* Start all transport and network connections, proxies and bridges * Start all transport and network connections, proxies and bridges
* @throws Exception * @throws Exception

View File

@ -42,18 +42,18 @@ import java.util.Set;
* *
* @version $Revision$ * @version $Revision$
*/ */
public class EmptyBroker implements Broker{ public class EmptyBroker implements Broker {
public BrokerId getBrokerId(){ public BrokerId getBrokerId() {
return null; return null;
} }
public String getBrokerName(){ public String getBrokerName() {
return null; return null;
} }
public Broker getAdaptor(Class type){ public Broker getAdaptor(Class type) {
if (type.isInstance(this)){ if (type.isInstance(this)) {
return this; return this;
} }
return null; return null;
@ -67,152 +67,159 @@ public class EmptyBroker implements Broker{
return Collections.EMPTY_SET; return Collections.EMPTY_SET;
} }
public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception{ public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
} }
public void removeConnection(ConnectionContext context,ConnectionInfo info,Throwable error) throws Exception{ public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
} }
public void addSession(ConnectionContext context,SessionInfo info) throws Exception{ public void addSession(ConnectionContext context, SessionInfo info) throws Exception {
} }
public void removeSession(ConnectionContext context,SessionInfo info) throws Exception{ public void removeSession(ConnectionContext context, SessionInfo info) throws Exception {
} }
public void addProducer(ConnectionContext context,ProducerInfo info) throws Exception{ public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {
} }
public void removeProducer(ConnectionContext context,ProducerInfo info) throws Exception{ public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception {
} }
public Connection[] getClients() throws Exception{ public Connection[] getClients() throws Exception {
return null; return null;
} }
public ActiveMQDestination[] getDestinations() throws Exception{ public ActiveMQDestination[] getDestinations() throws Exception {
return null; return null;
} }
public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception{ public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception {
return null; return null;
} }
public void beginTransaction(ConnectionContext context,TransactionId xid) throws Exception{ public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception {
} }
public int prepareTransaction(ConnectionContext context,TransactionId xid) throws Exception{ public int prepareTransaction(ConnectionContext context, TransactionId xid) throws Exception {
return 0; return 0;
} }
public void rollbackTransaction(ConnectionContext context,TransactionId xid) throws Exception{ public void rollbackTransaction(ConnectionContext context, TransactionId xid) throws Exception {
} }
public void commitTransaction(ConnectionContext context,TransactionId xid,boolean onePhase) throws Exception{ public void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase) throws Exception {
} }
public void forgetTransaction(ConnectionContext context,TransactionId transactionId) throws Exception{ public void forgetTransaction(ConnectionContext context, TransactionId transactionId) throws Exception {
} }
public Destination addDestination(ConnectionContext context,ActiveMQDestination destination) throws Exception{ public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
return null; return null;
} }
public void removeDestination(ConnectionContext context,ActiveMQDestination destination,long timeout) throws Exception{ public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
} }
public Subscription addConsumer(ConnectionContext context,ConsumerInfo info) throws Exception{ public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
return null; return null;
} }
public void removeConsumer(ConnectionContext context,ConsumerInfo info) throws Exception{ public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
} }
public void removeSubscription(ConnectionContext context,RemoveSubscriptionInfo info) throws Exception{ public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception {
} }
public void send(ConnectionContext context,Message message) throws Exception{ public void send(ConnectionContext context, Message message) throws Exception {
} }
public void acknowledge(ConnectionContext context,MessageAck ack) throws Exception{ public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
} }
public void gc(){ public void gc() {
} }
public void start() throws Exception{ public void start() throws Exception {
} }
public void stop() throws Exception{ public void stop() throws Exception {
} }
public void addBroker(Connection connection,BrokerInfo info){ public void addBroker(Connection connection, BrokerInfo info) {
}
public void removeBroker(Connection connection,BrokerInfo info){
} }
public BrokerInfo[] getPeerBrokerInfos(){ public void removeBroker(Connection connection, BrokerInfo info) {
}
public BrokerInfo[] getPeerBrokerInfos() {
return null; return null;
} }
/** /**
* Notifiy the Broker that a dispatch has happened * Notifiy the Broker that a dispatch has happened
*
* @param messageDispatch * @param messageDispatch
*/ */
public void processDispatch(MessageDispatch messageDispatch){ public void processDispatch(MessageDispatch messageDispatch) {
} }
public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception{ public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception {
} }
public boolean isSlaveBroker(){ public boolean isSlaveBroker() {
return false; return false;
} }
public boolean isStopped(){ public boolean isStopped() {
return false; return false;
} }
public Set getDurableDestinations(){ public Set getDurableDestinations() {
return null; return null;
} }
public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
} }
public void removeDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
} }
public boolean isFaultTolerantConfiguration(){ public boolean isFaultTolerantConfiguration() {
return false; return false;
} }
public ConnectionContext getAdminConnectionContext() {
return null;
}
public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
}
} }

View File

@ -38,7 +38,8 @@ import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.command.TransactionId; import org.apache.activemq.command.TransactionId;
/** /**
* Implementation of the broker where all it's methods throw an BrokerStoppedException. * Implementation of the broker where all it's methods throw an
* BrokerStoppedException.
* *
* @version $Revision$ * @version $Revision$
*/ */
@ -47,9 +48,9 @@ public class ErrorBroker implements Broker {
private final String message; private final String message;
public ErrorBroker(String message) { public ErrorBroker(String message) {
this.message=message; this.message = message;
} }
public Map getDestinationMap() { public Map getDestinationMap() {
return Collections.EMPTY_MAP; return Collections.EMPTY_MAP;
} }
@ -58,13 +59,13 @@ public class ErrorBroker implements Broker {
return Collections.EMPTY_SET; return Collections.EMPTY_SET;
} }
public Broker getAdaptor(Class type){ public Broker getAdaptor(Class type) {
if (type.isInstance(this)){ if (type.isInstance(this)) {
return this; return this;
} }
return null; return null;
} }
public BrokerId getBrokerId() { public BrokerId getBrokerId() {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
@ -72,7 +73,7 @@ public class ErrorBroker implements Broker {
public String getBrokerName() { public String getBrokerName() {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception { public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
@ -169,52 +170,57 @@ public class ErrorBroker implements Broker {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void addBroker(Connection connection,BrokerInfo info){ public void addBroker(Connection connection, BrokerInfo info) {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void removeBroker(Connection connection,BrokerInfo info){ public void removeBroker(Connection connection, BrokerInfo info) {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public BrokerInfo[] getPeerBrokerInfos(){ public BrokerInfo[] getPeerBrokerInfos() {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void processDispatch(MessageDispatch messageDispatch){ public void processDispatch(MessageDispatch messageDispatch) {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception{ public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public boolean isSlaveBroker(){ public boolean isSlaveBroker() {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public boolean isStopped(){ public boolean isStopped() {
return true; return true;
} }
public Set getDurableDestinations(){ public Set getDurableDestinations() {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public void removeDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public boolean isFaultTolerantConfiguration(){ public boolean isFaultTolerantConfiguration() {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public ConnectionContext getAdminConnectionContext() {
throw new BrokerStoppedException(this.message);
}
public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
throw new BrokerStoppedException(this.message);
}
} }

View File

@ -229,4 +229,12 @@ public class MutableBrokerFilter implements Broker {
return getNext().isFaultTolerantConfiguration(); return getNext().isFaultTolerantConfiguration();
} }
public ConnectionContext getAdminConnectionContext() {
return getNext().getAdminConnectionContext();
}
public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
getNext().setAdminConnectionContext(adminConnectionContext);
}
} }

View File

@ -180,9 +180,7 @@ public class BrokerView implements BrokerViewMBean {
} }
static public ConnectionContext getConnectionContext(Broker broker) { static public ConnectionContext getConnectionContext(Broker broker) {
ConnectionContext context = new ConnectionContext(); return broker.getAdminConnectionContext();
context.setBroker(broker);
return context;
} }
} }

View File

@ -85,6 +85,7 @@ public class RegionBroker implements Broker {
private Map clientIdSet = new HashMap(); // we will synchronize access private Map clientIdSet = new HashMap(); // we will synchronize access
protected PersistenceAdapter adaptor; protected PersistenceAdapter adaptor;
private final DestinationInterceptor destinationInterceptor; private final DestinationInterceptor destinationInterceptor;
private ConnectionContext adminConnectionContext;
public RegionBroker(BrokerService brokerService,TaskRunnerFactory taskRunnerFactory, UsageManager memoryManager, PersistenceAdapter adapter, DestinationInterceptor destinationInterceptor) throws IOException { public RegionBroker(BrokerService brokerService,TaskRunnerFactory taskRunnerFactory, UsageManager memoryManager, PersistenceAdapter adapter, DestinationInterceptor destinationInterceptor) throws IOException {
this.brokerService = brokerService; this.brokerService = brokerService;
@ -533,5 +534,11 @@ public class RegionBroker implements Broker {
return destinationInterceptor; return destinationInterceptor;
} }
public ConnectionContext getAdminConnectionContext() {
return adminConnectionContext;
}
public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
this.adminConnectionContext = adminConnectionContext;
}
} }