/** * Overriding removeConnection to make sure the security context is cleaned. */ @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); context.setSecurityContext(null); }
@Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } }
/** * 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 static ConnectionContext createAdminConnectionContext(Broker broker) { ConnectionContext context = new ConnectionContext(); context.setBroker(broker); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); return context; } }
@Override public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception { SecurityContext securityContext = context.getSecurityContext(); if (securityContext == null) { securityContext = authenticate(info.getUserName(), info.getPassword(), null); context.setSecurityContext(securityContext); securityContexts.add(securityContext); } try { super.addConnection(context, info); } catch (Exception e) { securityContexts.remove(securityContext); context.setSecurityContext(null); throw e; } }
@Override public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception { if (context.getSecurityContext() == null) { // Set the TCCL since it seems JAAS needs it to find the login module classes. ClassLoader original = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(JaasAuthenticationBroker.class.getClassLoader()); SecurityContext securityContext = null; try { securityContext = authenticate(info.getUserName(), info.getPassword(), null); context.setSecurityContext(securityContext); securityContexts.add(securityContext); super.addConnection(context, info); } catch (Exception error) { if (securityContext != null) { securityContexts.remove(securityContext); } context.setSecurityContext(null); throw error; } finally { Thread.currentThread().setContextClassLoader(original); } } else { super.addConnection(context, info); } }
@Override public final void start() throws Exception { started = true; Set<ActiveMQDestination> inactiveDests = getInactiveDestinations(); for (Iterator<ActiveMQDestination> iter = inactiveDests.iterator(); iter.hasNext();) { ActiveMQDestination dest = iter.next(); ConnectionContext context = new ConnectionContext(); context.setBroker(broker.getBrokerService().getBroker()); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.getBroker().addDestination(context, dest, false); } destinationsLock.readLock().lock(); try{ for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) { Destination dest = i.next(); dest.start(); } } finally { destinationsLock.readLock().unlock(); } }
/** * Overridden to allow for authentication based on client certificates. * Connections being added will be authenticated based on their certificate * chain and the JAAS module specified through the JAAS framework. NOTE: The * security context's username will be set to the first UserPrincipal * created by the login module. * * @param context The context for the incoming Connection. * @param info The ConnectionInfo Command representing the incoming * connection. */ @Override public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception { if (context.getSecurityContext() == null) { if (!(info.getTransportContext() instanceof X509Certificate[])) { throw new SecurityException("Unable to authenticate transport without SSL certificate."); } // Set the TCCL since it seems JAAS needs it to find the login // module classes. ClassLoader original = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(JaasAuthenticationBroker.class.getClassLoader()); try { SecurityContext s = authenticate(info.getUserName(), info.getPassword(), (X509Certificate[]) info.getTransportContext()); context.setSecurityContext(s); } finally { Thread.currentThread().setContextClassLoader(original); } } super.addConnection(context, info); }
public ConnectionContext createConnectionContext() { ConnectionContext answer = new ConnectionContext(); answer.setBroker(this.broker); answer.getMessageEvaluationContext().setDestination(getActiveMQDestination()); answer.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); return answer; }
private void fireFailedForwardAdvisory(MessageDispatch messageDispatch, Throwable error) { if (configuration.isAdvisoryForFailedForward()) { AdvisoryBroker advisoryBroker = null; try { advisoryBroker = (AdvisoryBroker) brokerService.getBroker().getAdaptor(AdvisoryBroker.class); if (advisoryBroker != null) { ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(brokerService.getBroker()); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty("cause", error.getLocalizedMessage()); advisoryBroker.fireAdvisory(context, AdvisorySupport.getNetworkBridgeForwardFailureAdvisoryTopic(), messageDispatch.getMessage(), null, advisoryMessage); } } catch (Exception e) { LOG.warn("failed to fire forward failure advisory, cause: {}", e); LOG.debug("detail", e); } } }
@Override public void networkBridgeStopped(BrokerInfo brokerInfo) { try { if (brokerInfo != null) { ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setBooleanProperty("started", false); networkBridges.remove(brokerInfo); ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic(); ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(getBrokerService().getBroker()); fireAdvisory(context, topic, brokerInfo, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("network bridge stopped", e); } }
@Override public void nowMasterBroker() { super.nowMasterBroker(); try { ActiveMQTopic topic = AdvisorySupport.getMasterBrokerAdvisoryTopic(); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(getBrokerService().getBroker()); fireAdvisory(context, topic, null, null, advisoryMessage); } catch (Exception e) { handleFireFailure("now master broker", e); } }
@Override public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) { try { if (brokerInfo != null) { ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setBooleanProperty("started", true); advisoryMessage.setBooleanProperty("createdByDuplex", createdByDuplex); advisoryMessage.setStringProperty("remoteIp", remoteIp); networkBridges.putIfAbsent(brokerInfo, advisoryMessage); ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic(); ConnectionContext context = new ConnectionContext(); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setBroker(getBrokerService().getBroker()); fireAdvisory(context, topic, brokerInfo, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("network bridge started", e); } }
this.context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
/** * Overriding removeConnection to make sure the security context is cleaned. */ @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); context.setSecurityContext(null); }
@Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { try { super.removeConnection(context, info, error); } finally { context.setSecurityContext(null); } } }
/** * Overriding removeConnection to make sure the security context is cleaned. */ @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); context.setSecurityContext(null); }
@Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } }
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { super.removeConnection(context, info, error); if (securityContexts.remove(context.getSecurityContext())) { context.setSecurityContext(null); } }
public ConnectionContext createConnectionContext() { ConnectionContext answer = new ConnectionContext(); answer.setBroker(this.broker); answer.getMessageEvaluationContext().setDestination(getActiveMQDestination()); answer.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); return answer; }
protected ConnectionContext createConnectionContext() { ConnectionContext answer = new ConnectionContext(new NonCachedMessageEvaluationContext()); answer.setBroker(this.broker); answer.getMessageEvaluationContext().setDestination(getActiveMQDestination()); answer.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); return answer; }