@SuppressWarnings("unchecked") private static Handler<Void> getConnectionLossHandler(final ProtonConnection con) { return con.attachments().get("connectionLossHandler", Handler.class); }
/** * Gets the principal representing a connection's client. * * @param con The connection to get the principal for. * @return The principal representing the authenticated client or {@link Constants#PRINCIPAL_ANONYMOUS} * if the client has not been authenticated. * @throws NullPointerException if the connection is {@code null}. */ public static HonoUser getClientPrincipal(final ProtonConnection con) { final Record attachments = Objects.requireNonNull(con).attachments(); return getClientPrincipal(attachments); }
/** * Gets the principal representing a connection's client. * * @param con The connection to get the principal for. * @return The principal representing the authenticated client or {@link Constants#PRINCIPAL_ANONYMOUS} * if the client has not been authenticated. * @throws NullPointerException if the connection is {@code null}. */ public static HonoUser getClientPrincipal(final ProtonConnection con) { final Record attachments = Objects.requireNonNull(con).attachments(); return getClientPrincipal(attachments); }
/** * Gets the principal representing a connection's client. * * @param con The connection to get the principal for. * @param principal The principal representing the authenticated client. * @throws NullPointerException if any of the parameters is {@code null}. */ public static void setClientPrincipal(final ProtonConnection con, final HonoUser principal) { Objects.requireNonNull(principal); final Record attachments = Objects.requireNonNull(con).attachments(); attachments.set(KEY_CLIENT_PRINCIPAL, HonoUser.class, principal); }
/** * Gets the (surrogate) identifier of an AMQP connection. * * @param connection The connection to determine the connection id for. * @return The identifier retrieved from the connection's <em>attachments</em> using key {@link #KEY_CONNECTION_ID} * or {@code null} if the attachments do not contain a value for that a key. */ public static String getConnectionId(final ProtonConnection connection) { return connection.attachments().get(KEY_CONNECTION_ID, String.class); }
/** * Sets the (surrogate) identifier of an AMQP connection. * <p> * The identifier will be added to the connection's <em>attachments</em> under key * {@link #KEY_CONNECTION_ID}. * * @param connection The connection to set id for. * @param id The identifier to set. * @throws NullPointerException if any of the parameters is {@code null}. */ public static void setConnectionId(final ProtonConnection connection, final String id) { Objects.requireNonNull(connection).attachments().set(Constants.KEY_CONNECTION_ID, String.class, Objects.requireNonNull(id)); }
/** * Gets the principal representing a connection's client. * * @param con The connection to get the principal for. * @param principal The principal representing the authenticated client. * @throws NullPointerException if any of the parameters is {@code null}. */ public static void setClientPrincipal(final ProtonConnection con, final HonoUser principal) { Objects.requireNonNull(principal); final Record attachments = Objects.requireNonNull(con).attachments(); attachments.set(KEY_CLIENT_PRINCIPAL, HonoUser.class, principal); }
/** * Gets the (surrogate) identifier of an AMQP connection. * * @param connection The connection to determine the connection id for. * @return The identifier retrieved from the connection's <em>attachments</em> using key {@link #KEY_CONNECTION_ID} * or {@code null} if the attachments do not contain a value for that a key. */ public static String getConnectionId(final ProtonConnection connection) { return connection.attachments().get(KEY_CONNECTION_ID, String.class); }
/** * Sets the (surrogate) identifier of an AMQP connection. * <p> * The identifier will be added to the connection's <em>attachments</em> under key * {@link #KEY_CONNECTION_ID}. * * @param connection The connection to set id for. * @param id The identifier to set. * @throws NullPointerException if any of the parameters is {@code null}. */ public static void setConnectionId(final ProtonConnection connection, final String id) { Objects.requireNonNull(connection).attachments().set(Constants.KEY_CONNECTION_ID, String.class, Objects.requireNonNull(id)); }
private static void addConnectionLossHandler(final ProtonConnection con, final Handler<Void> handler) { con.attachments().set("connectionLossHandler", Handler.class, handler); }
private void addPrincipal(final Principal authzId) { succeeded = true; protonConnection.attachments().set(Constants.KEY_CLIENT_PRINCIPAL, Principal.class, authzId); LOG.debug("authentication of client [authorization ID: {}] succeeded", authzId.getName()); sasl.done(SaslOutcome.PN_SASL_OK); }
private void publishConnectionClosedEvent(final ProtonConnection con) { String conId = con.attachments().get(Constants.KEY_CONNECTION_ID, String.class); if (conId != null) { vertx.eventBus().publish( Constants.EVENT_BUS_ADDRESS_CONNECTION_CLOSED, conId); } }
/** * Processes a peer's AMQP <em>open</em> frame. * <p> * This default implementation * <ol> * <li>adds a unique connection identifier to the connection's attachments * under key {@link Constants#KEY_CONNECTION_ID}</li> * <li>invokes {@link #processDesiredCapabilities(ProtonConnection, Symbol[])}</li> * <li>sets a timer that closes the connection once the client's token * has expired</li> * <li>sends the AMQP <em>open</em> frame to the peer</li> * </ol> * * @param connection The connection to open. */ protected void processRemoteOpen(final ProtonConnection connection) { final HonoUser clientPrincipal = Constants.getClientPrincipal(connection); LOG.debug("client [container: {}, user: {}] connected", connection.getRemoteContainer(), clientPrincipal.getName()); // attach an ID so that we can later inform downstream components when connection is closed connection.attachments().set(Constants.KEY_CONNECTION_ID, String.class, UUID.randomUUID().toString()); processDesiredCapabilities(connection, connection.getRemoteDesiredCapabilities()); final Duration delay = Duration.between(Instant.now(), clientPrincipal.getExpirationTime()); final WeakReference<ProtonConnection> conRef = new WeakReference<>(connection); vertx.setTimer(delay.toMillis(), timerId -> { if (conRef.get() != null) { closeExpiredConnection(conRef.get()); } }); connection.open(); }
final HonoUser clientPrincipal = Constants.getClientPrincipal(connection); connection.attachments().set(Constants.KEY_CONNECTION_ID, String.class, UUID.randomUUID().toString()); processDesiredCapabilities(connection, connection.getRemoteDesiredCapabilities()); final Duration delay = Duration.between(Instant.now(), clientPrincipal.getExpirationTime());
private static ProtonConnection newConnection(final HonoUser user) { final Record attachments = new RecordImpl(); attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID); attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user); final ProtonConnection con = mock(ProtonConnection.class); when(con.attachments()).thenReturn(attachments); when(con.getRemoteContainer()).thenReturn("test-client"); return con; }
private void setRemoteConnectionOpenHandler(final ProtonConnection connection) { connection.sessionOpenHandler(remoteOpenSession -> handleSessionOpen(connection, remoteOpenSession)); connection.receiverOpenHandler(remoteOpenReceiver -> handleReceiverOpen(connection, remoteOpenReceiver)); connection.senderOpenHandler(remoteOpenSender -> handleSenderOpen(connection, remoteOpenSender)); connection.disconnectHandler(this::handleRemoteDisconnect); connection.closeHandler(remoteClose -> handleRemoteConnectionClose(connection, remoteClose)); connection.openHandler(remoteOpen -> { LOG.info("client [container: {}, user: {}] connected", connection.getRemoteContainer(), getUserFromConnection(connection)); connection.open(); // attach an ID so that we can later inform downstream components when connection is closed connection.attachments().set(Constants.KEY_CONNECTION_ID, String.class, UUID.randomUUID().toString()); }); }
protonConnection.attachments().set(AmqpAdapterConstants.KEY_CURRENT_SPAN, Span.class, currentSpan); final Device authenticatedDevice = outcome.result(); protonConnection.attachments().set(AmqpAdapterConstants.KEY_CLIENT_DEVICE, Device.class, authenticatedDevice); succeeded = true;
connection.setContainer(containerId); connection.openHandler(conn -> { UserData userData = connection.attachments().get(SaslAuthenticator.USER_ATTACHMENT, UserData.class); if(userData != null) { LOG.info("Responding with user data " + userData);
checkAuthorizationToAttach(user, targetResource, Permission.READ, isAuthorized -> { if (isAuthorized) { copyConnectionId(con.attachments(), sender.attachments()); sender.setSource(sender.getRemoteSource()); endpoint.onLinkAttach(sender, targetResource);
checkAuthorizationToAttach(user, targetResource, Permission.WRITE, isAuthorized -> { if (isAuthorized) { copyConnectionId(con.attachments(), receiver.attachments()); receiver.setTarget(receiver.getRemoteTarget()); endpoint.onLinkAttach(receiver, targetResource);