Class BusPolicy

java.lang.Object
org.apache.juneau.console.bus.BusPolicy

public final class BusPolicy extends Object
What a ServerBus will carry, in which direction, to whom. Everything not allowed here is denied.

Downstream entries are topic patterns: a custom topic (ns.name), a keyed custom topic or key pattern (ns.name:key, ns.name:*), a job topic or pattern (job:<id>, job:*), or a card command topic (cmd:<cardId>). Upstream entries are exact custom topics, each with its UpstreamHandler.

Example:

BusPolicy p = BusPolicy.create() .downstream("ops.jobs", true) // retained state .downstream("ops.alert:*", false) // events, any key .upstream("ops.cancel-all", (session, topic, payload) -> jobs.cancelAll()) .authorizer((req, topic) -> req.isUserInRole("ops")) // per-user, both directions .boundary(boundary) // LoopbackBoundary or CsrfBoundary .build(); // In a page test: every topic the page's bridges request is granted (E-55 otherwise). p.check(PageCapture.of(html).contract());

Since:
10.0.0
  • Method Details

    • create

      public static BusPolicy.Builder create()
      Creates a new builder. An unmodified builder builds a policy that grants nothing.
      Returns:
      A new builder.
    • downstreamRetain

      Returns whether a topic (or a requested pattern) may flow downstream, and if so whether it is retained.

      A policy entry covers a topic when it is equal to it, or when the entry is family:* and the topic is family:<anything>.

      Parameters:
      topic - A concrete topic or a requested pattern. Can be null.
      Returns:
      The retain flag, or empty when the topic is denied.
    • allowsUpstream

      public boolean allowsUpstream(String topic)
      Returns whether a topic may flow upstream (exact match only).
      Parameters:
      topic - The topic. Can be null.
      Returns:
      true if the policy has a handler for it.
    • check

      public void check(Map<String,?> contract)
      Checks that this policy grants every topic that a page contract's bridges request (E-55).

      Adopter page tests call this next to PageContractAssert.hasNoWiringErrors(). The request-dependent authorizer() is not consulted: it can only narrow a grant at session time.

      Parameters:
      contract - The page contract (for example PageCapture.of(html).contract()).
      Throws:
      IllegalStateException - Listing every denied topic, one E-55 line each.
    • authorizer

      public BiPredicate<jakarta.servlet.http.HttpServletRequest,String> authorizer()
      Returns:
      The per-request, per-topic authorizer applied at session open. Defaults to allow-all.
    • boundary

      Returns:
      The request boundary, or null when the application has its own guard.
    • allowedOrigins

      Returns:
      The exact origins allowed on a WebSocket handshake when no boundary() is set.
    • sessionGrace

      Returns:
      How long a session survives after its last connection closes. Default 60 s.
    • maxSessionAge

      Returns:
      The absolute session lifetime. Default 12 h.
    • heartbeat

      public Duration heartbeat()
      Returns:
      The idle interval after which a ping frame is sent. Default 15 s.
    • maxSessions

      public int maxSessions()
      Returns:
      The maximum number of live sessions. Default 256.
    • maxQueuedFrames

      public int maxQueuedFrames()
      Returns:
      The per-connection outbound queue bound. Default 1024.
    • maxFrameBytes

      public int maxFrameBytes()
      Returns:
      The maximum encoded frame size in UTF-8 bytes, both directions. Default 65536.
    • maxUpstreamPerSecond

      public int maxUpstreamPerSecond()
      Returns:
      The per-session upstream frame rate limit. Default 20.
    • sessionAttributes

      public Function<jakarta.servlet.http.HttpServletRequest,Map<String,Object>> sessionAttributes()
      Returns:
      The function that captures session attributes at session open. Defaults to an empty map.