@Override public String getConnectionClientID() { return this.session.getRemotingConnection().getClientID(); }
@Override public void afterCreateConnection(RemotingConnection connection) throws ActiveMQException { try { //Verify that calling getClientID() before initialized doesn't cause an error //Test for ARTEMIS-1713 connection.getClientID(); } catch (Exception e) { throw new ActiveMQException(e.getMessage()); } } });
@Override public JsonObjectBuilder toJson(RemotingConnection connection) { List<ServerSession> sessions = server.getSessions(connection.getID().toString()); Set<String> users = new HashSet<>(); String jmsSessionClientID = null; for (ServerSession session : sessions) { String username = session.getUsername() == null ? "" : session.getUsername(); users.add(username); //for the special case for JMS if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) { jmsSessionClientID = session.getMetaData("jms-client-id"); } } return JsonLoader.createObjectBuilder().add("connectionID", toString(connection.getID())) .add("remoteAddress", toString(connection.getRemoteAddress())) .add("users", StringUtil.joinStringList(users, ",")) .add("creationTime", new Date(connection.getCreationTime()).toString()) .add("implementation", toString(connection.getClass().getSimpleName())) .add("protocol", toString(connection.getProtocolName())) .add("clientID", toString(connection.getClientID() != null ? connection.getClientID() : jmsSessionClientID)) .add("localAddress", toString(connection.getTransportLocalAddress())) .add("sessionCount", server.getSessions(connection.getID().toString()).size()); }
return connection.getProtocolName(); case "clientID": return connection.getClientID(); case "localAddress": return connection.getTransportLocalAddress();
@Override public String validateUser(String user, String password, RemotingConnection remotingConnection) { String validatedUser = super.validateUser(user, password, remotingConnection); if (validatedUser == null) { return null; } if ("STOMP".equals(remotingConnection.getProtocolName())) { final String clientId = remotingConnection.getClientID(); /* * perform some kind of clientId validation, e.g. check presence or format */ if (clientId == null || clientId.length() == 0) { System.err.println("ClientID not set!"); return null; } } return validatedUser; } };
@Override public JsonObjectBuilder toJson(ServerProducer producer) { ServerSession session = server.getSessionByID(producer.getSessionID()); //if session is not available then consumer is not in valid state - ignore if (session == null) { return null; } String jmsSessionClientID = null; //for the special case for JMS if (session.getMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY) != null) { jmsSessionClientID = session.getMetaData("jms-client-id"); } JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("id", toString(producer.getID())) .add("session", toString(session.getName())) .add("clientID", toString(session.getRemotingConnection().getClientID() != null ? session.getRemotingConnection().getClientID() : jmsSessionClientID)) .add("user", toString(session.getUsername())) .add("protocol", toString(session.getRemotingConnection().getProtocolName())) .add("address", toString(producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress())) .add("localAddress", toString(session.getRemotingConnection().getTransportConnection().getLocalAddress())) .add("remoteAddress", toString(session.getRemotingConnection().getTransportConnection().getRemoteAddress())) .add("creationTime", toString(producer.getCreationTime())); return obj; }
return matches(connection.getID()); case CLIENT_ID: return matches(connection.getClientID()); case USERS: List<ServerSession> sessions = server.getSessions(connection.getID().toString());
@Override public boolean test(ServerSession session) { // Using switch over enum vs string comparison is better for perf. if (f == null) return true; switch (f) { case ID: return matches(session.getName()); case CONNECTION_ID: return matches(session.getConnectionID()); case CONSUMER_COUNT: return matches(session.getServerConsumers().size()); case PRODUCER_COUNT: return matches(session.getServerProducers().size()); case PROTOCOL: return matches(session.getRemotingConnection().getProtocolName()); case CLIENT_ID: return matches(session.getRemotingConnection().getClientID()); case LOCAL_ADDRESS: return matches(session.getRemotingConnection().getTransportConnection().getLocalAddress()); case REMOTE_ADDRESS: return matches(session.getRemotingConnection().getTransportConnection().getRemoteAddress()); default: return true; } }
@Override public Object getField(ServerProducer producer, String fieldName) { ServerSession session = server.getSessionByID(producer.getSessionID()); //if session is not available then consumer is not in valid state - ignore if (session == null) { return null; } switch (fieldName) { case "id": return producer.getID(); case "session": return session.getName(); case "user": return session.getUsername(); case "clientID": return session.getRemotingConnection().getClientID(); case "protocol": return session.getRemotingConnection().getProtocolName(); case "address": return producer.getAddress() != null ? producer.getAddress() : session.getDefaultAddress(); case "localAddress": return session.getRemotingConnection().getTransportConnection().getLocalAddress(); case "remoteAddress": return session.getRemotingConnection().getTransportConnection().getRemoteAddress(); case "creationTime": return producer.getCreationTime(); default: throw new IllegalArgumentException("Unsupported field, " + fieldName); } }
@Override public boolean test(ServerProducer producer) { // Using switch over enum vs string comparison is better for perf. if (f == null) return true; switch (f) { case ID: return matches(producer.getID()); case CONNECTION_ID: return matches(producer.getConnectionID()); case SESSION_ID: return matches(producer.getSessionID()); case USER: return matches(server.getSessionByID(producer.getSessionID()).getUsername()); case ADDRESS: return matches(producer.getAddress() != null ? producer.getAddress() : server.getSessionByID(producer.getSessionID()).getDefaultAddress()); case PROTOCOL: return matches(producer.getProtocol()); case CLIENT_ID: return matches(server.getSessionByID(producer.getSessionID()).getRemotingConnection().getClientID()); case LOCAL_ADDRESS: return matches(server.getSessionByID(producer.getSessionID()).getRemotingConnection().getTransportConnection().getLocalAddress()); case REMOTE_ADDRESS: return matches(server.getSessionByID(producer.getSessionID()).getRemotingConnection().getTransportConnection().getRemoteAddress()); default: return true; } }
@Override public boolean test(ServerConsumer consumer) { // Using switch over enum vs string comparison is better for perf. if (f == null) return true; switch (f) { case ID: return matches(consumer.getSequentialID()); case SESSION_ID: return matches(consumer.getSessionID()); case USER: return matches(server.getSessionByID(consumer.getSessionID()).getUsername()); case ADDRESS: return matches(consumer.getQueue().getAddress()); case QUEUE: return matches(consumer.getQueue().getName()); case FILTER: return matches(consumer.getFilterString()); case PROTOCOL: return matches(server.getSessionByID(consumer.getSessionID()).getRemotingConnection().getProtocolName()); case CLIENT_ID: return matches(server.getSessionByID(consumer.getSessionID()).getRemotingConnection().getClientID()); case LOCAL_ADDRESS: return matches(server.getSessionByID(consumer.getSessionID()).getRemotingConnection().getTransportConnection().getLocalAddress()); case REMOTE_ADDRESS: return matches(server.getSessionByID(consumer.getSessionID()).getRemotingConnection().getTransportConnection().getRemoteAddress()); } return true; }